【问题标题】:Google Cloud Build and App Engine enviroment variablesGoogle Cloud Build 和 App Engine 环境变量
【发布时间】:2021-04-14 03:45:10
【问题描述】:

我的 App Engine 上有一个秘密令牌 app.yaml

env_variables:
  TOKEN: super-secret-token

显然,这个令牌已经不在 git 中了。使用 Google Cloud Build,如何在构建时或之前设置此参数TOKEN

【问题讨论】:

    标签: google-app-engine google-cloud-platform google-cloud-build


    【解决方案1】:

    在将应用部署到 App Engine 之前,您可以使用 Secret Manager within Cloud Build 获取实际密钥并替换 app.yaml 中的 super-secret-token 占位符值。看起来像这样:

    steps:
    - name: gcr.io/cloud-builders/gcloud
      entrypoint: 'bash'
      args: [ '-c', "gcloud secrets versions access latest --secret=secret-name --format='get(payload.data)' | tr '_-' '/+' | base64 -d > decrypted-data.txt" ]
    - name: 'gcr.io/cloud-builders/gcloud'
      entrypoint: /bin/sh
      args:
      - '-c'
      - |
         sed "s/super-secret-token/g" $(cat decrypted-data.txt)
    - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
      entrypoint: 'bash'
      args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']
    timeout: '1600s'
    

    话虽如此,您的秘密令牌仍然可以在您的 App Engine 的环境变量中以未加密的形式使用,这在安全性方面并不是最佳的。相反,您可能希望直接从 App Engine 代码中查询 Secret Manager。你会发现代码示例这样做here

    【讨论】:

    • 这太丑了哈哈!
    • 我想我应该使用Cloud Run,在那里我可以直接编辑环境变量
    • 呵呵,这是很常见的用例,例如在this CD sample 中为 GKE 生成新清单。
    • 根据 Cloud Run,处理环境变量确实比在 App Engine 中更容易,尽管它们也未加密,并且您不应该按照 caution 中记录的方式存储您的秘密i> 注意here
    猜你喜欢
    • 2020-07-24
    • 2019-01-05
    • 1970-01-01
    • 2022-10-15
    • 2022-10-02
    • 1970-01-01
    • 2019-03-21
    • 2019-09-17
    • 2021-05-19
    相关资源
    最近更新 更多