AWS Key Management Service

2026/05/20 - AWS Key Management Service - 3 updated api methods

Changes  AWS KMS now supports creating grants for AWS service principals using new GranteeServicePrincipal and RetiringServicePrincipal parameters. This release adds SourceArn grant constraint and three condition keys for controlling CreateGrant access. For more information, see Grants in AWS KMS.

CreateGrant (updated) Link ¶
Changes (request)
{'Constraints': {'SourceArn': 'string'},
 'GranteeServicePrincipal': 'string',
 'RetiringServicePrincipal': 'string'}

Adds a grant to a KMS key.

A grant is a policy instrument that allows Amazon Web Services principals to use KMS keys in cryptographic operations. It also can allow them to view a KMS key ( DescribeKey) and create and manage grants. When authorizing access to a KMS key, grants are considered along with key policies and IAM policies. Grants are often used for temporary permissions because you can create one, use its permissions, and delete it without changing your key policies or IAM policies.

You can create a grant for an Amazon Web Services principal (IAM user, IAM role, or Amazon Web Services account) by specifying the GranteePrincipal parameter. You can also create a grant for an Amazon Web Services service principal by specifying the GranteeServicePrincipal parameter.

For detailed information about grants, including grant terminology, see Grants in KMS in the Key Management Service Developer Guide . For examples of creating grants in several programming languages, see Use CreateGrant with an Amazon Web Services SDK or CLI.

The CreateGrant operation returns a GrantToken and a GrantId.

  • When you create, retire, or revoke a grant, there might be a brief delay, usually less than five minutes, until the grant is available throughout KMS. This state is known as eventual consistency. Once the grant has achieved eventual consistency, the grantee principal can use the permissions in the grant without identifying the grant. However, to use the permissions in the grant immediately, use the GrantToken that CreateGrant returns. For details, see Using a grant token in the Key Management Service Developer Guide .

  • The CreateGrant operation also returns a GrantId. You can use the GrantId and a key identifier to identify the grant in the RetireGrant and RevokeGrant operations. To find the grant ID, use the ListGrants or ListRetirableGrants operations.

The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of KMS keys in the Key Management Service Developer Guide.

Cross-account use: Yes. To perform this operation on a KMS key in a different Amazon Web Services account, specify the key ARN in the value of the KeyId parameter.

Required permissions: kms:CreateGrant (key policy)

Related operations:

  • ListGrants

  • ListRetirableGrants

  • RetireGrant

  • RevokeGrant

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

See also: AWS API Documentation

Request Syntax

client.create_grant(
    KeyId='string',
    GranteePrincipal='string',
    RetiringPrincipal='string',
    Operations=[
        'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext'|'GenerateMac'|'VerifyMac'|'DeriveSharedSecret',
    ],
    Constraints={
        'EncryptionContextSubset': {
            'string': 'string'
        },
        'EncryptionContextEquals': {
            'string': 'string'
        },
        'SourceArn': 'string'
    },
    GrantTokens=[
        'string',
    ],
    Name='string',
    DryRun=True|False,
    GranteeServicePrincipal='string',
    RetiringServicePrincipal='string'
)
type KeyId:

string

param KeyId:

[REQUIRED]

Identifies the KMS key for the grant. The grant gives principals permission to use this KMS key.

Specify the key ID or key ARN of the KMS key. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN.

For example:

  • Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab

  • Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab

To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey.

type GranteePrincipal:

string

param GranteePrincipal:

The identity that gets the permissions specified in the grant.

To specify the grantee principal, use the Amazon Resource Name (ARN) of an Amazon Web Services principal. Valid principals include Amazon Web Services accounts, IAM users, IAM roles, federated users, and assumed role users. For help with the ARN syntax for a principal, see IAM ARNs in the Identity and Access Management User Guide .

You must specify either GranteePrincipal or GranteeServicePrincipal, but not both.

type RetiringPrincipal:

string

param RetiringPrincipal:

The principal that has permission to use the RetireGrant operation to retire the grant.

To specify the principal, use the Amazon Resource Name (ARN) of an Amazon Web Services principal. Valid principals include Amazon Web Services accounts, IAM users, IAM roles, federated users, and assumed role users. For help with the ARN syntax for a principal, see IAM ARNs in the Identity and Access Management User Guide .

The grant determines the retiring principal. Other principals might have permission to retire the grant or revoke the grant. For details, see RevokeGrant and Retiring and revoking grants in the Key Management Service Developer Guide.

You can specify either RetiringPrincipal or RetiringServicePrincipal, but not both.

type Operations:

list

param Operations:

[REQUIRED]

A list of operations that the grant permits.

This list must include only operations that are permitted in a grant. Also, the operation must be supported on the KMS key. For example, you cannot create a grant for a symmetric encryption KMS key that allows the Sign operation, or a grant for an asymmetric KMS key that allows the GenerateDataKey operation. If you try, KMS returns a ValidationError exception. For details, see Grant operations in the Key Management Service Developer Guide.

  • (string) --

type Constraints:

dict

param Constraints:

Specifies a grant constraint.

KMS supports the following grant constraints.

  • EncryptionContextEquals and EncryptionContextSubset — These encryption context grant constraints allow the permissions in the grant only when the encryption context in the request matches ( EncryptionContextEquals) or includes ( EncryptionContextSubset) the encryption context specified in the constraint. Encryption context grant constraints are supported only on grant operations that include an EncryptionContext parameter, such as cryptographic operations on symmetric encryption KMS keys. You cannot use an encryption context grant constraint for cryptographic operations with asymmetric KMS keys or HMAC KMS keys. Operations with these keys don't support an encryption context. Grants with encryption context grant constraints can include the DescribeKey and RetireGrant operations, but the constraint doesn't apply to these operations. If a grant with an encryption context grant constraint includes the CreateGrant operation, the constraint requires that any grants created with the CreateGrant permission have an equally strict or stricter encryption context constraint. Each constraint value can include up to 8 encryption context pairs. The encryption context value in each constraint cannot exceed 384 characters. For more information about encryption context, see Encryption context in the Key Management Service Developer Guide .

  • SourceArn — This grant constraint allows the permissions in the grant only when the request is made on behalf of a specific Amazon Web Services resource, identified by its Amazon Resource Name (ARN). This is effectively the same as having the aws:SourceArn global condition key in the grant. The SourceArn constraint is supported on grants for all types of KMS keys and can also be applied to the DescribeKey operation when specified in the request. However, it does not apply to RetireGrant operation.

For information about grant constraints, see Using grant constraints in the Key Management Service Developer Guide.

  • EncryptionContextSubset (dict) --

    A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

    • (string) --

      • (string) --

  • EncryptionContextEquals (dict) --

    A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

    • (string) --

      • (string) --

  • SourceArn (string) --

    The Amazon Resource Name (ARN) of an Amazon Web Services resource on behalf of which the request is made. This is effectively the same as having the aws:SourceArn global condition key in the grant. The SourceArn constraint ensures that the principal can use the KMS key only when the request is made on behalf of the specified resource.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency. For more information, see Grant token and Using a grant token in the Key Management Service Developer Guide.

  • (string) --

type Name:

string

param Name:

A friendly name for the grant. Use this value to prevent the unintended creation of duplicate grants when retrying this request.

When this value is absent, all CreateGrant requests result in a new grant with a unique GrantId even if all the supplied parameters are identical. This can result in unintended duplicates when you retry the CreateGrant request.

When this value is present, you can retry a CreateGrant request with identical parameters; if the grant already exists, the original GrantId is returned without creating a new grant. Note that the returned grant token is unique with every CreateGrant request, even when a duplicate GrantId is returned. All grant tokens for the same grant ID can be used interchangeably.

type DryRun:

boolean

param DryRun:

Checks if your request will succeed. DryRun is an optional parameter.

To learn more about how to use this parameter, see Testing your permissions in the Key Management Service Developer Guide.

type GranteeServicePrincipal:

string

param GranteeServicePrincipal:

The Amazon Web Services service principal that gets the permissions specified in the grant.

When you specify a GranteeServicePrincipal, you must also specify a SourceArn grant constraint. In addition, you must specify either a RetiringPrincipal or a RetiringServicePrincipal.

You must specify either GranteePrincipal or GranteeServicePrincipal, but not both.

type RetiringServicePrincipal:

string

param RetiringServicePrincipal:

The Amazon Web Services service principal that has permission to use the RetireGrant operation to retire the grant.

You can specify either RetiringPrincipal or RetiringServicePrincipal, but not both.

rtype:

dict

returns:

Response Syntax

{
    'GrantToken': 'string',
    'GrantId': 'string'
}

Response Structure

  • (dict) --

    • GrantToken (string) --

      The grant token.

      Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency. For more information, see Grant token and Using a grant token in the Key Management Service Developer Guide.

    • GrantId (string) --

      The unique identifier for the grant.

      You can use the GrantId in a ListGrants, RetireGrant, or RevokeGrant operation.

ListGrants (updated) Link ¶
Changes (request, response)
Request
{'GranteeServicePrincipal': 'string'}
Response
{'Grants': {'Constraints': {'SourceArn': 'string'},
            'GranteeServicePrincipal': 'string',
            'RetiringServicePrincipal': 'string'}}

Gets a list of all grants for the specified KMS key.

You must specify the KMS key in all requests. You can filter the grant list by grant ID, grantee principal, or grantee service principal.

For detailed information about grants, including grant terminology, see Grants in KMS in the Key Management Service Developer Guide . For examples of creating grants in several programming languages, see Use CreateGrant with an Amazon Web Services SDK or CLI.

Cross-account use: Yes. To perform this operation on a KMS key in a different Amazon Web Services account, specify the key ARN in the value of the KeyId parameter.

Required permissions: kms:ListGrants (key policy)

Related operations:

  • CreateGrant

  • ListRetirableGrants

  • RetireGrant

  • RevokeGrant

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

See also: AWS API Documentation

Request Syntax

client.list_grants(
    Limit=123,
    Marker='string',
    KeyId='string',
    GrantId='string',
    GranteePrincipal='string',
    GranteeServicePrincipal='string'
)
type Limit:

integer

param Limit:

Use this parameter to specify the maximum number of items to return. When this value is present, KMS does not return more than the specified number of items, but it might return fewer.

This value is optional. If you include a value, it must be between 1 and 100, inclusive. If you do not include a value, it defaults to 50.

type Marker:

string

param Marker:

Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.

type KeyId:

string

param KeyId:

[REQUIRED]

Returns only grants for the specified KMS key. This parameter is required.

Specify the key ID or key ARN of the KMS key. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN.

For example:

  • Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab

  • Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab

To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey.

type GrantId:

string

param GrantId:

Returns only the grant with the specified grant ID. The grant ID uniquely identifies the grant.

type GranteePrincipal:

string

param GranteePrincipal:

Returns only grants where the specified principal is the grantee principal for the grant.

You can specify either GranteePrincipal or GranteeServicePrincipal, but not both.

type GranteeServicePrincipal:

string

param GranteeServicePrincipal:

Returns only grants where the specified Amazon Web Services service principal is the grantee service principal for the grant. This filter is only usable by callers in a service principal.

You can specify either GranteePrincipal or GranteeServicePrincipal, but not both.

rtype:

dict

returns:

Response Syntax

{
    'Grants': [
        {
            'KeyId': 'string',
            'GrantId': 'string',
            'Name': 'string',
            'CreationDate': datetime(2015, 1, 1),
            'GranteePrincipal': 'string',
            'RetiringPrincipal': 'string',
            'IssuingAccount': 'string',
            'Operations': [
                'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext'|'GenerateMac'|'VerifyMac'|'DeriveSharedSecret',
            ],
            'Constraints': {
                'EncryptionContextSubset': {
                    'string': 'string'
                },
                'EncryptionContextEquals': {
                    'string': 'string'
                },
                'SourceArn': 'string'
            },
            'GranteeServicePrincipal': 'string',
            'RetiringServicePrincipal': 'string'
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Grants (list) --

      A list of grants.

      • (dict) --

        Contains information about a grant.

        • KeyId (string) --

          The unique identifier for the KMS key to which the grant applies.

        • GrantId (string) --

          The unique identifier for the grant.

        • Name (string) --

          The friendly name that identifies the grant. If a name was provided in the CreateGrant request, that name is returned. Otherwise this value is null.

        • CreationDate (datetime) --

          The date and time when the grant was created.

        • GranteePrincipal (string) --

          The identity that gets the permissions in the grant.

          When a grant is created with the GranteePrincipal field, the ListGrants response usually contains the user or role designated as the grantee principal in the grant. However, if the grantee principal is an Amazon Web Services service, the GranteePrincipal field contains an Amazon Web Services service principal, which might correspond to several different grantee principals, such as an IAM user, IAM role, or Amazon Web Services account.

        • RetiringPrincipal (string) --

          The principal that can retire the grant.

        • IssuingAccount (string) --

          The Amazon Web Services account under which the grant was issued.

        • Operations (list) --

          The list of operations permitted by the grant.

          • (string) --

        • Constraints (dict) --

          The constraints on the grant, such as encryption context pairs or a SourceArn, that restrict the subsequent operations the grant allows.

          • EncryptionContextSubset (dict) --

            A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

            • (string) --

              • (string) --

          • EncryptionContextEquals (dict) --

            A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

            • (string) --

              • (string) --

          • SourceArn (string) --

            The Amazon Resource Name (ARN) of an Amazon Web Services resource on behalf of which the request is made. This is effectively the same as having the aws:SourceArn global condition key in the grant. The SourceArn constraint ensures that the principal can use the KMS key only when the request is made on behalf of the specified resource.

        • GranteeServicePrincipal (string) --

          The Amazon Web Services service principal that gets the permissions in the grant.

        • RetiringServicePrincipal (string) --

          The Amazon Web Services service principal that can retire the grant.

    • NextMarker (string) --

      When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in this response to the Marker parameter in a subsequent request.

ListRetirableGrants (updated) Link ¶
Changes (request, response)
Request
{'RetiringServicePrincipal': 'string'}
Response
{'Grants': {'Constraints': {'SourceArn': 'string'},
            'GranteeServicePrincipal': 'string',
            'RetiringServicePrincipal': 'string'}}

Returns information about all grants in the Amazon Web Services account and Region that have the specified retiring principal or retiring service principal.

You can specify any principal in your Amazon Web Services account. The grants that are returned include grants for KMS keys in your Amazon Web Services account and other Amazon Web Services accounts. You might use this operation to determine which grants you may retire. To retire a grant, use the RetireGrant operation.

For detailed information about grants, including grant terminology, see Grants in KMS in the Key Management Service Developer Guide . For examples of creating grants in several programming languages, see Use CreateGrant with an Amazon Web Services SDK or CLI.

Cross-account use: You must specify a principal in your Amazon Web Services account. This operation returns a list of grants where the retiring principal specified in the ListRetirableGrants request is the same retiring principal on the grant. This can include grants on KMS keys owned by other Amazon Web Services accounts, but you do not need kms:ListRetirableGrants permission (or any other additional permission) in any Amazon Web Services account other than your own.

Required permissions: kms:ListRetirableGrants (IAM policy) in your Amazon Web Services account.

Related operations:

  • CreateGrant

  • ListGrants

  • RetireGrant

  • RevokeGrant

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

See also: AWS API Documentation

Request Syntax

client.list_retirable_grants(
    Limit=123,
    Marker='string',
    RetiringPrincipal='string',
    RetiringServicePrincipal='string'
)
type Limit:

integer

param Limit:

Use this parameter to specify the maximum number of items to return. When this value is present, KMS does not return more than the specified number of items, but it might return fewer.

This value is optional. If you include a value, it must be between 1 and 100, inclusive. If you do not include a value, it defaults to 50.

type Marker:

string

param Marker:

Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.

type RetiringPrincipal:

string

param RetiringPrincipal:

The retiring principal for which to list grants. Enter a principal in your Amazon Web Services account.

To specify the retiring principal, use the Amazon Resource Name (ARN) of an Amazon Web Services principal. Valid principals include Amazon Web Services accounts, IAM users, IAM roles, federated users, and assumed role users. For help with the ARN syntax for a principal, see IAM ARNs in the Identity and Access Management User Guide .

You must specify either RetiringPrincipal or RetiringServicePrincipal, but not both.

type RetiringServicePrincipal:

string

param RetiringServicePrincipal:

The retiring service principal for which to list grants. This filter is only usable by callers in a service principal.

You must specify either RetiringPrincipal or RetiringServicePrincipal, but not both.

rtype:

dict

returns:

Response Syntax

{
    'Grants': [
        {
            'KeyId': 'string',
            'GrantId': 'string',
            'Name': 'string',
            'CreationDate': datetime(2015, 1, 1),
            'GranteePrincipal': 'string',
            'RetiringPrincipal': 'string',
            'IssuingAccount': 'string',
            'Operations': [
                'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext'|'GenerateMac'|'VerifyMac'|'DeriveSharedSecret',
            ],
            'Constraints': {
                'EncryptionContextSubset': {
                    'string': 'string'
                },
                'EncryptionContextEquals': {
                    'string': 'string'
                },
                'SourceArn': 'string'
            },
            'GranteeServicePrincipal': 'string',
            'RetiringServicePrincipal': 'string'
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Grants (list) --

      A list of grants.

      • (dict) --

        Contains information about a grant.

        • KeyId (string) --

          The unique identifier for the KMS key to which the grant applies.

        • GrantId (string) --

          The unique identifier for the grant.

        • Name (string) --

          The friendly name that identifies the grant. If a name was provided in the CreateGrant request, that name is returned. Otherwise this value is null.

        • CreationDate (datetime) --

          The date and time when the grant was created.

        • GranteePrincipal (string) --

          The identity that gets the permissions in the grant.

          When a grant is created with the GranteePrincipal field, the ListGrants response usually contains the user or role designated as the grantee principal in the grant. However, if the grantee principal is an Amazon Web Services service, the GranteePrincipal field contains an Amazon Web Services service principal, which might correspond to several different grantee principals, such as an IAM user, IAM role, or Amazon Web Services account.

        • RetiringPrincipal (string) --

          The principal that can retire the grant.

        • IssuingAccount (string) --

          The Amazon Web Services account under which the grant was issued.

        • Operations (list) --

          The list of operations permitted by the grant.

          • (string) --

        • Constraints (dict) --

          The constraints on the grant, such as encryption context pairs or a SourceArn, that restrict the subsequent operations the grant allows.

          • EncryptionContextSubset (dict) --

            A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

            • (string) --

              • (string) --

          • EncryptionContextEquals (dict) --

            A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

            • (string) --

              • (string) --

          • SourceArn (string) --

            The Amazon Resource Name (ARN) of an Amazon Web Services resource on behalf of which the request is made. This is effectively the same as having the aws:SourceArn global condition key in the grant. The SourceArn constraint ensures that the principal can use the KMS key only when the request is made on behalf of the specified resource.

        • GranteeServicePrincipal (string) --

          The Amazon Web Services service principal that gets the permissions in the grant.

        • RetiringServicePrincipal (string) --

          The Amazon Web Services service principal that can retire the grant.

    • NextMarker (string) --

      When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in this response to the Marker parameter in a subsequent request.