Repository navigation
fix(deploy/k8s): combined trust file, trust line on every run, settable token TTLs (#432) - #464
Conversation
…le token TTLs (rossoctl#432) Follow-ups from the OpenShift acceptance run (rossoctl#423) and the rossoctl#427 reviews. - --target ocp writes .generated/ocp/moca-ca.crt: the supervisor's certificate when it is self-issued, plus the cluster's default ingress CA (openshift-config-managed/default-ingress-cert ca-bundle.crt), which signs the control plane's edge Route. Reading the ingress CA is best effort; a failure is a warning. - The supervisor CA file is rebuilt from the Secret's tls.crt on every run (ocp and ocp-single), and print_access prints the NODE_EXTRA_CA_CERTS line on every run, so a re-run or a second checkout repeats it. - SH_API_TOKEN_TTL_SECONDS and SH_SESSION_TOKEN_TTL_SECONDS are sticky moca-settings keys read by the control plane; empty means its default. A malformed value is refused, given or stored. Fixes rossoctl#432 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
The three #432 follow-ups are well scoped and well tested: the sticky token lifetimes (validated given or stored, defaulting on empty, rolling on change), rebuilding the supervisor CA from the Secret, and printing the trust line on every run. There is one blocking bug. In the default --target ocp case (self-signed supervisor plus the ingress CA), the combined moca-ca.crt is malformed, and Node discards the whole file. The new test counts lines with grep -c, so it can't see the problem.
Author: pdettori (MEMBER, maintainer)
Areas reviewed: Shell (deploy/k8s/setup.sh, tests/setup.test.sh), K8s manifests (base/control-plane.yaml), TS test, Docs (README §2/§9.1/§9.3)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 14 checks, incl. deploy-scripts and k8s-kind-e2e)
Must-fix
refresh_supervisor_cawritesSUP_CAwithout a trailing newline, sowrite_trust_fileglues the ingress CA onto it:-----END CERTIFICATE----------BEGIN CERTIFICATE-----. I reproduced this with the same data flow and Node 24:NODE_EXTRA_CA_CERTS=moca-ca.crtprintsWarning: Ignoring extra certs from ..., load failed: error:04800066:PEM routines::bad end line, and neither cert gets loaded.openssl crl2pkcs7 -certfilealso parses 0 certs. A user who exports the line this PR prints therefore trusts neither Route.
Verified, no action needed
intEnv(packages/control-plane/src/main.ts:32) maps''→ default, so the empty-string ConfigMap value really is "the control plane's default", and the 8-digit cap is needed for the reason the comment gives.write_settingsruns beforeapply_stack. An upgraded stack therefore has the two new keys before the non-optionalconfigMapKeyRefs are applied, so the pod can't hitCreateContainerConfigError.
| crt="$(self_issued_crt "$json")" | ||
| mkdir -p "$(dirname "$SUP_CA")" | ||
| if [[ -n "$crt" ]]; then | ||
| printf '%s' "$crt" >"$SUP_CA" |
There was a problem hiding this comment.
must-fix: crt came through two $(...) captures, so its trailing newline is gone. Written with printf '%s', moca-supervisor-ca.crt therefore ends in -----END CERTIFICATE----- with no \n. On its own that file parses. But write_trust_file then cats it and appends the ingress bundle, which produces the line -----END CERTIFICATE----------BEGIN CERTIFICATE-----. OpenSSL rejects that (bad end line), and Node ignores the whole NODE_EXTRA_CA_CERTS file with a warning. This is the default ocp path (self-signed supervisor plus ingress CA), so the printed trust line doesn't work.
Fix: printf '%s\n' "$crt" >"$SUP_CA", matching refresh_relay_ca. You could also make write_trust_file robust to either input, e.g. { cat "$SUP_CA"; echo; }.
There was a problem hiding this comment.
Fixed in 3ce9d7e. refresh_supervisor_ca now writes printf '%s\n', matching refresh_relay_ca. write_trust_file also emits each PEM as printf '%s\n' "$(cat "$SUP_CA")", so it stays well-formed whatever its input ended with. I confirmed the regression is caught: with the old printf '%s' + cat restored, the suite fails at "moca-ca.crt must hold the supervisor certificate and the ingress CA".
| pass 'ocp-single: SH_SANDBOX_EGRESS_EXCEPT is rendered and recorded in its namespace' | ||
|
|
||
| echo "== #432: the combined trust file, the trust line on every run, settable token lifetimes" | ||
| pem_count() { grep -c 'BEGIN CERTIFICATE' "$1" 2>/dev/null || true; } |
There was a problem hiding this comment.
suggestion: grep -c counts lines, so the glued -----END CERTIFICATE----------BEGIN CERTIFICATE----- line still counts as one, and the file still scores 2. That's why the bug above passes. Count parsed certificates instead, e.g. openssl crl2pkcs7 -nocrl -certfile "$1" | openssl pkcs7 -print_certs -noout | grep -c '^subject='. The $(cat ...) == "$sup_crt" check in the second-checkout case also strips trailing newlines, so it can't catch this either.
There was a problem hiding this comment.
Done in 3ce9d7e. pem_count now counts parsed certificates (openssl crl2pkcs7 -nocrl -certfile | openssl pkcs7 -print_certs -noout | grep -c ^subject=). The second-checkout case compares byte for byte (printf '%s\n' "$sup_crt" | cmp -s - file), and the first case also refuses any text after END CERTIFICATE----- on the same line.
| local crt subject issuer | ||
| crt="$(json_value "$1" tls.crt)" | ||
| [[ -n "$crt" ]] || return 0 | ||
| subject="$(printf '%s\n' "$crt" | openssl x509 -noout -subject_hash 2>/dev/null)" || return 0 |
There was a problem hiding this comment.
suggestion: When tls.crt doesn't parse, || return 0 silently treats the cert as not self-issued. The run then removes the CA file and prints the "If mocactl does not trust the cluster's ingress certificate" line, with no hint that the supervisor's certificate was unreadable. refresh_relay_ca dies in the same situation (moca-relay-tls holds no readable certificate). A log "WARNING: ..." at minimum would keep the two consistent.
There was a problem hiding this comment.
Done in 3ce9d7e. An empty or unparsable tls.crt now logs WARNING: Secret <name> holds no readable certificate (tls.crt) ..., which names the Secret, and there is a test for it. I kept it a warning rather than a die: the supervisor CA is only a convenience file here, while the relay CA is shipped inside every P4 bundle.
| if json="$(kc get configmap default-ingress-cert -n openshift-config-managed --ignore-not-found -o json 2>"$err")"; then | ||
| bundle="$(cm_value "$json" ca-bundle.crt)" | ||
| [[ -n "$bundle" ]] || | ||
| log "WARNING: openshift-config-managed/default-ingress-cert has no ca-bundle.crt, so $TRUST_CA lacks the ingress CA" |
There was a problem hiding this comment.
nit: With --ignore-not-found, a missing ConfigMap returns empty output and exit 0, so it lands here and reports "has no ca-bundle.crt". Saying "is missing or has no ca-bundle.crt" would be accurate for both cases.
There was a problem hiding this comment.
Done in 3ce9d7e: the message is now "is missing or has no ca-bundle.crt". The new unreadable-cert test also covers it with the ConfigMap absent.
| # valid_ttl VALUE: empty (the control plane's default) or a positive whole number of seconds. At | ||
| # most 8 digits (over three years): the control plane silently takes its default for anything it | ||
| # cannot read as a positive number, so a typo must be refused here instead. | ||
| valid_ttl() { [[ -z "$1" || "$1" =~ ^[1-9][0-9]{0,7}$ ]]; } |
There was a problem hiding this comment.
nit: The cap allows an API bearer token of up to ~3 years (99,999,999 s). The README example is 8 h. Consider a log "WARNING: ..." above some sane ceiling (for example 7 days), so a stray extra digit doesn't mint near-permanent tokens unnoticed.
There was a problem hiding this comment.
Done in 3ce9d7e. write_settings logs a warning when either lifetime, given or stored, is over 7 days (604800 s), e.g. SH_API_TOKEN_TTL_SECONDS=2592000 is over 7 days: every API token a login mints stays valid that long. The tests cover both cases: an 8 h value gets no warning, and a 30 d value warns.
…sor CA, parsed-cert test - refresh_supervisor_ca wrote the certificate without its final newline (lost to $(...)), so write_trust_file glued the ingress CA onto its END line and Node ignored the whole NODE_EXTRA_CA_CERTS file. Write it newline-terminated, and have write_trust_file put each PEM on its own lines whatever its source ended with. - The test counted BEGIN lines, which a glued file still passes; count the certificates OpenSSL parses, compare the CA file byte for byte, and refuse text after an END line. - An unreadable supervisor tls.crt is now a warning naming the Secret, not silently treated as an issued certificate. - A missing default-ingress-cert is reported as "missing or has no ca-bundle.crt". - A token lifetime over 7 days is warned about. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Incremental review of daf212d..3ce9d7e. All five points from the previous review are addressed, and I verified each fix against the code at this head:
- must-fix (glued PEM): fixed.
refresh_supervisor_cawritesprintf '%s\n', andwrite_trust_filenewline-terminates each PEM, somoca-ca.crtis well-formed whatever its input ends with. - Test counted lines: fixed.
pem_countcounts parsed certificates, there is a new guard against text afterEND CERTIFICATE-----, and the second-checkout check is a byte-for-bytecmp. - Unreadable
tls.crt: now a WARNING naming the Secret, with a test. A warning rather than adieis reasonable here.logwrites to stderr, so it can't leak into the$(self_issued_crt …)capture. - Missing ConfigMap message and >7-day TTL warning: both fixed and tested. The arithmetic is octal-safe because
valid_ttlrejects leading zeros.
One nit inline. Non-blocking: only the API-token TTL warning has a test, and the session-token branch is the same shape.
Author: pdettori (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: 2, all signed-off
CI: passing (14/14)
| [[ "$subject" != "$issuer" ]] || printf '%s\n' "$crt" | ||
| return 0 | ||
| fi | ||
| log "WARNING: Secret $2 holds no readable certificate (tls.crt), so no trust file carries the supervisor's: fix or delete the Secret and re-run" |
There was a problem hiding this comment.
nit: "fix or delete the Secret and re-run" fits moca-supervisor-tls, where deleting it lets route_cert mint a fresh one. On ocp-single --tls-secret, though, this path runs for the operator's own preinstalled Secret, and deleting that makes the next run die in check_tls_secret ("does not exist"). Consider "fix the Secret (or delete it, if setup.sh made it) and re-run".
Conflicts with rossoctl#464 and rossoctl#465 in deploy/k8s/README.md and the two VM demo guides. Kept main's newer rows and settings text; the token rows say the 15-minute API token renews itself, and the k8s README's sticky SH_API_TOKEN_TTL_SECONDS default is now 900 seconds, with a note that a longer value only stretches revocation latency. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Follow-ups from the OpenShift acceptance run (#423) and the #427 reviews, for
deploy/k8s/setup.sh.Changes
Combined trust file (
--target ocp). Each run writesdeploy/k8s/.generated/ocp/moca-ca.crtand prints its path. It holds:ca-bundle.crtofopenshift-config-managed/default-ingress-cert). This CA signs the control plane's edge Route.Reading the ingress CA is best effort. If it fails, the run warns and the file holds the supervisor's certificate alone.
Trust line on every run. The supervisor's CA file is rebuilt from the Secret's
tls.crton every run, on bothocpandocp-single.print_accessprints theNODE_EXTRA_CA_CERTSline every time, so a re-run or a second checkout shows it too. With a CA-issued--tls-cert, nothing is called self-signed, and the file holds only the ingress CA.Settable token lifetimes.
SH_API_TOKEN_TTL_SECONDSandSH_SESSION_TOKEN_TTL_SECONDSare now kept inmoca-settings, sticky like the other settings.base/control-plane.yamlreads both. Empty means the control plane's default (3600 and 300 seconds). A malformed value is refused, whether it is given or already stored; otherwise the control plane would quietly use its default.The README is updated in §2 (sticky inputs), §9.1 (trust) and §9.3 (how long a login lasts).
Upgrade note
moca-settingsnow has eight keys instead of six. The settings hash changes, so an existing stack restarts its control plane once on its first re-run.Testing
deploy/k8s/tests/setup.test.shpasses, with 7 new cases:ocp-singletrust line, with and without Routes;packages/supervisork8s manifest tests: 88/88 pass.base-control-plane.test.tsnow checks the two new environment variables.Fixes #432
🤖 Assisted-By: Claude Code