Skip to content

Commit f7e72b0

Browse files
committed
feat(server): add --output-dir local mode to generate-certs
Presence of `--output-dir <DIR>` switches the subcommand from Kubernetes Secret writes to filesystem writes, making the kube flags optional. Local layout matches `deploy/rpm/init-pki.sh` exactly: <dir>/{ca.crt, ca.key, server/tls.{crt,key}, client/tls.{crt,key}} Stages writes to a sibling `<dir>.certgen.tmp` and renames into place for atomic per-file installation. Sets 0o700 on directories and 0o600 on key files. Reuses `openshell_bootstrap::mtls::store_pki_bundle` to populate the CLI auto-discovery directory at $XDG_CONFIG_HOME/openshell/gateways/ openshell/mtls/, mirroring init-pki.sh's local-CLI UX. Same idempotency contract as the Kubernetes path: all six files present → skip (and self-heal the CLI mTLS copy if missing); partial → fail with a recovery hint; nothing → generate and write. Sets up the seam for a follow-up PR that swaps init-pki.sh for the Rust command in the systemd unit. The shell script and unit are untouched here.
1 parent 31cc445 commit f7e72b0

3 files changed

Lines changed: 413 additions & 77 deletions

File tree

architecture/gateway.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,29 @@ tokens can expire or be revoked.
134134

135135
## PKI Bootstrap
136136

137-
On Kubernetes, the Helm chart runs a pre-install/pre-upgrade hook Job that
138-
invokes `openshell-gateway generate-certs` to create the gateway's server and
139-
client mTLS Secrets. The Job uses the gateway image itself — no separate
140-
cert-generation image — and reuses the same `rcgen`-based CA/leaf logic as the
141-
local `openshell` workflow.
137+
`openshell-gateway generate-certs` is the one place mTLS materials are
138+
created. Both deployment paths use it:
142139

143-
The hook is idempotent: both target Secrets present → skip; exactly one
144-
present → fail with a recovery hint; neither present → generate and create.
145-
This guards mTLS continuity across upgrades while still recovering cleanly if
146-
an operator deletes both Secrets and reinstalls.
140+
| Output mode | Selector | Layout |
141+
|---|---|---|
142+
| Kubernetes Secrets | (default) `--namespace`, `--server-secret-name`, `--client-secret-name` | Two `kubernetes.io/tls` Secrets with `tls.crt` / `tls.key` / `ca.crt`. |
143+
| Filesystem | `--output-dir <DIR>` | `<dir>/{ca.crt, ca.key, server/tls.{crt,key}, client/tls.{crt,key}}`. Also copies client materials to `$XDG_CONFIG_HOME/openshell/gateways/openshell/mtls/` for CLI auto-discovery. |
144+
145+
On Kubernetes, the Helm chart runs the command via a pre-install/pre-upgrade
146+
hook Job using the gateway image itself — no separate cert-generation image,
147+
no extra mirror burden in air-gapped environments. On the RPM gateway, the
148+
same command runs from the systemd unit's `ExecStartPre` to bootstrap PKI
149+
into the user's state directory on first start.
150+
151+
Both modes share the same idempotency contract: all targets present → skip;
152+
partial state → fail with a recovery hint; nothing present → generate and
153+
write. This guards mTLS continuity across restarts and upgrades while still
154+
recovering cleanly if an operator deletes everything and starts over.
147155

148156
Operators who manage PKI externally (cert-manager, an enterprise CA, or
149-
pre-created Secrets) disable the hook via `pkiInitJob.enabled=false`. The chart
150-
also ships a `certManager.*` path that produces equivalent Secrets through
151-
cert-manager `Issuer`/`Certificate` resources.
157+
pre-created Secrets) disable the Helm hook via `pkiInitJob.enabled=false`.
158+
The chart also ships a `certManager.*` path that produces equivalent Secrets
159+
through cert-manager `Issuer`/`Certificate` resources.
152160

153161
## Operational Constraints
154162

0 commit comments

Comments
 (0)