KMS
Encryption, key management, aliases, grants, real ECDH, key import.
fakecloud implements 56 of 56 KMS operations at 100% Smithy conformance.
Supported features
- Symmetric keys — CreateKey, Encrypt, Decrypt, GenerateDataKey, ReEncrypt. Real AES-256-GCM envelope encryption with AWS-shaped ciphertext blobs (key id header + IV + ciphertext + tag).
- Asymmetric keys — Sign, Verify, GetPublicKey across:
- RSA — RSA_2048, RSA_3072, RSA_4096 with real RSA Sign/Verify/GetPublicKey, and real RSA-OAEP Encrypt/Decrypt/ReEncrypt for
ENCRYPT_DECRYPTkeys. As on AWS, the ciphertext is the raw RSA-OAEP output (one modulus long, interchangeable with ciphertext produced outside KMS with the public key), which names no key:DecryptneedsKeyIdandEncryptionAlgorithm(ReEncryptSourceKeyIdandSourceEncryptionAlgorithm), and without the key the request isInvalidCiphertextException(the self-describingfakecloud-rsa:ciphertexts earlier fakecloud versions produced still open without it, so persisted data survives an upgrade) - ECC — ECC_NIST_P256, ECC_NIST_P384, ECC_NIST_P521, and ECC_SECG_P256K1 with real ECDSA Sign/Verify/GetPublicKey
- RSA — RSA_2048, RSA_3072, RSA_4096 with real RSA Sign/Verify/GetPublicKey, and real RSA-OAEP Encrypt/Decrypt/ReEncrypt for
- Key management — DescribeKey, EnableKey, DisableKey, ScheduleKeyDeletion, CancelKeyDeletion
- Aliases — CRUD with
alias/prefix validation. Aliases are regional, as in AWS: the same alias name can exist independently in every region,ListAliasespages through the request region's aliases only, and an alias must point at a key in its own region. An alias name resolves in the caller's region and an alias ARN in the region it names, anywhere a key id/ARN is accepted (Encrypt, Decrypt, Sign, Verify, GenerateDataKey, ReEncrypt, grants, key policies, cross-service KmsKeyId, which resolves in the resource's region). - Grants - CreateGrant, RetireGrant, RevokeGrant, ListGrants (
ListGrants/ListRetirableGrantsname each grant's key by its key ARN, a replica's grant by the replica's). Under--iam stricta grant authorizes direct KMS calls as on AWS: its grantee (an IAM user, a role and its assumed-role sessions, in the key's account or another) may perform the grant's operations on the key without any IAM or key-policy permission, within itsEncryptionContextSubset/EncryptionContextEqualsconstraints and itsSourceArnconstraint (which allows the grant's operations only on behalf of that resource,DescribeKeyincluded andRetireGrantexcepted, so a grant bound to a resource authorizes no direct API call); a grant to an AWS service principal (GranteeServicePrincipal, which needs aSourceArnconstraint and aRetiringPrincipalorRetiringServicePrincipal;CreateGrantrefuses aSourceArnoff the model's ARN pattern and each invalid grantee/retiring combination with theValidationExceptionmessages recorded against KMS, before it looks up the key) lets that service use the key when it acts itself for that resource through the KMS hook (ListGrantsfilters byGranteePrincipalorGranteeServicePrincipal,ListRetirableGrantsbyRetiringPrincipalorRetiringServicePrincipal); a grant naming an account only lets that account delegate through IAM policies; an explicit Deny in the key policy or an IAM policy still wins, an SCP that does not allow the action caps it, and the role's permissions boundary and session policies cap a grant to a role;RevokeGrant/RetireGrantremove the access at once. A grant names an IAM user or role grantee by its unique ID, as AWS does: a user or role deleted and recreated under the same name is a new principal the old grant does not cover, and once the grantee is goneListGrantsshows its unique ID (AIDA.../AROA...) asGranteePrincipal. Each key of a multi-Region set has its own grants and key policy: a bare key id names the replica in its region, and a multi-Region ciphertext is decrypted (directly or by a service) by the related key of the region of the call, under that key's policy and grants. A grant holdingCreateGrantlets its grantee create only grants for some of its operations with constraints at least as strict.CreateGrantrefuses encryption-context constraints (ValidationException) on a non-symmetric key or alongside an operation that takes no encryption context (onlyDescribeKey,RetireGrantandCreateGrantmay join them).RetireGrantis allowed to the grant's retiring principal, to its grantee when the grant allowsRetireGrant, and to principals of the key's account whose IAM policies allow it. See IAM enforcement. - Cross-account keys - a principal of another account names a key by its key ARN or alias ARN (key ARN only for
CreateGrant,GetKeyRotationStatus,ListGrants,RevokeGrant,RetireGrant, which may also name its grant byGrantTokenalone) for the operations AWS allows across accounts: the cryptographic operations,DescribeKeyandGetPublicKey. The request is served in the key's account and authorized by its key policy plus the caller's IAM policies, or by a grant. A symmetric ciphertext sealed for such a caller names the key by its ARN, so itsDecryptneeds noKeyId(also for a key with imported material). A key id or alias name always means a key of the caller's own account.ReEncrypttakes its source and destination keys from any accounts (the caller's or others', each by its ARN), authorized askms:ReEncryptFromon the source key andkms:ReEncryptToon the destination key, each by that key's policy and grants; the ciphertext is opened in the source key's account and resealed in the destination key's. - Key rotation — automatic rotation flag (tracked), on-demand rotation
- Key policies — PutKeyPolicy, GetKeyPolicy, ListKeyPolicies
- Tags — on keys
- Real ECDH — DeriveSharedSecret performs actual Elliptic Curve Diffie-Hellman
- Key import — GetParametersForImport, ImportKeyMaterial with real key material handling
- Custom key stores — CRUD (records only)
- Key replica — ReplicateKey
- Cross-service KMS hook - S3 (SSE-KMS), SQS, SNS, DynamoDB, Secrets Manager, SSM SecureString and the SES receipt-rule S3 action call into KMS for real encrypt/decrypt under the hood. Every call is recorded at
/_fakecloud/kms/usageso test code can assert which service principal triggered which operation on which key with which encryption context. AWS-managed keys (aws/s3,aws/sqs,aws/sns,aws/dynamodb,aws/secretsmanager,aws/ssm, ...) exist from first use, one per account and region, which that region'salias/aws/<service>names. As on AWS, AWS-managed keys cannot be managed:PutKeyPolicy,ScheduleKeyDeletion,CancelKeyDeletion,EnableKey/DisableKey, the rotation operations,TagResource/UntagResource,UpdateKeyDescription,CreateGrant,CreateAlias/UpdateAliastargeting one,ReplicateKey,UpdatePrimaryRegionand the imported-material operations answerAccessDeniedException("... because no resource-based policy allows the kms:action"). A resource can name another account's customer key by its key ARN or alias ARN (an SQS queue's KmsMasterKeyId, a secret'sKmsKeyId): the key is used in its own account and region, and only when its key policy allows the caller (the calling IAM user or role, an assumed-role session matching its role, when the service knows it; else the resource's account, which an account-root or bare account-id principal names) or a grant on the key does (grantee principal, operations andEncryptionContextSubset/EncryptionContextEqualsconstraints honoured); otherwise the service reports KMS'sAccessDeniedExceptionnaming the key. Another account'saws/<service>alias ARN creates no key there and is refused, as AWS-managed keys are never usable across accounts. A key id or alias name resolves in the resource's own account.- AWS-managed keys - the
alias/aws/<service>keys of every service AWS has one for (acm,backup,codeartifact,codecommit,dms,dynamodb,ebs,ecr,elasticache,elasticfilesystem,es,glue,kafka,kinesis,kinesisvideo,lambda,rds,redshift,s3,secretsmanager,ses,sns,sqs,ssm,timestream,xray; another name such asalias/aws/logsisNotFoundException"Aliasis not found.", as on AWS) carry the key policy and description AWS gives them, recorded from a real account. As on AWS, ListAliaseslists the predefined aliases (aws/dynamodb,aws/ebs,aws/elasticfilesystem,aws/es,aws/glue,aws/kinesisvideo,aws/rds,aws/redshift,aws/s3,aws/ssm,aws/xray) without aTargetKeyIduntil first used; the key is created the first time it is used, directly (DescribeKey,Encrypt, ...) or by its service.GetKeyPolicytakes a key id or ARN (an alias isInvalidArnException). The policy grantsEncrypt,Decrypt,ReEncrypt*andGenerateDataKey*only to principals of the owning account calling through the owning service (kms:ViaService=<service>.<region>.amazonaws.com,kms:CallerAccount= the account), and fakecloud evaluates it on every use: a directEncrypt,Decrypt,GenerateDataKey*orReEncryptonalias/aws/s3is refused withAccessDeniedException("User: ... is not authorized to perform: kms:Encrypt on resource:because no resource-based policy allows the kms:Encrypt action") whatever the IAM mode, while each service keeps using its own key through the KMS hook, which calls KMS through the calling service (so one service cannot use another's aws/*key) or, for SES, as the SES service principal. Theaws/lambdakey also lets account principals decrypt ciphertexts whose encryption context names one of the account's functions, andaws/seslets them decrypt the mail SES sealed, as their policies say. A key policy evaluated for a service's use of a key seeskms:ViaService,kms:CallerAccount(the caller's own account, not the account of the bucket or queue the service acts on), the request'skms:EncryptionContext:*keys and the caller's global keys (aws:PrincipalArn, which for an assumed-role session is its role,aws:PrincipalAccount,aws:PrincipalType,aws:userid,aws:PrincipalTag/*,aws:PrincipalOrgID), whatever the IAM mode; direct KMS API calls seekms:CallerAccountandkms:EncryptionContext:*under--iam strict.- Service ciphertexts - ciphertexts the hook seals bind the service's encryption context like KMS ciphertexts (S3
aws:s3:arn, SQSaws:sqs:arn, SNSaws:sns:topicArn, Secrets ManagerSecretARN+SecretVersionId, SSMPARAMETER_ARN, DynamoDBaws:dynamodb:tableName+aws:dynamodb:subscriberId, Lambdaaws:lambda:FunctionArn), so the KMS API decrypts one only with that context (InvalidCiphertextExceptionotherwise). Context-free service ciphertexts persisted before this binding still decrypt after an upgrade. A failed KMS call is reported by each service with its own declared error (SQSKMS.AccessDeniedException/KMS.DisabledException/KMS.InvalidKeyUsageException/KMS.InvalidStateException/KMS.NotFoundException, SNSKMSAccessDenied/KMSDisabled/KMSInvalidState/KMSNotFound, S3AccessDenied/KMS.<code>, SSMAccessDeniedException/InvalidKeyId, Secrets ManagerAccessDeniedException/InvalidParameterException/EncryptionFailure/DecryptionFailure, DynamoDBCreateTable/UpdateTableAccessDeniedException/ValidationException), relaying KMS's message. A refusal names the identity the service acted for (the IAM user or assumed role that called it, the account root when the service acts for the account). Under--iam strictthe caller's SCPs cap that key use too, as the KMS request is the caller's (kms:ViaServicenames the service): an SCP refusal is named as such in the message. Services that deliver into SQS as their own service principal (SNS subscriptions, EventBridge rule targets, S3 event notifications) need the queue key's policy to name that principal: a queue under the AWS-managedaws/sqskey refuses them, as on AWS, so SNS delivers nothing and countsAWS/SNSNumberOfNotificationsFailed(and uses the subscription's dead-letter queue), EventBridge delivers nothing, countsAWS/EventsFailedInvocationsand sends the event to the target'sDeadLetterConfigqueue (message attributesERROR_CODENO_PERMISSIONS,ERROR_MESSAGE,RULE_ARN,TARGET_ARN;InvocationsSentToDlq/InvocationsFailedToBeSentToDlq), and S3 refuses the notification configuration withInvalidArgument"Unable to validate the following destination configurations"; a customer key whose policy grants the principal works, and the account itself (or a role a service acts as: Scheduler, Pipes, Step Functions, Lambda destinations) still usesaws/sqs. SSE-SQS queues (SqsManagedSseEnabled, the default) encrypt bodies at rest with an SQS-owned key and never call KMS, so service principals deliver to them freely and noaws/sqskey is created for them. Secrets Manager encrypts every secret, one created withoutKmsKeyIdunder the region'saws/secretsmanagerkey (also when CloudFormation creates it); secrets stored in plaintext by an older fakecloud still read back. A stored ciphertext that does not open (disabled or deleted key, refused key) fails the read with the service's error, never reads as its ciphertext, and an SQS message keeps its seal when it moves to an unencrypted dead-letter queue, so it is still decrypted there.- Default keys on encrypted resources - a resource encrypted at rest without a named key reports the ARN of its service's AWS-managed key, a real key minted once per account and region that
DescribeKey alias/aws/<service>resolves to:aws/rdsfor RDS instances and clusters, DocumentDB and Neptune clusters,aws/ebsfor EBS volumes and snapshots (or the account's EBS default key whenModifyEbsDefaultKmsKeyIdcustomized it), andaws/elasticfilesystem,aws/redshift,aws/dms,aws/kafka,aws/timestream,aws/codeartifact,aws/codecommitfor their services. A key named by alias (resolved in the resource's region) or key id is reported as the ARN of the key it names. CloudFormation-provisioned resources report the same keys.- Service Quotas enforcement (opt-in): with "Customer Master Keys (CMKs)" (
L-C2F1777E) enforced in Service Quotas,CreateKeyandReplicateKeyare refused withLimitExceededExceptiononce the region holds that many customer managed keys (any key state, pending deletion included; AWS managed keys do not count). Off by defaultIntrospection
GET /_fakecloud/kms/usage— list every cross-service KMS call (operation, service principal, key ARN, encryption context). Useful for asserting that your code path actually triggered KMS encrypt/decrypt under the hood.
Protocol
JSON protocol.
X-Amz-Targetheader, JSON body, JSON responses.Gotchas
- Real AES-256-GCM, AWS-shaped ciphertext. Encrypt/Decrypt round-trip across process restarts as long as the same key material is available. Ciphertext layout mimics AWS (key id header, IV, ciphertext, GCM tag) so length and shape match what real callers expect, but blobs are not interchangeable with real AWS KMS.
Source
- AWS-managed keys - the