Hub documentation

容器仓库访问控制

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

容器仓库访问控制

谁可以拉取和推送镜像取决于仓库的可见性以及每位成员在组织中的角色:任何人都可以从公共仓库拉取,私有仓库仅限成员拉取,而推送则需要 write 角色。令牌遵循相同的规则:具有 read 权限的 User Access Token 用于拉取,具有 write 权限的用于推送。CI 任务还可以通过在仓库上配置的 trusted publisher 在无需存储令牌的情况下进行推送。

使用资源组进行访问控制

在采用 Team 或 Enterprise 套餐的组织中,容器仓库可以归属于某个 资源组。此时,成员在该组中的角色将取代其组织角色,用于该仓库的权限控制:read 用于拉取,write 用于推送。资源组中的私有仓库仅允许该组的成员和组织管理员进行拉取。

创建仓库时选择组,或在仓库的设置中,或从组的 Resources 选项卡中进行选择。使用 API 时,在创建仓库时传入 resourceGroupId,或移动现有仓库(组的 ID 位于其页面 URL 的末尾,GET /api/organizations/my-org/resource-groups 可列出所有组):

curl -X POST https://huggingface.co/api/containers/my-org/my-app/resource-group \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"resourceGroupId": "<resource-group-id>"}'

使用 hf CLI,可以将仓库分配给某个组,或将其从组中移除:

hf resource-groups assign <resource-group-id> my-org/my-app --type container
hf resource-groups unassign my-org/my-app --type container

hf resource-groups ls --org my-org 会列出各个组及其 ID。

Update on GitHub