您可以改用Google Secret Manager。我们仍在更新文档,但有一个示例说明如何将其与 Cloud Build 结合使用:
首先,创建一个秘密:
$ echo -n "my-secret-data" | gcloud beta secrets create "my-api-key" \
--replication-policy "automatic" \
--data-file -
授予 Cloud Build Service Account 访问您的密钥的权限:
$ gcloud beta secrets add-iam-policy-binding "my-api-key" \
--member "serviceAccount:<project-number>@cloudbuild.gserviceaccount.com" \
--role "roles/secretmanager.secretAccessor"
更新(2021 年 2 月)
然后在构建步骤中检索秘密:
steps:
- name: 'my-step'
args:
- '--secret=$$MY_SECRET'
secretEnv:
- 'MY_SECRET'
availableSecrets:
secretManager:
- env: 'MY_SECRET'
versionName: 'projects/my-project/secrets/my-secret/versions/latest'
旧答案(2021 年 2 月之前)
然后在构建步骤中检索秘密:
steps:
- name: 'gcr.io/cloud-builders/gcloud@sha256:c1dfa4702cae9416b28c45c9dcb7d48102043578d80bfdca57488f6179c2211b'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud beta secrets versions access --secret=my-api-key latest > /secrets/my-api-key
volumes:
- name: 'secrets'
path: '/secrets'
- name: 'my-step'
volumes:
- name: 'secrets'
path: '/secrets'
args: # ... /secrets/my-api-key contains the secret