encryption - 如何使用 Google Cloud Build 和 Google Cloud KMS 从构建时解密的文件中读取变量
问题描述
我正在按照本教程将加密密钥添加到我的 cloudbuild YAML 文件中。我试图了解我应该如何在我的 YAML 文件的后续步骤中“使用工作区目录中的解密 ... 文件”变量。
我解密密钥文件的 cloudbuild 步骤如下:
- name: gcr.io/cloud-builders/gcloud
args: ['kms', 'decrypt', '--ciphertext-file=<encrypted_file>', '--plaintext-file=<decrypted_file>', '--location=<location>', '--keyring=<keyring>', '--key=<key>']
该教程不清楚如何执行此操作,我在 Internet 上找不到与此相关的任何内容。
非常感谢任何帮助。
谢谢。
解决方案
使用 加密内容时gcloud kms encrypt
,可以将输出写入工作区中的文件,例如:
# replace with your values
gcloud kms encrypt \
--location=global \
--keyring=my-kr \
--key=my-key \
--plaintext-file=./data-to-encrypt \
--ciphertext-file=./encrypted-data
./data-to-encrypt
磁盘上包含明文机密的文件在哪里,并且是磁盘上应写入加密密文./encrypted-data
的目标路径。
直接使用 API 时,交互如下所示:
plaintext -> kms(encrypt) -> ciphertext
但是,当使用 时gcloud
,它看起来像这样:
plaintext-file -> gcloud(read) -> kms(encrypt) -> ciphertext -> gcloud(write)
当您调用 Cloud Build 时,它会有效地获取应用程序的 tarball,减去.gcloudignore
. 这意味着./encrypted-data
将在容器步骤内的文件系统上可用:
steps:
# decrypt the value in ./my-secret
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --location=global
- --keyring=my-kr
- --key=my-key
- --ciphertext=file=./encrypted-data
- --plaintext-file=./my-secret
- name: gcr.io/my-project/my-image
steps:
- my-app start --secret=./my-secret
目前,在 Cloud Build 中,步骤之间共享数据的唯一方法是使用文件,但所有构建步骤都具有相同的共享文件系统。
推荐阅读
- javascript - 加载ajax时变量不保留值
- docker - 大厅中的 docker-image 和 registry-image 有什么区别?
- javascript - querySelectorAll 不在父级中的元素 display: none
- reactjs - 在本机反应中将动态变量传递给`flatListProps`中的`renderItem`
- arrays - 在 JSONB 数组中强制唯一性
- mysql - Mysql 是否省略尾随空格?
- ios - 如何使用 DispatchQueue 使视图在一段时间后出现和消失?
- java - 如何从 Android Studio 中的实时 Firebase 检索特定用户
- r - str_extract 带有引号和分号的正则表达式
- c++ - 在 C++ 中请求条件信息