Repository navigation
Commit a5c2b1a
authored
fix(secret): treat ErrNotFound on keyring delete as already deleted (#1758)
## Bug
`KeyringProvider.Delete` treats every error from `keyring.Delete` as a
keyring failure, including `keyring.ErrNotFound`. When the entry was
already removed outside mcpproxy (Keychain Access, `security
delete-generic-password`, Seahorse, Credential Manager), it returns
before `removeFromRegistry`, so the name stays in the registry and
`List` keeps showing it. Every later delete hits the same error.
It also calls `markUnavailable()`, so for the rest of the process every
keyring `Store`/`Delete` short-circuits with `ErrKeyringUnavailable`,
even though the keyring just answered fine.
## Trigger
1. Store a secret `foo` through the UI or `mcpproxy secrets set`.
2. Delete the `mcpproxy`/`foo` item in Keychain Access.
3. Call `DELETE /api/v1/secrets/foo`. It returns `500 failed to delete
secret foo from keyring: secret not found in keyring` on every retry,
`foo` stays listed, and further secret writes fail as "keyring
unavailable".
## Fix
Treat `keyring.ErrNotFound` from the delete as success: the keyring
answered and the entry is already gone. So the provider is not marked
unavailable and execution continues to `removeFromRegistry`. Other
errors behave as before. `IsAvailable` already uses the same convention,
where `ErrNotFound` means "available, no secret".
## Test
`TestKeyringProvider_Delete_AlreadyGoneCleansRegistry` uses the existing
`withKeyringMocks` seam, with `Delete` returning `ErrNotFound`. It
asserts that `Delete` returns nil, the registry drops `foo`, `List`
returns only `bar`, and the provider is not marked unavailable.
## Commands run
- `CGO_ENABLED=0 go test -count=1 ./internal/secret`: ok
- With the fix reverted (`git stash` of `keyring_provider.go`), `-run
AlreadyGone` fails with `Delete of an already-removed secret: failed to
delete secret foo from keyring: secret not found in keyring`.
- `gofmt -l` on the edited files: no output1 parent 1f9911d commit a5c2b1a
2 files changed
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
| |||
0 commit comments