di/id
GitHub: di/id
一款跨平台 OIDC 凭证自动发现工具,简化 CI/CD 和云环境中的身份获取流程。
Stars: 14 | Forks: 7
# id

[](https://pypi.org/project/id)
[](https://api.securityscorecards.dev/projects/github.com/di/id)
[](https://slsa.dev/)
`id` 是一个用于生成 OIDC 身份的 Python 工具。它可以自动检测并在多种环境中生成 OIDC 凭证,包括 GitHub Actions、GitLab 流水线和 Google Cloud。
## 安装说明
`id` 需要 Python 3.8 或更新版本,并且可以通过 `pip` 直接安装:
```
python -m pip install id
```
## 使用方法
你可以通过 `python -m` 将 `id` 作为 Python 模块运行:
```
python -m id --help
```
顶层命令:
```
usage: id [-h] [-V] [-v] [-d] audience
a tool for generating OIDC identities
positional arguments:
audience the OIDC audience to use
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v, --verbose run with additional debug logging; supply multiple times to
increase verbosity (default: 0)
-d, --decode decode the OIDC token into JSON (default: False)
```
对于 Python API 的使用,提供了一个可导入的函数 `detect_credential`:
```
>>> from id import detect_credential
>>> detect_credential(audience='something')
''
```
此函数需要一个 `audience` 参数,用于生成 OIDC token。该参数应设置为 token 的预期受众。
如果未找到支持的环境,`detect_credential` 返回 `None`。如果找到了支持的环境但 `detect_credential` 检索 token 失败,则会抛出 `AmbientCredentialError`。
## 支持的环境
`id` 目前支持在以下环境中进行环境凭证检测:
* [GitHub Actions](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
* Google Cloud
* [Cloud Run](https://cloud.google.com/run/docs/securing/service-identity)
* [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity)
* [Compute Engine](https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances)
* 以及更多
* [Buildkite](https://buildkite.com/docs/agent/v3/cli-oidc)
* [GitLab](https://docs.gitlab.com/ee/ci/secrets/id_token_authentication.html) (参见下文的 _环境变量_)
* [CircleCI](https://circleci.com/docs/oidc-tokens-with-custom-claims/)
### 环境变量中的 Tokens
GitLab 通过环境变量提供 OIDC token。变量名必须是 `_ID_TOKEN`,其中 `` 是大写的 audience 参数,且所有非 ASCII 字母和数字的字符都必须替换为 "_"。开头的数字也必须替换为 "_"。
## 许可证
`id` 根据 Apache 2.0 许可证授权。
## 贡献指南
详情请参阅[贡献文档](https://github.com/di/id/blob/main/CONTRIBUTING.md)。
### SLSA Provenance
此项目在其发布版本中包含 SLSA provenance!这使您能够验证下载构件的完整性,并确保二进制文件的代码确实来自此源代码。
为此,请按照[此处](https://github.com/slsa-framework/slsa-github-generator#verify-provenance)的说明进行操作。
标签:GitHub Actions, GitLab CI, Google Cloud, JWT, OIDC, OpenID Connect, Python, SOC Prime, SSO, 令牌, 单点登录, 开发工具, 无后门, 自动笔记, 身份生成, 逆向工具