Commit 177e903
fix(keys): KeysExist must respect WithKeyParts
Background
----------
Vault delivers only the Encryption-side material (EncKey) to clients via
the agent manifest — Eval/Sec stay inside Vault for FHE evaluation and
re-encryption. A consumer reading that bundle calls
OpenKeysFromFile(WithKeyPath(...), ..., WithKeyParts(KeyPartEnc))
OpenKeysFromFile begins with a `KeysExist(opts...)` gate; if it returns
false, the open fails fast with ErrKeysNotFound.
Bug
---
KeysExist walked all three slots (Enc / Eval / Sec) unconditionally,
ignoring the caller's WithKeyParts. So the Vault-delivered Enc-only
bundle was rejected even when the caller had explicitly said "I only
need Enc".
Reproducer (the path the rune-mcp boot loop hit on first GetAgentManifest):
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "EncKey.json"), []byte("{}"), 0o600)
KeysExist(
WithKeyPath(dir),
WithKeyID("k"), WithKeyDim(1024),
WithKeyParts(KeyPartEnc),
)
// pre-fix: false → bundle rejected
// fixed: true → bundle accepted
Fix
---
KeysExist now resolves the requested KeyParts via the same helper
OpenKeysFromFile uses (resolveKeyParts) and only checks the slots the
caller actually requested. Default behavior (no WithKeyParts) is
preserved: resolveKeyParts returns enc=true,eval=true,sec=true, so a
bare KeysExist(WithKeyPath(...)) still requires all three.
Tests
-----
TestKeysExist_PartsAware covers:
- enc-only dir + WithKeyParts(KeyPartEnc) → true (Vault use case)
- enc-only dir + default parts → false (backward compat)
- enc-only dir + WithKeyParts(KeyPartEval) → false (other parts still missing)
Existing TestKeysExist_FalseWhenEmpty / TestGenerateKeys_CreatesAllThreeFiles
keep their prior expectations — both are exercised through the same
resolveKeyParts code path now.
Discovered while wiring rune-mcp v0.4 (Go port) against Vault's
GetAgentManifest flow; the boot loop's envector adapter opens keys with
KeyPartEnc only and was bouncing on this gate every retry.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 171f75b commit 177e903
2 files changed
Lines changed: 53 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | | - | |
127 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
0 commit comments