aws:SourceAccount 和 aws:SourceOwner AWS SNS 访问策略语句之间有什么区别

What is difference between aws:SourceAccount and aws:SourceOwner AWS SNS access policy statements

AWS 文档有 examples of different SNS access control 配置。

有两个类似的配置示例:

first one 允许将通知从另一个帐户的 S3 存储桶发布到 SNS 主题:

{
  "Effect": "Allow",
   "Principal": { 
    "Service": "s3.amazonaws.com" 
  },
  "Action": "sns:Publish",
  "Resource": "arn:aws:sns:us-east-2:111122223333:MyTopic",
  "Condition": {
    "StringEquals": {
      "AWS:SourceAccount": "444455556666"
    }       
  }
}

second one 允许从另一个帐户的 SES 电子邮件向 SNS 主题发布通知:

{
  "Effect": "Allow",
  "Principal": {
    "Service": "ses.amazonaws.com"
  },
  "Action": "SNS:Publish",
  "Resource": "arn:aws:sns:us-east-2:444455556666:MyTopic",
  "Condition": {
    "StringEquals": {
      "aws:SourceOwner": "111122223333"
    }
  }
}

不同的是第一个例子用的是aws:SourceAccount,第二个例子用的是aws:SourceOwner.

文档中有一个专门的段落称为“aws:SourceAccount versus aws:SourceOwner”,但我仍然不清楚这两个语句之间的区别。

能否说明 aws:SourceAccountaws:SourceOwner 政策声明之间的区别?

1. SourceOwner 用于授予从特定账户访问其他 AWS 服务的权限

例如,我们要定义一个策略,只允许来自帐户 111122223333 的 SES 向主题 444455556666 发布消息:

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__default_statement_ID",
      "Effect": "Allow",
      "Principal": {
        "Service": "ses.amazonaws.com"
      },
      "Action": "SNS:Publish",
      "Resource": "arn:aws:sns:us-east-2
:444455556666:MyTopic",
      "Condition": {
        "StringEquals": {
          "aws:SourceOwner": "111122223333"
        }
      }
    }
  ]
}

2。 SourceAccount 用于授予 IAM 角色从帐户访问主题的权限。

比如我们要定义一个策略,只允许账号444455556666向主题111122223333发布消息:

{
  "Statement": [{
    "Effect": "Allow",
     "Principal": { 
      "AWS": "*"
    },
    "Action": "sns:Publish",
    "Resource": "arn:aws:sns:us-east-2
:111122223333:MyTopic",
    "Condition": {
      "StringEquals": {
        "AWS:SourceAccount": "444455556666"
      }
    }
  }]
}

现在对于第 1 种情况,如果您只有 1 个帐户,则没有意义,因为 SES 将使用与 SNS 相同的帐户。但是如果你有更多的帐户,它带来的好处是你只允许特定帐户的 SES 向你的主​​题发送消息。

希望对您有所帮助。有不清楚的地方欢迎留言,我会尽量解释的。

提供更多信息以使事情更清楚。

  1. 以S3发送SNS消息为例。 对于这种情况,AWS 将使用内部 S3 帐户的凭据并代表您的 帐户 进行调用,而不是来自 资源。因此,我们需要使用 aws:SourceAccount 在策略中执行验证。

  2. 以SES发送SNS消息为例。 对于这种情况,AWS 将使用内部 S3 帐户的凭证并代表您的 资源 进行调用,而不是来自 账户。因此,我们需要在策略中使用 aws:SourceOwner

我建议您逐一参考文档以了解您需要使用哪一个。但我希望你现在明白他们两个之间的区别。

只有当资源的所有者与资源所属的帐户不同时,才能看出差异。这是一个高级设置。这是官方文档的摘录,其中提供了此类设置的示例。

... it is possible for another account to own a resource in your account. For example, the trusting account might allow the trusted account to create new resources, such as creating new objects in an Amazon S3 bucket.

Source