简体   繁体   English

AWS Cloudwatch 无法使用 SSE 发布到 SNS 主题

[英]AWS Cloudwatch can not publish to SNS Topic with SSE

I have a Route53 health check, which submits its metrics into Cloudwatch, and finally Cloudwatch specifies thresholds and should send alerts through SNS.我有一个 Route53 健康检查,它将其指标提交到 Cloudwatch,最后 Cloudwatch 指定阈值并应通过 SNS 发送警报。

However, I would like my SNS Topic to be encrypted.但是,我希望对我的 SNS 主题进行加密。 When I turn on SNS Topic encryption using the alias/aws/sns key I receive these messages in the Cloudwatch message history:当我使用alias/aws/sns密钥打开 SNS 主题加密时,我会在 Cloudwatch 消息历史记录中收到这些消息:

{
  "actionState": "Failed",
  "stateUpdateTimestamp": 123456778899,
  "notificationResource": "arn:aws:sns:xx-region-y:zzzzzzzzzz:topic_name",
  "publishedMessage": null,
  "error": "null (Service: AWSKMS; Status Code: 400; Error Code: AccessDeniedException; Request ID: ccccccccccccccccccc)"
}

This appears to not be an IAM issue with Cloudwatch, but with SNS itself being unauthorized to use the KMS resources.似乎不是 Cloudwatch 的 IAM 问题,而是 SNS 本身未被授权使用 KMS 资源。

I enjoy using the IAM Policy Simulator for IAM users to identify where their permissions are lacking, but there doesn't seem to be a way to validate a Service's access to other services.我喜欢为 IAM 用户使用 IAM 策略模拟器来确定他们缺少权限的地方,但似乎没有一种方法可以验证服务对其他服务的访问权限。 Is that a thing I can manage?这是我能应付的事情吗?

https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html


I have also tried this with a CMK with the following policy:我还尝试使用具有以下策略的 CMK:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "sns.amazonaws.com"
            },
            "Action": [
                "kms:GenerateDataKey*",
                "kms:Decrypt"
            ],
            "Resource": "*"
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "route53.amazonaws.com"
            },
            "Action": [
                "kms:GenerateDataKey*",
                "kms:Decrypt"
            ],
            "Resource": "*"
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "events.amazonaws.com"
            },
            "Action": [
                "kms:GenerateDataKey*",
                "kms:Decrypt"
            ],
            "Resource": "*"
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::XXXXXXXX:role/OrganizationAccountAccessRole"
            },
            "Action": "kms:*",
            "Resource": "*"
        }
    ]
}

I'm pretty much throwing darts at a wall with the principals, but I think there's validation for sns.amazonaws.com for SNS and events.amazonaws.com for Cloudwatch.我几乎和校长们在墙上投掷飞镖,但我认为有对 SNS 的events.amazonaws.com和 Cloudwatch 的sns.amazonaws.com的验证。

I received the exact same error, "null (Service: AWSKMS; Status Code: 400; Error Code: AccessDeniedException; Request ID: ccccccccccccccccccc)" , when using a CMK in this manner as well.在以这种方式使用 CMK 时,我收到了完全相同的错误"null (Service: AWSKMS; Status Code: 400; Error Code: AccessDeniedException; Request ID: ccccccccccccccccccc)" I can understand my CMK not working properly, but the Amazon managed key I think should just work out of the box.我可以理解我的 CMK 无法正常工作,但我认为 Amazon 托管的密钥应该是开箱即用的。


I've tried using a CMK which grants sns.amazonaws.com and events.amazonaws.com with kms:* permissions.我尝试使用 CMK 授予sns.amazonaws.comevents.amazonaws.comkms:*权限。 Same error.同样的错误。

Update: It's likely this information is out of date.更新:此信息可能已过时。 Please try the other answers and let everyone know if they work for you.请尝试其他答案,并让所有人知道它们是否适合您。


Apparently, CloudWatch can't send messages to encrypted SNS topics according to Protecting Amazon SNS Data Using Server-Side Encryption (SSE) and AWS KMS :显然,根据使用服务器端加密 (SSE) 和 AWS KMS 保护 Amazon SNS 数据,CloudWatch无法将消息发送到加密的 SNS 主题:

Currently, CloudWatch alarms don't work with Amazon SNS encrypted topics.目前,CloudWatch 警报不适用于 Amazon SNS 加密主题。 For information about publishing alarms to unencrypted topics, see Using Amazon CloudWatch Alarms in the Amazon CloudWatch User Guide.有关将警报发布到未加密主题的信息,请参阅 Amazon CloudWatch 用户指南中的使用 Amazon CloudWatch 警报。

However, the blog post Encrypting messages published to Amazon SNS with AWS KMS seems to indicate you can...但是,博客文章使用 AWS KMS 加密发布到 Amazon SNS 的消息似乎表明您可以...

🤦 🤦

Just summarizing the correct answer here because the accepted answer seems to be outdated:.只是在这里总结正确的答案,因为接受的答案似乎已经过时了:。

  1. You cannot use the Amazon managed CMK alias/aws/sns because in order to connect cloudwatch with an SNS topic encrypted with a KMS CMK, you need to set a resource-policy/access-policy on the CMK so that cloudwatch service can perform kms:GenerateDataKey* and kms:Decrypt actions on the key and the access-policy on amazon managed keys cannot be edited.您不能使用 Amazon 托管的 CMK alias/aws/sns因为为了将 cloudwatch 与使用 KMS CMK 加密的 SNS 主题连接,您需要在 CMK 上设置资源策略/访问策略,以便 cloudwatch 服务可以执行kms:GenerateDataKey*kms:Decrypt密钥上的操作和亚马逊托管密钥上的访问策略无法编辑。

  2. For your case, you would need to create a customer managed symmetric CMK, and edit the access-policy to allow cloudwatch service principal to access that CMK.对于您的情况,您需要创建一个客户管理的对称 CMK,并编辑访问策略以允许 cloudwatch 服务委托人访问该 CMK。 The access-policy will look like:访问策略将如下所示:

    "Version": "2012-10-17",
    "Id": "key-policies",
    "Statement": [
        {
            "Sid": "Enable IAM User Permissions for administration of this key",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::xxxxxxxxxxxx:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        },
        {
            "Sid": "Allow cloudwatch metric to use this key",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudwatch.amazonaws.com"
            },
            "Action": [
                "kms:Decrypt",
                "kms:GenerateDataKey*"
            ],
            "Resource": "*"
        }
    ]
}

The service is not "events.amazonaws.com", it is "cloudwatch.amazonaws.com".该服务不是“events.amazonaws.com”,而是“cloudwatch.amazonaws.com”。 You should get the SNS notifications once you change this in the key policy.在密钥策略中更改此设置后,您应该会收到 SNS 通知。

See https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html for more information.有关更多信息,请参阅https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html

While some AWS services use an IAM Role in your account, others use a specific principal to be granted access instead.虽然某些 AWS 服务在您的账户中使用 IAM 角色,但其他服务使用特定委托人来授予访问权限。 See https://aws.amazon.com/blogs/compute/encrypting-messages-published-to-amazon-sns-with-aws-kms/ .请参阅https://aws.amazon.com/blogs/compute/encrypting-messages-published-to-amazon-sns-with-aws-kms/

I think in your case you need to allow the cloudwatch principal, events.amazonaws.com , to be allowed to use the KMS key you specified, in the key's policy.我认为在您的情况下,您需要允许 cloudwatch 主体events.amazonaws.com使用您在密钥策略中指定的 KMS 密钥。 See the section "Enabling compatibility between encrypted topics and event sources" in the above link.请参阅上面链接中的“启用加密主题和事件源之间的兼容性”部分。

Note that as the document says, "Several AWS services publish events to Amazon SNS topics. To allow these event sources to work with encrypted topics, you must first create a customer-managed CMK and then add the following statement to the policy of the CMK."请注意,如文档所述,“多个 AWS 服务将事件发布到 Amazon SNS 主题。要允许这些事件源使用加密主题,您必须首先创建客户管理的 CMK,然后将以下语句添加到 CMK 的策略中.” This only works with customer managed keys.这仅适用于客户管理的密钥。

I ran into the same issue today!我今天遇到了同样的问题! I see there are suggestions for granting the CMK to cloudwatch.amazonaws.com and also to events.amazonaws.com .我看到有人建议将 CMK 授予cloudwatch.amazonaws.comevents.amazonaws.com For me, I needed to grant to both for that to work.对我来说,我需要同时授予两者才能起作用。 Here is the entirety of my Cloudformation definition for the CMK.这是我对 CMK 的完整 Cloudformation 定义。

 InternalSNSKey:
    Type: AWS::KMS::Key
    Properties:
      Description: IA-Internal-SNS Encryption Key
      KeyPolicy:
        Version: 2012-10-17
        Id: allow-root-access-to-key
        Statement:
          - Sid: allow-root-to-delegate-actions
            Effect: Allow
            Principal:
              AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
            Action:
              - kms:*
            Resource: '*'
          - Sid: allow-cloudwatch-to-use-key
            Effect: Allow
            Principal:
              Service: cloudwatch.amazonaws.com
            Action:
              - kms:Decrypt
              - kms:GenerateDataKey*
            Resource: '*'
          - Sid: allow-events-to-use-key
            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Action:
              - kms:Decrypt
              - kms:GenerateDataKey*
            Resource: '*'

Adding just the below events.amazon.com permissions to the KMS key's resource policy did the trick for me, specifically to allow AWS::Events::Rule that had encrypted SNS topics registered as Targets for 'FAILED' CodeBuild and CodePipeline states.只需添加下面的events.amazon.com权限KMS密钥的资源政策,为我做的伎俩,特别是允许AWS::Events::Rule是已加密的已登记为SNS主题Targets为“失败” CodeBuild和CodePipeline状态。

       {
            "Sid": "Allow Events use of key (for publishing to CMK encrypted SNS topics)",
            "Effect": "Allow",
            "Principal": {
                "Service": "events.amazonaws.com"
            },
            "Action": [
                "kms:Decrypt",
                "kms:GenerateDataKey*"
            ],
            "Resource": "*"
        }

Hope this saves someone else some of the frustration and time this had caused me.希望这可以为其他人节省一些挫折和时间,这给我带来了。

暂无
暂无

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

相关问题 来自账户 A 的 AWS Cloudwatch 警报无法发布到账户 B 中的 SNS 主题 - AWS Cloudwatch alarm from Account A unable to publish to SNS topic in Account B 使用Cloudformation AWS将SNS主题添加到现有CloudWatch Alarm - Add SNS topic to existing CloudWatch Alarm with Cloudformation AWS 如何在 AWS 控制台中将 SNS 主题写入 CloudWatch 日志? - How to write SNS topic into CloudWatch log within AWS console? 您能否在不使用 AWS Lambda 函数的情况下将消息发布到 SNS 主题? 在速度模板中? - Can you publish a message to an SNS topic without using an AWS Lambda function? in velocity template? 您能否使用由 node.js 支持的 AWS Lambda 函数将消息发布到 SNS 主题? - Can you publish a message to an SNS topic using an AWS Lambda function backed by node.js? 我们可以使用由 python 支持的 AWS Lambda function 将消息发布到 SNS 主题吗? - Can we publish a message to an SNS topic using an AWS Lambda function backed by python? CloudFormation:发布到SNS主题 - CloudFormation: Publish to SNS topic 发布到另一个 AWS 账户拥有的 SNS 主题时获取 AuthorizationErrorException - Getting AuthorizationErrorException while publish to a SNS topic that is owned by another AWS account 使用 C# 将 json 消息发布到 AWS SNS 主题 - Publish a json message to AWS SNS topic using C# AWS SNS是否可以灵活地发布到主题订阅者的子集? - AWS SNS Flexibility to Publish to Subset of Topic's Subscribers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM