Files
floci/docs/services/kms.md
T
Priamo Germosen 984886f697 feat(kms): implement UpdateAlias (#2324)
* feat(kms): implement UpdateAlias

Repoints an existing alias at a different KMS key, following the
existing createAlias/deleteAlias/resolveKey patterns. Required by the
Terraform AWS provider, which treats a target_key_id change on
aws_kms_alias as an in-place update.

* fix(kms): reject invalid replacement keys in UpdateAlias

UpdateAlias accepted any existing key as a replacement target,
including keys pending deletion or with a different key usage/spec
than the alias's current target. Real AWS KMS rejects both: the
replacement key must be in a compatible state and match the current
target's key usage and key spec.

* fix(kms): compare key type instead of exact key spec in UpdateAlias

The exact KeySpec comparison rejected valid updates between same-type
keys with different specs (e.g. RSA_2048 to RSA_3072), which AWS KMS
accepts as long as both keys share the same key type and usage.

* test(kms): add Terraform compatibility test for UpdateAlias

Verifies the exact scenario from #2291: the Terraform AWS provider
treats target_key_id on aws_kms_alias as an in-place update, so
re-applying with a different target must call UpdateAlias and update
the alias without a destroy/recreate. Self-contained config, mirroring
the eni-destroy-tf pattern, since it needs a second apply with a
different var rather than the shared single-apply main.tf.

* fix(kms): compare key family instead of KeyType in UpdateAlias

Comparing the fine-grained KeyType enum rejected valid cross-family
asymmetric updates (e.g. RSA_2048 to ECC_NIST_P256) that AWS KMS
accepts. AWS only requires the current and new key to be "the same
type (both symmetric or both asymmetric or both HMAC)" - a coarser
three-way split - so compare on that instead.
2026-08-15 12:54:39 -04:00

98 lines
3.8 KiB
Markdown

# KMS
**Protocol:** JSON 1.1 (`X-Amz-Target: TrentService.*`)
**Endpoint:** `POST http://localhost:4566/`
## Supported Actions
<!-- floci:actions:start -->
| Action | Description |
| --- | --- |
| `CreateKey` | Create a new KMS key |
| `GenerateRandom` | Generate random bytes |
| `GetPublicKey` | Get public key material for asymmetric keys |
| `DescribeKey` | Get key metadata |
| `ListKeys` | List all keys |
| `CreateGrant` | Create a grant for a KMS key |
| `ListGrants` | List grants for a KMS key |
| `ListRetirableGrants` | List grants retirable by a principal |
| `RevokeGrant` | Revoke (administratively delete) a grant |
| `RetireGrant` | Retire a grant (token- or key+grant-based) |
| `Encrypt` | Encrypt plaintext with a key |
| `Decrypt` | Decrypt ciphertext |
| `ReEncrypt` | Re-encrypt under a different key |
| `GenerateDataKey` | Generate a data key (plaintext + encrypted) |
| `GenerateDataKeyWithoutPlaintext` | Generate only the encrypted data key |
| `Sign` | Sign a message with an asymmetric key |
| `Verify` | Verify a signature |
| `GenerateMac` | Generate a MAC with an HMAC key |
| `VerifyMac` | Verify a MAC with an HMAC key |
| `CreateAlias` | Create a friendly name for a key |
| `UpdateAlias` | Repoint an alias at a different key |
| `DeleteAlias` | Remove an alias |
| `ListAliases` | List all aliases |
| `ScheduleKeyDeletion` | Mark a key for deletion |
| `CancelKeyDeletion` | Cancel pending deletion |
| `TagResource` | Tag a key |
| `UntagResource` | Remove tags |
| `ListResourceTags` | List tags |
| `GetKeyPolicy` | Get a key's resource policy |
| `PutKeyPolicy` | Update a key's resource policy |
| `ListKeyPolicies` | List a key's policy names (always the single `default` policy) |
| `UpdateKeyDescription` | Update a key's description |
| `GetKeyRotationStatus` | Check if automatic key rotation is enabled |
| `EnableKeyRotation` | Enable automatic key rotation (symmetric keys only) |
| `DisableKeyRotation` | Disable automatic key rotation |
| `EnableKey` | Enable a key |
| `DisableKey` | Disable a key |
| `RotateKeyOnDemand` | Rotate key material on demand (symmetric keys only) |
<!-- floci:actions:end -->
## Grant Support Scope
Grant lifecycle operations (`CreateGrant`, `ListGrants`, `ListRetirableGrants`, `RevokeGrant`, `RetireGrant`) are supported. However, grant lifecycle support **does not** imply grant-based authorization enforcement on cryptographic operations (`Encrypt`, `Decrypt`, `Sign`, `Verify`, `GenerateDataKey`, etc.). Grants are stored and queryable but are not evaluated during crypto operations.
## Configuration
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_KMS_ENABLED` | `true` | Enable or disable the service |
## Examples
```bash
export AWS_ENDPOINT_URL=http://localhost:4566
# Create a symmetric key
KEY_ID=$(aws kms create-key \
--description "My encryption key" \
--query KeyMetadata.KeyId --output text \
--endpoint-url $AWS_ENDPOINT_URL)
# Create an alias
aws kms create-alias \
--alias-name alias/my-key \
--target-key-id $KEY_ID \
--endpoint-url $AWS_ENDPOINT_URL
# Encrypt
CIPHER=$(aws kms encrypt \
--key-id alias/my-key \
--plaintext "Hello, World!" \
--query CiphertextBlob --output text \
--endpoint-url $AWS_ENDPOINT_URL)
# Decrypt
aws kms decrypt \
--ciphertext-blob $CIPHER \
--query Plaintext --output text \
--endpoint-url $AWS_ENDPOINT_URL | base64 --decode
# Generate a data key (envelope encryption)
aws kms generate-data-key \
--key-id alias/my-key \
--key-spec AES_256 \
--endpoint-url $AWS_ENDPOINT_URL
```
`CreateKey` also accepts a reserved creation-time tag key, `floci:override-id`, when tests need a deterministic `KeyId`. Floci uses the tag value as the created key id, strips the reserved tag from stored resource tags, and rejects attempts to add `floci:*` tags later via `TagResource`.