Using service-linked roles for Amazon Inspector
Amazon Inspector uses an AWS Identity and Access Management (IAM) service-linked role named AWSServiceRoleForAmazonInspector2
. This service-linked role is an
IAM role that is linked directly to Amazon Inspector. It is predefined by Amazon Inspector and it
includes all the permissions that Amazon Inspector requires to call other AWS services on your
behalf.
A service-linked role makes setting up Amazon Inspector easier because you don’t have to manually add the necessary permissions. Amazon Inspector defines the permissions of its service-linked role and, unless defined otherwise, only Amazon Inspector can assume the role. The defined permissions include the trust policy and the permissions policy, and that permissions policy cannot be attached to any other IAM entity.
You must configure permissions to allow an IAM entity (such as a group or role) to create, edit, or delete a service-linked role. For more information, see Service-linked role permissions in the IAM User Guide. You can delete a service-linked role only after deleting its related resources. This protects your Amazon Inspector resources because you can't inadvertently remove permission to access the resources.
For information about other services that support service-linked roles, see AWS services that work with IAM and look for the services that have Yes in the Service-linked roles column. Choose a Yes with a link to review the service-linked role documentation for that service.
Service-linked role permissions for Amazon Inspector
Amazon Inspector uses the service-linked role named AWSServiceRoleForAmazonInspector2
. This
service-linked role trusts the inspector2.amazonaws.com
service to assume the
role.
The permissions policy for the role, which is named AmazonInspector2ServiceRolePolicy
, allows
Amazon Inspector to perform tasks such as:
-
Use Amazon Elastic Compute Cloud (Amazon EC2) actions to retrieve information about your instances and network paths.
-
Use AWS Systems Manager actions to retrieve inventory from your Amazon EC2 instances.
-
Use Amazon Elastic Container Registry actions to retrieve information about your container images.
-
Use AWS Lambda actions to retrieve information about your Lambda functions.
-
Use AWS Organizations actions to describe associated accounts.
The role is configured with the following permissions policy.
{ "Version": "2012-10-17", "Statement": [{ "Sid": "TirosPolicy", "Effect": "Allow", "Action": [ "directconnect:DescribeConnections", "directconnect:DescribeDirectConnectGatewayAssociations", "directconnect:DescribeDirectConnectGatewayAttachments", "directconnect:DescribeDirectConnectGateways", "directconnect:DescribeVirtualGateways", "directconnect:DescribeVirtualInterfaces", "ec2:DescribeAvailabilityZones", "ec2:DescribeCustomerGateways", "ec2:DescribeInstances", "ec2:DescribeInternetGateways", "ec2:DescribeManagedPrefixLists", "ec2:DescribeNatGateways", "ec2:DescribeNetworkAcls", "ec2:DescribeNetworkInterfaces", "ec2:DescribePrefixLists", "ec2:DescribeRegions", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeTransitGatewayAttachments", "ec2:DescribeTransitGatewayConnects", "ec2:DescribeTransitGatewayPeeringAttachments", "ec2:DescribeTransitGatewayRouteTables", "ec2:DescribeTransitGatewayVpcAttachments", "ec2:DescribeTransitGateways", "ec2:DescribeVpcEndpointServiceConfigurations", "ec2:DescribeVpcEndpoints", "ec2:DescribeVpcPeeringConnections", "ec2:DescribeVpcs", "ec2:DescribeVpnConnections", "ec2:DescribeVpnGateways", "ec2:GetManagedPrefixListEntries", "ec2:GetTransitGatewayRouteTablePropagations", "ec2:SearchTransitGatewayRoutes", "elasticloadbalancing:DescribeListeners", "elasticloadbalancing:DescribeLoadBalancerAttributes", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeRules", "elasticloadbalancing:DescribeTags", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth", "network-firewall:DescribeFirewall", "network-firewall:DescribeFirewallPolicy", "network-firewall:DescribeResourcePolicy", "network-firewall:DescribeRuleGroup", "network-firewall:ListFirewallPolicies", "network-firewall:ListFirewalls", "network-firewall:ListRuleGroups", "tiros:CreateQuery", "tiros:GetQueryAnswer" ], "Resource": [ "*" ] }, { "Sid": "PackageVulnerabilityScanning", "Effect": "Allow", "Action": [ "ecr:BatchGetImage", "ecr:BatchGetRepositoryScanningConfiguration", "ecr:DescribeImages", "ecr:DescribeRegistry", "ecr:DescribeRepositories", "ecr:GetAuthorizationToken", "ecr:GetDownloadUrlForLayer", "ecr:GetRegistryScanningConfiguration", "ecr:ListImages", "ecr:PutRegistryScanningConfiguration", "organizations:DescribeAccount", "organizations:DescribeOrganization", "organizations:ListAccounts", "ssm:DescribeAssociation", "ssm:DescribeAssociationExecutions", "ssm:DescribeInstanceInformation", "ssm:ListAssociations", "ssm:ListResourceDataSync" ], "Resource": "*" }, { "Sid": "LambdaPackageVulnerabilityScanning", "Effect": "Allow", "Action": [ "lambda:ListFunctions", "lambda:GetFunction", "lambda:GetLayerVersion" ], "Resource": "*" }, { "Sid": "GatherInventory", "Effect": "Allow", "Action": [ "ssm:CreateAssociation", "ssm:StartAssociationsOnce", "ssm:DeleteAssociation", "ssm:UpdateAssociation" ], "Resource": [ "arn:*:ec2:*:*:instance/*", "arn:*:ssm:*:*:document/AmazonInspector2-*", "arn:*:ssm:*:*:document/AWS-GatherSoftwareInventory", "arn:*:ssm:*:*:managed-instance/*", "arn:*:ssm:*:*:association/*" ] }, { "Sid": "DataSyncCleanup", "Effect": "Allow", "Action": [ "ssm:CreateResourceDataSync", "ssm:DeleteResourceDataSync" ], "Resource": [ "arn:*:ssm:*:*:resource-data-sync/InspectorResourceDataSync-do-not-delete" ] }, { "Sid": "ManagedRules", "Effect": "Allow", "Action": [ "events:PutRule", "events:DeleteRule", "events:DescribeRule", "events:ListTargetsByRule", "events:PutTargets", "events:RemoveTargets" ], "Resource": [ "arn:*:events:*:*:rule/DO-NOT-DELETE-AmazonInspector*ManagedRule" ] } ] }
For details about updates to the AmazonInspector2ServiceRolePolicy
policy, see Amazon Inspector updates to AWS managed
policies.
You must configure permissions to allow an IAM entity (such as a user, group, or role) to create, edit, or delete a service-linked role. For more information, see Service-linked role permissions in the IAM User Guide.
Creating a service-linked role for Amazon Inspector
You don't need to manually create a service-linked role. When you activate Amazon Inspector in the AWS Management Console, the AWS CLI, or the AWS API, Amazon Inspector creates the service-linked role for you.
Editing a service-linked role for Amazon Inspector
Amazon Inspector does not allow you to edit the AWSServiceRoleForAmazonInspector2
service-linked role.
After a service-linked role is created, you cannot change the name of the role because various
entities might reference the role. However, you can edit the description of the role by using
IAM. For more information, see Editing
a service-linked role in the IAM User Guide.
Deleting a service-linked role for Amazon Inspector
If you no longer need to use Amazon Inspector, we recommend that you delete the
AWSServiceRoleForAmazonInspector2
service-linked role. Before you can delete the role, you must
deactivate Amazon Inspector in each AWS Region where it's activated. When you deactivate Amazon Inspector, it doesn't
delete the role for you. Therefore, if you activate Amazon Inspector again, it can use the existing role.
That way you don’t have an unused entity that is not actively monitored or maintained.
However, you must clean up the resources for your service-linked role before you can manually
delete it.
If you delete this service-linked role and then need to create it again, you can use the same process to re-create the role in your account. When you activate Amazon Inspector, Amazon Inspector re-creates the service-linked role for you.
If the Amazon Inspector service is using the role when you try to delete the resources, the deletion might fail. If that happens, wait a few minutes and then try the operation again.
You can use the IAM console, the AWS CLI, or the AWS API to delete the
AWSServiceRoleForAmazonInspector2
service-linked role. For more information, see Deleting a service-linked role in the IAM User Guide.