其他 AWS 用户(错误地)能够访问我的 AWS SecretsManager 秘密值,该秘密值使用我的 AWS KMS CMK 加密

Other AWS User is (Incorrectly) Able to Access My AWS SecretsManager Secret Value, That's Encrypted With My AWS KMS CMK

我正在使用我的 AWS KMS CMK 加密和 AWS SecretsManager Secret,但我的同事可以看到秘密值!!

知道为什么吗?

技术细节:

我正在使用 AWS SAM CLI 进行部署。

这是我的 AWS SAM 模板:

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Parameters:
  SecretValue:
    Type: String
  KmsCmkId: 
    Type: String

Resources:
  MySecret:
    Type: AWS::SecretsManager::Secret
    Properties:
      SecretString:
        Ref: SecretValue
      KmsKeyId: !Ref KmsCmkId

我用这个构建和部署它:

sam build ; sam deploy --guided --parameter-overrides SecretValue=ABC KmsCmkId=REDACTED

我迄今为止的调试:

{
    "Id": "key-consolepolicy-3",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Enable IAM User Permissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::REDACTED:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        },
        {
            "Sid": "Allow access for Key Administrators",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::REDACTED:user/MY_COWORKER"
                ]
            },
            "Action": [
                "kms:Create*",
                "kms:Describe*",
                "kms:Enable*",
                "kms:List*",
                "kms:Put*",
                "kms:Update*",
                "kms:Revoke*",
                "kms:Disable*",
                "kms:Get*",
                "kms:Delete*",
                "kms:TagResource",
                "kms:UntagResource",
                "kms:ScheduleKeyDeletion",
                "kms:CancelKeyDeletion"
            ],
            "Resource": "*"
        },
        {
            "Sid": "Allow use of the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::REDACTED:user/ME"
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey"
            ],
            "Resource": "*"
        },
        {
            "Sid": "Allow attachment of persistent resources",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::REDACTED:user/ME"
            },
            "Action": [
                "kms:CreateGrant",
                "kms:ListGrants",
                "kms:RevokeGrant"
            ],
            "Resource": "*",
            "Condition": {
                "Bool": {
                    "kms:GrantIsForAWSResource": "true"
                }
            }
        }
    ]
}

非常感谢@JohnRotenstein 为我指明了正确的方向,并在上面回答了我的问题!

解决方案背景 1

正如 John 所问,当我在上面说我的同事“是我们帐户的管理员”时,我的意思是他的 IAM 用户帐户具有 AWS 托管策略 Administrator Access,它提供“完全访问权限”到(据我所知)AWS 中的所有内容或几乎所有内容(包括 KMS!!)。

解决方案背景2

确实,在我上面的问题中,我的密钥策略(这是默认密钥策略)包含以下语句:

{
    "Sid": "Enable IAM User Permissions",
    "Effect": "Allow",
    "Principal": {
        "AWS": "arn:aws:iam::REDACTED:root"
    },
    "Action": "kms:*",
    "Resource": "*"
},

根据@JohnRotenstein 的评论和 these AWS docs,此策略声明允许 IAM 策略访问和使用此密钥——如果这些策略指定了正确的权限.

因此(据我所知),这将允许相当多的人(任何可以在我公司的帐户上编辑 IAM 策略的人)能够为自己提供一个允许他们做任何他们想做的事情的策略使用我的 KMS 密钥! (这不安全!)

我需要压制它。 (下面的解决方案!)

解决方案背景3

在“默认 KMS 密钥策略”(我在上面的问题中发布)中,您会看到密钥管理员可以 kms:Put*。允许他们 kms:PutKeyPolicy,这将允许他们更改策略以给自己(或任何人)kms:Decrypt,这将允许他们解密 my Secrets Manager 秘密并获取秘密值!

我也需要压制它...

解决方案

以下关键政策:

  • 确保 我的 Lambda 函数可以(通过我给执行 Lambda 函数的 IAM 角色的策略声明)使用 IAM 策略来使用它钥匙,他们只能kms:Decrypt

  • 只允许关键用户(我)进行加解密操作(当然Lambda函数除外;见上文)

  • 虽然密钥管理员不能使用我的密钥来加密或解密(或 kms:PutKeyPolicy),但他们可以执行所有管理任务,例如删除 KMS 密钥或其授权。

{
  "Id": "mount-houlis-secure-kms-key-policy",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Allow use of the key",
      "Effect": "Allow",
      "Principal": {
        "AWS": THE_ARN_OF_THE_IAM_USER_WHO_OWNS_THE_SECRET____WHICH_IS_ME
      },
      "Action": [
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:ReEncrypt*",
        "kms:GenerateDataKey*",
        "kms:DescribeKey",
        "kms:GetKeyPolicy",
        "kms:PutKeyPolicy"
      ],
      "Resource": "*"
    },
    {
      "Sid": "Admins",
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          ARNS_OF_VARIOUS,
          KEY_ADMINISTRATORS,
          AND_ME
        ]
      },
      "Action": [
        "kms:CancelKeyDeletion",
        "kms:CreateAlias",
        "kms:DeleteAlias",
        "kms:DescribeKey",
        "kms:DisableKey",
        "kms:DisableKeyRotation",
        "kms:EnableKey",
        "kms:EnableKeyRotation",
        "kms:GetKeyPolicy",
        "kms:GetKeyRotationStatus",
        "kms:ListGrants",
        "kms:ListKeyPolicies",
        "kms:ListResourceTags",
        "kms:ListRetirableGrants",
        "kms:RetireGrant",
        "kms:RevokeGrant",
        "kms:ScheduleKeyDeletion",
        "kms:TagResource",
        "kms:UntagResource",
        "kms:UpdateAlias",
        "kms:UpdateKeyDescription"
      ],
      "Resource": "*"
    },
    {
      "Sid": "Allow Lambda function to do Action secretsmanager:GetSecretValue",
      "Effect": "Allow",
      "Principal": {
        "AWS": ARN_OF_THE_ROLE_THAT_YOUR_LAMBDA_FUNCTION_EXECUTES_AS____SHOULD_BE_arn:aws:iam::ACCOUNT_NUMBER:role/your-lambda-function-role-name
      },
      "Action": "kms:Decrypt",
      "Resource": "*"
    }
  ]
}