我正在使用cloud storage
带有 kms 密钥的文件上传。这是我的代码:
await storage.bucket(config.bucket).upload(file, {
kmsKeyName: `projects/${process.env.PROJECT_ID}/locations/global/keyRings/test/cryptoKeys/nodejs-gcp`,
destination: 'mmczblsq.kms.encrypted.doc'
});
我有一个获得许可的cloud-storage-admin.json
服务帐户。使用此服务帐户cloud storage admin
初始化。storage
const storage: Storage = new Storage({
projectId: process.env.PROJECT_ID,
keyFilename: path.resolve(__dirname, '../.gcp/cloud-storage-admin.json')
});
而且,我使用gcloud kms keys add-iam-policy-binding
添加roles/cloudkms.cryptoKeyEncrypterDecrypter
到cloud-storage-admin.json
服务帐户。
当我尝试使用 kms 密钥上传文件时,仍然出现此权限错误:
Cloud KMS 密钥的权限被拒绝。请确保您的云存储服务帐号已被授权使用此密钥。
更新
☁ nodejs-gcp [master] ⚡ gcloud kms keys get-iam-policy nodejs-gcp --keyring=test --location=global
bindings:
- members:
- serviceAccount:cloud-storage-admin@<PROJECT_ID>.iam.gserviceaccount.com
- serviceAccount:service-16536262744@gs-project-accounts.iam.gserviceaccount.com
role: roles/cloudkms.cryptoKeyEncrypterDecrypter
etag: BwWJ2Pdc5YM=
version: 1