Skip to content

Comments

[keymanager/wsd] Add /keys:destroy Go KOL handler with KEM + binding key destruction#651

Open
atulpatildbz wants to merge 12 commits intogoogle:mainfrom
atulpatildbz:wsd_destroy_go
Open

[keymanager/wsd] Add /keys:destroy Go KOL handler with KEM + binding key destruction#651
atulpatildbz wants to merge 12 commits intogoogle:mainfrom
atulpatildbz:wsd_destroy_go

Conversation

@atulpatildbz
Copy link
Collaborator

@atulpatildbz atulpatildbz commented Feb 9, 2026

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:

  1. Workload sends {key_handle: {handle: ...}} to WSD
  2. WSD looks up binding UUID from the KEM→Binding map
  3. WSD calls KPS DestroyKEMKey — destroys the KEM key from the registry
  4. WSD calls WSD KCC DestroyBindingKey — destroys the binding key from the registry
  5. WSD removes the KEM→Binding mapping
  6. Returns 204 No Content

Changes:

  • C headers: Added key_manager_destroy_kem_key (KPS) and key_manager_destroy_binding_key (WSD) declarations
  • CGO bridges: Added DestroyKEMKey() and DestroyBindingKey() Go wrappers for the Rust FFI functions
  • KPS service: Extended Service with DestroyKEMKey method and KEMKeyDestroyer interface
  • WSD server: Added KEMKeyDestroyer/BindingKeyDestroyer interfaces, DestroyRequest type, handleDestroy handler, /v1/keys:destroy route registration
  • Tests: 7 new destroy handler tests + 2 new KPS service tests + Integration test TestIntegrationDestroyKey

Dependencies

This PR is built on top of:

What to review

Please review the following commits:

  1. d1d6badfeat(keymanager): Add manual FFI headers for destroy (C headers for destroy)
  2. 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

  • Unit tests: go test ./keymanager/workload_service/... (Passed)
  • Integration tests: go test -tags=integration ./keymanager/workload_service/... (Passed)

Manual Verification (Curl)

Manually verified the destruction workflow locally:

  1. Generate Key: POST /v1/keys:generate_kem -> Returns Handle.
  2. Destroy Key (First): POST /v1/keys:destroy -> Returns 204.
  3. Destroy Key (Second): POST /v1/keys:destroy -> Returns 404 (Key mapping removed).

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.
NilanjanDaw and others added 8 commits February 16, 2026 09:40
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
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.

2 participants