Skip to content

Commit 71209e6

Browse files
feat(rpm): replace init-pki.sh with openshell-gateway generate-certs (#1426)
* 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. * docs(certgen): remove stale init-pki.sh references in comments --------- Co-authored-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 0cbd2d6 commit 71209e6

7 files changed

Lines changed: 26 additions & 219 deletions

File tree

‎crates/openshell-bootstrap/src/pki.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ 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",
@@ -26,6 +29,7 @@ const DEFAULT_SERVER_SANS: &[&str] = &[
2629
"openshell.localhost",
2730
"*.openshell.localhost",
2831
"host.docker.internal",
32+
"host.containers.internal",
2933
"127.0.0.1",
3034
];
3135

‎crates/openshell-server/src/certgen.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//! in the supplied namespace. Used by the Helm pre-install hook. Requires
1010
//! `--namespace`, `--server-secret-name`, `--client-secret-name`.
1111
//! - **Local mode** (`--output-dir <DIR>`): write PEMs to a filesystem layout
12-
//! matching `deploy/rpm/init-pki.sh`. Used by the RPM systemd unit's
13-
//! `ExecStartPre`. Also copies client materials to
12+
//! used by the RPM systemd unit's `ExecStartPre`. Also copies client
13+
//! materials to
1414
//! `$XDG_CONFIG_HOME/openshell/gateways/openshell/mtls/` so the local CLI
1515
//! picks them up automatically.
1616
//!
@@ -216,7 +216,7 @@ enum LocalAction {
216216
Create,
217217
}
218218

219-
/// Layout under `<dir>` matches `deploy/rpm/init-pki.sh`:
219+
/// Layout under `<dir>`:
220220
///
221221
/// ```text
222222
/// <dir>/ca.crt

‎deploy/man/openshell-gateway.8.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ View logs:
114114
journalctl --user -u openshell-gateway
115115
journalctl --user -u openshell-gateway -f
116116

117-
The unit runs two **ExecStartPre** scripts on first start:
117+
The unit runs two **ExecStartPre** steps on first start:
118118

119-
1. **init-pki.sh** generates a self-signed PKI bundle for mTLS.
119+
1. **openshell-gateway generate-certs --output-dir** generates a
120+
self-signed PKI bundle for mTLS.
120121
2. **init-gateway-env.sh** generates the environment configuration
121122
file.
122123

123-
Both scripts are idempotent and skip generation if their output files
124+
Both steps are idempotent and skip generation if their output files
124125
already exist.
125126

126127
To persist the service across logouts:
@@ -147,9 +148,6 @@ This creates a drop-in override that persists across package upgrades.
147148
*/usr/lib/systemd/user/openshell-gateway.service*
148149
: Systemd user unit file.
149150

150-
*/usr/libexec/openshell/init-pki.sh*
151-
: PKI bootstrap script.
152-
153151
*/usr/libexec/openshell/init-gateway-env.sh*
154152
: Gateway environment file generator.
155153

‎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
|------|---------|----------|
@@ -247,7 +249,7 @@ For air-gapped environments:
247249
| Gateway binary | `/usr/bin/openshell-gateway` |
248250
| CLI binary | `/usr/bin/openshell` |
249251
| Systemd user unit | `/usr/lib/systemd/user/openshell-gateway.service` |
250-
| PKI bootstrap script | `/usr/libexec/openshell/init-pki.sh` |
252+
| PKI bootstrap | `openshell-gateway generate-certs` (run from `ExecStartPre`) |
251253
| Env/config generator script | `/usr/libexec/openshell/init-gateway-env.sh` |
252254
| TLS certificates | `~/.local/state/openshell/tls/` |
253255
| 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
@@ -111,9 +111,10 @@ OPENSHELL_GATEWAY_CONFIG=${CONFIG_FILE}
111111
# ${CONFIG_FILE}
112112
113113
# ---- TLS (mTLS enabled by default) ----
114-
# PKI is auto-generated by init-pki.sh on first start. Client certs are
115-
# placed in ~/.config/openshell/gateways/openshell/mtls/ so the CLI
116-
# discovers them automatically.
114+
# PKI is auto-generated by 'openshell-gateway generate-certs' from the
115+
# unit's ExecStartPre on first start. Client certs are placed in
116+
# ~/.config/openshell/gateways/openshell/mtls/ so the CLI discovers them
117+
# automatically.
117118
#
118119
# To use externally-managed certs, uncomment and edit the paths below.
119120
# 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 (commented config reference) on first
157158
# 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)