How Amazon S3 works with IAM
Before you use IAM to manage access to Amazon S3, learn what IAM features are available to use with Amazon S3.
| IAM feature | Amazon S3 support |
|---|---|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Partial |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Partial |
To get a high-level view of how Amazon S3 and other AWS services work with most IAM features, see AWS services that work with IAM in the IAM User Guide.
For more information about the permissions to S3 API operations by S3 resource types, see Required permissions for Amazon S3 API operations.
Identity-based policies for Amazon S3
Supports identity-based policies: Yes
Identity-based policies are JSON permissions policy documents that you can attach to an identity, such as an IAM user, group of users, or role. These policies control what actions users and roles can perform, on which resources, and under what conditions. To learn how to create an identity-based policy, see Define custom IAM permissions with customer managed policies in the IAM User Guide.
With IAM identity-based policies, you can specify allowed or denied actions and resources as well as the conditions under which actions are allowed or denied. To learn about all of the elements that you can use in a JSON policy, see IAM JSON policy elements reference in the IAM User Guide.
Identity-based policy examples for Amazon S3
To view examples of Amazon S3 identity-based policies, see Identity-based policies for Amazon S3.
Resource-based policies within Amazon S3
Supports resource-based policies: Yes
Resource-based policies are JSON policy documents that you attach to a resource. Examples of resource-based policies are IAM role trust policies and Amazon S3 bucket policies. In services that support resource-based policies, service administrators can use them to control access to a specific resource. For the resource where the policy is attached, the policy defines what actions a specified principal can perform on that resource and under what conditions. You must specify a principal in a resource-based policy. Principals can include accounts, users, roles, federated users, or AWS services.
To enable cross-account access, you can specify an entire account or IAM entities in another account as the principal in a resource-based policy. For more information, see Cross account resource access in IAM in the IAM User Guide.
The Amazon S3 service supports bucket policies, access points policies, and access grants:
-
Bucket policies are resource-based policies that are attached to an Amazon S3 bucket. A bucket policy defines which principals can perform actions on the bucket.
-
Access point policies are resource-based polices that are evaluated in conjunction with the underlying bucket policy.
-
Access grants are a simplified model for defining access permissions to data in Amazon S3 by prefix, bucket, or object. For information about S3 Access Grants, see Managing access with S3 Access Grants.
Principals for bucket policies
The Principal element specifies the user, account, service, or other
entity that is either allowed or denied access to a resource.
The following are examples of specifying Principal. For more
information, see Principal
in the IAM User Guide.
Grant permissions to an AWS account
To grant permissions to an AWS account, identify the account using the following format.
"AWS":"account-ARN"
The following are examples.
"Principal":{"AWS":"arn:aws:iam::AccountIDWithoutHyphens:root"}
"Principal":{"AWS":["arn:aws:iam::AccountID1WithoutHyphens:root","arn:aws:iam::AccountID2WithoutHyphens:root"]}
Note
The examples above grant permissions to the root user, which delegates permissions to the account level. However, IAM policies are still required on the specific roles and users in the account.
Grant permissions to an IAM user
To grant permission to an IAM user within your account, you must provide an
"AWS":" name-value
pair.user-ARN"
"Principal":{"AWS":"arn:aws:iam::account-number-without-hyphens:user/username"}
For detailed examples that provide step-by-step instructions, see Example 1: Bucket owner granting its users bucket permissions and Example 3: Bucket owner granting permissions to objects it does not own.
Note
If an IAM identity is deleted after you update your bucket policy, the bucket policy will show a unique identifier in the principal element instead of an ARN. These unique IDs are never reused, so you can safely remove principals with unique identifiers from all of your policy statements. For more information about unique identifiers, see IAM identifiers in the IAM User Guide.
Grant anonymous permissions
Warning
Use caution when granting anonymous access to your Amazon S3 bucket. When you grant anonymous access, anyone in the world can access your bucket. We highly recommend that you never grant any kind of anonymous write access to your S3 bucket.
To grant permission to everyone, also referred as anonymous access, you set
the wildcard ("*") as the Principal value. For
example, if you configure your bucket as a website, you want all the objects in
the bucket to be publicly accessible.
"Principal":"*"
"Principal":{"AWS":"*"}
Using "Principal": "*" with an Allow effect in a
resource-based policy allows anyone, even if they’re not signed in to AWS, to
access your resource.
Using "Principal" : { "AWS" : "*" } with an Allow
effect in a resource-based policy allows any root user, IAM user, assumed-role
session, or federated user in any account in the same partition to access your
resource.
For anonymous users, these two methods are equivalent. For more information, see All principals in the IAM User Guide.
You cannot use a wildcard to match part of a principal name or ARN.
Important
In AWS access control policies, the Principals "*" and {"AWS": "*"} behave identically.
Restrict resource permissions
You can also use resource policy to restrict access to resources that would otherwise be available to IAM principals. Use a Deny statement to prevent access.
The following example blocks access if a secure transport protocol isn’t used:
Using "Principal": "*" so that this restriction applies to everyone is a best practice for this policy, instead of attempting to deny access only to specific accounts or principals using this method.
Require access through CloudFront URLs
You can require that your users access your Amazon S3 content only by using CloudFront URLs instead of Amazon S3 URLs. To do this, create a CloudFront origin access control (OAC). Then, change the permissions on your S3 data. In your bucket policy, you can set CloudFront as the Principal as follows:
"Principal":{"Service":"cloudfront.amazonaws.com"}
Use a Condition element in the policy to allow CloudFront to access the bucket only when the request is on behalf of the CloudFront distribution that contains the S3 origin.
"Condition": { "StringEquals": { "AWS:SourceArn": "arn:aws:cloudfront::111122223333:distribution/CloudFront-distribution-ID" } }
For more information about requiring S3 access through CloudFront URLs, see Restricting access to an Amazon Simple Storage Service origin in the Amazon CloudFront Developer Guide. For more information about the security and privacy benefits of using Amazon CloudFront, see Configuring secure access and restricting access to content.
Resource-based policy examples for Amazon S3
To view policy examples for Amazon S3 buckets, see Bucket policies for Amazon S3.
To view policy examples for access points, see Configuring IAM policies for using access points.
Policy actions for Amazon S3
Supports policy actions: Yes
Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.
The Action element of a JSON policy describes the
actions that you can use to allow or deny access in a policy. Include actions in a policy to grant permissions to perform the associated operation.
The following shows different types of mapping relationship between S3 API operations and the required policy actions.
One-to-one mapping with the same name. For example, to use the
PutBucketPolicyAPI operation, thes3:PutBucketPolicypolicy action is required.One-to-one mapping with different names. For example, to use the
ListObjectsV2API operation, thes3:ListBucketpolicy action is required.One-to-many mapping. For example, to use the
HeadObjectAPI operation, thes3:GetObjectis required. Also, when you use S3 Object Lock and want to get an object's Legal Hold status or retention settings, the correspondings3:GetObjectLegalHoldors3:GetObjectRetentionpolicy actions are also required before you can use theHeadObjectAPI operation.Many-to-one mapping. For example, to use the
ListObjectsV2orHeadBucketAPI operations, thes3:ListBucketpolicy action is required.
To see a list of Amazon S3 actions for use in policies, see Actions defined by Amazon S3 in the Service Authorization Reference. For a complete list of Amazon S3 API operations, see Amazon S3 API Actions in the Amazon Simple Storage Service API Reference.
For more information about the permissions to S3 API operations by S3 resource types, see Required permissions for Amazon S3 API operations.
Policy actions in Amazon S3 use the following prefix before the action: