[keymanager/wsd] Add /keys:destroy Go KOL handler with KEM + binding key destruction#651
Open
atulpatildbz wants to merge 12 commits intogoogle:mainfrom
Open
[keymanager/wsd] Add /keys:destroy Go KOL handler with KEM + binding key destruction#651atulpatildbz wants to merge 12 commits intogoogle:mainfrom
atulpatildbz wants to merge 12 commits intogoogle:mainfrom
Conversation
background reaper Enhances key lifecycle management by introducing FFI functions for manual key destruction and a background reaper for automatic expiration. Key Changes: - FFI Destruction: Added `key_manager_destroy_kem_key` (KPS) and `key_manager_destroy_binding_key` (WS) to allow external callers to explicitly remove keys from the registry. - Background Reaper: Implemented a background thread in `KeyRegistry` that periodically scans for and purges expired KEM keys. - Registry initialization: Updated KPS `KEY_REGISTRY` initialization to automatically start the reaper thread. - Testing: Added unit tests for manual destruction (success, not found, null ptr) and verified reaper functionality.
0d75eb1 to
60466aa
Compare
This change introduces automated C header generation using binding and fixes a critical ABI mismatch in the key custody FFI layer. Changes: 1. FFI Header Generation: - Added keymanager/generate_ffi_headers.sh script to generate C headers for all key custody components. - Added cbindgen.toml configurations for km_common, kps_key_custody_core, and ws_key_custody_core. - Exposed km_common::ffi with stable C-ABI structs and constants to ensure compatibility. 2. FFI ABI Safety Fix: - Problem: Previous FFI functions accepted HpkeAlgorithm (Protobuf-generated repr(Rust) struct) by value. This caused undefined behavior as C callers expected a C-compatible layout. - Fix: Updated key_manager_generate_kem_keypair and key_manager_generate_binding_keypair to accept KmHpkeAlgorithm, a dedicated repr(C) struct. - Mechanism: Implemented safe conversion (impl From<KmHpkeAlgorithm> for HpkeAlgorithm) to bridge the FFI boundary safely. - Verification: Added FFI-specific tests covering KmHpkeAlgorithm usage.
- Implement binding and KEM key generation endpoints in Workload Service.
- Add Key Protection Service client integration.
- Adapt Go CGO wrappers to match new Rust FFI signatures (KmHpkeAlgorithm, usize).
- Add component integration tests (Go Service -> Rust Core) to verify FFI flow.
Updates the EnumerateKEMKeys API to use snake_case JSON tags and string serialization for enums (KemAlgorithm, KeyProtectionMechanism) to align with the defined API contract.
- Update GenerateKemRequest and GenerateKemResponse JSON tags to use snake_case. - Update KemAlgorithm enum string representation to remove KEM_ALGORITHM_ prefix. - Update tests to reflect these changes.
…struction
Implement the Go KOL handler for POST /keys:destroy that orchestrates
the full key destruction flow:
1. Workload sends {kemKeyHandle} to WSD
2. WSD looks up binding UUID from KEM-to-binding map
3. WSD calls KPS DestroyKEMKey to destroy the KEM key
4. WSD calls WSD KCC DestroyBindingKey to destroy the binding key
5. WSD removes the KEM→Binding mapping
6. Returns 204 No Content
Changes:
- C headers: add key_manager_destroy_kem_key (KPS) and
key_manager_destroy_binding_key (WSD) declarations
- CGO bridges: add DestroyKEMKey and DestroyBindingKey Go wrappers
- KPS service: extend with DestroyKEMKey method and KEMKeyDestroyer
interface
- WSD server: add KEMKeyDestroyer/BindingKeyDestroyer interfaces,
DestroyRequest type, handleDestroy handler, /keys:destroy route
- Tests: 7 new destroy handler tests + 2 new KPS service tests
60466aa to
cff8e70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the Go orchestration layer (KOL) for
POST /v1/keys:destroy, the key destruction endpoint that allows workloads to explicitly destroy a key pair.Flow:
{key_handle: {handle: ...}}to WSDDestroyKEMKey— destroys the KEM key from the registryDestroyBindingKey— destroys the binding key from the registry204 No ContentChanges:
key_manager_destroy_kem_key(KPS) andkey_manager_destroy_binding_key(WSD) declarationsDestroyKEMKey()andDestroyBindingKey()Go wrappers for the Rust FFI functionsServicewithDestroyKEMKeymethod andKEMKeyDestroyerinterfaceKEMKeyDestroyer/BindingKeyDestroyerinterfaces,DestroyRequesttype,handleDestroyhandler,/v1/keys:destroyroute registrationTestIntegrationDestroyKeyDependencies
This PR is built on top of:
key_manager_destroy_ffi) — Rust FFI changes (Base commit:d1d6bad)wsd_generate_key_go) — Included via merge (Commit:d7f52c6)What to review
Please review the following commits:
d1d6bad—feat(keymanager): Add manual FFI headers for destroy(C headers for destroy)60466aa—[keymanager/wsd] Add /keys:destroy endpoint with KEM + binding key destruction(Go implementation)All other commits are from dependencies (PRs #647, #652) that are not yet merged to main but required for this build.
Verification
Automated Tests
go test ./keymanager/workload_service/...(Passed)go test -tags=integration ./keymanager/workload_service/...(Passed)Manual Verification (Curl)
Manually verified the destruction workflow locally:
POST /v1/keys:generate_kem-> Returns Handle.POST /v1/keys:destroy-> Returns 204.POST /v1/keys:destroy-> Returns 404 (Key mapping removed).