証跡取得ケースとは別の話でConsoleやCLIで、マルチアカウントのGuardDutyのアクティビティ状況を集約する機能
証跡取得ケースも絡めて記載はしている。
・[②組織内の特定アカウントで証跡を集中管理]を例に設定例を記載します。
・組織全体を集中管理(全てのリージョンを対象に記載)
・サービス-GuardDutyの信頼されたアクセスを有効にする
・組織内の特定アカウントにGuardDutyの管理を委任する
・組織内の特定アカウントにGuardDutyのアクセス許可を委任する
・GuardDuty用のKeyを作成する
・GuardDuty記録用のS3バケットを作成する
・GuardDutyのエクスポートオプションを設定する
・GurdDutyの自動有効化と現状のメンバ承認を行う
CloudShellから以下を実行する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# サービス-GuardDutyの信頼されたアクセスを有効にする aws organizations enable -aws-service-access --service-principal=guardduty.amazonaws.com #特定アカウントにGuardDutyの管理を委任する ACCOUNT_ID=(委任先のAWSアカウントID 12桁) aws organizations register-delegated-administrator --account- id ${ACCOUNT_ID} --service-principal guardduty.amazonaws.com #全てのリージョンで組織内の特定アカウントにGuardDutyのアクセス許可を委任する ACCOUNT_ID=(委任先のAWSアカウントID 12桁) aws ec2 describe-regions --query "Regions[].[RegionName]" --output text \ | while read region; do echo "##### enable organization admin account in ${region}" aws --region ${region} guardduty enable -organization-admin-account --admin-account- id ${ACCOUNT_ID} done |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
{ "Version" : "2012-10-17" , "Statement" : [ { "Sid" : "Enable User permissions" , "Effect" : "Allow" , "Principal" : { "AWS" : "arn:aws:iam::[委任先アカウントID]:root" }, "Action" : "kms:*" , "Resource" : "*" }, { "Sid" : "Allow GuardDuty to use the key" , "Effect" : "Allow" , "Principal" : { "Service" : "guardduty.amazonaws.com" }, "Action" : "kms:GenerateDataKey" , "Resource" : "*" , "Condition" : { "StringEquals" : { "aws:SourceAccount" : [ "[委任先アカウントID]" ] } } } ] } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
{ "Version" : "2012-10-17" , "Statement" : [ { "Sid" : "AllowGuardDutygetBucketLocation" , "Effect" : "Allow" , "Principal" : { "Service" : "guardduty.amazonaws.com" }, "Action" : [ "s3:GetBucketLocation" , "s3:ListBucket" ], "Resource" : "arn:aws:s3:::[GuardDuty用S3バケット]" , "Condition" : { "StringEquals" : { "aws:SourceAccount" : [ "[委任先アカウントID]" ] } } }, { "Sid" : "AllowGuardDutyPutObject" , "Effect" : "Allow" , "Principal" : { "Service" : "guardduty.amazonaws.com" }, "Action" : "s3:PutObject" , "Resource" : "arn:aws:s3:::[GuardDuty用S3バケット]/*" , "Condition" : { "StringEquals" : { "aws:SourceAccount" : [ "[委任先アカウントID]" ] } } }, { "Sid" : "DenyUnencryptedUploadsThis is optional" , "Effect" : "Deny" , "Principal" : { "Service" : "guardduty.amazonaws.com" }, "Action" : "s3:PutObject" , "Resource" : "arn:aws:s3:::[GuardDuty用S3バケット]/*" , "Condition" : { "StringNotEquals" : { "s3:x-amz-server-side-encryption" : "aws:kms" } } }, { "Sid" : "DenyIncorrectHeaderThis is optional" , "Effect" : "Deny" , "Principal" : { "Service" : "guardduty.amazonaws.com" }, "Action" : "s3:PutObject" , "Resource" : "arn:aws:s3:::[GuardDuty用S3バケット]/*" , "Condition" : { "StringNotEquals" : { "s3:x-amz-server-side-encryption-aws-kms-key-id" : "arn:aws:kms:[GuardDuty用S3バケットのリージョン名]:[委任先アカウントID]:key/[キーID]" } } }, { "Sid" : "Deny non SSL request" , "Effect" : "Deny" , "Principal" : "*" , "Action" : "s3:*" , "Resource" : [ "arn:aws:s3:::[GuardDuty用S3バケット]" , "arn:aws:s3:::[GuardDuty用S3バケット]/*" ], "Condition" : { "Bool" : { "aws:SecureTransport" : "false" } } } ] } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#全てのリージョンでGurdDutyのエクスポート先を設定する ACCOUNT_ID=(委任先のAWSアカウントID 12桁) DESTINATION_ARN=arn:aws:s3:::aggregation-${ACCOUNT_ID}-guardduty-log BUCKET_REGION=(S3バケットのリージョン名) aws ec2 describe-regions --query "Regions[].[RegionName]" --output text \ | while read region; do echo "## enable guard duty setting in ${region}" DETECTOR_ID=`aws --region ${region} guardduty list-detectors --query 'DetectorIds' --output text` KMS_KEY_ARN=`arn:aws:kms:${BUCKET_REGION}:${ACCOUNT_ID}: alias /GuardDutyKey ` aws --region ${region} guardduty create-publishing-destination --detector- id ${DETECTOR_ID} --destination- type S3 --destination-properties DestinationArn= "${DESTINATION_ARN}" ,KmsKeyArn= "${KMS_KEY_ARN}" done |
1 2 3 4 5 6 7 8 9 10 |
#全てのリージョンでGurdDutyの自動有効化と現状のメンバ承認を行う ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text) aws ec2 describe-regions --query "Regions[].[RegionName]" --output text \ | while read region; do echo "## create member in ${region}" DETECTOR_ID=`aws --region ${region} guardduty list-detectors --query 'DetectorIds' --output text` aws --region ${region} guardduty update-organization-configuration --auto- enable --detector- id ${DETECTOR_ID} MEMBER_ID=`aws organizations list-accounts --query "Accounts[?Id!='${ACCOUNT_ID}'].[Id,Email]" --output text | awk '{print "AccountId=" $1 "," "Email=" $2}' ` aws --region ${region} guardduty create-members --account-details $MEMBER_ID --detector- id ${DETECTOR_ID} done |