Skip to content

Enable TLS for operator-wide Redis defaults - #6838

Merged
ChrisJBurns merged 4 commits into
stacklok:mainfrom
Sanskarzz:feat/default-redis-tls
Oct 27, 2026
Merged

ChrisJBurns merged 4 commits into
stacklok:mainfrom
Sanskarzz:feat/default-redis-tls

Conversation

@Sanskarzz

@Sanskarzz Sanskarzz commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The runtime and per-workload APIs support Redis TLS after #6731 and #6767, but workloads using the operator-wide defaultRedis fallback still cannot enable it. This prevents that fallback from connecting to TLS-only Redis endpoints.

  • Add explicit global TLS enablement and an optional CA Secret reference to Helm values.
  • Read and validate operator environment settings once before manager startup, preventing malformed TLS configuration from silently becoming plaintext. Inject the same defaults into all three controllers and the vMCP converter, keeping TLS conversion and CA projection independent of the environment.
  • Reuse session TLS conversion, CA projection, and deployment drift handling for MCPServer, MCPRemoteProxy, and VirtualMCPServer. Rate limiters continue to share the selected session storage TLS settings through the existing runtime wiring.
  • Preserve explicit per-workload Redis overrides and plaintext behavior when TLS is disabled.

Closes #6827

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • October 27 rebase: focused operator race tests (controllerutil, vmcpconfig, controllers, app), operator lint with golangci-lint v2.15.0, all 88 Helm tests, chart rendering, Helm lint, and Helm documentation generation passed. The ConfigMap cases exercise the real reconciler-to-converter path.
  • October 25 review revision: focused operator tests through Task with the repository's linker flags and race detector passed for controllerutil, vmcpconfig, controllers, and app.
  • October 25 review revision: operator lint through Task with CI's pinned golangci-lint v2.15.0 reported 0 issues; license and codespell v2.4.3 checks passed.
  • On the rebased chart, task helm-unittest passed 85 operator tests and 3 CRD-chart tests, and task helm-docs completed. The subsequent startup-injection revision does not change the chart.
  • The auth-server Redis storage package passed with race detection on the rebased branch. This revision does not change that package.

The paired regression test builds the actual runtime configuration and Deployment from the same workload specification, then checks that the runtime CA path resolves to the selected Secret mount. It covers all three workload types, global fallback, explicit overrides, disabled TLS, and existing memory-provider differences.

The ConfigMap test also exercises the real ensureVmcpConfigConfigMap pipeline with injected global plaintext and private-CA TLS defaults, plus an explicit plaintext Redis override. This pins the reconciler's forwarding of defaults to the converter.

Original implementation verification — October 15, 2026

The original implementation passed focused operator race tests, operator lint with golangci-lint v2.14.0, all 88 Helm tests, chart-testing lint for both charts and their CI values, Helm documentation generation, the license check, and codespell v2.4.3 over tracked files. A manual check also verified that malformed TLS settings stop the actual operator binary before Kubernetes setup.

Live verification used an isolated Kind cluster, the locally built operator, published v0.54.0 workload runtimes, and TLS-only password-protected Redis with a projected private CA:

  • MCPServer and VirtualMCPServer workloads became ready using only global Redis defaults, including the password and CA projections.
  • A Legacy MCP session initialized through vMCP, listed backend tools, and had its session key persisted in TLS-only Redis.
  • Restarting the operator with a different global CA Secret reference created new workload pods. The vMCP pod using the unrelated CA failed certificate verification and did not become ready; there was no plaintext downgrade. The previous healthy replica remained available during the failed rollout.

These live checks have not been repeated for the startup-injection revision.

The full repository unit suite, task test-e2e, and all operator integration suites were not run.

API Compatibility

  • This PR does not break the v1beta1 API.

No CRD fields, schemas, or runtime TLS types change. Global TLS defaults to disabled; existing address/password precedence remains unchanged.

The Go converter's default behavior does change: NewConverter(resolver, client) no longer reads global Redis settings from the environment during conversion. Direct Go callers relying on that fallback must load and validate defaults once at application startup with controllerutil.LoadDefaultRedisConfigFromEnv, handle its error, and pass WithDefaultRedisConfig(defaults) to the constructor. The operator already forwards this snapshot through VirtualMCPServerReconciler, so its Kubernetes Redis fallback remains wired without configuration migration.

Changes

File or area Change
Operator Helm values/template TLS settings, validation, and environment bridge
controllerutil/defaultredis.go, app/app.go Read and validate global defaults once, reject invalid settings, and inject the startup snapshot
controllerutil/session_redis_tls.go Keep TLS conversion and CA projection pure; callers pass the selected session storage
MCPServer/MCPRemoteProxy run-config builders and vMCP converter Forward global TLS into existing runtime configuration
All three reconcilers and Deployment builders Use injected defaults for configuration, password references, CA mounts, and drift detection
Existing Go/chart tests Validation, precedence, startup snapshots, paired runtime/CA projection, and reference changes
Chart README and architecture docs Configuration, namespace requirements, missing-CA FailedMount diagnostics, compatibility, and rotation behavior

Does this introduce a user-facing change?

Yes. Previously, the global fallback could only connect to Redis without TLS. Workloads using it can now connect to TLS-only Redis endpoints with certificate verification:

operator:
  defaultRedis:
    addr: redis.example.com:6380
    existingSecret: redis-password
    existingSecretKey: password
    tls:
      enabled: true
      caCertSecretRef:
        name: redis-ca
        key: ca.crt

Omit the CA reference to use system roots. Password and CA Secrets must exist in each workload's namespace; the operator projects references into workloads without copying Secrets between namespaces.

A missing CA Secret or key leaves affected pods in ContainerCreating with FailedMount events. Diagnose the missing reference with kubectl describe pod in the workload namespace. Updating global defaults requires an operator restart; workloads apply the new snapshot as they reconcile.

The environment bridge is TOOLHIVE_DEFAULT_REDIS_TLS_ENABLED, TOOLHIVE_DEFAULT_REDIS_TLS_CA_SECRET_NAME, and TOOLHIVE_DEFAULT_REDIS_TLS_CA_SECRET_KEY. Global TLS always verifies certificates; it has no insecureSkipVerify option.

Implementation plan

Implementation plan
  1. Extend global defaults with the existing Redis TLS type; read and validate once before manager startup and inject the snapshot into controllers and the converter.
  2. Add explicit Helm enablement and CA references without changing address/password resolution.
  3. Reuse runtime TLS and CA projection helpers for all three workload kinds.
  4. Verify overrides, failure handling, startup snapshot behavior, and CA reference changes; test runtime configuration and CA projections together.
  5. Update chart and architecture documentation.

Special notes for reviewers

  • Explicit per-workload Redis settings override the entire global connection, including TLS. Explicit Redis without TLS stays plaintext even when global TLS is enabled.
  • Preserve the pre-existing provider-selection inconsistency: MCPRemoteProxy suppresses global defaults for any explicit session storage; MCPServer/vMCP can still select global Redis for explicit provider: memory. Existing password selection is unchanged. CA projection follows each runtime selection policy.
  • TLS or CA-reference changes update the desired Deployment. Changing CA contents under the same reference requires a workload restart: the existing mount uses subPath, and the runtime loads trust at startup.
  • Invalid global settings return an error at startup, before controllers start. TLS helpers do not read environment variables or panic on malformed environment settings; callers supply the selected storage configuration from the validated startup snapshot.
  • The chart has no values.schema.json, so the existing Helm template validation remains in place.
  • Shared runtime TLS type consolidation and adopting the CA-file loader added by toolhive-core#386 are separate follow-up work, as requested in review. This PR changes neither runtime TLS types nor CA-file loading.
  • No new CLI flag, Redis client, mTLS, automatic CA reload, or chart version bump. Chart versions are release-bot managed.

@Sanskarzz Sanskarzz added the kubernetes Items related to Kubernetes label Oct 15, 2026
@Sanskarzz Sanskarzz self-assigned this Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.13%. Comparing base (f71ed5f) to head (993cdfc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/thv-operator/app/app.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6838   +/-   ##
=======================================
  Coverage   80.13%   80.13%           
=======================================
  Files         845      845           
  Lines       85670    85715   +45     
=======================================
+ Hits        68651    68691   +40     
- Misses      17014    17019    +5     
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reyortiz3 reyortiz3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. I checked it against toolhive-core's redisconn and the existing pkg/redisconfig path. It reuses the existing flow (sessionRedisTLS → SessionRedisTLSConfig → redisconfig.TLSConfig → redisconn.BuildTLSConfig) and adds no TLS handling of its own, so I see no conflict with core. I also checked the other callers of the changed helpers, and none is affected by the new nil→default behavior.

Two suggestions, both on choices the description already calls deliberate:

  1. sessionRedisTLS(nil) now reads the env and can panic. I understand the intent, and the startup validation makes it unreachable in the operator. A helper that was a pure function of its argument still gains a hidden env read, and each populateScalingConfig* re-parses the env. Could the default be read and validated once at startup and passed in?

  2. The fallback policy is encoded twice. SessionRedisTLSVolumesWithDefault and the populateScalingConfig* functions each decide when the global default applies. If they drift, a pod gets a CA mount without Redis, or Redis TLS without the CA. Could a test pin the two together?

Minor: a missing CA Secret only appears as a pod FailedMount, and the global default affects every workload that falls back to it. A line in the docs about that symptom would help. A values.schema.json might also replace some of the Helm fail checks, if the chart uses one.

Separately, not for this PR: the shared TLSConfig from #6731 duplicates storage.RedisTLSRunConfig (same two fields, different JSON tag casing). I'd like a follow-up to either upstream the CA-file loading into redisconn or unify the two types.

@reyortiz3

Copy link
Copy Markdown
Collaborator

Also, adding some of this to stacklok/toolhive-core#386 so we can re-use it later

@Sanskarzz
Sanskarzz force-pushed the feat/default-redis-tls branch from 0d9a1e1 to be386bf Compare October 25, 2026 19:03
@Sanskarzz

Copy link
Copy Markdown
Collaborator Author

Thanks @reyortiz3 — addressed both suggestions in be386bf.

  • Global Redis defaults are now read and validated once in app.Run, then the same read-only snapshot is injected into all three reconcilers and the vMCP converter. Runtime configuration, password Secret references, CA mounts, and drift checks use that snapshot. The TLS helpers are pure again: nil input returns nil, with no environment reads or panic path.
  • The regression test now builds the actual runtime configuration and Deployment from the same workload specification and checks that the runtime CA path resolves to the selected Secret mount. It covers all three workload types, explicit overrides, disabled TLS, the existing memory-provider differences, and CA reference changes. It also changes the environment after loading the defaults to verify that reconciliation continues using the startup snapshot.
  • Added the missing-CA FailedMount/ContainerCreating diagnostics and workload-namespace guidance to the architecture docs, and updated the PR description.

I also rebased onto upstream main and resolved the generated chart README conflict while preserving upstream's current chart/image versions.

Local verification passed: focused operator tests with race detection, operator lint with CI's pinned golangci-lint v2.15.0, license checks, and codespell. All 88 Helm tests passed on the rebased chart; the subsequent startup-injection changes do not modify the chart.

The chart does not currently have a values.schema.json, so I retained its template validation. Thanks for the CA-file loading work in toolhive-core#386; adopting that loader and consolidating the runtime TLS types remain separate follow-up work, as you suggested.

@ChrisJBurns

Copy link
Copy Markdown
Collaborator

@Sanskarzz Is this a breaking change? vMCP Converter no longer falls back to the default Redis address from the environment unless WithDefaultRedisConfig is passed?

Allow workloads using global Redis session defaults to request verified TLS with system roots or a namespace-local CA Secret. Reuse the session TLS wiring and CA projection paths while preserving explicit workload overrides and existing plaintext defaults.

Signed-off-by: Sanskarzz <[email protected]>
Read and validate global Redis settings once and inject the same snapshot
into session configuration, password references, CA mounts, and drift checks.
Keep TLS helpers independent of the environment and remove the panic path.

Pin runtime configuration to the generated CA projection for all three
workload kinds, including environment changes after startup. Document
missing-CA mount failures and the operator restart requirement.

Signed-off-by: Sanskarzz <[email protected]>
Exercise the reconciler-to-ConfigMap path with injected plaintext and TLS
defaults so missing converter option forwarding cannot silently select
in-memory storage. Preserve explicit Redis overrides in the same test.

Document the changed default behavior for direct Go converter callers and
their migration path, while distinguishing the preserved operator fallback.

Signed-off-by: Sanskarzz <[email protected]>
@Sanskarzz
Sanskarzz force-pushed the feat/default-redis-tls branch from be386bf to 993cdfc Compare October 27, 2026 14:13
@Sanskarzz

Copy link
Copy Markdown
Collaborator Author

@Sanskarzz Is this a breaking change? vMCP Converter no longer falls back to the default Redis address from the environment unless WithDefaultRedisConfig is passed?

Thanks, @ChrisJBurns, you’re right about direct Go callers. Removing the implicit environment fallback changes the converter’s default behavior. The operator’s fallback remains preserved because startup loads the defaults and the vMCP reconciler passes WithDefaultRedisConfig. This addresses @reyortiz3 request to avoid environment reads during conversion. I’ve documented the Go-level compatibility change and added regression coverage through the actual ConfigMap generation path.

@ChrisJBurns
ChrisJBurns merged commit d6bffea into stacklok:main Oct 27, 2026
43 of 44 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 28, 2026
2 tasks
github-actions Bot added a commit to stacklok/docs-website that referenced this pull request Oct 28, 2026
Covers operator.defaultRedis.tls (stacklok/toolhive#6838) and
dcrConfig.registrationProbeInterval (stacklok/toolhive#6948) for v0.59.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jerm-dro pushed a commit to stacklok/docs-website that referenced this pull request Oct 30, 2026
* Update stacklok/toolhive to v0.59.0

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Refresh reference assets for toolhive v0.59.0

* Document Redis TLS default and DCR re-check

Covers operator.defaultRedis.tls (stacklok/toolhive#6838) and
dcrConfig.registrationProbeInterval (stacklok/toolhive#6948) for v0.59.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Clarify DCR registration re-check wording

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kubernetes Items related to Kubernetes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TLS for operator-wide default Redis session storage

3 participants