Using service-linked roles for AWS CloudTrail - AWS CloudTrail

Using service-linked roles for AWS CloudTrail

AWS CloudTrail uses AWS Identity and Access Management (IAM) service-linked roles. A service-linked role is a unique type of IAM role that is linked directly to CloudTrail. Service-linked roles are predefined by CloudTrail and include all the permissions that the service requires to call other AWS services on your behalf.

A service-linked role makes setting up CloudTrail easier because you don’t have to manually add the necessary permissions. CloudTrail defines the permissions of its service-linked roles, and unless defined otherwise, only CloudTrail can assume its roles. The defined permissions include the trust policy and the permissions policy, and that permissions policy cannot be attached to any other IAM entity.

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 Role column. Choose a Yes with a link to view the service-linked role documentation for that service.

Service-linked role permissions for CloudTrail

CloudTrail uses the service-linked role named AWSServiceRoleForCloudTrail – This service linked role is used for supporting organization trails and organization event data stores.

The AWSServiceRoleForCloudTrail service-linked role trusts the following services to assume the role:

  • cloudtrail.amazonaws.com

This role is used to support the creation and management of CloudTrail organization trails and CloudTrail Lake organization event data stores in CloudTrail. For more information, see Creating a trail for an organization.

The CloudTrailServiceRolePolicy policy attached to the role allows CloudTrail to complete the following actions on the specified resources:

  • Actions on all CloudTrail resources:

    • All

  • Actions on all AWS Organizations resources:

    • organizations:DescribeAccount

    • organizations:DescribeOrganization

    • organizations:ListAccounts

    • organizations:ListAWSServiceAccessForOrganization

  • Actions on all Organizations resources for the CloudTrail service principal to list the delegated administrators for the organization:

    • organizations:ListDelegatedAdministrators

  • Actions for disabling Lake federation on an organization event data store:

    • glue:DeleteTable

    • lakeformation:DeRegisterResource

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 CloudTrail

You don't need to manually create a service-linked role. When you create an organization trail or organization event data store, or add a delegated administrator in the CloudTrail console, or by using the AWS CLI or API operation, CloudTrail creates the service-linked role for you if it does not already exist.

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 create an organization trail or organization event data store, or add a delegated administrator, CloudTrail creates the service-linked role for you again.

Editing a service-linked role for CloudTrail

CloudTrail does not allow you to edit the AWSServiceRoleForCloudTrail service-linked role. After you create a service-linked role, you cannot change the name of the role because various entities might reference the role. However, you can edit the description of the role using IAM. For more information, see Editing a Service-Linked Role in the IAM User Guide.

Deleting a service-linked role for CloudTrail

You don't need to manually delete the AWSServiceRoleForCloudTrail role. If an AWS account is removed from an Organizations organization, the AWSServiceRoleForCloudTrail role is automatically removed from that AWS account. You cannot detach or remove policies from the AWSServiceRoleForCloudTrail service-linked role in an organization management account without removing the account from the organization.

You can also use the IAM console, the AWS CLI or the AWS API to manually delete the service-linked role. To do this, you must first manually clean up the resources for your service-linked role, and then you can manually delete it.

Note

If the CloudTrail service is using the role when you try to delete the resources, then deletion might fail. If that happens, wait for a few minutes and try the operation again.

To remove a resource being used by the AWSServiceRoleForCloudTrail role, you can do one of the following:

To manually delete the service-linked role using IAM

Use the IAM console, the AWS CLI, or the AWS API to delete the AWSServiceRoleForCloudTrail service-linked role. For more information, see Deleting a service-linked role in the IAM User Guide.

Supported Regions for CloudTrail service-linked roles

CloudTrail supports using service-linked roles in all of the AWS Regions where CloudTrail and Organizations are both available. For more information, see AWS service endpoints in the AWS General Reference.