Manages Huawei Cloud IAM identity configuration for users, groups, policies, agencies and permanent AK/SK. Every write (R2/R1) is previewed and explicitly confirmed; deletes enumerate impacted resources first; high-authority grants and external-account agencies show warnings; the Secret Access Key is returned once and never persisted or logged. Provides 22 huawei_* actions: huawei_list_iam_users, huawei_list_iam_groups, huawei_list_iam_policies, huawei_list_iam_agencies, huawei_list_iam_custom_policies, huawei_analyze_iam_least_privilege, huawei_analyze_iam_password_compliance, 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, huawei_delete_iam_user, huawei_delete_iam_group, huawei_delete_iam_agency, huawei_delete_iam_ak_sk, huawei_delete_iam_custom_policy, huawei_add_iam_user_to_group, huawei_provision_iam_user. The last two (add-user-to-group / one-shot provision) run as pure Python SDK scripts signed with AK/SK or temporary AK/SK (security token); they need no hcloud/KooCLI, are idempotent (409 reuse / already_member), support --dry-run and --confirm, and never print credentials. Triggers include: IAM, 用户, 用户组, 策略, 委托, 权限, AK/SK, MFA, 创建用户, 删除用户, 创建子用户并加入用户组, 一键开通 IAM 用户, 用户加入用户组, AddUserToGroupV5, provision IAM user, policy, agency, delete.
---
name: huawei-cloud-iam-manage
description: >
Manages Huawei Cloud IAM identity configuration for users, groups, policies, agencies and permanent
AK/SK. Every write (R2/R1) is previewed and explicitly confirmed; deletes enumerate impacted
resources first; high-authority grants and external-account agencies show warnings; the Secret Access
Key is returned once and never persisted or logged. Provides 22 huawei_* actions:
huawei_list_iam_users, huawei_list_iam_groups, huawei_list_iam_policies, huawei_list_iam_agencies,
huawei_list_iam_custom_policies, huawei_analyze_iam_least_privilege,
huawei_analyze_iam_password_compliance, 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,
huawei_delete_iam_user, huawei_delete_iam_group, huawei_delete_iam_agency,
huawei_delete_iam_ak_sk, huawei_delete_iam_custom_policy, huawei_add_iam_user_to_group,
huawei_provision_iam_user. The last two (add-user-to-group / one-shot provision) run as pure Python
SDK scripts signed with AK/SK or temporary AK/SK (security token); they need no hcloud/KooCLI, are
idempotent (409 reuse / already_member), support --dry-run and --confirm, and never print credentials.
Triggers include: IAM, 用户, 用户组, 策略, 委托, 权限, AK/SK, MFA, 创建用户, 删除用户, 创建子用户并加入用户组,
一键开通 IAM 用户, 用户加入用户组, AddUserToGroupV5, provision IAM user, policy, agency, delete.
tags: [huawei-cloud, iam, identity, security, management]
---
# 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 using `hcloud 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
1. **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), then `hcloud configure list` must show a valid profile with mode `AKSK` and a real
`accessKeyId`.
- **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** read `HUAWEICLOUD_SDK_AK`/`HUAWEICLOUD_SDK_SK`, `HUAWEI_ACCESS_KEY`/`HUAWEI_SECRET_KEY`,
or `HW_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 with `hcloud configure set`.
- Verify authentication with the `configure list` subcommand.
2. **Region**: always pass `--cli-region={region}` (e.g. `cn-north-4`).
3. **IAM permissions** on the calling identity: least-privilege policies are provided in
`references/iam-policies.md`. The calling user/agency must hold the corresponding
`iam:users:createUser` / `iam:users:deleteUser` / `iam:groups:createGroup` / `iam:agencies:createAgency`
/ `iam:credentials:createAKSK` / `iam:permissions:grantRoleToUserOnProject` style permissions, or be
the account administrator.
4. Read-only pre-checks (`list_*`, `GetAccountSummaryV5`) require at least
`iam:users:listUsers` / `iam:groups:listGroups` / `iam:permissions:listPolicies` /
`iam:agencies:listAgencies` permissions.
5. **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" in `references/commands-reference.md`); never run with
literal `{...}`.
6. **`skill-quality-cli`** — ensured by `bash scripts/ensure_cli.sh` (idempotent, skips if present;
hardened download with timeout, retry and SHA256 verification).
- Upgrade: run `skill-quality-cli upgrade` manually (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-checksum`
opt-in bypasses verification (a loud warning is printed).
7. **Provisioning (Python SDK) path only** — for `huawei_add_iam_user_to_group` /
`huawei_provision_iam_user`, instead of `hcloud` you need Python 3.7+ and the SDK
(`requirements.txt`: `huaweicloudsdkcore`, `huaweicloudsdkiam`), plus `HW_ACCESS_KEY` / `HW_SECRET_KEY`
(optional `HW_SECURITY_TOKEN` for temporary AK/SK). Run `skill action=exec: python3
skill://scripts/ensure_env.py` once to prepare and validate.
- The first run creates a virtual environment at `~/.cache/huawei-cloud-iam-manage/venv`
(`%LOCALAPPDATA%\huawei-cloud-iam-manage\venv` on Windows; override with `HW_VENV_DIR`) and runs
the script again with `bin/python3` (`Scripts\python.exe`); the system interpreter and the skill
directory are left untouched (PEP 668 safe, no file-count pollution).
- `iam_user_provision.py` uses the same bootstrap: a plain `python3` invocation 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.txt`
manually and re-run the script.
> **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
```text
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_policy` with a high-authority policy (AdministratorAccess / *FullAccess / *Admin* /
`iam:permissions:grantRoleToUserOnProject` on a system policy): additionally print a warning:
*"This grants broad authority. Confirm you intend to grant this permission."*
- `create_iam_agency` targeting an external account (`--agency.trust_domain_name` set 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_login` with a `--password`: treat the value as Sensitive — obtain it via
`read -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 via `ListEntitiesForPolicyV5`), print the impact list,
then require explicit confirmation.
## Core Commands
> Every `hcloud` command in this skill MUST be wrapped with
> `skill-quality-cli run --skill-name huawei-cloud-iam-manage -- <command>` — bare `hcloud` calls are
> forbidden. The complete command templates (all 20 hcloud actions, dual bare/wrapped form, and resource-ID
> resolution) are in `references/commands-reference.md`; the examples below are one per capability. The two
> Provision actions use the Python SDK instead of `hcloud` and are documented in
> `references/provisioning-api-reference.md`.
### Query (R3 — read-only)
```bash
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)
```bash
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)
```bash
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)
```bash
# 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.
```bash
# 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> --help` before constructing a command to confirm exact parameter
> names. Operation+param tables were verified against KooCLI 7.2.12 and are kept in
> `references/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=1` opt-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 resolution
- `references/parameters-reference.md` — Parameter Confirmation tables (Query / Analyze / Create / Attach / Login / Delete)
- `references/provisioning-api-reference.md` — Python SDK provisioning endpoints, parameters, validation, error matrix
- `references/iam-policies.md` — Least-privilege IAM policies required for each action
- `references/dataflow-diagram.md` — Mermaid data flow diagram
- `references/verification-method.md` — Verification method and acceptance checks
- `references/acceptance-criteria.md` — Acceptance criteria for the 22 huawei_* actions
- `references/troubleshooting.md` — Common errors and fixes
- `references/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/docdon't have the plugin yet? install it then click "run inline in claude" again.