Huawei Cloud IAM Management
STOP - Do not answer from general knowledge. Follow the procedure below.
Overview
This skill provides write-capable management of Huawei Cloud IAM identity configuration through the
IAM service of the hcloud CLI (advanced operation reference: IAM --help). It is the manage
companion to the read-only IAM query capability (a query+manage pair for IAM security).
It covers 22 huawei_* actions in four capability groups:
| Capability | Risk level | Actions |
|---|---|---|
| Query (read-only pre-checks) | R3 — run directly | huawei_list_iam_users, huawei_list_iam_groups, huawei_list_iam_policies, huawei_list_iam_agencies, huawei_list_iam_custom_policies |
| Diagnose / Analyze (read-only) | R3 — run directly | huawei_analyze_iam_least_privilege, huawei_analyze_iam_password_compliance |
| Manage (create/configure) | R2 — preview + confirm | huawei_create_iam_user, huawei_create_iam_group, huawei_attach_iam_policy, huawei_detach_iam_policy, huawei_create_iam_agency, huawei_create_iam_ak_sk, huawei_create_iam_custom_policy, huawei_config_iam_login |
| Manage (delete) | R1 — preview + confirm + impact list | huawei_delete_iam_user, huawei_delete_iam_group, huawei_delete_iam_agency, huawei_delete_iam_ak_sk, huawei_delete_iam_custom_policy |
| Provision (Python SDK, no hcloud) | R2 — preview + confirm | huawei_add_iam_user_to_group, huawei_provision_iam_user |
The two Provision actions are the only actions in this skill that do not go through the hcloud CLI: they run the bundled Python SDK scripts (
scripts/iam_user_provision.py) signed with AK/SK or temporary AK/SK (security token). All other actions keep usinghcloud IAM.
Scope boundaries:
- ✅ List users/groups/policies/agencies/custom policies (R3, read-only, run directly)
- ✅ Analyze least-privilege and domain password policy compliance (R3, read-only)
- ✅ Create users, groups, agencies, custom policies, permanent AK/SK; attach/detach policies; configure login profile / password / login protection (R2, preview + confirm)
- ✅ Delete users, groups, agencies, permanent AK/SK, custom policies (R1, preview + confirm)
- ✅ Add an existing user to a user group, and one-shot provision (create user → create group → add to
group) via pure Python SDK with
--dry-run/--confirm(R2, no hcloud dependency) - ❌ NEVER modify a system (predefined) policy — only custom policies are manageable
- ❌ NEVER disable the root/enterprise administrator account, or take any irreversible action without explicit confirmation
- ❌ NEVER write the Secret Access Key (SK), passwords, or any credential value to logs, files, persistent storage, tool intermediates, or any later conversation turn — the SK may only appear in the final reply, shown once to the user
Dependency: Quality telemetry is collected automatically via skill-quality-cli (installed by scripts/ensure_cli.sh if absent).
Critical Warnings
| Trap | Why |
|---|---|
SK 仅返回一次 — The Secret Access Key is returned exactly once by CreatePermanentAccessKey. Show it to the user exactly once, in the final reply. It must not be written to logs, files, persistent storage, tool-call inputs/outputs, or any later conversation turn. |
A lost SK cannot be retrieved; the key must be deleted and re-created. |
Passwords are Sensitive — --password in login-profile operations must never be echoed, logged, or stored. |
Credential leakage. |
Granting high-authority policies (e.g. AdministratorAccess, SysAdm*, FullAccess) requires an explicit warning before confirmation. |
Least-privilege principle. |
Creating an agency for an external account authorizes that account to assume the rights granted by the agency — show the trusted account (trust_domain_name) and warn before confirmation. |
Cross-account risk. |
| Delete is irreversible — deleting a user permanently removes the IAM user and its access keys; deleting an agency revokes delegated access; deleting a custom policy breaks any attachments. | Data/access loss. |
Verifying by name first — always run the read-only pre-check (list_users, list_groups, list_policies, list_agencies) before creating to avoid duplicates, and re-read after write to confirm. |
Idempotency + accuracy. |
Prerequisites
- hcloud CLI (KooCLI 7.2.x or later) installed and authenticated.
- Recommended authentication — Mode B: local hcloud profile via the configure wizard: run
hcloud configure set(interactive; credentials are prompted and never passed on the command line), thenhcloud configure listmust show a valid profile with modeAKSKand a realaccessKeyId. - AK/SK environment variables are NOT a supported credential path for KooCLI — KooCLI reads its
configuration from the OS user home directory (resolved from the OS user home, not
$HOME), and does not readHUAWEICLOUD_SDK_AK/HUAWEICLOUD_SDK_SK,HUAWEI_ACCESS_KEY/HUAWEI_SECRET_KEY, orHW_ACCESS_KEY/HW_SECRET_KEY(verified against KooCLI 7.2.12: no such env names are consulted — those names belong to the Huawei Cloud SDKs, not KooCLI). Do not rely on environment variables for authentication; always configure a profile withhcloud configure set. - Verify authentication with the
configure listsubcommand.
- Recommended authentication — Mode B: local hcloud profile via the configure wizard: run
- Region: always pass
--cli-region={region}(e.g.cn-north-4). - IAM permissions on the calling identity: least-privilege policies are provided in
references/iam-policies.md. The calling user/agency must hold the correspondingiam:users:createUser/iam:users:deleteUser/iam:groups:createGroup/iam:agencies:createAgency/iam:credentials:createAKSK/iam:permissions:grantRoleToUserOnProjectstyle permissions, or be the account administrator. - Read-only pre-checks (
list_*,GetAccountSummaryV5) require at leastiam:users:listUsers/iam:groups:listGroups/iam:permissions:listPolicies/iam:agencies:listAgenciespermissions. - Placeholders are illustrative — every
{user_id}/{group_id}/{policy_id}/{agency_id}/{access_key}must be replaced with the real value from the read-only list commands (see "Resolving resource IDs" inreferences/commands-reference.md); never run with literal{...}. skill-quality-cli— ensured bybash scripts/ensure_cli.sh(idempotent, skips if present; hardened download with timeout, retry and SHA256 verification).- Upgrade: run
skill-quality-cli upgrademanually (no auto-upgrade) - Disable telemetry report: set
SKILL_QUALITY_REPORT=0 - If the release publishes no SHA256 metadata, the installer refuses to install; only after
confirming the artifact source, an explicit
bash scripts/install_cli.sh --force --no-checksumopt-in bypasses verification (a loud warning is printed).
- Upgrade: run
- Provisioning (Python SDK) path only — for
huawei_add_iam_user_to_group/huawei_provision_iam_user, instead ofhcloudyou need Python 3.7+ and the SDK (requirements.txt:huaweicloudsdkcore,huaweicloudsdkiam), plusHW_ACCESS_KEY/HW_SECRET_KEY(optionalHW_SECURITY_TOKENfor temporary AK/SK). Runskill action=exec: python3 skill://scripts/ensure_env.pyonce to prepare and validate.- The first run creates a virtual environment at
~/.cache/huawei-cloud-iam-manage/venv(%LOCALAPPDATA%\huawei-cloud-iam-manage\venvon Windows; override withHW_VENV_DIR) and runs the script again withbin/python3(Scripts\python.exe); the system interpreter and the skill directory are left untouched (PEP 668 safe, no file-count pollution). iam_user_provision.pyuses the same bootstrap: a plainpython3invocation re-runs itself with that interpreter when the SDK is absent there, so the commands below stay valid.- If automatic creation fails, run
python3 -m venv ~/.cache/huawei-cloud-iam-manage/venv && ~/.cache/huawei-cloud-iam-manage/venv/bin/pip install -r requirements.txtmanually and re-run the script.
- The first run creates a virtual environment at
Account SCP restriction (environment, not skill logic): under an org SCP, user/login/AK-SK writes (
CreateUserV5, login-profile/protect,CreatePermanentAccessKey) may be denied (PAP5.0001-style) even with the IAM permissions above; groups/policies/agencies/attach/detach/list are unaffected — report the deny, suggest checking the org SCP, then proceed with permitted actions.
Workflow
1. Identify target → region, user/group/policy/agency name or id, action intent
2. Classify intent →
- Query / Diagnose (R3): list / analyze — run directly
- Manage (R2): create / attach / detach / configure — show preview, DO-NOT-WARN advice, ask confirmation
- Manage (R1): delete — enumerate impacted resources, show irreversible warning, require confirmation
- Provision (R2, Python SDK): add-user-to-group / one-shot provision — preview with --dry-run,
require --confirm (no hcloud involved)
3. Pre-check (write actions) → run the relevant read-only list command and confirm no duplicate / correct targets
4. Execute → hcloud actions: build the command from references/commands-reference.md (wrapped with
skill-quality-cli); Provision actions: run scripts/iam_user_provision.py (see "Core Commands → Provision")
5. Verify → re-read the resource with the corresponding query command
6. Output → structured JSON summary (never credentials)
Confirmation gates (MUST NOT be skipped):
- R3 actions: run directly (read-only; no resource state is changed).
- R2 actions (
create_user,create_group,attach_iam_policy,detach_iam_policy,create_iam_agency,create_iam_ak_sk,create_iam_custom_policy,config_iam_login,add_iam_user_to_group,provision_iam_user): show the full command, the resource to be created/changed, and ask "confirm?" before running.attach_iam_policywith a high-authority policy (AdministratorAccess / *FullAccess / Admin /iam:permissions:grantRoleToUserOnProjecton a system policy): additionally print a warning: "This grants broad authority. Confirm you intend to grant this permission."create_iam_agencytargeting an external account (--agency.trust_domain_nameset to a different account than the current one): print the trusted account name and warn: "This authorizes an external account to assume this agency — confirm."create_iam_ak_sk: warn that the SK will be shown only once and must not be committed or logged.config_iam_loginwith a--password: treat the value as Sensitive — obtain it viaread -s/env, never echo it in the conversation; never include it in the printed command.
- R1 actions (
delete_user,delete_group,delete_agency,delete_ak_sk,delete_custom_policy): first list the target's dependencies (user's attached policies / AK-SK / group memberships; agency's attached policies; custom policy's attachments viaListEntitiesForPolicyV5), print the impact list, then require explicit confirmation.
Core Commands
Every
hcloudcommand in this skill MUST be wrapped withskill-quality-cli run --skill-name huawei-cloud-iam-manage -- <command>— barehcloudcalls are forbidden. The complete command templates (all 20 hcloud actions, dual bare/wrapped form, and resource-ID resolution) are inreferences/commands-reference.md; the examples below are one per capability. The two Provision actions use the Python SDK instead ofhcloudand are documented inreferences/provisioning-api-reference.md.
Query (R3 — read-only)
hcloud IAM ListUsersV5 --cli-region={region}
skill-quality-cli run --skill-name huawei-cloud-iam-manage -- hcloud IAM ListUsersV5 --cli-region={region}
Diagnose / Analyze (R3 — read-only)
hcloud IAM ShowPasswordPolicyV5 --cli-region={region}
skill-quality-cli run --skill-name huawei-cloud-iam-manage -- hcloud IAM ShowPasswordPolicyV5 --cli-region={region}
Manage Create (R2 — preview + confirm)
hcloud IAM CreateUserV5 --cli-region={region} --name={user_name} --enabled=true
skill-quality-cli run --skill-name huawei-cloud-iam-manage -- hcloud IAM CreateUserV5 --cli-region={region} --name={user_name} --enabled=true
Manage Delete (R1 — preview + confirm + impact list)
# Impact pre-check first, then delete after the user confirms the impact list.
hcloud IAM ListAttachedUserPoliciesV5 --cli-region={region} --user_id={user_id}
hcloud IAM DeleteUserV5 --cli-region={region} --user_id={user_id}
skill-quality-cli run --skill-name huawei-cloud-iam-manage -- hcloud IAM DeleteUserV5 --cli-region={region} --user_id={user_id}
Provision (R2 — Python SDK, no hcloud)
huawei_provision_iam_user and huawei_add_iam_user_to_group use the bundled Python SDK scripts, not
hcloud. Always run them via skill action=exec; do not call hcloud, curl, or the IAM API directly
for these two actions.
# One-time environment prep: installs requirements.txt (mirror + PyPI fallback), verifies SDK imports,
# validates credentials with a read-only ListUsersV5 call. Credential values are never printed.
skill action=exec: python3 skill://scripts/ensure_env.py
# Preview (offline, no client built, no write call)
skill action=exec: python3 skill://scripts/iam_user_provision.py provision \
--user-name alice --group-name ops --dry-run --json
# Execute one-shot provisioning (user -> group -> membership)
skill action=exec: python3 skill://scripts/iam_user_provision.py provision \
--user-name alice --group-name ops --description "ops engineer" --confirm --json
# Atomic sub-commands
skill action=exec: python3 skill://scripts/iam_user_provision.py create-user \
--name alice --confirm --json
skill action=exec: python3 skill://scripts/iam_user_provision.py create-group \
--group-name ops --confirm --json
skill action=exec: python3 skill://scripts/iam_user_provision.py add-user-to-group \
--user-name alice --group-name ops --confirm --json
# Read-only lookups (no --confirm needed)
skill action=exec: python3 skill://scripts/iam_user_provision.py list-users --name alice --json
| Variable | Required | Description |
|---|---|---|
HW_ACCESS_KEY |
Yes | AK (falls back to HUAWEICLOUD_SDK_AK) |
HW_SECRET_KEY |
Yes | SK (falls back to HUAWEICLOUD_SDK_SK) |
HW_REGION_NAME |
No | Default cn-north-4 (IAM v5 is global; region selects the endpoint) |
HW_SECURITY_TOKEN |
No | Temporary AK/SK security token (falls back to HUAWEICLOUD_SDK_SECURITY_TOKEN) |
HW_INSECURE_TLS |
No | Default unset = TLS certificates are verified. Set to 1 only for a trusted proxy with a private CA (falls back to HUAWEICLOUD_SDK_INSECURE_TLS) |
Behavior: existing users/groups are reused (reused: true); a create 409 is re-queried and reused; an
existing membership is reported as already_member (exit 0). Without --confirm a write exits 2 and
makes no API call; --dry-run works offline with zero calls. Credentials live in memory only, are
redacted in repr, and never appear in output, logs, or files. Exit codes: 0 ok, 1 API/runtime error,
2 validation / missing --confirm. See references/provisioning-api-reference.md for endpoint,
parameter, and error-code details.
KooCLI Command Format Standard
| Feature | Description | Example |
|---|---|---|
| Service name | IAM (as shown by the IAM service --help; metadata dir iam) |
hcloud IAM ListUsersV5 --cli-region=cn-north-4 |
| Operation name | PascalCase | ListUsersV5, CreateUserV5, DeletePolicyV5 |
| Region parameter | --cli-region=<value> |
--cli-region=cn-north-4 |
| Simple parameter | --key=value |
--user_id=xxx |
| Indexed / dotted body | --parent.child=value |
--credential.user_id=xxx, --login_protect.enabled=true |
Always run
hcloud IAM <Operation> --helpbefore constructing a command to confirm exact parameter names. Operation+param tables were verified against KooCLI 7.2.12 and are kept inreferences/parameters-reference.md.
Parameter Confirmation (参数确认)
The full operation/parameter tables for Query, Analyze, Create, Attach/Detach, Configure Login and
Delete are in references/parameters-reference.md (including the --password disambiguation note for
login-profile operations).
Troubleshooting
Common errors and fixes are documented in references/troubleshooting.md.
Security Considerations
- MUST always pre-check with read-only list commands before write actions (avoid duplicate/incorrect targets).
- MUST show the full command and ask for confirmation for every R2/R1 action — never bypass the gate for writes.
- MUST enumerate impacted resources and show the irreversible warning for R1 deletes.
- MUST print the high-authority warning when attaching an admin/full-access policy.
- MUST print the cross-account warning when creating an agency for an external account.
- MUST show the SK once only, never persist/log it; passwords are Sensitive and never echoed.
- MUST delete any temporary jsonInput file containing a password immediately after the login-profile call.
- MUST NOT modify system policies; only custom policies are manageable.
- MUST keep TLS certificate verification enabled for IAM OpenAPI calls; disabling it requires the
explicit
HW_INSECURE_TLS=1opt-in (only for a private-CA proxy) and must never be a default. - SHOULD tie policies to groups and attach users to groups (coarse-grained) rather than attaching policies directly to many users.
Error Code Convention
| Prefix | Category | Examples |
|---|---|---|
| U | User input | U01 missing param, U03 no data found |
| C | Configuration | C01 missing AK/SK/env, C02 hcloud not authenticated |
| N | Network | N01 timeout, N02 connection refused |
| B | Code bug | B01 null pointer, B04 version mismatch |
| P | Platform | P01 scheduler error, P02 resource insufficient |
Reference Documents
references/commands-reference.md— Full Core Commands templates for the hcloud actions (dual bare/wrapped form) and resource-ID resolutionreferences/parameters-reference.md— Parameter Confirmation tables (Query / Analyze / Create / Attach / Login / Delete)references/provisioning-api-reference.md— Python SDK provisioning endpoints, parameters, validation, error matrixreferences/iam-policies.md— Least-privilege IAM policies required for each actionreferences/dataflow-diagram.md— Mermaid data flow diagramreferences/verification-method.md— Verification method and acceptance checksreferences/acceptance-criteria.md— Acceptance criteria for the 22 huawei_* actionsreferences/troubleshooting.md— Common errors and fixesreferences/cli-installation-guide.md— CLI installation and upgrade guidance- IAM API reference: https://support.huaweicloud.com/api-iam/iam_18_0001.html
- API Explorer: https://console.huaweicloud.com/apiexplorer/#/openapi/IAM/doc
