devstack
~ by xennui
devstack is a command-line tool, written in Python, that reads one config file
(devstack.toml) and builds one locked-down container from it on a Linux host. The container
is an incus system container running Debian 13, and it does two jobs:
- The development machine. VSCode connects to it over SSH, and the project folder is shared into it from the host.
- A local copy of production. Caddy handles TLS with a local certificate and passes requests to a hardened Node app, which talks to Postgres.
The container sits between the host and code that isn't fully trusted, such as npm packages, editor extensions and coding agents. That code can do what it likes inside the container. It has only a few ways to affect the host, and the operating system enforces those limits, so they don't depend on the code behaving.
The diagram shows the host at the top, incus in the middle as the boundary, and the container
and project folder below it. The numbered arrows are the connections between them, explained
in the key at the bottom right. The sections after it go through each part in turn. The full
reasoning is in the project's design document, DESIGN.md.
The tool
The tool is two files:
devstackis a short Bash launcher that finds Python 3.11 or newer, the first version withtomllibfor reading TOML. It tries/usr/bin/python3before searchingPATH, because version managers such as pyenv and conda often put an older Python first.devstack.pyis everything else: about 7,200 lines that use only the Python standard library. With no pip dependencies there is nothing extra to install or to trust.
Templates hold content and devstack.py holds logic. Placeholders look like @@UPPER_SNAKE@@,
since ${} and {} already mean something in TypeScript and in Caddyfiles. Rendering fails
if any placeholder is left over.
Templates and data
devstack.example.tomllists every config key with its default and help text. It is generated from the schema indevstack.py(./devstack init -n -c devstack.example.toml --force), so the documentation always matches the code.templates/project/is the starting scaffold for a new project.templates/system/holds the files rendered into the container: the sshd config, the app's systemd unit, the runner socket and service, the firewall rules (egress.nft) and the service that loads them, thedevstack-synchelper and the Postgres config.data/iana-tlds.txtis a snapshot of the real top-level domains. The dev domain suffix (dns.tld) must not be one of them, because a rule such asaddress=/com/…in dnsmasq would send every.comlookup on the host to the container.
Tests and CI
tests/test_devstack.pyhas about 215 unit tests that run without root, incus or a real host. They cover config parsing, template rendering, shell quoting, the journal and undo (against a fake command runner), the CA's name constraints (using real openssl), the network ACL rules, the SBOM normalizer, the gitleaks arguments and checkpoints on a temporary git repository.tests/verify_pins.pydownloads every pinned file and checks its sha256. It needs the network, so CI runs it once a week instead of on every pull request..github/workflows/ci.ymlsyntax-checks the launcher (bash -n), compiles the Python, checks the example config and runs the unit tests, plus the weekly pin check. It tests devstack itself and isn't meant as a CI setup for projects.
Documentation
DESIGN.mdis the specification, written for maintainers and coding agents. It records settled decisions, which should only be reopened when new facts turn up, and lists security details that look as if they could be simplified but can't.README.mdhas the quick start, a summary of the security model and the table of trust roots.SECURITY.mdhas the threat model and what is in and out of scope.index.htmlis the user manual, the "devstack Field Guide". It covers setup, phases, undo, security and troubleshooting, and comes with a self-hosted font.
Configuration
Every config key is defined once, in a table called SCHEMA in devstack.py, with its type,
default, help text and validator. devstack init, devstack config explain, validation and
the example file are all built from that table. An unknown key is an error, and the message
suggests the closest real key.
Two files
The config is split in two to keep anything that contains host details out of public repositories.
devstack.tomlbelongs to one user on one machine and is kept out of git. It holds host paths, SSH and DNS settings, and the host side of each mount.<project>/infra/devstack-requires.tomlis the project's part, committed with the project. It can only contain container settings: the image, Node, Caddy, the app, runners, Postgres, and whether to use a GPU. It can ask for mounts, but only by name and container path, never by a path on the host.
devstack treats devstack.toml with the same care as a script that could do damage, so
settings that weaken isolation only take effect after you type yes (or pass --yes). These
include mounting $HOME, ~/.ssh or /etc, granting full sudo, using the open app profile,
allowing LAN exceptions and adding runners.
The project file is read against an allowlist, so a cloned repository can't change anything on the host, and any change since the last run needs your approval.
Running more than one stack
Anything that could clash between two stacks, such as the container name, the domain suffix,
volumes, the SSH key, the dnsmasq file, systemd units and users, is named after stack.name
by default. A second stack only needs a different name. Preflight reports any clash with
something the current stack doesn't own.
How a run works
Phases
devstack up builds the container in six phases, each adding a single concern:
base: the container itselfapp: the appproxy: the proxystandards: client-side web standardsisolation: server-side isolationpostgres: the database
A phase is a list of steps, and each step can describe itself, check whether it has already
been done, and apply itself. The phase ends with checks that verify the result. Steps skip work
that is already done, so up is safe to run again.
devstack preflight and devstack plan change nothing. They check the host's dependencies,
incus, name clashes and risky settings, and list every host path a run would write to. They
are meant to be run first.
Undo
- Inside the container, undo uses incus snapshots. Before every phase after
base, devstack takes a snapshot nameddevstack-pre-<phase>. Undoing a phase restores it, which reverts packages, files, users and devices in one go, without needing a reverse operation for every command. - Outside the container, changes are written to
journal.jsonlbefore they are made. Undo works through the journal using a fixed set of entry types, and never runs shell commands stored in it. It also checks each path in the journal against what the current config would produce, so an edited journal can't pointsudo rmsomewhere else. - When a phase fails, the default setting
run.on_failure = rollbackundoes it, whilestopleaves it in place for debugging. A file lock (fcntl) makes sure only one run happens at a time.
The aim is that a run never leaves things half-finished in a way you can't get out of.
Checkpoints
Checkpoints are for undoing changes after the container is built, such as an agent's work or a bad install. A checkpoint is taken with the container stopped and has four parts:
- a container snapshot
- snapshots of the data volumes
- a commit of the project on a hidden git ref (
refs/devstack/checkpoints/<name>) - a tar file of the files git ignores
Your branches and HEAD are left alone. git is run hermetically, ignoring any config the project could have written, so the project can't use it to run code on the host.
State and logs
Each stack keeps its state in ~/.local/state/devstack/<stack>/: state.json, the journal,
the lock file, the log, backups/, ca/, scan reports and the browser profile.
The console shows info messages. The log file always records at debug level, including
every command with its exit code and output. Secrets are passed through stdin or files, never
as command-line arguments, and a redaction filter on the log catches any that get through.
The data volumes for Postgres and the app survive both undo and destroy unless you pass
--purge-data, and devstack takes a backup before purging. Running up again reattaches them.
On the host
DNS
devstack writes one dnsmasq file per stack that points *.<tld> at the container's IP
address. This lets the app run at its real domain with a dev suffix added, such as
app.example.com.webstack.
The host must already resolve names through dnsmasq. Setting that up is a one-time manual
step, because it changes DNS for the whole machine, and devstack never edits resolv.conf.
Certificates
The root certificate and its key are created on the host, and the certificate is X.509
name-constrained to *.<tld>. The container only gets an intermediate certificate, so if its
key is stolen from the container, it can only sign names under the dev suffix.
The first version used Caddy's built-in CA, whose key lived in the container and was trusted for every site.
SSH
Each stack has its own ed25519 key, a marked block in ~/.ssh/config and its own
known_hosts file. The container's host key is read through incus exec, so the first
connection doesn't have to trust an unknown key. Login is by key only, with agent and X11
forwarding turned off.
Network ACL
An incus network ACL is attached to the container's network interface and enforced by the host. It rejects traffic from the container to the host and the LAN, apart from DNS and DHCP to the gateway. In the first version nothing stopped the container from reaching either.
The base phase tests the ACL by starting a temporary listener on the host and checking that
the container can't reach it.
Read-only .git
The project's .git directory is mounted into the container read-only. The host runs git in
that directory, so a hook or a core.fsmonitor setting written from inside the container
would run code on the host, and refs or grafts control what git log shows. Commits are made
on the host.
At first only hooks and config were read-only; later this was extended to all of .git.
Data volumes
<stack>-pgdata and <stack>-appdata are incus custom volumes. They are kept out of
container snapshots, so rolling the container back never rolls back data.
devstack browse
This opens Chromium with its own profile and certificate store. It is the only browser that trusts the dev CA. Every request outside the dev domain, including requests to localhost, goes to a proxy that drops it.
Pages from the container opened in your everyday browser could reach services on the host's
loopback interface and on the LAN, and the ACL can't stop that because the requests come from
the browser on the host. For the same reason tls.browser_trust defaults to no.
Scanners
grype and gitleaks run on the host, against files the container produced. The container is what gets checked and the host does the checking, which keeps the scanners out of the environment they audit. It also means the container doesn't need grype's vulnerability database, which is about 1 GB.
Inside the container
The login user and every agent run under the same uid, so the container can't tell them apart.
The rule that follows from this is that nothing the login user can edit runs as root, and
changes that affect security come from the host, through devstack up.
Users and access
- The login user
devhas the same uid as your user on the host, so files in the shared folder keep the right owner. It can reach the internet and use the database as the app role. It can't use sudo for anything exceptdevstack-sync. In the first version it had passwordless sudo, which made every agent root. The name is generic so it doesn't end up in committed files. devstack-syncis the only command sudo allows, and it accepts a fixed set of verbs.packagesreads package names on stdin, so root never opens a file the user controls. It accepts exact Debian package names only, stops newly installed services from starting and masks any new units. The other verbs restart the app or the runners, validate or reload Caddy (as the caddy user), and report status. This lets agents get apt packages installed through a list in git that can be reviewed.- sshd only allows key login, only for
dev, with no root login and no agent or X11 forwarding. TCP forwarding stays on because VSCode Remote-SSH needs it.
Caddy
Caddy handles TLS with certificates from the intermediate CA, serves static files and forwards
/api/* to the app. It uses two Caddyfiles:
/etc/caddy/Caddyfileis root-owned and holds the global options, which put the admin API on a unix socket instead of TCP port 2019, and the same-origin rule. It then imports the project's file.infra/Caddyfilebelongs to the project. It can't override the global options, because Caddy refuses to parse a second global block, so an attempt to do so stops Caddy instead of weakening it.
The same-origin rule makes Caddy return 403 for requests the browser marks as cross-site or
same-site, and for requests with another site's Origin header. This stops other sites from
calling the app with your cookies.
The app and runners
- The app runs as a hardened systemd service (
ProtectSystem=strict, a syscall filter, no capabilities and more) under a fixed user,<stack>-app. It listens on 127.0.0.1 only and accepts only requests that carry theX-Internal-Tokenheader, which only Caddy adds. The first version usedDynamicUser, which gives no stable uid to write firewall rules for or to own files. - Runners are for jobs that need the internet or that parse untrusted files, such as
fetchers or ffmpeg. Each one is socket-activated and starts one short-lived process per
connection, under its own user, with no secrets and no access to app data except the
incoming/directory.
Firewall
- Outbound access is set per user.
egress.nftmatches on the uid that owns each socket (meta skuid). The app gets thelocalprofile: loopback only, without DNS, so data can't be smuggled out in DNS lookups. Runners get the public internet and nothing else. devstack-egress.serviceloads the rules, and the app and runner unitsRequire=it, so if the rules aren't loaded the app doesn't start. This replaced systemd'sIPAddressDeny, which silently did nothing.- Inbound, ufw blocks connections except on ports 22, 80 and 443. Debian's
nftables.serviceisn't used, because it runsflush ruleset, which would wipe ufw's rules.
Postgres and secrets
- Postgres comes from the PGDG repository, with its key fingerprint pinned. It listens on
localhost with scram authentication, and the superuser can only log in through peer
authentication. devstack creates the app role, its database and a
<db>_testdatabase. The data is on the persistent volume, and the postgres uid is fixed at 500 so that a rebuilt container still owns the files.db restoreruns as the app role in a single transaction. - Secrets live in
/etc/app-secrets/: the internal token andpostgres.env. They are generated once with Python'ssecrets.token_hexand never passed as command-line arguments. The dev env file is written as the login user, so root never writes through a path the user controls.
Toolchain
- Node is installed from the release tarball, which is checked with
gpgvagainst Node's release keyring. The keyring is pinned by commit and sha256. pnpm comes through corepack, pinned to a version that is at least a week old. - syft, which generates the SBOM, is installed in the container as a pinned binary. It runs
there because that's where the real dpkg database and
node_modulesare.
The project it creates
devstack only creates project files that don't exist yet, and reports the ones it skipped. The toolchain files (the ESLint config, the pnpm workspace file and the lint script) are only added to new projects, because adding them next to an existing lockfile could break a rebuild.
The app
server.ts,static/anderror/are a small TypeScript app with no dependencies, along with a static page and an error page. The app has a/api/healthendpoint and the token check, and refuses to start in production without a token. It only exists to prove the stack works.package.jsonandtsconfig.jsonset up ES modules, pin pnpm throughpackageManager, and turn onstrictandnoUncheckedIndexedAccess. TypeScript stays at 6.0 until typescript-eslint supports version 7.
Linting and dependencies
eslint.config.jsuses thestrict-type-checkedrules and the security and no-unsanitized plugins, banseval, and allowschild_processin one wrapper only. It takes the place of a static analysis tool. Semgrep was considered and rejected because it can't be pinned as a single binary and sends usage data home.pnpm-workspace.yamlholds the supply-chain settings.minimumReleaseAgeonly allows packages that have been published for at least 7 days, andblockExoticSubdeps,trustPolicy: no-downgradeandstrictDepBuildsare turned on.scripts/sync-env.shrunssudo devstack-sync packages < infra/apt-packages.txtand thenpnpm install --frozen-lockfile.scripts/lint-changed.shlints the files that changed. You run it inside the container. It isn't a git hook, because hooks run on the host, which would mean running project code there.
infra/
infra/apt-packages.txtlists the system packages the project needs, one per line, so every addition shows up as a diff to review.infra/Caddyfilehas the routes, the CSP and other headers. devstack generates and manages it by default, or the project can take it over.infra/compress-static.shwrites.brand.gzcopies of the static files for Caddy to serve.infra/sbom/container.cdx.jsonandinfra/sbom/app.cdx.jsonare CycloneDX inventories of everything installed, committed to the repository. They are normalized, with timestamps, ids and file paths removed and entries sorted, so any change in them is a real dependency change. They replaced a hand-writtenSBOM.md.infra/devstack-requires.tomlis the project's part of the config, described under Configuration above.
For agents and people
AGENTS.mdtells coding agents what the container enforces: no root, a read-only.git, how to request packages and the rules for secrets. Agents can read the limits there instead of running into them.README.mdexplains the project and its dependency policy..gitignoreexcludes.env, keys and the compressed copies of static files.
Supply chain and auditing
Trust roots
The fingerprints of the Caddy and PGDG apt keys, the commit and sha256 of Node's keyring, and
the versions and sha256 hashes of syft, grype and gitleaks are all constants in devstack.py.
A unit test fails if any of them is missing from the table in the README. Plain sha256 hashes
were chosen over cosign signatures because they depend on far less.
SBOM
devstack sbom generate, sbom check and sbom scan handle the software bill of materials.
syft generates it inside the container, devstack normalizes it, and you commit it. grype then
scans it from the host.
The check only counts vulnerabilities that have a fix available. On a real Debian system none of the 554 critical findings had a fix, and a check that always fails ends up switched off. When the check fails, devstack exits with code 5, which is kept separate from the exit codes for tool errors. Scanning is its own command and not a seventh phase.
Upgrades
devstack upgrade updates Debian packages from the host rather than through devstack-sync,
so the login user gains no new abilities. It passes --force-confold; without it, a Caddy
upgrade could restore the default Caddyfile and put the admin API back on TCP. It only lets
services that were already running restart, and masks any new units.
Secret scanning
devstack leaks scan runs gitleaks on the host over the git history plus a copy of the working
tree and staged files. The container can write every file that could change how gitleaks
behaves, so devstack replaces or bypasses all of them:
.gitleaks.toml.gitleaksignore- inline
gitleaks:allowcomments -diffentries in.gitattributes
gitleaks can hit a git error without reporting it, and devstack treats that as a failed scan.