Files
docs/i18n/zh-cn/docs/current/usage/actions/openid-connect.md
T
2af7b60fd9 docs(actions): document OIDC workload identity (#526)
Document the OpenID Connect tokens that Gitea Actions jobs can request since https://github.com/go-gitea/gitea/pull/39052, so they can sign in to cloud providers without long-lived secrets.

- Add an OpenID Connect page covering how to trust Gitea, request a token and match its claims
- Document the `id-token` permission scope and its maximum
- Translate both for zh-cn and zh-tw, which still listed `id-token` as unsupported

Co-authored-by: silverwind <[email protected]>
Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/docs/pulls/526
Reviewed-by: silverwind <[email protected]>
Co-authored-by: Max P. <[email protected]>
2026-10-18 07:12:16 +00:00

2.4 KiB
Raw Blame History

date, slug, sidebar_position
date slug sidebar_position
2026-08-23T00:00:00+00:00 openid-connect 40

OpenID Connect

Job可以请求短期有效的OpenID Connect(OIDC)令牌来登录云服务商和其他服务,无需存储长期有效的密钥。这些令牌采用GitHub Actions的格式,因此aws-actions/configure-aws-credentials、google-github-actions/auth和azure/login等Action无需修改即可使用。

信任Gitea

在服务中将Gitea添加为OIDC身份提供方:

  • Issuer:<ROOT_URL>/api/actions/oidc
  • Audience:<ROOT_URL>/<owner>,除非工作流请求了其他值

然后通过sub声明上的条件限制哪些工作流可以登录。

Gitea使用其在<APP_DATA_PATH>/jwt/actions_oidc.pem创建的密钥签名令牌。负载均衡器后的多个实例必须共享此文件。

请求令牌

为工作流或Job授予id-token权限:

permissions:
  id-token: write

默认权限从不包含此权限,来自fork拉取请求的Job也永远无法获得。所有者和仓库可以通过最大令牌权限禁用它。

上述Action会自行请求令牌。在脚本中,请使用ACTIONS_ID_TOKEN_REQUEST_URL和ACTIONS_ID_TOKEN_REQUEST_TOKEN:

curl --fail --silent --show-error \
  --header "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
  "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=my-service"

令牌位于响应的value字段中,五分钟后过期。

声明

sub声明包含所有者和仓库的名称及ID,因此重命名或重新创建的仓库无法匹配已有的信任策略:

repo:<owner>@<owner-id>/<repo>@<repo-id>:ref:<ref>
repo:<owner>@<owner-id>/<repo>@<repo-id>:pull_request

pull_request事件使用第二种格式,其他所有事件(包括pull_request_target)使用第一种。

其他声明与GitHub相同,例如repository、ref、sha、workflow_ref和job_workflow_ref。位于<ROOT_URL>/api/actions/oidc/.well-known/openid-configuration的发现文档列出了所有声明。

与GitHub Actions的区别:

  • 没有environment声明。
  • 拉取请求的运行使用refs/pull/<index>/head及其提交,而不是合并引用和合并提交。
  • run_number按仓库计数,而不是按工作流计数。