id: huawei-iam-access-key-rotation-hygiene-sentinel
namespace: company.team
description: |
List a Huawei Cloud IAM user's permanent access keys on a schedule,
classify the result HEALTHY or STALE_ACCESS_KEY_DETECTED based on how
many active keys exceed a configurable rotation age, log clean passes,
and alert Slack with the exact access key ID and age before a
long-lived credential becomes a security liability.
triggers:
- id: periodic_key_rotation_check
type: io.kestra.plugin.core.trigger.Schedule
description: "Checks once a day - access key age changes slowly, so daily
resolution is enough to catch rotation drift well before it becomes a real
audit finding. Shipped disabled; enable it once huawei_region and
target_user_id point at a real Huawei Cloud IAM user and a manual run has
been verified."
cron: "0 9 * * *"
disabled: true
inputs:
huawei_region: "eu-west-101"
target_user_id: "REPLACE-WITH-YOUR-IAM-USER-ID"
max_key_age_days: 90
inputs:
- id: huawei_region
type: STRING
displayName: "Huawei Cloud Region"
defaults: "eu-west-101"
description: "Region passed to io.kestra.plugin.huawei.koocli.KooCLI, matching
the plugin's own documented example region. IAM is a global service, but
KooCLI still requires a region to configure its profile."
- id: target_user_id
type: STRING
displayName: "IAM User ID"
defaults: "REPLACE-WITH-YOUR-IAM-USER-ID"
description: "IAM user ID whose permanent access keys are audited, passed to
ListPermanentAccessKeys's own user_id query parameter (verified from
Huawei's own API reference). Must be replaced with a real IAM user ID -
querying another user's keys requires administrator permissions."
- id: max_key_age_days
type: INT
displayName: "Max Access Key Age (days)"
defaults: 90
description: "An active permanent access key older than this (by its
create_time) is flagged as overdue for rotation - a long-lived, unrotated
credential is a classic audit finding and a larger blast radius if it ever
leaks."
tasks:
- id: probe_list_access_keys
type: io.kestra.plugin.huawei.koocli.KooCLI
description: "hcloud IAM ListPermanentAccessKeys (service and operation name
verified from this plugin's own doc example pattern - hcloud IAM
KeystoneListProjects - combined with ListPermanentAccessKeys's own
documented GET /v3.0/OS-CREDENTIAL/credentials endpoint and user_id
parameter) is read-only; it cannot create, disable, or delete any access
key. The output-capture convention here strips both spaces and newlines,
matching this plugin's own documented example exactly, since every field
in this response (access key ID, status, timestamps) is a space-free token
with no human-readable sentence to corrupt."
accessKeyId: "{{ secret('HUAWEI_ACCESS_KEY_ID') }}"
secretAccessKey: "{{ secret('HUAWEI_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.huawei_region }}"
commands:
- hcloud IAM ListPermanentAccessKeys --user_id={{ inputs.target_user_id }}
--cli-output=json | tr -d ' \n' | xargs -0 -I {} echo
'::{"outputs":{}}::'
- id: evaluate_key_rotation_hygiene
type: io.kestra.plugin.core.flow.If
description: "STALE_ACCESS_KEY_DETECTED whenever at least one key with status
active (verified output fields from ListPermanentAccessKeys's own
documented response schema: credentials, status, create_time, access) has
a create_time older than max_key_age_days. fromdateiso8601 and now are
real, documented jq builtins already used in this repository's other
date-window sentinels."
condition: "{{ (outputs.probe_list_access_keys.vars.credentials ?? []) |
jq('map(select(.status == \"active\" and (now - (.create_time |
sub(\"\\.[0-9]+Z$\"; \"Z\") | fromdateiso8601)) > (' ~
inputs.max_key_age_days ~ ' * 86400))) | length') > 0 }}"
then:
- id: alert_stale_access_keys
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Always alert on STALE_ACCESS_KEY_DETECTED, listing each flagged
key's access key ID and age in days so the team knows exactly which
credential to rotate without querying the IAM console."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Huawei IAM access key sentinel: STALE_ACCESS_KEY_DETECTED for user " ~ inputs.target_user_id ~ ". Active keys past " ~ inputs.max_key_age_days ~ " days: " ~ ((outputs.probe_list_access_keys.vars.credentials ?? []) | jq('map(select(.status == \"active\" and (now - (.create_time | sub(\"\\.[0-9]+Z$\"; \"Z\") | fromdateiso8601)) > (' ~ inputs.max_key_age_days ~ ' * 86400))) | map("\(.access) (\(((now - (.create_time | sub(\"\\.[0-9]+Z$\"; \"Z\") | fromdateiso8601)) / 86400) | floor) days old)") | join("; ")')) ~ ". Execution " ~ execution.id ~ "."
} | toJson }}
else:
- id: log_access_keys_healthy
type: io.kestra.plugin.core.log.Log
message: "HEALTHY: no active permanent access keys for user {{
inputs.target_user_id }} exceed {{ inputs.max_key_age_days }} days
old, out of {{ (outputs.probe_list_access_keys.vars.credentials ?? [])
| length }} key(s) returned."
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: "Final status line for every run, independent of which branch fired."
message: "Access key rotation audit complete for user {{ inputs.target_user_id
}}. total_keys={{ (outputs.probe_list_access_keys.vars.credentials ?? [])
| length }}."
errors:
- id: alert_execution_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Alert when the flow itself fails outside the handled
HEALTHY/STALE_ACCESS_KEY_DETECTED branches, for example an invalid IAM
user ID, insufficient permissions to query another user's keys, or invalid
credentials."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Huawei IAM access key sentinel FAILED in execution " ~ execution.id ~ " for user " ~ inputs.target_user_id ~ ". ListPermanentAccessKeys did not complete; investigate before trusting the last known HEALTHY/STALE_ACCESS_KEY_DETECTED status."
} | toJson }}