Skip to content

feat: replace VaultAuth init container with operator-side vault-client-go#1399

Merged
slntopp merged 5 commits intomainfrom
refactor/vault-auth-operator-side
Mar 13, 2026
Merged

feat: replace VaultAuth init container with operator-side vault-client-go#1399
slntopp merged 5 commits intomainfrom
refactor/vault-auth-operator-side

Conversation

@chris-rock
Copy link
Copy Markdown
Member

Summary

  • Replaces the hashicorp/vault:1.18.3 init container approach with direct use of vault-client-go in the operator controller
  • The operator now fetches Vault credentials during reconciliation and writes a kubeconfig Secret that the CronJob mounts identically to kubeconfigSecretRef
  • Removes the need for the Vault image, init containers, emptyDir volumes, and a separate ServiceAccount for Vault auth

Changes

New files:

  • controllers/k8s_scan/vault.go — Vault client logic: VaultTokenFetcher interface, DefaultVaultTokenFetcher (Kubernetes auth login + credential generation), kubeconfig builder, Secret builder
  • controllers/k8s_scan/vault_test.go — Unit tests for vault helpers

Modified files:

  • controllers/k8s_scan/resources.go — Removed VaultImage, VaultAuthServiceAccountName, VaultAuthServiceAccount, vaultInitContainer; replaced VaultAuth CronJob case with simple Secret volume mount
  • controllers/k8s_scan/deployment_handler.go — Replaced syncVaultAuthServiceAccount with syncVaultKubeconfigSecret; updated cleanup logic
  • controllers/k8s_scan/deployment_handler_test.go — Rewrote Vault tests using mock VaultTokenFetcher
  • controllers/mondooauditconfig_controller.go — Added update verb for secrets RBAC; wired VaultTokenFetcher
  • api/v1alpha2/mondooauditconfig_types.go — Added VaultAuthConfig type and updated field comments
  • docs/user-manual.md — Added credential refresh timing note
  • go.mod / go.sum — Added vault-client-go v0.4.3
  • config/rbac/role.yaml — Regenerated with update verb for secrets
  • config/crd/bases/k8s.mondoo.com_mondooauditconfigs.yaml — Regenerated CRD

Test plan

  • make generate passes
  • make manifests passes
  • make test passes (all unit tests)
  • make lint passes (0 issues)
  • make lint/actions passes
  • Manual verification with a Vault instance and external cluster

🤖 Generated with Claude Code

@chris-rock chris-rock force-pushed the refactor/vault-auth-operator-side branch from 89d7235 to 978e140 Compare February 19, 2026 15:39
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 19, 2026

Test Results

  7 files  ± 0   44 suites  ±0   1h 29m 52s ⏱️ -53s
413 tests +16  413 ✅ +16  0 💤 ±0  0 ❌ ±0 
479 runs  +16  473 ✅ +16  6 💤 ±0  0 ❌ ±0 

Results for commit 9dc2874. ± Comparison against base commit e74726a.

♻️ This comment has been updated with latest results.

@slntopp slntopp force-pushed the refactor/vault-auth-operator-side branch from 7ef40f8 to b4bb4b9 Compare March 13, 2026 10:59
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Vault-based dynamic credentials for external cluster scanning work correctly but tokens may expire before next reconcile.

Comment thread controllers/k8s_scan/deployment_handler.go
Comment thread controllers/k8s_scan/vault.go
Comment thread docs/user-manual.md
chris-rock and others added 4 commits March 13, 2026 14:20
…t-go

Instead of running a hashicorp/vault init container with shell scripts,
the operator now fetches credentials from Vault during reconciliation
using vault-client-go and writes a kubeconfig Secret that the CronJob
mounts directly. This removes the need for the Vault image, init
containers, and a separate ServiceAccount for Vault auth.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Return a clear error if the referenced CA cert secrets are missing
the expected "ca.crt" key, rather than silently falling back to
system CAs or insecure-skip-tls-verify.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the README feature table and auth method list to include
HashiCorp Vault. Fix stale mutually-exclusive comments on
KubeconfigSecretRef, ServiceAccountAuth, and WorkloadIdentity
fields that were missing SPIFFEAuth and/or VaultAuth.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The temp file path comes from os.CreateTemp which is safe. The newer
CI linter (v2.10.1) flags this as G703 path traversal via taint analysis.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@slntopp slntopp force-pushed the refactor/vault-auth-operator-side branch from b4bb4b9 to e84720d Compare March 13, 2026 13:21
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Adds HashiCorp Vault auth for external cluster scanning; RBAC broadening and lack of token-refresh requeue are the main concerns.

Additional findings (file/line not in diff):

  • 🟡 controllers/k8s_scan/deployment_handler.go:181Reconcile always returns ctrl.Result{} (no RequeueAfter). When VaultAuth is in use, the Vault-issued token stored in the kubeconfig Secret will expire, but no reconcile will be triggered to refresh it until the next external event (config change, or the controller-runtime default resync—usually 10h). Consider returning ctrl.Result{RequeueAfter: <something shorter than TTL>} when at least one VaultAuth cluster is configured, so the Secret is refreshed before the token expires.

Comment thread config/rbac/role.yaml
Comment thread controllers/k8s_scan/vault.go
Comment thread controllers/k8s_scan/deployment_handler_test.go
* fix: generate crds

* test-suites for external scanning with Vault and self-scanning with connected Mondoo integration

* feat: implement Vault credential refresh logic and update user manual
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Vault credentials now auto-refresh before expiry; e2e test coverage added for Vault-based external cluster scanning.

@slntopp slntopp merged commit 23cbca0 into main Mar 13, 2026
29 of 30 checks passed
@slntopp slntopp deleted the refactor/vault-auth-operator-side branch March 13, 2026 14:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants