Skip to content

Commit f25afae

Browse files
committed
fix(packaging): use gateway TOML config in packages
1 parent 910d3f0 commit f25afae

10 files changed

Lines changed: 146 additions & 109 deletions

File tree

deploy/deb/init-gateway-config.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,29 @@ fi
1515

1616
mkdir -p "$(dirname "$CONFIG_FILE")" "$VM_STATE_DIR"
1717

18+
toml_string() {
19+
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
20+
}
21+
22+
bind_address="${OPENSHELL_BIND_ADDRESS:-127.0.0.1}"
1823
port="${OPENSHELL_SERVER_PORT:-17670}"
24+
case "$bind_address" in
25+
*:*) listen_address="[${bind_address}]:${port}" ;;
26+
*) listen_address="${bind_address}:${port}" ;;
27+
esac
28+
1929
scheme="https"
20-
if [ "${OPENSHELL_DISABLE_TLS:-false}" = "true" ]; then
21-
scheme="http"
22-
fi
30+
disable_tls="false"
31+
case "${OPENSHELL_DISABLE_TLS:-false}" in
32+
1 | true | TRUE | yes | YES | on | ON)
33+
disable_tls="true"
34+
scheme="http"
35+
;;
36+
esac
37+
38+
tls_cert="${OPENSHELL_TLS_CERT:-${PKI_DIR}/server/tls.crt}"
39+
tls_key="${OPENSHELL_TLS_KEY:-${PKI_DIR}/server/tls.key}"
40+
tls_client_ca="${OPENSHELL_TLS_CLIENT_CA:-${PKI_DIR}/ca.crt}"
2341

2442
tmp="${CONFIG_FILE}.tmp"
2543
{
@@ -28,23 +46,30 @@ tmp="${CONFIG_FILE}.tmp"
2846
version = 1
2947
3048
[openshell.gateway]
49+
bind_address = "$(toml_string "$listen_address")"
50+
disable_tls = ${disable_tls}
3151
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
3252
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
3353
EOF
3454

3555
if [ "$scheme" = "https" ]; then
3656
cat <<EOF
37-
guest_tls_ca = "${PKI_DIR}/ca.crt"
38-
guest_tls_cert = "${PKI_DIR}/client/tls.crt"
39-
guest_tls_key = "${PKI_DIR}/client/tls.key"
57+
guest_tls_ca = "$(toml_string "${PKI_DIR}/ca.crt")"
58+
guest_tls_cert = "$(toml_string "${PKI_DIR}/client/tls.crt")"
59+
guest_tls_key = "$(toml_string "${PKI_DIR}/client/tls.key")"
4060
EOF
4161
fi
4262

4363
cat <<EOF
4464
65+
[openshell.gateway.tls]
66+
cert_path = "$(toml_string "$tls_cert")"
67+
key_path = "$(toml_string "$tls_key")"
68+
client_ca_path = "$(toml_string "$tls_client_ca")"
69+
4570
[openshell.drivers.vm]
46-
state_dir = "${VM_STATE_DIR}"
47-
driver_dir = "${DRIVER_DIR}"
71+
state_dir = "$(toml_string "$VM_STATE_DIR")"
72+
driver_dir = "$(toml_string "$DRIVER_DIR")"
4873
grpc_endpoint = "${scheme}://127.0.0.1:${port}"
4974
5075
[openshell.drivers.docker]

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=/bin/sh -c 'exec /usr/libexec/openshell/init-gateway-config.sh "$${OPENSHELL_GATEWAY_CONFIG:-%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

deploy/man/openshell-gateway.env.5.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ date: 2025
88

99
# NAME
1010

11-
openshell-gateway.env - OpenShell gateway environment configuration
11+
openshell-gateway.env - legacy OpenShell gateway environment overrides
1212

1313
# DESCRIPTION
1414

15-
The **openshell-gateway.env** file contains environment variables that
16-
configure the OpenShell gateway server when running as a systemd user
17-
service. It is generated automatically on first start by
18-
**init-gateway-env.sh** and is not overwritten on subsequent starts or
19-
package upgrades.
15+
The **openshell-gateway.env** file contains optional environment
16+
overrides for the OpenShell gateway server when running as a systemd
17+
user service. Packaged defaults live in the gateway TOML file; this
18+
environment file is kept for compatibility and for settings that must
19+
remain outside TOML, such as **OPENSHELL_DB_URL**.
2020

2121
The file uses the standard systemd **EnvironmentFile** format: one
2222
**KEY=VALUE** pair per line. Lines beginning with **#** are comments.
@@ -33,62 +33,64 @@ The systemd user unit reads it via:
3333
EnvironmentFile=-~/.config/openshell/gateway.env
3434

3535
The **-** prefix means the service starts normally if the file does not
36-
exist (the unit has built-in defaults for all required settings).
36+
exist.
3737

3838
# VARIABLES
3939

4040
## Gateway
4141

42-
**OPENSHELL_BIND_ADDRESS** (default: 0.0.0.0)
43-
: IP address to bind all listeners to. The RPM default of **0.0.0.0**
44-
exposes the gateway on all network interfaces; mTLS must remain
45-
enabled to prevent unauthenticated access. Set to **127.0.0.1** for
46-
local-only access.
42+
**OPENSHELL_BIND_ADDRESS**
43+
: IP address to bind all listeners to. Overrides
44+
`bind_address` in the TOML file.
4745

48-
**OPENSHELL_SERVER_PORT** (default: 8080)
49-
: Port for the multiplexed gRPC/HTTP API.
46+
**OPENSHELL_SERVER_PORT**
47+
: Port for the multiplexed gRPC/HTTP API. Overrides the port in the
48+
TOML `bind_address`.
5049

51-
**OPENSHELL_HEALTH_PORT** (default: 0)
50+
**OPENSHELL_HEALTH_PORT**
5251
: Port for unauthenticated health endpoints (/healthz, /readyz).
5352
Set to a non-zero value to enable a dedicated health listener.
5453

55-
**OPENSHELL_METRICS_PORT** (default: 0)
54+
**OPENSHELL_METRICS_PORT**
5655
: Port for Prometheus metrics endpoint (/metrics). Set to a
5756
non-zero value to enable a dedicated metrics listener.
5857

59-
**OPENSHELL_LOG_LEVEL** (default: info)
58+
**OPENSHELL_LOG_LEVEL**
6059
: Log verbosity: **trace**, **debug**, **info**, **warn**, **error**.
6160

62-
**OPENSHELL_DRIVERS** (default: podman)
61+
**OPENSHELL_DRIVERS**
6362
: Compute driver for sandbox management. Options: **podman**,
64-
**docker**, **kubernetes**. The RPM unit defaults to **podman**.
63+
**docker**, **kubernetes**, **vm**. Overrides `compute_drivers` in
64+
the TOML file.
6565

66-
**OPENSHELL_DB_URL** (default: sqlite://$XDG_STATE_HOME/openshell/gateway.db)
67-
: SQLite database URL for gateway state persistence.
66+
**OPENSHELL_DB_URL**
67+
: SQLite database URL for gateway state persistence. The gateway
68+
rejects `database_url` in TOML, so packages pass this value through
69+
**--db-url** when it is set.
6870

6971
## TLS
7072

71-
**OPENSHELL_TLS_CERT** (default: auto-generated path)
73+
**OPENSHELL_TLS_CERT**
7274
: Path to server TLS certificate.
7375

74-
**OPENSHELL_TLS_KEY** (default: auto-generated path)
76+
**OPENSHELL_TLS_KEY**
7577
: Path to server TLS private key.
7678

77-
**OPENSHELL_TLS_CLIENT_CA** (default: auto-generated path)
79+
**OPENSHELL_TLS_CLIENT_CA**
7880
: Path to CA certificate for client certificate verification. When
7981
set without **OPENSHELL_OIDC_ISSUER**, mTLS is required. When both
8082
are set, callers may authenticate via Bearer token or client
8183
certificate.
8284

83-
**OPENSHELL_DISABLE_TLS** (default: unset)
85+
**OPENSHELL_DISABLE_TLS**
8486
: Set to **true** to disable TLS entirely and listen on plaintext
85-
HTTP. Not recommended for production. When the bind address is
86-
**0.0.0.0** (the RPM default), disabling TLS exposes the API to the
87-
entire network without authentication. Restrict
87+
HTTP. Not recommended for production. When the bind address is a
88+
public interface, disabling TLS exposes the API to the network
89+
without authentication. Restrict
8890
**OPENSHELL_BIND_ADDRESS** to **127.0.0.1** or place the gateway
8991
behind a TLS-terminating reverse proxy.
9092

91-
**OPENSHELL_SERVER_SAN** (default: unset)
93+
**OPENSHELL_SERVER_SAN**
9294
: Comma-separated SANs configured on the gateway server certificate.
9395
Wildcard DNS SANs also enable sandbox service URLs under that
9496
domain.

deploy/snap/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,20 @@ override is required. The OpenShell snap still requires the Docker snap because
140140
it relies on the `docker:docker-daemon` slot; it does not work with Docker
141141
installed from a Debian package or Docker's upstream packages.
142142

143-
The service runs the gateway with the Docker driver enabled:
143+
The service runs the gateway with an explicit config file and database URL:
144144

145145
```shell
146146
openshell.gateway \
147-
--drivers docker \
148-
--disable-tls \
149-
--port 17670 \
150-
--db-url "sqlite:$SNAP_COMMON/gateway.db?mode=rwc" \
151-
--config "$SNAP_COMMON/gateway.toml"
147+
--config "$SNAP_COMMON/gateway.toml" \
148+
--db-url "sqlite:$SNAP_COMMON/gateway.db?mode=rwc"
152149
```
153150

154151
This stores the gateway SQLite database at
155152
`/var/snap/openshell/common/gateway.db`. The generated TOML stores Docker
156-
driver settings such as the supervisor binary path, network name, sandbox
157-
namespace, sandbox image, pull policy, and callback endpoint.
153+
gateway settings such as the bind address, plaintext TLS mode, and selected
154+
compute driver, plus Docker driver settings such as the supervisor binary path,
155+
network name, sandbox namespace, sandbox image, pull policy, and callback
156+
endpoint.
158157

159158
## Connect with the OpenShell CLI
160159

deploy/snap/bin/openshell-gateway-wrapper

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
set -eu
66

77
CONFIG_FILE="${OPENSHELL_GATEWAY_CONFIG:-${SNAP_COMMON}/gateway.toml}"
8+
DB_URL="${OPENSHELL_DB_URL:-sqlite:${SNAP_COMMON}/gateway.db?mode=rwc}"
89

910
if [ ! -f "$CONFIG_FILE" ]; then
1011
mkdir -p "$(dirname "$CONFIG_FILE")"
1112
cat > "$CONFIG_FILE" << EOF
1213
[openshell]
1314
version = 1
1415
15-
[openshell.drivers.docker]
16+
[openshell.gateway]
17+
bind_address = "127.0.0.1:17670"
18+
disable_tls = true
19+
compute_drivers = ["docker"]
1620
default_image = "ghcr.io/nvidia/openshell-community/sandboxes/base:latest"
21+
22+
[openshell.drivers.docker]
1723
image_pull_policy = "IfNotPresent"
1824
sandbox_namespace = "docker-snap"
1925
grpc_endpoint = "http://host.openshell.internal:17670"
@@ -24,4 +30,4 @@ EOF
2430
fi
2531

2632
export OPENSHELL_GATEWAY_CONFIG="$CONFIG_FILE"
27-
exec "${SNAP}/bin/openshell-gateway" "$@"
33+
exec "${SNAP}/bin/openshell-gateway" --config "$CONFIG_FILE" --db-url "$DB_URL" "$@"

deploy/snap/meta/snap.yaml.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ apps:
3535
daemon: simple
3636
refresh-mode: endure
3737
environment:
38-
OPENSHELL_BIND_ADDRESS: 127.0.0.1
39-
OPENSHELL_SERVER_PORT: 17670
40-
OPENSHELL_DB_URL: "sqlite:$SNAP_COMMON/gateway.db?mode=rwc"
41-
OPENSHELL_DISABLE_TLS: true
42-
OPENSHELL_DRIVERS: docker
43-
OPENSHELL_GATEWAY_CONFIG: "$SNAP_COMMON/gateway.toml"
4438
XDG_DATA_HOME: "$SNAP_COMMON"
4539
# Used for creating and locating certain sockets.
4640
XDG_RUNTIME_DIR: "$SNAP_COMMON"

0 commit comments

Comments
 (0)