Skip to content

fix(openshell): remove cert-manager Certificate to fix TLS race condition - #1833

Merged
pdettori merged 3 commits into
rossoctl:mainfrom
pdettori:worktree-fix-openshell-tls-race
Jun 5, 2026
Merged

pdettori merged 3 commits into
rossoctl:mainfrom
pdettori:worktree-fix-openshell-tls-race

Conversation

@pdettori

@pdettori pdettori commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Remove charts/openshell/templates/certificate.yaml — the cert-manager Certificate resources
    were overwriting TLS secrets created by the certgen Helm hook with certs signed by a different CA
  • Remove unused tls.* values from values.yaml
  • Simplify deploy-tenant.sh Step 3 — replace the complex cert-manager retry loop with a simple
    secret-existence check (certgen hook now handles all TLS)

Root Cause

The chart had two conflicting TLS generators targeting the same secrets (openshell-server-tls,
openshell-client-tls):

  1. certgen.yaml — Helm pre-install hook that generates a self-signed CA + leaf certs
  2. certificate.yaml — cert-manager Certificates signed by openshell-ca-issuer (different CA)

Race condition:

  1. certgen hook runs → creates secrets with CA-A
  2. StatefulSet starts → gateway loads certs signed by CA-A
  3. cert-manager reconciles → overwrites secrets with certs signed by CA-B
  4. Sandbox pod starts → mounts CA-B → rejects gateway's CA-A cert → UnknownCA

Fix

Remove certificate.yaml so certgen is the sole TLS source. Helm hook ordering
guarantees certgen completes before the StatefulSet deploys, eliminating the race.

Test plan

  • Deploy with scripts/openshell/deploy-tenant.sh team1 on Kind
  • Verify openshell sandbox create succeeds (no UnknownCA errors)
  • Verify gateway pod serves cert matching the CA in the secret:
    kubectl get secret -n team1 openshell-server-tls -o jsonpath='{.data.ca\.crt}' | base64 -d > /tmp/ca.pem
    kubectl port-forward -n team1 svc/openshell-server 18080:8080 &
    echo | openssl s_client -connect localhost:18080 -CAfile /tmp/ca.pem 2>/dev/null | grep "Verify return code"
    # Expected: Verify return code: 0 (ok)

Assisted-By: Claude Code

pdettori added 3 commits May 7, 2026 22:41
cryptography is intentionally pinned to <47 in kagenti/backend because
versions 47+ crash with SIGILL on ARM64 Kind clusters. Add a Dependabot
ignore rule to prevent it from repeatedly opening PRs that conflict with
this constraint.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ell-tls-race

Signed-off-by: Paolo Dettori <[email protected]>

# Conflicts:
#	.github/dependabot.yml
…tion

The chart had two conflicting TLS cert generators targeting the same secrets:

1. certgen.yaml — Helm pre-install hook (creates openshell-server-tls and
   openshell-client-tls with a self-generated CA)
2. certificate.yaml — cert-manager Certificate resources (overwrites the same
   secrets with certs signed by a different CA via openshell-ca-issuer)

This caused a race condition: the gateway loads certs from certgen during
startup, then cert-manager overwrites the secrets with a different CA.
Sandbox pods that start later mount the new CA and reject the gateway's
stale cert with UnknownCA during mTLS handshake.

Fix: remove certificate.yaml so certgen is the sole TLS source.
The certgen hook runs before the StatefulSet (Helm hook ordering guarantees
this), eliminating the race.

Also simplifies deploy-tenant.sh Step 3 — no longer needs the complex
cert-manager retry loop since TLS is handled entirely by the certgen hook.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>

@mrsabath mrsabath 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.

Bel taglio, Paolo — netto, motivato, e i fatti tornano. I verified the key claims:

  • ✅ certgen hook (charts/openshell/templates/certgen.yaml) writes both openshell-server-tls and openshell-client-tls with matching SANs (server, .{tenant}, .svc, .svc.cluster.local, localhost, ingress.host).
  • ✅ Hook ordering: certgen Job uses helm.sh/hook: pre-install,pre-upgrade with hook-weight: -20 (RBAC at -30), so it runs before the StatefulSet. Race eliminated.
  • ✅ gatewayJwt.enabled: true is the default in values.yaml:46, so certgen always runs.
  • ✅ .Values.tls.* is referenced only in the file being deleted — no leakage.
  • ✅ −112 lines net; deploy/E2E pending the maintainer /run-e2e trigger.

Areas reviewed: Helm chart, Shell
Commits: 3 commits, all signed-off ✓ — net diff is only the 3 TLS files (the first two commits' content is already on main via f8ba6ab5/merge from upstream). Squash-on-merge would leave a single clean commit.
CI status: all green; deploy/E2E gated on maintainer trigger (expected).

Left a couple of non-blocking suggestions inline + two off-diff observations below. Approving as-is.

Off-diff observations

1. Stale openshell-ca-issuer setup/teardown. scripts/openshell/deploy-shared.sh:335-348 still installs a ClusterIssuer openshell-ca-issuer, and cleanup-shared.sh:238 removes it. After this PR, nothing in the chart consumes the issuer anymore — it's installed and torn down for no purpose. Candidate for a follow-up cleanup PR.

2. Research doc references. docs/research/openshell-mvp.md (lines 791, 841, 867, 884) still references the deleted tls.* values + cert-manager flow as design. It's a research note rather than user docs, so deferring is fine — just flagging.

# ── Step 3: Wait for certificates ──────────────────────────────────────────
log_info "Step 3: Waiting for cert-manager certificates"
# ── Step 3: Verify TLS secrets ─────────────────────────────────────────────
log_info "Step 3: Verifying TLS secrets (created by certgen hook)"

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.

suggestion (rotation): the deleted Certificate had duration: 8760h (1 year) with renewBefore: 720h (30 days), giving cert-manager auto-renew. With certgen, the secrets are created on pre-install / pre-upgrade, so rotation now requires a helm upgrade to re-run the hook. For an MVP that's a fine trade — but worth either a one-line note here (or in the gateway/install docs) so operators know the rotation model changed, or filing a tracking issue for built-in rotation when this graduates beyond MVP. Not a blocker for this PR.

@pdettori
pdettori merged commit 20209d6 into rossoctl:main Jun 5, 2026
24 of 25 checks passed
@github-project-automation github-project-automation Bot moved this from New /:ToDo to Done in Rossoctl Issue Prioritization Jun 5, 2026
pdettori added a commit that referenced this pull request Jun 6, 2026
fix(openshell): remove cert-manager Certificate to fix TLS race condition

(cherry picked from commit 20209d6)
Ladas added a commit to Ladas/kagenti that referenced this pull request Jun 6, 2026
Upstream PR rossoctl#1833 removed cert-manager Certificate resources, so the
certgen hook is now the sole TLS mechanism. The gatewayJwt.enabled=false
workaround (added to avoid cert-manager conflict) is no longer needed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants