Skip to content

Commit 18acd88

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

21 files changed

Lines changed: 614 additions & 497 deletions

crates/openshell-driver-podman/NETWORKING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ Supervisor proxy in container netns
357357

358358
The Podman driver auto-detects the callback endpoint scheme based on whether
359359
TLS client certificates are configured. When the RPM's auto-generated PKI is in
360-
place, the endpoint is `https://host.containers.internal:8080` and the
360+
place, the endpoint is `https://host.containers.internal:17670` and the
361361
supervisor connects with mTLS. Without TLS configuration, it falls back to
362-
`http://host.containers.internal:8080`.
362+
`http://host.containers.internal:<gateway-port>`.
363363

364364
```text
365365
Supervisor in container netns
@@ -382,9 +382,8 @@ Gateway
382382
9. Same gRPC channel reused for RelayStream calls
383383
```
384384

385-
The gateway binds to `0.0.0.0` by default in the RPM packaging. mTLS prevents
386-
unauthenticated access even though the gateway is reachable from the network.
387-
Client certificates are auto-generated by `init-pki.sh` on first start and
385+
The gateway binds to `127.0.0.1:17670` by default in the RPM packaging. Client
386+
certificates are auto-generated by `init-pki.sh` on first start and
388387
bind-mounted into sandbox containers by the Podman driver.
389388

390389
## Differences from the Kubernetes Driver
@@ -412,7 +411,8 @@ published ports, or the supervisor relay.
412411

413412
| Port | Component | Purpose |
414413
|---|---|---|
415-
| `8080` | Gateway | gRPC and HTTP multiplexed default server port. |
414+
| `17670` | RPM gateway | Package-managed gRPC and HTTP multiplexed server port. |
415+
| `8080` | Gateway | Built-in gRPC and HTTP multiplexed default server port. |
416416
| `2222` | Sandbox | Container port mapping default for the SSH compatibility port. |
417417
| `3128` | Sandbox proxy | HTTP CONNECT proxy inside the sandbox network model. |
418418
| `0` | Host | Ephemeral host port requested for the container SSH compatibility port. |
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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|rpm|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+
write_rpm_config() {
127+
pki_dir="${1:-}"
128+
supervisor_image="${2:-}"
129+
if [ -z "$pki_dir" ] || [ -z "$supervisor_image" ]; then
130+
usage
131+
fi
132+
133+
mkdir -p "$(dirname "$CONFIG_FILE")"
134+
135+
tmp="${CONFIG_FILE}.tmp"
136+
{
137+
cat <<EOF
138+
[openshell]
139+
version = 1
140+
141+
[openshell.gateway]
142+
bind_address = "127.0.0.1:17670"
143+
# Leave unset to auto-detect the compute driver.
144+
# compute_drivers = ["podman"]
145+
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
146+
supervisor_image = $(toml_string "$supervisor_image")
147+
guest_tls_ca = $(toml_string "${pki_dir}/ca.crt")
148+
guest_tls_cert = $(toml_string "${pki_dir}/client/tls.crt")
149+
guest_tls_key = $(toml_string "${pki_dir}/client/tls.key")
150+
151+
[openshell.gateway.tls]
152+
cert_path = $(toml_string "${pki_dir}/server/tls.crt")
153+
key_path = $(toml_string "${pki_dir}/server/tls.key")
154+
client_ca_path = $(toml_string "${pki_dir}/ca.crt")
155+
156+
[openshell.drivers.podman]
157+
image_pull_policy = "missing"
158+
network_name = "openshell"
159+
stop_timeout_secs = 10
160+
EOF
161+
} > "$tmp"
162+
163+
chmod 600 "$tmp"
164+
mv "$tmp" "$CONFIG_FILE"
165+
}
166+
167+
case "$profile" in
168+
deb)
169+
write_desktop_config "${3:-}" "${4:-}" "${5:-}" "" ""
170+
;;
171+
homebrew)
172+
write_desktop_config "${3:-}" "${4:-}" "${5:-}" "${6:-}" "${7:-}"
173+
;;
174+
rpm)
175+
write_rpm_config "${3:-}" "${4:-}"
176+
;;
177+
snap)
178+
write_snap_config "${3:-}"
179+
;;
180+
*)
181+
usage
182+
;;
183+
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ 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
17-
EnvironmentFile=-%h/.config/openshell/gateway.env
9+
# Gateway TOML lives under the user config root. %E resolves to
10+
# $XDG_CONFIG_HOME for user services.
11+
EnvironmentFile=-%E/openshell/gateway.env
1812
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
13+
ExecStartPre=/usr/libexec/openshell/init-gateway-config.sh deb %E/openshell/gateway.toml %S/openshell/tls /usr/libexec/openshell %S/openshell/vm-driver
14+
ExecStart=/bin/sh -c 'exec /usr/bin/openshell-gateway --config "$${OPENSHELL_GATEWAY_CONFIG:-%E/openshell/gateway.toml}" --db-url "$${OPENSHELL_DB_URL:-sqlite:%S/openshell/gateway/openshell.db}"'
2115
Restart=on-failure
2216
RestartSec=5s
2317
PrivateTmp=true

0 commit comments

Comments
 (0)