Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
web: ${{ steps.filter.outputs.web }}
python: ${{ steps.filter.outputs.python }}
shell: ${{ steps.filter.outputs.shell }}
kubernetes: ${{ steps.filter.outputs.kubernetes }}
steps:
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: filter
Expand All @@ -40,6 +41,19 @@ jobs:
- '**/*.py'
- 'scripts/benchmark/**'
- '.github/**'
kubernetes:
- 'sandbox/**'
- 'deploy/**'
- 'cmd/artex-runner/**'
- 'cmd/artex-exec-wrap/**'
- 'cmd/artex-egress-proxy/**'
- 'Dockerfile.runner'
- 'Dockerfile.worker'
- 'Dockerfile.egress-proxy'
- 'scripts/k3d-e2e.sh'
- 'go.mod'
- 'go.sum'
- '.github/workflows/ci.yml'
# Added files too: a new top-level directory must appear in the bot summary.
shell:
- '**/*.sh'
Expand Down Expand Up @@ -188,7 +202,7 @@ jobs:
# shellcheck is preinstalled on the ubuntu runners. -S warning: the scripts
# currently have only info-level notes (intentional A && B || C chains in
# update.sh, an unquoted glob in backup.sh's prune), so fail on warnings.
- run: shellcheck -S warning install.sh update.sh start.sh scripts/backup.sh scripts/verify.sh reset-password.sh scripts/extract-changelog-section.sh scripts/test-extract-changelog-section.sh .github/scripts/bot.sh scripts/test-bot-context.sh scripts/test-start-sh.sh
- run: shellcheck -S warning install.sh update.sh start.sh scripts/backup.sh scripts/verify.sh reset-password.sh scripts/extract-changelog-section.sh scripts/test-extract-changelog-section.sh .github/scripts/bot.sh scripts/test-bot-context.sh scripts/test-start-sh.sh scripts/k3d-e2e.sh
- run: bash scripts/test-extract-changelog-section.sh
# start.sh is the Docker ENTRYPOINT and runs under dash there, as /bin/sh does here.
- run: bash scripts/test-start-sh.sh
Expand All @@ -197,6 +211,40 @@ jobs:
# scripts/benchmark/ exist.
- run: bash scripts/test-bot-context.sh

# Live test of the Kubernetes sandbox backend and the Helm chart on k3d: the runner,
# worker and egress-proxy images are built from this checkout, the chart is installed
# runner-only (the panel image is not needed), and TestKubeSandboxE2E checks pod
# hardening, NetworkPolicy isolation, the egress proxy, kill, recovery and cleanup.
kubernetes:
needs: changes
if: ${{ !cancelled() && (github.event_name != 'pull_request' || needs.changes.result != 'success' || needs.changes.outputs.kubernetes == 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 30
env:
K3D_VERSION: v5.9.0
# Pinned here, not taken from the release's own checksums file (see the
# Dockerfile tools stage for why).
K3D_SHA256: 06d8f25bc3a971c4eb29e0ff08429b180402db0f4dec838c9eac427e296800a0
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version-file: go.mod
- name: install k3d
run: |
curl -fsSL -o /tmp/k3d "https://github.com/k3d-io/k3d/releases/download/${K3D_VERSION}/k3d-linux-amd64"
echo "${K3D_SHA256} /tmp/k3d" | sha256sum -c -
sudo install -m 0755 /tmp/k3d /usr/local/bin/k3d
k3d version
helm version --short
- name: helm lint
run: helm lint --strict deploy/helm/artex
- name: k3d sandbox e2e
env:
RUNNER_ONLY: "1"
ARTEX_E2E_INTERNET: "1"
run: bash scripts/k3d-e2e.sh

web:
needs: changes
if: ${{ !cancelled() && (github.event_name != 'pull_request' || needs.changes.result != 'success' || needs.changes.outputs.web == 'true') }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project are documented in this file. The format is b

## [Unreleased]

### Added

- **Kubernetes sandbox backend for `artex-runner`.** With `ARTEX_RUNNER_BACKEND=kubernetes` each task runs in a worker pod behind its own egress-proxy pod, created through the Kubernetes API with no container runtime socket. The worker runs as uid/gid 10001 with `runAsNonRoot`, a read-only root filesystem, all capabilities dropped, `seccomp: RuntimeDefault`, no service-account token and no service links, and mounts only its task directory. Per-task NetworkPolicies are created before the pods and deleted after them: the worker can reach only its own proxy, and the proxy only cluster DNS, public addresses and the task's scope CIDRs. The runner waits until the policies are in effect before the first command, runs commands through `pods/exec`, and re-adopts task pods after a restart.
- **Helm chart for Kubernetes.** `deploy/helm/artex` deploys the panel, PostgreSQL and `artex-runner` with the Kubernetes sandbox backend, a namespace-scoped Role, NetworkPolicies and a values schema. A chart-level default-deny covers every runner-managed pod, so a missing per-task policy fails closed. The `volume-permissions` init container fixes the `Bash can create files in /app/data` self-test failure on world-writable volumes (#620). `scripts/k3d-e2e.sh` and the new `kubernetes` CI job test the chart live on k3d.
- **Scope-restricted panel egress for `sandbox.mode=off` on Kubernetes.** With the sandbox off, agent commands run in the panel pod, whose egress was open to the internet, other namespaces, the nodes and the Kubernetes API. The chart now restricts it by default (`sandbox.offModeEgress.enabled=true`): a static NetworkPolicy allows only cluster DNS, the database and a small controller, and the controller (`artex-runner` with `ARTEX_RUNNER_BACKEND=panel-egress`, a Role limited to NetworkPolicies, non-root, no capabilities) keeps a second NetworkPolicy with the IP addresses of the operator-approved scope of every live task, the known hostnames under it, the LLM endpoints and `extraHosts`/`extraCIDRs`. The panel computes the scope with the same code as the per-task proxy and pushes it over the new authenticated `PUT /v1/panel-egress` before each agent turn and every 30 s; it holds no Kubernetes credentials. Resolved private, metadata and IPv6 addresses are dropped unless an approved CIDR covers them, revoked scope leaves on the next push, DNS rotation is tolerated for `retention`, and a stopped controller leaves the last policy in place (fail closed). `GET /api/health` reports the state as `sandbox_egress`. In-scope direct scans such as `nmap -sT` work; the limits (union of tasks, IP-based, DNS still resolvable, IPv6, no `NET_RAW`) are in the chart README. `sandbox.offModeEgress.enabled=false` restores the old open egress. The panel also scrubs `ARTEX_RUNNER_TOKEN` from its environment after startup. Docker deployments and required mode are unchanged. `scripts/k3d-e2e.sh` gains `OFF_MODE=1`.

### Security

- **Company egress is promoted only from operator-approved company scope.** A sandboxed worker could register assets with `insert_assets` (an attacker IP or domain attributed to the company through its domain or ICP rule), and the agent could add rules with `add_company_scope`; the next operator selection or re-approval of the company copied those hosts into `task_scope_egress`, persistently widening the approved sandbox egress. The approval snapshot now copies only `company_scope` domain and IP/CIDR rules with the new `approved_by_operator` flag (migration `0025_company_scope_approved.sql`), which only the operator company API sets; `add_company_scope` and the ScopeSentry sync store rules with the flag off. Existing rules are backfilled as approved. Behaviour change: a domain or IP discovered only in assets is no longer reachable from the sandbox until it is added explicitly to the company scope (operator) or to the task scope. Egress rows already frozen by earlier approvals are not purged by this change, and re-approving the company does not remove them (the snapshot only adds rows); removing the company from the task scope drops its rows, and approving it again rebuilds them from approved rules only.
Expand Down
4 changes: 4 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ not the console afterwards.
- Prebuilt GHCR images: the image is published from the next tagged release. Until then,
`docker-compose.ghcr.yml` and `docker pull ghcr.io/baarai/artex` return `denied`; use the checkout
build above.
- Kubernetes: the Helm chart in [`deploy/helm/artex`](deploy/helm/artex/README.md) runs the panel,
PostgreSQL and the sandbox runner with its Kubernetes backend: every agent command runs in a
per-task pod, with no Docker socket. It needs a CNI that enforces NetworkPolicy.
`scripts/k3d-e2e.sh` installs and tests it on a local k3d cluster.

## Troubleshooting

Expand Down
85 changes: 66 additions & 19 deletions cmd/artex-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -22,33 +23,75 @@ func envOr(k, def string) string {
return def
}

// buildBackend selects the backend from ARTEX_RUNNER_BACKEND ("docker", the
// default, "kubernetes", or "panel-egress").
func buildBackend() (sandbox.Backend, error) {
wsRoot := envOr(sandbox.EnvWorkspaceRoot, sandbox.DefaultWorkspaceRoot)
auditRoot := envOr(sandbox.EnvAuditRoot, sandbox.DefaultAuditRoot)
workerImage := envOr(sandbox.EnvWorkerImage, sandbox.DefaultWorkerImage)
proxyImage := envOr(sandbox.EnvProxyImage, sandbox.DefaultProxyImage)

switch kind := strings.ToLower(envOr(sandbox.EnvRunnerBackend, sandbox.BackendDocker)); kind {
case sandbox.BackendDocker:
sock := envOr("DOCKER_SOCK", "/var/run/docker.sock")
if dh := strings.TrimSpace(os.Getenv("DOCKER_HOST")); strings.HasPrefix(dh, "unix://") {
sock = strings.TrimPrefix(dh, "unix://")
}
log.Printf("[runner] backend=docker socket=%s", sock)
return sandbox.NewDockerBackend(sandbox.DockerConfig{
SocketPath: sock,
WorkerImage: workerImage,
ProxyImage: proxyImage,
WorkspaceRoot: wsRoot,
HostWorkspaceRoot: envOr("ARTEX_HOST_WORKSPACE_ROOT", wsRoot),
AuditRoot: auditRoot,
HostAuditRoot: envOr("ARTEX_HOST_AUDIT_ROOT", auditRoot),
TaskNetPrefix: envOr(sandbox.EnvTaskNetPrefix, sandbox.DefaultTaskNetPrefix),
EgressNet: envOr(sandbox.EnvEgressNet, sandbox.DefaultEgressNet),
}), nil
case sandbox.BackendKubernetes:
cfg, err := sandbox.KubeConfigFromEnv()
if err != nil {
return nil, err
}
cfg.WorkerImage, cfg.ProxyImage = workerImage, proxyImage
cfg.WorkspaceRoot, cfg.AuditRoot = wsRoot, auditRoot
b, err := sandbox.NewKubernetesBackend(cfg)
if err != nil {
return nil, err
}
log.Printf("[runner] backend=kubernetes namespace=%s claim=%s", b.Namespace(), cfg.DataClaim)
return b, nil
case sandbox.BackendPanelEgress:
// ARTEX_SANDBOX=off on Kubernetes: no task pods, only the panel's scope
// NetworkPolicy (sandbox/paneleggress.go).
cfg, err := sandbox.PanelEgressConfigFromEnv()
if err != nil {
return nil, err
}
c, err := sandbox.NewPanelEgressController(cfg)
if err != nil {
return nil, err
}
log.Printf("[runner] backend=panel-egress policy=%s refresh=%s retention=%s extra_hosts=%d extra_cidrs=%d",
cfg.PolicyName, cfg.Refresh, cfg.Retention, len(cfg.ExtraHosts), len(cfg.ExtraCIDRs))
return c, nil
default:
return nil, fmt.Errorf("invalid %s=%q (want %q, %q or %q)", sandbox.EnvRunnerBackend, kind, sandbox.BackendDocker, sandbox.BackendKubernetes, sandbox.BackendPanelEgress)
}
}

func main() {
token := strings.TrimSpace(os.Getenv(sandbox.EnvRunnerToken))
if token == "" {
log.Fatalf("[runner] %s is required (refusing to start unauthenticated)", sandbox.EnvRunnerToken)
}
addr := envOr("ARTEX_RUNNER_ADDR", sandbox.DefaultRunnerAddr)
sock := envOr("DOCKER_SOCK", "/var/run/docker.sock")
if dh := strings.TrimSpace(os.Getenv("DOCKER_HOST")); strings.HasPrefix(dh, "unix://") {
sock = strings.TrimPrefix(dh, "unix://")
backend, err := buildBackend()
if err != nil {
log.Fatalf("[runner] %v", err)
}

wsRoot := envOr(sandbox.EnvWorkspaceRoot, sandbox.DefaultWorkspaceRoot)
hostWSRoot := envOr("ARTEX_HOST_WORKSPACE_ROOT", wsRoot)
auditRoot := envOr(sandbox.EnvAuditRoot, sandbox.DefaultAuditRoot)
hostAuditRoot := envOr("ARTEX_HOST_AUDIT_ROOT", auditRoot)
backend := sandbox.NewDockerBackend(sandbox.DockerConfig{
SocketPath: sock,
WorkerImage: envOr(sandbox.EnvWorkerImage, sandbox.DefaultWorkerImage),
ProxyImage: envOr(sandbox.EnvProxyImage, sandbox.DefaultProxyImage),
WorkspaceRoot: wsRoot,
HostWorkspaceRoot: hostWSRoot,
AuditRoot: auditRoot,
HostAuditRoot: hostAuditRoot,
TaskNetPrefix: envOr(sandbox.EnvTaskNetPrefix, sandbox.DefaultTaskNetPrefix),
EgressNet: envOr(sandbox.EnvEgressNet, sandbox.DefaultEgressNet),
})

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

Expand All @@ -58,6 +101,10 @@ func main() {
log.Printf("[runner] recovered %d managed task container(s) by label", n)
}

if r, ok := backend.(interface{ Run(context.Context) }); ok {
go r.Run(ctx)
}

rs, err := sandbox.NewRunnerServer(token, version, backend)
if err != nil {
log.Fatalf("[runner] init failed: %v", err)
Expand Down
18 changes: 17 additions & 1 deletion cmd/artex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func run() int {
return 1
}
var sandboxClient server.SandboxClient
panelEgressURL := strings.TrimSpace(os.Getenv(sandbox.EnvPanelEgressURL))
var panelEgressOpt server.Option = func(*server.Server) {}
if sandboxCfg.Mode == sandbox.ModeRequired {
sandboxClient = sandbox.NewClient(sandboxCfg.RunnerURL, sandboxCfg.RunnerToken)
hctx, hcancel := context.WithTimeout(ctx, 5*time.Second)
Expand All @@ -272,11 +274,25 @@ func run() int {
} else {
slog.Info("[sandbox] ARTEX_SANDBOX=required: connected to artex-runner", "runner_url", sandboxCfg.RunnerURL, "workers", h.Workers, "version", h.Version)
}
if panelEgressURL != "" {
slog.Warn("[sandbox] " + sandbox.EnvPanelEgressURL + " is ignored: panel egress control applies only to ARTEX_SANDBOX=off")
}
} else {
server.LogSandboxOffBanner()
// Kubernetes (Helm chart, sandbox.offModeEgress): the panel's egress is
// limited to the approved scope of its tasks by a NetworkPolicy the panel
// egress controller maintains from the scope pushed here.
if panelEgressURL != "" {
if sandboxCfg.RunnerToken == "" {
slog.Error("[sandbox] " + sandbox.EnvPanelEgressURL + " is set but " + sandbox.EnvRunnerToken + " is empty")
return 1
}
panelEgressOpt = server.WithPanelEgress(sandbox.NewClient(panelEgressURL, sandboxCfg.RunnerToken), server.PanelEgressEnvHosts())
slog.Info("[sandbox] ARTEX_SANDBOX=off: panel egress is limited to task scope by the panel egress controller", "controller", panelEgressURL)
}
}

srv := server.New(ctx, mgr, skillDir, *dataDir, keyDir, server.WithSecretScrub(), server.WithTrustedProxies(trusted), server.WithExecPrivilege(priv), server.WithIsolationStatus(isolation), server.WithSharedBrowser(*sharedBrowser), server.WithSharedBrowserLockTimeout(*sharedBrowserLockTimeout), server.WithSandbox(sandboxClient, sandboxCfg.Mode))
srv := server.New(ctx, mgr, skillDir, *dataDir, keyDir, server.WithSecretScrub(), server.WithTrustedProxies(trusted), server.WithExecPrivilege(priv), server.WithIsolationStatus(isolation), server.WithSharedBrowser(*sharedBrowser), server.WithSharedBrowserLockTimeout(*sharedBrowserLockTimeout), server.WithSandbox(sandboxClient, sandboxCfg.Mode), panelEgressOpt)
// ReadTimeout bounds how long the request headers and body may take to arrive.
// It does not limit how long a handler runs, so an event stream stays open.
// WriteTimeout is left unset: a write deadline would cut that stream.
Expand Down
14 changes: 14 additions & 0 deletions deploy/helm/artex/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: artex
description: ARTEX autonomous pentest platform with the per-task Kubernetes sandbox (no Docker socket).
type: application
version: 0.1.0
appVersion: "0.7.1"
kubeVersion: ">=1.25.0-0"
home: https://github.com/BaaRai/ARTEX
sources:
- https://github.com/BaaRai/ARTEX
keywords:
- pentest
- security
- sandbox
Loading
Loading