Repository navigation
feat(deploy/k8s): ocp-single opt-in Routes -- SH_ROUTE_DOMAIN and --tls-secret - #448
Conversation
…ls-secret The ocp-single target reaches the stack by port-forward because the cluster's apps domain cannot be read with namespace rights. A tenant whose operator set up a custom domain (wildcard DNS + certificate, ingress controller) can be reached properly: SH_ROUTE_DOMAIN opts into two Routes in the namespace -- moca.<domain> (supervisor, TLS passthrough to a ghostunnel L4 sidecar, the ocp target's shape) and moca-control-plane.<domain> (edge) -- rendered by a new overlays/ocp-single/routes Component the generated overlay lists only when the domain is set, so a stack without it renders exactly as before. The supervisor's certificate comes from --tls-secret (a preinstalled kubernetes.io/tls Secret referenced by name, never copied), --tls-cert/--tls- key, or a generated self-signed one, in that order. Both inputs are sticky in moca-setup; SH_ROUTE_DOMAIN= turns Routes off. SH_PUBLIC_HARNESS_URL follows the domain, so /v1/discovery advertises the Route and mocactl needs no port-forward. Verified on the ROKS tenant of §12.3: the operator's Let's Encrypt wildcard serves both the passthrough (--tls-secret) and edge (controller default) paths, with a namespace-scoped ingress controller admitted by the policy-group selector (README §12.5). Co-Authored-By: Claude Code <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Opt-in OpenShift Routes for ocp-single look right: passthrough + ghostunnel for the supervisor (keeps ADR-0037's per-connection routing), an edge Route for the control plane, NetworkPolicies that let the router in, and a Component that leaves the default render unchanged. Tests cover the render, stickiness and refusals well. Three suggestions about how --tls-secret interacts with --tls-cert and stickiness on re-runs; none block merge.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Shell, Kustomize/K8s YAML, TypeScript tests, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: 11 passing; Check, proto, k8s-kind-e2e pending
Assisted-By: Claude Code
| if [[ -n "$TLS_SECRET" ]]; then | ||
| local json | ||
| json="$(secret_json "$TLS_SECRET" "$NS")" | ||
| [[ -n "$json" ]] || die "Secret $TLS_SECRET does not exist (or is unreadable): --tls-secret needs a preinstalled kubernetes.io/tls Secret" |
There was a problem hiding this comment.
suggestion — A bad --tls-secret is recorded before it is rejected. In main, load_setup_inputs (which applies moca-setup with SH_TLS_SECRET) and ensure_secrets both run before ensure_tls checks the Secret. So a mistyped name, or --tls-secret with SH_ROUTE_DOMAIN= empty, is saved to moca-setup before the abort. That contradicts "a missing or mistyped name aborts before any apply" in the PR body. Recovery is easy (pass the right --tls-secret). Still, the existence/type check could move into load_setup_inputs before the ConfigMap is applied. Or record SH_TLS_SECRET only when ROUTE_DOMAIN is non-empty. The refusal test in setup.test.sh only checks that no moca-supervisor-tls Secret was written; it never checks moca-setup.
There was a problem hiding this comment.
Done in db1c508: the existence/type check is now check_tls_secret, called from load_setup_inputs before the moca-setup apply, so a mistyped name (or a name resolved from a saved domain) is refused without ever being recorded. The refusal test now also asserts moca-setup holds no SH_TLS_SECRET after the abort.
There was a problem hiding this comment.
Done in db1c508: the existence/type check is now check_tls_secret, called from load_setup_inputs before the moca-setup apply, so a mistyped name (or a name resolved from a saved domain) is refused without ever being recorded. The refusal test now also asserts moca-setup holds no SH_TLS_SECRET after the abort.
| data="$(jq -nc --argjson d "$data" --arg dom "$ROUTE_DOMAIN" '($d + {SH_ROUTE_DOMAIN: $dom}) | with_entries(select(.value != ""))')" | ||
| # --tls-secret is sticky too: with Routes kept on (SH_ROUTE_DOMAIN unset), a re-run without | ||
| # the flag must not fall back to a self-signed certificate over the operator's Secret. | ||
| if [[ -z "$TLS_SECRET" && -n "$ROUTE_DOMAIN" ]]; then TLS_SECRET="$(cm_value "$json" SH_TLS_SECRET)"; fi |
There was a problem hiding this comment.
suggestion — A saved --tls-secret silently beats --tls-cert/--tls-key. Once SH_TLS_SECRET is in moca-setup, a re-run with --tls-cert/--tls-key still loads the old secret name here. ensure_tls then uses it and ignores the cert pair without a word. Passing --tls-secret and --tls-cert together isn't refused either. Elsewhere the script avoids silent ignores on purpose (see the comment in ensure_tls). Suggest refusing the two flags together, and letting --tls-cert clear the saved SH_TLS_SECRET.
There was a problem hiding this comment.
Done in db1c508: --tls-cert/--tls-key and --tls-secret together are refused ('two certificate sources; pass one'), and a --tls-cert run no longer loads the saved name -- the key is simply absent from the applied ConfigMap, so the server-side apply drops it, and no later re-run can resurrect it over what the pair installed. Tested: the swap keeps the sticky domain, installs the pair, drops the volume patch and the ConfigMap key.
| [[ "$TARGET" == ocp ]] || die '--tls-cert/--tls-key apply to --target ocp only' | ||
| # ocp always has Routes; ocp-single only with SH_ROUTE_DOMAIN (README §12.5). | ||
| [[ "$TARGET" == ocp || "$TARGET" == ocp-single ]] || die '--tls-cert/--tls-key apply to --target ocp only' | ||
| [[ "$TARGET" != ocp-single || -n "${SH_ROUTE_DOMAIN-}" ]] || die '--tls-cert/--tls-key need SH_ROUTE_DOMAIN on --target ocp-single: without it there is no Route to serve' |
There was a problem hiding this comment.
suggestion — This check reads the env var SH_ROUTE_DOMAIN, not the saved domain. So a re-run that keeps Routes on (env unset) and passes --tls-cert/--tls-key to swap in a real certificate is refused. The --tls-secret path deliberately defers its check to ensure_tls for exactly this reason (see the comment at its validation in parse_args). --tls-cert could get the same deferral for consistency.
There was a problem hiding this comment.
Done in db1c508: --tls-cert gets the same deferral -- the domain check moved out of parse_args into load_setup_inputs (where the sticky domain is resolved), covering --tls-secret and --tls-cert alike, so a sticky-domain re-run swapping in a real certificate works. ensure_tls keeps only the certificate-serving logic; a source with no Routes is refused before moca-setup records anything.
…ot silently beat each other (rossoctl#448 review) Three interactions of --tls-secret with --tls-cert and stickiness, from the rossoctl#448 review: - A bad --tls-secret was recorded in moca-setup before the abort. The existence/type check moves into load_setup_inputs, before the ConfigMap apply (check_tls_secret), so a mistyped name is refused without ever being recorded; ensure_tls keeps only its use of the helper. - A saved SH_TLS_SECRET silently beat a later --tls-cert/--tls-key pair. The two flags together are refused (two certificate sources), and a --tls-cert run does not load the saved name -- the key's absence from the applied ConfigMap makes server-side apply drop it, so no later re-run can resurrect it over what the pair installed. - --tls-cert's SH_ROUTE_DOMAIN check read the env var, not the saved domain, so a sticky-domain re-run swapping in a real certificate was refused. The check now runs where the domain is resolved (load_setup_inputs, same deferral --tls-secret documents), covering --tls-secret/--tls-cert alike. Tests: the refusal cases now also assert nothing reached moca-setup; new cases for the mutual exclusion and the --tls-cert replacement (volume patch gone, ConfigMap key dropped, sticky domain intact). Co-Authored-By: Claude Code <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…s own directory (#448 follow-up) generated-overlay.test.ts and overlay-ocp-single-routes.test.ts both used deploy/k8s/.generated/test-ocp-single-routes. vitest runs test files in parallel, so one file's afterAll rmSync could remove the directory before the other's kubectl kustomize read it ("not a valid directory"); make test failed this way after the rebase onto #448. The generated-overlay case now writes .generated/test-generated-ocp-single-routes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
What
ocp-singlecan now serve the stack by OpenShift Routes instead of port-forwards, opted into with one environment variable:SH_ROUTE_DOMAIN(README §12.5). On a tenant whose operator set up a custom domain — wildcard DNS + certificate and an ingress controller — mocactl needs no port-forward at all:Two Routes render, in the namespace:
moca.<domain>(the supervisor, TLS passthrough to a ghostunnel L4 sidecar — §11's shape, because an edge Route there would silently break the supervisor's per-connection routing, ADR-0037) andmoca-control-plane.<domain>(ordinary edge).SH_PUBLIC_HARNESS_URLfollows the domain, so/v1/discoveryadvertises the Route and mocactl finds the harness through it.Why the domain is an input, not a lookup
The
ocptarget readsingresses.config/clusterfor the apps domain — a cluster-scoped read this target assumes you lack (§12.1). WithSH_ROUTE_DOMAINyou give the domain instead; nothing new needs cluster scope. The domain and--tls-secretare sticky inmoca-setuplike every input;SH_ROUTE_DOMAIN=set-but-empty turns the Routes off and returns to port-forward access.The supervisor's certificate, in priority order
--tls-secret NAMEkubernetes.io/tlsSecret by name; never copies it (existence and type checked; a missing or mistyped name aborts before any apply)--tls-cert FILE --tls-key FILEmoca-supervisor-tlsSecret (previously refused on ocp-single; now allowed with a domain)NODE_EXTRA_CA_CERTS)The edge Route embeds no certificate: the ingress controller serves its own (the operator's wildcard on a custom-domain tenant; the router default otherwise).
Structure
overlays/ocp-single/routes/— a Component (the p4-relay pattern) the generated overlay lists only when the domain is set, so a stack without it renders exactly as before. Contains: the ghostunnel sidecar patch (digest-pinned image, no explicit UID/GID — restricted-v2 assigns), themoca-supervisor-tlsService, both Routes (placeholder hosts; the generated overlay patches them), and the two router-admitting NetworkPolicies.setup.sh—SH_ROUTE_DOMAINvalidation + stickiness,--tls-secret(sticky too, so a re-run without the flag never falls back to a self-signed cert over the operator's),ensure_tls/public_harness_url/write_overlay/print_accessfor the new path.Tests
deploy/k8s/tests/setup.test.sh: renders (component listed, hosts patched, volume follows--tls-secret, settings and access text), stickiness (re-run keeps Routes; empty turns off), refusals (invalid domain, wrong target, missing/mistyped--tls-secretaborts generating nothing), self-signed fallback said aloud.packages/supervisor/test/k8s/overlay-ocp-single-routes.test.ts(new): the component rendered through realkubectl kustomize— sidecar shape, passthrough/edge Routes, netpol selectors and ports, ocp-single invariants intact with the component layered.generated-overlay.test.ts: an ocp-single + domain +--tls-secretvariant through setup.sh's ownwrite_overlay, asserting the Route hosts and thesecretNamepatch land.Verified
On the §12.3 ROKS tenant (
moca-ns): the operator's Let's Encrypt wildcard for*.moca-ns.vpc-int.res.ibm.comserves the passthrough path via--tls-secret moca-ns(and the edge path as the controller's default certificate), with a namespace-scoped ingress controller admitted by thepolicy-group.network.openshift.io/ingressselector. After a clean re-run (hand-applied canary objects deleted first),mocactl doctorpasses 7/7 over the Routes: control plane reachable/ready, logged in, credential present, harness located via the advertised Route URL, reachable, trusted.🤖 Assisted By Claude Code