Fix: prevent stale Vault credential caching and fix default KV secret keys#118
Open
tdferreira wants to merge 4 commits into
Open
Fix: prevent stale Vault credential caching and fix default KV secret keys#118tdferreira wants to merge 4 commits into
tdferreira wants to merge 4 commits into
Conversation
|
I would like it to be merged |
Contributor
Author
|
@froque could you please review this? |
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.
Problem
When the plugin is configured to read credentials from Vault
KV1orKV2secrets, the handling ofusername_key/password_keyand the in-memory credential cache can produce incorrect and misleading behavior.There were three related issues:
username_key/password_keyfields did not actually default tousername/passwordWhat was happening
In the UI, the
Username keyandPassword keyfields showed placeholder textusernameandpassword, which makes it look like those are the defaults. However, placeholders are only visual hints. If the user leaves those fields empty, the saved additional properties are empty strings, not actual default values.For
KV1/KV2, the plugin then used those empty values as the lookup keys when parsing the Vault response. That led to code paths equivalent to:data.get("")data.data.get("")which return
null, even if the secret actually contains validusernameandpasswordfields.This produced a confusing outcome:
nullWhy it was especially confusing
The plugin also caches fetched credentials in a static
ConcurrentHashMap.Originally, the cache key only contained:
It did not include:
username_keypassword_keyThat means a first failed fetch using blank or wrong key names could cache a
Credentialsobject containingnullvalues. If the user later corrected the key names in the UI, the plugin could still reuse the previously cached credentials because the cache key had not changed.From the user?s perspective, this looked like:
In reality, the plugin was often reusing stale cached credentials from an earlier incorrect lookup.
Expected behavior
For
KV1andKV2:username_keyandpassword_keyblank, the plugin should use sensible defaults:usernameandpasswordFor
DYNAMIC_ROLEandSTATIC_ROLE:username/passwordfields returned by VaultRoot causes
Visual default vs runtime default mismatch
The widget showed placeholder text but did not normalize blank values to actual defaults at runtime.
Incomplete cache key
The cache did not account for the configured KV field names, so changing those fields did not invalidate cached results.
Too-late failure mode
Missing values in the Vault payload were allowed to propagate as
null, instead of being validated where the secret was parsed.Blank token file handling
A blank token file field should mean ?use the normal default resolution?, including
$HOME/.vault-token.This behavior is now made explicit at the provider boundary.
What this PR changes
username_keynow defaults tousernamepassword_keynow defaults topasswordKV1/KV2; dynamic/static role handling remains unchangedusername_keyandpassword_key$HOME/.vault-tokenUser-visible impact
This fixes cases where:
KV2secret correctly contains:data.data.usernamedata.data.passwordnullcredentialsIt also improves diagnostics by failing at the Vault parsing step instead of only surfacing as a downstream database authentication failure.
Why this matters
Without this change, users can end up in a state where:
nullcredentials or reuses stale onesThat makes the issue very hard to reason about and can easily be mistaken for:
This PR aligns the runtime behavior with what the UI suggests, makes cache invalidation correct, and ensures incorrect KV key configuration fails in a direct and actionable way.
Considering the nature of this fix, it's recommended to create a new release (v2.0.2?) if this Pull Request is accepted.