【问题标题】:KMS Not found Exception in AWS Cross Account S3 PutObject encrypted by AWS Managed Key在 AWS 托管密钥加密的 AWS 跨账户 S3 PutObject 中未找到 KMS 异常
【发布时间】:2021-03-21 09:11:40
【问题描述】:

我正在尝试将账户 B 中的 Glue 中的一个虚拟文件放入账户 A 中的 S3 存储桶。S3 存储桶(测试存储桶)正在启用 AWS-KMS 加密并启用 aws/s3 托管密钥。

  1. 我在账户 A-S3 存储桶(测试存储桶)中添加了以下权限:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Deny PutObject if NOT using correct KMS Encryption Key",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::test-bucket/*",
            "Condition": {
                "StringNotEquals": {
                    "s3:x-amz-server-side-encryption": "",
                    "s3:x-amz-server-side-encryption-aws-kms-key-id": "<ARN_KMS_ACCOUNT_A>"
                }
            }
        },
        {
            "Sid": "Allow Glue Role in Application account to put objects in the S3 bucket",
            "Effect": "Allow",
            "Principal": {
                "AWS": "<IAM_Glue_Role_ARN>"
            },
            "Action": [
                "s3:AbortMultipartUpload",
                "s3:GetBucketLocation",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:ListBucketMultipartUploads",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::test-bucket",
                "arn:aws:s3:::test-bucket/*"
            ]
        },
        {
            "Sid": "Only allow writes to my bucket with bucket owner full control",
            "Effect": "Allow",
            "Principal": {
                "AWS": "<IAM_Glue_Role_ARN>"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::test-bucket/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        }
    ]
}
  1. 为账户 B 中的 IAM Glue 角色添加了以下策略
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:Get*",
                "s3:List*",
                "s3:Put*"
            ],
            "Resource": "arn:aws:s3:::test-bucket*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "kms:Decrypt",
                "kms:Encrypt",
                "kms:GenerateDataKey"
            ],
            "Resource": "<ARN_KMS_ACCOUNT_A>",
            "Effect": "Allow"
        }
    ]
}

这是我的胶水代码:

s3.put_object(
    Bucket='output',
    Key='_SUCCESS',
    ServerSideEncryption='aws:kms',
    SSEKMSKeyId='<ARN_KMS_ACCOUNT_A>'
)

从 Account B Glue 运行此代码时出现以下错误:

ClientError: An error occurred (KMS.NotFoundException) when calling the PutObject operation: Invalid arn ap-southeast-2

对此有什么想法吗?

【问题讨论】:

  • 这真的有意义吗? "StringNotEquals": { "s3:x-amz-server-side-encryption": "",

标签: amazon-web-services amazon-s3 aws-glue amazon-kms


【解决方案1】:

有几件事:

  1. 对于存储桶上的策略,Deny 权限应始终在所有Allow 权限之后。并删除Deny 权限上的condition。您想阻止所有未经授权的流量。
  2. 使用托管 KMS 密钥。在该密钥上,将 kms:decrypt 授予密钥策略的粘合角色。

【讨论】:

    【解决方案2】:

    AWS 托管 CMK aws/s3 只能在同一账户中使用,即密钥存在的地方(在您的情况下,它的账户 A)。您可以尝试使用账户 B 中的 aws/s3 CMK 或在账户 A 中创建客户管理的 CMK,并按照步骤 here 与账户 B 共享。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-06
      • 2020-12-04
      • 1970-01-01
      • 2016-02-09
      • 2021-11-29
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      相关资源
      最近更新 更多