【问题标题】:Create Policy in Cloudformation Granting Access to s3 Buckets From Separate AWS Account在 Cloudformation 中创建策略,授予从单独的 AWS 账户访问 s3 存储桶的权限
【发布时间】:2018-02-16 00:16:32
【问题描述】:

我已阅读“Specifying Principals in a Policy”文档:https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-bucket-user-policy-specifying-principal-intro.html,并从中推断出一些行为以及其他未专门处理 Cloudformation 的 SO(如 aws lambda function getting access denied when getObject from s3)问题。

当我尝试创建一个授予外部角色访问本地存储桶的策略时,我仍然对此错误感到困惑。 Cloudformation 的错误是:Policy document should not specify a principal.

情况细分

我有两个 AWS 账户。账户 A 创建了一个存储桶,我想授予账户 B 对其的写入权限。

在账户 A Cloudformation 中我创建了一个策略,授予账户 B 角色访问所述存储桶的权限。来自https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html 的指南。该角色存在于帐户 B。

AccountBWriteToS3Policy: Type: 'AWS::IAM::Policy' Properties: PolicyName: AccountBWriteToS3Policy PolicyDocument: Version: 2012-10-17 Statement: - Principal: AWS: 'arn:aws:iam::123456789876:role/AccountBRole' Effect: Allow Action: - 's3:PutObject' - 's3:ListBucket' Resource: !Sub - '${bucketArn}/*' - bucketArn: !GetAtt - AccountABucket - Arn Roles: - AccountARole

但是,cloudformation 无法执行,并回滚并出现错误 Policy document should not specify a principal.

我很困惑。

谁能解释这个错误?

谁能指明前进的道路?

这似乎是一个简单而常见的需求,在许多示例中都有介绍。也许我应该在存储桶声明本身中指定策略,而不是创建帐户范围的策略?

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation amazon-iam


    【解决方案1】:

    您需要创建一个具有“信任策略”的角色,该角色具有原则,然后是“权限策略”,以允许对 S3 存储桶进行读/写访问。

    这是来自我的 Cloudformation 的 sn-p。

      Role:
        Type: "AWS::IAM::Role"
        Properties:
          RoleName: !Sub '${RuleName}-Role'
          Path: "/"     
          AssumeRolePolicyDocument:
            Version: '2012-10-17'
            Statement:
            - Effect: Allow
              Principal: !Sub 'arn:aws:iam::${AccountID}:user/*'
              Action: sts:AssumeRole      
      RolePolicies:
        Type: "AWS::IAM::ManagedPolicy"
        Properties:
          ManagedPolicyName: !Sub '${RuleName}-RolePolicies'
          Roles:
            - Ref: "Role"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:       
            - Effect: Allow
              Action:
              - s3:Get*
              - s3:Put*
              - s3:List*
              - s3:AbortMultipartUpload       
              Resource:
              - !Ref Bucket
    

    参考:Cross account tutorial

    【讨论】:

    • 成功了,谢谢!看起来角色可以有委托人(可能是其他角色),而策略只指定操作
    猜你喜欢
    • 1970-01-01
    • 2013-10-31
    • 2022-01-17
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2019-04-23
    相关资源
    最近更新 更多