AWS Key Management Service

2016/08/10 - AWS Key Management Service - 3 new 2 updated api methods

Changes  Adds support for importing customer-supplied cryptographic keys. New import key feature lets you import keys from your own key management infrastructure to KMS for greater control over generation and storage of keys and meeting compliance requirements of sensitive workloads.

DeleteImportedKeyMaterial (new) Link ¶

Deletes key material that you previously imported and makes the specified customer master key (CMK) unusable. For more information about importing key material into AWS KMS, see Importing Key Material in the AWS Key Management Service Developer Guide .

When the specified CMK is in the PendingDeletion state, this operation does not change the CMK's state. Otherwise, it changes the CMK's state to PendingImport .

After you delete key material, you can use ImportKeyMaterial to reimport the same key material into the CMK.

Request Syntax

client.delete_imported_key_material(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

The identifier of the CMK whose key material to delete. The CMK's Origin must be EXTERNAL .

A valid identifier is the unique key ID or the Amazon Resource Name (ARN) of the CMK. Examples:

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

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

returns

None

ImportKeyMaterial (new) Link ¶

Imports key material into an AWS KMS customer master key (CMK) from your existing key management infrastructure. For more information about importing key material into AWS KMS, see Importing Key Material in the AWS Key Management Service Developer Guide .

You must specify the key ID of the CMK to import the key material into. This CMK's Origin must be EXTERNAL . You must also send an import token and the encrypted key material. Send the import token that you received in the same GetParametersForImport response that contained the public key that you used to encrypt the key material. You must also specify whether the key material expires and if so, when. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. To use the CMK again, you can reimport the same key material. If you set an expiration date, you can change it only by reimporting the same key material and specifying a new expiration date.

When this operation is successful, the specified CMK's key state changes to Enabled , and you can use the CMK.

After you successfully import key material into a CMK, you can reimport the same key material into that CMK, but you cannot import different key material.

Request Syntax

client.import_key_material(
    KeyId='string',
    ImportToken=b'bytes',
    EncryptedKeyMaterial=b'bytes',
    ValidTo=datetime(2015, 1, 1),
    ExpirationModel='KEY_MATERIAL_EXPIRES'|'KEY_MATERIAL_DOES_NOT_EXPIRE'
)
type KeyId

string

param KeyId

[REQUIRED]

The identifier of the CMK to import the key material into. The CMK's Origin must be EXTERNAL .

A valid identifier is the unique key ID or the Amazon Resource Name (ARN) of the CMK. Examples:

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

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

type ImportToken

bytes

param ImportToken

[REQUIRED]

The import token that you received in the response to a previous GetParametersForImport request. It must be from the same response that contained the public key that you used to encrypt the key material.

type EncryptedKeyMaterial

bytes

param EncryptedKeyMaterial

[REQUIRED]

The encrypted key material to import. It must be encrypted with the public key that you received in the response to a previous GetParametersForImport request, using the wrapping algorithm that you specified in that request.

type ValidTo

datetime

param ValidTo

[REQUIRED]

The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. You must omit this parameter when the ExpirationModel parameter is set to KEY_MATERIAL_DOES_NOT_EXPIRE . Otherwise it is required.

type ExpirationModel

string

param ExpirationModel

Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES , in which case you must include the ValidTo parameter. When this parameter is set to KEY_MATERIAL_DOES_NOT_EXPIRE , you must omit the ValidTo parameter.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

GetParametersForImport (new) Link ¶

Returns the items you need in order to import key material into AWS KMS from your existing key management infrastructure. For more information about importing key material into AWS KMS, see Importing Key Material in the AWS Key Management Service Developer Guide .

You must specify the key ID of the customer master key (CMK) into which you will import key material. This CMK's Origin must be EXTERNAL . You must also specify the wrapping algorithm and type of wrapping key (public key) that you will use to encrypt the key material.

This operation returns a public key and an import token. Use the public key to encrypt the key material. Store the import token to send with a subsequent ImportKeyMaterial request. The public key and import token from the same response must be used together. These items are valid for 24 hours, after which they cannot be used for a subsequent ImportKeyMaterial request. To retrieve new ones, send another GetParametersForImport request.

Request Syntax

client.get_parameters_for_import(
    KeyId='string',
    WrappingAlgorithm='RSAES_PKCS1_V1_5'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
    WrappingKeySpec='RSA_2048'
)
type KeyId

string

param KeyId

[REQUIRED]

The identifier of the CMK into which you will import key material. The CMK's Origin must be EXTERNAL .

A valid identifier is the unique key ID or the Amazon Resource Name (ARN) of the CMK. Examples:

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

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

type WrappingAlgorithm

string

param WrappingAlgorithm

[REQUIRED]

The algorithm you will use to encrypt the key material before importing it with ImportKeyMaterial. For more information, see Encrypt the Key Material in the AWS Key Management Service Developer Guide .

type WrappingKeySpec

string

param WrappingKeySpec

[REQUIRED]

The type of wrapping key (public key) to return in the response. Only 2048-bit RSA public keys are supported.

rtype

dict

returns

Response Syntax

{
    'KeyId': 'string',
    'ImportToken': b'bytes',
    'PublicKey': b'bytes',
    'ParametersValidTo': datetime(2015, 1, 1)
}

Response Structure

  • (dict) --

    • KeyId (string) --

      The identifier of the CMK to use in a subsequent ImportKeyMaterial request. This is the same CMK specified in the GetParametersForImport request.

    • ImportToken (bytes) --

      The import token to send in a subsequent ImportKeyMaterial request.

    • PublicKey (bytes) --

      The public key to use to encrypt the key material before importing it with ImportKeyMaterial.

    • ParametersValidTo (datetime) --

      The time at which the import token and public key are no longer valid. After this time, you cannot use them to make an ImportKeyMaterial request and you must send another GetParametersForImport request to retrieve new ones.

CreateKey (updated) Link ¶
Changes (request, response)
Request
{'Origin': 'AWS_KMS | EXTERNAL'}
Response
{'KeyMetadata': {'ExpirationModel': 'KEY_MATERIAL_EXPIRES | '
                                    'KEY_MATERIAL_DOES_NOT_EXPIRE',
                 'KeyState': {'PendingImport'},
                 'Origin': 'AWS_KMS | EXTERNAL',
                 'ValidTo': 'timestamp'}}

Creates a customer master key (CMK).

You can use a CMK to encrypt small amounts of data (4 KiB or less) directly, but CMKs are more commonly used to encrypt data encryption keys (DEKs), which are used to encrypt raw data. For more information about DEKs and the difference between CMKs and DEKs, see the following:

Request Syntax

client.create_key(
    Policy='string',
    Description='string',
    KeyUsage='ENCRYPT_DECRYPT',
    Origin='AWS_KMS'|'EXTERNAL',
    BypassPolicyLockoutSafetyCheck=True|False
)
type Policy

string

param Policy

The key policy to attach to the CMK.

If you specify a policy and do not set BypassPolicyLockoutSafetyCheck to true, the policy must meet the following criteria:

  • It must allow the principal making the CreateKey request to make a subsequent PutKeyPolicy request on the CMK. This reduces the likelihood that the CMK becomes unmanageable. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide .

  • The principal(s) specified in the key policy must exist and be visible to AWS KMS. When you create a new AWS principal (for example, an IAM user or role), you might need to enforce a delay before specifying the new principal in a key policy because the new principal might not immediately be visible to AWS KMS. For more information, see Changes that I make are not always immediately visible in the IAM User Guide .

If you do not specify a policy, AWS KMS attaches a default key policy to the CMK. For more information, see Default Key Policy in the AWS Key Management Service Developer Guide .

The policy size limit is 32 KiB (32768 bytes).

type Description

string

param Description

A description of the CMK.

Use a description that helps you decide whether the CMK is appropriate for a task.

type KeyUsage

string

param KeyUsage

The intended use of the CMK.

You can use CMKs only for symmetric encryption and decryption.

type Origin

string

param Origin

The source of the CMK's key material.

The default is AWS_KMS , which means AWS KMS creates the key material. When this parameter is set to EXTERNAL , the request creates a CMK without key material so that you can import key material from your existing key management infrastructure. For more information about importing key material into AWS KMS, see Importing Key Material in the AWS Key Management Service Developer Guide .

The CMK's Origin is immutable and is set when the CMK is created.

type BypassPolicyLockoutSafetyCheck

boolean

param BypassPolicyLockoutSafetyCheck

A flag to indicate whether to bypass the key policy lockout safety check.

Warning

Setting this value to true increases the likelihood that the CMK becomes unmanageable. Do not set this value to true indiscriminately.

For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide .

Use this parameter only when you include a policy in the request and you intend to prevent the principal making the request from making a subsequent PutKeyPolicy request on the CMK.

The default value is false.

rtype

dict

returns

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'ENCRYPT_DECRYPT',
        'KeyState': 'Enabled'|'Disabled'|'PendingDeletion'|'PendingImport',
        'DeletionDate': datetime(2015, 1, 1),
        'ValidTo': datetime(2015, 1, 1),
        'Origin': 'AWS_KMS'|'EXTERNAL',
        'ExpirationModel': 'KEY_MATERIAL_EXPIRES'|'KEY_MATERIAL_DOES_NOT_EXPIRE'
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the CMK.

      • AWSAccountId (string) --

        The twelve-digit account ID of the AWS account that owns the CMK.

      • KeyId (string) --

        The globally unique identifier for the CMK.

      • Arn (string) --

        The Amazon Resource Name (ARN) of the CMK. For examples, see AWS Key Management Service (AWS KMS) in the Example ARNs section of the AWS General Reference .

      • CreationDate (datetime) --

        The date and time when the CMK was created.

      • Enabled (boolean) --

        Specifies whether the CMK is enabled. When KeyState is Enabled this value is true, otherwise it is false.

      • Description (string) --

        The description of the CMK.

      • KeyUsage (string) --

        The cryptographic operations for which you can use the CMK. Currently the only allowed value is ENCRYPT_DECRYPT , which means you can use the CMK for the Encrypt and Decrypt operations.

      • KeyState (string) --

        The state of the CMK.

        For more information about how key state affects the use of a CMK, see How Key State Affects the Use of a Customer Master Key in the AWS Key Management Service Developer Guide .

      • DeletionDate (datetime) --

        The date and time after which AWS KMS deletes the CMK. This value is present only when KeyState is PendingDeletion , otherwise this value is omitted.

      • ValidTo (datetime) --

        The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. This value is present only for CMKs whose Origin is EXTERNAL and whose ExpirationModel is KEY_MATERIAL_EXPIRES , otherwise this value is omitted.

      • Origin (string) --

        The source of the CMK's key material. When this value is AWS_KMS , AWS KMS created the key material. When this value is EXTERNAL , the key material was imported from your existing key management infrastructure or the CMK lacks key material.

      • ExpirationModel (string) --

        Specifies whether the CMK's key material expires. This value is present only when Origin is EXTERNAL , otherwise this value is omitted.

DescribeKey (updated) Link ¶
Changes (response)
{'KeyMetadata': {'ExpirationModel': 'KEY_MATERIAL_EXPIRES | '
                                    'KEY_MATERIAL_DOES_NOT_EXPIRE',
                 'KeyState': {'PendingImport'},
                 'Origin': 'AWS_KMS | EXTERNAL',
                 'ValidTo': 'timestamp'}}

Provides detailed information about the specified customer master key.

Request Syntax

client.describe_key(
    KeyId='string',
    GrantTokens=[
        'string',
    ]
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type GrantTokens

list

param GrantTokens

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide .

  • (string) --

rtype

dict

returns

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'ENCRYPT_DECRYPT',
        'KeyState': 'Enabled'|'Disabled'|'PendingDeletion'|'PendingImport',
        'DeletionDate': datetime(2015, 1, 1),
        'ValidTo': datetime(2015, 1, 1),
        'Origin': 'AWS_KMS'|'EXTERNAL',
        'ExpirationModel': 'KEY_MATERIAL_EXPIRES'|'KEY_MATERIAL_DOES_NOT_EXPIRE'
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the key.

      • AWSAccountId (string) --

        The twelve-digit account ID of the AWS account that owns the CMK.

      • KeyId (string) --

        The globally unique identifier for the CMK.

      • Arn (string) --

        The Amazon Resource Name (ARN) of the CMK. For examples, see AWS Key Management Service (AWS KMS) in the Example ARNs section of the AWS General Reference .

      • CreationDate (datetime) --

        The date and time when the CMK was created.

      • Enabled (boolean) --

        Specifies whether the CMK is enabled. When KeyState is Enabled this value is true, otherwise it is false.

      • Description (string) --

        The description of the CMK.

      • KeyUsage (string) --

        The cryptographic operations for which you can use the CMK. Currently the only allowed value is ENCRYPT_DECRYPT , which means you can use the CMK for the Encrypt and Decrypt operations.

      • KeyState (string) --

        The state of the CMK.

        For more information about how key state affects the use of a CMK, see How Key State Affects the Use of a Customer Master Key in the AWS Key Management Service Developer Guide .

      • DeletionDate (datetime) --

        The date and time after which AWS KMS deletes the CMK. This value is present only when KeyState is PendingDeletion , otherwise this value is omitted.

      • ValidTo (datetime) --

        The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. This value is present only for CMKs whose Origin is EXTERNAL and whose ExpirationModel is KEY_MATERIAL_EXPIRES , otherwise this value is omitted.

      • Origin (string) --

        The source of the CMK's key material. When this value is AWS_KMS , AWS KMS created the key material. When this value is EXTERNAL , the key material was imported from your existing key management infrastructure or the CMK lacks key material.

      • ExpirationModel (string) --

        Specifies whether the CMK's key material expires. This value is present only when Origin is EXTERNAL , otherwise this value is omitted.