Invalid request: key does not exist – KV v2 list endpoint pagination ambiguity
0 reputation · 30 Jan 2024, 18:41 UTC
0 reputation · 30 Jan 2024, 18:41 UTC
The goal is to enumerate every key under a large KV v2 path using the /v1/secret/metadata/?list=true endpoint. The current implementation returns a plain keys array with no continuation token, so the caller must rely on prefix filtering to simulate pagination. Performance degrades noticeably with more than ~1,000 entries, and there is no documented cap on the number of keys returned per request.
When a non‑existent path is queried, the response is an error: Invalid request: key does not exist. It is unclear whether this error could also surface when the list operation is implicitly truncated by an internal limit, or if it only signals a truly missing path. ACL policies may hide keys, potentially masking the truncation.
Unresolved questions:
Invalid request: key does not exist error be triggered by an internal truncation rather than a truly missing path?31775 reputation · 31 Jan 2024, 01:33 UTC
The KV v2 /v1/secret/metadata/?list=true endpoint does not impose a documented internal key‑count limit; it returns all immediate children for the given prefix in a single response. The error Invalid request: key does not exist is only returned when the targeted metadata path does not exist (or is hidden by an ACL), not when an internal limit is reached.
/data/* prefix never supports ?list=true.keys array with no continuation token or limit/offset parameters in any released Vault version.When the prefix contains many keys, the single large JSON payload can exceed practical HTTP or memory limits, causing slow parsing or time‑outs. This performance drop is not due to a hidden pagination cutoff; it is simply the cost of transferring a large array.
GET /v1/secret/metadata//?list=true (note the trailing slash if you intend to list a “directory”)./data/ segment is present.keys array without error.Invalid request: key does not exist, verify that the prefix exists in the metadata tree and that your token’s policy includes list capability on that path.Use comments to ask for clarification. Post a solution as an answer.
4,470 reputation · 31 Jan 2024, 03:36 UTC
As the existing answer notes, there is no documented internal key-count limit or pagination for the KV v2 metadata list endpoint — the keys array contains all immediate children in one response. A subtlety that often causes confusion: the list only returns immediate children, not a recursive walk. If your 1,000+ entries live in nested sub-paths, a single list call will only ever show the top-level "folders" (entries ending in /), which can look like truncation when it isn't.
Listing /v1/secret/metadata/foo?list=true (no trailing slash) targets a key literally named foo, not the folder foo/. If only foo/bar exists, you'll get Invalid request: key does not exist even though data exists underneath. Always append the trailing slash when listing a directory.
vault list secret/foo/ against the raw API call — the CLI normalizes the slash for you, the HTTP API does not.