Skip to content

fix(deploy/k8s): combined trust file, trust line on every run, settable token TTLs (#432) - #464

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/432-ocp-trust-and-ttls
Oct 8, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/432-ocp-trust-and-ttls

Conversation

@pdettori

@pdettori pdettori commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-ups from the OpenShift acceptance run (#423) and the #427 reviews, for deploy/k8s/setup.sh.

Changes

  1. Combined trust file (--target ocp). Each run writes deploy/k8s/.generated/ocp/moca-ca.crt and prints its path. It holds:

    • the supervisor's certificate, when it is self-issued;
    • the cluster's default ingress CA (ca-bundle.crt of openshift-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.

  2. Trust line on every run. The supervisor's CA file is rebuilt from the Secret's tls.crt on every run, on both ocp and ocp-single. print_access prints the NODE_EXTRA_CA_CERTS line 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.

  3. Settable token lifetimes. SH_API_TOKEN_TTL_SECONDS and SH_SESSION_TOKEN_TTL_SECONDS are now kept in moca-settings, sticky like the other settings. base/control-plane.yaml reads 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-settings now 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.sh passes, with 7 new cases:
    • the combined file's contents;
    • the trust line on a re-run, and on a run from a fresh checkout with the file rebuilt from the Secret;
    • an issued operator certificate;
    • an unreadable ingress CA;
    • the ocp-single trust line, with and without Routes;
    • the token lifetimes: sticky, cleared when set empty, a change restarts the control plane, malformed values refused whether given or stored.
  • packages/supervisor k8s manifest tests: 88/88 pass. base-control-plane.test.ts now checks the two new environment variables.
  • The pre-commit hooks pass.

Fixes #432

🤖 Assisted-By: Claude Code

…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]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 8, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_ca writes SUP_CA without a trailing newline, so write_trust_file glues 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.crt prints Warning: Ignoring extra certs from ..., load failed: error:04800066:PEM routines::bad end line, and neither cert gets loaded. openssl crl2pkcs7 -certfile also 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_settings runs before apply_stack. An upgraded stack therefore has the two new keys before the non-optional configMapKeyRefs are applied, so the pod can't hit CreateContainerConfigError.

Comment thread deploy/k8s/setup.sh Outdated
crt="$(self_issued_crt "$json")"
mkdir -p "$(dirname "$SUP_CA")"
if [[ -n "$crt" ]]; then
printf '%s' "$crt" >"$SUP_CA"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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; }.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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".

Comment thread deploy/k8s/tests/setup.test.sh Outdated
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; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread deploy/k8s/setup.sh Outdated
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread deploy/k8s/setup.sh Outdated
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread deploy/k8s/setup.sh
# 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}$ ]]; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_ca writes printf '%s\n', and write_trust_file newline-terminates each PEM, so moca-ca.crt is well-formed whatever its input ends with.
  • Test counted lines: fixed. pem_count counts parsed certificates, there is a new guard against text after END CERTIFICATE-----, and the second-checkout check is a byte-for-byte cmp.
  • Unreadable tls.crt: now a WARNING naming the Secret, with a test. A warning rather than a die is reasonable here. log writes 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_ttl rejects 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)

Comment thread deploy/k8s/setup.sh
[[ "$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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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".

@pdettori
pdettori merged commit 9ce3101 into rossoctl:main Oct 8, 2026
14 checks passed
@pdettori
pdettori deleted the fix/432-ocp-trust-and-ttls branch October 8, 2026 16:48
pdettori added a commit to pdettori/moca that referenced this pull request Oct 9, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deploy/k8s setup.sh --target ocp: combined trust file, trust line on every run, settable token TTLs

2 participants