[英]Error when Deploying a Google Cloud function (Node JS) using a cloudbuild.yaml
[英]How to pass multiple environment variables as secrets using Google Cloud Build with KMS in cloudbuild.yaml?
我应该如何编辑我的 cloudbuild.yaml 文件,以便我可以将多个环境变量作为机密传递?
我已将两个身份验证令牌存储在本地计算机当前工作目录中的两个单独文件 SECRET1.txt 和 SECRET2.txt 中。
我想使用 KMS 将这两个身份验证令牌作为机密传递给 Google Cloud Build。
cloudbuild.yaml 文件应该是什么样子的,以便 Cloud Build 可以安全地访问我的令牌?
我尝试使用此处找到的加密机密https://cloud.google.com/cloud-build/docs/securing-builds/use-encrypted-secrets-credentials
这是我为 cloudbuild.yaml 尝试的内容:
steps:
- name: "gcr.io/cloud-builders/gcloud"
secretEnv: ['SECRET1', 'SECRET2']
timeout: "1600s"
secrets:
- kmsKeyName: projects/<Project-Name>/locations/global/keyRings/<Key-Ring-Name>/cryptoKeys/<Key-Name>
secretEnv:
SECRET1: <encrypted-key-base64 here>
SECRET2: <encrypted-key-base64 here>
我收到此错误消息:错误
Cloud Build 能够读取令牌(我在此处使用红色墨水将其删除Error ),但它会输出一条错误消息,指出“错误:ENOENT:没有这样的文件或目录”。
谁能告诉我我的方法出了什么问题以及为什么 Cloud Build 无法访问这些身份验证令牌(秘密)?
如果您正在解密一个值以用作构建步骤的环境变量,您可以按照您的描述使用以下设置。
steps:
- name: "gcr.io/cloud-builders/gcloud"
secretEnv: ['SECRET1', 'SECRET2', ...]
timeout: "1600s"
secrets:
- kmsKeyName: projects/[Project-Name]/locations/global/keyRings/[Key-Ring-Name]/cryptoKeys/[Key-Name]
secretEnv:
SECRET1: [encrypted-base64-encoded-secret]
SECRET2: [encrypted-base64-encoded-secret]
但是,如果您要解密文件,则需要在使用它们之前的构建步骤中解密它们,如下所示:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args:
- kms
- decrypt
- --ciphertext-file=SECRET1.txt.enc
- --plaintext-file=SECRET1.txt
- --project=$PROJECT_ID
- --location=global
- --keyring=[KEYRING-NAME]
- --key=[KEY-NAME]
- name: "gcr.io/cloud-builders/gcloud"
args:
- kms
- decrypt
- --ciphertext-file=SECRET2.txt.enc
- --plaintext-file=SECRET2.txt
- --project=$PROJECT_ID
- --location=global
- --keyring=[KEYRING-NAME]
- --key=[KEY-NAME]
- name: "gcr.io/cloud-builders/gcloud"
args:
- [something that uses SECRET1.txt and SECRET2.txt]
timeout: "1600s"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.