Skip to content

🔒 fix(security): reject cross-namespace secretRef at admission + validate inventory auth mode - #377

Merged
konih merged 1 commit into
mainfrom
fm/kollect-b2-secretref
Oct 1, 2026
Merged

konih merged 1 commit into
mainfrom
fm/kollect-b2-secretref

Conversation

@konih

@konih konih commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes two admission/startup defects from the six-review unification register
(batch B2, findings K-04 and K-12).

  • K-04 (CRITICAL) — cross-namespace secretRef confused deputy. A namespaced
    family-sink author could point spec.secretRef (or caSecretRef /
    git.auth.secretRef / databaseRef / per-backend secretRef) at another
    namespace's Secret while the manager holds cluster-wide secrets get. The
    validating webhook now rejects any SecretReference whose namespace is neither
    the sink's own namespace nor in a process-wide operator allowlist
    (--allow-secret-ref-namespaces / Helm allowSecretRefNamespaces, empty by
    default = deny). Captain decision C-1(a).
  • K-12 (HIGH) — inventory auth-mode typo disabled authorization. --inventory-auth-mode
    was a free string; anything but the exact kubernetes left the inventory HTTP
    server authenticating tokens without authorization. Startup now fails on any
    value outside {kubernetes, disabled}, and only disabled bypasses auth.

What changed

Area Change
internal/validation/secret_ref_namespace.go New: process-wide allowlist + ValidateSecretRefNamespaces walking every reference path on a normalized sink spec
internal/webhook/v1alpha1/family_sink_webhook.go The three family-sink validators call the guard on create/update
cmd/startup_flags.go / cmd/main.go New --allow-secret-ref-namespaces flag; validateInventoryAuthMode fails startup; RequireInventoryGet true for every non-disabled mode
internal/inventory/auth.go AuthDisabled() matches only disabled (drops the undocumented none alias)
Helm allowSecretRefNamespaces value + --allow-secret-ref-namespaces render + unittest
Docs Cross-namespace rule in the snapshot-sink CRD page and the security architecture

Test lock

  • Webhook envtest (internal/webhook/v1alpha1/secret_ref_namespace_envtest_test.go):
    cross-namespace ref denied through the real API server + webhook when the
    allowlist is empty (error names spec.secretRef.namespace); admitted when the
    namespace is allowlisted; same-namespace ref admitted.
  • Startup flag enum (cmd/startup_flags_test.go): kubernetes/disabled
    pass, anything else errors; allowlist flag round-trip.
  • Unit coverage of every reference path in internal/validation/secret_ref_namespace_test.go.

Testing

  • go test ./internal/webhook/v1alpha1/ (envtest) ✅
  • go test ./cmd/... ./internal/inventory/... ./internal/validation/... ✅
  • task arch-lint, golangci-lint (changed packages), gofmt, go vet ✅
  • helm unittest charts/kollect, task helm-lint, task helm-docs:verify ✅
  • Full non-e2e suite green except internal/sink/git, which hangs on a git
    credential prompt in this environment and passes with
    GIT_TERMINAL_PROMPT=0 (untouched package).

Risk / residual

  • The guard is admission-time, per C-1. Disabling webhooks removes it, and a
    sink admitted before the control is not re-checked; a resolve-time check
    against the same allowlist would close that and is a possible follow-up.
  • The allowlist is a flat list of target namespaces: any sink author can read an
    allowlisted namespace, so it should list only namespaces whose Secrets every
    sink author is trusted to read. Documented in values.yaml and the security doc.

Independent review

A fresh diff-only reviewer returned APPROVE, with the admission-only scope
and allowlist breadth noted above; the docs were tightened to state the control
is admission-time.

@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/validation/secret_ref_namespace.go 96.07% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…lidate auth mode

K-04: a family-sink SecretReference is rejected at admission when its
namespace is neither the sink's own namespace nor in the operator
--allow-secret-ref-namespaces allowlist (process-wide, never a CRD field).
Covers secretRef, tls.caSecretRef, git.auth.secretRef and every per-backend
databaseRef/secretRef; test lock is webhook envtest cross-ns reject/allow.

K-12: --inventory-auth-mode is validated at startup against
{kubernetes, disabled}; only disabled bypasses auth, so a typo can no longer
leave the inventory HTTP server authentication-only. Test lock is the startup
flag enum test.
@konih
konih force-pushed the fm/kollect-b2-secretref branch from b28b44c to df8c8b3 Compare October 1, 2026 15:27
@konih
konih merged commit 23e8b86 into main Oct 1, 2026
38 of 39 checks passed
@konih
konih deleted the fm/kollect-b2-secretref branch October 1, 2026 15:35
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant