无法从 S3 存储桶中访问从RDS导出的加密文件

0

【以下的问题经过翻译处理】 我通过“aws_s3.query_export_to_s3”函数将数据从 Aurora Postgres 实例导出到 S3。目标存储桶未启用默认加密。当我尝试下载其中一个文件时,出现以下错误:

The ciphertext refers to a customer mast3r key that does not exist, does not exist in this region, or you are not allowed to access.

注意:我不得不更改 mast3r 这个词,因为这个论坛不允许我发布它,因为它是一个“非包容性”的词......

原因似乎是文件已使用具有以下策略的 AWS 托管 RDS 密钥加密:

{
    "Version": "2012-10-17",
    "Id": "auto-rds-2",
    "Statement": [
        {
            "Sid": "Allow access through RDS for all principals in the account that are authorized to use RDS",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:CreateGrant",
                "kms:ListGrants",
                "kms:DescribeKey"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "kms:CallerAccount": "123456789",
                    "kms:ViaService": "rds.eu-central-1.amazonaws.com"
                }
            }
        },
        {
            "Sid": "Allow direct access to key metadata to the account",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::123456789:root"
            },
            "Action": [
                "kms:Describe*",
                "kms:Get*",
                "kms:List*",
                "kms:RevokeGrant"
            ],
            "Resource": "*"
        }
    ]
}

我假设在尝试通过 S3 解密文件时,由于“ViaService”条件,访问不起作用。

我尝试使用 root 用户而不是 IAM 用户访问文件并且它有效。有什么方法可以访问 IAM 用户吗?据我所知,您无法修改 AWS 托管密钥的策略。我也不明白为什么 root 用户可以解密文件,因为除了从 RDS 调用时的权限外,策略没有明确授予解密权限。

1 回答
0

【以下的回答经过翻译处理】 aws_s3.query_export_to_s3 使用 AWS 托管密钥 aws/s3 来加密导出的数据(而不是问题中列出的 aws/rds)。该密钥的策略如下:

{ "Version": "2012-10-17", "Id": "auto-s3-2", "Statement": [ { "Sid": "Allow access through S3 for all principals in the account that are authorized to use S3", "Effect": "Allow", "Principal": { "AWS": "" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource": "", "Condition": { "StringEquals": { "kms:CallerAccount": "123456789012", "kms:ViaService": "s3.eu-central-1.amazonaws.com" } } }, { "Sid": "Allow direct access to key metadata to the account", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:root" }, "Action": [ "kms:Describe", "kms:Get*", "kms:List*" ], "Resource": "*" } ] }

根据此策略,您账户的任何 IAM 委托人都可以使用该密钥通过 S3 服务执行“加密”、“解密”等操作(第一个策略声明),而直接使用仅限于元数据操作(第二个策略声明)。因此,如果您的 IAM 委托人与密钥位于同一帐户中,并且可以通过“GetObject”访问 S3 对象,那么他们也应该能够解密和下载导出的数据。我能想到的这种情况的原因是

  1. 您尝试从另一个账户中的委托人访问对象(该账户可以访问数据,例如通过跨账户角色或存储桶策略),但无法访问 AWS 托管密钥“aws/s3”进行解密。
  2. 存在针对您的 IAM 委托人的明确拒绝,阻止您的 IAM 委托人访问密钥。

请注意,在这种情况下不需要显式拒绝,因为 IAM 委托人无法在不通过 S3 的情况下直接使用“aws/s3”来“解密”。任何 IAM 委托人(甚至 root)也没有可能获得该特定密钥的特权,因为

  1. AWS 托管密钥的密钥策略(例如 aws/s3)不能更改,并且
  2. aws/s3 的密钥策略不允许CreateGrant 委托访问密钥(即使是root 用户)。
profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则