代理 API

  • Tier: 基础版,专业版,旗舰版
  • Offering: JihuLab.com,私有化部署
History
    • 代理令牌 API 引入于极狐GitLab 15.0。

使用 Agents API 与极狐GitLab Kubernetes 代理进行交互。

列出项目的代理#

返回注册项目的代理列表。

您必须至少拥有开发者角色才能使用此端点。

plaintext
GET /projects/:id/cluster_agents

参数:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径

响应:

响应是具有以下字段的代理列表:

属性类型描述
id整数代理的 ID
name字符串代理的名称
config_project对象表示代理所属项目的对象
config_project.id整数项目的 ID
config_project.description字符串项目的描述
config_project.name字符串项目的名称
config_project.name_with_namespace字符串项目完整名称与命名空间
config_project.path字符串项目的路径
config_project.path_with_namespace字符串项目完整路径与命名空间
config_project.created_at字符串项目创建时的 ISO8601 日期时间
created_at字符串代理创建时的 ISO8601 日期时间
created_by_user_id整数创建代理的用户 ID

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents"

示例响应:

json
1[ 2 { 3 "id": 1, 4 "name": "agent-1", 5 "config_project": { 6 "id": 20, 7 "description": "", 8 "name": "test", 9 "name_with_namespace": "Administrator / test", 10 "path": "test", 11 "path_with_namespace": "root/test", 12 "created_at": "2022-03-20T20:42:40.221Z" 13 }, 14 "created_at": "2022-04-20T20:42:40.221Z", 15 "created_by_user_id": 42 16 }, 17 { 18 "id": 2, 19 "name": "agent-2", 20 "config_project": { 21 "id": 20, 22 "description": "", 23 "name": "test", 24 "name_with_namespace": "Administrator / test", 25 "path": "test", 26 "path_with_namespace": "root/test", 27 "created_at": "2022-03-20T20:42:40.221Z" 28 }, 29 "created_at": "2022-04-20T20:42:40.221Z", 30 "created_by_user_id": 42 31 } 32]

获取代理的详细信息#

获取单个代理的详细信息。

您必须至少拥有开发者角色才能使用此端点。

plaintext
GET /projects/:id/cluster_agents/:agent_id

参数:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID

响应:

响应是具有以下字段的单个代理:

属性类型描述
id整数代理的 ID
name字符串代理的名称
config_project对象表示代理所属项目的对象
config_project.id整数项目的 ID
config_project.description字符串项目的描述
config_project.name字符串项目的名称
config_project.name_with_namespace字符串项目完整名称与命名空间
config_project.path字符串项目的路径
config_project.path_with_namespace字符串项目完整路径与命名空间
config_project.created_at字符串项目创建时的 ISO8601 日期时间
created_at字符串代理创建时的 ISO8601 日期时间
created_by_user_id整数创建代理的用户 ID

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/1"

示例响应:

json
1{ 2 "id": 1, 3 "name": "agent-1", 4 "config_project": { 5 "id": 20, 6 "description": "", 7 "name": "test", 8 "name_with_namespace": "Administrator / test", 9 "path": "test", 10 "path_with_namespace": "root/test", 11 "created_at": "2022-03-20T20:42:40.221Z" 12 }, 13 "created_at": "2022-04-20T20:42:40.221Z", 14 "created_by_user_id": 42 15}

将代理注册到项目#

将代理注册到项目。

您必须至少拥有维护者角色才能使用此端点。

plaintext
POST /projects/:id/cluster_agents

参数:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
name字符串代理的名称

响应:

响应是具有以下字段的新代理:

属性类型描述
id整数代理的 ID
name字符串代理的名称
config_project对象表示代理所属项目的对象
config_project.id整数项目的 ID
config_project.description字符串项目的描述
config_project.name字符串项目的名称
config_project.name_with_namespace字符串项目完整名称与命名空间
config_project.path字符串项目的路径
config_project.path_with_namespace字符串项目完整路径与命名空间
config_project.created_at字符串项目创建时的 ISO8601 日期时间
created_at字符串代理创建时的 ISO8601 日期时间
created_by_user_id整数创建代理的用户 ID

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents" \ -H "Content-Type:application/json" \ -X POST --data '{"name":"some-agent"}'

示例响应:

json
1{ 2 "id": 1, 3 "name": "agent-1", 4 "config_project": { 5 "id": 20, 6 "description": "", 7 "name": "test", 8 "name_with_namespace": "Administrator / test", 9 "path": "test", 10 "path_with_namespace": "root/test", 11 "created_at": "2022-03-20T20:42:40.221Z" 12 }, 13 "created_at": "2022-04-20T20:42:40.221Z", 14 "created_by_user_id": 42 15}

删除注册的代理#

删除现有的代理注册。

您必须至少拥有维护者角色才能使用此端点。

plaintext
DELETE /projects/:id/cluster_agents/:agent_id

参数:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID

示例请求:

shell
curl --request DELETE --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/1

列出代理的令牌#

History
    • 引入于极狐GitLab 15.0。

返回代理的活动令牌列表。

您必须至少拥有开发者角色才能使用此端点。

plaintext
GET /projects/:id/cluster_agents/:agent_id/tokens

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数或字符串代理的 ID

响应:

响应是具有以下字段的令牌列表:

属性类型描述
id整数令牌的 ID
name字符串令牌的名称
description字符串或 null令牌的描述
agent_id整数令牌所属代理的 ID
status字符串令牌的状态。有效值为 activerevoked
created_at字符串令牌创建时的 ISO8601 日期时间
created_by_user_id字符串创建令牌的用户 ID

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/tokens"

示例响应:

json
1[ 2 { 3 "id": 1, 4 "name": "abcd", 5 "description": "Some token", 6 "agent_id": 5, 7 "status": "active", 8 "created_at": "2022-03-25T14:12:11.497Z", 9 "created_by_user_id": 1 10 }, 11 { 12 "id": 2, 13 "name": "foobar", 14 "description": null, 15 "agent_id": 5, 16 "status": "active", 17 "created_at": "2022-03-25T14:12:11.497Z", 18 "created_by_user_id": 1 19 } 20]
令牌的 `last_used_at` 字段仅在获取单个代理令牌时返回。

获取单个代理令牌#

History
    • 引入于极狐GitLab 15.0。

获取单个代理令牌。

您必须至少拥有开发者角色才能使用此端点。

如果代理令牌已被吊销,则返回 404

plaintext
GET /projects/:id/cluster_agents/:agent_id/tokens/:token_id

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
token_id整数令牌的 ID

响应:

响应是具有以下字段的单个令牌:

属性类型描述
id整数令牌的 ID
name字符串令牌的名称
description字符串或 null令牌的描述
agent_id整数令牌所属代理的 ID
status字符串令牌的状态。有效值为 activerevoked
created_at字符串令牌创建时的 ISO8601 日期时间
created_by_user_id字符串创建令牌的用户 ID
last_used_at字符串或 null令牌最后使用时的 ISO8601 日期时间

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/token/1"

示例响应:

json
1{ 2 "id": 1, 3 "name": "abcd", 4 "description": "Some token", 5 "agent_id": 5, 6 "status": "active", 7 "created_at": "2022-03-25T14:12:11.497Z", 8 "created_by_user_id": 1, 9 "last_used_at": null 10}

创建代理令牌#

History
    • 引入于极狐GitLab 15.0。
    • 双令牌限制引入于极狐GitLab 16.1,使用名为 cluster_agents_limit_tokens_created功能标志
    • 双令牌限制在极狐GitLab 16.2 GA。功能标志 cluster_agents_limit_tokens_created 被移除。

为代理创建新令牌。

您必须至少拥有维护者角色才能使用此端点。

代理一次只能有两个活动令牌。

plaintext
POST /projects/:id/cluster_agents/:agent_id/tokens

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
name字符串令牌的名称
description字符串令牌的描述

响应:

响应是具有以下字段的新令牌:

属性类型描述
id整数令牌的 ID
name字符串令牌的名称
description字符串或 null令牌的描述
agent_id整数令牌所属代理的 ID
status字符串令牌的状态。有效值为 activerevoked
created_at字符串令牌创建时的 ISO8601 日期时间
created_by_user_id字符串创建令牌的用户 ID
last_used_at字符串或 null令牌最后使用时的 ISO8601 日期时间
token字符串密钥令牌值
`token` 仅在 `POST` 端点响应中返回,之后无法检索。

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/tokens" \ -H "Content-Type:application/json" \ -X POST --data '{"name":"some-token"}'

示例响应:

json
1{ 2 "id": 1, 3 "name": "abcd", 4 "description": "Some token", 5 "agent_id": 5, 6 "status": "active", 7 "created_at": "2022-03-25T14:12:11.497Z", 8 "created_by_user_id": 1, 9 "last_used_at": null, 10 "token": "qeY8UVRisx9y3Loxo1scLxFuRxYcgeX3sxsdrpP_fR3Loq4xyg" 11}

吊销代理令牌#

History
    • 引入于极狐GitLab 15.0。

吊销代理令牌。

您必须至少拥有维护者角色才能使用此端点。

plaintext
DELETE /projects/:id/cluster_agents/:agent_id/tokens/:token_id

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
token_id整数令牌的 ID

示例请求:

shell
curl --request DELETE --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/tokens/1

接收代理#

  • Tier: 旗舰版
  • Offering: 极狐GitLab 私有化部署
History
    • 引入于极狐GitLab 17.4。

接收代理允许极狐GitLab与无法建立网络连接到极狐GitLab 实例但可以通过极狐GitLab连接的 Kubernetes 集群集成。

列出接收代理的 URL 配置#

返回代理的 URL 配置列表。

您必须至少拥有开发者角色才能使用此端点。

plaintext
GET /projects/:id/cluster_agents/:agent_id/url_configurations

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数或字符串代理的 ID

响应:

响应是具有以下字段的 URL 配置列表:

属性类型描述
id整数URL 配置的 ID
agent_id整数URL 配置所属代理的 ID
url字符串此 URL 配置的 URL
public_key字符串(可选)如果使用 JWT 认证,则为 Base64 编码的公钥
client_cert字符串(可选)如果使用 mTLS 认证,则为 PEM 格式的客户端证书
ca_cert字符串(可选)用于验证代理端点的 PEM 格式的 CA 证书
tls_host字符串(可选)用于验证代理端点服务器名称的 TLS 主机名

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/url_configurations"

示例响应:

json
1[ 2 { 3 "id": 1, 4 "agent_id": 5, 5 "url": "grpcs://agent.example.com:4242", 6 "public_key": "..." 7 } 8]
`public_key` 或 `client_cert` 设置,但从不同时设置。

获取单个代理 URL 配置#

获取单个代理 URL 配置。

您必须至少拥有开发者角色才能使用此端点。

plaintext
GET /projects/:id/cluster_agents/:agent_id/url_configurations/:url_configuration_id

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
url_configuration_id整数URL 配置的 ID

响应:

响应是具有以下字段的单个 URL 配置:

属性类型描述
id整数URL 配置的 ID
agent_id整数URL 配置所属代理的 ID
url字符串此 URL 配置的代理 URL
public_key字符串(可选)如果使用 JWT 认证,则为 Base64 编码的公钥
client_cert字符串(可选)如果使用 mTLS 认证,则为 PEM 格式的客户端证书
ca_cert字符串(可选)用于验证代理端点的 PEM 格式的 CA 证书
tls_host字符串(可选)用于验证代理端点服务器名称的 TLS 主机名

示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/url_configurations/1"

示例响应:

json
1{ 2"id": 1, 3"agent_id": 5, 4"url": "grpcs://agent.example.com:4242", 5"public_key": "..." 6}
`public_key` 或 `client_cert` 设置,但从不同时设置。

创建代理 URL 配置#

为代理创建新的 URL 配置。

您必须至少拥有维护者角色才能使用此端点。

代理一次只能有一个 URL 配置。

plaintext
POST /projects/:id/cluster_agents/:agent_id/url_configurations

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
url字符串此 URL 配置的代理 URL
client_cert字符串如果应使用 mTLS 认证,则为 PEM 格式的客户端证书。必须与 client_key 一起提供。
client_key字符串如果应使用 mTLS 认证,则为 PEM 格式的客户端密钥。必须与 client_cert 一起提供。
ca_cert字符串用于验证代理端点的 PEM 格式的 CA 证书
tls_host字符串用于验证代理端点服务器名称的 TLS 主机名

响应:

响应是具有以下字段的新 URL 配置:

属性类型描述
id整数URL 配置的 ID
agent_id整数URL 配置所属代理的 ID
url字符串此 URL 配置的代理 URL
public_key字符串(可选)如果使用 JWT 认证,则为 Base64 编码的公钥
client_cert字符串(可选)如果使用 mTLS 认证,则为 PEM 格式的客户端证书
ca_cert字符串(可选)用于验证代理端点的 PEM 格式的 CA 证书
tls_host字符串(可选)用于验证代理端点服务器名称的 TLS 主机名

使用 JWT 令牌创建 URL 配置的示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/url_configurations" \ -H "Content-Type:application/json" \ -X POST --data '{"url":"grpcs://agent.example.com:4242"}'

JWT 认证的示例响应:

json
1{ 2"id": 1, 3"agent_id": 5, 4"url": "grpcs://agent.example.com:4242", 5"public_key": "..." 6}

使用文件 client.pemclient-key.pem 中的客户端证书和密钥,通过 mTLS 创建 URL 配置的示例请求:

shell
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/url_configurations" \ -H "Content-Type:application/json" \ -X POST --data '{"url":"grpcs://agent.example.com:4242", "client_cert":"'"$(awk -v ORS='\\n' '1' client.pem)"'", "client_key": "'"$(awk -v ORS='\\n' '1' client-key.pem)"'"}'

mTLS 的示例响应:

json
1{ 2"id": 1, 3"agent_id": 5, 4"url": "grpcs://agent.example.com:4242", 5"client_cert": "..." 6}
如果未提供 `client_cert` 和 `client_key`,则会生成一对私钥-公钥,并使用 JWT 认证而不是 mTLS。

删除代理 URL 配置#

删除代理 URL 配置。

您必须至少拥有维护者角色才能使用此端点。

plaintext
DELETE /projects/:id/cluster_agents/:agent_id/url_configurations/:url_configuration_id

支持的属性:

属性类型必需的描述
id整数或字符串经过身份验证的用户维护的项目的 ID 或 URL 编码路径
agent_id整数代理的 ID
url_configuration_id整数URL 配置的 ID

示例请求:

shell
curl --request DELETE --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects/20/cluster_agents/5/url_configurations/1