こんにちは。AWS CLIが好きな福島です。
はじめに
マルチアカウントが主流である昨今、監査や分析を目的にログをS3に集約することが多いかと存じます。
単一のAWSアカウントから各種AWSサービスのログをS3に出力する際のバケットポリシーについては、AWSのドキュメントに記載がありますが、 複数のAWSアカウントからログを集約する際のバケットポリシーは、アレンジが必要な場合が多いです。
そのため今回は、複数のAWSアカウントから各種AWSサービスのログをS3に集約する際のバケットポリシーについて、まとめてみました。
前提
- aws:SourceOrgIDを活用し、組織内のアカウントからのアクセスのみを許可します
- Security Hubの以下のコントロールに従い、全てのS3バケットポリシーに「AllowSSLRequestsOnly」を追加します
- [S3.5] S3 汎用バケットではリクエストに SSL を使用する必要があります。
- https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/s3-controls.html#s3-5
ガバナンス系
CloudTrail
Control Towerで構築されるCloudTrailのS3バケットポリシーを参考にします。
参考:監査アカウントの Amazon S3 バケットポリシー - AWS Control Tower
- ポイント
- 本ポリシーは、CloudTrailを組織で有効化する場合に利用可能
- 組織で有効化することにより、
aws:SourceOrgID
ではなく、aws:SourceArn
を利用した制御が可能
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- region: リージョン
- managementAccountID: マネジメントアカウントのAWSアカウントID
- trailName: CloudTrailのトレイル名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSCloudTrailAclCheck20150319", "Effect": "Allow", "Principal": { "Service": [ "cloudtrail.amazonaws.com" ] }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceArn": "arn:aws:cloudtrail:region:managementAccountID:trail/trailName" } } }, { "Sid": "AWSCloudTrailWrite20150319", "Effect": "Allow", "Principal": { "Service": [ "cloudtrail.amazonaws.com" ] }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/AWSLogs/managementAccountID/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceArn": "arn:aws:cloudtrail:region:managementAccountID:trail/trailName" } } }, { "Sid": "AWSCloudTrailOrganizationWrite20150319", "Effect": "Allow", "Principal": { "Service": [ "cloudtrail.amazonaws.com" ] }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/AWSLogs/organizationID/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceArn": "arn:aws:cloudtrail:region:managementAccountID:trail/trailName" } } } ] }
Config
Control Towerで構築されるConfigのS3バケットポリシーを参考にします。
参考:監査アカウントの Amazon S3 バケットポリシー - AWS Control Tower
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSConfigBucketPermissionsCheck", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSConfigBucketExistenceCheck", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSConfigBucketDelivery", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/organizationID/AWSLogs/*/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceOrgID": "organizationID" } } } ] }
補足:Control Towerにより構築されるCloudTrail,Config用のS3バケットポリシー
Control Towerでは、CloudTrail,Configのログ用のS3バケットが生成されます。 CloudTrailとConfigのアクセス許可が混在したポリシーとなりますが、参考として、以下に記載します。
また、以下の値にはアカウントごとに適切な値が代入されます
- ACCOUNTID-REGION
- organizationID
- managementAccountID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION", "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSBucketPermissionsCheck", "Effect": "Allow", "Principal": { "Service": [ "cloudtrail.amazonaws.com", "config.amazonaws.com" ] }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION" }, { "Sid": "AWSConfigBucketExistenceCheck", "Effect": "Allow", "Principal": { "Service": [ "cloudtrail.amazonaws.com", "config.amazonaws.com" ] }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION" }, { "Sid": "AWSBucketDeliveryForConfig", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION/organizationID/AWSLogs/*/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSBucketDeliveryForOrganizationTrail", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "s3:PutObject", "Resource": [ "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION/organizationID/AWSLogs/managementAccountID/*", "arn:aws:s3:::aws-controltower-logs-ACCOUNTID-REGION/organizationID/AWSLogs/organizationID/*" ], "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
Session Manager
以下のドキュメントを参考にします。
参考: Session Manager のログ記録用に一元 S3 バケットを設定する | AWS re:Post
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetEncryptionConfiguration", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "organizationID" } } }, { "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": [ "s3:PutObject", "s3:PutObjectAcl" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "organizationID" } } } ] }
ネットワーク系
VPC Flow Logs
以下のドキュメントを参考にします。
参考:フローログのための Amazon S3 バケットのアクセス許可 - Amazon Virtual Private Cloud
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSLogDeliveryWrite", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSLogDeliveryAclCheck", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
Transit Gateway Flow Logs
以下のドキュメントを参考にします。
参考:Amazon S3 の Transit Gateway フローログレコード - Amazon VPC
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSLogDeliveryWrite", "Effect": "Allow", "Principal": {"Service": "delivery.logs.amazonaws.com"}, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSLogDeliveryCheck", "Effect": "Allow", "Principal": {"Service": "delivery.logs.amazonaws.com"}, "Action": ["s3:GetBucketAcl", "s3:ListBucket"], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
セキュリティ系
GuardDuty
以下のドキュメントを参考にします。
参考:生成された GuardDuty の検出結果を Amazon S3 バケットにエクスポートする - Amazon GuardDuty
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
- optional prefix: GuardDutyのS3バケットに出力する際のプレフィックス
- KMS key ARN: GuardDutyのS3バケットに出力する際のKMSキーARN
{ "Version": "2012-10-17", "Statement": [ { "Sid": "Allow GetBucketLocation", "Effect": "Allow", "Principal": { "Service": "guardduty.amazonaws.com" }, "Action": "s3:GetBucketLocation", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "Allow PutObject", "Effect": "Allow", "Principal": { "Service": "guardduty.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/[optional prefix]/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Sid": "Deny unencrypted object uploads", "Effect": "Deny", "Principal": { "Service": "guardduty.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/[optional prefix]/*", "Condition": { "StringNotEquals": { "s3:x-amz-server-side-encryption": "aws:kms" } } }, { "Sid": "Deny incorrect encryption header", "Effect": "Deny", "Principal": { "Service": "guardduty.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/[optional prefix]/*", "Condition": { "StringNotEquals": { "s3:x-amz-server-side-encryption-aws-kms-key-id": "KMS key ARN" } } }, { "Sid": "Deny non-HTTPS access", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/[optional prefix]/*", "Condition": { "Bool": { "aws:SecureTransport": "false" } } } ] }
Inspector
以下のドキュメントを参考にします。
参考:Amazon Inspector 検出結果レポートのエクスポート - Amazon Inspector
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "allow-inspector", "Effect": "Allow", "Principal": { "Service": "inspector2.amazonaws.com" }, "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:AbortMultipartUpload" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
WAF
以下のドキュメントを参考にします。
- 以下の項目は、実際の値に置き換えてください。
- LOGGING-BUCKET-SUFFIX: S3バケット名のプレフィックス
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Id": "AWSLogDeliveryWrite20150319", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::aws-waf-logs-LOGGING-BUCKET-SUFFIX", "arn:aws:s3:::aws-waf-logs-LOGGING-BUCKET-SUFFIX/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSLogDeliveryWrite", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::aws-waf-logs-LOGGING-BUCKET-SUFFIX/AWSLogs/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceOrgID": "organizationID" } } }, { "Sid": "AWSLogDeliveryAclCheck", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::aws-waf-logs-LOGGING-BUCKET-SUFFIX", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
コンテンツ配信
ELB
以下のドキュメントを参考にします。
参考:Application Load Balancer のアクセスログを有効にする - エラスティックロードバランシング
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
- optional prefix: GuardDutyのS3バケットに出力する際のプレフィックス
- elb-account-id: リージョンの Elastic Load Balancing AWS アカウント の の ID
- 例
- アジアパシフィック (東京) — 582318560864
- アジアパシフィック (大阪) – 383597477331
- 米国東部 (バージニア北部) – 127311923021
- 米国西部 (オレゴン) — 797873946194
- 例
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::elb-account-id:root" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/prefix/AWSLogs/*" "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
CloudFront
CloudFrontのドキュメントには以下の記載があります。
標準ログ記録 (v2) を設定する - Amazon CloudFront
バケットを作成したら、標準ログ記録を許可するために必要なアクセス許可が必要です。 詳細については「Amazon CloudWatch Logs User Guide」の「Logs sent to Amazon S3」を参照してください。
そのため、S3バケットポリシーは以下のドキュメントを参考にします。
参考:Enable logging from AWS services - Amazon CloudWatch Logs
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
{ "Version": "2012-10-17", "Id": "AWSLogDeliveryWrite20150319", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Sid": "AWSLogDeliveryWrite", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/AWSLogs/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
Route 53 クエリログ
以下のドキュメントを参考にします。
参考:AWS Resolver クエリログを送信できる リソース - Amazon Route 53
- 以下の項目は、実際の値に置き換えてください。
- amzn-s3-demo-bucket: S3バケット名
- organizationID: AWS Organizationsの組織ID
- CentralAccountID: 中央アカウントのAWSアカウントID
ドキュメントに記載がある通り、クエリログはCentralAccountIDで設定をした上で各AWSアカウントにはRAMで共有することが推奨されています。
組織の中心的な S3 バケットにログを保存する場合は、(中心的バケットへの書き込みに必要なアクセス許可を持つ) 中央のアカウントからクエリログ記録を設定した上で、RAM を使用しながら、 アカウント全体でその構成を共有することをお勧めします。
{ "Version": "2012-10-17", "Id": "CrossAccountAccess", "Statement": [ { "Sid": "AllowSSLRequestsOnly", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } }, { "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/AWSLogs/*", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } }, { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::CentralAccountID:root" }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringEquals": { "aws:SourceOrgID": "organizationID" } } } ] }
終わりに
今回は、複数のAWSアカウントから各種AWSサービスのログをS3に集約する際のバケットポリシーについて、まとめてみました。 どなたかのお役に立てれば幸いです。