{{< details >}}

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: JihuLab.com, 私有化部署

{{< /details >}}

{{< history >}}

  • 引入于极狐GitLab 17.2,使用名为 container_registry_protected_containers功能标志。默认斤用。
  • 在极狐GitLab 17.8 中为 JihuLab.com 启用。
  • 在极狐GitLab 17.8 中 GA。功能标志 container_registry_protected_containers 被移除。

{{< /history >}}

列出容器仓库保护规则

从项目的容器注册表中获取容器仓库保护规则列表。

GET /api/v4/projects/:id/registry/protection/repository/rules

支持的属性:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径

如果成功,返回 200 和容器仓库保护规则列表。

可能返回以下状态码:

  • 200 OK: 保护规则列表。
  • 401 Unauthorized: 访问令牌无效。
  • 403 Forbidden: 用户没有权限列出此项目的保护规则。
  • 404 Not Found: 未找到项目。

请求示例:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules"

响应示例:

[
  {
    "id": 1,
    "project_id": 7,
    "repository_path_pattern": "flightjs/flight0",
    "minimum_access_level_for_push": "maintainer",
    "minimum_access_level_for_delete": "maintainer"
  },
  {
    "id": 2,
    "project_id": 7,
    "repository_path_pattern": "flightjs/flight1",
    "minimum_access_level_for_push": "maintainer",
    "minimum_access_level_for_delete": "maintainer"
  }
]

创建容器仓库保护规则

{{< history >}}

  • 引入于极狐GitLab 17.2。

{{< /history >}}

为项目的容器注册表创建容器仓库保护规则。

POST /api/v4/projects/:id/registry/protection/repository/rules

支持的属性:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
repository_path_pattern string 受保护规则保护的容器仓库路径模式。例如 flight/flight-*。允许使用通配符 *
minimum_access_level_for_push string 推送容器镜像到容器注册表所需的最低极狐GitLab 访问级别。例如 maintainer, owneradmin。当 minimum_access_level_for_delete 未设置时必须提供。
minimum_access_level_for_delete string 删除容器注册表中的容器镜像所需的最低极狐GitLab 访问级别。例如 maintainer, owner, admin。当 minimum_access_level_for_push 未设置时必须提供。

如果成功,返回 201 和已创建的容器仓库保护规则。

可能返回以下状态码:

  • 201 Created: 保护规则创建成功。
  • 400 Bad Request: 保护规则无效。
  • 401 Unauthorized: 访问令牌无效。
  • 403 Forbidden: 用户没有权限创建保护规则。
  • 404 Not Found: 未找到项目。
  • 422 Unprocessable Entity: 保护规则无法创建。例如,因为 repository_path_pattern 已被占用。

请求示例:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules" \
  --data '{
        "repository_path_pattern": "flightjs/flight-needs-to-be-a-unique-path",
        "minimum_access_level_for_push": "maintainer",
        "minimum_access_level_for_delete": "maintainer"
    }'

更新容器仓库保护规则

{{< history >}}

  • 引入于极狐GitLab 17.2。

{{< /history >}}

更新项目的容器注册表中的容器仓库保护规则。

PATCH /api/v4/projects/:id/registry/protection/repository/rules/:protection_rule_id

支持的属性:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
protection_rule_id integer 要更新的保护规则的 ID。
repository_path_pattern string 受保护规则保护的容器仓库路径模式。例如 flight/flight-*。允许使用通配符 *
minimum_access_level_for_push string 推送容器镜像到容器注册表所需的最低极狐GitLab 访问级别。例如 maintainer, owneradmin。当 minimum_access_level_for_delete 未设置时必须提供。要取消设置该值,请使用空字符串 ""
minimum_access_level_for_delete string 删除容器注册表中的容器镜像所需的最低极狐GitLab 访问级别。例如 maintainer, owner, admin。当 minimum_access_level_for_push 未设置时必须提供。要取消设置该值,请使用空字符串 ""

如果成功,返回 200 和更新后的保护规则。

可能返回以下状态码:

  • 200 OK: 保护规则更新成功。
  • 400 Bad Request: 保护规则无效。
  • 401 Unauthorized: 访问令牌无效。
  • 403 Forbidden: 用户没有权限更新保护规则。
  • 404 Not Found: 未找到项目。
  • 422 Unprocessable Entity: 保护规则无法更新。例如,因为 repository_path_pattern 已被占用。

请求示例:

curl --request PATCH \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules/32" \
  --data '{
       "repository_path_pattern": "flight/flight-*"
    }'

删除容器仓库保护规则

{{< history >}}

  • 引入于极狐GitLab 17.4。

{{< /history >}}

从项目的容器注册表中删除容器仓库保护规则。

DELETE /api/v4/projects/:id/registry/protection/repository/rules/:protection_rule_id

支持的属性:

属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
protection_rule_id integer 要删除的容器仓库保护规则的 ID。

如果成功,返回 204 No Content

可能返回以下状态码:

  • 204 No Content: 保护规则删除成功。
  • 400 Bad Request: idprotection_rule_id 缺失或无效。
  • 401 Unauthorized: 访问令牌无效。
  • 403 Forbidden: 用户没有权限删除保护规则。
  • 404 Not Found: 未找到项目或保护规则。

请求示例:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules/1"