Skip to content

Commit 3d47dc7

Browse files
committed
fix(packaging): use gateway TOML config in packages
1 parent f819f7d commit 3d47dc7

14 files changed

Lines changed: 375 additions & 238 deletions
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/sh
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -eu
6+
7+
usage() {
8+
echo "Usage: init-gateway-config.sh <deb|homebrew|snap> <config-file> [package args...]" >&2
9+
exit 2
10+
}
11+
12+
profile="${1:-}"
13+
CONFIG_FILE="${2:-}"
14+
if [ -z "$profile" ] || [ -z "$CONFIG_FILE" ]; then
15+
usage
16+
fi
17+
18+
if [ -f "$CONFIG_FILE" ]; then
19+
exit 0
20+
fi
21+
22+
toml_escape() {
23+
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
24+
}
25+
26+
toml_string() {
27+
printf '"%s"' "$(toml_escape "$1")"
28+
}
29+
30+
emit_string_field() {
31+
key="$1"
32+
value="$2"
33+
if [ -n "$value" ]; then
34+
printf '%s = %s\n' "$key" "$(toml_string "$value")"
35+
fi
36+
}
37+
38+
write_desktop_config() {
39+
pki_dir="${1:-}"
40+
driver_dir="${2:-}"
41+
vm_state_dir="${3:-}"
42+
docker_supervisor_image="${4:-}"
43+
docker_tls_dir="${5:-}"
44+
if [ -z "$pki_dir" ] || [ -z "$driver_dir" ] || [ -z "$vm_state_dir" ]; then
45+
usage
46+
fi
47+
48+
mkdir -p "$(dirname "$CONFIG_FILE")" "$vm_state_dir"
49+
50+
tmp="${CONFIG_FILE}.tmp"
51+
{
52+
cat <<EOF
53+
[openshell]
54+
version = 1
55+
56+
[openshell.gateway]
57+
bind_address = "127.0.0.1:17670"
58+
# Leave unset to auto-detect the compute driver.
59+
# compute_drivers = ["vm"]
60+
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
61+
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
62+
guest_tls_ca = $(toml_string "${pki_dir}/ca.crt")
63+
guest_tls_cert = $(toml_string "${pki_dir}/client/tls.crt")
64+
guest_tls_key = $(toml_string "${pki_dir}/client/tls.key")
65+
66+
[openshell.gateway.tls]
67+
cert_path = $(toml_string "${pki_dir}/server/tls.crt")
68+
key_path = $(toml_string "${pki_dir}/server/tls.key")
69+
client_ca_path = $(toml_string "${pki_dir}/ca.crt")
70+
71+
[openshell.drivers.vm]
72+
state_dir = $(toml_string "$vm_state_dir")
73+
driver_dir = $(toml_string "$driver_dir")
74+
grpc_endpoint = "https://127.0.0.1:17670"
75+
76+
[openshell.drivers.docker]
77+
grpc_endpoint = "https://127.0.0.1:17670"
78+
EOF
79+
80+
emit_string_field supervisor_image "$docker_supervisor_image"
81+
if [ -n "$docker_tls_dir" ]; then
82+
emit_string_field guest_tls_ca "${docker_tls_dir}/ca.crt"
83+
emit_string_field guest_tls_cert "${docker_tls_dir}/client/tls.crt"
84+
emit_string_field guest_tls_key "${docker_tls_dir}/client/tls.key"
85+
fi
86+
} > "$tmp"
87+
88+
chmod 600 "$tmp"
89+
mv "$tmp" "$CONFIG_FILE"
90+
}
91+
92+
write_snap_config() {
93+
supervisor_bin="${1:-}"
94+
if [ -z "$supervisor_bin" ]; then
95+
usage
96+
fi
97+
98+
mkdir -p "$(dirname "$CONFIG_FILE")"
99+
100+
tmp="${CONFIG_FILE}.tmp"
101+
{
102+
cat <<EOF
103+
[openshell]
104+
version = 1
105+
106+
[openshell.gateway]
107+
bind_address = "127.0.0.1:17670"
108+
disable_tls = true
109+
# Leave unset to auto-detect the compute driver.
110+
# compute_drivers = ["docker"]
111+
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
112+
113+
[openshell.drivers.docker]
114+
image_pull_policy = "IfNotPresent"
115+
sandbox_namespace = "docker-snap"
116+
grpc_endpoint = "http://host.openshell.internal:17670"
117+
supervisor_bin = $(toml_string "$supervisor_bin")
118+
network_name = "openshell-snap"
119+
EOF
120+
} > "$tmp"
121+
122+
chmod 600 "$tmp"
123+
mv "$tmp" "$CONFIG_FILE"
124+
}
125+
126+
case "$profile" in
127+
deb)
128+
write_desktop_config "${3:-}" "${4:-}" "${5:-}" "" ""
129+
;;
130+
homebrew)
131+
write_desktop_config "${3:-}" "${4:-}" "${5:-}" "${6:-}" "${7:-}"
132+
;;
133+
snap)
134+
write_snap_config "${3:-}"
135+
;;
136+
*)
137+
usage
138+
;;
139+
esac

deploy/deb/init-gateway-config.sh

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

deploy/deb/openshell-gateway.service

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ After=default.target
66
[Service]
77
Type=simple
88
StateDirectory=openshell/gateway
9-
# %S resolves to $XDG_STATE_HOME for user services.
10-
Environment=OPENSHELL_BIND_ADDRESS=127.0.0.1
11-
Environment=OPENSHELL_SERVER_PORT=17670
12-
Environment=OPENSHELL_TLS_CERT=%S/openshell/tls/server/tls.crt
13-
Environment=OPENSHELL_TLS_KEY=%S/openshell/tls/server/tls.key
14-
Environment=OPENSHELL_TLS_CLIENT_CA=%S/openshell/tls/ca.crt
15-
Environment=OPENSHELL_DB_URL=sqlite:%S/openshell/gateway/openshell.db
16-
Environment=OPENSHELL_GATEWAY_CONFIG=%S/openshell/gateway/config.toml
9+
# Legacy OPENSHELL_* overrides are still honored, but packaged defaults live
10+
# in %S/openshell/gateway/config.toml. %S resolves to $XDG_STATE_HOME for user
11+
# services.
1712
EnvironmentFile=-%h/.config/openshell/gateway.env
1813
ExecStartPre=/usr/bin/openshell-gateway generate-certs --output-dir %S/openshell/tls --server-san host.openshell.internal
19-
ExecStartPre=/usr/libexec/openshell/init-gateway-config.sh %S/openshell/gateway/config.toml %S/openshell/tls /usr/libexec/openshell %S/openshell/vm-driver
20-
ExecStart=/usr/bin/openshell-gateway
14+
ExecStartPre=/usr/libexec/openshell/init-gateway-config.sh deb %S/openshell/gateway/config.toml %S/openshell/tls /usr/libexec/openshell %S/openshell/vm-driver
15+
ExecStart=/bin/sh -c 'exec /usr/bin/openshell-gateway --config "$${OPENSHELL_GATEWAY_CONFIG:-%S/openshell/gateway/config.toml}" --db-url "$${OPENSHELL_DB_URL:-sqlite:%S/openshell/gateway/openshell.db}"'
2116
Restart=on-failure
2217
RestartSec=5s
2318
PrivateTmp=true

deploy/man/openshell-gateway.8.md

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ network and filesystem policies to sandboxes, routes inference
2222
requests, and provides the SSH tunnel endpoint for CLI-to-sandbox
2323
connections.
2424

25-
When installed via RPM, the gateway runs as a systemd user service
26-
with the Podman compute driver. Sandboxes are rootless Podman
27-
containers on the host.
25+
When installed via a Linux package, the gateway runs as a systemd user
26+
service. The packaged service creates a gateway TOML file on first
27+
start and launches the gateway with **--config**.
2828

29-
The gateway exposes a single port (default 8080) with multiplexed
30-
gRPC and HTTP, secured by mutual TLS (mTLS) by default.
29+
The gateway exposes a single port with multiplexed gRPC and HTTP,
30+
secured by mutual TLS (mTLS) by default unless the TOML config disables
31+
TLS.
3132

3233
# OPTIONS
3334

@@ -100,7 +101,7 @@ configured in the TOML file passed with **--config**.
100101

101102
# SYSTEMD INTEGRATION
102103

103-
The RPM installs a systemd user unit at
104+
The package installs a systemd user unit at
104105
*/usr/lib/systemd/user/openshell-gateway.service*. Manage the gateway
105106
with standard systemd commands:
106107

@@ -114,13 +115,13 @@ View logs:
114115
journalctl --user -u openshell-gateway
115116
journalctl --user -u openshell-gateway -f
116117

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

119-
1. **init-pki.sh** generates a self-signed PKI bundle for mTLS.
120-
2. **init-gateway-env.sh** generates the environment configuration
121-
file.
120+
1. **openshell-gateway generate-certs** generates a self-signed PKI
121+
bundle for mTLS.
122+
2. **init-gateway-config.sh** generates the gateway TOML 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:
@@ -129,11 +130,20 @@ To persist the service across logouts:
129130

130131
# CONFIGURATION
131132

132-
The systemd user unit reads configuration from
133-
*~/.config/openshell/gateway.env*. See **openshell-gateway.env**(5)
134-
for the full variable reference.
133+
The systemd user unit launches the gateway with:
135134

136-
To override individual settings without modifying gateway.env:
135+
openshell-gateway --config ~/.local/state/openshell/gateway/config.toml \
136+
--db-url sqlite:~/.local/state/openshell/gateway/openshell.db
137+
138+
Gateway listener, TLS, and compute driver settings live in
139+
*~/.local/state/openshell/gateway/config.toml*. The database URL stays
140+
on **--db-url** because the gateway rejects `database_url` in TOML.
141+
142+
For compatibility, the unit also reads optional environment overrides
143+
from *~/.config/openshell/gateway.env*. Gateway environment variables
144+
in that file continue to override TOML values.
145+
146+
To override individual settings without modifying the generated TOML:
137147

138148
systemctl --user edit openshell-gateway
139149

@@ -147,19 +157,19 @@ This creates a drop-in override that persists across package upgrades.
147157
*/usr/lib/systemd/user/openshell-gateway.service*
148158
: Systemd user unit file.
149159

150-
*/usr/libexec/openshell/init-pki.sh*
151-
: PKI bootstrap script.
152-
153-
*/usr/libexec/openshell/init-gateway-env.sh*
154-
: Gateway environment file generator.
160+
*/usr/libexec/openshell/init-gateway-config.sh*
161+
: Gateway TOML file generator.
155162

156163
*~/.config/openshell/gateway.env*
157-
: Gateway environment configuration (generated on first start).
164+
: Optional legacy environment overrides.
165+
166+
*~/.local/state/openshell/gateway/config.toml*
167+
: Gateway TOML configuration (generated on first start).
158168

159169
*~/.local/state/openshell/tls/*
160170
: Auto-generated TLS certificates.
161171

162-
*~/.local/state/openshell/gateway.db*
172+
*~/.local/state/openshell/gateway/openshell.db*
163173
: SQLite database for gateway state.
164174

165175
*~/.config/openshell/gateways/openshell/mtls/*
@@ -176,11 +186,10 @@ Check gateway health from the CLI:
176186
openshell gateway add --local https://127.0.0.1:8080
177187
openshell status
178188

179-
Override the API port via a systemd drop-in:
189+
Override the API port in the generated TOML:
180190

181-
systemctl --user edit openshell-gateway
182-
# Add: [Service]
183-
# Add: Environment=OPENSHELL_SERVER_PORT=9090
191+
$EDITOR ~/.local/state/openshell/gateway/config.toml
192+
systemctl --user restart openshell-gateway
184193

185194
# SEE ALSO
186195

0 commit comments

Comments
 (0)