Create grants - Amazon Simple Storage Service
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Create grants

An individual access grant in an S3 Access Grants instance allows a specific identity—an AWS Identity and Access Management (IAM) principal, or a user or group in a corporate directory—to get access within a location that is registered in your S3 Access Grants instance. A location maps buckets or prefixes to an IAM role. S3 Access Grants assumes this IAM role to vend temporary credentials to grantees.

After you register at least one location in your S3 Access Grants instance, you can create an access grant.

The grantee can be an IAM user or role, a directory user or group, or an attribute. A directory user or group comes from your corporate directory. Your users can sign in through AWS IAM Identity Center or through IAM federation with your external identity provider (IdP). For more information, see S3 Access Grants and corporate directory identities.

For a directory user or group, you enter one identifier. The identifier can be either of the following.

  • A name. For a user, this is the subject that IAM sets from your IdP token, for example, 00u1a2b3c4EXAMPLE. For a group, this is the group's display name in IAM Identity Center, for example, finance-analysts.

  • The ID that IAM Identity Center uses for the user or group, for example, a1b2c3d4-5678-90ab-cdef-EXAMPLE11111. For more information about how to view user information in IAM Identity Center, see View user and group assignments in the AWS IAM Identity Center user guide.

S3 Access Grants stores the identifier exactly as you enter it. When a user requests access, S3 Access Grants matches grants that use the user's name and grants that use the user's IAM Identity Center ID. Matching is exact and case sensitive. Leading zeros, hyphens, and capitalization must match the value in the user's session.

An attribute grant gives access to every federated user whose IdP token contains a specific claim and value. The identifier has the form aws:TransactionContext/IdentityProvider/key=value, for example, aws:TransactionContext/IdentityProvider/department=Finance. Each attribute grant contains one key and one value. S3 Access Grants matches the key and value exactly, and the comparison is case sensitive.

S3 Access Grants doesn't check that the identifier belongs to a real user, group, or attribute when you create a grant. A successful request means that S3 Access Grants saved the grant. It doesn't mean that the grant matches a user. For the cases where a saved grant doesn't match, see Why a saved grant might not give access.

An application-scoped grant limits a grant to one IAM Identity Center application. Application-scoped grants match only users who sign in through an IAM Identity Center instance that isn't opted in to the simplified experience for trusted identity propagation. With the simplified experience, IAM Identity Center adds the user's identity to each AWS session. Application-scoped grants don't match users who sign in through IAM federation or through an IAM Identity Center instance that is opted in to the simplified experience. You can create an application-scoped grant only for a directory user or group, and only if your S3 Access Grants instance is associated with an IAM Identity Center instance that isn't opted in. Otherwise, CreateAccessGrant rejects the request and the grant isn't created. You can create application-scoped grants in the Amazon S3 console, the AWS CLI, the Amazon S3 REST API, or the AWS SDKs.

You can grant access to a bucket, a prefix, or an object. A prefix in Amazon S3 is a string of characters in the beginning of an object key name that is used to organize objects within a bucket. This can be any string of allowed characters, for example, object key names in your bucket that start with the engineering/ prefix.

Subprefix

When granting access to a registered location, you can use the Subprefix field to narrow the scope of access to a subset of the location scope. If the registered location that you choose for the grant is the default S3 path (s3://), you must narrow the grant scope. You cannot create an access grant for the default location (s3://), which would give the grantee access to every bucket in an AWS Region. Instead, you must narrow the grant scope to one of the following:

  • A bucket: s3://bucket/*

  • A prefix within a bucket: s3://bucket/prefix*

  • A prefix within a prefix: s3://bucket/prefixA/prefixB*

  • An object: s3://bucket/object-key-name

If you are creating an access grant where the registered location is a bucket, you can pass one of the following in the Subprefix field to narrow the grant scope:

  • A prefix within the bucket: prefix*

  • A prefix within a prefix: prefixA/prefixB*

  • An object: /object-key-name

After you create the grant, the grant scope that's displayed in the Amazon S3 console or the GrantScope that is returned in the API or AWS Command Line Interface (AWS CLI) response is the result of concatenating the location path with the Subprefix. Make sure that this concatenated path maps correctly to the S3 bucket, prefix, or object to which you want to grant access.

Note
  • If you need to create an access grant that grants access to only one object, you must specify that the grant type is for an object. To do this in an API call or a CLI command, pass the s3PrefixType parameter with the value Object. In the Amazon S3 console, when you create the grant, after you select a location, under Grant Scope, select the Grant scope is an object checkbox.

  • You cannot create a grant to a bucket if the bucket does not yet exist. However, you can create a grant to a prefix that does not yet exist.

  • For the maximum number of grants that you can create in your S3 Access Grants instance, see S3 Access Grants limitations.

Why a saved grant might not give access

When you create a grant, S3 Access Grants doesn't check that the identifier belongs to a real user, group, or attribute. A successful request means that the grant is saved. It doesn't mean that the grant matches anyone. If a user can't get the access that you expect, check for the following causes.

The identifier doesn't match the user's session

S3 Access Grants compares identifiers exactly, and the comparison is case sensitive. A grant doesn't match when:

  • The value is different in any way. For example, the grant uses 00U1A2B3C4EXAMPLE but the session has 00u1a2b3c4EXAMPLE. Update the grant to match the value that your identity provider sends.

  • You changed which identity provider claim IAM maps to the subject, for example, from email to an immutable user ID. Grants on the old values stop matching. Create new grants that use the new values.

Some grants work only with certain sign-in methods

Some grants rely on information that only certain sign-in methods include in the user's session, such as group membership or identity provider attributes. If the session doesn't include that information, the grant doesn't match.

For users who sign in through IAM federation:

  • If the IAM identity provider isn't linked to an IAM Identity Center directory, the session has no group membership and no IAM Identity Center user ID. Group grants and grants that use an IAM Identity Center user or group ID don't match. Grant access by user name or attribute instead, or link the IAM identity provider to an IAM Identity Center directory.

  • If the user's subject isn't a user name in IAM Identity Center, S3 Access Grants denies the request, and no grant applies, not even grants for the IAM role. This applies when the IAM identity provider is linked to a directory. To fix this, add the user to IAM Identity Center with a user name that matches their subject.

Attribute grants match only sessions that your application gets through IAM federation, with AssumeRoleWithWebIdentity or AssumeRoleWithSAML. IAM adds the claims from the identity provider's token, such as department=Finance, to these sessions, including when the IAM identity provider is linked to an IAM Identity Center directory. Sessions that your application gets through IAM Identity Center don't include these claims, even when IAM Identity Center uses the same external identity provider as its identity source. For users whose sessions come from IAM Identity Center, grant access by user name or group.

To see which grants match each sign-in type, see Which grants match each sign-in type.

You can create an access grant by using the Amazon S3 console, AWS CLI, the Amazon S3 REST API, and AWS SDKs.

To create an access grant
  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://eusc-de-east-1.console.amazonaws-eusc.eu/s3/.

  2. In the left navigation pane, choose Access Grants.

  3. On the S3 Access Grants page, choose the Region that contains the S3 Access Grants instance that you want to work with.

    If you're using the S3 Access Grants instance for the first time, make sure that you have completed Step 2 - register a location and navigated to Step 3 of the Set up Access Grants instance wizard. If you already have an S3 Access Grants instance, choose View details, and then from the Grants tab, choose Create grant.

    1. In the Grant scope section, select or enter a registered location.

      If you selected the default s3:// location, use the Subprefix box to can narrow the scope of the access grant. For more information, see Subprefix. If you're granting access only to an object, select Grant scope is an object.

    2. Under Permissions and access, select the Permission level, either Read, Write, or both.

      Then choose the Grantee identifier type.

      • To grant access to a user from your corporate directory, choose Directory user. For Subject, enter the user's subject exactly as your identity provider sends it.

      • To grant access to a group, choose Directory group. For Group name, enter the group name exactly as it appears in IAM Identity Center.

      • To grant access to federated users who share an identity provider attribute, choose Attribute. Under Runtime claim, enter the Key and Value, for example, department and Finance. Values are case sensitive.

      (Optional) For a directory user or group, you can limit the grant to one IAM Identity Center application by entering its application ARN. You can use an application ARN only if your S3 Access Grants instance is associated with an IAM Identity Center instance that isn't opted in to the simplified experience. If you leave the application ARN empty, the grant applies to requests from any application.

      If the Grantee identifier type is an IAM user or role, choose IAM principal. Under IAM principal type, choose User or Role. Then, under IAM principal user, either choose from the list or enter the identity's ID.

    3. To create the S3 Access Grants grant, choose Next or Create grant.

  4. If Next or Create grant is disabled:

    Cannot create grant
    • You might need to register a location first in your S3 Access Grants instance.

    • You might not have the s3:CreateAccessGrant permission to create an access grant. Contact your account administrator.

To install the AWS CLI, see Installing the AWS CLI in the AWS Command Line Interface User Guide.

The following examples show how to create an access grant request for an IAM principal, a corporate directory user or group, and an attribute.

To use the following example commands, replace the user input placeholders with your own information.

Note

If you're creating an access grant that grants access to only one object, include the required parameter --s3-prefix-type Object.

Example Create an access grant request for an IAM principal
aws s3control create-access-grant \ --account-id 111122223333 \ --access-grants-location-id a1b2c3d4-5678-90ab-cdef-EXAMPLE22222 \ --access-grants-location-configuration S3SubPrefix=prefixB* \ --permission READ \ --grantee GranteeType=IAM,GranteeIdentifier=arn:aws-eusc:iam::111122223333:user/data-consumer-3
Example Create an access grant response
{"CreatedAt": "2023-05-31T18:41:34.663000+00:00", "AccessGrantId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "AccessGrantArn": "arn:aws-eusc:s3:us-east-2:111122223333:access-grants/default/grant/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "Grantee": { "GranteeType": "IAM", "GranteeIdentifier": "arn:aws-eusc:iam::111122223333:user/data-consumer-3" }, "AccessGrantsLocationId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "AccessGrantsLocationConfiguration": { "S3SubPrefix": "prefixB*" }, "GrantScope": "s3://amzn-s3-demo-bucket/prefix*", "Permission": "READ" }
Example Create an access grant for a directory user by name

The grantee type is DIRECTORY_USER and the grantee identifier is the name that your IdP sends for the user. For a group, use DIRECTORY_GROUP and the group name.

aws s3control create-access-grant \ --account-id 111122223333 \ --access-grants-location-id default \ --access-grants-location-configuration S3SubPrefix="amzn-s3-demo-bucket/finance/*" \ --permission READ \ --grantee GranteeType=DIRECTORY_USER,GranteeIdentifier=00u1a2b3c4EXAMPLE
Example Create an access grant for an attribute

The grantee type is ATTRIBUTE and the grantee identifier is the IdP claim and its value.

aws s3control create-access-grant \ --account-id 111122223333 \ --access-grants-location-id default \ --access-grants-location-configuration S3SubPrefix="amzn-s3-demo-bucket/finance/*" \ --permission READ \ --grantee GranteeType=ATTRIBUTE,GranteeIdentifier="aws:TransactionContext/IdentityProvider/department=Finance"
Example Get an IAM Identity Center ID for a directory user or group

To create a grant with an IAM Identity Center ID instead of a name, first get the ID. You can find the ID of an IAM Identity Center user through the IAM Identity Center console or by using the AWS CLI or AWS SDKs. The following command lists the users in the specified IAM Identity Center instance, with their names and identifiers.

aws identitystore list-users --identity-store-id d-1a2b3c4d1234

This command lists the groups in the specified IAM Identity Center instance.

aws identitystore list-groups --identity-store-id d-1a2b3c4d1234
Example Create an access grant for a directory user or group by IAM Identity Center ID

This command is similar to creating a grant for IAM users or roles, except the grantee type is DIRECTORY_USER or DIRECTORY_GROUP, and the grantee identifier is the IAM Identity Center ID for the directory user or group.

aws s3control create-access-grant \ --account-id 111122223333 \ --access-grants-location-id default \ --access-grants-location-configuration S3SubPrefix="amzn-s3-demo-bucket/rafael/*" \ --permission READWRITE \ --grantee GranteeType=DIRECTORY_USER,GranteeIdentifier=83d43802-00b1-7054-db02-f1d683aacba5 \

For information about the Amazon S3 REST API support for managing access grants, see the following sections in the Amazon Simple Storage Service API Reference:

This section provides examples of how to create an access grant by using the AWS SDKs.

Java

To use the following example, replace the user input placeholders with your own information:

Note

If you are creating an access grant that grants access to only one object, include the required parameter .s3PrefixType(S3PrefixType.Object).

Example Create an access grant request
public void createAccessGrant() { CreateAccessGrantRequest createRequest = CreateAccessGrantRequest.builder() .accountId("111122223333") .accessGrantsLocationId("a1b2c3d4-5678-90ab-cdef-EXAMPLEaaaaa") .permission("READ") .accessGrantsLocationConfiguration(AccessGrantsLocationConfiguration.builder().s3SubPrefix("prefixB*").build()) .grantee(Grantee.builder().granteeType("IAM").granteeIdentifier("arn:aws-eusc:iam::111122223333:user/data-consumer-3").build()) .build(); CreateAccessGrantResponse createResponse = s3Control.createAccessGrant(createRequest); LOGGER.info("CreateAccessGrantResponse: " + createResponse); }
Example Create an access grant response
CreateAccessGrantResponse( CreatedAt=2023-06-07T05:20:26.330Z, AccessGrantId=a1b2c3d4-5678-90ab-cdef-EXAMPLE33333, AccessGrantArn=arn:aws-eusc:s3:us-east-2:444455556666:access-grants/default/grant/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333, Grantee=Grantee( GranteeType=IAM, GranteeIdentifier=arn:aws-eusc:iam::111122223333:user/data-consumer-3 ), AccessGrantsLocationId=a1b2c3d4-5678-90ab-cdef-EXAMPLEaaaaa, AccessGrantsLocationConfiguration=AccessGrantsLocationConfiguration( S3SubPrefix=prefixB* ), GrantScope=s3://amzn-s3-demo-bucket/prefixB, Permission=READ )