0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Amazon S3 クロスアカウントバケットポリシー設定パターン

Posted at

なんか混乱してくるので整理しました。

アクセス元アカウント ID で制限

別のアカウントから IAM role を使用したアクセスを許可する場合は、Principal にアカウント ID を指定します。

Parameters:
  TestBucket:
    Type: AWS::S3::Bucket
  TestBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref TestBucket
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Sid: TestBucketPermissions
            Effect: Allow
            Action: s3:*
            Resource:
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}"
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}/*"
            Principal:
              AWS:
                - (アカウント ID)

アクセス元を Organizations に制限

Organizations のすべてのアカウントからのアクセスを許可する場合は、Conditionaws:PrincipalOrgID を指定します。

Parameters:
  TestBucket:
    Type: AWS::S3::Bucket
  TestBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref TestBucket
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Sid: TestBucketPermissions
            Effect: Allow
            Action: s3:*
            Resource:
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}"
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}/*"
            Principal:
              AWS: "*"
            Condition:
              StringEquals:
                aws:PrincipalOrgID: (Organization ID)

サービスプリンシパルによるアクセス元アカウントで制限

Service-linked role を使用したサービスからのアクセスを許可する場合は、Principal にサービスプリンシパルを指定し、アクセス元アカウントは Conditionaws:SourceAccount で指定します。aws:PrincipalOrgID で Organization を指定することは使用できません。

Parameters:
  TestBucket:
    Type: AWS::S3::Bucket
  TestBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref TestBucket
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Sid: TestBucketPermissions
            Effect: Allow
            Action: s3:*
            Resource:
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}"
              - !Sub "arn:${AWS::Partition}:s3:::${TestBucket}/*"
            Principal:
              Service:
                - config.amazonaws.com
            Condition:
              StringEquals:
                aws:SourceAccount:
                  - (アカウント ID)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?