简体   繁体   English

SNS跨账户订阅,附加层

[英]SNS cross account subscription with additional layer

We own an AWS Account, account A. We rely on an external team to publish messages to their SNS topic, which is in their account B. We use an SQS queue in account A to subscribe to the SNS topic in account B. Account A has been whitelisted by the owner of account B to subscribe to the SNS topic.我们拥有一个 AWS 账户,账户 A。我们依靠外部团队将消息发布到他们的账户 B 中的 SNS 主题。我们使用账户 A 中的 SQS 队列订阅账户 B 中的 SNS 主题。账户 A已被账号 B 的所有者列入订阅 SNS 主题的白名单。

Now, we would like to subscribe to the SNS topic in Account B for multiple (new) accounts.现在,我们想为多个(新)账户订阅账户 B 中的 SNS 主题。 However, the team that owns account B does not have the capacity to manually whitelist the many accounts we will be creating.但是,拥有账户 B 的团队无法手动将我们将创建的许多账户列入白名单。

Is there a way for us to delegate or proxy permissions from account A to all the new accounts that we are creating, via something like an IAM Role created in account A?我们有没有办法通过在账户 A 中创建的 IAM 角色之类的东西,将账户 A 的权限委托或代理到我们正在创建的所有新账户?

The problem is that account B is trying to give permission to a specific user of account A. Like you mentioned, this can be an issue if you need to setup multiple accounts.问题是帐户 B 正试图向帐户 A 的特定用户授予权限。就像您提到的,如果您需要设置多个帐户,这可能是一个问题。

You can solve this in multiple ways.您可以通过多种方式解决此问题。

  1. Account B gives the root of Account A permission.账户 B 授予账户 A 的权限。 Then, Account A has full permission to delegate the access to any IAM roles / users.然后,账户 A 拥有将访问权限委派给任何 IAM 角色/用户的完全权限。 Here is a blog post contains this method of setup https://aws.amazon.com/blogs/compute/cross-account-integration-with-amazon-sns/这是一篇博客文章,其中包含这种设置方法https://aws.amazon.com/blogs/compute/cross-account-integration-with-amazon-sns/
  2. Create an IAM group in Account A, and assign users to the group.在账户 A 中创建一个 IAM 组,并将用户分配到该组。 Then, in Account B give the permission to Account A's group instead of the specific user.然后,在账户 B 中,将权限授予账户 A 的组而不是特定用户。 Here is an example of providing access via groups 这是通过组提供访问权限的示例

Please note that if you are going with solution #1 that any IAM user in account A will be able to access the SNS resource.请注意,如果您使用解决方案 #1,账户 A 中的任何 IAM 用户都将能够访问 SNS 资源。 If multiple applications are running in account A this could be an issue.如果多个应用程序在帐户 A 中运行,这可能是一个问题。

Your current situation is:你现在的情况是:

  • Amazon SQS queue ( Queue-A ) in Account-A owned by you您拥有的Account-A中的 Amazon SQS 队列 ( Queue-A )
  • Amazon SNS topic ( Topic-B ) in Account-B owned by somebody else其他人拥有的Account-B中的 Amazon SNS 主题 ( Topic-B )
  • Permissions have been added to Topic-B that allows Account-A to subscribe to the topic已向Topic-B添加权限,允许Account-A订阅该主题

The above has worked well.以上效果很好。

New requirements:新要求:

  • Allow Account-C and Account-D to subscribe to Topic-B允许Account-CAccount-D订阅Topic-B
  • The owner of Account-B does not wish to modify the permissions on Topic-B to allow these subscription requests Account-B的所有者不希望修改Topic-B的权限以允许这些订阅请求

Solution解决方案

Instead of Account-C and Account-D sending a Subscribe() request, ask the owner of Topic-B to directly subscribe the new queues .不是Account-CAccount-D发送Subscribe()请求,而是要求Topic-B的所有者直接订阅新队列

You say that "the team that owns account B does not have the capacity to manually whitelist the many accounts we will be creating."你说“拥有账户 B 的团队没有能力手动将我们将创建的许多账户列入白名单。”

This is based on the idea that Account-C and Account-D should, themselves, send the Subscribe request to Topic-B .这是基于Account-CAccount-D应该自己将订阅请求发送到Topic-B的想法。 Instead, I am recommending that you provide the ARNs of Queue-C and Queue-D to the team that owns Topic-B and ask them to add these queues as subscribers.相反,我建议您将Queue-CQueue-D的 ARN 提供给拥有Topic-B的团队,并要求他们将这些队列添加为订阅者。 This does not require any change to the permission policy on Topic-B .不需要Topic-B的权限策略进行任何更改。

However, a couple of things to note:但是,有几点需要注意:

  • Queue-C and Queue-D will need to confirm the subscription. Queue-CQueue-D需要确认订阅。 The easiest way to do this is to view the initial message sent to the queue after being subscribed to the topic, copy the subscription URL shown in the message and then paste it into a web browser.最简单的方法是查看订阅主题后发送到队列的初始消息,复制消息中显示的订阅 URL,然后将其粘贴到 web 浏览器中。 This is a one-off process.这是一个一次性的过程。
  • Queue-C and Queue-D will need to add permission to allow Topic-B to send a message to their queue. Queue-CQueue-D将需要添加权限以允许Topic-B向其队列发送消息。 You probably have this in place already for Queue-A .您可能已经为Queue-A做好了准备。 The policy would look like:该政策如下所示:
{
  "Version": "2012-10-17",
  "Id": "arn:aws:sqs:ap-southeast-2:ccc:my-queue/SQSDefaultPolicy",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:ap-southeast-2:ccc:my-queue",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:ap-southeast-2:bbb:their-topic"
        }
      }
    }
  ]
}

See also:也可以看看:

If you can't rely on the owners of Account-B to do anything for you, then your only option would be:如果您不能依靠Account-B的所有者为您做任何事情,那么您唯一的选择是:

  • Create your own SNS Topic in Account-A ( Topic-A ) where you can manage subscriptions在 Account-A ( Topic-A ) 中创建您自己的 SNS 主题,您可以在其中管理订阅
  • Create an AWS Lambda function that will send messages to Topic-A创建一个 AWS Lambda function 将消息发送到Topic-A
  • Subscribe the Lambda function to your existing Queue-A , so that any message sent to Queue-A will be re-sent to Topic-A订阅 Lambda function 到您现有的Queue-A ,以便发送到Queue-A任何消息都将重新发送到Topic-A
  • Have all the accounts use Topic-A as if it was Topic-B让所有帐户都像使用Topic-A一样使用 Topic- Topic-B

This way, you can use your existing SQS queue ( Queue-A ) as a 'relay' to a new SNS topic ( Topic-A ) under your control.这样,您可以使用现有的 SQS 队列 ( Queue-A ) 作为您控制下的新 SNS 主题 ( Topic-A ) 的“中继”。 You would also need to change your current apps that consume from Queue-A to consume from a new queue that is subscribed to Topic-A .您还需要将当前从Queue-A使用的应用程序更改为从订阅Topic-A的新队列中使用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM