设计与多媒体

Huawei Cloud Swr Image Governance

试用

通过 hcloud CLI 管理华为云 SWR 镜像权限、保留规则、共享下载域名与委托关系。

它能做什么

基于 hcloud CLI 提供华为云 SWR 镜像治理能力,覆盖命名空间与仓库级别的权限授予、查询、修改、撤销,以及使用 tag_rule 或 date_rule 模板创建、查询、修改、删除镜像保留规则。同时支持跨组织的共享下载域名管理、共享仓库列表与特性开关查询,以及 SWR 委托关系的检查与创建。命令因权限不足失败时,会列出对应 API 所需的 IAM 操作与策略 JSON,引导用户在 IAM 控制台完成授权后继续。

什么时候用它

  • 为用户授予、修改或撤销命名空间与仓库的读写权限
  • 配置保留规则,保留最新 N 个 tag 或最近 N 天的镜像版本
  • 为仓库创建或更新共享下载域名,供跨组织拉取镜像
  • 检查并创建 SWR 委托,用于对接 OBS、CCE 等其他云服务

技能文档

Huawei Cloud SWR Image Governance

Overview

This skill provides governance capabilities for Huawei Cloud SWR (Software Repository for Container) using the hcloud CLI, covering permissions, retention policies, sharing, and agency delegation.

Architecture: hcloud CLI → SWR Service API → Permission/Retention/Domain/Share/Agency resources

Related Skills:

  • huawei-cloud-swr-image-management - Image lifecycle management (namespace, repo, tag, auth, quota)
  • huawei-cloud-swr-image-automation - Image automation ops (sync, triggers, domains)
  • huawei-cloud-swr-enterprise-instance - Enterprise instance management

Capabilities:

  • Grant, query, modify, and revoke namespace-level permissions
  • Grant, query, modify, and revoke repository-level permissions
  • Create and manage image retention rules for automated cleanup
  • Create and manage shared download domains for cross-organization access
  • List shared repositories and check sharing feature gates
  • Check and create agency delegation for SWR operations
  • List repository accessories and references

Typical Use Cases:

  • "Grant edit permission on namespace 'group-dev' to user 'dev-team'"
  • "List all users with access to namespace 'group-dev'"
  • "Set up a retention rule to keep only the last 10 tags in repository 'nginx'"
  • "Create a shared download domain for repository 'my-app'"
  • "List all shared repositories"
  • "Check if image sharing feature is enabled"
  • "Check agency delegation status for SWR"
  • "Revoke a user's permission on a repository"

Prerequisites

1. hcloud CLI Requirements (MANDATORY)

  • hcloud CLI installed (version >= 7.2.2)
  • Run hcloud version to verify installation
  • First-time usage: printf "y\n" | hcloud version to accept privacy statement

2. Credential Configuration

  • Valid Huawei Cloud credentials (AK/SK mode)
  • Security Rules:
    • 🚫 Never expose AK/SK values in code, conversation, or commands
    • 🚫 Never use echo $HUAWEI_CLOUD_AK or echo $HUAWEI_CLOUD_SK to check credentials
    • ✅ Use environment variables: HUAWEI_CLOUD_AK, HUAWEI_CLOUD_SK, HUAWEI_CLOUD_REGION
    • ✅ Prefer IAM users over root account for cloud operations
    • ✅ Enable MFA for sensitive operations

Configuration Method (Environment Variables Only):

export HUAWEI_CLOUD_AK=
export HUAWEI_CLOUD_SK=
export HUAWEI_CLOUD_REGION=cn-north-4

⚠️ Important Security Notes:

  • Never commit credentials to version control
  • Use IAM users with minimal required permissions
  • Enable MFA for sensitive operations
  • Rotate AK/SK regularly

3. IAM Permission Requirements

API ActionPermissionPurpose
swr:namespace:auth:createCreate NS authGrant namespace permissions
swr:namespace:auth:getGet NS authQuery namespace permissions
swr:namespace:auth:updateUpdate NS authModify namespace permissions
swr:namespace:auth:deleteDelete NS authRevoke namespace permissions
swr:repository:auth:createCreate repo authGrant repository permissions
swr:repository:auth:getGet repo authQuery repository permissions
swr:repository:auth:updateUpdate repo authModify repository permissions
swr:repository:auth:deleteDelete repo authRevoke repository permissions
swr:retention:createCreate retentionCreate retention rules
swr:retention:listList retentionList retention rules
swr:retention:getGet retentionView retention rule details
swr:retention:updateUpdate retentionModify retention rules
swr:retention:deleteDelete retentionRemove retention rules
swr:domain:createCreate domainCreate shared download domains
swr:domain:listList domainsList shared download domains
swr:domain:getGet domainView domain details
swr:domain:updateUpdate domainModify domain settings
swr:domain:deleteDelete domainRemove shared download domains
swr:share:listList shared reposList shared repositories
swr:share:getGet shared repoView shared repository details
swr:share:feature:getGet share featureCheck sharing feature gates
swr:global:feature:getGet global featureCheck global feature gates
swr:agency:checkCheck agencyCheck agency delegation status
swr:agency:createCreate agencyCreate agency delegation
swr:accessory:listList accessoriesList repository accessories
swr:reference:listList referencesList repository references

See IAM Permission Policies for complete policy JSON.

Permission Failure Handling:

  1. When any command fails due to permission errors, read references/iam-policies.md
  2. Display the required permission list and policy JSON to the user
  3. Guide the user to create a custom policy in the IAM console and grant authorization
  4. Pause execution and wait for user confirmation that permissions have been granted

Core Commands

1. Namespace Permissions

See Task: Namespace Permissions for detailed workflows.

# Show namespace permissions (who has access and their auth levels)
hcloud SWR ShowNamespaceAuth --namespace=pancake --cli-region=cn-north-4

# Grant namespace permission to a user
hcloud SWR CreateNamespaceAuth --namespace=pancake --1.auth=7 --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

# Update namespace permission for a user
hcloud SWR UpdateNamespaceAuth --namespace=pancake --1.auth=3 --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

# Revoke namespace permission for a user
hcloud SWR DeleteNamespaceAuth --namespace=pancake --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

Auth Values: 7 = manage (full control), 3 = edit (push/pull), 1 = read (pull only)

⚠️ Array-Style Parameters: Permission operations use --[N].auth, --[N].user_id, --[N].user_name format where [N] is the array index (starting from 1). For a single user, use --1.auth=7 --1.user_id=xxx --1.user_name=xxx. See Common Pitfalls for details.

2. Repository Permissions

See Task: Repository Permissions for detailed workflows.

# Show repository permissions
hcloud SWR ShowUserRepositoryAuth --namespace=pancake --repository=openclaw-sandbox --cli-region=cn-north-4

# Grant repository permission to a user
hcloud SWR CreateUserRepositoryAuth --namespace=pancake --repository=openclaw-sandbox --1.auth=7 --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

# Update repository permission for a user
hcloud SWR UpdateUserRepositoryAuth --namespace=pancake --repository=openclaw-sandbox --1.auth=3 --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

# Revoke repository permission for a user
hcloud SWR DeleteUserRepositoryAuth --namespace=pancake --repository=openclaw-sandbox --1.user_id=05949eb5350010e21f85c017722182de --1.user_name=hwstaff_p00506267 --cli-region=cn-north-4

Auth Values: Same as namespace permissions: 7 = manage, 3 = edit, 1 = read

3. Agency Delegation

# Check if agency delegation is enabled
hcloud SWR CheckAgency --cli-region=cn-north-4

# Create agency delegation for SWR
hcloud SWR CreateAgency --cli-region=cn-north-4

Use Cases:

  • Agency delegation allows SWR to access other services (OBS, CCE) on your behalf
  • Required for features like image sync to OBS and CCE trigger deployments
  • CheckAgency returns whether agency is already configured; CreateAgency sets up the delegation

4. Retention Rules

See Task: Retention Management for detailed workflows.

# List retention rules for a repository
hcloud SWR ListRetentions --namespace=pancake --repository=openclaw-sandbox --cli-region=cn-north-4

# Create a retention rule (keep last 10 tags)
hcloud SWR CreateRetention --namespace=pancake --repository=openclaw-sandbox --algorithm=or --rules.1.template=tag_rule --rules.1.params.num=10 --rules.1.tag_selectors.1.kind=label --rules.1.tag_selectors.1.pattern=latest --cli-region=cn-north-4

# Create a retention rule (keep tags from last 30 days)
hcloud SWR CreateRetention --namespace=pancake --repository=openclaw-sandbox --algorithm=or --rules.1.template=date_rule --rules.1.params.days=30 --rules.1.tag_selectors.1.kind=label --rules.1.tag_selectors.1.pattern=latest --cli-region=cn-north-4

# Show retention rule details
hcloud SWR ShowRetention --namespace=pancake --repository=openclaw-sandbox --retention_id= --cli-region=cn-north-4

# Update a retention rule
hcloud SWR UpdateRetention --namespace=pancake --repository=openclaw-sandbox --retention_id= --algorithm=or --rules.1.template=tag_rule --rules.1.params.num=5 --rules.1.tag_selectors.1.kind=label --rules.1.tag_selectors.1.pattern=latest --cli-region=cn-north-4

# Delete a retention rule
hcloud SWR DeleteRetention --namespace=pancake --repository=openclaw-sandbox --retention_id= --cli-region=cn-north-4

# List retention execution histories
hcloud SWR ListRetentionHistories --namespace=pancake --repository=openclaw-sandbox --retention_id= --cli-region=cn-north-4

Retention Rule Templates:

  • tag_rule: Keep a specified number of the most recent tags (params.num)
  • date_rule: Keep tags created within a specified number of days (params.days)

Tag Selector Kinds:

  • label: Exact tag name match (e.g., latest, v1.0)
  • regexp: Regex pattern match (e.g., v\d+\.\d+\.\d+)

Algorithm: or means rules are combined with OR logic (a tag is retained if it matches ANY rule)

5. Shared Download Domains

See Task: Shared Domains for detailed workflows.

# List shared download domains for a repository
hcloud SWR ListRepoDomains --namespace=pancake --repository=openclaw-sandbox --cli-region=cn-north-4

# Create a shared download domain
hcloud SWR CreateRepoDomains --namespace=pancake --repository=openclaw-sandbox --domain=shared-domain-name --cli-region=cn-north-4

# Show shared domain details
hcloud SWR ShowAccessDomain --namespace=pancake --repository=openclaw-sandbox --access_domain=shared-domain-name --cli-region=cn-north-4

# Update a shared download domain
hcloud SWR UpdateRepoDomains --namespace=pancake --repository=openclaw-sandbox --domain=shared-domain-name --permit=read --cli-region=cn-north-4

# Delete a shared download domain
hcloud SWR DeleteRepoDomains --namespace=pancake --repository=openclaw-sandbox --access_domain=shared-domain-name --cli-region=cn-north-4

6. Image Sharing

See Task: Image Sharing for detailed workflows.

# List all shared repositories
hcloud SWR ListSharedReposDetails --cli-region=cn-north-4

# List shared repository details
hcloud SWR ListSharedRepoDetails --cli-region=cn-north-4

# Check sharing feature gates
hcloud SWR ShowShareFeatureGates --cli-region=cn-north-4

# Check global feature gates
hcloud SWR ListGlobalFeatureGates --cli-region=cn-north-4

7. Repository Accessories & References

# List repository accessories
hcloud SWR ListRepoAccessories --namespace=pancake --repository=openclaw-sandbox --cli-region=cn-north-4

# List repository references
hcloud SWR ListReferences --namespace=pancake --repository=openclaw-sandbox --cli-region=cn-north-4

Parameter Reference

Common Parameters

ParameterRequired/OptionalDescriptionDefault
--cli-regionRequiredHuawei Cloud region IDConfig value or HUAWEI_CLOUD_REGION
--namespaceContext-dependentSWR namespace (organization)N/A
--repositoryContext-dependentImage repository nameN/A

Permission Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesNamespace nameMust exist
--repositoryYesRepository name (repo-level only)Must exist
--[N].authYesPermission level7=manage, 3=edit, 1=read
--[N].user_idYesIAM user IDHex string (e.g., 05949eb5350010e21f85c017722182de)
--[N].user_nameYesIAM user nameIAM user display name

⚠️ Array Index Format: [N] starts from 1 (not 0). For granting permission to a single user, use --1.auth=7 --1.user_id=xxx --1.user_name=xxx. For multiple users, use --1.auth=7 --1.user_id=xxx --1.user_name=xxx --2.auth=3 --2.user_id=yyy --2.user_name=yyy.

Retention Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesNamespace nameMust exist
--repositoryYesRepository nameMust exist
--retention_idYesRetention rule ID (for show/update/delete)Numeric ID
--algorithmYesRule combination logicFixed value or
--rules.[N].templateYesRule template typedate_rule or tag_rule
--rules.[N].paramsYesRule parametersdays for date_rule, num for tag_rule
--rules.[N].tag_selectors.[N].kindYesSelector kindlabel or regexp
--rules.[N].tag_selectors.[N].patternYesSelector patternTag name or regex

Domain Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesNamespace nameMust exist
--repositoryYesRepository nameMust exist
--domainYes (create)Shared domain nameDomain identifier
--access_domainYes (show/delete)Domain nameSame as domain
--permitYes (update)Permission typeread

Output Format

See Output Format for detailed response format examples (NamespaceAuth, RepositoryAuth, RepoDomains, CheckAgency, ShareFeatureGates, GlobalFeatureGates, Retentions, RepoAccessories, ListSharedReposDetails).

Key Format Notes:

  • auth: Permission value (7=manage, 3=edit, 1=read)
  • self_auth vs others_auths: Check both when auditing permissions
  • ListRepoDomains: Uses created/updated (NOT created_at/updated_at)
  • ListRetentions: Returns flat array (empty [] when no rules)
  • ListRepoAccessories: Uses total + accessories (null when empty)

Verification

See Verification Method for step-by-step verification.

Best Practices

  1. Least Privilege: Grant the minimum auth level needed — 1 (read) for pull-only, 3 (edit) for push/pull, 7 (manage) for full control
  2. Namespace vs Repository Permissions: Namespace permissions apply to ALL repositories under it; repository permissions are granular per-repo
  3. Retention Rules: Use tag_rule (keep N most recent) for most cases; date_rule (keep tags within N days) for time-based cleanup
  4. Retention Tag Selectors: Use label kind with latest pattern to protect important tags from retention cleanup
  5. Shared Domains: Use deadline=forever for stable internal sharing; set specific deadlines for temporary cross-team access
  6. Agency Delegation: Check agency status before configuring image sync or CCE triggers — these require agency to be enabled
  7. Audit Permissions Regularly: Use ShowNamespaceAuth and ShowUserRepositoryAuth to periodically review who has access

Reference Documents

DocumentDescription
SWR Governance API Guidehcloud SWR governance API reference
Output FormatResponse format examples (verified)
IAM Permission PoliciesRequired permissions and policy JSON
Verification MethodStep-by-step verification
Common PitfallsTroubleshooting guides
Task: Namespace PermissionsNamespace permission workflows
Task: Repository PermissionsRepository permission workflows
Task: Retention ManagementRetention rule workflows
Task: Shared DomainsShared domain workflows
Task: Image SharingImage sharing workflows

Notes

  • Permission changes are immediate — no delay between granting and availability
  • Revoke with caution — removing manage auth (7) prevents the user from administering the namespace/repository
  • Retention rules execute automatically — tags matching the rule conditions will be deleted during execution
  • AK/SK must never be hardcoded — credentials should only be obtained via environment variables
  • hcloud CLI is the only supported method — all operations use hcloud SWR format
  • ListRepoDomains timestamps use created/updated — NOT created_at/updated_at

Common Pitfalls

See Common Pitfalls & Solutions for detailed troubleshooting guides.

Quick Reference:

PitfallSymptomQuick Fix
Array-style paramsPermission grant failsUse --1.auth=7 --1.user_id=xxx (index from 1, not 0)
Auth value wrongUser has unexpected access7=manage, 3=edit, 1=read (not 1/2/3)
self_auth vs others_authsMissing user in auditCheck both self_auth and others_auths
Domain timestamp fieldsParsing created_at failsUse created/updated (not created_at)
Retention rule formatCreateRetention failsNested array params: --rules.1.tag_selectors.1.kind
Agency not configuredImage sync/CCE trigger failsRun CheckAgency then CreateAgency

常见问题

对 hcloud CLI 版本有什么要求?
要求 7.2.2 及以上版本。首次使用需执行 `printf "y\n" | hcloud version` 接受隐私声明。
凭证应当如何配置?
只能通过环境变量 HUAWEI_CLOUD_AK、HUAWEI_CLOUD_SK、HUAWEI_CLOUD_REGION 配置,严禁在命令或对话中直接 echo 这些变量值,也不得提交到版本控制;推荐使用 IAM 用户而非根账号,并开启 MFA。
遇到权限不足错误时如何处理?
技能会读取 references/iam-policies.md,展示失败接口所需的 IAM 操作和策略 JSON,然后暂停执行,等待用户在 IAM 控制台创建自定义策略并完成授权。

相关技能

通过 hcloud CLI 管理华为云 SWR 命名空间、镜像仓库、版本标签、登录凭证与配额。

作者 shijingcheng3 次安装1 星标

Query the list of Huawei Cloud SWR (Software Repository for Container) image repositories under the current project/region. Lists all image repositories with their name, namespace, category, visibility (public/private), image/tag count, size, download count, full image path, tags and timestamps. Supports optional filtering by namespace, repository name (fuzzy match), category, and pagination (limit/offset) with sorting for account-wide repository inventory. Use when the user wants to: (1) list all Huawei Cloud SWR image repositories / 查询华为云SWR镜像仓库列表, (2) check how many image repositories exist in the account or region, (3) inspect repository visibility, size, tag count, or path for daily inspection or troubleshooting, (4) filter repositories by namespace, name, or category, (5) page through or sort repository results. Triggers include: "SWR列表", "华为云SWR列表", "查询SWR列表", "SWR镜像仓库列表", "容器镜像仓库列表", "SWR repository list", "list SWR repos", "ListReposDetails", "SWR仓库查询", "查看SWR仓库", "镜像仓库列表"

1 次安装

在华为云 SWR 上配置跨区域镜像同步和触发器,让镜像推送自动变成 CCE/CCI 部署更新。

作者 shijingcheng3 次安装1 星标

Query the list of Huawei Cloud SWR (Software Repository for Container) namespaces (organizations) under the current project/region. Lists all namespaces with their ID, name, creator, auth level, access user count and repository count. Supports optional filtering by namespace name. This is the top-level resource listing for SWR — namespaces organize image repositories into groups. Use when the user wants to: (1) list all Huawei Cloud SWR namespaces / 查询华为云SWR组织列表, (2) check how many SWR organizations exist in the account or region, (3) inspect namespace auth level, repository count, or creator for daily inspection or troubleshooting, (4) filter namespaces by name. Triggers include: "SWR组织列表", "华为云SWR组织列表", "查询SWR组织", "SWR namespace list", "list SWR namespaces", "ListNamespaces", "SWR命名空间列表", "查看SWR组织", "SWR名称列表"

1 次安装

Huawei Cloud SWR enterprise instance lifecycle management via hcloud CLI. Trigger: "SWR enterprise instance", "SWR 企业实例", "SWR 企业版", "企业仓库实例", "swr.ee", "实例管理

作者 shijingcheng3 次安装1 星标

Provides guidance for Huawei Cloud KooCLI command-line tool operations. Covers KooCLI installation, IAM authentication configuration, access credential confi...

作者 huaweicloud-skills-team1 次安装

shijingcheng 的更多技能

浏览全部技能

通过 Python SDK 管理华为云 CCE 集群、节点池、节点和插件的全生命周期,危险操作需 confirm=true。

作者 shijingcheng4 次安装1 星标

查询华为云 CCE 集群 Pod/Node 指标及 ECS、ELB、EIP、NAT 资源指标,支持基于阈值的异常检测。

作者 shijingcheng4 次安装1 星标

在华为云 SWR 上配置跨区域镜像同步和触发器,让镜像推送自动变成 CCE/CCI 部署更新。

作者 shijingcheng3 次安装1 星标

通过 hcloud CLI 管理华为云 SWR 命名空间、镜像仓库、版本标签、登录凭证与配额。

作者 shijingcheng3 次安装1 星标

通过 hcloud CLI 全生命周期管理华为云 CCI 容器实例:命名空间、网络、工作负载、日志查询,并内置安全确认机制。

作者 shijingcheng3 次安装1 星标