Skip to content

feat(credentials): authenticate to Vault with the Kubernetes auth method - #3487

Open
khrisrichardson wants to merge 3 commits into
chainloop-dev:mainfrom
khrisrichardson:feat/vault-kubernetes-auth
Open

khrisrichardson wants to merge 3 commits into
chainloop-dev:mainfrom
khrisrichardson:feat/vault-kubernetes-auth

Conversation

@khrisrichardson

@khrisrichardson khrisrichardson commented Sep 28, 2026 •

Copy link
Copy Markdown

Part of #3488.

The Vault backend took only a static token. A static token has to be stored, and it either never expires or has to be
replaced by hand; the config already noted that role-based auth was the intended direction.

This adds an optional kubernetes_auth block (role, mount_path, token_path) as the alternative to token. The
schema requires exactly one of the two, as a protovalidate message oneof, so the Go API is unchanged.

How the login is kept alive:

  • chainloop logs in with the pod's service account token and renews the resulting lease with Vault's lifetime watcher.
  • When renewal ends, it logs in again, re-reading the projected token, which the kubelet rotates.
  • Renewal starts only after the client has validated, and it runs under a context.

Chart:

  • controlplane and cas keep automountServiceAccountToken: false. When kubernetesAuth.role is set, each gets a
    projected service account token (1h expiry, optional kubernetesAuth.audience) mounted at
    /var/run/secrets/chainloop/vault, and token_path defaults to it.
  • Otherwise the chart still requires token.

This works with OpenBao, which serves the same auth API.

Chart version bumped to 1.493.1.

AI assistance: this PR was written with the help of Claude Code. Each commit carries an Assisted-by: Claude Code trailer.

@chainloop-platform

chainloop-platform Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

PR validation — ⚠️ 1 failing

Status Policy Material Messages
⚠️ Failed pr-min-approvals pr-info
✅ Passed pr-description-required pr-info -
✅ Passed pr-user-story-linked pr-info -

View attestation ↗

AI Session Checks — ⏭️ bypassed by label

AI Coding Session Check Bypassed

This PR carries the skip-ai-session label, so the AI coding session check was bypassed.

Learn more about Chainloop Trace.

Security Checks — ✅ 7 passing

✅ AI Security Analysis

Nothing this change touches re-opens a recorded security fix.

View in Chainloop ↗ · How this works ↗

✅ secret-scan

Status Policy Messages
✅ Passed secrets-detection -

✅ sast-scan

Status Policy Messages
✅ Passed owasp-top10-2025 -
✅ Passed sast -
✅ Passed cwe-top25 -
✅ Passed cwe-top26-40-cusp -

✅ iac-scan

Status Policy Messages
✅ Passed iac-misconfiguration -
Scans not applied (2)
Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed

View attestation ↗


Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread pkg/credentials/vault/keyval.go Resolved
@jiparis

jiparis commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Thank you for this contribution. Before we can merge it, please fix these items:

  1. Sign your commits. The commits have a DCO sign-off, but GitHub shows them as not verified. Our contribution rules require signed commits (git commit -S -s). Refer to the GitHub signing guide.
  2. Bump the chart version. This PR changes the Helm chart source, so it must increase the patch version in deployment/chainloop/Chart.yaml. Rebase on main first, because the chart version on main changed after you opened this PR.
  3. Disclose AI assistance. If an AI tool helped you write any part of this PR, our AI contribution policy requires you to disclose it. Add an Assisted-by: trailer to each affected commit (for example Assisted-by: Claude Code), and state it in the PR description. Use the name of the tool that you used, not the name of the model.

@jiparis jiparis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check my comment

@khrisrichardson
khrisrichardson force-pushed the feat/vault-kubernetes-auth branch from 9920516 to 6b2bfa7 Compare October 1, 2026 17:59
The Vault backend took only a static token (config.proto carried
"TODO: Use application role auth instead"). A static token must be
stored, and either never expires or has to be replaced by hand.

Add an optional kubernetes_auth block (role, mount_path, token_path) as the
alternative to token; exactly one of them is required. chainloop logs in
with the pod's service account token, renews the resulting lease with
Vault's lifetime watcher, and logs in again (re-reading the projected
token, which the kubelet rotates) when renewal ends. Works with OpenBao,
which serves the same auth API. The chart renders kubernetes_auth when
secretsBackend.vault.kubernetesAuth.role is set, and still requires the
token otherwise.

Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
Assisted-by: Claude Code
…ken and kubernetes_auth

The either/or rule was enforced only in vault.NewManager. A protovalidate
message oneof states it in the schema, so an invalid configuration is
rejected when it is validated, with the Go API unchanged (a proto oneof
would have replaced the existing Token field).

Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
Assisted-by: Claude Code
…faults, and start renewal only once the client is valid

Review follow-ups on the Vault Kubernetes auth change:

- The chart sets automountServiceAccountToken: false on controlplane and
  cas, so the kubelet's default token path does not exist in their pods
  and a login with the chart's defaults could not succeed. When
  kubernetesAuth is selected, both pods now get a projected service
  account token (1h expiry, optional audience) mounted at
  /var/run/secrets/chainloop/vault, and token_path defaults to it.
  Automount stays off.
- The renewal goroutine started before client validation, so a failed
  validation left it running. It now starts only after validation
  succeeds, and keepLoggedIn takes a context that ends every wait.
- Tests: a lease that ends is replaced by a login that re-reads the
  (rotated) token file, and the loop stops with its context; a manager
  that fails validation logs in once and starts no renewer.

Signed-off-by: Khris Richardson <khris.richardson@gmail.com>
Assisted-by: Claude Code
@khrisrichardson

Copy link
Copy Markdown
Author

Thanks for the review. Rebased on main. All three commits are now signed, carry Assisted-by: Claude Code, and the PR description says so. The chart is bumped to 1.493.1. The cubic findings are fixed on this branch (token projected only when Kubernetes auth is selected; renewal starts after validation; a re-login test with a rotated token).

Checks run locally (container golang:1.27.3; chainloop main d4fc985 vs this branch): go mod tidy clean; the credentials config buf generate gives no diff; golangci-lint v2.14.0 (root, controlplane, cli, artifact-cas) and buf lint: 0 new findings (the first run found 3 in this PR's new test, two t.Fatal and an import group, now fixed); go test ./pkg/... ./internal/... ./deployment/... and make test for cli, controlplane and artifact-cas pass. Not run here: make api (its OpenAPI step needs Docker; this PR touches no controlplane API proto) and the integration tests (testcontainers), since there is no unprivileged Docker here.

CI: the Actions workflows (Test, Lint, CodeQL) have never run on this PR. As a first-time contributor's fork PR they waited for approval and expired after 30 days. Could a maintainer approve the runs after this push? The integration tests (testcontainers: Vault, AWS, the credentials manager) only run there; we ran everything else locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants