01 Amazon GuardDuty requires permissions to perform malware scans on your behalf. To implement the required permissions, create and assign an IAM role. Define the trust relationship policy for the required IAM role and save the policy document to a new JSON file named cc-iam-role-trust-policy.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "malware-protection-plan.guardduty.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
02 Run create-role command (OSX/Linux/UNIX) to create a new IAM role using the trust relationship policy defined at the previous step (i.e. cc-iam-role-trust-policy.json):
aws iam create-role
--role-name MalwareProtectionIamRole
--assume-role-policy-document file://cc-iam-role-trust-policy.json
03 The command output should return the information available for the new IAM role:
{
"Role": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "malware-protection-plan.guardduty.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"RoleId": "ABCDABCDABCDABCDABCDA",
"CreateDate": "2024-11-12T15:00:00.002Z",
"RoleName": "MalwareProtectionIamRole",
"Path": "/",
"Arn": "arn:aws:iam::123456789012:role/MalwareProtectionIamRole"
}
}
04 Define the access permissions for your new IAM role and save the policy document to a new JSON file named cc-iam-role-access-policy.json. Replace the \<aws-account-id\> and \<bucket-name\> placeholders with your own values:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowManagedRuleToSendS3EventsToGuardDuty",
"Effect": "Allow",
"Action": [
"events:PutRule"
],
"Resource": [
"arn:aws:events:us-east-1:<aws-account-id>:rule/DO-NOT-DELETE-AmazonGuardDutyMalwareProtectionS3*"
],
"Condition": {
"StringEquals": {
"events:ManagedBy": "malware-protection-plan.guardduty.amazonaws.com"
},
"ForAllValues:StringEquals": {
"events:source": "aws.s3",
"events:detail-type": [
"Object Created",
"AWS API Call via CloudTrail"
]
},
"Null": {
"events:source": "false",
"events:detail-type": "false"
}
}
},
{
"Sid": "AllowUpdateTargetAndDeleteManagedRule",
"Effect": "Allow",
"Action": [
"events:DeleteRule",
"events:PutTargets",
"events:RemoveTargets"
],
"Resource": [
"arn:aws:events:us-east-1:<aws-account-id>:rule/DO-NOT-DELETE-AmazonGuardDutyMalwareProtectionS3*"
],
"Condition": {
"StringEquals": {
"events:ManagedBy": "malware-protection-plan.guardduty.amazonaws.com"
}
}
},
{
"Sid": "AllowGuardDutyToMonitorEventBridgeManagedRule",
"Effect": "Allow",
"Action": [
"events:DescribeRule",
"events:ListTargetsByRule"
],
"Resource": [
"arn:aws:events:us-east-1:<aws-account-id>:rule/DO-NOT-DELETE-AmazonGuardDutyMalwareProtectionS3*"
]
},
{
"Sid": "AllowEnableS3EventBridgeEvents",
"Effect": "Allow",
"Action": [
"s3:PutBucketNotification",
"s3:GetBucketNotification"
],
"Resource": [
"arn:aws:s3:::<bucket-name>"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "<aws-account-id>"
}
}
},
{
"Sid": "AllowPostScanTag",
"Effect": "Allow",
"Action": [
"s3:GetObjectTagging",
"s3:GetObjectVersionTagging",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
],
"Resource": [
"arn:aws:s3:::<bucket-name>/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "<aws-account-id>"
}
}
},
{
"Sid": "AllowPutValidationObject",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::<bucket-name>/malware-protection-resource-validation-object"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "<aws-account-id>"
}
}
},
{
"Sid": "AllowCheckBucketOwnership",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::<bucket-name>"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "<aws-account-id>"
}
}
},
{
"Sid": "AllowMalwareScan",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::<bucket-name>/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "<aws-account-id>"
}
}
}
]
}
05 Run create-policy command (OSX/Linux/UNIX) to create a new Amazon IAM customer-managed policy using the policy document defined in the previous step:
aws iam create-policy
--policy-name MalwareProtectionAccessPolicy
--policy-document file://cc-iam-role-access-policy.json
--query 'Policy.Arn'
06 The command output should return the ARN of the newly created IAM policy:
"arn:aws:iam::123456789012:policy/MalwareProtectionAccessPolicy"
07 Run attach-role-policy command (OSX/Linux/UNIX) to attach the customer-managed policy created at the previous steps to your new IAM role (if successful, the command does not produce an output):
aws iam attach-role-policy
--policy-arn "arn:aws:iam::123456789012:policy/MalwareProtectionAccessPolicy"
--role-name MalwareProtectionIamRole
08 Run create-malware-protection-plan command (OSX/Linux/UNIX) to enable Malware Protection for S3, for the specified Amazon S3 bucket (replace \ with the name of the S3 bucket that you want to protect). The following command example enables Malware Protection for S3 with scanned S3 object tagging. This will create a Malware Protection plan for the selected S3 bucket:
aws guardduty create-malware-protection-plan
--role "arn:aws:iam::123456789012:role/MalwareProtectionIamRole"
--protected-resource "S3Bucket"={"BucketName"="<bucket-name>"}
--actions "Tagging"={"Status"="ENABLED"}
09 The command output should return the ID of the newly created Malware Protection plan:
{
"MalwareProtectionPlanId": "abcd1234abcd1234abcd"
}
10 Repeat steps no. 8 and 9 for each Amazon S3 bucket that you want to protect with the Malware Protection feature.
11 Change the AWS region by updating the --region command parameter value and repeat step no. 1 - 10 to enable the Malware Protection for S3 feature for other AWS cloud regions.