Skip to content

Commit c262cf3

Browse files
PurpleCHOImsmschoi
andauthored
feat(launcher): bring up the OpenShell gateway on start (engine auto-select) (#1189)
* feat(launcher): add openshell compose profile to the catalog The standing OpenShell gateway (profile: openshell, #1187) joins the launcher's profile catalog so AllProfiles() sweeps it on down/stop and start can activate it. Wiring that brings it up lives in the next commits. * feat(launcher): bring up the OpenShell gateway on start (engine auto-select) `start` now stands up the standing OpenShell gateway (profile: openshell, #1187) alongside the stack, so the default `openshell` sandbox provider admits the engagement out of the box — previously the launcher only brought up `cli` and the resolver stayed unbound. internal/openshell: PrepareGateway(home, runtime) picks the compute engine from the detected container runtime (podman → rootless, else docker), renders the engine's embedded gateway TOML into DECEPTICON_HOME (the launcher owns it — SyncConfigFiles ships only compose+litellm, not containers/), creates the podman data dir, and exports the OPENSHELL_* env the compose service reads. cmd/start.go calls it before compose up, prints the boundary banner, and activates the openshell profile (CLI path and desktop path). Verified on sec-dev: go build / vet / test (openshell + compose) pass. * test(launcher): live OpenShell gateway integration test (guarded) OPENSHELL_LIVE=1 runs the real PrepareGateway path on a host with podman: renders the gateway TOML + exports OPENSHELL_*, brings up the openshell compose profile, and asserts the gateway is healthy (/readyz) with the podman compute driver connected. Skips in CI (needs podman + the gateway image). Verified on ra-trial: PASS — gateway healthy via host.containers.internal, podman driver connected, using the launcher-rendered config. * docs(changelog): link launcher OpenShell gateway PR #1189 * test(launcher): assert gateway JWT path OS-independently (fix Windows CI) TestPrepareGatewayPodman built the expected JWT path with filepath.Join, which uses backslashes on windows-latest; the rendered TOML uses forward slashes (the template is @DaTa@/tls/jwt/...). The gateway only runs on Linux, so the code is unaffected — assert with a literal forward-slash path. --------- Co-authored-by: mschoi <mschoi@elicer.com>
1 parent 52b6009 commit c262cf3

9 files changed

Lines changed: 507 additions & 3 deletions

File tree

‎CHAGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Keep proposed and unmerged changes out of released sections.
1515

1616
## [Unreleased]
1717

18+
- Added [launcher brings up the OpenShell gateway on start #1189](https://github.com/BitterSecurity/Decepticon/pull/1189), not released. `decepticon start` now stands up the standing OpenShell gateway (profile `openshell`, #1187) alongside the stack, so the default `openshell` sandbox provider admits the engagement out of the box — previously `start` only activated `cli` and the resolver stayed unbound. New `internal/openshell.PrepareGateway` picks the compute engine from the detected container runtime (podman → rootless, else docker), renders the engine's embedded gateway TOML into `DECEPTICON_HOME` (the launcher owns it — `SyncConfigFiles` ships only compose+litellm, not `containers/`), creates the podman data dir, and exports the `OPENSHELL_*` env the compose service reads; `start` prints a boundary banner and activates the `openshell` profile. Engine is auto-selected (no new prompt). Verified on ra-trial: a guarded live test (`OPENSHELL_LIVE=1`) runs the real `PrepareGateway` path → `compose --profile openshell up` → gateway healthy via `host.containers.internal` with the podman driver connected; `go build`/`vet`/`test` green on sec-dev. Follow-ups (separate): engagement draft/lock + asset inventory (postgres); full stack E2E.
19+
1820
- Proposed [OpenShell gateway in compose #1186](https://github.com/BitterSecurity/Decepticon/pull/1186), not released. Design-only, no code. Since #1144 OpenShell is the only network-boundary authority and the default sandbox provider (#1178), but `docker compose` / `make dogfood` never stands up a gateway, so an out-of-the-box install on the default provider cannot admit any engagement. The proposal adds a standing `openshell-gateway` compose service (docker driver) and wires its endpoint + mTLS into `langgraph`; policy stays per-engagement and is already auto-generated from scope → `plan/roe.json` by the existing resolver. Decepticon is driver-neutral (gRPC client only), so the choice is a gateway-config one. **Decided (revised after real-host verification):** the compute engine is **selectable** (`compute_driver = docker | podman`) and **Podman rootless is the recommended path**, with Docker kept supported. Rootless is the real boundary for threat (A) (a gateway holding a rootful `docker.sock` ≈ host root; rootless maps an escape to an unprivileged namespaced uid); the OpenShell policy governs the sandbox interior (threat B) and does not substitute for it. Verified E2E on ra-trial (2026-11-13, official `ghcr.io/nvidia/openshell/gateway:latest` 0.1.8): **rootless Docker** nesting + caps work (sibling sandbox created; `CAP_NET_RAW` present → `nmap -sS` works, `CAP_NET_ADMIN` dropped as on rootful; root inside so `apt`/`pip` fine), **but** the docker driver forces the supervisor to host-net `127.0.0.1:8080`, so the gateway must be `--network host` and `langgraph` (a bridge container) can only reach it if the rootless daemon runs with `--disable-host-loopback=false` — a custom per-user flag, so rootless Docker is advanced-only. **Podman rootless** needs no such flag: gateway `--userns=keep-id`, `netavark`, auto-detected loopback callback → sandbox `Completed` + `ConnectSupervisor` 200, and a bridge control-plane container reaches the gateway via `host.containers.internal` (HTTP 200). Hardening/isolation opt-ins stay documented: external compute driver (all-gRPC, socket confined to one process), `vm`/MicroVM or `--runtime krun`/`youki` for adversarial-code isolation. Implementation PR (dual-engine compose + gateway image pin + TLS/JWT lifecycle) follows on top. [Design](docs/design/2026-11-13-openshell-gateway-in-compose.md).
1921
- Added [OpenShell gateway in compose #1187](https://github.com/BitterSecurity/Decepticon/pull/1187), not released. Stands up a standing OpenShell gateway as a compose service (profile `openshell`) so the default `openshell` sandbox provider admits engagements out of the box — previously `docker compose` / `make dogfood` never brought up a gateway and the resolver stayed unbound. One service definition, two compute engines selected by env: **Docker** (default/supported; gateway holds the host Docker socket — rootful is the official default, threat A documented) and **Podman** (recommended; user Podman socket + `--userns=keep-id`, the rootless threat-A boundary, no custom daemon flags). The gateway runs `network_mode: host` (the compute driver pins the sandbox supervisor to host-net and dials `127.0.0.1:8080`); `langgraph` reaches it via `host.docker.internal` / `host.containers.internal`. Data dir bind-mounted same-path host↔container (so the extracted supervisor binary resolves); an init service runs `generate-certs` for the supervisor JWT keys. Adds `openshell-gateway-init` + `openshell-gateway` services, `containers/openshell/gateway.{docker,podman}.toml`, `make openshell-up [ENGINE=]` / `openshell-down`, `.env.example` vars, and `docs/deploy/openshell-gateway.md`. Verified E2E on a real host for both engines (gateway image 0.1.8): compute driver connected and a sandbox reached `Completed` via compose; Podman also `ConnectSupervisor` 200 + bridge control-plane reachability. Implements [Design](docs/design/2026-11-13-openshell-gateway-in-compose.md) (#1186). Follow-ups (separate): uniform sandbox-provider `providers/` package; launcher one-click engine selection.
2022

‎clients/launcher/cmd/start.go‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/health"
2424
opsinternal "github.com/BitterSecurity/Decepticon/clients/launcher/internal/infracontrol"
2525
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/migrate"
26+
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/openshell"
2627
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/platform"
2728
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/starprompt"
2829
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/ui"
@@ -431,10 +432,26 @@ func runStartMode(cmd *cobra.Command, args []string, existingEngagement string,
431432
defer os.Remove(overlay)
432433
c.OverlayFile = overlay
433434
}
435+
// Stand up the OpenShell admission gateway alongside the stack so the
436+
// default `openshell` sandbox provider can admit this engagement out of
437+
// the box. The compute engine is chosen from the detected container
438+
// runtime (podman → rootless, else docker); the exported OPENSHELL_* env
439+
// reaches compose via ComposeCommandEnv()'s os.Environ() forwarding.
440+
gwProfile, gwLabel, gwErr := openshell.PrepareGateway(home, c.Runtime)
441+
if gwErr != nil {
442+
return fmt.Errorf("prepare OpenShell gateway: %w; inspect with `decepticon doctor`", gwErr)
443+
}
444+
ui.Info("Sandbox boundary · OpenShell gateway: " + gwLabel)
445+
434446
ui.Info("[4/5] Services · starting and waiting for readiness")
435-
startServices := func() error { return c.Up(compose.Profiles.CLI) }
447+
startServices := func() error { return c.Up(compose.Profiles.CLI, gwProfile) }
436448
if existingEngagement != "" && !attachInteractive {
437-
startServices = c.UpDesktop
449+
startServices = func() error {
450+
if err := c.Up(gwProfile); err != nil {
451+
return err
452+
}
453+
return c.UpDesktop()
454+
}
438455
}
439456
if err := startServices(); err != nil {
440457
return fmt.Errorf("start services: %w; inspect with `decepticon doctor` and `decepticon logs` (services kept)", err)

‎clients/launcher/internal/compose/compose.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,17 @@ var Profiles = struct {
6363
C2 string
6464
AD string
6565
Reversing string
66+
OpenShell string
6667
}{
6768
CLI: "cli",
6869
C2: "c2-sliver",
6970
AD: "ad",
7071
Reversing: "reversing",
72+
// OpenShell is the standing sandbox-admission gateway. Unlike the
73+
// specialist workloads, `decepticon start` activates it alongside
74+
// `cli` so the default `openshell` sandbox provider can admit
75+
// engagements out of the box (see internal/openshell).
76+
OpenShell: "openshell",
7177
}
7278

7379
// AllProfiles returns every profile flag the launcher should pass
@@ -81,6 +87,7 @@ func AllProfiles() []string {
8187
"--profile", Profiles.C2,
8288
"--profile", Profiles.AD,
8389
"--profile", Profiles.Reversing,
90+
"--profile", Profiles.OpenShell,
8491
}
8592
}
8693

‎clients/launcher/internal/compose/compose_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ func TestAllProfiles(t *testing.T) {
120120
profiles := AllProfiles()
121121
// ADR-0006 Sprint 2 expanded the catalog to cover every workload
122122
// the launcher may need to tear down: cli + c2-sliver + ad +
123-
// reversing = 4 profiles = 8 cli args (--profile NAME).
123+
// reversing; the standing openshell gateway joins so `down`/`stop`
124+
// sweep it too = 5 profiles = 10 cli args (--profile NAME).
124125
expected := []string{
125126
"--profile", "cli",
126127
"--profile", "c2-sliver",
127128
"--profile", "ad",
128129
"--profile", "reversing",
130+
"--profile", "openshell",
129131
}
130132
if len(profiles) != len(expected) {
131133
t.Fatalf("AllProfiles() len = %d, want %d", len(profiles), len(expected))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# OpenShell gateway — Docker compute driver. Rendered by the launcher
2+
# (internal/openshell): @DATA@ is replaced with the gateway data dir.
3+
[openshell]
4+
version = 2
5+
6+
[openshell.gateway]
7+
bind_address = "0.0.0.0:8080"
8+
health_bind_address = "0.0.0.0:8081"
9+
log_level = "info"
10+
compute_driver = "docker"
11+
disable_tls = true
12+
13+
[openshell.gateway.auth]
14+
allow_unauthenticated_users = true
15+
16+
[openshell.gateway.gateway_jwt]
17+
signing_key_path = "@DATA@/tls/jwt/signing.pem"
18+
public_key_path = "@DATA@/tls/jwt/public.pem"
19+
kid_path = "@DATA@/tls/jwt/kid"
20+
gateway_id = "decepticon-gateway"
21+
22+
[openshell.drivers.docker]
23+
default_image = "ghcr.io/bittersecurity/decepticon-sandbox:latest"
24+
sandbox_runtime_image = "ghcr.io/nvidia/openshell/sandbox:latest"
25+
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
26+
image_pull_policy = "if_not_present"
27+
sandbox_label = "decepticon"
28+
app_armor_profile = "Unconfined"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# OpenShell gateway — Podman compute driver (rootless, recommended).
2+
# Rendered by the launcher (internal/openshell): @DATA@ is replaced with the
3+
# gateway data dir (user-writable; the gateway runs --userns=keep-id as the
4+
# host user, so JWT keys must be user-owned).
5+
[openshell]
6+
version = 2
7+
8+
[openshell.gateway]
9+
bind_address = "0.0.0.0:8080"
10+
health_bind_address = "0.0.0.0:8081"
11+
log_level = "info"
12+
compute_driver = "podman"
13+
disable_tls = true
14+
15+
[openshell.gateway.auth]
16+
allow_unauthenticated_users = true
17+
18+
[openshell.gateway.gateway_jwt]
19+
signing_key_path = "@DATA@/tls/jwt/signing.pem"
20+
public_key_path = "@DATA@/tls/jwt/public.pem"
21+
kid_path = "@DATA@/tls/jwt/kid"
22+
gateway_id = "decepticon-gateway"
23+
24+
[openshell.drivers.podman]
25+
default_image = "ghcr.io/bittersecurity/decepticon-sandbox:latest"
26+
sandbox_runtime_image = "ghcr.io/nvidia/openshell/sandbox:latest"
27+
supervisor_image = "ghcr.io/nvidia/openshell/supervisor:latest"
28+
image_pull_policy = "if_not_present"
29+
grpc_endpoint = ""
30+
ssh_socket_path = "/run/openshell/ssh.sock"
31+
network_name = "decepticon-openshell"
32+
app_armor_profile = "Unconfined"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package openshell
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
"time"
10+
11+
"github.com/BitterSecurity/Decepticon/clients/launcher/internal/runtime"
12+
)
13+
14+
// TestLivePrepareGatewayPodman is a real-host integration check: it runs the
15+
// actual PrepareGateway code to render the gateway TOML + export OPENSHELL_*,
16+
// then brings up ONLY the openshell gateway service via `podman compose` using
17+
// that output and asserts the gateway comes up healthy on the podman driver.
18+
//
19+
// Guarded: skips unless OPENSHELL_LIVE=1 and podman is present. Needs the repo
20+
// docker-compose.yml, the podman user socket, and the gateway image pulled.
21+
// Run on ra-trial:
22+
//
23+
// OPENSHELL_LIVE=1 go test -run TestLivePrepareGatewayPodman -v ./internal/openshell/
24+
func TestLivePrepareGatewayPodman(t *testing.T) {
25+
if os.Getenv("OPENSHELL_LIVE") != "1" {
26+
t.Skip("set OPENSHELL_LIVE=1 to run the live gateway integration test")
27+
}
28+
if _, err := exec.LookPath("podman"); err != nil {
29+
t.Skip("podman not on PATH")
30+
}
31+
32+
repoCompose := findRepoFile(t, "docker-compose.yml")
33+
repoRoot := filepath.Dir(repoCompose)
34+
35+
home := t.TempDir()
36+
// The launcher runs compose from DECEPTICON_HOME; mirror that by copying
37+
// the compose file in. Services it references by build context are not
38+
// started (we bring up only the gateway service), so a copy is enough.
39+
must(t, copyFile(repoCompose, filepath.Join(home, "docker-compose.yml")))
40+
must(t, os.WriteFile(filepath.Join(home, ".env"), nil, 0o600))
41+
42+
// Detect podman exactly as the launcher does.
43+
rt, err := runtime.Detect()
44+
if err != nil || rt.Name != "podman" {
45+
t.Skipf("podman runtime not detected (got %q, err %v)", rt.Name, err)
46+
}
47+
48+
// THE CODE UNDER TEST: render config + export OPENSHELL_* env.
49+
profile, label, err := PrepareGateway(home, rt)
50+
if err != nil {
51+
t.Fatalf("PrepareGateway: %v", err)
52+
}
53+
t.Logf("engine label=%q profile=%q", label, profile)
54+
55+
// Bring up only the gateway service via the docker CLI pointed at the
56+
// podman socket (the proven compose-on-podman path). This verifies the
57+
// launcher-rendered TOML + exported OPENSHELL_* env, which is what W1
58+
// adds; the launcher's own compose-command selection is pre-existing.
59+
project := "dcp-w1-live"
60+
composeEnv := append(os.Environ(), "DOCKER_HOST=unix://"+os.Getenv("OPENSHELL_COMPUTE_SOCK"))
61+
up := exec.Command("docker", "compose", "-p", project,
62+
"--profile", profile, "up", "-d", "openshell-gateway")
63+
up.Dir = home
64+
up.Env = composeEnv
65+
if out, err := up.CombinedOutput(); err != nil {
66+
t.Fatalf("compose up gateway failed: %v\n%s", err, out)
67+
}
68+
t.Cleanup(func() {
69+
down := exec.Command("docker", "compose", "-p", project, "--profile", profile, "down")
70+
down.Dir = home
71+
down.Env = composeEnv
72+
_ = down.Run()
73+
})
74+
75+
// Health: a bridge container reaches the host-net gateway via
76+
// host.containers.internal (the real host can't, under rootless podman).
77+
var healthy bool
78+
var lastOut string
79+
for i := 0; i < 60; i++ {
80+
// /readyz returns the status JSON ({"status":"healthy",...}); /healthz
81+
// is an empty 200, so assert against /readyz.
82+
probe := exec.Command("podman", "run", "--rm", "docker.io/curlimages/curl:latest",
83+
"-fsS", "--max-time", "3", "http://host.containers.internal:8081/readyz")
84+
probe.Env = up.Env
85+
out, err := probe.CombinedOutput()
86+
lastOut = string(out)
87+
if err == nil && strings.Contains(lastOut, "healthy") {
88+
healthy = true
89+
break
90+
}
91+
time.Sleep(time.Second)
92+
}
93+
if !healthy {
94+
logs := exec.Command("podman", "logs", "decepticon-openshell-gateway")
95+
logs.Env = up.Env
96+
lg, _ := logs.CombinedOutput()
97+
t.Fatalf("gateway not healthy after 30s; last probe=%q\n--- logs ---\n%s", lastOut, lg)
98+
}
99+
t.Logf("gateway healthy via host.containers.internal: %s", strings.TrimSpace(lastOut))
100+
101+
// Confirm the podman compute driver connected (the launcher-rendered TOML).
102+
logs := exec.Command("podman", "logs", "decepticon-openshell-gateway")
103+
logs.Env = up.Env
104+
lg, _ := logs.CombinedOutput()
105+
if !strings.Contains(string(lg), "compute driver") || !strings.Contains(string(lg), "podman") {
106+
t.Errorf("gateway log does not confirm podman compute driver:\n%s", lg)
107+
}
108+
109+
_ = repoRoot
110+
}
111+
112+
func findRepoFile(t *testing.T, name string) string {
113+
t.Helper()
114+
dir, err := os.Getwd()
115+
if err != nil {
116+
t.Fatalf("getwd: %v", err)
117+
}
118+
for i := 0; i < 8; i++ {
119+
p := filepath.Join(dir, name)
120+
if _, err := os.Stat(p); err == nil {
121+
return p
122+
}
123+
parent := filepath.Dir(dir)
124+
if parent == dir {
125+
break
126+
}
127+
dir = parent
128+
}
129+
t.Skipf("could not locate %s above %s", name, dir)
130+
return ""
131+
}
132+
133+
func copyFile(src, dst string) error {
134+
b, err := os.ReadFile(src)
135+
if err != nil {
136+
return err
137+
}
138+
return os.WriteFile(dst, b, 0o644)
139+
}
140+
141+
func must(t *testing.T, err error) {
142+
t.Helper()
143+
if err != nil {
144+
t.Fatal(err)
145+
}
146+
}

0 commit comments

Comments
 (0)