Issue #8302 : Add Kubernetes authentication to the HashiCorp Vault variable resolver - #8305
Issue #8302 : Add Kubernetes authentication to the HashiCorp Vault variable resolver#8305mattcasters wants to merge 2 commits into
Conversation
…ult variable resolver
bamaer
left a comment
There was a problem hiding this comment.
Nice work — the design is sound, backward compatibility is handled (empty authenticationType → TOKEN), and the JWT is read through HopVfs as it should be. I decompiled vault-java-driver to double-check the login path: loginByKubernetes(role, jwt, path) builds <address>/v1/<path>/login, so kubernetesLoginPath() returning auth/<mount> is correct.
Three things I'd like to see addressed:
1. An expired or revoked token is never retried, and the failure is silent. In tokenNeedsRefresh(), the 30s margin only applies when tokenRenewable is true. A non-renewable token (a role with token_type=batch, common for short-lived k8s workloads) only refreshes once remaining <= 0 — after it has already died. A resolve() in that window uses the dead token, gets a 403, and resolve() logs and returns null, so the variable silently resolves to nothing. Same gap if Vault revokes the token early, and if getAuthLeaseDuration() returns ≤ 0 then tokenExpiryMillis stays 0 and nothing ever refreshes.
Suggest applying the margin regardless of tokenRenewable, and re-authenticating once on an auth failure rather than returning null.
2. The old Vault token stays in the metadata file after switching to Kubernetes auth. setWidgetsHidden is visual only — GuiCompositeWidgets.getWidgetsContents reads every element regardless of visibility. So a user who had a token, switches to KUBERNETES and saves still has that token written into the variable-resolver JSON, which usually lives in a version-controlled project directory. The field is hidden, so they have no reason to think it is still there. Worth clearing the credentials that don't apply to the selected auth type on save.
3. toUpperCase() without a locale in parseAuthType() and readAuthType(). In a Turkish locale "kubernetes".toUpperCase() maps i → İ and valueOf throws. toUpperCase(Locale.ROOT) on both. testAuthTypeIsCaseInsensitive won't catch it since it runs in the default locale.
Testing. Ran both layers locally and they pass: VaultKubernetesAuthIT 7/7 against a real Vault container, plus the unit and UI tests, and the docker suite PROJECT_NAME=vault 4/4 including the new main-0004-kubernetes-auth. The test setup is genuinely good — neither layer needs a real cluster. One caveat for CI: @Testcontainers(disabledWithoutDocker = true) means the 7 IT tests skip silently and the build still reports success, so it's worth confirming the CI agent has a Docker daemon.
…ntication Apply the 30s refresh margin for non-renewable tokens, retry Kubernetes auth once on 401/403, clear unused credentials on save, and parse auth types with Locale.ROOT.
|
Thanks for the review — addressed in 0ed000d:
The CI Docker-daemon caveat is noted; |
|
Thanks for the thorough review, @bamaer! All points have been addressed in commit
All unit and UI tests pass, and Spotless is clean. |
The HashiCorp Vault (and OpenBAO) variable resolver can now authenticate with a Kubernetes ServiceAccount JWT instead of a long-lived Vault token.
Addresses #8302
What changed
TOKEN/KUBERNETESauthentication type onBaseVaultVariableResolver. Existing metadata without the field still usesTOKEN./var/run/secrets/kubernetes.io/serviceaccount/token, read with HopVfs), optional inline JWT, optional auth mount (defaultkubernetes).Tests
main-0004-kubernetes-authplus the existing vault suite.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean install apache-rat:checkto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.git rebase -i.addresses #123), if applicable.To make clear that you license your contribution under the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.