Skip to content

feat: add KMS service with all 39 operations - #6

Merged
tyrchen merged 3 commits into
masterfrom
feat/kms-service
Mar 19, 2026
Merged

tyrchen merged 3 commits into
masterfrom
feat/kms-service

Conversation

@tyrchen

@tyrchen tyrchen commented Mar 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Add complete AWS KMS (Key Management Service) support with 39 operations across 3 phases, real cryptographic operations via aws-lc-rs, and full aws-sdk-kms compatibility
  • Three new crates: ruststack-kms-model (Smithy-generated types), ruststack-kms-http (awsJson1.1 protocol layer), ruststack-kms-core (business logic + crypto engine)
  • Integrated into the gateway on port 4566 with TrentService.* X-Amz-Target routing, feature-gated behind kms cargo feature

Phase 0: Key Management + Cryptographic Operations (21 ops)

  • Key lifecycle: CreateKey, DescribeKey, ListKeys, EnableKey, DisableKey, ScheduleKeyDeletion, CancelKeyDeletion, UpdateKeyDescription
  • Symmetric encryption: Encrypt, Decrypt, ReEncrypt (AES-256-GCM with self-describing ciphertext blobs)
  • Envelope encryption: GenerateDataKey, GenerateDataKeyWithoutPlaintext, GenerateDataKeyPair, GenerateDataKeyPairWithoutPlaintext
  • Digital signatures: Sign, Verify (RSA PSS/PKCS1v1.5, ECDSA P-256/P-384/P-521), GetPublicKey
  • HMAC: GenerateMac, VerifyMac (HMAC-SHA-224/256/384/512)
  • Random: GenerateRandom

Phase 1: Aliases + Tags + Policies (10 ops)

  • CreateAlias, DeleteAlias, ListAliases, UpdateAlias
  • TagResource, UntagResource, ListResourceTags
  • GetKeyPolicy, PutKeyPolicy, ListKeyPolicies

Phase 2: Grants + Key Rotation (8 ops)

  • CreateGrant, ListGrants, RetireGrant, RevokeGrant, ListRetirableGrants
  • EnableKeyRotation, DisableKeyRotation, GetKeyRotationStatus

Key Design Decisions

  • Real crypto via aws-lc-rs: AES-256-GCM, RSA OAEP, RSA PSS/PKCS1, ECDSA, HMAC — not mocked
  • Self-describing ciphertext blob: embeds key ID + IV + auth tag so Decrypt works without explicit KeyId
  • Base64 blob serde: custom serializers for bytes::Bytes fields matching AWS wire format
  • Epoch seconds timestamps: custom serde for chrono::DateTime fields matching AWS SDK expectations
  • Key state machine: Enabled ↔ Disabled → PendingDeletion, with proper state validation on all operations
  • Key material redacted from Debug: prevents accidental logging of cryptographic secrets

Test plan

  • 29 integration tests using aws-sdk-kms covering all phases
  • All 1061 existing tests pass (no regressions)
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo +nightly fmt applied
  • CI integration tests pass (cargo test -p ruststack-integration -- --ignored)

🤖 Generated with Claude Code

tyrchen and others added 3 commits March 18, 2026 09:27
Implement AWS KMS (Key Management Service) support for RustStack with
real cryptographic operations using aws-lc-rs.

## Phase 0: Key Management + Crypto (21 operations)
- CreateKey, DescribeKey, ListKeys, EnableKey, DisableKey
- ScheduleKeyDeletion, CancelKeyDeletion, UpdateKeyDescription
- Encrypt/Decrypt (AES-256-GCM symmetric), ReEncrypt
- GenerateDataKey, GenerateDataKeyWithoutPlaintext
- GenerateDataKeyPair, GenerateDataKeyPairWithoutPlaintext
- Sign/Verify (RSA PSS/PKCS1, ECDSA P-256/P-384/P-521)
- GetPublicKey, GenerateMac/VerifyMac (HMAC-SHA-*), GenerateRandom

## Phase 1: Aliases + Tags + Policies (10 operations)
- CreateAlias, DeleteAlias, ListAliases, UpdateAlias
- TagResource, UntagResource, ListResourceTags
- GetKeyPolicy, PutKeyPolicy, ListKeyPolicies

## Phase 2: Grants + Key Rotation (8 operations)
- CreateGrant, ListGrants, RetireGrant, RevokeGrant, ListRetirableGrants
- EnableKeyRotation, DisableKeyRotation, GetKeyRotationStatus

## Architecture
- Smithy-generated model types from official AWS JSON AST
- Custom base64 serde for blob fields (ciphertext, plaintext, etc.)
- Self-describing ciphertext blob format (key ID + IV + tag + data)
- Key state machine (Enabled/Disabled/PendingDeletion)
- DashMap-based concurrent storage for keys, aliases, grants
- TrentService.* X-Amz-Target routing (awsJson1.1 protocol)
- Feature-gated integration in gateway (single binary on port 4566)
- 29 integration tests using aws-sdk-kms

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Security:
- Redact key material in Debug impls for KmsKey and KeyMaterial

Correctness:
- Fix internal_error using DependencyTimeoutException -> KMSInternalException
- Add PendingWindowInDays validation (7-30 range)
- Add key state validation for update_key_description
- Fix cast_sign_loss with usize::try_from

Compatibility:
- Add epoch_seconds serde for timestamp fields (f64 epoch seconds)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tyrchen
tyrchen merged commit 88368ef into master Mar 19, 2026
14 checks passed
@tyrchen
tyrchen deleted the feat/kms-service branch March 19, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant