Huawei Cloud IAM User Login Protection Enable
Overview
Use the hcloud (KooCLI) command-line tool to enable login protection for one Huawei Cloud IAM user. Login protection adds a second authentication factor when the user signs in to the Huawei Cloud management console.
This SKILL is references-only: it does not ship a Python mutation script. The Agent calls hcloud directly using the command recipes in references/cli-commands.md.
Scope:
- One IAM user per run. Batch changes are not supported.
- Only users whose login protection is off or never configured are eligible.
- The change is free; no cloud resources are created.
- The SKILL does not set API login protection (console-only), does not bind/unbind phone, email, MFA or security keys, and does not create/delete IAM users.
When to Use This SKILL
- Use this SKILL for single-user risk remediation: discover IAM users whose login protection is off or never configured, disclose the risk, check method binding, apply the high-sensitivity confirmation guardrail, change one user, and verify.
- Use the general-purpose IAM lifecycle skill in the same family (
huawei-cloud-iam-manage, actionhuawei_config_iam_login) for general IAM login-protection configuration, or when the user is already working inside that skill's workflow. - Both routes call
UpdateLoginProtect. Decide by intent: risk remediation for one user → this SKILL; general configuration → the lifecycle skill.
Prerequisites
hcloud(KooCLI) >= 7.2.2 installed and configured with AK/SK authentication.- The AK/SK identity has IAM read/write permission (Security Administrator or equivalent), including
UpdateLoginProtect. --cli-regionis required by hcloud. Usecn-north-4by default; IAM is a global service, so the region does not change the IAM data. Do not ask the user to choose a region.--project_idis not required.- The target IAM user exists and is enabled.
- The target user's login protection is
enabled=falseor never configured. - Binding prerequisites for the selected method:
sms: a valid phone number;email: a valid email address;console_vmfa/vmfa: a virtual MFA device or security key.
- Important: the server does not validate phone/email/MFA binding. It accepts all four methods even when nothing is bound. The SKILL must warn the user; otherwise the user may be unable to complete the console second factor.
Safety Rules
- Single user only. Never loop over multiple users or run a batch change.
- Never change an already-enabled user. If the user explicitly names one, answer "already enabled, no action required" and refuse; do not report it as missing.
- Extra confirmation for high-sensitivity accounts.
is_root_user=true/is_domain_owner=true(root / enterprise administrator) or a description indicating a system account requires an additional explicit confirmation. - Never trust the process exit code. API business errors return exit code 0 and put the error JSON on stdout. Judge by JSON content.
- Never output full PII. Show phone/email as "bound / not bound" or a masked value. Never output AK/SK, tokens, or passwords.
- Never set API login protection. The API does not expose it; it is console-only.
- Never retry a failed change blindly. Same-parameter updates are idempotent, but a failure must be reported and the workflow stopped.
- Stop on failure. Do not touch other users.
Workflow
Copy the checklist below and track progress:
- [ ] Step 0: Environment and Authentication Check
- [ ] Step 1: Discover IAM Users and Login Protection Status
- [ ] Step 2: Select One IAM User
- [ ] Step 3: Select a Verification Method and Check Binding
- [ ] Step 4: Risk Disclosure and Explicit Confirmation
- [ ] Step 5: Pre-change Check, Execute, and Verify
- [ ] Step 6: Business Verification Guidance, Rollback, and Summary
Interaction Rules (minimize turns)
- Do not ask the user to choose a region; use the default
cn-north-4unless the user explicitly provided another region. - The user's selection of a user is the confirmation of
user_id; do not ask again. - The user's selection of a verification method is the confirmation of
verification_method; do not ask again. - Do not ask for permission to read
references/; read them directly when the step requires it. - Do not repeat the full user table after selection; refer to the selected user by name.
- Do not list already-enabled or disabled users in the default table; show only actionable users plus the hidden-count line. If the user asks for the full inventory, render it on request.
- If
--cli-queryis rejected, remove it and parse the first JSON object/array; do not treat the rejection as an API failure. - Reply to the user in the user's language. This document and all reference files are written in English.
Step 0: Environment and Authentication Check
- Run
hcloud versionand a read-only IAM call:hcloud IAM ListUserLoginProtects --cli-region=cn-north-4 --cli-output=json \ --cli-query="login_protects[].{user_id:user_id,enabled:enabled,verification_method:verification_method}" - If the command fails with DNS/authentication/authorization errors, report the missing prerequisite and terminate. Do not continue to discovery.
- If
--cli-queryis not accepted, retry without it and parse the first JSON object/array from stdout. - Do not use
--project_id.
Step 1: Discover IAM Users and Login Protection Status
Run the two discovery calls:
# Keep the full JSON so page_info is preserved
hcloud IAM ListUsersV5 --cli-region=cn-north-4 --limit=200 --cli-output=json
hcloud IAM ListUserLoginProtects --cli-region=cn-north-4 --cli-output=json \
--cli-query="login_protects[].{user_id:user_id,enabled:enabled,verification_method:verification_method}"
- The
ListUsersV5response containsusers[]andpage_info. Ifpage_infocontains a next marker, follow it with--markeruntil all pages are read. Merge only after the full list is read; do not filter while paging. - Build a full state map in memory by merging on
user_id:- present in
ListUserLoginProtectswithlogin_protects[].enabled=true→ login protection enabled; - present with
login_protects[].enabled=false→ login protection disabled (method is normallynone); - absent → never configured.
- present in
- The two
enabledfields are different:ListUsersV5.users[].enabled— whether the IAM user itself is enabled;ListUserLoginProtects.login_protects[].enabled— whether login protection is enabled.
- Render only actionable users:
user.enabled=trueAND the login-protection state is notenabled=true.- login protection disabled and the user is enabled → show;
- login protection never configured and the user is enabled → show;
- login protection already enabled → hide;
- IAM user disabled → hide (it cannot be changed even if login protection is off).
- Present a table with: sequence number, user name, masked user ID, login protection state (disabled / never configured), high-sensitivity marker. Do not include "enabled state", "selectable", or "current method" columns; after filtering they carry no information.
- Add one summary line under the table, for example:
Hidden: N users with login protection already enabled, M disabled users.Do not list them individually. - Mark
is_root_user=trueor a description that marks an administrator/system account as high sensitivity; such users still require the extra confirmation in Step 4. - If there is no actionable user, report the reason together with the hidden counts and terminate.
- If the user explicitly asks for the full inventory, render the full state map; the default interaction still shows only actionable users.
- Do not query phone/email/MFA for every user at this step; binding is checked only for the selected user in Step 3.
Step 2: Select One IAM User
- Ask the user to select one row from the actionable table. The selection is the confirmation of
user_id; do not ask again. - Record
user_id, user name, description, and high-sensitivity flag. - If the user explicitly names an already-enabled user (not in the table), look it up in the full state map and answer "already enabled, no action required"; do not report it as missing.
- If the user explicitly names a disabled IAM user, answer "the user is disabled and cannot be changed".
- If the user asks to change multiple users, refuse and explain "this SKILL supports one IAM user per run".
- If the user asks to see all users, render the full state map, but still allow only one actionable user to be selected.
Step 3: Select a Verification Method and Check Binding
Query the selected user's binding:
hcloud IAM ShowUser --cli-region=cn-north-4 --user_id=<USER_ID> --cli-output=json \
--cli-query="user.{phone:phone,email:email,areacode:areacode,is_domain_owner:is_domain_owner,xuser_type:xuser_type,access_mode:access_mode,enabled:enabled,description:description}"
hcloud IAM ListMfaDevicesV5 --cli-region=cn-north-4 --user_id=<USER_ID> --cli-output=json
hcloud IAM ShowUserMfaDevice --cli-region=cn-north-4 --user_id=<USER_ID> --cli-output=json
- If
ShowUserreturnsis_domain_owner=true, mark the user as high-sensitivity and apply the extra confirmation in Step 4. - Treat
phoneequal to-or empty as not bound; treat emptyemailas not bound. - Treat non-empty
mfa_devices[]as MFA bound;ShowUserMfaDevicereturningIAM.0004means no virtual MFA bound. - Security keys cannot be distinguished by the API. If the user may use a security key, ask them to confirm manually.
- Present the four methods:
| Spec | Value | Prerequisite | Console login | Programmatic access / Token | Recommendation |
|---|---|---|---|---|---|
| Virtual MFA / security key (console) | console_vmfa |
Virtual MFA or security key bound | Second factor required | Password-based token acquisition still works | Default recommendation |
| Virtual MFA (includes API login protection) | vmfa |
Virtual MFA bound | Second factor required | Password-based token acquisition may fail; password+TOTP required | Use with caution |
| SMS code | sms |
Phone number bound | SMS code required | Unaffected | Optional |
| Email code | email |
Email address bound | Email code required | Unaffected | Optional |
- Mark availability:
console_vmfa: "available" if MFA is bound; otherwise "no MFA detected; confirm manually if a security key is used".vmfa: same as above, plus the API login protection / Token warning.sms: "available" if phone bound; otherwise "not bound".email: "available" if email bound; otherwise "not bound".
- State clearly: the server does not validate binding; an unbound method may still be accepted, but the user may be unable to complete the console second factor.
- Ask the user to select one method. The selection is the confirmation of
verification_method; do not ask again. - If the user selects
vmfa, show the Token risk. - If the selected method is unbound, require an explicit acknowledgment in the same turn: "I understand the unbound risk and want to continue". Do not treat this as a second method confirmation.
Step 4: Risk Disclosure and Explicit Confirmation
Read references/risks-and-impact.md and present the decision card. Do not dump the reference file verbatim; render the five sections:
- What changes — the next console sign-in requires the selected second factor (
<method>) in addition to the username and password. - What does not change — AK/SK programmatic access, existing console sessions, other IAM users; no cloud resources are created and compute/network load does not change.
- Cost — free of charge (login protection, IAM API calls, virtual MFA, SMS/email verification codes).
- Risks of inaction — account takeover, sensitive operations without a second confirmation, compliance audit failure, malicious resource operations.
- Decision-critical warnings — the server does not validate binding; security keys cannot be detected automatically;
vmfamay break password-based token acquisition; rollback leaves a permanent record; high-sensitivity accounts need extra confirmation.
Do not present "no impact" dimensions or a per-item cost table. Do not hardcode row counts.
Then ask for explicit confirmation before any change:
- "Confirm enabling login protection for
<user_name>with verification method<method>?" - If the user does not confirm, terminate without any change.
- If the user is high-sensitivity, require an additional explicit confirmation (for example: "I confirm this change on a high-sensitivity account").
- If the selected method is unbound, require the explicit acknowledgment from Step 3.
- Do not execute
UpdateLoginProtectbefore this confirmation.
Step 5: Pre-change Check, Execute, and Verify
Pre-change check (all must pass; otherwise terminate):
- Re-read the current state (do not rely only on the Step 1 snapshot):
hcloud IAM ShowUserLoginProtect --cli-region=cn-north-4 --user_id=<USER_ID> --cli-output=jsonIAM.0004→ never configured (eligible);enabled=false→ off (eligible);enabled=true→ already enabled (stop; no change needed).
- Target user exists and
enabled=true. - Selected method is one of
console_vmfa,vmfa,sms,email. - Exactly one user is being changed.
- High-sensitivity extra confirmation and unbound-method acknowledgment are present.
Execute:
hcloud IAM UpdateLoginProtect --cli-region=cn-north-4 --user_id=<USER_ID> \
--login_protect.enabled=true \
--login_protect.verification_method=<METHOD> \
--cli-output=json
- Use dot notation exactly as above. Do not pass a JSON string for
login_protect. - Optional dry-run (safe, no change): add
--dryrunto inspect the request before executing. - Do not attempt
--login_protect.api_login_protector--api_login_protect; these are rejected and the feature is console-only.
Verify:
hcloud IAM ShowUserLoginProtect --cli-region=cn-north-4 --user_id=<USER_ID> --cli-output=json \
--cli-query="login_protect.{enabled:enabled,verification_method:verification_method,user_id:user_id}"
hcloud IAM ListUserLoginProtects --cli-region=cn-north-4 --cli-output=json
- Success:
enabled=true,verification_methodequals the selected method, and the user appears inListUserLoginProtects. - Judge by JSON content, not the process exit code. API business errors return exit code 0.
- If stdout contains a localized diagnostic table after the JSON, parse only the first JSON object/array, or use
--cli-query. - Error mapping:
IAM.0004: before the change = never configured (expected); after the change = failure.IAM.0002: user does not exist or no permission.- HTTP 404 with
error.{code,message,title}: user not found during update. IAM.0073: invalidverification_method.USE_ERROR: CLI-side missing parameter, invalid boolean, or unknown field.
- Do not retry blindly. A repeat of the same parameters is idempotent; a failure must be reported and the workflow stopped.
- If the change fails, do not touch other users.
Step 6: Business Verification Guidance, Rollback, and Summary
Read references/verification-method.md and present the business verification steps as manual/user-driven:
- Console login: the next console sign-in by the target IAM user requires a second factor in addition to the username and password; the method matches the configuration.
- Programmatic access: the target user's AK/SK access to cloud services through APIs/SDKs is unaffected.
- Existing sessions: console sessions established before the change are unaffected.
- Password-based token acquisition: with
console_vmfa/sms/email, the IAM user token can still be obtained with the password; withvmfa, it may fail and password+TOTP is required. - API login protection: configurable only in the console; this SKILL does not handle or verify it.
Do not claim the SKILL executed these checks. Record user-reported results truthfully.
Read references/rollback.md and present the rollback guidance:
hcloud IAM UpdateLoginProtect --cli-region=cn-north-4 --user_id=<USER_ID> \
--login_protect.enabled=false \
--login_protect.verification_method=<CURRENT_METHOD> \
--cli-output=json
- The response sets
enabled=falseandverification_method=none. - The user remains in
ListUserLoginProtectspermanently; the record cannot be deleted. - "Never configured" cannot be restored; the final state is "disabled".
- Disabling login protection reduces security; recommend re-enabling after troubleshooting.
- Verify the rollback with
ShowUserLoginProtectandListUserLoginProtects.
Finish with a summary table: step, status, user, method, result, residual, and the reference files used. Mention that the change is free, single-user, and non-batch.
KooCLI Command Format Standard
| Feature | Description | Example |
|---|---|---|
| Service name | IAM (as shown by hcloud IAM --help; metadata dir iam) |
hcloud IAM ListUsersV5 --cli-region=cn-north-4 |
| Operation name | PascalCase | ListUsersV5, ShowUser, UpdateLoginProtect |
| Region parameter | --cli-region=<value> |
--cli-region=cn-north-4 |
| Simple parameter | --key=value |
--user_id=xxx |
| Indexed / dotted body | --parent.child=value |
--login_protect.enabled=true, --login_protect.verification_method=sms |
Run
hcloud IAM <Operation> --helpbefore constructing a command to confirm exact parameter names. Operation and parameter behavior was verified against KooCLI 7.2.2.
References
- CLI Commands — hcloud IAM commands, parameters, fields, parsing, and error envelopes.
- Risks and Impact — Decision-card content: risks of inaction, what changes/does not change, cost, and decision-critical warnings.
- Verification Method — Result verification and manual business connectivity checks.
- Rollback — Rollback command, residual record, and limitations.
- IAM Authentication and Policies — Authentication methods, required IAM actions, system and least-privilege policies, and authorization errors.
- CLI Installation Guide — hcloud installation, AK/SK configuration, upgrade, and troubleshooting.
- Acceptance Criteria — Acceptance gate, test cases, and expected results.
