【问题标题】:How to pass multiple environment variables as secrets using Google Cloud Build with KMS in cloudbuild.yaml?如何在 cloudbuild.yaml 中使用带有 KMS 的 Google Cloud Build 将多个环境变量作为机密传递?
【发布时间】:2019-11-20 08:04:51
【问题描述】:

我应该如何编辑我的 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>

我收到此错误消息: Error

Cloud Build 能够读取令牌(我在此处使用 RED 墨水将其删除 Error),但它会输出一条错误消息,指出“错误:ENOENT:没有这样的文件或目录”。

谁能告诉我我的方法出了什么问题以及为什么 Cloud Build 无法访问这些身份验证令牌(秘密)?

【问题讨论】:

  • 发布问题时包括结果和错误消息。

标签: node.js google-app-engine google-cloud-platform google-cloud-build


【解决方案1】:

如果您要解密一个值以用作构建步骤的 env var,则可以按照您的描述使用以下设置。

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"

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 2021-02-13
    • 2019-01-05
    • 2022-10-02
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 2019-12-04
    • 2019-11-18
    相关资源
    最近更新 更多