google-cloud-platform - (gcloud.kms.encrypt) 无法读取明文文件
问题描述
我想用gcloud
命令行工具加密一个密钥文件。
我正在运行的命令是:
gcloud kms encrypt --project=pname --location=global --keyring=keyring \
--key=key-credential \
--plaintext-file=/Users/macuser/Desktop/test/keys/testkey.json.decrypted \
--ciphertext-file=testkey.json.encrypted
但我不断收到错误
ERROR: (gcloud.kms.encrypt) Failed to read plaintext file
[/Users/macuser/Desktop/test/keys/testkey.json.decrypted]:
Unable to read file [/Users/macuser/Desktop/test/keys/testkey.json.decrypted]:
[Errno 2] No such file or directory:
'/Users/macuser/Desktop/test/keys/testkey.json.decrypted'
文件
/Users/macuser/Desktop/test/keys/testkey.json.decrypted
存在。我尝试使用绝对路径和相对路径,以及带和不带引号,但我一直收到同样的错误。
为什么 gcloud 看不到文件?
解决方案
- 确保调用加密和解密方法的用户对用于加密或解密的密钥具有
cloudkms.cryptoKeyVersions.useToEncrypt
和权限。cloudkms.cryptoKeyVersions.useToDecrypt
允许用户加密或解密的一种方法是将用户添加到该密钥的roles/cloudkms.cryptoKeyEncrypter
、roles/cloudkms.cryptoKeyDecrypter
或roles/cloudkms.cryptoKeyEncrypterDecrypter
IAM 角色。
- 要在命令行上使用 Cloud KMS,请先安装或升级到最新版本的 Cloud SDK。
gcloud kms encrypt \
--key key \
--keyring key-ring \
--location location \
--plaintext-file file-with-data-to-encrypt \
--ciphertext-file file-to-store-encrypted-data
- 将 key 替换为用于加密的密钥的名称。
- 将 key-ring 替换为密钥所在的密钥环的名称。
- 将 location 替换为 Cloud KMS 位置作为密钥环。
- 将
file-with-data-to-encrypt
和替换file-to-store-encrypted-data
为用于读取明文数据并保存加密输出的本地文件路径。
推荐阅读
- reactjs - 如何影响列表中单个元素的 Gatsby/React useState
- r - 在编程模式下从 data.table 中选择行
- php - 提示时 Ajax 不执行新请求
- r - 如何让 RStudio 使用 R 语言设置?
- netbeans - 如何修复 8.2 和 11.0 上损坏的 NetBeans 缓存?
- reactjs - 无法将其他道具传递给 {this.props.children}
- python - 无法使用来自 Gizmodo 网站的 Selenium、python 请求和 beautifulsoup 获取评论文本
- elasticsearch - 使用 GCP/GAE 搜索和缓存 API
- android - Flutter Firestore QuerySnapshot 没有 getter 'document 的实例
- security - 为什么 OAuth2.0 的查询字符串参数中有访问令牌?