简体   繁体   English

尝试在 gcp 中使用 set iam policy 方法使用 python 更新云存储策略时出错?

[英]Getting an error when trying to use set iam policy method in gcp to update cloud storage policy using python?

Getting an error when trying to add encrypter decrypter role to the bucket service account.尝试将加密器解密器角色添加到存储桶服务帐户时出错。 Below is the code.. Any idea what's missing?下面是代码..知道缺少什么吗?

storage_client = storage.Client(credentials=credentials)
sa_name = storage_client.get_service_account_email("project name")
print(sa_name)

bucket = storage_client.get_bucket("bucket name")
policy = bucket.get_iam_policy(requested_policy_version=3)
policy.version = 3
policy.bindings.append({
    "role": "roles/cloudkms.cryptoKeyEncrypterDecrypter",
    "members": {"serviceAccount:{}".format(sa_name)}
})
bucket.set_iam_policy(policy)
**Error:** google.api_core.exceptions.BadRequest: 400 PUT https://storage.googleapis.com/storage/v1/b/bucketname/iam?prettyPrint=false: Role roles/cloudkms.cryptoKeyEncrypterDecrypter is not supported for this resource.

The error message XYZ is not supported for this resource means that you are trying to grant a permission (role) to a resource that does not use that permission or does not provide a resource, such as a KMS key, upon which that permission can be granted.错误消息XYZ is not supported for this resource表示您正在尝试向不使用该权限或不提供该权限的资源(例如 KMS 密钥)授予权限(角色)的确。

In your question you are trying to grant the permission roles/cloudkms.cryptoKeyEncrypterDecrypter to a Google Cloud Storage bucket .在您的问题中,您尝试将权限roles/cloudkms.cryptoKeyEncrypterDecrypter授予 Google Cloud Storage bucket You have the logic reversed, you would modify a KMS resource policy, such as a key instead of a bucket resource policy.您将逻辑颠倒过来,您将修改 KMS 资源策略,例如密钥而不是存储桶资源策略。 Refer to the following link for more details on binding to a KMS resource:有关绑定到 KMS 资源的更多详细信息,请参阅以下链接:

KMS: Granting roles on a resource KMS:在资源上授予角色

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用以下python代码从Azure Blob存储下载内容时,出现错误:“重试策略不允许重试” - Getting the error : “Retry policy did not allow for a retry” while trying to download contents from azure blob storage using the below python code 我在哪里可以找到有关 google.cloud.resourcemanager_v3 的方法 set_iam_policy 的更多文档 - Where could I find further documentation for the method set_iam_policy of the google.cloud.resourcemanager_v3 GCP 中是否有使用 python 更新存储桶加密的方法? - Is there a method in GCP to update the encryption of a storage bucket using python? aws iam 上的令人困惑的错误:“策略中的语法错误” - confusing error on aws iam: "Syntax error in policy" 使用 Boto 创建 IAM 策略时出现 MalformedPolicyDocumentException - MalformedPolicyDocumentException while creating IAM policy using Boto 尝试使用推荐器在 GCP 中列出 IdleVM 时出错 - Getting an error when trying to list IdleVM's in GCP using recommender 使用 Python 更新组织策略约束 - Update Org Policy constraints with Python 设置IAM策略可在本地计算机上运行,​​但不适用于GCE实例 - Set IAM Policy works on local machine but not in GCE instance 尝试使用 ploty-dash 应用程序连接到 mysql db 时出现错误 - when trying to connect to mysql db using ploty-dash app iam getting an error Python Google Cloud Function 中的 CORS 策略 - CORS policy in a Python Google Cloud Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM