Skip to content

Commit 267fe24

Browse files
committed
feat(rpm): replace init-pki.sh with openshell-gateway generate-certs
Cuts the RPM gateway over to the unified Rust certgen path. The systemd user unit's first ExecStartPre now invokes: /usr/bin/openshell-gateway generate-certs --output-dir %S/openshell/tls producing the same six-PEM layout init-pki.sh built (ca.{crt,key}, server/tls.{crt,key}, client/tls.{crt,key}) and the same CLI mTLS copy under $XDG_CONFIG_HOME/openshell/gateways/openshell/mtls/. None of the OPENSHELL_TLS_* / OPENSHELL_PODMAN_TLS_* paths in the unit change. Adds host.containers.internal to the gateway's built-in SAN list so podman containers reaching their host validate cleanly with no per-deployment --server-san flag. Docker (host.docker.internal) and Kubernetes (cluster.local DNS) were already covered. Drops 197 lines of openssl shell, the install/file lines for the script itself, and updates the docs (man page, RPM CONFIGURATION.md, env-file generator comment) to point at the new entrypoint. The %S state dir, unit security hardening, and consumer paths are untouched.
1 parent a4efc0b commit 267fe24

6 files changed

Lines changed: 23 additions & 216 deletions

File tree

crates/openshell-bootstrap/src/pki.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ pub struct PkiBundle {
1717
pub client_key_pem: String,
1818
}
1919

20-
/// Default SANs always included on the server certificate.
20+
/// Default SANs always included on the server certificate. Covers the host
21+
/// aliases used by every supported runtime: Kubernetes service DNS,
22+
/// `host.docker.internal` for Docker Desktop and rootless Docker on Linux,
23+
/// and `host.containers.internal` for Podman containers reaching their host.
2124
const DEFAULT_SERVER_SANS: &[&str] = &[
2225
"openshell",
2326
"openshell.openshell.svc",
2427
"openshell.openshell.svc.cluster.local",
2528
"localhost",
2629
"host.docker.internal",
30+
"host.containers.internal",
2731
"127.0.0.1",
2832
];
2933

deploy/man/openshell-gateway.8.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ View logs:
134134
journalctl --user -u openshell-gateway
135135
journalctl --user -u openshell-gateway -f
136136

137-
The unit runs two **ExecStartPre** scripts on first start:
137+
The unit runs two **ExecStartPre** steps on first start:
138138

139-
1. **init-pki.sh** generates a self-signed PKI bundle for mTLS.
139+
1. **openshell-gateway generate-certs --output-dir** generates a
140+
self-signed PKI bundle for mTLS.
140141
2. **init-gateway-env.sh** generates the environment configuration
141142
file with an auto-generated SSH handshake secret.
142143

143-
Both scripts are idempotent and skip generation if their output files
144+
Both steps are idempotent and skip generation if their output files
144145
already exist.
145146

146147
To persist the service across logouts:
@@ -167,9 +168,6 @@ This creates a drop-in override that persists across package upgrades.
167168
*/usr/lib/systemd/user/openshell-gateway.service*
168169
: Systemd user unit file.
169170

170-
*/usr/libexec/openshell/init-pki.sh*
171-
: PKI bootstrap script.
172-
173171
*/usr/libexec/openshell/init-gateway-env.sh*
174172
: Gateway environment file generator.
175173

deploy/rpm/CONFIGURATION.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ though it listens on all interfaces (`0.0.0.0`).
1414

1515
### Auto-generated certificates
1616

17-
On first start, the `init-pki.sh` script generates certificates using
18-
OpenSSL:
17+
On first start, the gateway's `ExecStartPre` runs
18+
`openshell-gateway generate-certs --output-dir <state-dir>/openshell/tls`,
19+
which generates the certificates with `rcgen` (the same routine the CLI
20+
uses for local mTLS bundles):
1921

2022
| File | Purpose | Location |
2123
|------|---------|----------|
@@ -245,7 +247,7 @@ For air-gapped environments:
245247
| Gateway binary | `/usr/bin/openshell-gateway` |
246248
| CLI binary | `/usr/bin/openshell` |
247249
| Systemd user unit | `/usr/lib/systemd/user/openshell-gateway.service` |
248-
| PKI bootstrap script | `/usr/libexec/openshell/init-pki.sh` |
250+
| PKI bootstrap | `openshell-gateway generate-certs` (run from `ExecStartPre`) |
249251
| Env generator script | `/usr/libexec/openshell/init-gateway-env.sh` |
250252
| TLS certificates | `~/.local/state/openshell/tls/` |
251253
| CLI client certs | `~/.config/openshell/gateways/openshell/mtls/` |

deploy/rpm/init-gateway-env.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ OPENSHELL_SSH_HANDSHAKE_SECRET=${SECRET}
7777
#OPENSHELL_SANDBOX_IMAGE_PULL_POLICY=missing
7878
7979
# ---- TLS (mTLS enabled by default) ----
80-
# PKI is auto-generated by init-pki.sh on first start. Client certs are
81-
# placed in ~/.config/openshell/gateways/openshell/mtls/ so the CLI
82-
# discovers them automatically.
80+
# PKI is auto-generated by 'openshell-gateway generate-certs' from the
81+
# unit's ExecStartPre on first start. Client certs are placed in
82+
# ~/.config/openshell/gateways/openshell/mtls/ so the CLI discovers them
83+
# automatically.
8384
#
8485
# To use externally-managed certs, uncomment and edit the paths below.
8586
# To rotate certs, delete ~/.local/state/openshell/tls/ and restart.

deploy/rpm/init-pki.sh

Lines changed: 0 additions & 197 deletions
This file was deleted.

openshell.spec

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ Type=exec
149149
# CLI discovers them automatically.
150150
# See /usr/share/doc/openshell-gateway/ for details.
151151

152-
# Auto-generate PKI on first start if not present.
153-
# %%S expands to $XDG_STATE_HOME (~/.local/state) in user units.
154-
ExecStartPre=%{_libexecdir}/openshell/init-pki.sh %%S/openshell/tls
152+
# Auto-generate PKI on first start. Idempotent: skips when all six PEMs are
153+
# already in place. %%S expands to $XDG_STATE_HOME (~/.local/state) in user
154+
# units.
155+
ExecStartPre=/usr/bin/openshell-gateway generate-certs --output-dir %%S/openshell/tls
155156

156157
# Auto-generate gateway.env (SSH handshake secret + commented config
157158
# reference) on first start if not present.
@@ -186,9 +187,8 @@ RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
186187
WantedBy=default.target
187188
EOF
188189

189-
# --- PKI bootstrap script and gateway env generator ---
190+
# --- Gateway env generator ---
190191
install -d %{buildroot}%{_libexecdir}/%{name}
191-
install -pm 0755 deploy/rpm/init-pki.sh %{buildroot}%{_libexecdir}/%{name}/init-pki.sh
192192
install -pm 0755 deploy/rpm/init-gateway-env.sh %{buildroot}%{_libexecdir}/%{name}/init-gateway-env.sh
193193
# Patch commented image defaults to match the build type (dev or latest).
194194
# The source file uses :latest as a generic reference; the installed copy
@@ -275,7 +275,6 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} %{python3} -c "from importlib.metadata
275275
%doc %{_docdir}/%{name}-gateway/TROUBLESHOOTING.md
276276
%{_bindir}/%{name}-gateway
277277
%{_userunitdir}/%{name}-gateway.service
278-
%{_libexecdir}/%{name}/init-pki.sh
279278
%{_libexecdir}/%{name}/init-gateway-env.sh
280279
%{_mandir}/man8/openshell-gateway.8*
281280
%{_mandir}/man5/openshell-gateway.env.5*

0 commit comments

Comments
 (0)