Compare commits

...
Author SHA1 Message Date
branderson d58afa548a Assert the resolver survives, not just that names resolve
tests / confined (launch) (pull_request_target) Failing after 29s
tests / confined (conversation) (pull_request_target) Successful in 1m1s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (project) (pull_request_target) Successful in 3m3s
tests / confined (audit) (pull_request_target) Successful in 3m26s
tests / confined (static) (pull_request_target) Successful in 2m57s
tests / confined (proxy) (pull_request_target) Successful in 1m7s
tests / confined (share) (pull_request_target) Successful in 1m53s
tests / confined (shellcheck) (pull_request_target) Successful in 1m17s
tests / confined (remote) (pull_request_target) Successful in 2m40s
tests / confined (config) (pull_request_target) Successful in 4m44s
tests / privileged (pull_request_target) Successful in 4m52s
tests / runner-env (privileged) (pull_request_target) Successful in 48s
Four runtime tests resolve names through the DNS proxy. All of them would pass
on any arrangement that ends with a working resolver, however it got there, so
none of them says whether Docker's rules are where Docker put them.

One that reads the nat table back does. It also asserts the other half of the
condition: that nothing of dejima's is in there, which is what makes leaving
the table alone right rather than convenient.

The static guard is the pair of that, for a gate with no Docker: clearing a
table is right exactly when this script writes to it, so both directions fail
- a reset of a table it does not write, and a write to a table it does not
reset.
2026-09-11 22:47:16 -07:00
branderson ff8062622e Clear the table this script owns, and leave the daemon's alone
init-firewall.sh makes the whole egress decision in `filter`: seventeen
appends and three policies, and nothing anywhere else. It was clearing `nat`
and `mangle` as well, which took Docker's embedded-DNS rules with them - so
they had to be read out of a text dump first and pushed back through the CLI
afterwards, with two chain names written out by hand because a saved chain
declaration does not name the address it serves.

Scoped to what it owns, none of that is needed. The resolver stays where the
daemon put it.

`nat` is left deliberately rather than by omission, because it can reach the
decision this script makes: for a locally generated packet the order is
`nat OUTPUT` -> routing -> `filter OUTPUT`, so a DNAT rewrites the destination
before the allowlist is consulted. It is still the daemon's to hold. It built
this namespace and put the resolver in it, and a dockerd rewriting `nat` to
slip a destination past the allowlist could have skipped the filter container
altogether. Nothing else can write there: the session declares no NET_ADMIN,
and in here this script is the only thing that touches netfilter.

What the script relies on from that table is stated where it is relied on, and
two existing checks already refuse a namespace without it - dns-proxy.sh,
which runs first, and the self-check at the end of this file.
2026-09-11 22:47:16 -07:00
branderson 9ef51488ad Merge pull request 'Name the script that joins the forge's hosts into the allowlist' (#336) from release-pass-check into development
tests / confined (conversation) (pull_request_target) Successful in 1m1s
tests / confined (proxy) (pull_request_target) Successful in 1m8s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / confined (providers) (pull_request_target) Successful in 1m53s
tests / confined (remote) (pull_request_target) Successful in 2m39s
tests / confined (project) (pull_request_target) Successful in 3m4s
tests / confined (audit) (pull_request_target) Successful in 3m25s
tests / privileged (pull_request_target) Successful in 4m36s
tests / confined (shellcheck) (pull_request_target) Successful in 1m16s
tests / runner-env (confined) (pull_request_target) Successful in 49s
tests / confined (static) (pull_request_target) Successful in 2m59s
tests / confined (config) (pull_request_target) Successful in 4m43s
tests / runner-env (privileged) (pull_request_target) Successful in 46s
Reviewed-on: #336
Reviewed-by: branderson <brad@branderson.io>
2026-09-11 14:51:40 -07:00
branderson c637d1dee6 Name the script that joins the forge's hosts into the allowlist
tests / confined (conversation) (pull_request_target) Successful in 1m2s
tests / confined (proxy) (pull_request_target) Successful in 1m9s
tests / confined (providers) (pull_request_target) Successful in 2m0s
tests / confined (launch) (pull_request_target) Successful in 2m4s
tests / runner-env (confined) (pull_request_target) Successful in 52s
tests / confined (share) (pull_request_target) Successful in 1m59s
tests / confined (remote) (pull_request_target) Successful in 2m55s
tests / confined (shellcheck) (pull_request_target) Successful in 1m17s
tests / confined (project) (pull_request_target) Successful in 3m28s
tests / confined (audit) (pull_request_target) Successful in 4m16s
tests / confined (static) (pull_request_target) Successful in 4m6s
tests / privileged (pull_request_target) Successful in 4m35s
tests / runner-env (privileged) (pull_request_target) Successful in 43s
tests / confined (config) (pull_request_target) Successful in 7m43s
`entrypoint.sh` did that until the egress control moved to a container of its
own. It still exists and still runs; what it no longer does is this.

The claim around it is unchanged and is the point of the paragraph: a line
added to a forge manifest widens the egress boundary on the next run. Only the
mechanism named had gone stale.

Found by the documentation half of the release pass, which is what that half
is for.
2026-09-11 12:17:52 -07:00
branderson 6a0ec12d41 Merge pull request 'Add [mounts] read_write_per_project, so a centralized directory is not a shared one' (#335) from rw-per-project into development
tests / confined (conversation) (pull_request_target) Successful in 1m6s
tests / confined (providers) (pull_request_target) Successful in 1m59s
tests / confined (proxy) (pull_request_target) Successful in 1m13s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / confined (share) (pull_request_target) Successful in 1m53s
tests / confined (audit) (pull_request_target) Successful in 4m16s
tests / confined (static) (pull_request_target) Successful in 3m13s
tests / privileged (pull_request_target) Successful in 4m36s
tests / runner-env (privileged) (pull_request_target) Successful in 48s
tests / confined (project) (pull_request_target) Successful in 3m31s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (remote) (pull_request_target) Successful in 2m45s
tests / confined (config) (pull_request_target) Successful in 5m56s
Reviewed-on: #335
Reviewed-by: branderson <brad@branderson.io>
2026-09-11 11:18:31 -07:00
branderson 44bcee193f Recommend the list that does not make a shared pile
tests / runner-env (confined) (pull_request_target) Successful in 51s
tests / confined (share) (pull_request_target) Successful in 1m53s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / confined (project) (pull_request_target) Successful in 3m8s
tests / confined (launch) (pull_request_target) Successful in 1m57s
tests / confined (remote) (pull_request_target) Successful in 2m45s
tests / confined (audit) (pull_request_target) Successful in 3m27s
tests / confined (static) (pull_request_target) Successful in 2m50s
tests / privileged (pull_request_target) Successful in 4m36s
tests / confined (config) (pull_request_target) Successful in 4m45s
tests / runner-env (privileged) (pull_request_target) Successful in 46s
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (providers) (pull_request_target) Successful in 1m53s
tests / confined (proxy) (pull_request_target) Successful in 1m10s
Both places that told an operator to use read_write for design docs now name
read_write_per_project, and the reference table carries a row for it.

The thing that decides between them is one question, so the docs ask it:
should another project's session read what this one leaves there? For a build
cache, yes. For anything written to be read later as background, no - and a
shared one is a channel from any project into every other.

The read_write example is a toolchain cache now. It was ~/specs, which is the
case that belongs in the other list.
2026-09-10 23:07:52 -07:00
branderson c88240b4b6 Test the slice, the split, and every list that must refuse the root
Eight cases. The two that carry the feature are the mount itself - this
project's slice at the path named, and the whole directory NOT mounted
alongside it - and two workspaces getting two directories, which one launch
cannot show and which is the entire point.

The rest are the refusals: a per-project root named in read_write or in
readonly, a per-project entry overlapping a guarded store, a root that does
not exist, and the same path in two lists.

Mutation-checked: mounting the root instead of the slice fails two, removing
the root refusal fails three, and removing the existing-directory check fails
one.
2026-09-10 23:07:52 -07:00
branderson c6a0a3ff77 Add [mounts] read_write_per_project, so a centralized directory is not a shared one
docs/configuration.md recommended `read_write` for design docs and scratch
notes - anything an agent writes at a fixed host path to be read later. That
is the arrangement the share_dir split removed: every session seeing every
other project's, across projects. A spec is written to be read as background,
which makes it threat-model item 4 with nobody attacking anything.

An operator declares ~/specs; the container gets ~/specs, backed by
~/specs/projects/<slug> rather than by the whole thing. The property that
separates these lists from share_dir survives - a mount arrives at the path it
names, so "put specs in ~/specs" goes on working - and the pile does not.

Its own key rather than a marker on read_write, which is what makes it small:
a key that did not previously parse has nothing in it on the day it lands.
Nothing moves, nothing is stranded, no migration. read_write stays right for
what it is good at, since some writable mounts are meant to be shared.

Three things the wiring could not skip:

The briefing gets a sentence of its own. The existing one says these are
"host directories ... at their own paths", which is untrue of a sliced mount
and would tell a session it can see what it cannot.

The exit audit gets the SOURCE paths, not the container ones. That report
names what on the host a session could have written, and naming the root there
would claim a blast radius this feature exists to have narrowed.

Naming a per-project root's `projects` directory in readonly or read_write is
refused, with a message about the pile rather than about approval stores.
That refusal is also what catches the same path appearing in two lists, since
a path named in both is an ancestor of its own projects root - so there is no
separate duplicate check, because one could never fire.

dejima creates the slice and never the root: a path that is not there is a
typo, and creating it would turn the typo into a directory. The slice is
created on the launch path rather than where it is resolved, so composing a
briefing with --print-briefing still leaves nothing behind.
2026-09-10 23:07:52 -07:00
branderson e953bfa5fa Name the per-project layout for what it is, not for its first user
`share_projects_root` and `share_dir_for` describe a layout rather than a
share: a host directory sliced per project holds one `projects` subdirectory
and one directory per slug inside it. [core] share_dir was the first thing to
want that; [mounts] read_write_per_project is the second.

So the layout gets the generic names and share_dir keeps its own spelling of
them, which is what lets bin/dejima-share go on talking about a share rather
than about "a per-project root". One definition either way, which is this
file's stated reason for existing: two callers disagreeing about where a
project's directory is means an operator dropping a file where nothing reads
it.
2026-09-10 23:07:52 -07:00
branderson 5e0a390839 Merge pull request 'Run the egress filter in a container the session cannot reach' (#328) from filter-container into development
Reviewed-on: #328
Reviewed-by: branderson <brad@branderson.io>
2026-09-10 22:07:10 -07:00
branderson 88d54cab78 Merge pull request 'Let PID 1 signal the session, which it has not been able to since #330' (#334) from tini-kill into filter-container
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (proxy) (pull_request_target) Successful in 1m7s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / confined (providers) (pull_request_target) Successful in 1m53s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (remote) (pull_request_target) Successful in 2m36s
tests / confined (project) (pull_request_target) Successful in 2m57s
tests / confined (audit) (pull_request_target) Successful in 3m20s
tests / confined (static) (pull_request_target) Successful in 2m53s
tests / runner-env (privileged) (pull_request_target) Successful in 46s
tests / confined (config) (pull_request_target) Successful in 4m31s
tests / privileged (pull_request_target) Successful in 4m30s
Reviewed-on: #334
Reviewed-by: branderson <brad@branderson.io>
2026-09-10 21:47:38 -07:00
branderson d6f7f8c9d7 Read the agent socket from the session, which is the only process that has it
tests / confined (conversation) (pull_request_target) Successful in 1m5s
tests / confined (proxy) (pull_request_target) Successful in 1m11s
tests / confined (providers) (pull_request_target) Successful in 2m1s
tests / runner-env (confined) (pull_request_target) Successful in 51s
tests / confined (share) (pull_request_target) Successful in 1m58s
tests / confined (remote) (pull_request_target) Successful in 2m50s
tests / confined (project) (pull_request_target) Successful in 3m16s
tests / confined (launch) (pull_request_target) Successful in 2m3s
tests / confined (shellcheck) (pull_request_target) Successful in 1m14s
tests / confined (audit) (pull_request_target) Successful in 3m36s
tests / confined (static) (pull_request_target) Successful in 2m58s
tests / privileged (pull_request_target) Successful in 4m33s
tests / confined (config) (pull_request_target) Successful in 4m50s
tests / runner-env (privileged) (pull_request_target) Successful in 46s
The last /proc/1/environ read, and the one I left when I repointed the other
four - on the reasoning that tini's environment is the container's, so
SSH_AUTH_SOCK would be in it.

Wrong about this variable. Docker does not pass it: entrypoint.sh creates it,
by starting an agent, in a process that is tini's CHILD. So under `init: true`
PID 1 is the one process in the container that has never heard of it, and the
exec got an empty socket path and an ssh-add that found no agent.

Which is the whole lesson of this branch arriving twice: every environment
read in this file meant the SESSION's environment, and PID 1 only answered
correctly while it happened to be the session.
2026-09-10 21:37:34 -07:00
branderson 881e6343e5 Run an init in the fixtures, so the suite has a tini that can fail
tests / confined (audit) (pull_request_target) Successful in 3m26s
tests / confined (config) (pull_request_target) Successful in 4m37s
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (launch) (pull_request_target) Successful in 2m1s
tests / confined (project) (pull_request_target) Successful in 3m6s
tests / confined (providers) (pull_request_target) Successful in 1m55s
tests / confined (proxy) (pull_request_target) Successful in 1m11s
tests / confined (remote) (pull_request_target) Successful in 2m44s
tests / confined (share) (pull_request_target) Successful in 1m50s
tests / privileged (pull_request_target) Failing after 4m51s
tests / confined (static) (pull_request_target) Successful in 2m48s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / runner-env (confined) (pull_request_target) Successful in 50s
tests / runner-env (privileged) (pull_request_target) Successful in 43s
Nothing in this file ran one. Every container started with a bare `docker run`,
so PID 1 was the session itself and there was nothing forwarding signals to
it - which is how a floor that left tini unable to signal its own child went
green through a privileged run.

I knew the fixtures differed from production here: when a capability
assertion read /proc/1/status, I made the assertion PID-1-independent rather
than making the fixture faithful, because that was the smaller change. The
smaller change left the difference in place, and this is what it cost.

The session container gets --init, matching `init: true`. Four reads of
/proc/1/environ meant the SESSION's environment and now say so - under an init
PID 1 holds the environment Docker gave the container, which still carries the
empty ANTHROPIC_* pair one of them asserts the entrypoint unset, so they would
have started passing for the wrong reason.

And the failure itself, reproduced: `docker kill --signal=WINCH` delivers to
PID 1 through the same door the kernel uses, so the container must still be
running afterwards and the session must still be in it. Its own pair, because
a failure here would otherwise take every later test in the file with it.
2026-09-10 20:49:50 -07:00
branderson 668c3feccf Let PID 1 signal the session, which it has not been able to since #330
A tmux split ends the session with:

  [FATAL tini (1)] Unexpected error when forwarding signal: 'Operation not
  permitted'

`init: true` makes PID 1 an init that forwards every signal it receives to its
child. The entrypoint changes uid in place before exec'ing the session, so
that child's real AND saved uids are the sandbox user's while tini is uid 0.
kill(2) permits a signal only with CAP_KILL or a uid match, and there is
neither - so every forwarded signal is EPERM, and tini treats a failed forward
as fatal. PID 1 exiting ends the container.

The signal that arrives in practice is SIGWINCH: the kernel sends it to the
pty's foreground process group on any terminal resize, tini included. So
resizing a pane kills the session.

Measured in the running container: PID 1 is uid 0 holding
chown,dac_override,fowner,setgid,setuid,setpcap, and its child is uid
1000/1000/1000/1000.

KILL was in this list for `dejima-allow --container`, which signals dnsmasq.
That reason moved to the filter container with dnsmasq and the capability went
with it - and this second reason, which had been quietly carried by the same
line for as long as `init: true` has been set, went unnoticed.
2026-09-10 20:49:50 -07:00
branderson 8fb4a4d39b Merge pull request 'Take either half of the pair, because a briefing hands over the filter's id' (#332) from allow-pair into filter-container
tests / confined (conversation) (pull_request_target) Successful in 1m2s
tests / confined (proxy) (pull_request_target) Successful in 1m6s
tests / confined (share) (pull_request_target) Successful in 1m49s
tests / confined (shellcheck) (pull_request_target) Successful in 1m12s
tests / confined (remote) (pull_request_target) Successful in 2m32s
tests / confined (config) (pull_request_target) Successful in 4m27s
tests / confined (providers) (pull_request_target) Successful in 1m49s
tests / runner-env (confined) (pull_request_target) Successful in 49s
tests / confined (project) (pull_request_target) Successful in 2m57s
tests / confined (audit) (pull_request_target) Successful in 3m15s
tests / confined (static) (pull_request_target) Successful in 2m45s
tests / privileged (pull_request_target) Successful in 4m26s
tests / runner-env (privileged) (pull_request_target) Successful in 47s
Reviewed-on: #332
Reviewed-by: branderson <brad@branderson.io>
2026-09-10 19:47:33 -07:00
branderson 3b6c5c016f Merge pull request 'Fixes from the review of the filter-container stack' (#333) from review-fixes into allow-pair
tests / confined (conversation) (pull_request_target) Successful in 1m5s
tests / confined (proxy) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 49s
tests / confined (remote) (pull_request_target) Successful in 2m42s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / confined (project) (pull_request_target) Successful in 3m3s
tests / confined (audit) (pull_request_target) Successful in 3m23s
tests / privileged (pull_request_target) Successful in 4m15s
tests / confined (launch) (pull_request_target) Successful in 1m54s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / confined (share) (pull_request_target) Successful in 1m50s
tests / confined (static) (pull_request_target) Successful in 2m50s
tests / confined (config) (pull_request_target) Successful in 4m36s
tests / runner-env (privileged) (pull_request_target) Successful in 45s
Reviewed-on: #333
Reviewed-by: branderson <brad@branderson.io>
2026-09-10 01:55:26 -07:00
branderson 0a6b55b5b9 Give the privileged job the compose plugin it was missing
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (proxy) (pull_request_target) Successful in 1m7s
tests / confined (providers) (pull_request_target) Successful in 1m52s
tests / confined (launch) (pull_request_target) Successful in 1m57s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / confined (project) (pull_request_target) Successful in 3m7s
tests / runner-env (privileged) (pull_request_target) Successful in 45s
tests / runner-env (confined) (pull_request_target) Successful in 51s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / confined (remote) (pull_request_target) Successful in 2m45s
tests / confined (audit) (pull_request_target) Successful in 3m32s
tests / confined (static) (pull_request_target) Successful in 2m55s
tests / privileged (pull_request_target) Successful in 4m23s
tests / confined (config) (pull_request_target) Successful in 4m44s
`docker compose` is a CLI plugin, so without it the subcommand does not exist
at all - which is why the compose-file test failed there with "unknown
shorthand flag: 'f'" and a usage listing with no compose in it.

This job already installs its own docker CLI and buildx by hand, from
download.docker.com and github.com. compose comes from the same release host
as buildx, so this needs no allowlist entry - and the privileged tier has no
per-pool allowlist in any case, since its jobs run in the host network
namespace. Nothing outside this repository had to change.

Checked rather than assumed, the same way buildx is: an error page chmods as
well as a binary does, and here the symptom would be a test that skips rather
than one that fails. The asset is named for `uname -m`, like the CLI tarball
and unlike buildx, which uses the Debian architecture name.

What it buys is that CI parses the compose file at all. Every launch on a real
host goes through `docker compose`, and no job had ever run one.
2026-09-10 00:35:50 -07:00
branderson e250c705ed Skip the compose parse where there is no compose, and say what that means
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (launch) (pull_request_target) Successful in 2m4s
tests / runner-env (confined) (pull_request_target) Successful in 49s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / confined (audit) (pull_request_target) Successful in 3m34s
tests / confined (static) (pull_request_target) Successful in 2m54s
tests / confined (proxy) (pull_request_target) Successful in 1m15s
tests / confined (providers) (pull_request_target) Successful in 1m55s
tests / confined (share) (pull_request_target) Successful in 1m55s
tests / confined (remote) (pull_request_target) Successful in 2m50s
tests / confined (project) (pull_request_target) Successful in 3m14s
tests / privileged (pull_request_target) Successful in 4m21s
tests / runner-env (privileged) (pull_request_target) Successful in 44s
tests / confined (config) (pull_request_target) Successful in 4m50s
The privileged runner has the docker CLI and a socket and no compose plugin,
so the test I added to parse the compose file failed there on `unknown
shorthand flag: 'f'`. It skips when the plugin is absent.

A test that always skips is worth little, so the skip says the thing that
matters more than the test does: no CI job runs `docker compose` at all, which
means no CI job exercises the launch path bin/dejima actually takes. Every
container runtime.bats starts, it starts with plain `docker run`.

That is a coverage gap this test cannot close from inside CI. It closes it on
any host that has the plugin, which is every host a session is launched from.
2026-09-09 23:59:32 -07:00
branderson 2cbf1a414c Parse the compose file in a test, since nothing ever had
tests / confined (conversation) (pull_request_target) Successful in 1m1s
tests / confined (providers) (pull_request_target) Successful in 1m52s
tests / runner-env (confined) (pull_request_target) Successful in 49s
tests / confined (remote) (pull_request_target) Successful in 2m45s
tests / confined (shellcheck) (pull_request_target) Successful in 1m12s
tests / confined (project) (pull_request_target) Successful in 3m9s
tests / confined (proxy) (pull_request_target) Successful in 1m9s
tests / confined (launch) (pull_request_target) Successful in 1m56s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / confined (audit) (pull_request_target) Successful in 3m29s
tests / confined (static) (pull_request_target) Successful in 2m52s
tests / runner-env (privileged) (pull_request_target) Successful in 44s
tests / privileged (pull_request_target) Failing after 4m16s
tests / confined (config) (pull_request_target) Successful in 4m38s
Nothing in this repo runs `docker compose` against a real daemon: runtime.bats
builds with plain `docker build`, and every launch test elsewhere stubs docker
entirely. A compose file that stopped interpolating would therefore reach an
operator before it reached a test, and it would present as a failing BUILD,
because `build` and `run` both parse the whole file first.

Which is how the claim that `network_mode` does not affect the build came to
be reasoned rather than observed. It is observed now, on the privileged
runner, along with what the default resolves to when nothing supplies a
namespace to join.

Every name the file interpolates without a default is supplied, read out of
the file rather than listed here. Two shapes and both matter: `${VAR:?}` fails
the parse outright, and a bare `${VAR}` resolves to the empty string, which is
a volume line with no source - `SANDBOX_SHARE_DIR` is one of those, and
supplying only the first kind would have failed on it.

Run by hand, `docker compose build sandbox` fails on four of those today. That
is correct - bin/dejima sets all of them well before it builds - and it is
exactly why this had never been checked.
2026-09-09 21:56:00 -07:00
branderson 3100a5f454 Check that a variable the filter container is given is one it can receive
tests / confined (static) (pull_request_target) Successful in 3m11s
tests / confined (config) (pull_request_target) Successful in 5m43s
tests / privileged (pull_request_target) Successful in 4m20s
tests / confined (audit) (pull_request_target) Successful in 4m15s
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (launch) (pull_request_target) Successful in 1m58s
tests / confined (project) (pull_request_target) Successful in 3m28s
tests / confined (providers) (pull_request_target) Successful in 1m57s
tests / confined (proxy) (pull_request_target) Successful in 1m12s
tests / confined (remote) (pull_request_target) Successful in 2m33s
tests / confined (share) (pull_request_target) Successful in 1m53s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / runner-env (confined) (pull_request_target) Successful in 1m13s
tests / runner-env (privileged) (pull_request_target) Successful in 45s
The drift guard derived the names the firewall path reads and asserted each
appears as `-e NAME` on the filter container's run line. That catches a script
that starts reading a new variable, and misses the other half of the same
failure: `-e NAME` takes its value from the launcher's environment, so a name
that is assigned and never exported passes an empty one.

The filter container then allowlists less than it was told to, and what an
operator sees is a domain they approved being unreachable, with nothing
pointing here.

Not hypothetical - `export DEJIMA_FORGE_HOSTS` had to be added by hand when
the filter container was introduced, because until then that variable had only
ever needed to reach the sandbox as `-e NAME=value`, which carries its own
value. Nothing would have noticed its absence.

All nine are exported today, so this guards the next one. Continuations are
flattened before matching, and `export` is matched anywhere on a line rather
than at its start, because two of the nine are exported after a `;` on the
line that assigns them - a form that a start-anchored check reports as missing
and would have made this fail on correct code.
2026-09-09 20:25:51 -07:00
branderson b32c8921c2 Fail closed when nothing supplies a namespace to join
`network_mode: ${SANDBOX_NETNS_CONTAINER:-bridge}` fell back to a real network
with no filter on it. Only a `docker compose` invocation by hand reaches that
default - bin/dejima always exports the variable - but what it produced there
was a working sandbox with unfiltered egress, and nothing about it looked
wrong. `none` fails the same case visibly instead.

The static guard is scoped to the key and the value together. Excluding every
`network_mode` line would hide a real forge name written on one, and excluding
the bare word `none` - which is also a shipped forge - would hide it anywhere
in the file. Checked in all three directions.
2026-09-09 20:25:51 -07:00
branderson e151faf4ec Read a network's creation time in whatever shape Docker rendered it
The reconciler reaped filter containers and never a single network, which is
the half the address pool depends on.

`Created` is not the same type on the two structs it asks about: a string on a
container, a time.Time on a network. A Go template prints the second through
String(), which appends a timezone NAME, and date(1) refuses that outright -
so `_epoch_age` returned nonzero, `|| continue` fired, and every network
looked too new to touch. Forever.

That is the same failure the container half had already moved off
`{{.CreatedAt}}` to avoid. Its comment even claimed every caller here read RFC
3339, which was true of one of them - assuming the format is what broke this,
so the fix stops assuming rather than assuming a different one. A trailing
timezone name is stripped, which leaves RFC 3339 untouched and makes this
independent of which struct a caller asked about.

An unparseable value still yields no age rather than a huge one, so the
failure stays "nothing was reaped" and never becomes "everything was".

The stub answered both queries in the container's format, which is why the
test asserting `network rm` passed against code that never issued one. It
answers each in the shape Docker really uses, and reverting the fix now turns
that test red.
2026-09-09 20:25:36 -07:00
branderson 251beaab45 Assert which container each half of the command reaches
tests / confined (conversation) (pull_request_target) Successful in 56s
tests / confined (proxy) (pull_request_target) Successful in 1m4s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / confined (launch) (pull_request_target) Successful in 1m57s
tests / runner-env (confined) (pull_request_target) Successful in 51s
tests / confined (remote) (pull_request_target) Successful in 2m46s
tests / confined (audit) (pull_request_target) Successful in 3m32s
tests / privileged (pull_request_target) Successful in 4m3s
tests / confined (config) (pull_request_target) Successful in 4m44s
tests / confined (share) (pull_request_target) Successful in 1m57s
tests / confined (shellcheck) (pull_request_target) Successful in 1m16s
tests / confined (project) (pull_request_target) Successful in 3m12s
tests / confined (static) (pull_request_target) Successful in 3m2s
tests / runner-env (privileged) (pull_request_target) Successful in 41s
On the calls rather than the messages: which container the ipset add and the
reachability probe run in is the whole point, and a message could name either
while the exec went elsewhere.

Both directions - the filter's id accepted and resolved to its session, and a
container that is neither half refused with somewhere to go instead.

Mutation-checked by removing the filter branch, and by leaving each of the two
execs pointed at the wrong container in turn.
2026-09-09 19:02:57 -07:00
branderson af6f0e4aa7 Take either half of the pair, because a briefing hands over the filter's id
A session asked for its own container id reads /etc/hostname, and Docker names
a container that joined another's network namespace after the container it
joined. So what a session reads there - and what every briefing substitutes
into the `dejima-allow --container` line it tells the agent to hand over - is
the FILTER container's id.

Given that id, dejima-allow found no `container:` in its NetworkMode and
refused, telling the operator to relaunch a session that was working fine.
That is the one command every briefing advertises, failing on the id the
briefing itself supplied.

Either half is accepted now, and the other derived: a session container names
its filter directly, and a filter container is matched against the running
container in its namespace. The allowlist change still goes to the filter and
the reachability probe still runs in the session, because those are facts
about where dnsmasq lives and about whose reachability is being claimed.

A container that is neither gets told what to do instead rather than to
relaunch something that may already be gone.

The renderer's comment claimed /etc/hostname is "the container's own ID",
which is what made this easy to miss. It says what the value is.
2026-09-09 19:02:57 -07:00
branderson 3a6c233a0f Merge pull request 'Reclaim the filter containers an interrupted launch leaves behind' (#331) from reconcile into filter-container
tests / confined (conversation) (pull_request_target) Successful in 1m2s
tests / confined (proxy) (pull_request_target) Successful in 1m9s
tests / confined (shellcheck) (pull_request_target) Successful in 1m15s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (remote) (pull_request_target) Successful in 2m38s
tests / confined (project) (pull_request_target) Successful in 3m1s
tests / confined (audit) (pull_request_target) Successful in 3m22s
tests / privileged (pull_request_target) Successful in 4m18s
tests / confined (static) (pull_request_target) Successful in 3m8s
tests / confined (config) (pull_request_target) Successful in 4m34s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
Reviewed-on: #331
Reviewed-by: branderson <brad@branderson.io>
2026-09-09 18:40:33 -07:00
branderson 924dd4ed51 Test each branch that decides not to remove something
tests / confined (conversation) (pull_request_target) Successful in 1m2s
tests / confined (proxy) (pull_request_target) Successful in 1m7s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / confined (launch) (pull_request_target) Successful in 1m59s
tests / runner-env (confined) (pull_request_target) Successful in 51s
tests / confined (share) (pull_request_target) Successful in 1m55s
tests / confined (remote) (pull_request_target) Successful in 2m48s
tests / confined (shellcheck) (pull_request_target) Successful in 1m15s
tests / confined (project) (pull_request_target) Successful in 3m12s
tests / confined (audit) (pull_request_target) Successful in 3m34s
tests / confined (static) (pull_request_target) Successful in 2m58s
tests / privileged (pull_request_target) Successful in 4m15s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
tests / confined (config) (pull_request_target) Successful in 4m47s
Every one of these tests would pass against a reconciler that did nothing at
all, so the first asserts the mechanism fires and the rest assert what it
spares: a filter container with a session still in its namespace, and one
younger than the grace. Both are the cases where being wrong costs somebody
else's running agent.

Plus the two properties that are not about which container: the removal is
announced, because a leak that is cleaned up silently is a leak nobody learns
they are producing; and a docker that cannot answer any of it does not refuse
the launch.

Mutation-checked by removing the call, the joiner check, the grace, the
announcement, and the `|| true` in turn - each fails the test that names it.
2026-09-09 18:07:16 -07:00
branderson 271d7843fe Reclaim the filter containers an interrupted launch leaves behind
Step 6 of #305, and the last. A launch removes its own pair from the exit
trap, which covers every exit the trap reaches; a SIGKILL, a restarted host or
a docker daemon restart reach none of them, and each leaves a filter container
holding a network open.

The leak is inert - a filter container filters a namespace nothing is in - so
this is hygiene rather than a second control. What makes it worth doing is the
address pool: Docker carves a bounded number of networks out of its default
pool, and exhausting it fails a launch with an error about address space that
says nothing about the cause.

A candidate is reaped when nothing is in its namespace AND it is older than
the window in which a pair is still being built. That window is real: between
`docker run` for the filter container and `docker compose run` for the
session, a perfectly healthy filter container has no joiner, for as long as
the firewall takes to come up. Reaping one out from under a concurrent launch
costs that launch; waiting costs one more pass.

Ages come from `inspect`'s `.Created` rather than `ps --format {{.CreatedAt}}`,
which prints a trailing timezone NAME that date(1) refuses outright. Measured,
not assumed - and the refusal would have been silent, leaving every candidate
looking newly made and nothing ever reaped. An unparseable timestamp yields no
age rather than a huge one, so that failure stays "nothing was reaped" instead
of becoming "everything was".

Networks need less care, because `docker network rm` refuses one that still
has an endpoint, but they get the same grace: a network is created a moment
before its filter container attaches, and that moment is a launch a concurrent
one could otherwise pull the network out from under.

Never fatal, and it runs before the launch makes anything of its own. A daemon
that cannot answer this is about to fail the launch a few lines down for a
reason worth reporting, and a tidy-up pass should not be what reports it.
2026-09-09 18:07:16 -07:00
branderson 9b6ad238f3 Merge pull request 'Take the network capabilities off the container that runs the session' (#330) from caps-split into filter-container
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (proxy) (pull_request_target) Successful in 1m11s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / confined (share) (pull_request_target) Successful in 1m51s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / runner-env (confined) (pull_request_target) Successful in 46s
tests / confined (remote) (pull_request_target) Successful in 2m38s
tests / confined (project) (pull_request_target) Successful in 2m59s
tests / confined (audit) (pull_request_target) Successful in 3m23s
tests / confined (static) (pull_request_target) Successful in 2m55s
tests / privileged (pull_request_target) Successful in 4m32s
tests / confined (config) (pull_request_target) Successful in 4m35s
tests / runner-env (privileged) (pull_request_target) Successful in 50s
Reviewed-on: #330
Reviewed-by: branderson <brad@branderson.io>
2026-09-09 17:33:58 -07:00
branderson 19fb87c1f8 Assert the refusal, not just the declaration
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m7s
tests / confined (launch) (pull_request_target) Successful in 1m23s
tests / confined (providers) (pull_request_target) Successful in 1m53s
tests / confined (shellcheck) (pull_request_target) Successful in 1m14s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (share) (pull_request_target) Successful in 1m49s
tests / confined (remote) (pull_request_target) Successful in 2m37s
tests / confined (project) (pull_request_target) Successful in 3m1s
tests / confined (audit) (pull_request_target) Successful in 3m19s
tests / confined (static) (pull_request_target) Successful in 2m48s
tests / privileged (pull_request_target) Successful in 4m20s
tests / confined (config) (pull_request_target) Successful in 4m30s
tests / runner-env (privileged) (pull_request_target) Successful in 43s
The claim the whole arrangement rests on needs a real kernel to settle, so
runtime.bats asks it directly: root in the session container running
`iptables -F` and `ipset list` must be refused, with the filter read back
afterwards to show there were rules there to flush - a negative that would
look identical against an empty table.

As root deliberately. `node cannot run iptables directly` beside it asserts
the unprivileged case, and would pass just as well on a container that held
the capability and a user who did not.

The sysctl gets the same treatment: declared on the filter container, read
back from the session container, because the session container is where it
has to be true.

Statically, both floors are asserted in both directions - each of NET_ADMIN,
NET_RAW and KILL absent from the session's list and present in the filter's.
One direction alone is satisfied by a launch that has no filter container to
hold them either.

Two existing guards asserted the old shape and are repointed rather than
loosened: the capability floor no longer requires NET_ADMIN in compose, and
the bind-:443 precondition reads the sysctl where it is set.
2026-09-09 14:49:20 -07:00
branderson 75eb427e62 Take the network capabilities off the container that runs the session
Step 4 of #305, and what the previous three were for. The session container
declares no network capability at all - not NET_ADMIN, not NET_RAW. It sits
inside a namespace the filter container owns and has already installed the
rules in, and capabilities are per process, so uid 0 in there is refused by
the kernel rather than by policy.

KILL goes with dnsmasq. It was only ever there so `dejima-allow --container`
could signal it, and dnsmasq is in the filter container - so bin/dejima
declares it beside the daemon that needs it.

The sysctl goes for the same reason: net.ipv4.ip_unprivileged_port_start is a
property of a network namespace, and the session container does not own the
one it is in. Set once, by the container that does, and it applies to the
session container that joins it - which is where the credential proxy's TLS
terminator binds :443 as the unprivileged sandbox user.

That leaves the session container with what its root phase actually does
before the session starts: write and chown files, drop privilege once, and
spend SETPCAP taking the rest away.
2026-09-09 14:49:20 -07:00
branderson aa3a198e26 Say what the arrangement is, not what it stopped being
tests / confined (conversation) (pull_request_target) Successful in 1m1s
tests / confined (proxy) (pull_request_target) Successful in 1m6s
tests / confined (share) (pull_request_target) Successful in 1m47s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / confined (shellcheck) (pull_request_target) Successful in 1m14s
tests / runner-env (confined) (pull_request_target) Successful in 48s
tests / confined (remote) (pull_request_target) Successful in 2m34s
tests / confined (project) (pull_request_target) Successful in 2m58s
tests / confined (audit) (pull_request_target) Successful in 3m18s
tests / confined (static) (pull_request_target) Successful in 2m48s
tests / privileged (pull_request_target) Successful in 4m21s
tests / confined (config) (pull_request_target) Successful in 4m25s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
A pass over the prose this branch added. Documentation is a description of
current state, and several passages had been written as a diff against the
previous one: "it runs in the filter container now rather than", "two things
follow that were previously arguments", "concurrent sessions no longer share
a link layer". A reader arriving today has no previous arrangement to hold
these against.

remote-access.md's sentence needed nothing at all - it was already about which
host address a sandbox can reach, which is unchanged, and the clause about
where the rule lives was history added to a fact.

Two comments in docker-compose.yml were worse than stale phrasing: the
capability floor still described this container as running the firewall and
holding a root log daemon, neither of which is true of it.
2026-09-09 14:14:22 -07:00
branderson 1de83f8a16 Read the push grant's announcement from the container that prints it
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m4s
tests / confined (providers) (pull_request_target) Successful in 1m49s
tests / confined (share) (pull_request_target) Successful in 1m47s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / runner-env (confined) (pull_request_target) Successful in 44s
tests / confined (remote) (pull_request_target) Successful in 2m32s
tests / confined (project) (pull_request_target) Successful in 2m54s
tests / confined (audit) (pull_request_target) Successful in 3m17s
tests / confined (static) (pull_request_target) Successful in 3m4s
tests / privileged (pull_request_target) Successful in 4m20s
tests / confined (config) (pull_request_target) Successful in 4m27s
tests / runner-env (privileged) (pull_request_target) Successful in 45s
The one test left failing on the privileged runner. init-firewall.sh prints
"ALLOW_GITHUB_PUSH=1: opening port 22", and init-firewall.sh is what moved -
so the poll was watching the session container's log for a line that is now
written to the filter container's.

The connect check above it stays where it is, for the opposite reason:
reachability is a claim about the session, and it is the half of this test
that would still pass on a grant nothing ever announced.

Checked for the rest of the class rather than fixing the one CI named: of
every string this suite asserts on, exactly one is printed by the firewall
stack, and this was it.
2026-09-09 00:20:02 -07:00
branderson bd96919504 Build the pair in runtime.bats, since a session container alone has no firewall
tests / confined (conversation) (pull_request_target) Successful in 1m25s
tests / confined (proxy) (pull_request_target) Successful in 1m31s
tests / confined (share) (pull_request_target) Successful in 2m8s
tests / confined (providers) (pull_request_target) Successful in 2m12s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 46s
tests / confined (remote) (pull_request_target) Successful in 2m51s
tests / confined (project) (pull_request_target) Successful in 3m14s
tests / confined (audit) (pull_request_target) Successful in 3m34s
tests / confined (static) (pull_request_target) Successful in 2m40s
tests / confined (config) (pull_request_target) Successful in 4m43s
tests / privileged (pull_request_target) Failing after 9m13s
tests / runner-env (privileged) (pull_request_target) Successful in 45s
The privileged job failed on this branch: fifteen of fifty-one, every one a
firewall, DNS or logging test. The cause is the change itself and I should
have done this with it. entrypoint.sh stopped bringing the egress control up,
because the container beside it does - and every fixture here starts one
container.

start_pair builds what bin/dejima builds: a filter container that owns the
network namespace, waited for on the same readiness marker the launcher waits
for, and a session container that joins it. Twenty-two fixtures go through it.
Both capability floors come from the code that declares each - the session's
from docker-compose.yml as before, the filter's from bin/dejima's own run -
so neither is a copy that can drift.

The environment goes to both halves, which is deliberately not what bin/dejima
does. A fixture that varies ALLOW_GITHUB_PUSH or a forge host is varying what
the FIREWALL does, and making twenty-two call sites each declare which half
their variables belong to would be twenty-two chances to send one to the wrong
container - a mistake that fails by passing, since a firewall told nothing
simply allowlists less.

Six tests reach into the container the egress control is in rather than the
one the session is in: ip6tables, the ipsets, the dnsmasq signal, ulogd2's
user, and the log shipper. dexec_filter is that, and the three per-test
fixtures that inspect dnsmasq config get a filter name beside their container
name.

Two fixtures stay single deliberately and say so: one must refuse to start
without SETPCAP, the other must abort at the transport check, which is well
before anything needs a network.

Teardown had to learn about both. The per-test sweep is anchored on the run
suffix, so filter names end with it - which makes the file-wide filter match
too, and removing that after the first test would take the network namespace
out from under every later one.
2026-09-08 23:35:23 -07:00
branderson a721e3d1fb Snapshot the registry on the session's own run, not on every docker call
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m8s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / privileged (pull_request_target) Failing after 2m37s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / confined (share) (pull_request_target) Successful in 1m49s
tests / confined (project) (pull_request_target) Successful in 3m19s
tests / confined (audit) (pull_request_target) Successful in 4m9s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / confined (remote) (pull_request_target) Successful in 2m27s
tests / confined (static) (pull_request_target) Successful in 2m44s
tests / confined (config) (pull_request_target) Successful in 5m43s
A launch makes several docker calls now - a build, this launch's filter
container, and two removals from the exit trap. This stub snapshotted on each
and cleared the previous one first, so the last call won, and the two removals
run after the registry entry is gone. What the test then read was an empty
directory.

Matched on the compose run, which is the call the entry is meant to exist
during, and the one run_line already identifies in this file.
2026-09-04 15:52:36 -07:00
branderson d7e4c6be0a Describe the pair, since the boundary is no longer one container
tests / confined (conversation) (pull_request_target) Successful in 53s
tests / confined (proxy) (pull_request_target) Successful in 1m1s
tests / confined (share) (pull_request_target) Successful in 1m45s
tests / confined (providers) (pull_request_target) Successful in 1m47s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 46s
tests / confined (remote) (pull_request_target) Failing after 2m35s
tests / privileged (pull_request_target) Failing after 2m42s
tests / confined (project) (pull_request_target) Successful in 3m9s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (audit) (pull_request_target) Successful in 4m4s
tests / confined (static) (pull_request_target) Successful in 3m50s
tests / confined (config) (pull_request_target) Successful in 6m59s
security.md gains the arrangement and what follows from it: the two claims
that were previously arguments - no window between an interface and a filter,
and a killed filter container leaving loopback alone rather than open egress -
are now properties of how the pair is built.

development.md's file table names the three new scripts and stops saying the
entrypoint brings the firewall up. remote-access.md's bridge-gateway rule is
unchanged in what it permits and changed in who can alter it, which is worth
one clause rather than a rewrite.
2026-09-04 15:52:17 -07:00
branderson 2c31d83a49 Test how a launch is arranged, and make CI run the suite that does
test/launch.bats: the containers a launch starts, in what order, on what
network, and what it takes down. Against a stubbed docker, so the ordering and
the flags are the subject - whether the filter filters stays runtime.bats's
question and needs a real one.

The load-bearing one is the environment test. The sandbox gets its environment
from docker-compose.yml; the filter container is started with `docker run` and
gets nothing not named on that command line. So a firewall script that starts
reading a new variable does not fail - it reads an empty one and allowlists
less than it was told to, which presents as an approved domain being
unreachable rather than as anything about this. Derived from the scripts.

Adding a suite turned up that the CI matrix is enumerated by hand while
run-confined.sh discovers suites from the directory, so a suite added to the
tree runs locally and never runs in CI: a green set of checks covering less
than it appears to, with nothing watching for it. Asserted now in both
directions, reading run-confined.sh's own privileged list rather than
restating which suites are confined.

The step 2 guard flips: the session's entrypoint must NOT bring the firewall
up, and the filter container's must, with the readiness marker after it. Three
stub dockers in project.bats needed teaching that a session shares a filter
container's namespace, and one new test covers the refusal when it does not.
2026-09-04 15:52:17 -07:00
branderson 077cd241a7 Point dejima-allow at the container the allowlist is now in
The dnsmasq and the ipsets moved with the filter, so every mutation goes
there. The reachability probe stays in the session's container, because that
is the container whose reachability this command claims to have changed - one
run in the filter container would pass on an arrangement where the session
still could not reach anything.

Derived from HostConfig.NetworkMode rather than recorded: Docker already knows
which container holds the namespace, because joining one is how the pair is
built. A session that shares no namespace is told to relaunch, rather than
finding out through a docker exec that fails somewhere inside a heredoc.
2026-09-04 15:52:04 -07:00
branderson 4e47c30457 Run the egress filter in a container the session cannot reach
Step 3 of #305, and the one that flips the arrangement. A launch starts two
containers now: a filter container that owns the network namespace and
installs the packet filter, and the sandbox, which joins that namespace rather
than getting one of its own.

Capabilities are per process, not per namespace, so a container that declares
no network capability cannot alter a filter installed in a namespace it is
inside of. Measured on the host rather than reasoned: iptables and ipset both
answer a joiner without NET_ADMIN with Operation not permitted.

The ordering is what this buys today. The namespace has its rules before
anything is created in it, so the window where a session holds an interface
and no filter does not exist rather than being bounded by how fast an
entrypoint runs. filter-entrypoint.sh writes a readiness marker only on the
success path; bin/dejima waits for it and refuses the launch with the filter
container's own output when it never comes.

The network is per launch because it has to be: dns-proxy.sh forwards to
Docker's embedded resolver, which exists only on a user-defined network.
Concurrent sessions no longer sharing a link layer comes with that.

The filter container runs the base image, never a project's derived one. It is
the privileged half of the pair and has no use for a project's dependencies.

Two corrections to the session container. It no longer brings the firewall up,
because the container beside it did and this one declares nothing it would
take. And it points its own /etc/resolv.conf at the namespace's resolver:
that file is per container even when the namespace is shared, so dns-proxy.sh
repointing the filter container's says nothing about this one - and left
alone, every lookup would go around dnsmasq while the packet filter still
held, so the DNS allowlist would apply to nothing and nothing would fail.

The sandbox still declares NET_ADMIN. Narrowing both floors is step 4.
2026-09-04 15:52:04 -07:00
branderson 5b7250f8f0 Merge pull request 'Extract the egress control into a script of its own' (#327) from firewall-up into development
Reviewed-on: #327
Reviewed-by: branderson <brad@branderson.io>
2026-09-04 14:22:36 -07:00
branderson f1f2fe4b02 Point the drift guards at the files, and cover the fragments
tests / confined (conversation) (pull_request_target) Successful in 52s
tests / confined (proxy) (pull_request_target) Successful in 1m3s
tests / confined (share) (pull_request_target) Successful in 1m41s
tests / confined (providers) (pull_request_target) Successful in 1m43s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 44s
tests / confined (remote) (pull_request_target) Successful in 2m29s
tests / confined (project) (pull_request_target) Successful in 2m50s
tests / confined (audit) (pull_request_target) Successful in 3m11s
tests / confined (static) (pull_request_target) Successful in 2m44s
tests / privileged (pull_request_target) Successful in 3m54s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (config) (pull_request_target) Successful in 4m39s
Three static tests read entrypoint.sh for things that now live in
firewall-up.sh and caps-lib.sh. They caught the move, which is what they are
for; repointed rather than loosened.

Two new ones. The entrypoint must still call firewall-up.sh, unguarded - an
extraction that left nothing calling it is a sandbox with no egress control,
and every other check here would keep passing because they all read the files
it moved to. `|| true`, an `if` and a background `&` each fail it too, since
each turns a firewall that failed to come up into a session that runs anyway.

And shellcheck now covers sourced fragments under docker/. Discovery is by
shebang, so caps-lib.sh would have been dropped silently - the failure that
file's own comment calls the worst version of. fixed-domains.sh was already
uncovered for the same reason. Matched by directory rather than by name,
because a list is a thing to forget to add to.
2026-09-04 13:51:01 -07:00
branderson a4f4d1428f Extract the egress control into a script of its own
Step 2 of #305's filter container, and the plan's version of this step was
wrong: it said to move the firewall block out with the container still unused,
"nothing changes behaviour yet". Moving it out with nothing running the filter
container is a sandbox with no firewall. Extracted rather than moved, so the
arrangement is unchanged and one caller becomes two later.

firewall-up.sh is the DNS proxy, the packet filter and the two log producers.
Its own script because what it does is a property of a network namespace, and
everything else an entrypoint does is a property of a container - and the two
need not belong to the same one. No executable line changed in the move,
confirmed by diffing the block against its original.

caps-lib.sh carries drop_caps and the SETPCAP precondition, now that the
entrypoint is not the only caller. Sourced rather than copied: what drop_caps
does is the difference between a session holding nothing and a session holding
the whole floor, which is not a thing to have two of.

log-shipper.sh reparents to the container's init when firewall-up.sh exits.
Started from the entrypoint it was a child of the very session process it
exists to keep an eye on, which was never the intent.
2026-09-04 13:51:01 -07:00
branderson a301bae1c4 Merge pull request 'Bind everything the exit trap removes before the trap can fire' (#326) from run-id into development
Reviewed-on: #326
Reviewed-by: branderson <brad@branderson.io>
2026-09-04 13:24:25 -07:00
branderson 849ec326a2 Merge pull request 'Empty the capability bounding set for everything that outlives the root phase' (#324) from caps-floor into development
Reviewed-on: #324
Reviewed-by: branderson <brad@branderson.io>
2026-09-04 13:24:01 -07:00
branderson a0b45bdacc Launch with both names inherited, and check the canary survives
tests / confined (conversation) (pull_request_target) Successful in 54s
tests / confined (proxy) (pull_request_target) Successful in 1m4s
tests / confined (providers) (pull_request_target) Successful in 1m47s
tests / confined (share) (pull_request_target) Successful in 1m45s
tests / confined (shellcheck) (pull_request_target) Successful in 1m7s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / confined (remote) (pull_request_target) Successful in 2m31s
tests / confined (project) (pull_request_target) Successful in 2m51s
tests / confined (audit) (pull_request_target) Successful in 3m10s
tests / confined (static) (pull_request_target) Successful in 2m41s
tests / privileged (pull_request_target) Successful in 3m36s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
tests / confined (config) (pull_request_target) Successful in 4m18s
The static tests assert where the assignments are. This asserts what that
buys: with remote access off and DEJIMA_STATE_DIR and DEJIMA_RUN_ID both set
in the environment, a launch must not remove the files that join names.

Two canaries rather than one, because the removal needs both halves to come
from the environment - either name being dejima's own is enough to miss the
path, and a single file would pass on a fix that only covered one of them.
2026-09-04 01:27:52 -07:00
branderson 77e65513d9 Check the invariant bin/dejima states about its own exit trap
Two tests, and neither is the one already there. That one asks whether a name
cleanup() reads is BOUND, which is about set -u aborting the trap, and it
accepts `${NAME:-}` as the answer. Guarding against unbound does nothing about
a name arriving from the caller's environment already carrying a value, which
the trap then removes - and that is the invariant bin/dejima's own comment
states, so three names had drifted out of it with nothing to say so.

The first test asserts it for every argument to an rm in cleanup().

The second exists because the first has an exception. SANDBOX_GITCONFIG_DIR is
assigned below the trap and is safe there, but on a claim about its window
rather than about the name: no exit sits between the two lines. An edit that
puts one there turns the exception into the bug it is exempted from, and
nothing about that edit would look like it touched this.
2026-09-04 01:27:52 -07:00
branderson a41aebb09f Bind everything the exit trap removes before the trap can fire
Step 1 of #305's filter container, and a defect the step turned up.

The run id is generated for every launch now, not only a remote-enabled one.
It is the launch's identity and it was derived from whether one optional
feature is configured; the filter container needs it to label a network and a
container that exist either way.

That matters on its own, because cleanup() joins it to DEJIMA_STATE_DIR and
removes the result. With remote access off nothing assigned either name, so
both came from the caller's environment if it had them and the EXIT trap
removed a path of the environment's choosing.

bin/dejima already has a block for exactly this hazard, above `trap cleanup
EXIT`, and states the rule: every name cleanup() removes but does not itself
create belongs in it. Three more had drifted out of it - SANDBOX_BRIEFING_FILE,
SANDBOX_CREDENTIAL_PROXY_DIR and SANDBOX_FAKE_CREDENTIALS_FILE are first
assigned below the trap with ten, twelve and twelve ordinary `exit` paths in
between. The second is an `rm -rf` argument. Bound above the trap as well now,
rather than moved: their later sites read as what each feature starts from and
are correct as that.

SANDBOX_GITCONFIG_DIR stays the one exception and its comment stops claiming
uniqueness it had lost. What makes it safe is its window holding no exit, which
is a property worth asserting rather than re-deriving.
2026-09-04 01:27:41 -07:00
branderson b872fabdf6 Merge pull request 'Set the update notice apart from the launch output around it' (#323) from update-notice-visibility into development
Reviewed-on: #323
Reviewed-by: branderson <brad@branderson.io>
2026-09-04 01:17:02 -07:00
branderson 1e788548a0 Separate the two claims the capability floor was making at once
tests / confined (conversation) (pull_request_target) Successful in 57s
tests / confined (proxy) (pull_request_target) Successful in 1m1s
tests / confined (share) (pull_request_target) Successful in 1m45s
tests / confined (providers) (pull_request_target) Successful in 1m47s
tests / confined (shellcheck) (pull_request_target) Successful in 1m10s
tests / runner-env (confined) (pull_request_target) Successful in 44s
tests / confined (remote) (pull_request_target) Successful in 2m27s
tests / confined (project) (pull_request_target) Successful in 2m49s
tests / confined (audit) (pull_request_target) Successful in 3m7s
tests / confined (static) (pull_request_target) Successful in 2m40s
tests / confined (config) (pull_request_target) Successful in 4m15s
tests / privileged (pull_request_target) Successful in 10m42s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
"No path back to root" and "no capability if there were one" were one sentence
resting on the other. They are independent now, so say so, and say what the
floor actually describes: the container's root phase, which under `init: true`
PID 1 goes on holding for the life of the session. Narrowing that means
narrowing the floor itself, which is #305.
2026-09-04 00:50:56 -07:00
branderson 3734a614bd Assert the capability posture against the process that has it
Three changes, and the first is a fidelity bug the other two rest on.

`the real running node process has NET_ADMIN/NET_RAW stripped` read
/proc/1/status. PID 1 is the session here only because these fixtures use a
bare `docker run`; docker-compose.yml sets `init: true`, so in a real launch
PID 1 is the init that reaps for the session, running as root with the whole
floor effective. The assertion was about one process in the suite and a
different one in production. It now finds the session by what it is, and the
floor is read from a fresh `docker exec`, which is where the container's
declared set is observable rather than whatever the entrypoint left behind.

Then the bounding set, which is the claim with teeth: an empty effective set
is what changing uid gives you anyway.

And the two states that were untested. The container must refuse to start
without SETPCAP, because the alternative is a session running with the full
set and nothing anywhere saying so. The log shipper must still be root, and
must hold nothing while it is - which also exercises that it can read both
sources on ordinary permissions, since it says so itself when it cannot.

Its own container for that one: the shipper exits immediately without
LOKI_URL, so the file-wide fixture never started one and nothing in the suite
had ever observed it running.
2026-09-04 00:50:56 -07:00
branderson 55c33a8cc5 Say when the shipper cannot read a source, instead of shipping nothing
`tail -F` discards its stderr because it is meant to wait for a file that does
not exist yet and complains once a second while it does. That also swallows a
permission error, which is not transient and which presents identically to a
quiet session: a stream carrying no lines.

That mattered less while the shipper held DAC_OVERRIDE. It now reads both logs
on their ordinary permissions and nothing else, so the case is reachable and
the symptom is an oversight log that silently stops.
2026-09-04 00:50:56 -07:00
branderson 95b90761dd Empty the bounding set for everything that outlives the root phase
The session ran as an unprivileged user with an empty effective set, inside
a tree whose bounding set still held all seven capabilities the startup
sequence needed. A bounding set survives execve and a uid-0 process recovers
its permitted set from it, so "the session holds nothing" was a statement
about its effective set and about nothing else.

Measured in a live container rather than inferred: the session process, PID 1
and every long-lived daemon each carry the full floor in CapBnd. Only their
effective sets differ.

The session and log-shipper.sh - the one root process that outlives the
entrypoint - now start through capsh with an empty one. That costs SETPCAP in
the floor, which is worth stating plainly: a capability added so the rest can
be taken away. It can only reduce, since Linux 4.3 grants nothing a process
does not already hold, and it goes with everything else before the session
starts.

capsh rather than `setpriv --bounding-set`, which is the obvious tool and
silently the wrong one. Without CAP_SETPCAP setpriv exits 0 having changed
nothing, so a floor that lost the capability would run every session with the
full set and report success at every step; capsh refuses out loud. Confirmed
both ways against a real process. The entrypoint checks for the capability up
front as well, so the reason names the file the floor lives in rather than
arriving as an abort partway through startup.
2026-09-04 00:50:40 -07:00
branderson a438bf368b Declare libcap2-bin, rather than inheriting capsh from iproute2
capsh is about to become load-bearing: entrypoint.sh uses it to hand the
session a container it holds no capabilities in, and refuses to start
without it. It was present only as a dependency of iproute2, which is the
kind of thing an unrelated package change takes away.
2026-09-04 00:50:30 -07:00
branderson 2a20ae62cc Assert the notice names install.sh
tests / confined (conversation) (pull_request_target) Successful in 58s
tests / confined (proxy) (pull_request_target) Successful in 1m4s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / confined (share) (pull_request_target) Successful in 1m48s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / runner-env (confined) (pull_request_target) Successful in 46s
tests / confined (remote) (pull_request_target) Successful in 2m32s
tests / confined (project) (pull_request_target) Successful in 2m59s
tests / confined (audit) (pull_request_target) Successful in 3m19s
tests / privileged (pull_request_target) Successful in 3m34s
tests / runner-env (privileged) (pull_request_target) Successful in 36s
tests / confined (static) (pull_request_target) Successful in 3m19s
tests / confined (config) (pull_request_target) Successful in 4m25s
The fixture's own path, not ./install.sh, because the whole point of the
instruction is that it works from wherever the operator is standing.
2026-09-04 00:13:49 -07:00
branderson 2efb93c644 Point the update notice at install.sh, by absolute path
Pulling is only half an update: install.sh is what links bin/ onto PATH,
and a release can add or rename tools, so a checkout updated by pull
alone keeps the old links. The notice now says to re-run it after the
pull, joined with && so the whole line pastes as one command.

Both paths absolute, as the pull already was: the operator reading this
is not necessarily standing in the checkout it names.
2026-09-04 00:13:49 -07:00
branderson cdad2fb1e9 Assert the update notice keeps a blank line either side
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m6s
tests / confined (providers) (pull_request_target) Successful in 1m49s
tests / confined (share) (pull_request_target) Successful in 1m47s
tests / confined (shellcheck) (pull_request_target) Successful in 1m10s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m28s
tests / confined (project) (pull_request_target) Successful in 2m53s
tests / confined (audit) (pull_request_target) Successful in 3m14s
tests / confined (static) (pull_request_target) Successful in 2m41s
tests / privileged (pull_request_target) Successful in 3m37s
tests / runner-env (privileged) (pull_request_target) Successful in 41s
tests / confined (config) (pull_request_target) Successful in 4m21s
The whitespace is the fix, so it is pinned: a reformat that drops the
blank lines restores the bug exactly. Read from the file the check wrote
rather than from bats' $output, because run strips the blank lines at
either end of what it captures - they are invisible to a run-based
assertion in both directions.
2026-09-03 21:59:37 -07:00
branderson b1d7975aee Set the update notice apart from the launch output around it
The notice printed at the margin, in the body colour, between the
launch's own startup lines and the image build - which starts scrolling
immediately after - so its two lines read as part of whichever stream the
operator was already watching. Everything it has to say is "the dejima
you are about to wait through a build for is not current", which is
worth noticing before the build rather than after it.

A blank line either side, the two-space indent the other startup
warnings carry, and C_WARN for the notice line: the same treatment the
"not registered for" guards warning gets. The blank lines come from the
check itself rather than from bin/dejima because the check is silent
when the checkout is current, and the separation must not appear
without the notice.
2026-09-03 21:59:35 -07:00
branderson f2f40caa6b Merge pull request 'Say what a green check means, since that is the state agents actually see' (#322) from ci-green into development
Reviewed-on: #322
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 18:43:13 -07:00
branderson 6f4e176400 Say what a green check means, since that is the state agents actually see
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m6s
tests / confined (providers) (pull_request_target) Successful in 1m47s
tests / confined (share) (pull_request_target) Successful in 1m46s
tests / confined (shellcheck) (pull_request_target) Successful in 1m10s
tests / runner-env (confined) (pull_request_target) Successful in 44s
tests / confined (remote) (pull_request_target) Successful in 2m29s
tests / confined (project) (pull_request_target) Successful in 2m56s
tests / confined (audit) (pull_request_target) Successful in 3m17s
tests / privileged (pull_request_target) Successful in 3m37s
tests / confined (static) (pull_request_target) Successful in 2m59s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
tests / confined (config) (pull_request_target) Successful in 4m27s
.dejima.md warned not to read "CI covers it" as "it passed", which is true
of a queued job and not of a green one. The forge does not show a check
green until every job has finished and passed, and runtime.bats is one of
those jobs - so there is no state where the checks are green and the
privileged half was skipped.

Read as written, the warning taught every agent working here to hedge a
result that is not in doubt, on every pull request. That is the error that
actually happens: the operator sees the hedge, knows the run was green, and
disregards the sentence - which costs the warning its force for the case it
was written for.

So it says what each colour means and what to report for it. Green is
verified end to end and should be reported that way. Yellow or grey is a run
that has not happened, and reporting one as passing is what the paragraph is
for. Both halves, because leaving either out is how this goes wrong in one
direction or the other.

docs/release.md and test/release-pass.sh carried the same framing and now
carry the same rule. The test that pinned the script's warning asserts both
halves, against the script flattened to one line so that rewrapping a
message is not a failure about what it says.
2026-09-03 18:20:15 -07:00
branderson bc5e5dc05b Merge pull request 'Compare the release against the base that is actually released' (#320) from release-pass-base into development
Reviewed-on: #320
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 18:07:38 -07:00
branderson 3a26bd2618 Compare the release against the base that is actually released
tests / confined (share) (pull_request_target) Successful in 1m39s
tests / confined (remote) (pull_request_target) Successful in 4m49s
tests / confined (config) (pull_request_target) Successful in 18m22s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (conversation) (pull_request_target) Successful in 1m32s
tests / confined (providers) (pull_request_target) Successful in 2m24s
tests / confined (proxy) (pull_request_target) Successful in 1m21s
tests / confined (shellcheck) (pull_request_target) Successful in 1m5s
tests / confined (project) (pull_request_target) Successful in 5m54s
tests / privileged (pull_request_target) Successful in 3m53s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
tests / confined (audit) (pull_request_target) Successful in 8m27s
tests / confined (static) (pull_request_target) Successful in 7m46s
test/release-pass.sh took `main` - the local branch - as its default base.
Everything it prints is derived from base..head: which manual checks apply
comes from the paths the diff touches, and the rollback list comes from the
config keys it adds. A base behind the real one therefore reports on a
different release, and reports it confidently.

Not hypothetical. Two passes ran here against a local main 260 commits
behind origin/main, and both named config keys that had shipped releases
earlier and a trust-anchor domain this release does not add. One of those
reports was written into a handoff and read by the next agent as fact.

The default is the tracking ref now, and a base named explicitly is refused
when it is behind its own upstream - `main` is the ordinary thing to type
and is exactly how both stale runs happened, so catching only the default
would catch neither.

It exits rather than warning. A gate that says something is wrong and then
prints its report anyway is one whose output still ends up in a release PR.
2026-09-03 17:42:25 -07:00
branderson 483e44978d Merge pull request 'Ask git where the push is going, not where the fetch comes from' (#319) from secreview into development
Reviewed-on: #319
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 16:02:41 -07:00
branderson f51403a3dc Ask git where the push is going, not where the fetch comes from
tests / confined (conversation) (pull_request_target) Successful in 54s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (providers) (pull_request_target) Successful in 1m44s
tests / confined (share) (pull_request_target) Successful in 1m43s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m24s
tests / confined (project) (pull_request_target) Successful in 2m50s
tests / confined (audit) (pull_request_target) Successful in 3m9s
tests / confined (static) (pull_request_target) Successful in 2m40s
tests / privileged (pull_request_target) Successful in 3m47s
tests / runner-env (privileged) (pull_request_target) Successful in 41s
tests / confined (config) (pull_request_target) Successful in 4m17s
Found by the release pass's security review, reading the two push guards
against what they claim.

Both resolved the remote with `git remote get-url`, which answers with
remote.<name>.url. git pushes to remote.<name>.pushurl when one is set, so
a pushurl naming any other host was checked against the fetch URL and
allowed. No evasion needed: .git/config is in the read-write project mount
- deliberately, since `git push -u` writes there - so a session can set one
and every later push is checked against the wrong host. `get-url --push` is
the one question that answers where the push goes.

A one-command `-c remote.origin.pushurl=...` slipped a second way: both
guards skipped `-c` and its value while finding the subcommand, then
resolved the URL without it, answering for a different configuration than
the push would run under. Both now carry those overrides into their own
lookup.

And the hook had two problems of its own, neither shared with the shadow:

It recognised `git push` and `git -C <dir> push` by pattern and nothing
else, so `git -c k=v push`, `git --git-dir=... push` and `git --no-pager
push` were not pushes as far as it was concerned and it exited 0 before any
check ran. It walks tokens now, splitting compound commands on the shell
separators first so that only a segment beginning with git is read as a git
invocation - `echo push` is not one.

It also failed OPEN on a remote it could not resolve where the shadow fails
closed, and the shadow's comment says why closed is right: an unresolvable
remote is what a disagreement between a parser and git's own looks like,
and that has to be a refusal rather than a push nobody checked. Reaching
that state was easy, because splitting the command on the first occurrence
of "push" split inside `pushurl` and produced a nonsense remote.

The shadow catches every one of these regardless - it is the layer that
holds whichever harness is selected - so what was wrong was the earlier
warning being quieter than it claimed, not the boundary. The test that the
two guards agree now has cases where they did not.
2026-09-03 15:46:49 -07:00
branderson ebfc5ce7ff Merge pull request 'Fix the release blocker, and report the axis the rollback check was missing' (#315) from release-fixes into development
Reviewed-on: #315
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 15:29:48 -07:00
branderson 3e1521c412 Describe what the code does, not what it stopped doing
tests / confined (conversation) (pull_request_target) Successful in 56s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (share) (pull_request_target) Successful in 1m41s
tests / confined (providers) (pull_request_target) Successful in 1m43s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m22s
tests / confined (project) (pull_request_target) Successful in 2m44s
tests / confined (audit) (pull_request_target) Successful in 3m6s
tests / confined (static) (pull_request_target) Successful in 2m36s
tests / privileged (pull_request_target) Successful in 3m39s
tests / runner-env (privileged) (pull_request_target) Successful in 41s
tests / confined (config) (pull_request_target) Successful in 4m15s
The passage fixing the credential blocker narrated the change instead of
the state: "used to fall through to it", "that is now a refusal". Someone
reading it to find out what happens today has to work out which half is
still true, and .dejima.md says exactly this - cut what the code replaced,
git holds it, and a reader debugging the line has no use for it.

Two more of the same voice, both mine from the prose pass: the credential
proxy "is no longer on that list", and a session-start hook being "no
longer the only route". Neither past state is load-bearing; both sentences
say more without it.
2026-09-03 15:15:02 -07:00
branderson 6baf78d05c Print nothing when there is nothing to print, and accept a bracketed model
Two small things from a real install and a real launch.

install.sh emitted a blank line before the defaults rebuild whether or not
the rebuild had anything to say, so a run that added, dropped and reported
nothing left a double gap between two paragraphs that were already
separated. The blank line belongs to each message instead, which makes
silence silent.

And `claude-opus-5[1m]` was refused as a model id. The modelid type was
added a week ago because `identifier` had no slash and no OpenRouter id
could be configured; the set it grew was built from the ids in that report,
and Anthropic brackets a context variant. So the same bug, one release
later, for the same reason: a charset derived from the failure at hand
rather than from what the catalogues actually spell.

Brackets carry no meaning anywhere this value goes - it is written with jq
--arg - and the reason the type stays narrow is unchanged: a newline or a
tab would split a record every reader of this config expects to be one
line. Those are still refused, along with a space, a semicolon and a
backtick.

The test grew the bracketed id beside the others rather than replacing
them, and says why: real ids from every catalogue dejima can reach, not the
ones that prompted a fix.
2026-09-03 15:15:02 -07:00
branderson 26ed2e6a5b Wait for the byte to arrive rather than pumping for a fixed 0.8s
CI failed static.bats 144 with

    FAIL ctrl-c-still-reaches-the-session b'ped\n'

The last four bytes the container received were the tail of `typed\n`,
the line sent immediately before: ^C had not arrived yet when the check
looked. Nothing was wrong with the code under test.

Two sites sent a byte, pumped the pty for 0.8 seconds and then asserted -
timing the machine rather than waiting for the thing. A byte written to
the master has to reach the client, cross into the container stand-in and
be appended to a file before a check can see it, and on a loaded host that
is not reliably under 0.8s.

This is the third instance of the same bug in this file. The reclaim wait
and await_raw are the first two, and await_raw's own comment names the
shape - "Sampling the flags right after fg was timing the machine, and on
a loaded one it read the shell's own canonical mode". So it gets the same
answer they got, factored: await_received polls until what the container
received satisfies a predicate, and returns the predicate's answer at the
deadline either way, so a real failure still fails rather than hanging
until the suite's own timeout.

Verified under load rather than by argument: three consecutive runs green
with twenty busy loops on ten cores, which is heavier than the CI host
that failed it.
2026-09-03 15:15:02 -07:00
branderson 1f251efd5b Stop describing a fallthrough that is now a refusal
Release blocker, found by a release pass rather than by a test.

c306c32 made an unproxied credential a launch refusal: a Claude Code
signed in with a console API token has no claudeAiOauth block, so
backends/anthropic cannot serve it, and dejima used to skip the proxy and
mount the real file. docs/security.md's arrangements table went on listing
that as the fourth row - the one where the real credential is mounted and
a compromised session can take it.

A document promising the weakest posture for a launch that no longer
happens is worse than one saying nothing, because it is the posture an
operator plans around. Only proxy = off lands there now, and only where
they wrote it. The passage says what happens instead, and that the refusal
is scoped to a credential that exists: an absent one still launches,
because that is a host nobody has signed in on yet.

A static test pins the two together, since the drift was silent for a
release and nothing would have caught the next one. It reads the table's
own row rather than the prose around it, and asserts the code still
refuses - so removing the refusal fails the test about the document, which
is the direction that matters.

Also from the same pass: test/release-pass.sh enumerated four provider
axes under a comment claiming every one, and tools is the fifth. A new
tool is the same rollback hazard - [core] tools = rtk is refused by a
dejima that does not ship rtk - so it now reports one, names it through
the value that refuses rather than as a config section it does not have,
and a check against the tree fails when an axis is added and not listed.
A change under tools/ gets a manual check too; nothing here runs one.

And a flourish trimmed in docs/development.md: "confirmed rather than
argued" said nothing the sentence after it did not. What is left is the
fact, now stronger - Cline has run real completions through the terminator
against two backends of different api_style.
2026-09-03 15:15:02 -07:00
branderson 58c6f1b64d Merge pull request 'Read the rejection whatever its framing, and stop calling a 429 a refusal' (#317) from proxy-log2 into development
Reviewed-on: #317
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 15:14:24 -07:00
branderson 3642156e7c Merge pull request 'Say that a Claude subscription is served to Claude Code, and that dejima will not pretend otherwise' (#318) from subscription-gating into development
Reviewed-on: #318
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 15:14:00 -07:00
branderson df7c32154c Keep the gating in providers.md, where a limit on dejima belongs
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (share) (pull_request_target) Successful in 1m46s
tests / confined (shellcheck) (pull_request_target) Successful in 1m10s
tests / confined (providers) (pull_request_target) Successful in 2m18s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m29s
tests / confined (project) (pull_request_target) Successful in 2m53s
tests / confined (audit) (pull_request_target) Successful in 3m13s
tests / confined (config) (pull_request_target) Successful in 4m29s
tests / privileged (pull_request_target) Successful in 3m52s
tests / runner-env (privileged) (pull_request_target) Successful in 43s
tests / confined (static) (pull_request_target) Successful in 2m45s
responsible-use.md is where dejima makes a judgement about what an operator
does - don't spam maintainers, own what you merge, security is not
retrofittable. Working around a vendor's client gating is not that, and
dejima has no view on whether someone should try.

What dejima has is a limit: it does not do it. That is a fact about the
credential proxy, so it lives beside the fact that prompted it, in
providers.md, where someone choosing a backend is already reading.

The reasons are the engineering ones. The proxy substitutes the credential
and changes nothing else, so getting past the gate would mean sending a
system prompt the harness never wrote - a second answer to "which client is
this" inside the component whose only job is to pass the first one through.
And it would be brittle where the cost lands on the operator's account
rather than on dejima.

Gone with the section: the sentence about a sandbox not getting to pick
which boundaries it honours. True of the sandbox, and an argument nobody
reading this needed.
2026-09-03 15:03:24 -07:00
branderson ea352d21ce Say that a Claude subscription is served to Claude Code, and that dejima
tests / confined (conversation) (pull_request_target) Successful in 53s
tests / confined (proxy) (pull_request_target) Successful in 1m1s
tests / confined (share) (pull_request_target) Successful in 1m45s
tests / confined (providers) (pull_request_target) Successful in 1m48s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m27s
tests / confined (project) (pull_request_target) Successful in 2m51s
tests / confined (audit) (pull_request_target) Successful in 3m12s
tests / confined (static) (pull_request_target) Successful in 2m42s
tests / confined (config) (pull_request_target) Successful in 4m22s
tests / privileged (pull_request_target) Successful in 3m37s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
will not pretend otherwise

The compatibility table said `anthropic` x `cline` and stopped there, which
is true of the dialects and not of the answer a session gets. A Claude
subscription's OAuth credential is served to Claude Code and refused to
other clients per model: claude-haiku-4-5 is served, claude-opus-5 and
claude-sonnet-5 are not, while an otherwise identical request from Claude
Code succeeds.

The refusal is a 429 rate_limit_error whose body message is the word
Error, so from inside it is indistinguishable from a quota problem - an
account nowhere near any limit still has every request refused. That is
worth documenting on its own: it cost an afternoon of reading usage graphs
before an experiment settled it.

The table itself is unchanged and stays derived - it answers whether dejima
will pair the two, which is a question about api_style. Whether the
endpoint then serves the request is the endpoint's to answer, and now has
a section of its own beside the table rather than a hedge inside it. The
matrix test keeps checking the cells against the manifests, which is what
it is for.

R5's "confirmed end to end" is qualified rather than withdrawn: the
arrangement is confirmed - placeholder in, real credential injected
host-side, a real completion out - and which models the credential will
serve a client that is not Claude Code is a separate question it never
asked.

And the non-goal, in responsible-use.md where this project's positions
live: dejima will not make one harness present itself as another to get
past that gate. It would forge a product's identity against the operator's
own account, on a control the provider put there deliberately. It would be
brittle in the worst way - working until the day it does not, and that day
being a question about someone's account rather than a bug report. And it
would contradict what the rest of the project spends its effort on: the
credential proxy forwards the harness's own request so that what the API
sees is true, down to declining to send a header the client did not.

The supported answers are both real ones - a credential that is yours to
spend for another harness, or the harness the subscription was issued for.
2026-09-03 14:37:25 -07:00
branderson ec1b662429 Log the request id, because the body turned out to say nothing
tests / confined (proxy) (pull_request_target) Successful in 59s
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (providers) (pull_request_target) Successful in 1m41s
tests / confined (share) (pull_request_target) Successful in 1m40s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m22s
tests / confined (project) (pull_request_target) Successful in 2m46s
tests / confined (audit) (pull_request_target) Successful in 3m7s
tests / confined (static) (pull_request_target) Successful in 2m36s
tests / confined (config) (pull_request_target) Successful in 4m15s
tests / privileged (pull_request_target) Successful in 3m37s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
The decoded 429 reads, in full:

    {"type":"error","error":{"type":"rate_limit_error","message":"Error"}}

The word Error and nothing else. So on the response this whole thread of
changes was chasing, the body is not where the information is - the
headers are, and a reader should not have to know to go looking for them.

request-id is what Anthropic support asks for and is the only thing on
that response that identifies it from the other side; retry-after is the
only thing that says how long. Both are logged when present.

Deliberately not the account and workspace ids the same response carries.
They name the operator's organisation, and this line is written to be
pasted into a bug report - request-id is enough to find the request
without carrying who made it. A test asserts they stay out, and fails when
one is added back.

The fixture gained all four headers, so the assertion that two are kept
and two are dropped has something to be true about.
2026-09-03 13:59:08 -07:00
branderson 9007e34c20 Read brotli where the host can, and say what to install where it cannot
tests / confined (conversation) (pull_request_target) Successful in 55s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (share) (pull_request_target) Successful in 1m42s
tests / confined (providers) (pull_request_target) Successful in 1m44s
tests / confined (shellcheck) (pull_request_target) Successful in 1m7s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m20s
tests / confined (project) (pull_request_target) Successful in 2m44s
tests / confined (audit) (pull_request_target) Successful in 3m4s
tests / confined (static) (pull_request_target) Successful in 2m37s
tests / confined (config) (pull_request_target) Successful in 4m12s
tests / privileged (pull_request_target) Successful in 3m54s
tests / runner-env (privileged) (pull_request_target) Successful in 43s
gzip was the guess; the real answer came back br. So the encoding this
could not read was the common case rather than an edge - brotli is what a
Node client negotiates when offered, and cline offers it.

Decoded through brotli or brotlicffi when either is importable, using the
incremental decoder in both, since what this reads is a bounded prefix
rather than a whole stream. Optional on purpose: the proxy runs on the
host as the operator's user, and a diagnostic is not worth a hard
dependency on a module Debian packages separately. Absent, the line names
the encoding, the size, and the two commands that would fix it - a note an
operator can act on rather than one that only explains why they cannot.

Not solved by asking the API for an encoding this can read. The request it
sees is deliberately the harness's own header block, byte for byte, and
Accept-Encoding is part of what makes a session look like a stock install
- there is a comment about not sending CPython's own `identity` tell for
exactly that reason. Rewriting it so a log line is easier to read would
trade a property the sandbox exists for against a convenience.

The test asserts whichever half the host can demonstrate, and requires the
absent branch to name the fix rather than only the problem. Both branches
still produce no unprintable bytes, which is the invariant that does not
depend on any of this.
2026-09-03 13:41:24 -07:00
branderson 3f4d6f217d Decompress the rejection before logging it, and never log bytes
tests / confined (conversation) (pull_request_target) Successful in 58s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (providers) (pull_request_target) Successful in 1m45s
tests / confined (share) (pull_request_target) Successful in 1m44s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m25s
tests / confined (project) (pull_request_target) Successful in 2m48s
tests / confined (audit) (pull_request_target) Successful in 3m9s
tests / confined (static) (pull_request_target) Successful in 2m45s
tests / confined (config) (pull_request_target) Successful in 4m20s
tests / privileged (pull_request_target) Successful in 3m53s
tests / runner-env (privileged) (pull_request_target) Successful in 42s
The logging reached a real 429 and put this on the operator's terminal:

    dejima: line 1333: warning: command substitution: ignored null byte in input
    ...f0303U=....$..&.....o.IB..b..W.H,%..S..an,....;.G..2...f..m2.t.L/jz5..

The client's own Accept-Encoding is forwarded verbatim - deliberately, so
the request the API sees is the harness's own - and every Node client asks
for gzip. So the error body came back compressed and the prefix read for
the log was compressed bytes, written out raw. Which is also why the
message that would have explained the 429 was unreadable: the thing added
to answer the question was the thing hiding the answer.

Two changes, and the second is the one that matters. gzip and deflate are
decompressed with decompressobj, which works on the bounded prefix that is
all this reads; br and zstd have no stdlib decoder and are named rather
than printed. Then, whatever the encoding, only printable characters reach
the file - unconditionally, not as a consequence of recognising the
encoding.

That second half is an invariant this had no business breaking in the
first place. dejima-audit hex-encodes control characters in a finding
precisely because they scroll, blank and reorder a terminal, and an
upstream error body is no more trustworthy than a session-authored path.
An unknown encoding now degrades to a note about its size rather than to
bytes.

Control characters become spaces rather than being dropped, so a message
cannot be silently re-joined into a different one.

The fixture grew the shape this actually met: gzip, chunked, retry-after,
against a client that asked for gzip. The previous one answered plain, so
it could not have caught this - the same way the one before it answered
with a Content-Length and could not catch the chunked case.
2026-09-03 13:13:00 -07:00
branderson d751f53e68 Read the rejection whatever its framing, and stop calling a 429 a refusal
tests / confined (conversation) (pull_request_target) Successful in 57s
tests / confined (proxy) (pull_request_target) Successful in 1m2s
tests / confined (share) (pull_request_target) Successful in 1m49s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / confined (shellcheck) (pull_request_target) Successful in 1m12s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / confined (remote) (pull_request_target) Successful in 2m32s
tests / confined (project) (pull_request_target) Successful in 2m57s
tests / confined (audit) (pull_request_target) Successful in 3m16s
tests / confined (static) (pull_request_target) Successful in 2m47s
tests / confined (config) (pull_request_target) Successful in 4m20s
tests / runner-env (privileged) (pull_request_target) Successful in 41s
tests / privileged (pull_request_target) Failing after 2h14m16s
The logging added last change met its first real rejection and recorded
half of it:

    12:07:25 dejima-credential-proxy: upstream answered 429 for /v1/messages
    12:07:28 dejima-credential-proxy: upstream answered 429 for /v1/messages
    12:07:32 dejima-credential-proxy: upstream answered 429 for /v1/messages

Three status codes and nothing to act on. The body was read only where
upstream declared a small Content-Length, and a rate limiter answers
chunked - so the one thing that says which limit was hit, and the
retry-after that says for how long, were both dropped.

It reads a bounded prefix whatever the framing now, with read1, which
returns what has arrived rather than waiting for a buffer. That costs one
chunk, is written out before the stream picks up where it left off, and
retry-after is named on its own rather than left among the headers for a
reader to spot.

The summary called every one of those a refusal. A 429 is a client being
asked to wait, and cline retried through these - the session may well have
got its answer. It groups by status now, prints the most recent line
whole, and says plainly that a retried status is not a verdict on the
session. Grouping is the point rather than tidiness: one condition a
client retries becomes several identical lines, and a list of them says no
more than a count does.

The fixture grew a rate limiter's actual shape - chunked, no
Content-Length, retry-after - because the previous one answered with a
length and so could not have caught this.

One incidental: the grouping awk matches on the whole line rather than
looping over fields. A loop needs an index, and an awk index inside single
quotes is indistinguishable to the test that every name cleanup() uses is
bound before the EXIT trap fires. That test is right to be strict; it also
caught the index in the comment explaining this, which is the correct
amount of strict.
2026-09-03 12:45:57 -07:00
branderson 288d28a210 Merge pull request 'Say what the API refused, instead of forwarding a rejection in silence' (#316) from proxy-log into development
Reviewed-on: #316
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 11:57:14 -07:00
branderson 1e4d28021e Say what the API refused, instead of forwarding a rejection in silence
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (proxy) (pull_request_target) Successful in 1m11s
tests / confined (share) (pull_request_target) Successful in 2m2s
tests / confined (providers) (pull_request_target) Successful in 2m6s
tests / confined (shellcheck) (pull_request_target) Successful in 1m13s
tests / runner-env (confined) (pull_request_target) Successful in 46s
tests / confined (remote) (pull_request_target) Successful in 2m50s
tests / confined (project) (pull_request_target) Successful in 3m21s
tests / privileged (pull_request_target) Successful in 3m26s
tests / confined (audit) (pull_request_target) Successful in 3m42s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (static) (pull_request_target) Successful in 3m9s
tests / confined (config) (pull_request_target) Successful in 4m48s
Reported from a real launch: cline against the anthropic backend started,
listed models, ran a prompt, spun, and errored. No logs anywhere to act on.

The proxy is the only thing that sees both the request the session made and
the answer the API gave, and it forwarded a non-2xx verbatim and recorded
nothing. What the harness then shows is the harness's business, and for
that session it was nothing an operator could use. Every other part of this
repo says what happened; this path said nothing for exactly the case
someone is trying to debug.

It records the status, the path and the API's own message now. Only for a
rejection: logging a successful request would put the operator's traffic in
a file, and reading the body to do it would buffer a streaming response.
The body is read whole only where upstream declared a small Content-Length,
and forwarded byte for byte afterwards, so what the session sees is
unchanged - a streaming or oversized rejection is recorded by status alone
rather than buffered here.

To a file, not stderr. The proxy inherits bin/dejima's stderr, which is the
operator's terminal, and the session owns it while it runs: a line written
mid-request lands in the middle of whatever the harness is drawing.
bin/dejima reads it back during cleanup, before the temp directory goes and
before the exit audit, which stays the last thing on the terminal. With no
--log it still goes to stderr, so a proxy run by hand is not the case with
no diagnostics.
2026-09-03 11:45:07 -07:00
branderson 9c609f344d Merge pull request 'Say that a release pass ends at the report, not at the release PR' (#314) from release-pass-scope into development
Reviewed-on: #314
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 02:39:21 -07:00
branderson 49f68f4066 Say that a release pass ends at the report, not at the release PR
tests / confined (conversation) (pull_request_target) Successful in 53s
tests / confined (proxy) (pull_request_target) Successful in 57s
tests / confined (share) (pull_request_target) Successful in 1m35s
tests / confined (providers) (pull_request_target) Successful in 1m44s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m12s
tests / confined (project) (pull_request_target) Successful in 2m36s
tests / confined (audit) (pull_request_target) Successful in 3m6s
tests / confined (static) (pull_request_target) Successful in 2m40s
tests / privileged (pull_request_target) Successful in 3m23s
tests / runner-env (privileged) (pull_request_target) Successful in 37s
tests / confined (config) (pull_request_target) Successful in 3m50s
An agent that has just run the pass holds everything the release PR is made of, so the instructions now say where the pass stops: the report is the deliverable, the release PR is never opened unasked, and the sanctioned next move is to prompt the user to create it.
2026-09-03 02:23:41 -07:00
branderson ecd683b192 Merge pull request 'Pin dejima's defaults per machine, so a release cannot move a setting you never chose' (#313) from pinned-defaults into development
Reviewed-on: #313
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 02:14:21 -07:00
branderson 2954afda34 Say which file is whose, and leave --print-config's format alone
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (proxy) (pull_request_target) Successful in 59s
tests / confined (share) (pull_request_target) Successful in 1m43s
tests / confined (providers) (pull_request_target) Successful in 1m46s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m26s
tests / confined (project) (pull_request_target) Successful in 2m50s
tests / confined (audit) (pull_request_target) Successful in 3m11s
tests / privileged (pull_request_target) Successful in 3m24s
tests / confined (static) (pull_request_target) Successful in 2m39s
tests / runner-env (privileged) (pull_request_target) Successful in 35s
tests / confined (config) (pull_request_target) Successful in 4m17s
Documents the two files and the property they buy, in the reference and in
the README's first-run section: your config is yours and dejima never
writes it, defaults.conf beside it is dejima's and holds what its defaults
were when this machine first saw each key.

`required` gets a second, mechanical reading - it is exactly the set with
no line in defaults.conf, because a key with no default has nothing to
pin. The document and the file agree without anyone keeping them in step.

config_origin says which of the three layers answered, and --print-config
does NOT print it. Appending it as a second column broke eleven callers in
this repo, all using `grep -qx key=value`, which is the obvious way to read
that output and evidence that more exist outside it. A format with callers
is one to extend deliberately rather than in passing, and the question it
answers is already readable from the files: in config it is yours, in
defaults.conf it is pinned, in neither it is what this release ships.
2026-09-03 02:09:29 -07:00
branderson 0c5ae0e371 Rebuild the pinned defaults on install, and name what has moved
install.sh rewrites defaults.conf: keys this release added appended, keys
it retired dropped, every value already decided left exactly where it is.
Both halves fall out of rendering with "keep" rather than being two rules
someone has to remember.

Pruning is not the tidier half. An unknown key there is one this dejima
cannot read, so a file that only ever grew would collect them until the
launch notice about it became permanent.

A shipped default that no longer matches the pinned one is named here and
nowhere else, because here is when it moves - you pulled and re-ran this.
Both values are printed and neither is taken: taking one would be dejima
writing a change to a session's behaviour into an upgrade, which is what
this exists to stop. The line to adopt it goes in the operator's own
config, never in the file the next rebuild rewrites.

The starter config stops writing every key commented out at its default.
That was a second copy of the defaults, in comments nothing regenerates,
drifting against the schema as keys were added; defaults.conf beside it is
that reference now, complete and rewritten every install. What is left is
what was actually seeded - the selection and any legacy variables still
exported - with each section's header written by the first key that lands
under it, so a section nothing seeded leaves no empty stanza.
2026-09-03 01:29:49 -07:00
branderson 2110b9bc16 Pin the defaults on the first launch, and say so once
Nothing wrote defaults.conf, so the layer read in the last commit was
always empty and the schema always answered. A launch writes it when it is
absent.

dejima creating its own file is not the write this arrangement removes -
it is the opposite of one. Doing it here rather than only in install.sh is
what makes the property hold for an operator who never ran the installer,
and dejima runs perfectly well from a checkout without it.

A launch that finds the file does nothing further: no rebuild, no prune,
no drift check. Those belong to install.sh, which is when the shipped
defaults actually change, and doing them per launch would put a standing
condition in front of every one - the failure the orphaned-share list
already demonstrates.

Every installed provider's keys, not only the selected one. Pinning just
the harness in use leaves the next one an operator selects handing them
ITS current defaults, which is the same failure one axis over and a year
later. Keys with no default are absent, because there is nothing to pin:
those are exactly the ones docs/configuration.md marks required, so the
file and the document agree by construction.

After --print-config's exit, deliberately. That flag is what an operator
runs to inspect their configuration, and a query that creates a file as a
side effect is not one. It also kept a test honest, which is how the
ordering got noticed: --print-config emits one line per schema key, and
the announcement was an extra one.

A retired key in the file is named once, with ./install.sh, and the launch
continues on the schema's answer.
2026-09-03 01:08:36 -07:00
branderson 7051a01cf1 Read a pinned defaults layer between the operator's config and the schema
[core] harness has no default because a default that could change later is
a config file that is not the source of truth. That argument is not
special to harness: it holds for every defaulted key, and there is a
recorded instance of the failure - the [core] forge and workflow defaults
changed from gitea+worktree-pr to none+local-only, silently stopping
existing sandboxes pushing. install.sh still carries the note.

So a key resolves through three layers: the operator's config, then
defaults.conf, then the schema. The schema is reachable only for a key
defaults.conf has no line for - a fresh machine, or a key added since the
last ./install.sh - which is the one case where dejima's current answer is
the right one. Nothing writes defaults.conf yet; that is the next commit.

It lives beside the operator's file rather than under ~/.local/share,
because it explains the file next to it and the answer to "why is this
value what it is" belongs where someone would look for it.

The pinned layer gets its own two arrays rather than being seeded into the
operator's, and that is the whole load-bearing decision here.
config_is_set has ten callers and every one means "did the operator write
this" - the [core] ssh_key / [identity.default] ssh_key refusal fires only
when both are present, an identity's forge keys take precedence only when
it names one, and the ttyd knobs read unset as "the page decides from the
pointer type". A file naming every key would answer yes to all of them.

Its parse is lenient where the operator's is strict, line by line rather
than wholesale. An unknown key there is one dejima RETIRED, on a machine
whose defaults.conf predates the release that dropped it: the operator did
not write it and is told not to edit the file, so refusing would leave
them a launch that will not start and nothing to do about it. The schema
answers for whatever is skipped and the count is kept for the launch to
name once.

Both parsers stopped clearing their own arrays; config_validate clears all
four before either runs. That is not tidying: with the old shape, seeding
the pinned layer into the operator's arrays was a bug the following parse
happened to wipe, so the test for it passed against the mutation. It
fails now.
2026-09-03 00:47:13 -07:00
branderson dff6a40dd1 Merge pull request 'One table per config section, in the order an operator fills them in' (#312) from config-ref into development
Reviewed-on: #312
Reviewed-by: branderson <brad@branderson.io>
2026-09-03 00:42:03 -07:00
branderson 642fcd15b3 Merge pull request 'Say what decides a scroll step, rather than sending fewer of them' (#309) from scroll-step into development
Reviewed-on: #309
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 22:57:46 -07:00
branderson 79c8c25983 Merge pull request 'Guard the selected harness's config, and name the proxy's machinery after the proxy' (#308) from mounts-guard into development
Reviewed-on: #308
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 21:08:48 -07:00
branderson 757360a742 Name the binding that was actually doing it, and how to find yours
tests / confined (conversation) (pull_request_target) Successful in 59s
tests / confined (proxy) (pull_request_target) Successful in 1m5s
tests / confined (project) (pull_request_target) Successful in 2m59s
tests / confined (share) (pull_request_target) Successful in 1m31s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (audit) (pull_request_target) Successful in 3m48s
tests / confined (config) (pull_request_target) Successful in 4m38s
tests / confined (static) (pull_request_target) Successful in 2m34s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
tests / confined (providers) (pull_request_target) Successful in 1m51s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / confined (remote) (pull_request_target) Successful in 2m19s
tests / privileged (pull_request_target) Successful in 3m33s
The section said stock tmux, which scrolls five lines. The configuration
that prompted this bound halfpage-up instead - half the pane, so twenty
lines in a forty-line one, which is what "more than half the screen" was.

Both are worth naming, and neither is worth guessing at from here: the
first line of the section is now the list-keys that answers it. The
example scrolls four rather than one, which is what the reported fix
settled on and reads better on a desktop sharing the same server.
2026-09-02 19:02:44 -07:00
branderson 62eea1002d Revert the scroll step, and name what actually decides one
tests / confined (conversation) (pull_request_target) Successful in 1m0s
tests / confined (proxy) (pull_request_target) Successful in 1m8s
tests / confined (providers) (pull_request_target) Successful in 1m56s
tests / confined (project) (pull_request_target) Successful in 3m3s
tests / confined (share) (pull_request_target) Successful in 1m34s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / confined (audit) (pull_request_target) Successful in 4m12s
tests / confined (remote) (pull_request_target) Successful in 2m18s
tests / privileged (pull_request_target) Successful in 3m25s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (static) (pull_request_target) Successful in 3m37s
tests / confined (config) (pull_request_target) Successful in 6m41s
Reverts "Make a scroll notch cost more finger travel where a notch is
worth more" and its doc commit.

The diagnosis was half right. A notch is worth several rows to whoever
receives it, so one notch per row did outrun the finger - but sending
fewer notches trades a fast scroll for a stiff one and leaves each jump
exactly as big. On a phone that jump is what matters: five lines is more
than half the screen, and reported as still needing several tries to place
a line after the change.

Confirmed by asking where the notch lands: the pane enters copy mode with
a position counter, so tmux is receiving it and the five is tmux's own
binding.

Nothing in dejima can make that smaller. The page chooses how many notches
to send and nothing else, and `dejima-attach` joins the tmux session the
operator launched from, whose configuration is theirs. So the answer is
four lines in their ~/.tmux.conf, and docs/remote-access.md now carries
them - both key tables, since which is active follows mode-keys - along
with why this is not something dejima sets on their behalf.

web/test/gestures.test.js stays, rewritten for the behaviour that is back:
one notch per row of travel on both paths, nothing for travel shorter than
a row, and the direction. The module had no test file at all before, and
the reverted change is not why it wanted one.
2026-09-02 18:35:31 -07:00
branderson 53da70aae9 Point the shared-directory section at what reaching it remotely costs
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / runner-env (privileged) (pull_request_target) Successful in 37s
tests / confined (static) (pull_request_target) Successful in 2m9s
tests / confined (audit) (pull_request_target) Successful in 4m11s
tests / confined (config) (pull_request_target) Successful in 6m46s
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (project) (pull_request_target) Successful in 2m52s
tests / confined (providers) (pull_request_target) Successful in 1m48s
tests / confined (proxy) (pull_request_target) Successful in 58s
tests / confined (remote) (pull_request_target) Successful in 2m19s
tests / confined (share) (pull_request_target) Successful in 1m36s
tests / privileged (pull_request_target) Successful in 3m30s
tests / runner-env (confined) (pull_request_target) Successful in 46s
remote-access.md's "Mounting the box's files" is how you get at a project's
share from another machine, and it already links back here for the
clear-it-out advice. The other direction was missing, so an operator
reading about ~/shared had no way to reach the warning that a desktop
indexes, thumbnails and previews everything a sandboxed session wrote
there, with nothing of dejima's in the path.
2026-09-02 18:35:30 -07:00
branderson 314b711b6c Say what a scroll notch is worth, next to the setting that changes it
The knob is meaningless without the reason it exists, which is that who
receives a notch decides what it costs: one row when the page scrolls its
own scrollback, five when stock tmux is in copy mode.
2026-09-02 18:35:30 -07:00
branderson 14a91be8f1 Name the credential proxy's own machinery after the proxy, not after Anthropic
SANDBOX_ANTHROPIC_PROXY_SOCKET, _PROXY_PID, _PROXY_DIR, _PROXY_PORT,
_TLS_CERT, _TLS_KEY and _TRANSPORT describe a unix socket, a forwarder
process, a self-signed cert and a choice between TLS and loopback. None of
that is Anthropic's; the terminator answers for whichever backend's
proxied_domain was selected, and openrouter goes through the same code.
They are SANDBOX_CREDENTIAL_* now, and /etc/dejima-anthropic-tls inside the
container is /etc/dejima-credential-tls for the same reason.

Three keep the old name, and that is the interesting half. BASE_URL,
AUTH_TOKEN and API_KEY each carry a value into the ANTHROPIC_ variable
beside it in docker-compose.yml, which is what Claude Code reads. Renaming
those would name them after the thing they are not. Said at the
declaration so nobody finishes the rename by mistake.

SANDBOX_ANTHROPIC_TRANSPORT keeps its old name in the two places it is the
operator's rather than dejima's: install.sh seeds [credentials] transport
from it on a first install, and _warn_legacy_env names it as retired. Both
read what is in someone's shell profile, and that string did not change.
The rename removes the collision those had with dejima's own variable of
the same name.

A stub in config.bats filtered docker's environment to ^SANDBOX_ANTHROPIC,
so the renamed socket variable stopped appearing in what two credential
tests assert on. It takes both prefixes now.
2026-09-02 18:35:30 -07:00
branderson b497353fc6 Make a scroll notch cost more finger travel where a notch is worth more
The terminal page sent one wheel notch per row of finger travel. That
tracks the finger exactly while the page is scrolling its own scrollback,
because a notch moves one row there. It does not when an application is
reading the mouse: stock tmux binds copy-mode's WheelUpPane to
`send -X -N 5 scroll-up`, and a full-screen application picks its own
figure. So a small movement of a thumb threw the screen several rows, and
putting a particular line at the bottom took several tries.

[remote-access] ttyd_scroll_step is how many rows the finger travels per
notch, default 5, and it multiplies only on the path where a notch is
worth more than a row. Applying it to both would make the scrollback
sluggish to fix something that is not wrong there.

The odd one out among the -t knobs: unset does not mean "send nothing".
The page has to pick some travel per notch either way, so the schema
carries a real default and the page is told it rather than keeping a
second copy in step. ?scroll=N overrides per client, which matters here
more than for the others because the right number depends on what is
running in the session rather than on the host.

A step of zero or less is refused twice - by the schema's 1-40 bound and
again in the page - because scrollBy consumes accumulated travel in a
while loop keyed on it, so zero spins forever on the first drag.

gestures.js had no test file. It has one now, driving the real touch
handlers through a stub element: the scrollback path unchanged at any
step, an application path at 5, the old behaviour still reachable at 1,
and travel shorter than one step sending nothing rather than rounding up.
Removing the multiplier fails three of them.

Also checked in chromium against the built page, with a stub WebSocket
speaking ttyd's frames: a 20-row drag with SGR reporting on sends 4
notches by default and 20 at scrollStep=1, a server value arrives through
SET_PREFERENCES, and ?scroll=2 beats a server value of 10.
2026-09-02 18:35:30 -07:00
branderson af480bbf95 Say what the read_write refusal actually covers
The list in configuration.md named ~/.claude and stopped, which was the
same list bin/dejima had. It also left out the epitaph store and the share
root, both of which have been guarded for a while.
2026-09-02 18:35:30 -07:00
branderson 476c0e3e82 Guard the selected harness's own config, not the one harness named in a list
[mounts] read_write refused a writable mount overlapping $HOME/.claude, by
name. Cline keeps its configuration in ~/.agents and ~/.cline and its state
under ~/.local/share/dejima/cline, none of which were in that list - so
read_write = ~/.agents was accepted, handing a session write access to the
hooks and skills the operator's own machine runs next time. That is the
persistence this refusal exists to stop, and the docs already claimed it
was stopped.

The list is derived now. Every host path the selected harness's plugin
names, in all three declaration tiers, plus every `path`-typed key in its
manifest - so the state directories are covered without this knowing what
a given harness calls them, and a harness landing later is guarded on the
day it lands rather than when someone remembers.

Read-only tiers count too. A read-only mount protects the host's file from
the session that has it; it says nothing about a writable mount an
operator points at the same file, and what matters here is only that the
harness reads it on the host.

A staged or seeded entry contributes its host source AND $HOME/<rel>, the
path it is installed at. The two differ when the operator keeps the file
elsewhere, and the rel is named whether or not the file exists, which the
source is not - emit_seed_from drops an absent source. That is what still
covers ~/.claude/plugins, which is reached only through a seed
destination and which the literal used to cover.

The three loads move up to where the guard is, because a guard that runs
after the mount it would refuse is not one. They were already idempotent;
their consumers further down now read the arrays rather than reloading.

Tested by launch rather than by reading the list: one case per way a path
reaches it, under both shipped harnesses, plus a mount outside the
harness's config that must still be accepted - refusing everything would
pass the first test on its own. Each of the three arms was removed in
turn and each failed on a different path.
2026-09-02 18:35:30 -07:00
branderson 237653320f One table per config section, in the order an operator fills them in
tests / confined (config) (pull_request_target) Successful in 5m3s
tests / confined (audit) (pull_request_target) Successful in 4m14s
tests / confined (conversation) (pull_request_target) Successful in 1m3s
tests / confined (project) (pull_request_target) Successful in 3m5s
tests / confined (providers) (pull_request_target) Successful in 1m54s
tests / confined (proxy) (pull_request_target) Successful in 1m8s
tests / confined (remote) (pull_request_target) Successful in 2m11s
tests / confined (share) (pull_request_target) Successful in 1m34s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
tests / confined (static) (pull_request_target) Successful in 2m39s
tests / privileged (pull_request_target) Successful in 3m29s
Seventy rows in one table, in the order keys were added. [harness.cline]
was split across two places with the backends interleaved between them,
[ui] sat inside [core], [logging] was split around [epitaph], and nothing
distinguished a key you must set from one with a default.

It is a table per section now, each under a heading naming that section so
a row can say `harness` rather than `[core] harness`. Sections are ordered
by what a launch depends on: the three [core] selections first, then the
harness they select, then its backend, then the credential proxy, then who
the session acts as, then the forge, then the surfaces that are off until
switched on.

`required` in the Default column marks what an operator supplies. Exactly
one key is required unconditionally, and the intro says so - every other
one is conditional on a selection, and the section it sits under is what
names the condition.

[identity.<name>] gains rows at all. Its keys are computed - three of
dejima's own plus each forge's identity_keys - so they were in the schema,
settable, and documented only in a prose section further down.

The test that pins the reference against the schema follows the structure
rather than dictating it: a bare key under a heading naming its section
counts, as does a fully qualified one in the tables that cover several
sections at once. It now requires a table ROW in both cases. Matching the
key anywhere in the file let it pass with the key documented only in a
paragraph three sections away - which is the discoverability problem it
exists to catch, not an acceptable answer to it. Dropping a row for
[harness.cline] context_window passed before that and fails now.
2026-09-02 18:27:34 -07:00
branderson 4edf40f2fa Merge pull request 'Stop reporting the guards as off because they are no longer on the host' (#310) from guards-check into development
Reviewed-on: #310
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 18:25:20 -07:00
branderson def800d1be Merge pull request 'Let a model be named the way the endpoint that serves it names one' (#311) from model-id into development
Reviewed-on: #311
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 18:21:50 -07:00
branderson 103ef3f9c5 Let a model be named the way the endpoint that serves it names one
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (proxy) (pull_request_target) Successful in 53s
tests / confined (providers) (pull_request_target) Successful in 1m34s
tests / confined (shellcheck) (pull_request_target) Successful in 1m5s
tests / runner-env (confined) (pull_request_target) Successful in 40s
tests / confined (project) (pull_request_target) Successful in 2m23s
tests / confined (audit) (pull_request_target) Successful in 2m52s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (share) (pull_request_target) Successful in 6m22s
tests / confined (remote) (pull_request_target) Successful in 1m59s
tests / confined (static) (pull_request_target) Successful in 2m31s
tests / privileged (pull_request_target) Successful in 3m22s
tests / confined (config) (pull_request_target) Successful in 3m37s
[harness.cline] model was typed `identifier`, which is [A-Za-z0-9._-].
Every hosted catalogue namespaces by vendor with a slash and several
qualify a variant with a colon, so `z-ai/glm-5.3` was refused and not one
OpenRouter id could be configured at all - the backend this harness exists
to reach was unusable, and the launch said only "invalid value" without
saying which character it objected to.

A `modelid` type instead: a leading alphanumeric, then the identifier set
plus `/` and `:`. Still narrow, and for the reason `path` is rather than
for shell safety - the value is written with jq --arg, so JSON escaping is
not the concern. What it protects is that a newline or a tab would split a
record every reader of this config expects to be one line.

Every existing test said `model = m`, which is a bare identifier and
passes under either type. That is why nothing caught it. The new ones
configure real catalogue ids and check what lands in providers.json, not
just that the validator was happy - reverting the type fails them with the
exact error reported, and widening the type to accept anything fails the
half that keeps a space out.
2026-09-02 18:08:52 -07:00
branderson 3f3ddb782b Stop reporting the guards as off because they are no longer on the host
tests / confined (conversation) (pull_request_target) Successful in 49s
tests / confined (proxy) (pull_request_target) Successful in 1m0s
tests / confined (share) (pull_request_target) Successful in 1m32s
tests / confined (providers) (pull_request_target) Successful in 1m45s
tests / confined (shellcheck) (pull_request_target) Successful in 1m6s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m8s
tests / confined (project) (pull_request_target) Successful in 2m31s
tests / confined (audit) (pull_request_target) Successful in 3m0s
tests / confined (static) (pull_request_target) Successful in 2m34s
tests / privileged (pull_request_target) Successful in 3m26s
tests / confined (config) (pull_request_target) Successful in 3m36s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
Moving the hook registrations into dejima's own settings overlay left
harness_guards_registered reading the operator's ~/.claude/settings.json
and naming everything it did not find there. Nothing writes there any
more, so on a host that never ran the old installer every launch printed

  not registered for claude-code, so not in force this session:
    the session briefing
    push-guard
    merge-guard
    bash-deny
  Run ./install.sh to register them.

with all four in force, in the overlay, at their baked paths. Following
the instruction makes it permanent: install.sh's upgrade cleanup strips
exactly the registrations the check is looking for.

The check is deleted rather than repointed. What the overlay carries is
composed fresh each launch from the manifest, so reading it back would be
asking dejima whether it did what it just did; which guards a harness
cannot host at all is the manifest's, and harness_report_guards already
says it. The hook stays in the plugin interface - what a harness needs
wired on the host is a real question a future one may answer differently.

Three tests went with it, and their being green is why this shipped. All
three asserted the notice against the operator's settings.json - one that
it fires when nothing is registered there, one that it names a single
hand-dropped guard, one that it stays quiet when all four are present.
Every one of them still passed after the move, because the notice did
still fire; what changed was that firing had become wrong. Tests that
pinned where the guards used to live outlived the guards.

What replaces them asks the question the launch actually answers: with
settings.json present and dejima nowhere in it - the state a correct
install now leaves - a launch must not claim the guards are off, and the
overlay must carry all four. The second half is not optional: without it
the first passes on a launch that registered nothing anywhere.
2026-09-02 17:39:22 -07:00
branderson ae0f31079e Merge pull request 'Answer the microVM question in the threat model, where it can be contradicted' (#307) from why-not-vm into development
Reviewed-on: #307
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 17:06:10 -07:00
branderson 1e35c5c90a Merge pull request 'Say harness where the doc means harness, and backend where it means backend' (#306) from docs-prose into development
Reviewed-on: #306
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 16:47:46 -07:00
branderson bd0d5f41d0 Merge pull request 'Register the sandbox's hooks in its own settings layer, not the operator's' (#304) from hooks-overlay into development
Reviewed-on: #304
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 16:46:31 -07:00
branderson 698020693d Cut the microVM section to what a reader deciding whether to trust it needs
tests / confined (audit) (pull_request_target) Successful in 4m29s
tests / confined (config) (pull_request_target) Successful in 6m28s
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (project) (pull_request_target) Successful in 3m2s
tests / confined (providers) (pull_request_target) Successful in 1m56s
tests / confined (proxy) (pull_request_target) Successful in 1m4s
tests / confined (remote) (pull_request_target) Successful in 2m25s
tests / confined (share) (pull_request_target) Successful in 1m35s
tests / confined (shellcheck) (pull_request_target) Successful in 1m14s
tests / privileged (pull_request_target) Successful in 3m46s
tests / runner-env (confined) (pull_request_target) Successful in 52s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
tests / confined (static) (pull_request_target) Successful in 2m12s
It was the longest section in the file and buried its answer. Most readers
bounce before the end of a section, and this one's audience is someone
wondering whether the container choice was considered - not someone planning a
port. So the whole argument is now in the first two hundred words, and the
detail that only serves a port is gone: what virtiofs would cost per mount,
what a vsock forwarder would be for, which of Docker's verbs the tooling uses,
and gVisor's odds against the browser in the image.

What survives is what the question is actually about. A microVM is the stronger
boundary and this does not dispute it. Escape is the least likely of the six
and the only one needing an exploit. There is already a VM here, hardened from
outside the guest, which is where the effort went. And the three things that
would reopen the decision, so it reads as a judgement rather than a door held
shut.

#104 and #305 are links now rather than bare numbers: a reader who wants the
detail this section stopped carrying should be one click from it.

The README callout goes in the stack section rather than the docs table,
because that is where a reader is standing when the question occurs to them,
and an answer nobody finds gets asked as a question instead.
2026-09-02 14:13:10 -07:00
branderson 5d16b273be Answer the microVM question in the threat model, where it can be contradicted
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (share) (pull_request_target) Successful in 1m29s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / confined (static) (pull_request_target) Successful in 2m38s
tests / privileged (pull_request_target) Successful in 3m29s
tests / confined (config) (pull_request_target) Successful in 3m48s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
tests / confined (proxy) (pull_request_target) Successful in 59s
tests / confined (providers) (pull_request_target) Successful in 1m44s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / confined (remote) (pull_request_target) Successful in 2m10s
tests / confined (project) (pull_request_target) Successful in 2m34s
tests / confined (audit) (pull_request_target) Successful in 3m5s
The most frequently asked question about this project, and the docs answered
only half of it. "Which deployment this describes" concedes the field's
tiering and says escape moves a layer; it does not say why the effort went
below the container rather than into a stronger one, so the answer lived in
conversations rather than anywhere a reader or a sweep could reach it.

Written as an argument that can lose. It concedes the ordering outright rather
than defending a container as the better primitive, names what gets harder
under a VM as well as the one thing that gets easier, and ends with four things
that would change the answer - Kata as the cheap path, gVisor as a spike,
dropping the trusted-project assumption, and a live escape clearing this
configuration's floor.

The point the field's framing usually misses is that there is already a VM
here. The choice is not one boundary against two: it is an outer VM enforced
from the hypervisor, against that plus an inner one managed by software running
inside the blast radius of the row it is meant to bound.

static.bats pins the concession rather than the prose, because the failure mode
is a later revision quietly upgrading it into a claim that a container is as
strong - which would be false, and would read as reasonable.
2026-09-02 12:50:55 -07:00
branderson 90e32b8936 Say harness where the doc means harness, and backend where it means backend
tests / confined (conversation) (pull_request_target) Successful in 52s
tests / confined (proxy) (pull_request_target) Successful in 58s
tests / confined (share) (pull_request_target) Successful in 1m31s
tests / confined (providers) (pull_request_target) Successful in 1m42s
tests / confined (shellcheck) (pull_request_target) Successful in 1m5s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m9s
tests / confined (project) (pull_request_target) Successful in 2m32s
tests / confined (audit) (pull_request_target) Successful in 3m4s
tests / confined (static) (pull_request_target) Successful in 2m35s
tests / privileged (pull_request_target) Successful in 3m33s
tests / confined (config) (pull_request_target) Successful in 3m48s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
The README and docs still stated general properties in Claude Code's
vocabulary, from before there was a second harness or a backend axis. Some
of it was only narrow; the rest had become wrong.

Wrong, and fixed here:

The exit-time audit does not watch ~/.claude/projects. That surface was
retired when the cross-project finding was, because since #104 a session
gets its own slugs and nothing else, so the only writes visible there are
other sessions doing their own work. The README still listed it, and
omitted .vscode/ and the host-execution surfaces the harness declares.

configuration.md described Cline's model configuration in terms of a
[harness.cline] base_url that no longer exists - where the model is moved
to the backend - and said a hosted API cannot be proxied, which openrouter
is. It also told an operator to resume a Cline session on the host with
CLINE_DATA_DIR, three paragraphs above the section saying that is not a
supported path (#301), and opened Cline's parity section with "almost
nothing carries over" while the table of what carries over sat below it.

development.md said the credential proxy was Claude Code's shape
throughout. It is arguments now, which is what lets Cline reach a proxied
backend without a branch of its own.

security.md described the push and merge guards as regex over a command
string. They shadow git and the forge CLI on PATH and read argv; only
deny-dangerous-bash.sh is regex.

The README claimed hooks refuse destructive commands, flat. That needs a
hook the harness can host, and Cline hosts none - the launch already says
so, and now the README does too.

Narrow rather than wrong, and widened:

"One project's session cannot reach another's" documented one harness's
mechanism for a property both have, so it now says what the property is
and then how each harness reaches it. The Cline half is a data directory
per workspace rather than a slice of yours, which is why it clears R4 more
cleanly rather than less.

The credential is a model credential, not an Anthropic OAuth one; the
allowlisted endpoint is the selected backend's, not api.anthropic.com; the
briefing reaches a session by one of three routes rather than through a
SessionStart hook. The ~/.claude mount inventory stays Claude Code's and
now says so, with a pointer to Cline's.

Notifications are gated on a harness declaring the notify guard, which
remote-access.md did not mention - a remote-enabled Cline session gets
attach and the web terminal and no push.
2026-09-02 12:27:18 -07:00
branderson bcb360a29b Say that install.sh writes nothing, rather than that it writes one hook
tests / confined (audit) (pull_request_target) Successful in 2m57s
tests / confined (config) (pull_request_target) Successful in 3m36s
tests / confined (conversation) (pull_request_target) Successful in 54s
tests / confined (project) (pull_request_target) Successful in 2m28s
tests / confined (providers) (pull_request_target) Successful in 1m37s
tests / confined (proxy) (pull_request_target) Successful in 57s
tests / confined (remote) (pull_request_target) Successful in 2m4s
tests / confined (share) (pull_request_target) Successful in 1m28s
tests / confined (static) (pull_request_target) Successful in 2m29s
tests / confined (shellcheck) (pull_request_target) Successful in 1m6s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / runner-env (privileged) (pull_request_target) Successful in 36s
tests / privileged (pull_request_target) Successful in 3m36s
The commit that took deny-dangerous-bash.sh off the host left three places
saying otherwise: the README's install step and development.md both named
it as the one hook install.sh still writes, and install.sh's own messages
reported that no guard hooks were registered when it can no longer
register any. The block those messages sit in still needs the harness
name, but for the upgrade cleanup rather than for registration.

security.md described the tamper it guards against as unlinking one of
install.sh's hook symlinks. The tamper is unchanged and the directory is
still mounted read-only for it, but the symlinks in it are now the
operator's own.
2026-09-02 11:50:38 -07:00
branderson 707ffaaa69 Make the placeholder files in the container, not on the operator's machine
tests / confined (conversation) (pull_request_target) Successful in 54s
tests / confined (proxy) (pull_request_target) Successful in 57s
tests / confined (share) (pull_request_target) Successful in 1m31s
tests / confined (providers) (pull_request_target) Successful in 1m43s
tests / confined (shellcheck) (pull_request_target) Successful in 1m9s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / confined (remote) (pull_request_target) Successful in 2m11s
tests / confined (project) (pull_request_target) Successful in 2m31s
tests / confined (audit) (pull_request_target) Successful in 3m1s
tests / confined (static) (pull_request_target) Successful in 2m34s
tests / privileged (pull_request_target) Successful in 3m33s
tests / confined (config) (pull_request_target) Successful in 3m45s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
harness_prepare_config created an empty settings.json and CLAUDE.md in
~/.claude when the host had none, so that staging had something to copy.
A file the operator does not have is not one dejima should make on their
machine for its own convenience, and the file is needed in the container
rather than there.

emit_staged_config takes an `ensure` flag now, and the entrypoint creates
what it names - root-owned, read-only, refusing a path that could climb
out of $HOME, and leaving an existing file alone so a second launch does
not blank what was staged from the operator's own.

Two kinds, because empty is not always a valid file. settings.json asks
for `{}`: an empty one is not valid JSON, and Claude Code discards a
settings.json it cannot parse wholesale, taking every permission, hook
and plugin with it - the exact failure the validation above it exists to
catch. statusline.sh asks for neither, because a placeholder there would
be installed executable and run as the status line.

That distinction was not something I reasoned out. The test asserting the
old behaviour said in its own comment that an empty settings.json is one
Claude Code would refuse to parse, which is the only reason the first
version of this - writing an empty file for both - did not ship.

Also adds a Model backend maturity section to docs/providers.md. The
harnesses and forges each have one saying how much use they have actually
had; four backends in a table without one invites the reading that they
are equally exercised. anthropic is the one with the miles on it,
anthropic-api-key and openrouter are confirmed working rather than worn
in, and self-hosted runs no proxy at all so there is least of dejima
between the session and the endpoint. A test derives the list from what
ships, so a backend added later fails it until someone says.
2026-09-02 10:41:04 -07:00
branderson 6b8eda6ff4 Wait for the child before calling it hung
tests / confined (conversation) (pull_request_target) Successful in 52s
tests / confined (proxy) (pull_request_target) Successful in 56s
tests / confined (share) (pull_request_target) Successful in 1m30s
tests / confined (providers) (pull_request_target) Successful in 1m38s
tests / confined (shellcheck) (pull_request_target) Successful in 1m5s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / confined (static) (pull_request_target) Successful in 2m30s
tests / privileged (pull_request_target) Successful in 3m22s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
tests / confined (remote) (pull_request_target) Successful in 2m7s
tests / confined (project) (pull_request_target) Successful in 2m27s
tests / confined (audit) (pull_request_target) Successful in 2m57s
tests / confined (config) (pull_request_target) Successful in 3m39s
The pty fixture ended its read loop when the child stopped WRITING and
then required it to have already exited. Those are not the same moment:
dejima runs its exit audit and stops its shipper after the last thing it
prints, so a child that was merely busy got killed and reported as a
hang - and took SIGPIPE on a pty nobody was reading any more, which is
where the "printf: write error: Broken pipe" in the failures came from.

It waits up to a minute for the child to finish now, and only kills after
that. An unanswered prompt still ends in a kill rather than a hung suite,
which is what the kill was for.

This is why --no-pause failed intermittently on the gate and once in six
isolated runs. It was never load: it was a race between a child
finishing and a fixture deciding it never would.

Recorded because the first attempt made it worse in a useful way. Adding
the grace period without importing `time` turned an intermittent failure
into a consistent traceback, which is how the real cause became visible
at all - an intermittent test that fails for two different reasons hides
the second one behind the first.
2026-09-02 09:55:18 -07:00
branderson 2758c998ed Write nothing to the harness's config, including the last hook
tests / confined (conversation) (pull_request_target) Successful in 49s
tests / confined (proxy) (pull_request_target) Successful in 57s
tests / confined (share) (pull_request_target) Successful in 1m30s
tests / confined (providers) (pull_request_target) Successful in 1m41s
tests / confined (shellcheck) (pull_request_target) Successful in 1m6s
tests / runner-env (confined) (pull_request_target) Successful in 42s
tests / confined (remote) (pull_request_target) Successful in 2m8s
tests / confined (project) (pull_request_target) Successful in 2m31s
tests / confined (audit) (pull_request_target) Successful in 2m58s
tests / confined (static) (pull_request_target) Successful in 2m33s
tests / privileged (pull_request_target) Successful in 3m34s
tests / confined (config) (pull_request_target) Successful in 3m39s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
deny-dangerous-bash.sh was the one exception: baked nowhere, registered
in the operator's ~/.claude/settings.json, and deliberately ungated so it
applied to their own sessions too. That was dejima deciding something
about a machine outside its sandbox, which is not dejima's to decide.

It is baked and overlay-registered with the others now, so it still
blocks what it blocked inside a container and stops existing anywhere
else. An operator who wants it on their host sessions can register it
themselves - it is a hook in this repo and always was.

install.sh consequently writes nothing to ~/.claude at all: no symlink,
no registration, and no settings.json brought into existence to hold
neither. harness_register_guards registers nothing and says so; the hook
is kept because "what a harness needs on the host" is a real question a
future one may answer differently, and for Claude Code the answer is now
nothing. The upgrade cleanup takes back this hook as well.

One bug found by a test rather than by reading. Removing install.sh's
`mkdir -p ~/.claude/hooks` left nothing creating ~/.claude, and
harness_prepare_config writes a settings.json and a CLAUDE.md there - so
on a host where Claude Code had never run, a launch failed reporting a
settings.json it had just failed to create. It creates the directory it
writes into now.
2026-09-02 09:32:04 -07:00
branderson b10f5ff89f Register the sandbox's hooks in its own settings layer, not the operator's
tests / confined (conversation) (pull_request_target) Successful in 52s
tests / confined (proxy) (pull_request_target) Successful in 57s
tests / confined (share) (pull_request_target) Successful in 1m28s
tests / confined (providers) (pull_request_target) Successful in 1m44s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / runner-env (confined) (pull_request_target) Successful in 43s
tests / confined (remote) (pull_request_target) Successful in 2m9s
tests / confined (project) (pull_request_target) Successful in 2m30s
tests / confined (audit) (pull_request_target) Successful in 3m0s
tests / confined (static) (pull_request_target) Successful in 2m36s
tests / privileged (pull_request_target) Successful in 3m27s
tests / confined (config) (pull_request_target) Successful in 3m44s
tests / runner-env (privileged) (pull_request_target) Successful in 38s
Fixes #303.

install.sh symlinked dejima's hooks into ~/.claude/hooks and registered
them in ~/.claude/settings.json. Five of six no-op outside a sandbox, so
nothing misbehaved - but dejima was editing a config that is not its own
to make its own sandbox work, and "harmless because six gates say so" is
a worse claim than not doing it.

Claude Code merges the --settings overlay with the operator's settings
rather than replacing it, which is what makes the alternative possible.
The codebase already relied on that: harness_register_notify has been
writing a Stop hook into the overlay all along.

So sandbox-context.sh, git-push-guard.sh, merge-guard.sh and
dejima-notify.sh are baked into the image at /usr/local/lib/dejima/hooks
and registered per launch into the overlay by absolute path. Baked rather
than staged under $HOME: a session owns its home directory, and a guard
whose script it can unlink is not one. That is the property the read-only
~/.claude/hooks mount used to provide.

deny-dangerous-bash.sh stays where it was. It is the one hook meant to
apply to the operator's own sessions, and it already yields to an
existing install.

An upgrade takes back what an older install.sh wrote - the symlinks and
the registrations - matched by name and only when the symlink points into
this repo, so an operator's own file at one of those names is left alone.
Without that, the claim would hold only for a fresh install.

The operator's own ~/.claude/hooks is still mounted read-only, so their
hooks reach a session exactly as before.
2026-09-02 02:59:28 -07:00
branderson dda28a3864 Merge pull request 'Bring Cline's host-side user config in, the way Claude Code's already is' (#300) from cline-configs into development
Reviewed-on: #300
Reviewed-by: branderson <brad@branderson.io>
2026-09-02 02:04:32 -07:00
branderson 4202e1fea1 Say that a Cline session cannot be resumed outside dejima
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (proxy) (pull_request_target) Successful in 56s
tests / confined (share) (pull_request_target) Successful in 1m28s
tests / confined (providers) (pull_request_target) Successful in 1m37s
tests / confined (shellcheck) (pull_request_target) Successful in 1m4s
tests / confined (audit) (pull_request_target) Successful in 2m52s
tests / confined (static) (pull_request_target) Successful in 2m31s
tests / privileged (pull_request_target) Successful in 3m23s
tests / runner-env (confined) (pull_request_target) Successful in 40s
tests / confined (remote) (pull_request_target) Successful in 2m3s
tests / confined (project) (pull_request_target) Successful in 2m22s
tests / confined (config) (pull_request_target) Successful in 3m35s
tests / runner-env (privileged) (pull_request_target) Successful in 39s
Session persistence per project already works: this project's Cline state
lives on the host in a directory of its own and survives the container, so
launching dejima again picks up where the last session left off. Importing
or exporting sessions across that boundary was assessed and is not being
built (#301), so the behaviour is documented instead.

The briefing was telling agents the opposite. Core's closing carried "They
can continue this exact session outside the container by running on the
host:", which is Claude Code's fact stated as everyone's - and Cline's
fragment answered it with a CLINE_DATA_DIR incantation for driving a
host-side Cline against a directory that is dejima's rather than Cline's
own. A Cline agent reading that would send its operator somewhere not
supported.

The sentence moves into the harness fragments, where the fact belongs and
where the comment above the assembly already said it belonged. Claude Code
keeps the offer and the command. Cline says it cannot be continued outside
dejima, tells the agent not to offer it, and says what continuing does
look like - launching dejima again - because an agent told nothing will
invent something.

--harness's briefing test keyed on CLINE_DATA_DIR to tell the two apart.
It keys on what each says about resuming now, in both directions, so a
briefing carrying both would fail either way rather than passing one.

harness_state_dir is now read by no shipped fragment. Left in place: it is
documented briefing vocabulary rather than a dead manifest key, and
removing it would take cline.sh's harness_briefing_state_dir with it.
Worth a decision rather than a silent deletion.
2026-09-02 01:07:18 -07:00
branderson 785c9d34d7 Stage global rules into the directory cline actually reads
tests / confined (conversation) (pull_request_target) Successful in 1m23s
tests / confined (proxy) (pull_request_target) Successful in 1m27s
tests / confined (share) (pull_request_target) Successful in 1m58s
tests / confined (providers) (pull_request_target) Successful in 2m13s
tests / confined (shellcheck) (pull_request_target) Successful in 1m11s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / confined (remote) (pull_request_target) Successful in 2m38s
tests / confined (project) (pull_request_target) Successful in 3m0s
tests / privileged (pull_request_target) Successful in 3m23s
tests / confined (audit) (pull_request_target) Successful in 3m32s
tests / runner-env (privileged) (pull_request_target) Successful in 35s
tests / confined (static) (pull_request_target) Successful in 2m35s
tests / confined (config) (pull_request_target) Successful in 4m13s
cline loads global rules from Documents/Cline/Rules and nowhere else.
~/.agents/rules reads like the obvious companion to ~/.agents/skills and
is not loaded - planting a file in each and asking `cline config` which
it had returned only the Documents one, while Skills(1) in the same run
confirmed ~/.agents/skills IS read.

So ~/.agents/rules is supported by staging its files INTO the directory
that is read, rather than by mounting it where nothing would look at it.
Host Documents/Cline/Rules is staged the same way. Dotfiles stay the
place an operator keeps rules; the Documents path is where they have to
arrive.

File by file rather than as a directory mount, because dejima writes its
own briefing into that directory and a read-only mount over it would
leave nowhere to put the briefing.

Two collisions have fixed answers. A name in both host locations is taken
from Documents/Cline/Rules: that is cline's own location for rules and
where it writes when they are edited through cline, and staging both
would be two bind mounts at one container path. A host file named
00-dejima.md is skipped - the briefing's name is read from the manifest
rather than repeated here, and entrypoint.sh already writes the briefing
after the staged files, so staging one it overwrites is only noise.

Only .md and .txt, which is what cline reads out of a rules directory.
2026-09-01 23:59:51 -07:00
branderson 585d1c3208 Bring Cline's host-side user config in, the way Claude Code's already is
tests / confined (conversation) (pull_request_target) Successful in 1m12s
tests / confined (proxy) (pull_request_target) Successful in 1m20s
tests / confined (share) (pull_request_target) Successful in 2m2s
tests / confined (providers) (pull_request_target) Successful in 2m19s
tests / confined (shellcheck) (pull_request_target) Successful in 1m14s
tests / runner-env (confined) (pull_request_target) Successful in 50s
tests / confined (remote) (pull_request_target) Successful in 2m50s
tests / privileged (pull_request_target) Successful in 3m13s
tests / confined (project) (pull_request_target) Successful in 3m17s
tests / runner-env (privileged) (pull_request_target) Successful in 35s
tests / confined (config) (pull_request_target) Successful in 4m42s
tests / confined (audit) (pull_request_target) Successful in 3m51s
tests / confined (static) (pull_request_target) Successful in 2m53s
Cline declared no config directories at all, so none of the operator's own
configuration reached a session: no skills, no hooks, no AGENTS.md. The
mechanisms this needs already existed for claude-code, so this is three
hook implementations rather than new machinery.

Read-only mounts for ~/.agents/skills, ~/.agents/hooks and
~/.cline/hooks. Read-only is the point rather than caution: everything
there is either an instruction the agent follows or a program cline runs,
and a session that could rewrite them would be choosing what happens on
the HOST the next time cline starts outside a container - persistence for
a prompt injection, in files nobody re-reads before the next run. Scanned
for symlink targets, because on a Linux host these are routinely links
into a dotfiles checkout.

~/.agents/AGENTS.md is staged: a root-owned read-only copy. It is
instructions the agent follows, so writing the host's would choose what
the next session is told - and staging also survives it being a symlink,
which a file mount does not.

~/.cline/settings.json and cline_mcp_settings.json are seeded writable
and discarded with the container. cline rewrites both as it runs, so a
read-only copy would fail the write rather than the persistence - and the
persistence is the part that matters, because cline_mcp_settings.json
names MCP servers, which are commands cline executes.

~/.agents/rules is deliberately absent. It reads like the obvious
companion to ~/.agents/skills and cline does not load it: planting a file
there and one in ~/Documents/Cline/Rules and asking `cline config` which
it had returned only the second. Mounting a directory the harness never
reads would be a promise dejima cannot keep, so the test asserts its
absence.

Also raises the pty fixture's idle bound. Sixty seconds was enough on an
idle box and not enough under the full gate, where it killed a child that
was merely slow and reported it as a hang - the same shape as #295.
2026-09-01 23:19:44 -07:00
branderson cb31e463f9 Merge pull request 'Say where a moved key went, and stop appending a section that already exists' (#299) from startup-ux into development
Reviewed-on: #299
Reviewed-by: branderson <brad@branderson.io>
2026-09-01 20:25:28 -07:00
branderson 3e995a477a Add --no-pause, and stop offering a flag that no longer exists
tests / confined (audit) (pull_request_target) Successful in 3m7s
tests / confined (config) (pull_request_target) Successful in 3m50s
tests / confined (conversation) (pull_request_target) Successful in 51s
tests / confined (project) (pull_request_target) Successful in 2m35s
tests / confined (providers) (pull_request_target) Successful in 1m47s
tests / confined (remote) (pull_request_target) Successful in 2m14s
tests / confined (share) (pull_request_target) Successful in 1m33s
tests / confined (static) (pull_request_target) Successful in 2m49s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / privileged (pull_request_target) Successful in 3m22s
tests / runner-env (confined) (pull_request_target) Successful in 45s
tests / runner-env (privileged) (pull_request_target) Successful in 37s
tests / confined (proxy) (pull_request_target) Successful in 56s
Starting several sessions from a tmuxinator layout gives every one of
them a terminal, so the pause fires on every one, and the operator wants
them all at a prompt rather than eight keys to press. --no-pause skips
the wait and still prints the notice: skipping the wait is not skipping
the telling.

A flag rather than a config key, deliberately. It describes the terminal
in front of one launch, not a standing preference - someone who wants
eight sessions to start unattended today has said nothing about the
launch they run by hand tomorrow.

Making room for it in --help found a real bug. --base-url was listed
there and had not been parsed since the provider axis moved the model's
address onto the backend and deleted the flag. Passing it answered
"unknown option", which is the worst kind of documentation: it reads as a
bug in dejima rather than in the text. Removing it also frees the line
the help page's own budget needed, which is how the constraint earned its
keep.

So a test now cross-checks the two: every flag --help offers must be one
bin/dejima parses. It has to match a flag anywhere in a case pattern,
because --ro is the second alternative of `--extra-readonly|--ro)`.

docs/configuration.md gains a short section on what dejima says before it
starts - the pause, when it fires, and that the shared-directory list is
sampled - since none of that was written down anywhere.
2026-09-01 19:46:14 -07:00
branderson ef6939f5d3 Answer the new pause where a test drives a terminal, and never hang on one
tests / confined (conversation) (pull_request_target) Successful in 56s
tests / confined (proxy) (pull_request_target) Successful in 54s
tests / confined (providers) (pull_request_target) Successful in 1m40s
tests / confined (remote) (pull_request_target) Successful in 2m8s
tests / confined (share) (pull_request_target) Successful in 1m33s
tests / confined (shellcheck) (pull_request_target) Successful in 1m8s
tests / confined (audit) (pull_request_target) Successful in 3m9s
tests / confined (static) (pull_request_target) Successful in 2m42s
tests / runner-env (privileged) (pull_request_target) Successful in 40s
tests / confined (project) (pull_request_target) Successful in 2m37s
tests / runner-env (confined) (pull_request_target) Successful in 41s
tests / privileged (pull_request_target) Successful in 3m43s
tests / confined (config) (pull_request_target) Successful in 3m56s
Adding a prompt before the build changed what every pty-driven launch
test is typing into. Two of them were driving a different prompt and had
their first keystroke eaten by this one.

test/fixtures/answer-prompt.py answers the pause automatically. It is
ambient - every launch fixture sets [core] ssh_key, which is a
deprecation, so it fires on all of them - and it is not the prompt any of
those tests is about. static.bats's tty helper does the same with a
leading newline, in the helper rather than in six callers, so each
caller's keys still mean what they say.

And the fixture no longer hangs. It waited on the child unconditionally,
so an unanswered prompt - the likeliest way for it to end badly - blocked
waitpid forever and took the whole suite with it, silently. It kills the
child and says which it was. That is what actually happened here: the
gate ran for twenty minutes on one stuck test before I looked.
2026-09-01 19:21:07 -07:00
branderson 72599e5c2d Give the startup notices somewhere to be read, and report a bad config once
Reported from a real launch, where the notices were sandwiched between a
ninety-entry file list and the first thousand lines of a Docker build.

The orphaned-share list is a sample now. It is a standing condition an
operator clears once, and printing all of it on every launch pushed
everything about THIS run off the top of the screen. Eight entries and a
count of the rest.

And a notice earns a pause. Every line after it is the image build, so a
notice that lands there scrolls away before it can be read - the same
reason the exit audit prints its findings last. It fires only when
something was said, and only with a terminal attached: an unattended
launch must not block on a keystroke nobody will press. The share list
deliberately does not raise it, because pausing every launch until a
standing condition is cleared teaches the operator to press Enter without
looking, which is the failure the pause exists to avoid.

Separately, and pre-existing: an invalid config reported its reason once
per PARSING CONTEXT. The early validation runs suppressed and, on failure,
dropped the cache so the next caller would parse and report - but the next
caller is usually a subshell, whose cache dies with it. One duplicated
line was merely odd; with a hint under it the same message printed twenty
lines. Re-parsed in this shell instead, so the reason is printed once and
the failed status is cached where subshells inherit it. Deliberately not
an exit: flags are not parsed at that point, and someone with a broken
config is exactly who needs --help.

The pause has a positive test as well as the unattended one. Without it
the guard test passes just as well when the feature does not exist, which
is not hypothetical: an accidental `git checkout` wiped both this and the
share sampling mid-session, and only the sampling test noticed.
2026-09-01 18:37:40 -07:00
branderson 63e79d81cc Say where a moved key went, write into the section that exists, and
give the startup notices room

Three things reported from a real launch on a fresh container.

A key dejima itself moved reported only "unknown key". base_url left the
harness for the backend in the provider axis, and an operator who had it
got a message that is true and useless: it does not distinguish a typo
from a move, and the answer is in a document they have no reason to think
they need. Unknown keys dejima once accepted now say where they went, and
show the two sections to write. Kept deliberately to keys dejima moved -
a key nobody ever accepted is a typo, and guessing at what it meant is
worse than saying nothing.

The assumed_backend migration appended its own [harness.<name>] section
even when the operator already had one, leaving the same header twice. It
parses, and it reads as a mistake dejima made in someone else's file. It
writes into the existing section now, and appends only when there is
none. Inserting right after the header is safe here specifically because
the key is UNSET: there is no later assignment for a line near the top to
lose to, which is what makes editing a config file dangerous in general.
The file keeps its own permissions rather than a fresh temp file's.

And the startup notices ran together as one block: an environment
deprecation, an identity deprecation, dejima editing your config, and the
guards that are not registered, with nothing between them. Each notice
owns the blank line above it now - never below, so two firing on the same
launch cannot double up - and the migration says what it wrote with the
line picked out, because that is the one notice an operator may want to
go and look at.

The migration test pinned the old wording; it asserts the announcement
and the written line instead, and now also that exactly one section
exists, which is the reported bug.
2026-09-01 18:37:40 -07:00
branderson 2c14b10888 Merge pull request 'Stop documenting a manifest key this release deleted' (#298) from release-docs-drift into development
Reviewed-on: #298
Reviewed-by: branderson <brad@branderson.io>
2026-09-01 18:20:02 -07:00
branderson 4706a27ab2 Merge pull request 'Report the config keys a provider declares, and the backends axis' (#297) from release-pass-keys into development
Reviewed-on: #297
Reviewed-by: branderson <brad@branderson.io>
2026-09-01 18:19:36 -07:00
branderson 8350f68071 Stop documenting a manifest key this release deleted
tests / confined (conversation) (pull_request_target) Successful in 52s
tests / confined (proxy) (pull_request_target) Successful in 56s
tests / confined (share) (pull_request_target) Successful in 1m27s
tests / confined (providers) (pull_request_target) Successful in 1m40s
tests / confined (shellcheck) (pull_request_target) Successful in 1m6s
tests / runner-env (confined) (pull_request_target) Successful in 44s
tests / confined (remote) (pull_request_target) Successful in 2m9s
tests / confined (project) (pull_request_target) Successful in 2m29s
tests / confined (audit) (pull_request_target) Successful in 2m59s
tests / confined (static) (pull_request_target) Successful in 2m35s
tests / privileged (pull_request_target) Successful in 3m17s
tests / confined (config) (pull_request_target) Successful in 3m41s
tests / runner-env (privileged) (pull_request_target) Successful in 37s
Found by the release pass's documentation review, which asks whether any
document describes something that no longer exists.

proxied_api_domain was a HARNESS manifest key. The provider axis moved it
to the backend as proxied_domain, because a harness reaches whichever
endpoint it is configured for - leaving the name on the harness would
have the terminator answering for one API while the session talked to
another. The key is gone from the schema and from both harness manifests,
and docs/providers.md still had a row describing it, and
docs/development.md named it twice as something to find in
harnesses/<name>/harness.conf.

A reader following either would go looking for a key that cannot be set,
and conclude the feature was missing rather than moved.

Two smaller leftovers from the same rename: a refusal's comment cited
anthropic-console, which the two-backend consolidation removed, and a
static test was named for the provider's declared domain when the axis it
asserts on is the backend's.
2026-09-01 03:07:16 -07:00
52 changed files with 6320 additions and 1109 deletions
+22 -9
View File
@@ -100,13 +100,23 @@ locally is not a reason to stop, to hedge, or to leave a change unfinished. Run
the confined suites, open the PR, and say plainly in the PR body that the
privileged half was not run locally.
**But do not read "CI covers it" as "it passed."** That job is pinned to
`runs-on: dejima-privileged`, a label only the one configured self-hosted runner
carries — it needs the host network namespace, the Docker socket, and a shared
volume, none of which a workflow can request. If that runner is offline the job
**queues instead of failing**, and the PR sits with the runtime half neither
green nor red. Check the PR's actual checks before treating it as verified, and
if the job is still queued, say so rather than implying it ran.
**Green means it ran.** The forge does not show a check green until every job
in it has finished and passed, and `runtime.bats` is one of those jobs — so a
green PR is one where the privileged half executed. There is no state in which
the checks are green and that suite was skipped.
What a queued run looks like is yellow or grey, not green. That job is pinned
to `runs-on: dejima-privileged`, a label only the one configured self-hosted
runner carries — it needs the host network namespace, the Docker socket and a
shared volume, none of which a workflow can request — so if that runner is
offline the job **queues instead of failing**, and the PR sits unfinished
rather than passing.
So: read the colour, and say what it says. Green is verified end to end and
should be reported that way. Yellow or grey is a run that has not happened yet,
and reporting it as passing is the thing to avoid. Hedging a green one is the
opposite error and is the more common one here — it reads as doubt about a
result that is not in doubt.
If a change touches what gets mounted, whether the firewall runs, or which
credentials cross the container boundary, that runtime run is the only thing
@@ -162,7 +172,7 @@ only holds where nothing else set it. Both passed in CI and failed exactly where
the code was being worked on:
- `proxy.bats`'s cert check meant "no cert configured" by not setting
`SANDBOX_ANTHROPIC_TLS_CERT` — but `entrypoint.sh` exports it into every
`SANDBOX_CREDENTIAL_TLS_CERT` — but `entrypoint.sh` exports it into every
tls-transport session, so inside a sandbox the guard under test never fired.
- `remote.bats`'s default-port check asserted on 7681, which is the port a real
`dejima-ttyd` front door holds, so it failed on any host running the feature.
@@ -253,7 +263,10 @@ to do as a follow-on to finishing a branch. It has its own pass - suites,
security review, documentation review, and the manual checks nothing here can
run - in [docs/release.md](docs/release.md), and `test/release-pass.sh` runs
what can be run and prints the rest. If you are asked to prepare a release,
start there rather than opening the pull request first.
start there rather than opening the pull request first. When the ask is to
run the pass, the pass is the whole of it: the report is the deliverable, the
release pull request is not part of it, and you never open one unasked.
Prompt the user to create it - the report is what they decide on.
`gitea-pr` prints the base it is opening against, every time, and reads
`git config gitea.prBase` before falling back to the repository's default
+22
View File
@@ -80,6 +80,7 @@ jobs:
matrix:
suite:
- static
- launch
- project
- remote
- audit
@@ -327,9 +328,30 @@ jobs:
echo "resolves for this architecture." >&2
exit 1
}
# compose, from the same place and for a reason of the same kind: it
# is a plugin, so without it `docker compose` is not a command at
# all. Every launch on a real host goes through one, and nothing in
# CI did - so the compose file was the one input to a launch that no
# job had ever parsed.
#
# Its assets are named for `uname -m`, like the CLI tarball above and
# unlike buildx, which uses the Debian architecture name.
curl -fsSL -o /usr/local/lib/docker/cli-plugins/docker-compose \
"https://github.com/docker/compose/releases/download/v${COMPOSE_VERSION}/docker-compose-linux-$(uname -m)"
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
# Checked for the same reason buildx is: an error page chmods just as
# well as a binary, and the symptom would be a test that skips rather
# than one that fails.
docker compose version || {
echo "The compose plugin did not load, so the compose-file test will skip" >&2
echo "instead of running. Check the download URL above still resolves for" >&2
echo "this architecture." >&2
exit 1
}
env:
DOCKER_CLI_VERSION: 27.5.1
BUILDX_VERSION: 0.36.0
COMPOSE_VERSION: 5.5.1
# Fails here, with the fix in the message, rather than thirty tests deep
# in a suite that cannot work. Both of these are runner configuration,
+65 -39
View File
@@ -45,18 +45,18 @@ starts.
- **An egress allowlist.** DNS and IP, IPv4 and IPv6. Anything not on the
list does not connect, and the agent is told so.
- **Credentials that stay on the host.** Your Anthropic OAuth credential
never enters the container: a host-side proxy holds it and the container
gets a placeholder. Your SSH key doesn't either; the container sees an
agent socket, never the key.
- **Credentials that stay on the host.** Your model credential never enters
the container, whichever backend you selected: a host-side proxy holds it
and injects it per request, and the container gets a placeholder. Your SSH
key doesn't either; the container sees an agent socket, never the key.
- **Per-project declaration and approval.** A project declares the domains
and dependencies it needs in `.dejima/`. Declaring is not granting: the
approval is a separate decision you make on the host, and the approval
store is never mounted where a session could reach it.
- **One project's session cannot reach another's.** `~/.claude` is not
mounted whole. A session gets its own project's transcripts, memory and edit
history and nothing else, so it cannot read what you did elsewhere or write
into another project's memory.
- **One project's session cannot reach another's.** Your harness's state
directory is not mounted whole. A session gets its own project's
transcripts, memory and edit history and nothing else, so it cannot read
what you did elsewhere or write into another project's memory.
- **CI hardening, because push access is code execution elsewhere.** A session
opens a pull request, the workflow fires, and your runner executes that
commit before you've read a line of it. The container bounds what a session
@@ -64,12 +64,17 @@ starts.
[docs/ci.md](docs/ci.md) for what hardening a runner takes, and
[dejima-ci-hardener](https://gitbox.branderson.io/dejima/dejima-ci-hardener)
for a tool that does it.
- **Guard rails inside the session.** Hooks refuse obviously destructive
commands, pushes to anywhere but the allowed remote, and merging a PR from
inside the sandbox. These are fast-fail guards against an overeager agent,
not a boundary against a hostile one: the container is the boundary.
- **Guard rails inside the session.** Pushes to anywhere but the allowed
remote, and merging a PR from inside the sandbox, are refused whichever
harness is selected - they shadow `git` and the forge CLI on `PATH`. Refusing
an obviously destructive command needs a hook the harness can host, so a
harness without one goes without it, and the launch says so rather than
leaving you to assume. All of these are fast-fail guards against an
overeager agent, not a boundary against a hostile one: the container is the
boundary.
- **An exit-time audit** of the host surfaces a session could have written to,
so a change to your git config or `~/.claude` does not go unnoticed.
so a change to your git config, to the workspace's own agent configuration,
or to a file your harness runs on the host does not go unnoticed.
**What it gives an agent to work with:**
@@ -83,9 +88,10 @@ starts.
name - and dejima loads it alongside a briefing on where the session is and
why the limits are there. An agent that knows it is in a sandbox asks for a
domain rather than working around the firewall.
- **Config parity with your host.** `CLAUDE.md`, settings, hooks, plugins and
git identity carry over; uid, home directory and project path match on both
sides, so a session's transcript is readable from the host afterward.
- **Config parity with your host.** Your harness's own global instructions,
settings, hooks, skills, rules and plugins carry over, and so does your git
identity; uid, home directory and project path match on both sides, so a
session's transcript is readable from the host afterward.
- **Remote access, opt-in and off by default.** Attach to a live session from
a terminal or a browser, with a push notification when it wants you.
- **What a long session worked out, kept.** Each time the agent compacts, the
@@ -145,6 +151,10 @@ what each one buys, what goes wrong without it, and where each one's boundary
ends. None of them is required to run dejima; what they change is what the
layer below the container costs, and whether anyone finds out.
**→ [Why a container, and not a microVM?](docs/threat-model.md#why-a-container-and-not-a-microvm)** -
the most common question about this design, and why the effort went into the
layers below the container rather than into a harder one.
## Setup
This repo only holds the tooling; no project lives here. Point it at a project
@@ -165,18 +175,27 @@ ones you want.
[Sign in on the host first](#sign-in-on-the-host-first) - and skip it
entirely for a harness pointed at a model you serve yourself, which needs
no credential.
2. **`./install.sh`**, which symlinks the CLIs into `~/.local/bin`, writes a
starter `~/.config/dejima/config` if none exists, and registers whatever
guard hooks the harness you selected can host. Idempotent, so re-run it
after pulling; it never overwrites an existing config.
2. **`./install.sh`**, which symlinks the CLIs into `~/.local/bin` and writes
a starter `~/.config/dejima/config` if none exists. It writes nothing to
your harness's own config: the sandbox's guards are baked into the image and
registered per launch into a settings layer of dejima's own, so installing
dejima does not change how your harness behaves outside a sandbox.
Idempotent, so re-run it after pulling; it never overwrites an existing
config.
3. **Put `~/.local/bin` on your `PATH`** if it isn't already.
4. **Set `[core] harness`.** It has no default and a launch is refused without
it, which is what stops a later release changing your selection for you.
That is enough to run `dejima`, and no push credential is needed to get this
far. The rest of the starter config is commented out at its defaults, which
means `[core] forge = none` and `[core] workflow = local-only`: the agent works
in the sandbox and commits locally, and nothing is pushed anywhere.
far. Everything else runs at its default, which means `[core] forge = none` and
`[core] workflow = local-only`: the agent works in the sandbox and commits
locally, and nothing is pushed anywhere.
**Those defaults are pinned to this machine, once.** The first launch writes
them to `~/.config/dejima/defaults.conf`, which your own config overrides, so
a later release cannot move a setting you never chose. `./install.sh` adds keys
a release introduced and names any shipped default that has moved, without
taking it.
**→ [docs/configuration.md](docs/configuration.md#configuration-reference)** -
every key, its default, and what it is for. `dejima --print-config` prints the
@@ -293,8 +312,8 @@ works if the host has a credential to hold. Authenticating from inside is not
the fix: the container is where the credential deliberately never goes, and the
egress allowlist is not built around completing a sign-in flow there. The same
applies to the account state your harness keeps alongside the credential, read
fresh from the host at every launch (see "Throwaway ~/.claude.json" in
[docs/security.md](docs/security.md)).
fresh from the host at every launch (Claude Code's is "Throwaway
~/.claude.json" in [docs/security.md](docs/security.md)).
So: run your harness once on the host, sign in, confirm it answers, and then
point dejima at a project. When a credential expires, refresh it the same way,
@@ -387,9 +406,11 @@ equivalent for it.
The allowlist covers what the sandbox needs to function - DNS, the Docker host,
GitHub on port 443 for read access whichever forge is selected, whatever the
selected forge needs, the harness's own update and model endpoints, and
`api.anthropic.com` when the credential proxy is off - plus whatever a project
has declared and had approved.
selected forge needs, the harness's own update endpoints, and the selected
backend's API endpoint when the credential proxy is off - plus whatever a
project has declared and had approved. With the proxy on that last name is
deliberately absent: the session reaches the API through the in-container
terminator rather than by resolving it.
DNS is allowlisted as well as IPs: a local resolver only forwards lookups for
names already on that same allowlist, so an unapproved domain does not resolve
@@ -438,17 +459,22 @@ exact command to hand you.
tarball dependencies, the symlink refusal that protects the approval store,
and the complete `dejima-allow`/`dejima-dep`/`dejima-project` reference.
## Config parity with your host Claude Code setup
## Config parity with your host harness setup
Global `CLAUDE.md`, settings, hooks, skills, plugins and git identity all carry
over, and your existing login stays effective, with the credential itself never
entering the container. `~/.claude` is not shared as a whole - only an
enumerated subset does, so a session transcript is readable from the host
afterward but a credential or cache isn't. The container's own user matches
yours exactly, so `$HOME`-relative paths resolve the same on both sides.
Your harness's own global instructions, settings, hooks, skills, rules and
plugins carry over, along with your git identity, and your existing login stays
effective with the credential itself never entering the container. The
harness's config directory is not shared as a whole - only an enumerated subset
is, so a session transcript is readable from the host afterward but a
credential or cache isn't. The container's own user matches yours exactly, so
`$HOME`-relative paths resolve the same on both sides.
Which files those are is each harness's own question, answered in its plugin:
`~/.claude` for Claude Code, `~/.agents` and `~/.cline` for Cline.
**→ [docs/configuration.md](docs/configuration.md)** - exactly what carries
over and what doesn't, and why single-file mounts couldn't be trusted here.
over and what doesn't, per harness, and why single-file mounts couldn't be
trusted here.
## Shared scratch space
@@ -525,9 +551,9 @@ what a forwarded personal agent changes, and the persistent alternative.
Before each run, dejima snapshots the host surfaces a session could write to
and persist through: `.git/config` keys that run a command on the next `git`,
`.git/hooks/`, the workspace's `.claude/`, `.mcp.json`, `.envrc`, and writes
under `~/.claude/projects`. After the container exits it diffs them and tells
you what changed.
`.git/hooks/`, the workspace's `.claude/` and `.vscode/`, `.mcp.json`, `.envrc`,
and any host-side file the selected harness declares as one it runs by itself.
After the container exits it diffs them and tells you what changed.
It is **advisory, not a block**, firing after the session has ended, so a
finding is something to clean up before your next `git` command or session in
+691 -54
View File
File diff suppressed because it is too large Load Diff
+59 -5
View File
@@ -268,6 +268,59 @@ if [ "$session_wanted" -eq 1 ]; then
[ -n "$container" ] || container="${containers%%$'\t'*}"
fi
# The dnsmasq and the ipsets are not in the session's container. They are
# in the filter container that owns its network namespace, which is what
# keeps a session from reaching either. So everything that CHANGES the
# allowlist below runs there, and only the reachability check at the end
# runs in the session's own container - because that is the container whose
# reachability this command claims to have changed.
#
# Both are derived from whichever one the caller named, rather than
# recorded anywhere: Docker already knows the pairing, because joining a
# namespace is how the pair is built.
#
# Naming either half has to work, and not as a convenience. A session that
# is asked for its own container id reads /etc/hostname, and Docker names a
# container that JOINED another's network namespace after the container it
# joined - so the id in a briefing, the one an agent hands its operator, is
# the filter container's. Nothing about the pair is worth making an
# operator hold in their head to type one command.
mode="$(docker inspect -f '{{.HostConfig.NetworkMode}}' "$container" 2>/dev/null)" || mode=""
case "$mode" in
container:*)
# A session container: it names its own filter.
filter="${mode#container:}"
;;
*)
# Then it is a filter container, or not part of a pair at all.
# `docker exec` takes a name or an id; NetworkMode reports the id,
# so the search below compares ids.
filter_id="$(docker inspect -f '{{.Id}}' "$container" 2>/dev/null)" || filter_id=""
session=""
if [ -n "$filter_id" ]; then
while IFS=' ' read -r _id _mode; do
[ "$_mode" = "container:$filter_id" ] || continue
session="$_id"
break
done < <(docker ps -q 2>/dev/null | xargs -r docker inspect \
-f '{{.Id}} {{.HostConfig.NetworkMode}}' 2>/dev/null)
fi
if [ -z "$session" ]; then
echo "$container is neither a running session nor the filter container of" >&2
echo "one, so there is no allowlist to add this domain to." >&2
echo "" >&2
echo "A session's own id is in its startup context, or from 'cat /etc/hostname'" >&2
echo "inside it - either half of the pair is accepted here. If the session has" >&2
echo "already exited, record the domain for the next one instead:" >&2
echo "" >&2
echo " dejima-allow --project $domain" >&2
exit 1
fi
filter="$container"
container="$session"
;;
esac
# The DNS proxy (dns-proxy.sh) NXDOMAINs anything not in its allowlist, so
# this has to happen *before* resolving the domain below - otherwise the dig
# right after this would itself get blocked. Append a server= line to
@@ -277,15 +330,16 @@ if [ "$session_wanted" -eq 1 ]; then
# single-quoted heredoc) rather than interpolated into the script text - it's
# validated above, but this keeps it that way even if the validation regex
# above is ever loosened later.
docker exec -u root "$container" bash -c '
docker exec -u root "$filter" bash -c '
domain="$1"
entry="server=/${domain}/127.0.0.11"
grep -qxF "$entry" /etc/dnsmasq-sandbox-servers.conf 2>/dev/null || echo "$entry" >> /etc/dnsmasq-sandbox-servers.conf
kill -HUP "$(cat /var/run/dnsmasq-sandbox.pid)"
' -- "$domain"
echo "Resolving $domain inside $container..."
ips=$(docker exec "$container" dig +short A "$domain" | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' || true)
# Named for where the lookup happens, which is where the DNS allowlist is.
echo "Resolving $domain in $filter, this session's egress control..."
ips=$(docker exec "$filter" dig +short A "$domain" | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' || true)
if [ -z "$ips" ]; then
# An internally-routed name can't be added to a *running* session at
# all: dnsmasq's stop-dns-rebind drops a private answer for any domain
@@ -294,7 +348,7 @@ if [ "$session_wanted" -eq 1 ]; then
# script SIGHUPs carries server= lines and nothing else. Asking the
# upstream resolver directly separates that dead end from a name that
# simply doesn't resolve, so the message can name the fix that works.
upstream=$(docker exec "$container" dig +short A "$domain" @127.0.0.11 2>/dev/null |
upstream=$(docker exec "$filter" dig +short A "$domain" @127.0.0.11 2>/dev/null |
grep -E '^(10\.|127\.|169\.254\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.)' || true)
if [ -n "$upstream" ]; then
echo "$domain resolves to a private address (${upstream//$'\n'/ }), which the" >&2
@@ -320,7 +374,7 @@ if [ "$session_wanted" -eq 1 ]; then
target_set=$(ipset_for_domain "$domain")
for ip in $ips; do
echo "Allowing $ip ($domain -> $target_set)"
docker exec -u root "$container" ipset add "$target_set" "$ip" -exist
docker exec -u root "$filter" ipset add "$target_set" "$ip" -exist
done
echo "$domain allowed for the running session ($container)."
+168 -5
View File
@@ -53,6 +53,7 @@ core.known_hosts path ~/.ssh/known_hosts
github.token_file path ~/.config/gh/sandbox-token
mounts.readonly ?list:path
mounts.read_write ?list:path
mounts.read_write_per_project ?list:path
mounts.nvim_config ?path
credentials.proxy bool on
credentials.transport enum:tls|loopback tls
@@ -165,6 +166,30 @@ _config_keys() {
_config_extra_keys
}
# A key that used to exist and now lives somewhere else.
#
# "unknown key" is true and useless on its own: an operator who wrote a key
# dejima once accepted has no way to tell a typo from a move, and the answer
# is in a document they have no reason to think they need. A rename that
# ships without this costs every operator who had the old key the same search.
#
# Keep this to keys that dejima ITSELF moved. A key nobody ever accepted is a
# typo, and guessing at what it was meant to be is worse than saying nothing.
_config_moved_hint() { # <section> <key>
local section="$1" key="$2"
case "$section.$key" in
harness.*.base_url|harness.*base_url)
printf ' Where the model is belongs to the backend now, not the harness.\n' >&2
printf ' For one you serve yourself:\n\n' >&2
printf ' [harness.%s]\n backend = self-hosted\n\n' \
"${section#harness.}" >&2
printf ' [backend.self-hosted]\n base_url = ...\n\n' >&2
printf ' A hosted API is a backend of its own instead, which carries its own\n' >&2
printf ' address - see docs/providers.md, "Model backends".\n' >&2
;;
esac
}
config_root() {
printf '%s' "${DEJIMA_CONFIG_DIR:-$HOME/.config/dejima}"
}
@@ -173,6 +198,17 @@ config_path() {
printf '%s/config' "$(config_root)"
}
# The pinned defaults, beside the operator's own file rather than under
# ~/.local/share. It explains the file next to it, and the answer to "why is
# this value what it is" belongs where someone would look for it.
#
# Machine-written, and the operator is told not to edit it - which is why the
# layer it produces is parsed leniently (see _config_parse_defaults) where
# theirs is not.
config_defaults_path() {
printf '%s/defaults.conf' "$(config_root)"
}
# ---------------------------------------------------------------------------
# Dependency specs
#
@@ -371,6 +407,25 @@ _config_valid_value() {
identifier)
[[ "$value" =~ ^[A-Za-z0-9._-]+$ ]]
;;
modelid)
# A model's name at whatever endpoint serves it, which is not an
# identifier: every hosted catalogue namespaces by vendor with a
# slash (`z-ai/glm-5.3`) and several qualify a variant with a colon
# (`deepseek/deepseek-r1:free`, `llama3:8b`), and Anthropic
# brackets a context variant (`claude-opus-5[1m]`). Typed
# `identifier`, not one OpenRouter id could be configured at all,
# so the backend this harness exists to reach was unusable; the
# first fix for that missed the brackets, which is why the set
# below is the union of what real catalogues spell rather than
# what the last reported id needed.
#
# Still narrow, and for the same reason `path` is: this reaches an
# agent's configuration file. It is written there with jq --arg, so
# the JSON escaping is not what this is protecting - what it
# protects is that a value carrying a newline or a tab would split
# a record every reader of this config expects to be one line.
[[ "$value" =~ ^[A-Za-z0-9][][A-Za-z0-9._:/-]*$ ]]
;;
jsonfield)
# Which value inside a credentials file is the key: dot-separated
# object names, nothing else. No array indices and no jq syntax,
@@ -469,12 +524,21 @@ _config_trim_into() {
# place; nothing shipped does that today (install.sh writes the file but never
# reads a value back).
declare -gA _CFG_VAL=() _CFG_SEEN=()
# The pinned layer, in arrays of its own rather than pre-seeded into the two
# above. Keeping them apart is what lets config_is_set keep meaning "the
# operator wrote this": a base file naming every key would otherwise answer
# yes for all of them, and every caller of it means the operator.
declare -gA _CFG_BASE_VAL=() _CFG_BASE_SEEN=()
_CFG_BASE_STALE=0
_CFG_PARSED_PATH=""
_CFG_PARSE_STATUS=1
config_reset() {
_CFG_VAL=()
_CFG_SEEN=()
_CFG_BASE_VAL=()
_CFG_BASE_SEEN=()
_CFG_BASE_STALE=0
_CFG_PARSED_PATH=""
_CFG_PARSE_STATUS=1
}
@@ -485,6 +549,16 @@ config_validate() {
if [ "$_CFG_PARSED_PATH" = "$conf" ]; then
return "$_CFG_PARSE_STATUS"
fi
# Cleared here rather than by each parser, so that neither one's
# correctness rests on the other having tidied up first. Seeding the
# pinned layer into the operator's arrays would then be a bug that
# SHOWS, instead of one the following parse happens to wipe.
_CFG_VAL=(); _CFG_SEEN=()
_CFG_BASE_VAL=(); _CFG_BASE_SEEN=(); _CFG_BASE_STALE=0
# The pinned layer first, so a value read during the operator's own parse
# resolves the same way one read afterwards does. It cannot fail the
# validation: nothing an operator can fix lives in it.
_config_parse_defaults "$(config_defaults_path)"
# $? captured before anything else runs - an assignment would reset it to
# 0 and cache every malformed config as valid.
_config_parse "$conf"
@@ -495,8 +569,6 @@ config_validate() {
_config_parse() {
local conf="$1" line section="" key value type
_CFG_VAL=()
_CFG_SEEN=()
if [ ! -f "$conf" ]; then
echo "no dejima config at $conf" >&2
return 1
@@ -532,6 +604,7 @@ _config_parse() {
_config_trim_into value "${line#*=}"
if ! _config_type_into type "$section.$key"; then
echo "unknown key in $conf: [$section] $key" >&2
_config_moved_hint "$section" "$key"
return 1
fi
if ! _config_valid_value "$type" "$value"; then
@@ -560,6 +633,65 @@ _config_parse() {
# Expands a leading "~" to $HOME, per element for a list type. Only for path
# types: a tilde inside a URL is a legal path character and must survive.
# The pinned layer. Same grammar as the operator's file and a different
# answer to everything wrong with it: skip the line and carry on, rather than
# refuse the launch.
#
# That is not leniency for its own sake. An unknown key here is a key dejima
# RETIRED, on a machine whose defaults.conf predates the release that dropped
# it - the operator did not write it and is told not to edit the file, so
# refusing would leave them a launch that will not start and nothing to do
# about it. The schema answers for anything skipped, and the count is reported
# once with the command that rebuilds the file.
#
# Absent is not an error either. A checkout that has never been launched has
# no pinned layer, and the schema is the right answer for every key until
# there is one.
_config_parse_defaults() {
local conf="$1" line section="" key value type skipped=0
[ -f "$conf" ] || return 0
while IFS= read -r line || [ -n "$line" ]; do
_config_trim_into line "$line"
case "$line" in
''|'#'*|';'*) continue ;;
'['*']')
section="${line#\[}"
section="${section%\]}"
_config_trim_into section "$section"
if ! _config_section_known "$section"; then
# Its keys are skipped with it: an unknown section is one
# whose provider is gone, and every key under it names
# something that no longer exists.
section=""
skipped=$((skipped + 1))
fi
continue ;;
*=*) ;;
*) skipped=$((skipped + 1)); continue ;;
esac
[ -n "$section" ] || { skipped=$((skipped + 1)); continue; }
_config_trim_into key "${line%%=*}"
_config_trim_into value "${line#*=}"
if ! _config_type_into type "$section.$key"; then
skipped=$((skipped + 1)); continue
fi
if ! _config_valid_value "$type" "$value"; then
skipped=$((skipped + 1)); continue
fi
_CFG_BASE_VAL["$section.$key"]="$value"
_CFG_BASE_SEEN["$section.$key"]=1
done < "$conf"
_CFG_BASE_STALE="$skipped"
return 0
}
# How many lines of the pinned layer this process could not use. Read by the
# launch, which says so once with the command that rebuilds it.
config_defaults_stale() {
config_validate >/dev/null 2>&1 || true
printf '%s' "${_CFG_BASE_STALE:-0}"
}
_config_expand() {
local type="$1" value="$2" element out=""
case "$type" in
@@ -597,8 +729,14 @@ _config_get_from_file() {
return 1
fi
config_validate || return 1
# Operator, then what this machine pinned, then the schema. The schema is
# reachable only for a key the pinned layer has no line for - a fresh
# install, or one added since the last ./install.sh - which is the one
# case where dejima's current answer is the right one.
if [ -n "${_CFG_SEEN[$section.$want]+x}" ]; then
found="${_CFG_VAL[$section.$want]}"
elif [ -n "${_CFG_BASE_SEEN[$section.$want]+x}" ]; then
found="${_CFG_BASE_VAL[$section.$want]}"
else
found="$(config_default "$section.$want")"
fi
@@ -611,9 +749,18 @@ _config_get_from_file() {
config_get() { _config_get_from_file "$@"; }
# config_is_set <section> <key>
# Whether the key APPEARS in the config file, as distinct from having a
# value: a key with a schema default always has a value, so "has a value" is
# the wrong question for anything asking what the operator configured.
# Whether the key APPEARS in the OPERATOR'S config file, as distinct from
# having a value: a key with a schema default always has a value, so "has a
# value" is the wrong question for anything asking what the operator
# configured.
#
# The pinned layer is deliberately not consulted, and this is the whole reason
# it lives in arrays of its own. Every caller here means "did the operator
# write this" - the [core] ssh_key / [identity.default] ssh_key refusal fires
# only when both are present, identity settings take precedence over a forge's
# only when the identity names one, and the ttyd knobs treat unset as "the
# page decides from the pointer type", which no host-wide value can see. A
# defaults.conf naming every key would answer yes to all of them.
config_is_set() {
local section="$1" want="$2" _t
if ! _config_type_into _t "$section.$want"; then
@@ -625,6 +772,22 @@ config_is_set() {
[ -n "${_CFG_SEEN[$section.$want]+x}" ]
}
# Which layer answered for a key: user, default (this machine's pinned value)
# or schema (nothing has pinned it yet). What --print-config prints beside a
# value, and the fastest answer to "why is this what it is".
config_origin() {
local section="$1" want="$2" _t
_config_type_into _t "$section.$want" || return 1
config_validate || return 1
if [ -n "${_CFG_SEEN[$section.$want]+x}" ]; then
printf 'user'
elif [ -n "${_CFG_BASE_SEEN[$section.$want]+x}" ]; then
printf 'default'
else
printf 'schema'
fi
}
config_get_bool() {
local value
value="$(config_get "$1" "$2")" || return 1
+166 -4
View File
@@ -28,6 +28,7 @@ import sys
import tempfile
import threading
import time
import zlib
from http.server import BaseHTTPRequestHandler
from urllib.parse import urlsplit
@@ -234,6 +235,102 @@ class BodyTooLarge(Exception):
answered as if the session had merely sent too much."""
# What an upstream error body says, as text fit to put on a terminal.
#
# Two things stand between the bytes and the log. The client's own
# Accept-Encoding is forwarded verbatim - a Node harness asks for gzip - so
# what comes back is compressed, and the first version wrote those bytes
# straight out: mojibake on the operator's terminal and a bash warning about
# a null byte in a command substitution. And whatever the encoding, this is
# upstream-controlled text landing where dejima-audit already refuses to put
# session-controlled text unescaped.
#
# So: decompress what the stdlib can, then keep only printable characters.
# The sanitising is the half that has to hold - it is not conditional on
# recognising the encoding, and an unknown one degrades to a note rather than
# to bytes.
def _brotli_decompress(raw):
"""A brotli decoder if the host has one, else None.
Optional on purpose. This runs on the host as the operator's user, and a
diagnostic is not worth a hard dependency on a module Debian ships
separately - so a host without it gets a note naming what to install
rather than a launch that refuses.
Not solved by asking the API for an encoding this can read: the request
the API sees is deliberately the harness's own header block, byte for
byte, and Accept-Encoding is part of what makes a session look like a
stock install. Rewriting it to make a log line readable trades a property
the sandbox is for against a convenience.
"""
for name in ("brotli", "brotlicffi"):
try:
mod = __import__(name)
except ImportError:
continue
try:
# A bounded prefix is a partial stream. The one-shot decompress
# wants a whole one, so this is the incremental decoder in both
# modules - and a prefix that ends mid-symbol yields what it can.
return mod.Decompressor().process(raw)
except Exception:
return None
return None
def _readable(raw, encoding):
enc = (encoding or "").strip().lower()
if enc in ("gzip", "x-gzip", "deflate"):
try:
# A bounded prefix is a partial stream, so decompressobj rather
# than gzip.decompress, which wants a whole member.
wbits = 16 + zlib.MAX_WBITS if enc != "deflate" else zlib.MAX_WBITS
raw = zlib.decompressobj(wbits).decompress(raw)
except zlib.error:
return "(%d bytes, %s, undecodable)" % (len(raw), enc)
elif enc == "br":
decoded = _brotli_decompress(raw)
if decoded is None:
return ("(%d bytes, br-encoded - no brotli module on this host, so "
"the message cannot be read here; pip install brotli, or "
"apt install python3-brotli)" % len(raw))
raw = decoded
elif enc:
# zstd and anything else. Saying which is more use than printing the
# bytes, and printing the bytes is what this exists to stop.
return "(%d bytes, %s-encoded)" % (len(raw), enc)
# Decodes only. Making the text fit for a terminal is _diag's, so that
# every producer is covered rather than this one path.
return raw.decode("utf-8", "replace").strip()
# One line, timestamped, appended. Falls back to stderr when the file cannot
# be written rather than losing the message: a diagnostic that disappears
# because the thing that reports problems had a problem is the worst kind.
def _diag(path, line):
# Sanitised at the sink, not at each producer. bin/dejima prints this file
# to the operator's terminal after a session ends, so it is a terminal-
# bound channel carrying text chosen by an upstream API and, through the
# request path and exception messages, by the session itself. That is the
# hazard docs/security.md describes for audit findings, which are
# hex-encoded for it.
#
# Nothing gets through today - CPython's request-line parser and
# http.client both refuse a control character in a URL, and both repr what
# they refuse - but that is two coincidences rather than a property, and
# neither of them covers a producer added later.
line = "".join(c if c.isprintable() or c == " " else " " for c in str(line))
stamped = "%s %s\n" % (time.strftime("%H:%M:%S"), line)
if path:
try:
with open(path, "a") as fh:
fh.write(stamped)
return
except OSError:
pass
sys.stderr.write(stamped)
class Handler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
@@ -241,7 +338,13 @@ class Handler(BaseHTTPRequestHandler):
pass # per-request lines would interleave with the session's own UI
def log_error(self, fmt, *args):
sys.stderr.write("dejima-credential-proxy: " + fmt % args + "\n")
_diag(getattr(self.server, "diag_path", None),
"dejima-credential-proxy: " + fmt % args)
# How much of an upstream error body is worth keeping. An API's rejection
# is a short JSON object; anything longer is not one, and this runs on the
# host with the session on the other end of it.
MAX_DIAG_BODY = 2048
# Capped, because the client is the sandboxed session and this runs on the
# host as the operator's user. Every other session-controlled size in this
@@ -401,8 +504,51 @@ class Handler(BaseHTTPRequestHandler):
"see host terminal",
log_message="upstream request failed: %s" % e)
try:
self.send_response(resp.status)
length = resp.getheader("Content-Length")
# An upstream rejection, said out loud. The proxy is the only
# thing that sees both the request the session made and the answer
# the API gave, and it used to forward a 4xx verbatim and record
# nothing - so a session that "spun for a bit and gave an error"
# left the operator with no way to find out why. It is not the
# container's job to explain: the harness shows whatever it shows.
#
# Read whole only when upstream declared a small length. A
# streaming or oversized body is logged by status alone rather
# than buffered here, which keeps this off the success path
# entirely - a 200 never gets read into memory.
early = None
if resp.status >= 400:
# Read a bounded prefix whatever the framing. The first
# version did this only where upstream declared a small
# Content-Length, and the first real rejection it caught -
# three 429s from a rate-limited account - recorded the status
# and nothing else, which is the half an operator cannot act
# on. read1 returns what has arrived rather than waiting for a
# full buffer, so this costs one chunk and is forwarded below
# before the stream continues normally.
early = resp.read1(self.MAX_DIAG_BODY)
detail = _readable(early, resp.getheader("content-encoding"))
# The headers carry more than the body does, which is not a
# guess: a real rate-limited call came back
# {"type":"rate_limit_error","message":"Error"} - the word
# Error and nothing else. request-id is what Anthropic support
# asks for, and retry-after is the only thing that says how
# long; neither is in the body, and a reader should not have to
# know to go looking for them.
#
# Deliberately not the account and workspace ids the same
# response carries. They identify the operator's org, this
# line gets pasted into bug reports, and request-id is enough
# to find the request from the other side.
extra = ""
for name in ("request-id", "retry-after"):
value = resp.getheader(name)
if value:
extra += " %s=%s" % (name, value)
self.log_error("upstream answered %s for %s%s%s",
resp.status, self.path, extra,
" " + detail if detail else "")
self.send_response(resp.status)
for k, v in resp.getheaders():
if k.lower() in HOP_BY_HOP or k.lower() in ("content-length", "date", "server"):
continue
@@ -416,6 +562,12 @@ class Handler(BaseHTTPRequestHandler):
self.send_header("Connection", "close")
self.end_headers()
self.wfile.flush()
if early:
# Already read for the log above; written out before the loop
# picks up where it left off, so the session receives the same
# bytes in the same order whether or not anything was logged.
self.wfile.write(early)
self.wfile.flush()
# Stream response body, flushing after each chunk for unbuffered delivery.
# Use read1() to get partial reads immediately rather than waiting for
# a full buffer or EOF, ensuring SSE events stream unbuffered. HTTPResponse.read1()
@@ -440,10 +592,11 @@ class Handler(BaseHTTPRequestHandler):
class ProxyServer(socketserver.ThreadingMixIn, socketserver.UnixStreamServer):
daemon_threads = True
def __init__(self, socket_path, upstream, creds, auth):
def __init__(self, socket_path, upstream, creds, auth, diag_path=None):
self.upstream = upstream
self.creds = creds
self.auth = auth
self.diag_path = diag_path
super().__init__(socket_path, Handler)
def get_request(self):
@@ -496,6 +649,14 @@ def main():
p.add_argument("--oauth-endpoint")
p.add_argument("--oauth-client-id")
p.add_argument("--refresh-margin", type=int, default=300)
# Where diagnostics go. A file rather than stderr, because stderr here is
# the operator's terminal and the session owns it: a line written mid-run
# lands in the middle of whatever the harness is drawing. bin/dejima reads
# this back after the container exits, alongside the exit audit.
#
# Absent, they go to stderr, which is what a proxy run by hand wants.
p.add_argument("--log", default=None,
help="append diagnostics here instead of stderr")
args = p.parse_args()
if "{token}" not in args.auth_format:
@@ -543,7 +704,8 @@ def main():
if os.path.exists(args.socket):
os.unlink(args.socket)
server = ProxyServer(args.socket, urlsplit(args.upstream), creds, auth)
server = ProxyServer(args.socket, urlsplit(args.upstream), creds, auth,
diag_path=args.log)
try:
server.serve_forever()
except KeyboardInterrupt:
+19 -2
View File
@@ -392,9 +392,26 @@ harness_config_dirs_load() {
DEJIMA_STAGED_CONFIG=()
# host path, and the path under $HOME it is installed at.
# `ensure` asks for a placeholder at that path in the container when the host
# has none, so a harness that needs a file to exist gets one without dejima
# creating it on the operator's machine.
#
# Two kinds, because empty is not always a valid file. `ensure` writes nothing;
# `ensure-json` writes `{}`, and settings.json needs that one - an empty file
# is not valid JSON, and Claude Code discards a settings.json it cannot parse
# wholesale, taking every permission, hook and plugin the operator configured
# with it.
#
# Opt-in per file rather than implied: an empty statusline.sh would be
# installed executable and run as the status line, so that one stays absent.
emit_staged_config() {
local src="$1" rel="$2"
local src="$1" rel="$2" ensure="${3:-}"
[ -n "$src" ] && [ -n "$rel" ] || return 0
case "$ensure" in
''|ensure|ensure-json) ;;
*) echo "Harness plugin emitted an invalid staged-config flag: $ensure" >&2
exit 1 ;;
esac
# The relative path becomes a location under $HOME inside the container.
# Anything that could climb out of it, or that is not relative at all, is
# a plugin bug rather than something to normalise quietly.
@@ -403,7 +420,7 @@ emit_staged_config() {
echo "Harness plugin emitted an invalid staged-config path: $rel" >&2
exit 1 ;;
esac
DEJIMA_STAGED_CONFIG+=("$src"$'\t'"$rel")
DEJIMA_STAGED_CONFIG+=("$src"$'\t'"$rel"$'\t'"$ensure")
}
harness_staged_config_load() {
+187 -7
View File
@@ -914,6 +914,174 @@ _identity_key_specs() {
done
}
# The pinned defaults file, rendered. Every key that HAS a default, at the
# value this release ships, grouped by section.
#
# Keys with no default are deliberately absent, because there is nothing to
# pin: they are the ones an operator must supply, and "has no line in
# defaults.conf" is exactly what docs/configuration.md marks as required. The
# document and the file agree by construction rather than by someone keeping
# them in step.
#
# EVERY installed provider, not only the selected one. Pinning just the
# harness in use would leave the next one an operator selects handing them
# ITS current defaults - the same failure one axis over, a year later, when
# nothing about their config changed.
# $1: "keep" to take a value already pinned in defaults.conf over the shipped
# one, which is what a rebuild does - it adds keys and drops retired ones
# without moving anything already decided. Empty renders the shipped defaults,
# which is what a first pin does.
config_defaults_render() {
local keep="${1:-}" key type default axis name spec section last=""
printf '# dejima'"'"'s own defaults, pinned when this machine first saw each key.\n'
printf '#\n'
printf '# NOT yours to edit - ./install.sh rewrites it, keeping the values already\n'
printf '# here so a release cannot move a setting you never chose. Put your own\n'
printf '# settings in %s, which overrides everything below and which\n' "$(config_path)"
printf '# dejima never writes.\n'
while IFS= read -r key; do
[ -n "$key" ] || continue
default="$(config_default "$key")" || continue
[ -n "$default" ] || continue
[ "$keep" = keep ] && [ -n "${_CFG_BASE_SEEN[$key]+x}" ] \
&& default="${_CFG_BASE_VAL[$key]}"
section="${key%.*}"
[ "$section" = "$last" ] || { printf '\n[%s]\n' "$section"; last="$section"; }
printf '%s = %s\n' "${key##*.}" "$default"
done < <(_config_keys_core_sorted)
for axis in forge harness backend; do
while IFS= read -r name; do
[ -n "$name" ] || continue
last=""
for spec in $(_provider_keys_field "$axis" "$name" 2>/dev/null); do
IFS=$'\t' read -r key type default <<< "$(_provider_keyspec_parse "$spec")"
[ -n "$default" ] || continue
[ "$keep" = keep ] && [ -n "${_CFG_BASE_SEEN[$axis.$name.$key]+x}" ] \
&& default="${_CFG_BASE_VAL[$axis.$name.$key]}"
[ -n "$last" ] || { printf '\n[%s.%s]\n' "$axis" "$name"; last=1; }
printf '%s = %s\n' "$key" "$default"
done
done < <(provider_list "$axis" 2>/dev/null)
done
}
# The core schema's keys with their sections kept together, so the rendered
# file groups rather than repeating a header per key. The schema's own order
# is otherwise preserved: it is the order docs/configuration.md follows.
_config_keys_core_sorted() {
local key member seen=" " sect
local -a keys=()
while IFS= read -r key; do
[ -n "$key" ] || continue
keys+=("$key")
done < <(_config_table | cut -f1 | grep -E '^[a-z-]+\.[a-z_]+$')
for key in "${keys[@]}"; do
sect="${key%.*}"
case "$seen" in *" $sect "*) continue ;; esac
seen="$seen$sect "
for member in "${keys[@]}"; do
[ "${member%.*}" = "$sect" ] && printf '%s\n' "$member"
done
done
}
# Rebuild the pinned file: keys this release added appended, keys it retired
# dropped, and every value already decided left exactly as it was.
#
# Both halves fall out of rendering with "keep" rather than being two rules
# somebody has to remember, and pruning is not the tidier half: an unknown key
# is one this dejima cannot read, so a file that only ever grew would collect
# them until the notice about it became permanent.
#
# Prints what it did, and what has drifted - a shipped default that no longer
# matches the pinned one - naming both values and the line that would adopt
# it. It does not adopt it. That would be dejima writing a decision into a
# session's behaviour on an upgrade, which is the thing this exists to stop.
config_defaults_rebuild() {
local path tmp key section leaf pinned shipped
local added=0 dropped=0 drifted=0
path="$(config_defaults_path)"
_config_parse_defaults "$path"
dropped="$_CFG_BASE_STALE"
mkdir -p "$(dirname "$path")" || return 1
tmp="$(mktemp "$path.XXXXXX")" || return 1
config_defaults_render keep > "$tmp" || { rm -f "$tmp"; return 1; }
chmod 600 "$tmp"
# Counted from the rendered file rather than guessed at: a key with no
# line in the old one is a key this release added.
while IFS= read -r key; do
[ -n "${_CFG_BASE_SEEN[$key]+x}" ] || added=$((added + 1))
done < <(_config_defaults_keys "$tmp")
if [ ! -e "$path" ]; then
mv "$tmp" "$path" || { rm -f "$tmp"; return 1; }
printf '\nPinned this release'"'"'s defaults in %s.\n' "$path"
return 0
fi
mv "$tmp" "$path" || { rm -f "$tmp"; return 1; }
# Each line carries the blank one before it, so a rebuild with nothing to
# say prints nothing at all rather than a gap where a message would go.
[ "$added" -eq 0 ] || printf '\nPinned %s new default(s) in %s.\n' "$added" "$path"
[ "$dropped" -eq 0 ] || printf '\nDropped %s retired line(s) from %s.\n' "$dropped" "$path"
# Drift, last, because it is the part that asks something of the operator.
while IFS= read -r key; do
[ -n "${_CFG_BASE_SEEN[$key]+x}" ] || continue
pinned="${_CFG_BASE_VAL[$key]}"
shipped="$(config_default "$key")" || continue
[ "$pinned" = "$shipped" ] && continue
[ "$drifted" -eq 0 ] && {
printf '\ndejima ships a different default now for %s:\n' "$path"
}
drifted=$((drifted + 1))
section="${key%.*}"; leaf="${key##*.}"
printf ' [%s] %s: yours stays %s, dejima now ships %s\n' \
"$section" "$leaf" "$pinned" "$shipped"
done < <(_config_defaults_keys "$path")
[ "$drifted" -eq 0 ] || {
printf '\nYours are kept, so nothing about your sandbox changed. To take one,\n'
printf 'write it in %s under its section - never in the file above.\n' "$(config_path)"
}
return 0
}
# "section.key" for each line of a rendered defaults file, in file order.
_config_defaults_keys() {
awk '
/^\[/ { s = $0; gsub(/^\[|\]$/, "", s); next }
/^[a-z_]+ = / && s != "" { split($0, p, " = "); print s "." p[1] }
' "$1"
}
# Write it if it is not there. dejima's own file, so dejima creating it is not
# the kind of write this whole arrangement removes - it is the opposite of
# one. Without it the pin would exist only for operators who ran ./install.sh,
# and dejima runs perfectly well from a checkout without it.
#
# Present is left alone: no rebuild, no prune, no drift check. Those belong to
# ./install.sh, which is when the shipped defaults actually change. Doing them
# per launch would put a standing condition in front of every one.
#
# Prints one line, and only when it creates the file.
config_defaults_ensure() {
local path tmp
path="$(config_defaults_path)"
[ -e "$path" ] && return 0
mkdir -p "$(dirname "$path")" || return 0
tmp="$(mktemp "$path.XXXXXX")" || return 0
if config_defaults_render > "$tmp" 2>/dev/null; then
chmod 600 "$tmp"
mv "$tmp" "$path" || { rm -f "$tmp"; return 0; }
printf 'Pinned dejima'"'"'s current defaults in %s so a later release cannot move them.\n' \
"$path" >&2
else
rm -f "$tmp"
fi
return 0
}
# Looks up one [forge.<name>]/[harness.<name>] key's TYPE<TAB>DEFAULT in that
# provider's `keys` manifest entry instead of a row hardcoded in core.
_config_extra_spec() {
@@ -1107,7 +1275,7 @@ identity_validate() {
# "once" that a session could not reach, and a deprecation nobody sees
# until removal is not a deprecation.
if config_is_set core ssh_key; then
printf ' %s[core] ssh_key is deprecated%s - it is [identity.default] ssh_key\n' \
printf '\n %s[core] ssh_key is deprecated%s - it is [identity.default] ssh_key\n' \
"${C_WARN:-}" "${C_RESET:-}" >&2
printf ' under its old name.\n' >&2
if [ -n "$name" ]; then
@@ -1123,8 +1291,10 @@ identity_validate() {
# force it answers with THAT identity's key - and printing it as the
# thing to move would name a key the operator is not being asked to
# touch.
printf ' [identity.default]\n ssh_key = %s\n\n' \
printf ' [identity.default]\n ssh_key = %s\n' \
"$(_config_get_from_file core ssh_key)" >&2
# Worth a pause before the build scrolls it away - see bin/dejima.
DEJIMA_STARTUP_NOTICE=1
fi
[ -n "$name" ] || return 0
@@ -1670,8 +1840,6 @@ If a task genuinely needs something else the sandbox can't provide -
broader network access than a domain or two, host-level or system changes,
GUI/hardware access - stop and explain clearly to the user what you need
and why, instead of trying to work around the firewall or sandbox yourself.
They can continue this exact session outside the container by running on
the host:
BRIEFING_EOF
}
@@ -1834,6 +2002,16 @@ _briefing_resolve_key() {
if [ -n "${DEJIMA_RW_MOUNTS:-}" ]; then
printf '\n These host directories are bind-mounted read-write at their own paths and\n outlive the container too: %s.\n ' "$DEJIMA_RW_MOUNTS"
fi
# A separate sentence, because the first one is not true of these.
# A per-project mount arrives at the path it names, like the
# others, but what is behind it is this project's own slice of
# that directory rather than the directory - so "these host
# directories ... at their own paths" would tell a session it can
# see something it cannot, and imply the next project's session
# will read what it leaves.
if [ -n "${DEJIMA_RW_PP_MOUNTS:-}" ]; then
printf '\n These are bind-mounted read-write too and also outlive the container, but\n each is THIS project'"'"'s own directory rather than one every project shares -\n the same arrangement as ~/shared: %s.\n ' "$DEJIMA_RW_PP_MOUNTS"
fi
;;
*)
echo "internal error: no resolver for whitelisted briefing key: $key" >&2
@@ -2025,9 +2203,11 @@ briefing_compose() {
# The harness fragment closes the briefing: it supplies both the resume
# command closing_a has just promised and the sentence about where the
# session history it resumes from actually lives. Both are the harness's
# own facts - Claude Code resumes from a bind-mounted ~/.claude, Cline
# from a per-project state directory named in the command itself - and
# core stating either one meant stating Claude Code's.
# own facts, INCLUDING whether there is anything to say. Claude Code
# resumes from a bind-mounted ~/.claude and says so; Cline cannot be
# resumed outside dejima at all, and a core sentence promising it could
# was Claude Code's fact stated as everyone's - which left a Cline session
# able to send its operator somewhere that does not work.
#
# $requirements and $project_doc (the missing-dependency report and
# .dejima.md) stay hook-computed and hook-appended after this - they read
+20 -8
View File
@@ -17,16 +17,28 @@
# runs inside the container, the other is a separate library).
ws_slug() { printf '%s' "$1" | sed 's/[^a-zA-Z0-9]/-/g'; }
# Every per-project share directory lives under this one subdirectory of
# `[core] share_dir` rather than directly in it, which is what makes "left
# over from before the split" a decidable question: anything at share_dir's
# top level other than this directory predates the layout, because nothing
# writes there any more. It is also the directory to mount over sshfs - one
# entry per project, with no loose files mixed in.
share_projects_root() { printf '%s/projects' "${1%/}"; }
# The per-project layout, and there is one of it because there is more than one
# caller: `[core] share_dir` slices this way, and so does every
# `[mounts] read_write_per_project` entry. A host directory sliced per project
# holds one `projects` subdirectory, and one directory per slug inside it.
#
# Everything lives under that single subdirectory rather than directly in the
# root, which is what makes "left over from before, or put there by hand" a
# decidable question: anything at the root's top level other than this
# directory was not written by dejima. It is also the directory to mount over
# sshfs - one entry per project, with no loose files mixed in.
projects_root() { printf '%s/projects' "${1%/}"; }
# The directory a launch against $2 gets from a root sliced this way.
project_dir_for() { printf '%s/%s' "$(projects_root "$1")" "$(ws_slug "$2")"; }
# share_dir's own spelling of the two above. `[core] share_dir` is one
# instance of the layout, and these names are what let bin/dejima-share go on
# talking about a share rather than about "a per-project root".
share_projects_root() { projects_root "$1"; }
# The host directory mounted at ~/shared for a launch against $2.
share_dir_for() { printf '%s/%s' "$(share_projects_root "$1")" "$(ws_slug "$2")"; }
share_dir_for() { project_dir_for "$1" "$2"; }
# The slugs belonging to $1: its own, plus one per live git worktree nested
# underneath it. One per line, sorted, no duplicates.
+15 -6
View File
@@ -33,7 +33,7 @@ dejima-update-check - say when this dejima checkout is behind its remote
Usage: dejima-update-check
Compares the checkout bin/dejima runs from against the branch it tracks and
prints one line when the remote has commits this checkout does not. Run at
prints a notice when the remote has commits this checkout does not. Run at
startup by bin/dejima; safe to run by hand.
Silent when the checkout is current or ahead, when [core] update_check is off,
@@ -175,16 +175,25 @@ color_init
# fire on the terminal of the operator this is trying to inform.
_remote_shown="$(sanitize "$remote")"
_branch_shown="$(sanitize "${upstream#refs/heads/}")"
# A blank line either side, the indent the other startup warnings carry, and
# C_WARN: a launch prints this between its startup lines and the image build,
# which starts scrolling immediately after, and two plain lines there are
# indistinguishable from either.
printf '\n' >&2
# The count only when it is known. It is not, whenever the remote's tip is a
# commit this checkout has never fetched, which is the common case - and a
# number invented for those would be the number of commits it can see, not the
# number there are.
if [ -n "$count" ] && [ "$count" != "0" ]; then
if [ "$count" = "1" ]; then noun="commit"; else noun="commits"; fi
printf '%sdejima%s: %s/%s has %s %s this checkout does not.\n' \
"$C_KEY" "$C_RESET" "$_remote_shown" "$_branch_shown" "$C_INFO$count$C_RESET" "$noun" >&2
printf ' %sdejima: %s/%s has %s %s this checkout does not.%s\n' \
"$C_WARN" "$_remote_shown" "$_branch_shown" "$count" "$noun" "$C_RESET" >&2
else
printf '%sdejima%s: %s/%s has commits this checkout does not.\n' \
"$C_KEY" "$C_RESET" "$_remote_shown" "$_branch_shown" >&2
printf ' %sdejima: %s/%s has commits this checkout does not.%s\n' \
"$C_WARN" "$_remote_shown" "$_branch_shown" "$C_RESET" >&2
fi
printf ' Update with %sgit -C %s pull%s\n' "$C_KEY" "$REPO_ROOT" "$C_RESET" >&2
# install.sh is safe to re-run, and a release can change what it links on PATH,
# so pulling is only half the update. Both paths absolute because the operator
# reading this is not necessarily standing in this checkout.
printf ' Update with %sgit -C %s pull && %s/install.sh%s\n\n' \
"$C_KEY" "$REPO_ROOT" "$REPO_ROOT" "$C_RESET" >&2
+111 -122
View File
@@ -31,10 +31,16 @@
# Written through a temp file and renamed: the destination is the settings
# layer bin/dejima is about to mount, and a jq that failed partway would
# otherwise leave the session with a truncated one.
# Where dejima's own hooks live inside the container. Baked into the image
# (see docker/Dockerfile) rather than reached through the ~/.claude/hooks
# mount, because that mount is the operator's configuration and dejima should
# not have to write to it to make its own sandbox work.
DEJIMA_HOOK_DIR=/usr/local/lib/dejima/hooks
harness_register_notify() {
local settings="$1" tmp
tmp="$(mktemp "${TMPDIR:-/tmp}/dejima-settings-remote.XXXXXX.json")"
if jq '.hooks.Stop = ((.hooks.Stop // []) + [{"matcher": "", "hooks": [{"type": "command", "command": "$HOME/.claude/hooks/dejima-notify.sh done"}]}])' \
if jq '.hooks.Stop = ((.hooks.Stop // []) + [{"matcher": "", "hooks": [{"type": "command", "command": "'"$DEJIMA_HOOK_DIR"'/dejima-notify.sh done"}]}])' \
"$settings" > "$tmp"; then
mv "$tmp" "$settings"
else
@@ -107,30 +113,16 @@ harness_state_mounts() {
# what it can host (see `guards` in its manifest), and registering something
# it did not declare would contradict the launch message that says so.
harness_register_guards() {
local repo="$1" backup="$2" settings="$HOME/.claude/settings.json"
local repo="$1" settings="$HOME/.claude/settings.json"
mkdir -p "$HOME/.claude/hooks"
_link_hook() {
local name="$1" src="$repo/hooks/$1" dest="$HOME/.claude/hooks/$1"
if [ -L "$dest" ] && [ "$(readlink -f "$dest")" = "$(readlink -f "$src")" ]; then
echo "Skipping: $name already linked to this repo's copy"
return
fi
if [ -e "$dest" ] || [ -L "$dest" ]; then
mkdir -p "$backup"
echo "Moving: existing ~/.claude/hooks/$name to $backup/$name"
mv "$dest" "$backup/$name"
fi
echo "Linking: $name ($src -> $dest)"
ln -s "$src" "$dest"
}
# Not a guard: this is R3, the briefing's delivery mechanism, and a
# session without it does not know it is in a sandbox.
_link_hook sandbox-context.sh
harness_has_guard push-guard && _link_hook git-push-guard.sh
harness_has_guard merge-guard && _link_hook merge-guard.sh
# Registers nothing. Every hook dejima uses is baked into the image and
# registered per launch into the sandbox's own --settings overlay, so
# installing dejima writes nothing to the operator's Claude Code config.
#
# What is left is taking back what older versions of this function put
# there. The hook is kept rather than deleted because "what a harness
# needs on the host" is a real question a future one may answer
# differently; for Claude Code the answer is now nothing.
# Symlink from before the gitea-merge-guard.sh -> merge-guard.sh rename
# points at a hooks/ path that no longer exists. Only remove it if it is
@@ -141,42 +133,18 @@ harness_register_guards() {
rm -f "$old_merge_guard"
fi
# Linked so it exists at a stable path for the read-only ~/.claude/hooks
# mount, but deliberately NOT registered below: bin/dejima registers it
# per session, into a throwaway settings copy, and only when remote
# access is configured. Registering it here would fire it for every
# unsandboxed host session too, where it has no marker directory to
# write to.
harness_has_guard notify && _link_hook dejima-notify.sh
# deny-dangerous-bash.sh is the one hook that is NOT sandbox-gated: it
# has no DEJIMA check, so it applies to the operator's own host sessions
# as well. That is deliberate, and it is why it may already be owned by
# another install (dotfiles, say) - only claim it if nothing else
# provides it, so this repo works standalone without clobbering an
# existing setup.
if harness_has_guard bash-deny; then
local deny_dest="$HOME/.claude/hooks/deny-dangerous-bash.sh"
if [ -e "$deny_dest" ] || [ -L "$deny_dest" ]; then
echo "Skipping: deny-dangerous-bash.sh already present at $deny_dest (leaving it as-is)"
else
echo "Linking: deny-dangerous-bash.sh ($repo/hooks/deny-dangerous-bash.sh -> $deny_dest)"
ln -s "$repo/hooks/deny-dangerous-bash.sh" "$deny_dest"
fi
fi
echo
if [ ! -f "$settings" ]; then
echo "Creating $settings"
echo '{}' > "$settings"
fi
# No settings.json is created here either: a file dejima writes nothing
# into is a file it has no business bringing into existence.
[ -f "$settings" ] || return 0
# The registration that went with the symlink removed above. Two things
# depend on it going: Claude Code reports a missing hook command on every
# session start while it points at a path that no longer exists, and -
# until the dedupe below stopped matching it - it also stood in for the
# registration it was renamed from, so `_register merge-guard.sh` skipped
# and the merge guard was registered nowhere at all. Dropped only when
# registration it was renamed from, so the merge guard's own registration
# was skipped and it was registered nowhere at all. Dropped only when
# the path it names is gone, so an operator's own file at that name keeps
# its registration, matching the symlink check above.
if [ ! -e "$old_merge_guard" ] && jq -e --arg s "/gitea-merge-guard.sh" \
@@ -191,34 +159,34 @@ harness_register_guards() {
"$settings" > "$stale_tmp" && mv "$stale_tmp" "$settings"
fi
_register() {
local event="$1" matcher="$2" script_name="$3" description="$4"
# endswith on the leading slash, not test(): test() is an unanchored
# regex, so a hook whose name merely ends in another's - which is what
# a rename like gitea-merge-guard.sh -> merge-guard.sh produces - read
# as already registered, and the new hook was silently never added.
if jq -e --arg s "/$script_name" \
"[.hooks.${event}[]?.hooks[]?.command // empty] | any(endswith(\$s))" \
"$settings" >/dev/null 2>&1; then
echo "Skipping: $script_name already registered as a $event hook"
return
# An upgrade has to take back what an older install.sh put here, or the
# claim above is only true of a fresh one. Removed by name and only when
# the symlink points into THIS repo: an operator's own file at one of
# these names is theirs.
local moved dest
for moved in sandbox-context.sh git-push-guard.sh merge-guard.sh dejima-notify.sh \
deny-dangerous-bash.sh; do
dest="$HOME/.claude/hooks/$moved"
if [ -L "$dest" ] && [ "$(readlink -f "$dest")" = "$(readlink -f "$repo/hooks/$moved")" ]; then
echo "Removing: $moved from ~/.claude/hooks (the sandbox registers its own now)"
rm -f "$dest"
fi
echo "Registering $script_name as a $event hook in $settings ($description)"
local tmp
tmp=$(mktemp)
jq --arg matcher "$matcher" --arg cmd "\$HOME/.claude/hooks/$script_name" \
".hooks.${event} = ((.hooks.${event} // []) + [{\"matcher\": \$matcher, \"hooks\": [{\"type\": \"command\", \"command\": \$cmd}]}])" \
"$settings" > "$tmp" && mv "$tmp" "$settings"
}
_register SessionStart "startup|resume|clear|compact" sandbox-context.sh \
"injects sandbox context on session start"
harness_has_guard push-guard && _register PreToolUse Bash git-push-guard.sh \
"blocks pushes outside the allowed host(s)/branches"
harness_has_guard merge-guard && _register PreToolUse Bash merge-guard.sh \
"blocks the configured forge's merge command inside the sandbox"
harness_has_guard bash-deny && _register PreToolUse Bash deny-dangerous-bash.sh \
"blocks obviously destructive Bash commands"
# And its registration, matched the same endswith way _register does.
local ev
for ev in SessionStart PreToolUse Stop; do
if jq -e --arg s "/$moved" \
"[.hooks.${ev}[]?.hooks[]?.command // empty] | any(endswith(\$s))" \
"$settings" >/dev/null 2>&1; then
echo "Removing: $moved's $ev registration from $settings"
local mv_tmp; mv_tmp=$(mktemp)
jq --arg s "/$moved" \
".hooks.${ev} = ((.hooks.${ev} // [])
| map(.hooks = ((.hooks // []) | map(select((.command // \"\") | endswith(\$s) | not))))
| map(select((.hooks | length) > 0)))" \
"$settings" > "$mv_tmp" && mv "$mv_tmp" "$settings"
fi
done
done
echo
return 0
}
@@ -380,14 +348,10 @@ harness_prepare_config() {
local overlay="$1" settings="$HOME/.claude/settings.json" settings_error
# install.sh normally creates settings.json, and many hosts have no
# CLAUDE.md at all. Created empty rather than left absent because
# harness_staged_config below emits both unconditionally and core skips
# staging a file that does not exist - so without this the session would
# silently start without them. statusline.sh is deliberately NOT created:
# an empty one would be staged executable and run as the status line.
[ -f "$settings" ] || echo '{}' > "$settings"
[ -f "$HOME/.claude/CLAUDE.md" ] || : > "$HOME/.claude/CLAUDE.md"
# Nothing is created on the host. A settings.json or CLAUDE.md the
# operator does not have is not one dejima should make on their machine so
# that it has something to copy - harness_staged_config asks for an empty
# one in the CONTAINER instead, which is where it is needed.
# Claude Code ignores a settings.json it cannot parse, wholesale and with
# only a startup warning, so a stray edit on the host costs the sandbox
@@ -396,7 +360,8 @@ harness_prepare_config() {
# symptom is an unexpected bypass-mode warning rather than anything
# mentioning settings. The file is staged verbatim, so nothing else parses
# it before the session reads it - check here, where the fix is at hand.
if ! settings_error="$(jq . "$settings" 2>&1 >/dev/null)"; then
# Absent is not unparseable: there is simply nothing to stage.
if [ -f "$settings" ] && ! settings_error="$(jq . "$settings" 2>&1 >/dev/null)"; then
echo "$settings is not valid JSON:" >&2
echo " $settings_error" >&2
echo "Claude Code would ignore it entirely and the sandbox would start with" >&2
@@ -411,7 +376,38 @@ harness_prepare_config() {
# --settings layer (the manifest's settings_args) above
# ~/.claude/settings.json, which holds only what the sandbox overrides;
# the operator's hooks, permissions and plugins still apply from there.
#
# And dejima's own hooks, registered HERE rather than in the operator's
# ~/.claude/settings.json. Claude Code merges this layer with theirs, so
# their hooks still run - proven by the one dejima deliberately leaves on
# the host, deny-dangerous-bash.sh, which fires inside a container while
# being registered only there.
#
# Registering them here is what lets install.sh stop writing to a config
# that is not dejima's. The scripts are baked into the image, so a session
# cannot unlink a guard the way it could one staged into a directory it
# owns.
jq -n '{sandbox: {enabled: false}}' > "$overlay"
_register_overlay_hook() { # <event> <matcher> <script>
local event="$1" matcher="$2" script="$3" tmp
tmp="$(mktemp "${TMPDIR:-/tmp}/dejima-overlay.XXXXXX.json")" || return 1
if jq --arg m "$matcher" --arg c "$DEJIMA_HOOK_DIR/$script" \
".hooks.${event} = ((.hooks.${event} // []) +
[{\"matcher\": \$m, \"hooks\": [{\"type\": \"command\", \"command\": \$c}]}])" \
"$overlay" > "$tmp"; then
mv "$tmp" "$overlay"
else
rm -f "$tmp"
echo "warning: could not register $script; it will not run this session." >&2
fi
}
# R3: without this a session is not told it is in a sandbox at all, which
# is why it is registered whether or not any guard is declared.
_register_overlay_hook SessionStart "startup|resume|clear|compact" sandbox-context.sh
harness_has_guard push-guard && _register_overlay_hook PreToolUse Bash git-push-guard.sh
harness_has_guard merge-guard && _register_overlay_hook PreToolUse Bash merge-guard.sh
harness_has_guard bash-deny && _register_overlay_hook PreToolUse Bash deny-dangerous-bash.sh
return 0
}
harness_staged_config() {
@@ -419,10 +415,13 @@ harness_staged_config() {
# and what a dangling symlink means, are core's to decide - filtering
# here would skip a dangling one silently, which is the case that must
# refuse rather than quietly leave the session without the file.
local f
for f in settings.json CLAUDE.md statusline.sh; do
emit_staged_config "$HOME/.claude/$f" ".claude/$f"
done
# settings.json and CLAUDE.md are asked to exist even when the host has
# none: Claude Code reads both, and an empty one reads the same as a file
# the operator never made. statusline.sh is not - an empty one would be
# installed executable and run as the status line.
emit_staged_config "$HOME/.claude/settings.json" ".claude/settings.json" ensure-json
emit_staged_config "$HOME/.claude/CLAUDE.md" ".claude/CLAUDE.md" ensure
emit_staged_config "$HOME/.claude/statusline.sh" ".claude/statusline.sh"
}
# Where this workspace's transcripts are, and which store key each belongs
@@ -602,35 +601,25 @@ harness_transform_transcript() {
' 2>/dev/null
}
# Which of the hooks install.sh registers are actually in the operator's
# settings, and which are not. Prints the missing ones, one per line, and
# returns 1 if there are any - so the launch can name what is not in force
# rather than assert that nothing is.
# harness_guards_registered is deliberately not defined.
#
# Every hook this harness would install is checked, not just the briefing:
# the realistic failure (install.sh never run with a harness set) is
# all-or-nothing, but a hand-edited settings.json missing one guard is a
# session quietly running without it, which is the case worth catching.
# It read the operator's own ~/.claude/settings.json and named any of dejima's
# hooks missing from it, because that is where install.sh used to put them and
# "install.sh never run with a harness set" was a real way to get a session
# with no briefing and no guards.
#
# dejima-notify.sh is deliberately absent: bin/dejima registers it per
# session into a throwaway layer, and it is never in the operator's file.
# Nothing is written there now: the hooks are baked into the image and
# registered per launch into dejima's own --settings overlay, so an absent
# registration in the operator's file is the correct state rather than a
# broken one. Left defined, it named all four as not in force on every launch
# of a host that had never run the old installer - and told the operator to
# run ./install.sh, which strips exactly those registrations, making the
# message permanent.
#
# Reads the operator's real settings rather than dejima's own layer, which
# is composed fresh each launch and always looks right.
harness_guards_registered() {
local settings="$HOME/.claude/settings.json" missing=0
_registered() {
[ -f "$settings" ] || return 1
jq -e --arg s "/$2" "[.hooks.$1[]?.hooks[]?.command // empty]
| any(endswith(\$s))" "$settings" >/dev/null 2>&1
}
_registered SessionStart sandbox-context.sh \
|| { printf 'the session briefing\n'; missing=1; }
harness_has_guard push-guard && { _registered PreToolUse git-push-guard.sh \
|| { printf 'push-guard\n'; missing=1; }; }
harness_has_guard merge-guard && { _registered PreToolUse merge-guard.sh \
|| { printf 'merge-guard\n'; missing=1; }; }
harness_has_guard bash-deny && { _registered PreToolUse deny-dangerous-bash.sh \
|| { printf 'bash-deny\n'; missing=1; }; }
return "$missing"
}
# There is nothing to put in its place. What the overlay carries is composed
# fresh each launch from the manifest, so reading it back would be asking
# dejima whether it did what it just did; which guards the harness cannot host
# at all is the manifest's, and harness_report_guards already says it.
#
# The hook itself stays in the plugin interface. What a harness needs wired on
# the host is a real question, and a future one may answer it differently.
+85
View File
@@ -332,6 +332,91 @@ harness_prepare_config() {
# nothing inside the container has to be told where its state is - the source
# is keyed by dejima's workspace slug and only the target follows the harness,
# which is what emit_mount_at is for.
# The operator's own configuration, brought in from the host.
#
# Read-only, and that is the whole point rather than caution: everything here
# is either an instruction the agent follows or a program cline runs. A
# session that could rewrite them would be choosing what happens on the HOST
# the next time cline starts outside a container - persistence for a prompt
# injection, in files nobody re-reads before the next run.
#
# `scan` for the same reason claude-code's directories are scanned: on a Linux
# host these are routinely symlinks into a dotfiles checkout, and the target
# has to be mounted for the link to resolve inside the container. Core refuses
# a target that overlaps a guarded store.
#
# ~/.agents/rules is deliberately absent. It reads like the obvious companion
# to ~/.agents/skills and cline does not load it - checked by planting a file
# in it and one in ~/Documents/Cline/Rules and asking `cline config` which it
# had: only the second appeared. Mounting a directory the harness never reads
# would be a promise dejima cannot keep.
harness_config_dirs() {
emit_config_dir "$HOME/.agents/skills" ro scan
# Not confirmed loaded by that same probe, unlike skills. Mounted because
# it is the documented default for --hooks-dir and because the cost of
# being wrong is an empty directory, where the cost of leaving it out is a
# hook that silently does not run.
emit_config_dir "$HOME/.agents/hooks" ro scan
emit_config_dir "$HOME/.cline/hooks" ro scan
}
# AGENTS.md is instructions the agent follows, so a session that could write
# the host's copy would be choosing what the next session is told. Staged
# rather than mounted: the copy lands root-owned and read-only, and a file
# that is a symlink into a dotfiles checkout arrives as its real content
# rather than as a link the host can still swap.
harness_staged_config() {
emit_staged_config "$HOME/.agents/AGENTS.md" ".agents/AGENTS.md"
# Global rules, from both host locations into the one directory cline
# actually reads.
#
# cline loads global rules from Documents/Cline/Rules and nowhere else -
# ~/.agents/rules reads like its companion and is not read, checked by
# planting a file in each and asking `cline config` which it had. So
# ~/.agents/rules is supported by staging its files INTO the directory
# that is read, rather than by mounting it where it sits and having
# nothing load it.
#
# File by file rather than as a directory mount, because dejima writes its
# own briefing into that same directory: a read-only mount over it would
# leave nowhere to put the briefing.
local d f base briefing seen=" "
# The briefing's own name, from the manifest rather than repeated here.
# dejima wins that collision, and entrypoint.sh already delivers it after
# the staged files - so staging a host file it is about to overwrite would
# only add a mount nobody reads.
briefing="$(basename "$(manifest_get harness cline briefing_path)")"
# Documents first, so a name present in both wins there: it is cline's own
# location for this, and where an operator editing rules through cline is
# writing. Two sources staged to one destination would otherwise be two
# bind mounts at the same container path.
for d in "$HOME/Documents/Cline/Rules" "$HOME/.agents/rules"; do
[ -d "$d" ] || continue
# .md and .txt are what cline reads out of a rules directory.
for f in "$d"/*.md "$d"/*.txt; do
[ -f "$f" ] || continue
base="$(basename "$f")"
[ "$base" = "$briefing" ] && continue
case "$seen" in *" $base "*) continue ;; esac
seen="$seen$base "
emit_staged_config "$f" "Documents/Cline/Rules/$base"
done
done
}
# Writable copies, discarded with the container.
#
# cline rewrites both of these as it runs - its settings TUI toggles them - so
# a read-only copy would fail the write rather than the persistence, and the
# persistence is the part that matters. cline_mcp_settings.json names MCP
# servers, which are commands cline executes: a session that could write the
# host's copy would be choosing what runs there next time.
harness_seed() {
emit_seed_from "$HOME/.cline/settings.json" ".cline/settings.json"
emit_seed_from "$HOME/.cline/cline_mcp_settings.json" ".cline/cline_mcp_settings.json"
}
harness_state_mounts() {
local dir
dir="$(_cline_state_dir "$1")" || return 0
+21 -1
View File
@@ -28,6 +28,11 @@ ENV TZ="$TZ"
# hardening). Whichever harness has one, its plugin's harness_prepare_config
# turns it off in the override layer, so there is nothing here to satisfy.
# Claude Code's is the "sandbox" block in settings.json.
#
# libcap2-bin is capsh, which entrypoint.sh uses to hand the session a
# container it holds no capabilities in. It was already here as a dependency of
# iproute2; a security control resting on another package's dependency graph is
# one an unrelated package change removes.
RUN apt-get update && apt-get install -y --no-install-recommends \
less \
git \
@@ -41,6 +46,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
iptables \
ipset \
iproute2 \
libcap2-bin \
dnsutils \
aggregate \
jq \
@@ -266,8 +272,11 @@ RUN npm install -g playwright@${PLAYWRIGHT_VERSION} && \
# are supplied at runtime, not baked into the image - see
# docker-compose.yml/entrypoint.sh.
COPY docker/fixed-domains.sh /usr/local/bin/
COPY docker/caps-lib.sh /usr/local/bin/
COPY docker/dns-proxy.sh /usr/local/bin/
COPY docker/init-firewall.sh /usr/local/bin/
COPY docker/firewall-up.sh /usr/local/bin/
COPY docker/filter-entrypoint.sh /usr/local/bin/
COPY docker/log-shipper.sh /usr/local/bin/
COPY docker/ulogd.conf /etc/ulogd-sandbox.conf
# Into $VIMRUNTIME/plugin, not /etc/xdg/nvim - see the file's own comment.
@@ -287,6 +296,17 @@ COPY docker/forge-guard.sh /usr/local/lib/dejima/forge-guard.sh
# entrypoint.sh, which renders the briefing before the session starts - to
# hand to the harness as an argument, or to write to a file it reads.
COPY hooks/dejima-briefing-render.sh /usr/local/lib/dejima/dejima-briefing-render.sh
# dejima's own hooks, for the same reason and one more: they are registered
# into the sandbox's --settings overlay rather than into the operator's
# ~/.claude/settings.json, so nothing has to be written to a host config to
# make the sandbox work. Baked rather than mounted from the checkout because a
# guard whose script can change under a running session is not one.
#
COPY hooks/deny-dangerous-bash.sh /usr/local/lib/dejima/hooks/deny-dangerous-bash.sh
COPY hooks/sandbox-context.sh /usr/local/lib/dejima/hooks/sandbox-context.sh
COPY hooks/git-push-guard.sh /usr/local/lib/dejima/hooks/git-push-guard.sh
COPY hooks/merge-guard.sh /usr/local/lib/dejima/hooks/merge-guard.sh
COPY hooks/dejima-notify.sh /usr/local/lib/dejima/hooks/dejima-notify.sh
# Back to root before the first RUN that writes outside /home/node. The npm
# installs above run as node deliberately; COPY writes as root regardless of
# USER, so the copies above are unaffected, but the install(1) below is a RUN
@@ -312,7 +332,7 @@ RUN bash /tmp/install-forge-bins.sh /tmp/forges /usr/local/lib/dejima/forge /usr
# and describes what a page should look like instead of going and seeing.
RUN ln -s /usr/local/share/npm-global/lib/node_modules /node_modules
RUN chmod +x /usr/local/bin/dns-proxy.sh /usr/local/bin/init-firewall.sh /usr/local/bin/log-shipper.sh /usr/local/bin/entrypoint.sh /usr/local/bin/dejima-harness-wrapper /usr/local/lib/dejima/git-guard.sh /usr/local/lib/dejima/forge-guard.sh /usr/local/lib/dejima/dejima-briefing-render.sh && \
RUN chmod +x /usr/local/bin/dns-proxy.sh /usr/local/bin/init-firewall.sh /usr/local/bin/firewall-up.sh /usr/local/bin/filter-entrypoint.sh /usr/local/bin/log-shipper.sh /usr/local/bin/entrypoint.sh /usr/local/bin/dejima-harness-wrapper /usr/local/lib/dejima/git-guard.sh /usr/local/lib/dejima/forge-guard.sh /usr/local/lib/dejima/dejima-briefing-render.sh /usr/local/lib/dejima/hooks/*.sh && \
echo 'export PATH="$PATH:/usr/local/share/npm-global/bin"' > /etc/profile.d/npm-global-path.sh
# Entrypoint runs as root (no USER node here) so it can set up the firewall
+45
View File
@@ -0,0 +1,45 @@
# Sourced by every entrypoint in this image. Nothing here runs on its own.
#
# The startup sequence needs real capabilities - it builds the packet filter,
# binds an NFLOG socket, chowns files and drops privilege twice. Nothing after
# it does, and a bounding set survives execve: a process that reaches uid 0
# anywhere downstream recovers its permitted set from whatever bounding set it
# inherited. So an unprivileged session whose effective set is empty still sits
# inside a tree holding every capability the container declares.
#
# `drop_caps` is how anything that outlives a startup script is started, and it
# is what makes a declared floor a description of the root phase rather than of
# the session's whole life.
#
# capsh, not `setpriv --bounding-set`, which is the obvious tool and silently
# the wrong one: without CAP_SETPCAP it exits 0 having changed nothing, so a
# container that lost the capability would run every session with the full set
# and report success at every step. capsh refuses out loud, which is the only
# behaviour worth having here.
#
# `-- -c 'exec "$@"'` runs the command through capsh's shell and immediately
# replaces it, so nothing is left between the caller and the process.
drop_caps() {
exec capsh --drop=all "$@"
}
# Checked rather than assumed, because the failure it prevents is invisible:
# capsh would abort each drop_caps call, and in an entrypoint the last of those
# is the session, so the container would die at the point it looked ready.
# Named here instead, against the file the floor actually lives in.
#
# Called once by each top-level entrypoint rather than from drop_caps: it is a
# precondition of the whole script, and the point is to refuse before doing
# work rather than partway through it.
require_setpcap() {
if capsh --decode="$(awk '/^CapEff:/ {print $2}' /proc/self/status)" \
| grep -q cap_setpcap; then
return 0
fi
echo "${0##*/}: this container does not hold CAP_SETPCAP, so the capabilities" >&2
echo "the startup sequence needs cannot be taken away again before the session" >&2
echo "starts - it would run inside a tree holding all of them." >&2
echo "Refusing to start rather than running with a floor that is not the one" >&2
echo "docker/docker-compose.yml declares. Add SETPCAP to its cap_add." >&2
exit 1
}
+7 -7
View File
@@ -22,14 +22,14 @@ const net = require("net");
const tls = require("tls");
const fs = require("fs");
const socketPath = process.env.SANDBOX_ANTHROPIC_PROXY_SOCKET;
const transport = process.env.SANDBOX_ANTHROPIC_TRANSPORT || "tls";
const socketPath = process.env.SANDBOX_CREDENTIAL_PROXY_SOCKET;
const transport = process.env.SANDBOX_CREDENTIAL_TRANSPORT || "tls";
const port = parseInt(
process.env.SANDBOX_ANTHROPIC_PROXY_PORT || (transport === "tls" ? "443" : "18300"),
process.env.SANDBOX_CREDENTIAL_PROXY_PORT || (transport === "tls" ? "443" : "18300"),
10,
);
if (!socketPath) {
console.error("credential-proxy-forwarder: SANDBOX_ANTHROPIC_PROXY_SOCKET not set");
console.error("credential-proxy-forwarder: SANDBOX_CREDENTIAL_PROXY_SOCKET not set");
process.exit(1);
}
@@ -43,11 +43,11 @@ const pipe = (client) => {
let server;
if (transport === "tls") {
const certPath = process.env.SANDBOX_ANTHROPIC_TLS_CERT;
const keyPath = process.env.SANDBOX_ANTHROPIC_TLS_KEY;
const certPath = process.env.SANDBOX_CREDENTIAL_TLS_CERT;
const keyPath = process.env.SANDBOX_CREDENTIAL_TLS_KEY;
if (!certPath || !keyPath) {
console.error(
"credential-proxy-forwarder: SANDBOX_ANTHROPIC_TLS_CERT/SANDBOX_ANTHROPIC_TLS_KEY not set",
"credential-proxy-forwarder: SANDBOX_CREDENTIAL_TLS_CERT/SANDBOX_CREDENTIAL_TLS_KEY not set",
);
process.exit(1);
}
+78 -32
View File
@@ -48,43 +48,87 @@ services:
# ten per run - becomes a permanent zombie, and a long session eventually
# exhausts the cgroup pids limit and can no longer fork at all.
init: true
# An explicit floor rather than Docker's default set plus two. The default
# carries about fourteen capabilities and this container uses seven: it
# writes and chowns files, runs the firewall, drops privilege twice (gosu
# for the session, `ulogd -u` for the log daemon), and signals dnsmasq.
# FSETID, MKNOD, SETFCAP, SETPCAP, SYS_CHROOT, AUDIT_WRITE and
# NET_BIND_SERVICE are used by nothing here - the last one because the
# sysctl below is what lets the TLS terminator bind :443 unprivileged.
# The session does not get a network namespace of its own. It joins the one
# the filter container owns, where the egress rules are already installed -
# so the filter bounding this session sits somewhere it declares no
# capability to reach. bin/dejima starts that container and passes its name
# here; see the block above its compose invocation, and docs/security.md.
#
# KILL is the one worth explaining, because it is not obvious from reading
# entrypoint.sh and was missing from the first version of this list. It is
# not for anything the entrypoint does. `dejima-allow --container` adds a
# domain to a RUNNING session by appending a server= line and sending
# dnsmasq a SIGHUP, from outside via docker exec - and dnsmasq drops to its
# own user (`user=dnsmasq`), so root in this container cannot signal it
# without CAP_KILL. Without this line, adding a domain mid-session fails
# with "Operation not permitted", which is a documented feature every
# session briefing tells the agent to ask for.
# The default is for a `docker compose` invocation by hand, which this
# file's first line says is not how to run it. It is `network_mode: none`
# rather than any real network, because the value that makes a session safe
# arrives from outside this file, and the question a default answers is
# what happens when it does not arrive: no network at all is a sandbox that
# visibly cannot work, where a real one is a sandbox that works and has
# unfiltered egress.
#
# It does not affect `docker compose build`, which reads `build.network`.
network_mode: ${SANDBOX_NETNS_CONTAINER:-none}
# An explicit floor rather than Docker's default set. The default carries
# about fourteen capabilities; this container writes and chowns files and
# drops privilege once, to the session user. FSETID, MKNOD, SETFCAP,
# SYS_CHROOT, AUDIT_WRITE and NET_BIND_SERVICE are used by nothing here -
# the last one because a sysctl on this namespace, not a capability, is
# what lets the TLS terminator bind :443 unprivileged.
#
# No network capability at all, which is the point of the arrangement
# rather than an economy. This container is inside a network namespace the
# filter container owns and has already installed the egress rules in, and
# capabilities are per process: without NET_ADMIN, nothing here can alter
# those rules even at uid 0. NET_RAW goes with it - a raw socket is the
# other way to speak past a filter, and nothing here opens one.
#
# KILL is here for tini, and for nothing else in this container.
#
# `init: true` above makes PID 1 the init that reaps for the session, and
# tini forwards every signal it receives to its child. That child is the
# entrypoint, which changes uid in place before exec'ing the session - so
# tini is uid 0 signalling a process whose real AND saved uids are the
# sandbox user's. kill(2) permits that only with CAP_KILL or a uid match,
# and there is no match, so without this every forwarded signal is EPERM.
#
# tini treats a failed forward as fatal, and PID 1 exiting ends the
# container. The signal that arrives in practice is SIGWINCH: the kernel
# sends it to the pty's foreground process group on any terminal resize,
# which includes tini. So without this line, splitting a tmux pane kills
# the session with `[FATAL tini (1)] Unexpected error when forwarding
# signal: 'Operation not permitted'`.
#
# It used to be here for `dejima-allow --container`, which signals dnsmasq;
# that reason moved to the filter container with dnsmasq, and this one was
# not noticed until the capability went away. Nothing in the suite ran an
# init at all - see runtime.bats.
#
# The general lesson, since the next capability will be the same shape:
# what the container needs is not only what its entrypoint does. Things
# reach into it later.
# what a container needs is not only what its entrypoint does. Things reach
# into it later.
#
# This narrows the ROOT phase. The session user's capabilities were already
# empty: they are cleared on the gosu drop, which runtime.bats asserts by
# reading CapEff of the running process. What this adds is that the set was
# never there to be regained.
# empty: they are cleared on the privilege drop, which runtime.bats asserts
# by reading CapEff of the running process. What this adds is that the set
# was never there to be regained.
#
# SETPCAP is the odd one out: nothing in the startup sequence uses it for
# its own work. It is spent, once, to take every capability above away from
# the session before it starts - see entrypoint.sh. A bounding set survives
# execve and a uid-0 process recovers its permitted set from it, so without
# this the whole list is held by everything the session can reach, effective
# set or not.
#
# Adding a capability to remove capabilities is worth stating plainly. It
# can only reduce: since Linux 4.3 SETPCAP grants nothing a process does
# not already hold in its permitted set, so what it buys is the drop and
# nothing else.
cap_drop:
- ALL
cap_add:
- NET_ADMIN
- NET_RAW
- KILL
- CHOWN
- DAC_OVERRIDE
- FOWNER
- SETUID
- SETGID
- KILL
- SETPCAP
# No path back up. gosu drops privilege rather than gaining it, so this
# does not interfere with it - what it forbids is a setuid binary or a file
# capability raising privileges on exec, which is the shape any escalation
@@ -92,12 +136,13 @@ services:
# structural instead of only observed.
security_opt:
- no-new-privileges:true
# The credential-proxy TLS terminator binds :443 as the unprivileged
# sandbox user (see entrypoint.sh). Docker already defaults this to 0, but
# pinning it makes the dependency explicit: a future default change then
# fails the launch instead of silently breaking the credential path.
sysctls:
net.ipv4.ip_unprivileged_port_start: 0
# No sysctls here. The one this container depends on -
# net.ipv4.ip_unprivileged_port_start, which lets the credential proxy's
# TLS terminator bind :443 as the unprivileged sandbox user - is a property
# of a network namespace, and this container does not own the one it is in.
# bin/dejima sets it on the filter container that does, so it is declared
# once, by the container it belongs to. runtime.bats reads the value back
# from in here, which is where it has to be true.
environment:
# The forge's own env vars (declared by its manifest's env_export) and
# the DEJIMA_* resolved values (DEJIMA_FORGE_HOSTS, DEJIMA_PUSH_HOSTS,
@@ -141,6 +186,7 @@ services:
SANDBOX_HARNESS_BRIEFING_ARGS: ${SANDBOX_HARNESS_BRIEFING_ARGS:-}
SANDBOX_HARNESS_BRIEFING_PATH: ${SANDBOX_HARNESS_BRIEFING_PATH:-}
SANDBOX_HARNESS_SEED: ${SANDBOX_HARNESS_SEED:-}
SANDBOX_HARNESS_STAGED_EMPTY: ${SANDBOX_HARNESS_STAGED_EMPTY:-}
# Opt-in escape hatch from the default hard GitHub-push block - see
# init-firewall.sh and git-push-guard.sh. Off unless explicitly set.
ALLOW_GITHUB_PUSH: ${ALLOW_GITHUB_PUSH:-0}
@@ -172,8 +218,8 @@ services:
# never enters the container; the host-side proxy swaps this for it per
# request, exactly as it does for a subscription login's token.
ANTHROPIC_API_KEY: ${SANDBOX_ANTHROPIC_API_KEY:-}
SANDBOX_ANTHROPIC_PROXY_SOCKET: ${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}
SANDBOX_ANTHROPIC_TRANSPORT: ${SANDBOX_ANTHROPIC_TRANSPORT:-}
SANDBOX_CREDENTIAL_PROXY_SOCKET: ${SANDBOX_CREDENTIAL_PROXY_SOCKET:-}
SANDBOX_CREDENTIAL_TRANSPORT: ${SANDBOX_CREDENTIAL_TRANSPORT:-}
volumes:
# Mounted at the same absolute path as on the host (rather than a
# fixed /workspace) so Claude Code's project/session-history keying
+69 -59
View File
@@ -8,56 +8,30 @@ set -Eeuo pipefail
# refuse deliberately, and say so (#59).
trap 'status=$?; echo "ERROR: entrypoint.sh aborted at line $LINENO (exit $status): $BASH_COMMAND" >&2' ERR
# DEJIMA_FORGE_HOSTS is resolved host-side by bin/dejima (forge_hosts, in
# dejima-provider-lib.sh) from whichever forge is configured, so this file
# does not derive or name any one forge's hostnames itself.
# drop_caps and require_setpcap, shared with the filter container's entrypoint.
# Sourced rather than defined here because the callers must not drift: what
# `drop_caps` does is the difference between a session holding nothing and a
# session holding the whole floor, and that is not a thing to have two of.
# shellcheck source=caps-lib.sh
source /usr/local/bin/caps-lib.sh
require_setpcap
# The egress control for this namespace is already up: the filter container
# that owns it installed the rules, and bin/dejima waited for that before
# starting this container. Nothing here brings it up, and nothing here could -
# this container declares none of the capabilities it would take.
#
# LOKI_URL (a full URL) still needs its own derivation here - Loki's host
# has to be reachable for log-shipper.sh to actually deliver anything.
loki_host=""
if [ -n "${LOKI_URL:-}" ]; then
loki_host=$(echo "$LOKI_URL" | sed -E 's#^[a-zA-Z]+://##; s#[:/].*##')
fi
extra_domains="${DEJIMA_FORGE_HOSTS:-} ${loki_host} ${ALLOWED_DOMAINS:-}"
# What this container does need is to be pointed at the resolver enforcing the
# name allowlist. /etc/resolv.conf is per container even when the namespace is
# shared, so dns-proxy.sh repointing the filter container's file says nothing
# about this one - which Docker generated pointing straight at its embedded
# resolver. Left alone, every lookup the session makes would go around dnsmasq
# and the DNS allowlist would apply to nothing.
#
# The same value dns-proxy.sh writes for itself, at the same loopback address,
# because loopback is shared with the container the resolver runs in.
if [ "${ENABLE_FIREWALL:-1}" = "1" ]; then
# dns-proxy.sh must run first: it repoints /etc/resolv.conf at a local
# dnsmasq that only resolves allowlisted names, so init-firewall.sh's own
# dig calls (and everything afterward) go through the same restriction.
EXTRA_ALLOWED_DOMAINS="${extra_domains}" /usr/local/bin/dns-proxy.sh
EXTRA_ALLOWED_DOMAINS="${extra_domains}" /usr/local/bin/init-firewall.sh
# NFLOG groups only exist once init-firewall.sh has run, so ulogd2 (the
# NFLOG consumer) and the Loki shipper start after it. Both are
# best-effort visibility on top of the enforcement above, not required
# for it - log-shipper.sh itself no-ops if LOKI_URL isn't set. Runs as
# its own unprivileged `ulogd` user (opens the NFLOG socket and output
# files first, then drops), not root - it's parsing headers from
# attacker-influenceable packets (whatever a compromised session sends),
# so a bug in it shouldn't be a path back to root in the container.
#
# `ulogd -d` daemonizes immediately and always exits 0 from this shell's
# point of view, regardless of whether the daemon itself goes on to
# start successfully - so `set -e` above won't catch a failure here (nor
# should it: logging is best-effort, not something worth failing the
# whole container over). Check separately so a failure is at least
# visible instead of silently producing no logs.
/usr/sbin/ulogd -d -u ulogd -c /etc/ulogd-sandbox.conf
sleep 0.5
if ! pgrep -x ulogd >/dev/null; then
echo "WARNING: ulogd2 failed to start - connection logging will be unavailable (see /var/log/ulogd.log)" >&2
fi
# Unlike ulogd2 above, this one stays root - deliberately, not an
# oversight. What it ships is an oversight log of the session running
# beside it, and letting the sandbox user own the shipper would let a
# compromised session tamper with or kill its own logging. Root buys
# tamper-resistance that a security log needs and a best-effort netflow
# counter does not.
#
# What it reads is dnsmasq's query log and ulogd2's output, both written
# by root-owned daemons here and neither session-writable.
/usr/local/bin/log-shipper.sh &
echo "nameserver 127.0.0.1" > /etc/resolv.conf
fi
# A normal login/ssh session always chowns the allocated pty to the logging
@@ -235,6 +209,36 @@ if [ -d /etc/dejima-harness ]; then
done < <(find /etc/dejima-harness -type f -print0)
fi
# Files the harness needs to exist whether or not the operator has one.
#
# Created HERE rather than on the host. A harness that reads a settings file
# still reads one when it is empty, and dejima creating that file on the
# operator's machine - so there is something to copy - is a write to their
# configuration for dejima's own convenience. Root-owned and read-only, the
# same as anything else staged, so the container's copy is not a channel back.
for _spec in ${SANDBOX_HARNESS_STAGED_EMPTY:-}; do
_kind="${_spec%%:*}"
_rel="${_spec#*:}"
case "$_rel" in
/*|*..*)
echo "entrypoint: refusing staged-config path '$_rel': it must be" >&2
echo "relative to the sandbox user's home and must not contain '..'." >&2
exit 1 ;;
esac
_dest="$SANDBOX_HOME/$_rel"
[ -e "$_dest" ] && continue
mkdir -p "$(dirname "$_dest")"
# An empty file is not valid JSON, and a harness that discards a config it
# cannot parse would lose everything in it rather than nothing.
if [ "$_kind" = ensure-json ]; then
printf '{}\n' > "$_dest"
else
: > "$_dest"
fi
chown root:root "$_dest"
chmod 444 "$_dest"
done
# The harness's own writable state. Unlike the staged config above, these are
# owned by the sandbox user and stay writable: they are what the harness
# rewrites as it runs - a plugin registry, a catalogue, an install marker -
@@ -360,25 +364,25 @@ fi
# extra_hosts: under [credentials] proxy = off nothing listens on :443, and
# an unconditional entry would black-hole the real API on exactly the path
# that has to keep working.
SANDBOX_ANTHROPIC_TRANSPORT="${SANDBOX_ANTHROPIC_TRANSPORT:-tls}"
export SANDBOX_ANTHROPIC_TRANSPORT
SANDBOX_CREDENTIAL_TRANSPORT="${SANDBOX_CREDENTIAL_TRANSPORT:-tls}"
export SANDBOX_CREDENTIAL_TRANSPORT
# Checked here rather than in bin/dejima because every launch reaches this
# script, including a bare `docker run` (see test/runtime.bats). The two halves
# branch on opposite polarity - bin/dejima treats anything but `loopback` as
# tls, this script and the forwarder treat anything but `tls` as loopback - so
# a typo would configure them for different transports and fail every API call
# with nothing pointing back at the cause.
case "$SANDBOX_ANTHROPIC_TRANSPORT" in
case "$SANDBOX_CREDENTIAL_TRANSPORT" in
tls|loopback) ;;
*)
echo "FATAL: SANDBOX_ANTHROPIC_TRANSPORT is set to '$SANDBOX_ANTHROPIC_TRANSPORT'." >&2
echo "FATAL: SANDBOX_CREDENTIAL_TRANSPORT is set to '$SANDBOX_CREDENTIAL_TRANSPORT'." >&2
echo "The only valid values are 'tls' (the default) and 'loopback'; they are" >&2
echo "case-sensitive. Not starting the session - an unrecognised value would" >&2
echo "otherwise be read as one transport here and the other by bin/dejima." >&2
exit 1
;;
esac
if [ -n "${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}" ]; then
if [ -n "${SANDBOX_CREDENTIAL_PROXY_SOCKET:-}" ]; then
forwarder_port=18300
# Which name the terminator answers for is the selected harness's, from
# `proxied_domain` in its manifest - this image is shared by every
@@ -393,7 +397,7 @@ if [ -n "${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}" ]; then
echo "Not starting the session - traffic would reach the API unintercepted." >&2
exit 1
fi
if [ "$SANDBOX_ANTHROPIC_TRANSPORT" = "tls" ]; then
if [ "$SANDBOX_CREDENTIAL_TRANSPORT" = "tls" ]; then
forwarder_port=443
# Generated here, in the container, rather than on the host: the key
# never touches host disk and there is no host state to clean up. It
@@ -401,7 +405,7 @@ if [ -n "${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}" ]; then
# unprivileged - and worthless to anyone else, since the only thing
# that trusts this anchor is this container, which is already reading
# that traffic in the clear.
tls_dir=/etc/dejima-anthropic-tls
tls_dir=/etc/dejima-credential-tls
mkdir -p "$tls_dir"
# set -e aborts the script on openssl's nonzero exit either way, so a
# failure here never proceeds to chown/export a missing cert - but
@@ -427,8 +431,8 @@ if [ -n "${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}" ]; then
chown "$SANDBOX_USER" "$tls_dir/key.pem" "$tls_dir/cert.pem"
chmod 600 "$tls_dir/key.pem"
chmod 644 "$tls_dir/cert.pem"
export SANDBOX_ANTHROPIC_TLS_CERT="$tls_dir/cert.pem"
export SANDBOX_ANTHROPIC_TLS_KEY="$tls_dir/key.pem"
export SANDBOX_CREDENTIAL_TLS_CERT="$tls_dir/cert.pem"
export SANDBOX_CREDENTIAL_TLS_KEY="$tls_dir/key.pem"
# /etc/hosts wins over DNS in getaddrinfo, so this bypasses the DNS
# proxy entirely - which is why fixed-domains.sh leaves the name off
# the allowlist whenever there is a proxy socket.
@@ -508,13 +512,19 @@ fi
# exercising the actual code path instead of a reimplementation of it that
# could drift out of sync.
if [ "${SANDBOX_TEST_MODE:-0}" = "1" ]; then
exec gosu "$SANDBOX_USER" sleep infinity
drop_caps --user="$SANDBOX_USER" -- -c 'exec "$@"' dejima sleep infinity
fi
# Drop root -> the sandbox user for the actual session; that user has no
# sudo/setuid path back to root after this, so it can't re-run
# init-firewall.sh itself to widen the allowlist mid-session.
#
# And drop the bounding set with it, so "no path back to root" and "no
# capability if there were one" are two separate things rather than one
# resting on the other. capsh does both in one process because it has to: the
# bounding set can only be reduced while CAP_SETPCAP is still held, and
# changing uid first gives it away.
#
# SANDBOX_CMD is what actually runs as that user - the selected harness's
# own command unless [core] command overrides it (e.g. to `nvim`) for an
# editor-driven workflow; pair that with SANDBOX_NVIM_CONFIG (see bin/dejima)
@@ -530,4 +540,4 @@ if [ -z "${SANDBOX_CMD:-}" ]; then
echo "command: docker run --entrypoint sh ..." >&2
exit 1
fi
exec gosu "$SANDBOX_USER" $SANDBOX_CMD "$@"
drop_caps --user="$SANDBOX_USER" -- -c 'exec "$@"' dejima $SANDBOX_CMD "$@"
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
# PID 1 of the filter container: brings this launch's egress control up, says
# so, and then holds the network namespace open for the sandbox to join.
#
# The sandbox is a separate container that joins this namespace and declares no
# network capability of its own. Capabilities are per process, so it cannot
# alter the filter installed here even at uid 0 - which is the whole reason the
# two are separate. See docs/security.md.
#
# Nothing a session runs ever executes in here. This container holds the
# privilege; the one beside it holds the session.
set -Eeuo pipefail
trap 'status=$?; echo "ERROR: filter-entrypoint.sh aborted at line $LINENO (exit $status): $BASH_COMMAND" >&2' ERR
# shellcheck source=caps-lib.sh
source /usr/local/bin/caps-lib.sh
require_setpcap
/usr/local/bin/firewall-up.sh
# Written last, and only on the success path above - `set -e` means a firewall
# that failed to come up never reaches this line. bin/dejima waits for this
# file before it starts the sandbox, so the ordering that makes the arrangement
# fail-closed is a fact about the filesystem rather than about how long a
# launcher guessed the firewall would take.
#
# Under /run, which is a tmpfs: a container that is restarted rather than
# relaunched must not inherit a marker saying its filter is up before it is.
: > /run/dejima-firewall-ready
echo "filter: egress control is up; holding the namespace for the session"
# Held open by a process that does nothing else. The namespace lives as long as
# a process is in it, and this container is started with an init that forwards
# SIGTERM, so `docker stop` ends it promptly rather than waiting out a timeout.
exec sleep infinity
+81
View File
@@ -0,0 +1,81 @@
#!/bin/bash
# Brings up this network namespace's egress control: the DNS proxy, the packet
# filter, and the two log producers that watch them.
#
# Its own script rather than a block inside entrypoint.sh because the namespace
# it acts on and the session that runs in it need not be in the same container.
# What this does is a property of a network namespace; everything else an
# entrypoint does is a property of a container.
#
# Called with the caller's environment: DEJIMA_FORGE_HOSTS, LOKI_URL,
# ALLOWED_DOMAINS, ENABLE_FIREWALL and the harness values fixed-domains.sh
# reads. It resolves nothing host-side itself.
set -Eeuo pipefail
# Same reason as entrypoint.sh's: under `set -e` alone a failure here aborts
# with no output, and the only symptom is a container that never appeared (#59).
trap 'status=$?; echo "ERROR: firewall-up.sh aborted at line $LINENO (exit $status): $BASH_COMMAND" >&2' ERR
# shellcheck source=caps-lib.sh
source /usr/local/bin/caps-lib.sh
# DEJIMA_FORGE_HOSTS is resolved host-side by bin/dejima (forge_hosts, in
# dejima-provider-lib.sh) from whichever forge is configured, so this file
# does not derive or name any one forge's hostnames itself.
#
# LOKI_URL (a full URL) still needs its own derivation here - Loki's host
# has to be reachable for log-shipper.sh to actually deliver anything.
loki_host=""
if [ -n "${LOKI_URL:-}" ]; then
loki_host=$(echo "$LOKI_URL" | sed -E 's#^[a-zA-Z]+://##; s#[:/].*##')
fi
extra_domains="${DEJIMA_FORGE_HOSTS:-} ${loki_host} ${ALLOWED_DOMAINS:-}"
if [ "${ENABLE_FIREWALL:-1}" = "1" ]; then
# dns-proxy.sh must run first: it repoints /etc/resolv.conf at a local
# dnsmasq that only resolves allowlisted names, so init-firewall.sh's own
# dig calls (and everything afterward) go through the same restriction.
EXTRA_ALLOWED_DOMAINS="${extra_domains}" /usr/local/bin/dns-proxy.sh
EXTRA_ALLOWED_DOMAINS="${extra_domains}" /usr/local/bin/init-firewall.sh
# NFLOG groups only exist once init-firewall.sh has run, so ulogd2 (the
# NFLOG consumer) and the Loki shipper start after it. Both are
# best-effort visibility on top of the enforcement above, not required
# for it - log-shipper.sh itself no-ops if LOKI_URL isn't set. Runs as
# its own unprivileged `ulogd` user (opens the NFLOG socket and output
# files first, then drops), not root - it's parsing headers from
# attacker-influenceable packets (whatever a compromised session sends),
# so a bug in it shouldn't be a path back to root in the container.
#
# `ulogd -d` daemonizes immediately and always exits 0 from this shell's
# point of view, regardless of whether the daemon itself goes on to
# start successfully - so `set -e` above won't catch a failure here (nor
# should it: logging is best-effort, not something worth failing the
# whole container over). Check separately so a failure is at least
# visible instead of silently producing no logs.
/usr/sbin/ulogd -d -u ulogd -c /etc/ulogd-sandbox.conf
sleep 0.5
if ! pgrep -x ulogd >/dev/null; then
echo "WARNING: ulogd2 failed to start - connection logging will be unavailable (see /var/log/ulogd.log)" >&2
fi
# Unlike ulogd2 above, this one stays root - deliberately, not an
# oversight. What it ships is an oversight log of the session running
# beside it, and letting the sandbox user own the shipper would let a
# compromised session tamper with or kill its own logging. Root buys
# tamper-resistance that a security log needs and a best-effort netflow
# counter does not.
#
# What it reads is dnsmasq's query log and ulogd2's output, both written
# by root-owned daemons here and neither session-writable.
#
# Root, and nothing else: it parses content the session's own traffic
# decides, and it needs no capability to read two files its gid already
# opens or to POST them. So it keeps the uid that makes it untamperable
# and holds none of the rest.
#
# It outlives this script, and reparents to the container's init when this
# one exits - which is where a daemon watching a session belongs. Started
# from the entrypoint, it was a child of the very session process it exists
# to keep an eye on.
drop_caps -- -c 'exec "$@"' dejima /usr/local/bin/log-shipper.sh &
fi
+1 -1
View File
@@ -53,7 +53,7 @@ fi
#
# Which name this is comes from the provider (proxied_domain); the rule
# about when to allowlist it is dejima's, and stays here.
if [ -z "${SANDBOX_ANTHROPIC_PROXY_SOCKET:-}" ] \
if [ -z "${SANDBOX_CREDENTIAL_PROXY_SOCKET:-}" ] \
&& [ -n "${SANDBOX_BACKEND_PROXIED_DOMAIN:-}" ]; then
FIXED_DOMAINS+=("$SANDBOX_BACKEND_PROXIED_DOMAIN")
fi
+20 -2
View File
@@ -38,6 +38,12 @@ fi
repo_dir="$PWD"
subcommand=""
argv=("$@")
# Every `-c key=value` this push carries, kept rather than only skipped. The
# question below is where the push will go, and git answers that from the
# config the push runs under - so resolving it without these would answer for
# a different configuration than the one about to be used. A one-command
# `-c remote.origin.pushurl=...` is exactly that case.
config_overrides=()
i=0
while [ "$i" -lt "${#argv[@]}" ]; do
case "${argv[$i]}" in
@@ -45,7 +51,12 @@ while [ "$i" -lt "${#argv[@]}" ]; do
i=$((i + 1))
[ "$i" -lt "${#argv[@]}" ] && repo_dir="${argv[$i]}"
;;
-c|--exec-path|--git-dir|--work-tree|--namespace|--super-prefix)
-c)
i=$((i + 1))
[ "$i" -lt "${#argv[@]}" ] \
&& config_overrides+=(-c "${argv[$i]}")
;;
--exec-path|--git-dir|--work-tree|--namespace|--super-prefix)
i=$((i + 1))
;;
-*)
@@ -97,7 +108,14 @@ while [ "$i" -lt "${#argv[@]}" ]; do
done
[ -n "$remote" ] || remote=origin
remote_url="$("$REAL_GIT" -C "$repo_dir" remote get-url "$remote" 2>/dev/null)"
# --push, because that is the URL the push will use. Without it this reads
# remote.<name>.url while git pushes to remote.<name>.pushurl when one is set,
# so a pushurl naming any other host is checked against the fetch URL and
# allowed. It needs no evasion to reach: `git -c remote.origin.pushurl=...
# push origin branch` sets one for a single command, and .git/config is in the
# read-write project mount, so a session can also just write one down.
remote_url="$("$REAL_GIT" ${config_overrides[@]+"${config_overrides[@]}"} \
-C "$repo_dir" remote get-url --push "$remote" 2>/dev/null)"
# A remote this cannot resolve is refused rather than passed through. It is
# usually a typo, which git would reject in a moment anyway - but it is also
# what a disagreement between this parser and git's looks like, and the
+22 -20
View File
@@ -28,17 +28,30 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=fixed-domains.sh
source "$SCRIPT_DIR/fixed-domains.sh"
# Docker's embedded-DNS NAT rules live in the same table we're about to
# flush - snapshot them first so they can be reinstated afterward.
docker_dns_nat_rules=$(iptables-save -t nat | grep "127\.0\.0\.11" || true)
# Reset to a known-empty state before laying down the real ruleset.
# What this script owns, and therefore what it clears: the `filter` table and
# its two ipsets. Every rule below is a `filter` append or policy - the whole
# egress decision is made there, and nothing here writes anywhere else.
#
# `nat` and `mangle` belong to the daemon that built this namespace, and are
# left to it. That is a decision rather than an omission, because `nat` can
# reach the decision this script is making: for a locally generated packet the
# order is `nat OUTPUT` -> routing -> `filter OUTPUT`, so a DNAT rewrites the
# destination before the allowlist is consulted. A rule there chooses what the
# rules below match against.
#
# It is still the daemon's to hold. It created this namespace and put the
# embedded resolver in it; a dockerd rewriting `nat` to slip a destination past
# the allowlist is one that could have skipped the firewall container
# altogether. Nothing else can write there - the session container declares no
# NET_ADMIN, and in here this script is the only thing that touches netfilter.
#
# What this script does rely on from that table is the resolver at 127.0.0.11,
# which every allowlisted lookup below goes through. Two things already refuse
# a namespace without it: dns-proxy.sh, which runs first and checks
# /etc/resolv.conf names it, and the self-check at the end of this file, which
# resolves a name and reports the whole path when it cannot.
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
ipset destroy allowed-domains 2>/dev/null || true
ipset destroy github-domains 2>/dev/null || true
@@ -104,17 +117,6 @@ else
echo "ip6tables unusable, and no IPv6 address outside loopback - nothing to filter"
fi
# Reinsert just the rules captured above - nothing else Docker had set up in
# nat comes back, so the reset above stays meaningful.
if [ -n "$docker_dns_nat_rules" ]; then
echo "Reinstating captured Docker DNS rules"
iptables -t nat -N DOCKER_OUTPUT 2>/dev/null || true
iptables -t nat -N DOCKER_POSTROUTING 2>/dev/null || true
echo "$docker_dns_nat_rules" | xargs -L 1 iptables -t nat
else
echo "No Docker DNS rules were present to restore"
fi
# Allow localhost. Every DNS query this container makes starts here: to
# dnsmasq on 127.0.0.1, and from there to Docker's embedded resolver on
# 127.0.0.11 (see resolv.conf). What this rule does NOT cover is the hop
+13
View File
@@ -48,6 +48,19 @@ ship_stream() {
last_flush=$(date +%s)
}
# tail's stderr is discarded below because -F is meant to wait for a file
# that does not exist yet, and complains once per second while it does.
# That also swallows a permission error, which is not transient and which
# looks identical from the outside: a stream that ships nothing, which is
# also what a quiet session looks like.
#
# This process holds no capabilities (see entrypoint.sh), so it reads these
# two files on their ordinary permissions and nothing else. Say so once
# when that is not enough, rather than shipping an empty stream.
if [ -e "$file" ] && [ ! -r "$file" ]; then
echo "WARNING: $file is not readable by $(id -un) - the $job stream will ship nothing." >&2
fi
last_flush=$(date +%s)
tail -F -n0 "$file" 2>/dev/null | while true; do
if IFS= read -r -t "$BATCH_MAX_SECONDS" line; then
+395 -102
View File
@@ -9,80 +9,218 @@ scratch space, and what the sandbox knows about itself.
## Configuration reference
Every key dejima reads, its default, and what it is for. All of it lives in
one file, `~/.config/dejima/config`. `./install.sh` writes a starter copy with
every key present and commented out at its default, so nothing here has to be
set to get a working sandbox: uncomment what you need. `dejima --print-config`
prints the resolved schema with real values, which is the fastest way to see
what a given launch will actually use.
Every key dejima reads, its default, and what it is for.
### Two files, and only one of them is yours
`~/.config/dejima/config` is **yours**. dejima reads it and never writes it.
`./install.sh` creates it if you have none, carrying your selection and
anything it could migrate from an older setup, and nothing else.
`~/.config/dejima/defaults.conf` beside it is **dejima's**, and holds every
defaulted key at the value dejima shipped *when this machine first saw that
key*. Your file overrides it; it overrides what the current release would have
chosen.
That second file is why a release cannot move a setting you never chose.
`[core] harness` has no default at all for this reason - a default that could
change later is a config file that is not the source of truth - and this
applies the same argument to every other key. It is not hypothetical: the
`forge` and `workflow` defaults once changed from `gitea`+`worktree-pr` to
`none`+`local-only`, which silently stopped existing sandboxes pushing.
The first launch on a machine writes it and says so once. `./install.sh`
rebuilds it: keys a release added are appended, keys it retired are dropped,
and **every value already in it stays**. When a shipped default no longer
matches your pinned one, `./install.sh` names both and the line that would
take the new one. It does not take it - that is the whole point - and the line
goes in *your* file, never in `defaults.conf`, which the next rebuild rewrites.
Do not edit `defaults.conf`. Anything in it that dejima no longer understands
is skipped rather than refused, since you are not the one who put it there, and
a launch tells you to re-run `./install.sh`.
`dejima --print-config` prints every key as it resolves. Which of the three
answered is readable from the files themselves: in `config` it is yours, in
`defaults.conf` it is pinned, in neither it is what this release ships.
**`required` in the Default column is what you have to set yourself**, and it
is exactly the set with no line in `defaults.conf`: a key with no default has
nothing to pin. Exactly one is required unconditionally - `[core] harness`.
Every other `required` is conditional on a selection you made, and each table
below says which; a section belonging to something you did not select is never
read, so its required keys are not yours to fill in.
Every tool takes `--help`, which describes its own arguments and what they do.
That is the fastest answer to "what does this flag mean"; this page is for the
config file behind them.
### `[core]` - what this sandbox runs
The three selections come first because everything below depends on them: the
harness decides which `[harness.<name>]` section is read, and the forge decides
which `[forge.<name>]`.
| Key | Default | Purpose |
| --- | --- | --- |
| `[core] harness` | *(none - must be set)* | agent harness the container runs; refused if unset, so a later default cannot change your selection. Also settable per launch with `--harness`, which is how a host keeps one harness as its default and reaches another when it wants to |
| `[core] forge` | `none` | forge integration: `gitea` (`gitea-pr`/`gitea-issue`), `github` (`gh`/`github-pr`, opens `ssh.github.com:22` for push), or `none` (no forge at all) |
| `[core] workflow` | `local-only` | workflow `sandbox-context.sh` tells the agent to follow: `worktree-pr` (push + open a PR), `branch-push` (push, stop at the branch), or `local-only` (commit locally, push nothing) |
| `[core] command` | *(the selected harness's own `command`)* | container's main process (e.g. `nvim`), also settable per launch with `--cmd`. Overriding it changes what dejima launches, not which harness is wrapped |
| `[core] identity` | unset | which `[identity.<name>]` section supplies the credentials and git name this session acts under; also settable per launch with `--identity`, which is how one host runs a session per account. Unset selects `[identity.default]` where the config has one. A name with no section is refused rather than falling back |
| `[core] tools` | unset | optional tools to put in the image, colon-separated; also `.dejima/tools` in a project (approved first) and `--include` per launch. None by default. See [docs/tools.md](tools.md) |
| `[core] update_check` | `on` | at startup, say when this checkout is behind the branch it tracks. One `ls-remote` to your own remote, at most hourly, never fetching; `off` makes dejima contact nothing of its own accord. The answer is cached in `~/.local/share/dejima/update-check`, which is safe to delete |
| `[ui] banner` | `on` | the three-line summary at the top of a launch - project and branch, the selection, and the switches whose state changes what a session can do. `off` prints nothing. Never drawn when output is redirected |
| `[core] firewall` | `on` | egress firewall; `off` disables it (debugging only), also settable per launch with `--no-firewall` |
| `[core] share_dir` | `~/.local/share/dejima/shared` | host-visible read/write scratch dir. One directory per project underneath it, and only that project's is mounted at `~/shared`. `dejima-share` is the host side of it |
| `[core] ssh_key` | unset | **deprecated** - the pre-identity spelling of `[identity.default] ssh_key`. Still read when the config has no `[identity.default]`; refused when it has one, since the two say the same thing |
| `[core] known_hosts` | `~/.ssh/known_hosts` | known-hosts file used for git-over-ssh |
| `[harness.claude-code] backend` | *(none - must be set)* | which model API this harness talks to, and so which credential the proxy injects. A directory under `backends/`, each shipping its own `[backend.<name>]` keys. Per harness rather than global, because running Claude Code against Anthropic and Cline against something else is the ordinary case. No default, for the reason `[core] harness` has none: one that could change later would move a session to another endpoint without its config changing. Unset, dejima writes `anthropic` into your config once and says so - a migration rather than a default, so nothing it decides later can move you. Also settable per launch with `--backend`. See [providers.md](providers.md#model-backends) |
| `[harness.claude-code] projects_dir` | `~/.claude/projects` | where Claude Code session transcripts live |
| `[harness.claude-code] file_history_dir` | `~/.claude/file-history` | Claude Code's edit-undo record, mounted per session rather than whole |
| `[harness.claude-code] statusline_path` | `~/.claude/statusline.sh` | statusline script path |
| `[harness.cline] backend` | *(none - must be set)* | as above, and the risk is concrete here: Cline supports many backends and has one of its own. Nothing is written for you either, because what this harness talked to before the key existed depends on `base_url`. Also settable per launch with `--backend` |
| `[backend.anthropic] credential_file` | `~/.claude/.credentials.json` | the host file this backend's credential is read from, per request. A path, never a secret, and never mounted into the container |
| `[backend.self-hosted] base_url` | *(none - must be set)* | where you serve the model. A loopback or RFC 1918 address, or a host you have allowlisted - it has to be an endpoint needing no credential, since there is none to withhold. On the backend rather than the harness, so a local endpoint stays configured while a hosted API is selected |
| `[backend.anthropic-api-key] credential_file` | `~/.claude.json` | where your Anthropic API key is. Defaulted to where Claude Code's console login puts it, so the common case needs nothing set; point it at a file of your own if you hold the key yourself. Read host-side per request and never mounted, and the key is stripped from the copy of `~/.claude.json` dejima stages |
| `[backend.anthropic-api-key] credential_field` | `primaryApiKey` | which value inside that file is the key, as dot-separated object names. Clear it (`credential_field =`) when the file is nothing but the key |
| `[backend.<name>] proxy` | *(inherits `[credentials] proxy`)* | whether the credential proxy runs for this backend. Per backend so that one backend the proxy cannot serve is not a reason to stop withholding credentials from the ones it can. Off means this backend's real credential is given to the session, and dejima says so at launch |
| `[backend.openrouter] credential_file` | *(none - must be set)* | your OpenRouter API key, in a file. Read host-side per request and never mounted; the container only ever holds a placeholder. No default, because a key's location is yours and guessing at one would point dejima at a file it has no reason to think exists |
| `[harness.cline] model` | *(none - must be set)* | model id the endpoint serves; no default, because any shipped one goes stale with the next Cline release. Also settable per launch with `--model` |
| `[harness.cline] context_window` | unset | tokens Cline may use before compacting. Needed for a model it has no catalogue entry for, which is every self-served one. Also settable per launch with `--context-window` |
| `[harness.cline] state_dir` | `~/.local/share/dejima/cline` | per-project Cline state; one directory per workspace |
| `[forge.gitea] ssh_host` | unset | Gitea/Forgejo SSH hostname: skip if you only push to GitHub |
| `[forge.gitea] api` | unset | `https://<gitea host>/api/v1`: skip if you only push to GitHub |
| `[forge.gitea] token_file` | `~/.config/gitea/token` | path to the Gitea/Forgejo API token (the file, not the token itself) |
| `[forge.github] push_token_file` | unset | path to a **write-capable** PAT, used only when `[core] forge = github`: deliberately separate from `[github] token_file` below; see "GitHub push" in docs/security.md |
| `[github] token_file` | `~/.config/gh/sandbox-token` | path to a read-only PAT for private GitHub repos / `gh` |
| `[mounts] readonly` | unset | extra host paths (colon-separated) a personal config needs, mounted read-only at their own path |
| `[mounts] read_write` | unset | host paths (colon-separated) mounted **read-write** at their own path: for directories meant to outlive the session; refused if they overlap anything dejima needs out of a session's reach |
| `[mounts] nvim_config` | unset | nvim config dir, used when `[core] command = nvim` |
| `[credentials] proxy` | `on` | host-side credential proxy; `off` mounts the real OAuth credential into the container directly |
| `[credentials] transport` | `tls` | set to `loopback` to fall back to a plaintext forwarder with an explicit `ANTHROPIC_BASE_URL`, keeping the credential out of the container but reinstating the base-URL fingerprint: for when certificate pinning breaks the default TLS path (see [security notes](security.md)) |
| `[logging] loki_url` | unset | ship DNS/firewall logs to a Loki endpoint; `--no-log` clears it for one launch, which silences everything downstream of it |
| `[epitaph] enabled` | `on` | keep the summary a harness writes when a session compacts; `--no-epitaph` skips it for one launch |
| `[epitaph] dir` | `~/.local/share/dejima/epitaphs` | where they are kept; never mounted into a container |
| `[epitaph] loki` | `off` | also push each epitaph to `[logging] loki_url`, host-side |
| `[logging] conversation` | `off` | opt-in: also ship session transcripts to Loki (needs `loki_url`); see "Conversation logging (opt-in)" in docs/security.md. `--no-conversation` turns it off for one launch, and `--no-log` implies it |
| `[audit] dir` | `~/.local/share/dejima/audit` | where exit-time audit findings are stored |
| `[audit] baselines_dir` | `~/.local/share/dejima/baselines` | where audit baselines are stored |
| `[audit] keep` | `10` | how many past findings/baselines to retain |
| `[audit] diffs` | `on` | keep the diff of what changed alongside each finding; `off` records that something changed without retaining the content |
| `[audit] strict` | `off` | refuse a headless (non-tty) launch over unacknowledged CRITICAL findings; also settable per launch with `--strict-audit` |
| `[remote-access] enabled` | `off` | the switch: nothing in "Remote access" below runs until this is `on` |
| `[remote-access] ntfy_url` | unset | ntfy topic URL for session notifications |
| `[remote-access] base_url` | unset | public URL of the web front door, for notification links |
| `[remote-access] ttyd_port` | `7681` | port `ttyd` listens on |
| `[remote-access] ttyd_font_size` | unset | `ttyd` terminal font size |
| `[remote-access] ttyd_tmux_prefix` | unset | the tmux prefix the page's buttons send; the page assumes stock `C-b` without it |
| `[remote-access] ttyd_focus_on_tap` | unset | `on` lets a tap on the terminal raise the phone keyboard; unset means only the KBD button does |
| `[remote-access] ttyd_button_colors` | unset | `off` returns the toolbar to monochrome |
| `[remote-access] debounce` | `60` | seconds between repeat notifications for the same session |
| `harness` | **required** | agent harness the container runs; refused if unset, so a later default cannot change your selection. Also settable per launch with `--harness`, which is how a host keeps one harness as its default and reaches another when it wants to |
| `forge` | `none` | forge integration: `gitea` (`gitea-pr`/`gitea-issue`), `github` (`gh`/`github-pr`, opens `ssh.github.com:22` for push), or `none` (no forge at all) |
| `workflow` | `local-only` | workflow the session briefing tells the agent to follow: `worktree-pr` (push + open a PR), `branch-push` (push, stop at the branch), or `local-only` (commit locally, push nothing) |
| `identity` | unset | which `[identity.<name>]` section supplies the credentials and git name this session acts under; also settable per launch with `--identity`, which is how one host runs a session per account. Unset selects `[identity.default]` where the config has one. A name with no section is refused rather than falling back |
| `command` | *(the selected harness's own)* | container's main process (e.g. `nvim`), also settable per launch with `--cmd`. Overriding it changes what dejima launches, not which harness is wrapped |
| `tools` | unset | optional tools to put in the image, colon-separated; also `.dejima/tools` in a project (approved first) and `--include` per launch. None by default. See [docs/tools.md](tools.md) |
| `firewall` | `on` | egress firewall; `off` disables it (debugging only), also settable per launch with `--no-firewall` |
| `share_dir` | `~/.local/share/dejima/shared` | host-visible read/write scratch dir. One directory per project underneath it, and only that project's is mounted at `~/shared`. `dejima-share` is the host side of it |
| `known_hosts` | `~/.ssh/known_hosts` | known-hosts file used for git-over-ssh |
| `update_check` | `on` | at startup, say when this checkout is behind the branch it tracks. One `ls-remote` to your own remote, at most hourly, never fetching; `off` makes dejima contact nothing of its own accord. The answer is cached in `~/.local/share/dejima/update-check`, which is safe to delete |
| `ssh_key` | unset | **deprecated** - the pre-identity spelling of `[identity.default] ssh_key`. Still read when the config has no `[identity.default]`; refused when it has one, since the two say the same thing |
**No forge is the default**: `[core] forge = none` with
`[core] workflow = local-only`, so the sandbox works locally and pushes
nowhere. Every other workflow needs forge credentials, which is what you are
opting into when you pick one.
### `[harness.<name>]` - the harness you selected
One section per harness, and only the one `[core] harness` names is read. Each
ships its own keys; see [providers.md](providers.md) for the manifest contract
behind them.
#### `[harness.claude-code]`
| Key | Default | Purpose |
| --- | --- | --- |
| `backend` | **required** | which model API this harness talks to, and so which credential the proxy injects. A directory under `backends/`, each shipping its own `[backend.<name>]` keys. Per harness rather than global, because running Claude Code against Anthropic and Cline against something else is the ordinary case. No default, for the reason `[core] harness` has none: one that could change later would move a session to another endpoint without its config changing. Unset, dejima writes `anthropic` into your config once and says so - a migration rather than a default, so nothing it decides later can move you. Also settable per launch with `--backend`. See [providers.md](providers.md#model-backends) |
| `projects_dir` | `~/.claude/projects` | where Claude Code session transcripts live |
| `file_history_dir` | `~/.claude/file-history` | Claude Code's edit-undo record, mounted per session rather than whole |
| `statusline_path` | `~/.claude/statusline.sh` | statusline script path |
#### `[harness.cline]`
| Key | Default | Purpose |
| --- | --- | --- |
| `backend` | **required** | as above, and the risk is concrete here: Cline supports many backends and has one of its own. Nothing is written into your config for you either, unlike Claude Code: there is no one endpoint every existing Cline session was already using, so any value dejima recorded would be a guess. Also settable per launch with `--backend` |
| `model` | **required** | model id the endpoint serves, exactly as that endpoint spells it - a hosted catalogue namespaces by vendor (`z-ai/glm-5.3`) and may qualify a variant (`deepseek/deepseek-r1:free`). No default, because any shipped one goes stale with the next Cline release. Also settable per launch with `--model` |
| `context_window` | unset | tokens Cline may use before compacting. Needed for a model it has no catalogue entry for, which is every self-served one. Also settable per launch with `--context-window` |
| `state_dir` | `~/.local/share/dejima/cline` | per-project Cline state; one directory per workspace |
### `[backend.<name>]` - the model API you selected
One section per backend, and only the one your harness's `backend` names is
read. `proxy` is available in every one of them; the rest are that backend's
own. See [providers.md](providers.md#model-backends) for how much use each has
actually had.
| Key | Default | Purpose |
| --- | --- | --- |
| `[backend.<name>] proxy` | *(inherits `[credentials] proxy`)* | whether the credential proxy runs for this backend. Per backend so that one backend the proxy cannot serve is not a reason to stop withholding credentials from the ones it can. Off means this backend's real credential is given to the session, and dejima says so at launch |
| `[backend.anthropic] credential_file` | `~/.claude/.credentials.json` | the host file this backend's credential is read from, per request. A path, never a secret, and never mounted into the container |
| `[backend.anthropic-api-key] credential_file` | `~/.claude.json` | where your Anthropic API key is. Defaulted to where Claude Code's console login puts it, so the common case needs nothing set; point it at a file of your own if you hold the key yourself. Read host-side per request and never mounted, and the key is stripped from the copy of `~/.claude.json` dejima stages |
| `[backend.anthropic-api-key] credential_field` | `primaryApiKey` | which value inside that file is the key, as dot-separated object names. Clear it (`credential_field =`) when the file is nothing but the key |
| `[backend.openrouter] credential_file` | **required** | your OpenRouter API key, in a file. Read host-side per request and never mounted; the container only ever holds a placeholder. No default, because a key's location is yours and guessing at one would point dejima at a file it has no reason to think exists |
| `[backend.self-hosted] base_url` | **required** | where you serve the model. A loopback or RFC 1918 address, or a host you have allowlisted - it has to be an endpoint needing no credential, since there is none to withhold. On the backend rather than the harness, so a local endpoint stays configured while a hosted API is selected |
### `[credentials]` - how the credential is withheld
| Key | Default | Purpose |
| --- | --- | --- |
| `proxy` | `on` | host-side credential proxy; `off` mounts the real credential into the container directly. Overridable per backend with `[backend.<name>] proxy` |
| `transport` | `tls` | set to `loopback` to fall back to a plaintext forwarder with an explicit base URL, keeping the credential out of the container but reinstating the base-URL fingerprint: for when certificate pinning breaks the default TLS path (see [security notes](security.md)) |
### `[identity.<name>]` - who the session acts as
Groups the SSH key, the git name and the forge credential belonging to one
account, so a host can run a session per account. Selected by `[core]
identity`, or `[identity.default]` when that is unset. Nothing here is
required: an identity supplies what it names and no more.
| Key | Default | Purpose |
| --- | --- | --- |
| `ssh_key` | unset | the SSH key this identity pushes with |
| `user_name` | unset | `user.name` for commits made in the session |
| `user_email` | unset | `user.email` for commits made in the session |
| `token_file` | *(the forge's own default)* | this identity's Gitea/Forgejo API token, overriding `[forge.gitea] token_file`. Read only when `[core] forge = gitea` |
| `push_token_file` | unset | this identity's write-capable GitHub PAT, overriding `[forge.github] push_token_file`. Read only when `[core] forge = github` |
See [Identities](#identities) below for the worked examples.
### `[forge.<name>]` and `[github]` - forge credentials
Only the section `[core] forge` names is read. `[github]` is separate from
`[forge.github]` on purpose: the first is read access to GitHub whichever forge
you selected, the second is push access when GitHub *is* your forge.
| Key | Default | Purpose |
| --- | --- | --- |
| `[forge.gitea] ssh_host` | **required** for `forge = gitea` | Gitea/Forgejo SSH hostname |
| `[forge.gitea] api` | **required** for `forge = gitea` | `https://<gitea host>/api/v1` |
| `[forge.gitea] token_file` | `~/.config/gitea/token` | path to the Gitea/Forgejo API token (the file, not the token itself) |
| `[forge.github] push_token_file` | unset | path to a **write-capable** PAT, used only when `[core] forge = github`: deliberately separate from `[github] token_file`; see "GitHub push" in [docs/security.md](security.md) |
| `[github] token_file` | `~/.config/gh/sandbox-token` | path to a read-only PAT for private GitHub repos / `gh`. Read whichever forge is selected, and it should stay read-only |
### `[mounts]` - extra host paths
| Key | Default | Purpose |
| --- | --- | --- |
| `readonly` | unset | extra host paths (colon-separated) a personal config needs, mounted read-only at their own path |
| `read_write` | unset | host paths (colon-separated) mounted **read-write** at their own path: for directories meant to outlive the session and be shared by every project; refused if they overlap anything dejima needs out of a session's reach |
| `read_write_per_project` | unset | the same, mounted at the path named but backed by `<path>/projects/<slug>` - one directory per project rather than one for the host. For anything a session writes to be read later as background, where another project reading it would be a channel rather than a convenience |
| `nvim_config` | unset | nvim config dir, used when `[core] command = nvim` |
### `[audit]` - the exit-time audit
| Key | Default | Purpose |
| --- | --- | --- |
| `dir` | `~/.local/share/dejima/audit` | where exit-time audit findings are stored |
| `baselines_dir` | `~/.local/share/dejima/baselines` | where audit baselines are stored |
| `keep` | `10` | how many past findings/baselines to retain |
| `diffs` | `on` | keep the diff of what changed alongside each finding; `off` records that something changed without retaining the content |
| `strict` | `off` | refuse a headless (non-tty) launch over unacknowledged CRITICAL findings; also settable per launch with `--strict-audit` |
### `[epitaph]` - what a compacted session leaves behind
| Key | Default | Purpose |
| --- | --- | --- |
| `enabled` | `on` | keep the summary a harness writes when a session compacts; `--no-epitaph` skips it for one launch |
| `dir` | `~/.local/share/dejima/epitaphs` | where they are kept; never mounted into a container |
| `loki` | `off` | also push each epitaph to `[logging] loki_url`, host-side |
### `[logging]` - shipping logs off the host
Off entirely until `loki_url` is set. Nothing leaves the machine otherwise,
and there is no endpoint of dejima's own anywhere in this.
| Key | Default | Purpose |
| --- | --- | --- |
| `loki_url` | unset | ship DNS/firewall logs to a Loki endpoint; `--no-log` clears it for one launch, which silences everything downstream of it |
| `conversation` | `off` | opt-in: also ship session transcripts to Loki (needs `loki_url`); see "Conversation logging (opt-in)" in [docs/security.md](security.md). `--no-conversation` turns it off for one launch, and `--no-log` implies it |
### `[remote-access]` - the web front door
Off entirely until `enabled` is `on`. The `ttyd_*` keys configure the terminal
page and are read once at process start, so editing them needs
`systemctl --user restart dejima-ttyd.service`. See
[docs/remote-access.md](remote-access.md).
| Key | Default | Purpose |
| --- | --- | --- |
| `enabled` | `off` | the switch: nothing else here runs until this is `on` |
| `ntfy_url` | **required** for notifications | ntfy topic URL for session notifications. `dejima-notify-watch` refuses to start without it; nothing else reads it |
| `base_url` | unset | public URL of the web front door, for the notification's deep link. Absent, pushes still go out - just with no link on them |
| `debounce` | `60` | seconds between repeat notifications for the same session |
| `ttyd_port` | `7681` | loopback port `ttyd` listens on; the reverse proxy has to `proxy_pass` to the same one |
| `ttyd_font_size` | unset | terminal font size in px, 8-72. Applies to every client, phone and desktop alike |
| `ttyd_tmux_prefix` | unset | the tmux prefix the page's buttons send; the page assumes stock `C-b` without it |
| `ttyd_focus_on_tap` | unset | `on` lets a tap on the terminal raise the phone keyboard; unset means only the KBD button does |
| `ttyd_button_colors` | unset | `off` returns the toolbar to monochrome |
### `[ui]` - what a launch prints
| Key | Default | Purpose |
| --- | --- | --- |
| `banner` | `on` | the three-line summary at the top of a launch - project and branch, the selection, and the switches whose state changes what a session can do. `off` prints nothing. Never drawn when output is redirected |
## Global and per-project domains and dependencies
Allowed domains and dependencies each stack through their own layers. The
@@ -340,7 +478,9 @@ you don't have one.
### Cline
Almost nothing carries over, and that is the design rather than a gap.
Your own configuration carries over the same way Claude Code's does - the
table under [What comes in from your host](#what-comes-in-from-your-host) is
the list. Your *sessions* do not, and that is the design rather than a gap.
Cline keeps one `sessions.db` indexing every session it has ever run, with
the project a session belonged to as a field inside the record rather than a
@@ -351,21 +491,33 @@ under `[harness.cline] state_dir` (default `~/.local/share/dejima/cline`),
mounted at `~/.cline/data` in the container. Sessions persist across runs of
the same project and are invisible to every other project.
Because that directory is dejima's rather than yours, resuming on the host
needs `CLINE_DATA_DIR` set to it. The exact command is at the end of every
session's briefing.
Because that directory is dejima's rather than yours, resuming on the host is
not a supported path - see
[Sessions, and where they live](#sessions-and-where-they-live) below. Relaunch
dejima on the same project instead, which is what the briefing tells the
session to offer.
The model configuration is written fresh by dejima at each launch and is
not yours either. Two shapes are supported:
The model configuration is written fresh by dejima at each launch and is not
yours either. Where the model is comes from `[harness.cline] backend` and
nowhere else, so there is no second setting for it to disagree with, and two
shapes are supported:
- **`base_url` unset** - Anthropic, reached through dejima's own credential
proxy exactly as Claude Code is. What is written into the container is the
placeholder `sandbox-credential-proxy-placeholder`; the real credential
stays on the host.
- **`base_url` set to a model you serve yourself** - either a loopback or
RFC 1918 address, or a host you have allowlisted with `dejima-allow`.
- **A backend the proxy serves** (`anthropic`, `anthropic-api-key`,
`openrouter`) - reached through dejima's own credential proxy exactly as
Claude Code is. What is written into the container is the placeholder
`sandbox-credential-proxy-placeholder` and the endpoint's real hostname; the
credential stays on the host. Which of Cline's own provider types dejima
writes comes from the backend's `api_style`: its native Anthropic client for
one, its OpenAI-compatible client for the other.
- **A backend with no credential** (`self-hosted`, carrying its own
`[backend.self-hosted] base_url`) - a model you serve, at either a loopback
or RFC 1918 address or a host you have allowlisted with `dejima-allow`.
Nothing needs a credential, so there is nothing to withhold.
Keeping the address on the backend rather than on the harness is what lets you
have a local model and a hosted API both configured and switch between them by
changing one word.
A name qualifies through the allowlist rather than through how it is spelled,
because that is the same store deciding whether the container can reach the
endpoint at all: one that fails the check is one the session could not have
@@ -373,13 +525,13 @@ connected to anyway. A model server on your own network normally has a name,
so requiring a literal address would have made this path unusable for the
ordinary case.
Anything else is refused at launch - a hosted backend's API key would have to
go inside the container, and dejima has no proxy that could hold one back on
its behalf. Note what the check is *not* doing: dejima writes a placeholder
into the container on this path whatever the endpoint is, so no real
credential enters it either way. What the check decides is whether the
configuration can work at all, which is worth saying at launch rather than as
an auth error three layers down. See
Anything else is refused at launch - a hosted API pointed at through a
no-credential backend would want its key inside the container, and dejima has
no proxy that could hold one back on its behalf. Note what the check is *not*
doing: dejima writes a placeholder into the container on the proxied path
whatever the endpoint is, so no real credential enters it either way. What the
check decides is whether the configuration can work at all, which is worth
saying at launch rather than as an auth error three layers down. See
[development.md](development.md#worked-example-cline).
If the endpoint serves a model Cline has no catalogue entry for - which is every
@@ -415,6 +567,96 @@ editing the base `Dockerfile`: a dependency added that way is declared,
approved and layered like any other, and it survives a rebuild. Editing the
Dockerfile directly puts it outside that record.
#### Sessions, and where they live
This project's Cline state - sessions, transcripts, tasks - is kept on the host
in `~/.local/share/dejima/cline/<project>` and mounted at `~/.cline/data`. It
survives the container being replaced, so **launching dejima again on the same
project picks up where the last session left off.**
A directory per project rather than one shared: Cline indexes every session it
has ever run in a single database, so sharing one would put every project's
history in every project's context - the same boundary `~/.claude/projects`
gets, for the same reason.
**Cline sessions are not importable or exportable.** A session started by
running `cline` on your own machine is in `~/.cline/data` and is not visible
inside dejima; a session started inside dejima is in the per-project directory
and is not offered back to a host-side Cline. There is no import, no export,
and no merge - see
[#301](https://gitbox.branderson.io/dejima/dejima/issues/301) for why that was
looked at and not built.
The session briefing tells a Cline agent this, so it will not offer to hand
you a session to resume outside the sandbox. Claude Code can be resumed on the
host and its briefing says so; the claim lives in each harness's own briefing
fragment rather than in the shared preamble, because only one of them can make
it.
#### What comes in from your host
The same shape as Claude Code's, and for the same reason: your own
configuration should reach a session, and nothing the session writes should
reach your machine.
| Host path | How it arrives | Why |
| --- | --- | --- |
| `~/.agents/skills/` | read-only mount | skills are instructions the agent follows |
| `~/.agents/hooks/`, `~/.cline/hooks/` | read-only mount | hooks are programs cline runs |
| `~/.agents/AGENTS.md` | read-only copy | instructions; a copy also survives it being a symlink into a dotfiles checkout |
| `~/.agents/rules/*.md`, `*.txt` | read-only copy, into `Documents/Cline/Rules/` | see below |
| `~/Documents/Cline/Rules/*.md`, `*.txt` | read-only copy | the location cline actually reads |
| `~/.cline/settings.json`, `~/.cline/cline_mcp_settings.json` | writable copy, discarded | cline rewrites both as it runs |
| `~/.cline/data/` | this project's own state directory | see above |
Read-only is the point rather than caution. A session that could rewrite a
hook, a skill or an MCP server definition would be choosing what happens on
**your** machine the next time you start cline outside a container - which is
persistence for a prompt injection, in files nobody re-reads before the next
run. The two settings files are copies rather than read-only mounts because
cline rewrites them itself; the copy is discarded with the container.
The read-only directories are scanned for symlinks, so a `skills/` that is a
link into a dotfiles checkout brings its target too. dejima refuses a target
that overlaps one of its own guarded stores.
**Global rules come from two places and land in one.** cline loads them from
`~/Documents/Cline/Rules` and nowhere else - `~/.agents/rules` reads like the
obvious companion to `~/.agents/skills` and is not loaded, which you can see
by planting a file in each and opening `cline config`. So dejima copies the
files from *both* host locations into the one directory cline reads, rather
than mounting `~/.agents/rules` where nothing would look at it.
They are copied file by file rather than mounted as a directory, because
dejima writes its own briefing into that same directory and a read-only mount
over it would leave nowhere to put it.
Two collisions have fixed answers. A name present in **both** host locations
is taken from `Documents/Cline/Rules`, since that is cline's own location for
rules and where it writes when you edit them through cline. A host file named
`00-dejima.md` is skipped: that is the briefing's name, and dejima's wins.
## What dejima says before it starts
Some launches print a notice first: an environment variable that is no longer
read, a deprecated key, a guard that is not registered, a line dejima wrote
into your config. Everything after that is the image build, which on a cold
cache is thousands of lines - so when a notice was printed, dejima waits for
Enter before starting it.
The wait happens only when there was something to read, and only when a
terminal is attached. An unattended launch never blocks on it.
`--no-pause` skips the wait and still prints the notice. It is for starting
several sessions at once - a tmuxinator layout, a script - where every one of
them has a terminal and none of them wants a keypress. It is a flag rather
than a config key on purpose: it describes the terminal in front of one
launch, not a standing preference.
A long list of entries left in the shared directory is sampled rather than
printed whole, for the same reason: it is a standing condition you clear once,
and it should not push the things about this run off the screen.
## Identities
**Several accounts on one machine, and none of them yours.** An
@@ -601,23 +843,57 @@ session is meant to write to and whose contents should outlive the container:
```
[mounts]
read_write = ~/specs
read_write = ~/.cache/shared-toolchain
```
Both lists mount at the host path they name, so a convention that says
`[mounts] read_write_per_project` mounts at the same path, but backs it with
one directory per project instead of the whole thing:
```
[mounts]
read_write_per_project = ~/specs
```
The container sees `~/specs` either way. Behind it, `read_write` puts the
directory itself - every session's contents, including other projects' - and
`read_write_per_project` puts `~/specs/projects/<slug>`, keyed the same way
`[core] share_dir` and the audit store are.
**Which to reach for is decided by one question: should another project's
session read what this one leaves there?** For a build cache or a directory of
scripts, yes, and `read_write` is right. For design docs, scratch notes,
anything an agent writes to be read later as background - no, and that is what
`read_write_per_project` is for. A spec is written to be read as context, so a
shared one is a channel from any project into every other.
All three lists mount at the host path they name, so a convention that says
"specs live in `~/specs`" keeps working inside the container without being
rewritten. That is the difference from `[core] share_dir`, which is
mounted at `~/shared` regardless of where it lives on the host because its job
is to be a well-known handoff point.
dejima creates the per-project directory; it never creates the one you named,
so a path that is not there is refused as the typo it is. Naming a
`read_write_per_project` root's `projects` directory in either of the other
two lists is refused as well - handing that over is handing over every
project's.
An entry is **refused, not warned about**, if it overlaps anything dejima
relies on being out of a session's reach: the approval store, either audit
store, `~/.claude`, `~/.local/bin`, dejima's own checkout, or the project mount
(already read-write, so listing it again is a mistake worth surfacing). A
writable mount over any of those would let a session approve its own domains,
delete the audit findings naming it, or plant code that runs unsandboxed on the
host next time you start an agent. Overlap is checked in both directions after
resolving symlinks, so `read_write = ~` is caught too.
store, the epitaph store, every project's share, `~/.local/bin`, dejima's own
checkout, the project mount (already read-write, so listing it again is a
mistake worth surfacing), and **everything the selected harness keeps on the
host** - its config directories, the files staged and seeded from them, and
the state directories its manifest declares. A writable mount over any of
those would let a session approve its own domains, delete the audit findings
naming it, read another project's transcripts, or plant code that runs
unsandboxed on the host next time you start an agent. Overlap is checked in
both directions after resolving symlinks, so `read_write = ~` is caught too.
The harness half of that list is derived from what the harness declares, not
written down in dejima, so it covers whichever one you selected - `~/.claude`
for Claude Code, `~/.agents` and `~/.cline` for Cline - and covers a harness
added later without anyone extending a list.
Sessions are told which directories these are, so "everything else is
disposable" stays true in the briefing rather than becoming a trap.
@@ -696,17 +972,27 @@ dejima-share adopt # move files left loose in share_dir into this proj
launching. That is what makes the inbound direction work without a mount that
every project can read.
**From another machine,** `sshfs` puts a project's share in your own file
manager over the SSH access you already have. Read
[Mounting the box's files](remote-access.md#mounting-the-boxs-files) before
setting that up: every byte and every filename in there was written by a
sandboxed session, and a desktop that mounts the directory indexes,
thumbnails and previews what it finds without waiting to be asked. Nothing
dejima runs is in that path, so the sanitising it does for its own output does
not reach there.
Treat it as a handoff point, not as general-purpose storage. If your own
project instructions tell agents to write somewhere at a fixed host path -
design docs, scratch notes, anything meant to outlive the session but stay out
of the project checkout - mount that directory instead, with
`[mounts] read_write`. It arrives at its own absolute path, so a convention
that says "put specs in `~/specs`" keeps working inside the container without
being rewritten to point at `~/shared`.
`[mounts] read_write_per_project`. It arrives at its own absolute path, so a
convention that says "put specs in `~/specs`" keeps working inside the
container without being rewritten to point at `~/shared` - and, like `~/shared`
itself, what a session finds there is this project's and not every project's.
`~/shared`, the project mount, and anything in `[mounts] read_write` are the
only writable host paths in the container. Everything else a session writes
goes away with it.
`~/shared`, the project mount, and anything in `[mounts] read_write` or
`[mounts] read_write_per_project` are the only writable host paths in the
container. Everything else a session writes goes away with it.
**Clear it out periodically.** The per-project split bounds which sessions can
read what you left, and bounds nothing about how long. A project's share
@@ -820,14 +1106,21 @@ session can run.
### The session briefing
A `SessionStart` hook (`~/.claude/hooks/sandbox-context.sh`) injects a
reminder when `DEJIMA` is set: the session is running in a
disposable, firewalled container and should stay within the task at hand -
if something genuinely needs to break out (broader network, host changes,
GUI/hardware), stop and ask rather than trying to work around the firewall,
since the same session can be resumed unrestricted on the host via
`claude --resume`. No-op outside the container. `deny-dangerous-bash.sh`
(`PreToolUse`) also applies here, since `~/.claude/hooks` is mounted in.
Every session is told where it is running: a disposable, firewalled container
it should stay within, and if something genuinely needs to break out - broader
network, host changes, GUI/hardware - it should stop and ask rather than work
around the firewall. Whether the session can be resumed unrestricted on the
host afterwards is the harness's own answer, and each harness's briefing
fragment gives it: Claude Code's names `claude --resume`, Cline's says plainly
that its sessions do not leave the sandbox.
*How* the briefing reaches a session is per harness too, because they do not
agree on a mechanism. Claude Code takes it as a system prompt through the flag
its manifest names; Cline takes no such flag and registers no hook, so
`entrypoint.sh` renders it into a file the harness reads, root-owned and
read-only. A harness doing neither gets it through a `SessionStart` hook. What
the briefing *says* is none of theirs - one script composes it for all three
routes. See [development.md](development.md).
When GitHub is a push destination this session - `--allow-github-push`, or
`forge = github` under a pushing workflow - the briefing also tells the
+54 -34
View File
@@ -14,10 +14,13 @@ run them.
| `docker/install-forge-bins.sh` | Installs each forge's CLIs into the image from its manifest's `install` list, and fails the build on a file that is shipped but not declared, or declared but not shipped |
| `docker/fixed-domains.sh` | Shared domain list sourced by both `init-firewall.sh` and `dns-proxy.sh` |
| `docker/dns-proxy.sh` | Starts the DNS-allowlisting `dnsmasq`, repoints `resolv.conf` at it |
| `docker/init-firewall.sh` | IPv4/IPv6 egress allowlist firewall, run at container start |
| `docker/init-firewall.sh` | IPv4/IPv6 egress allowlist firewall, run at filter-container start |
| `docker/firewall-up.sh` | Brings a network namespace's egress control up: the DNS proxy, the packet filter, and the two log producers. What a namespace needs, rather than what a container does |
| `docker/filter-entrypoint.sh` | PID 1 of the filter container: runs `firewall-up.sh`, signals readiness, then holds the namespace open for the sandbox to join |
| `docker/caps-lib.sh` | `drop_caps` and the `CAP_SETPCAP` precondition, sourced by both entrypoints so the two cannot drift |
| `docker/ulogd.conf` | `ulogd2` config: turns `init-firewall.sh`'s NFLOG-tagged packets into JSON |
| `docker/log-shipper.sh` | Tails the dnsmasq/ulogd2 logs and ships them to the configured Loki endpoint (`[logging] loki_url`). Container-side, because those files only exist there |
| `docker/entrypoint.sh` | Runs as root: DNS proxy, firewall, logging, drops to the sandbox user via `gosu`, then execs the session's command |
| `docker/entrypoint.sh` | PID 1 of the session container: runs as root to prepare the session's own state, points `resolv.conf` at the namespace's resolver, then execs the session's command as the sandbox user with an empty capability bounding set. The egress control is the filter container's to bring up, not this one's |
| `docker/harness-wrapper.sh` | Shadows the selected harness's command on `PATH` to add its no-confirm flags and dejima's settings layer. Named by no harness; `entrypoint.sh` links it into place |
| `docker/docker-compose.yml` | Wires up mounts/env; invoked via `bin/dejima`, not directly |
| `hooks/sandbox-context.sh` | `SessionStart` hook: injects sandbox context/workflow reminders, and any `.dejima.md` the project ships |
@@ -64,8 +67,10 @@ top-level entries like `statusline.sh`) to resolve, and runs
`docker compose run`. `bin/dejima-allow`
adds a domain to a running session's firewall from the host - see
[Adding a domain to a running session](security.md#adding-a-domain-to-a-running-session).
`install.sh` installs the hooks into
`~/.claude/hooks` and registers them in `~/.claude/settings.json`.
`install.sh` writes nothing to `~/.claude`. Every hook dejima uses is baked
into the image at `/usr/local/lib/dejima/hooks` and registered per launch into
the `--settings` overlay, which Claude Code merges with your
`~/.claude/settings.json` rather than replacing it.
## Tests
@@ -201,10 +206,12 @@ it has to argue about.
### What a harness must be able to do
Support is per harness and deliberate. A supported harness gets the same
depth of integration Claude Code has - the same mounts, the same guards, the
same audit surfaces - so a harness is not a manifest someone drops in. That
is only possible if the harness can host what those protections need.
Support is per harness and deliberate. A supported harness gets everything
dejima has to give: its state scoped per project, its config carried in
read-only, its audit surfaces watched, and its guards installed wherever it
can host one. So a harness is not a manifest someone drops in - and where it
cannot host a protection, the launch says so rather than leaving the gap
unnamed.
These are the requirements. A harness that fails one of the first four cannot
be supported, and that is a decision about the harness rather than a gap in
@@ -315,7 +322,7 @@ or better is the requirement.
| **R3** | **Yes, by running it, and the documentation is wrong about how.** A rules file at `~/Documents/Cline/Rules/00-dejima.md` reached the model: asked for a codeword only that file contained, the session answered with it. `~/.agents/AGENTS.md` works too. `~/Cline/Rules`, which the documentation names, is **not** read on Linux, and `CLINE_RULES` pointing at a file did nothing. So the briefing is a file rather than a hook, which is what `briefing_path` in the manifest is for. |
| **Network reach** | **In the container, unlike Claude Code's.** Not a requirement, but the thing [security.md](security.md#the-firewall-bounds-the-container-not-the-harness) says has to be established per harness rather than assumed. Asked to fetch a page the allowlist does not carry, Cline's web-fetch tool ran and returned "Unable to connect" - the same answer `curl` gives. So the egress allowlist bounds what reaches a Cline session, which is not true of Claude Code's `WebSearch`. |
| **R4** | **Yes, by running it, and this is where Cline is strongest.** `--data-dir` relocates the whole store - `db/`, `settings/`, `logs/`, `cache/`. A full run against a chosen directory put everything there and left nothing in the default location. There are per-path environment variables too: `CLINE_DATA_DIR`, `CLINE_DB_DATA_DIR`, `CLINE_SESSION_DATA_DIR`, `CLINE_TEAM_DATA_DIR`, `CLINE_PROVIDER_SETTINGS_PATH`, `CLINE_HOOKS_LOG_PATH`. Per-project scoping is a flag rather than an inference. |
| **R5** | **Yes, and confirmed end to end.** Credentials are a plain file, `settings/providers.json`, whose path `CLINE_PROVIDER_SETTINGS_PATH` relocates - so dejima can decline to mount the operator's. The substitute is the one that already exists: Cline configured for `anthropic` with the placeholder key `sandbox-credential-proxy-placeholder`, pointed at the real hostname, ran a real completion through dejima's in-container terminator and host-side proxy. No base-URL override and no new proxy work - the same arrangement as Claude Code's faked `.credentials.json`, and the session is indistinguishable from a stock install. |
| **R5** | **Yes, and confirmed end to end.** Credentials are a plain file, `settings/providers.json`, whose path `CLINE_PROVIDER_SETTINGS_PATH` relocates - so dejima can decline to mount the operator's. The substitute is the one that already exists: Cline configured for `anthropic` with the placeholder key `sandbox-credential-proxy-placeholder`, pointed at the real hostname, ran a real completion through dejima's in-container terminator and host-side proxy. No base-URL override and no new proxy work - the same arrangement as Claude Code's faked `.credentials.json`, and the session is indistinguishable from a stock install. **What that completion did not establish is which models the subscription credential will serve a client that is not Claude Code**: Anthropic gates that per model and answers a refused one with a 429, so the arrangement is confirmed and the entitlement is not dejima's to give. See [providers.md](providers.md#a-subscription-credential-is-claude-codes-and-anthropic-enforces-that). |
Two notes for whoever writes the integration. Cline's plugin manifest schema
still carries a field described as "not read by Claude Code", so its plugin
@@ -354,20 +361,26 @@ that command lives in the harness's briefing fragment rather than in
`resume_command`: briefing substitution is one pass, so a placeholder inside
a substituted value is never resolved.
*Provider-agnostic is not the same as endpoint-agnostic.* Cline can be pointed
anywhere; dejima cannot follow it everywhere. With `base_url` unset it runs
against Anthropic through dejima's own credential proxy and the key never
enters the container. Pointed at someone else's hosted API there is no proxy
that could hold a key back, so the key would have to go in - which is R5
failing, not a network restriction. The plugin therefore accepts `base_url`
only for a model the operator serves themselves - a loopback or RFC 1918
address, or a host they have allowlisted - where an open-weight model needs no
credential at all and R5 has nothing to protect. The allowlist is what
qualifies a name, because it is the same store deciding what the container can
reach: an endpoint failing the check is one the session could not have
connected to anyway, and a model server on someone's own network normally has
a name rather than a literal address. A provider-generic proxy would widen
this to hosted providers; nobody has written one (#171).
*Backend-agnostic is not the same as endpoint-agnostic.* Cline can be pointed
anywhere; dejima cannot follow it everywhere. A backend the proxy serves is
fine whatever its dialect - the proxy takes the credential's kind and header
names as arguments, so `openrouter` works the way `anthropic` does and the key
never enters the container either way. Whether the ENDPOINT then serves the
request is a separate question dejima does not answer: a Claude subscription
credential is served to Claude Code and refused to other clients for the
larger models, which is Anthropic's call and not one dejima works around
(see [providers.md](providers.md#a-subscription-credential-is-claude-codes-and-anthropic-enforces-that)). What dejima cannot follow is a hosted
API reached *without* a backend: there is no proxy holding a key back on its
behalf, so the key would have to go in, which is R5 failing rather than a
network restriction.
So the `credential = none` path is only accepted for a model the operator
serves themselves - a loopback or RFC 1918 address, or a host they have
allowlisted - where the endpoint needs no credential at all and R5 has nothing
to protect. The allowlist is what qualifies a name, because it is the same
store deciding what the container can reach: an endpoint failing the check is
one the session could not have connected to anyway, and a model server on
someone's own network normally has a name rather than a literal address.
*Conversation logging works; epitaphs do not, and only one of those is
Cline's fault.* Cline's transcripts are
@@ -499,9 +512,9 @@ harness-specific path resolving to nothing is the honest answer.
| Seeded files | that a harness reading a credential from a fixed path needs something at it, since an absent file and an empty one are not reliably the same to it. The manifest's `image_files`, created empty and 0600 in that harness's layer, where a mounted credential shadows it - rather than by `entrypoint.sh`, which runs in every image including the base one alone | `harnesses/<name>/harness.conf` |
| Image environment | anything the harness wants set for every session of its own - for Claude Code, `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`. The manifest's `image_env`, in the same layer | `harnesses/<name>/harness.conf` |
| Command | there is no default anywhere shared. `SANDBOX_CMD` comes from the manifest's `command` via `bin/dejima`, and `entrypoint.sh` refuses an empty one rather than naming a harness a given image may not contain | `harnesses/<name>/harness.conf`, `docker/entrypoint.sh` |
| Proxied endpoint | which name the in-container TLS terminator answers for, and what `/etc/hosts` pins to loopback. The manifest's `proxied_api_domain`; a credential proxy with no domain declared is refused rather than started answering for nothing | `harnesses/<name>/harness.conf`, `docker/entrypoint.sh` |
| Egress allowlist | `platform.claude.com` always, `api.anthropic.com` only when no credential proxy is in front of it. `api_domains` and `proxied_api_domain` in the manifest | `harnesses/<name>/harness.conf` |
| Credentials | the whole proxy exists because Claude Code authenticates from `~/.claude/.credentials.json` rather than an env var; the entrypoint seeds a well-formed fake so it has something to read | `bin/dejima-credential-proxy`, `docker/credential-proxy-forwarder.js`, `docker/entrypoint.sh` |
| Proxied endpoint | which name the in-container TLS terminator answers for, and what `/etc/hosts` pins to loopback. The BACKEND's `proxied_domain`, not the harness's: a harness reaches whichever endpoint it is configured for, so the name belongs to the endpoint. A proxied backend with no domain declared is refused rather than started answering for nothing | `backends/<name>/backend.conf`, `docker/entrypoint.sh` |
| Egress allowlist | `platform.claude.com` always, `api.anthropic.com` only when no credential proxy is in front of it. `api_domains` on the harness, `proxied_domain` on the backend | `harnesses/<name>/harness.conf`, `backends/<name>/backend.conf` |
| Credentials | which substitute the harness accepts, and where it reads it from: a well-formed fake `~/.claude/.credentials.json` the entrypoint seeds for Claude Code, a placeholder key in `settings/providers.json` for Cline, a placeholder in an environment variable on the API-key path. The proxy itself is neither harness's - what the credential is, which header carries it and whether it refreshes are the backend's, passed as arguments | `bin/dejima-credential-proxy`, `docker/credential-proxy-forwarder.js`, `docker/entrypoint.sh` |
| Hook protocol | the event payload arrives on stdin; `SessionStart` returns `hookSpecificOutput.hookEventName`/`additionalContext` as JSON, while a `PreToolUse` hook blocks by exiting 2 with its reason on stderr | `hooks/*.sh` |
| Hook registration | four hooks written into `~/.claude/settings.json` in Claude Code's schema, one `SessionStart` with a `startup\|resume\|clear\|compact` matcher and three `PreToolUse` matching `Bash`. In the plugin, gated per declared guard | `bin/harness/claude-code.sh` |
| Briefing delivery | **by which of three routes**, not whether. Claude Code takes the briefing as a system prompt, through the flag its manifest names in `briefing_args`, because a `SessionStart` payload past roughly nine kilobytes is persisted and replaced with a preview - so the hook route silently under-delivered a briefing carrying a project's `.dejima.md`. Cline takes no such flag and registers no hook, so it declares a `briefing_path` and reads a file `entrypoint.sh` writes root-owned and read-only. A harness doing neither still gets it through the hook. What the briefing *says* is none of theirs: composing it host-side is core's, and the container-side part - this container's id, the declared-versus-installed gap, the project's `.dejima.md` - is one script every route calls | `hooks/dejima-briefing-render.sh`, `hooks/sandbox-context.sh`, `docker/entrypoint.sh` |
@@ -551,13 +564,20 @@ because absent is visible to the operator and broken is not.
`claude-code` is no exception to that: it is declared by its own manifest and
built into its own layer like any other. The base image carries nothing of any
harness's - not its package, not the directories it keeps state in, not its
environment, and not its name as a default command. What is left on the
harness axis is the credential proxy, which is Claude Code's shape throughout
and is the R5 row above.
environment, and not its name as a default command.
Nor is the credential proxy harness-shaped. Which header carries the
credential, what shape it takes, what must not travel beside it and whether it
can be refreshed are all arguments the selected backend supplies, so a second
harness reaches a proxied backend without a branch of its own - the R5 row
above. Cline has run real completions through the same terminator
and the same host-side proxy, against `anthropic` and against `openrouter`,
which is a different api_style through the same code.
`providers.bats` covers the manifest contract itself and is where a new
`harness.conf` gets its parsing and validation tests. The suites that assert
on Claude Code paths by name - `config.bats`, `audit.bats`, `static.bats`,
`runtime.bats` - are the ones that will need a second set, and a green run
against the existing harness proves nothing about a new one. Nothing in
`test/` currently runs a second harness end to end.
`harness.conf` gets its parsing and validation tests. `config.bats`,
`static.bats`, `project.bats` and `conversation.bats` each carry a second
harness's cases beside Claude Code's, which is the shape a third one should
follow. What is still missing is the end of the ladder: `runtime.bats` boots
only `claude-code`, so nothing in `test/` runs a second harness end to end in
a real container, and a green confined run says nothing about that.
+93 -4
View File
@@ -232,11 +232,10 @@ A workflow's `briefing.md` is plain Markdown plus two marker forms that
| `command` | `identifier` | `claude` | The container's main process for this harness, and the name the wrapper shadows on `PATH`. `[core] command` defaults to it. |
| `command_path` | `?path` | (empty) | Where the real binary lives, behind the shadow. |
| `api_domains` | `?list:hostname` | (empty) | Hostnames this harness's own machinery must reach - its update host, its telemetry endpoint. They join the *fixed* allowlist rather than the extra one, which `dns-proxy.sh` exempts from stop-dns-rebind and `init-firewall.sh` treats as non-fatal when it fails to resolve. |
| `proxied_api_domain` | `?hostname` | (empty) | The model API endpoint the credential proxy stands in front of. Allowlisted **only when the proxy is off**: with it on, the session reaches the API through the forwarder, so leaving the name unresolvable defeats a bypass that looks it up by DNS. Which name it is comes from here; when to allowlist it is dejima's rule. |
| `api_styles` | `?list:identifier` | (empty) | Which backend `api_style`s this harness has a client for. `claude-code` speaks `anthropic`; `cline` speaks both, which is what makes it the backend-agnostic one. Empty means unchecked. |
| `guards` | `?list:identifier` | (empty) | Which of dejima's guard rails this harness can host: `bash-deny`, `push-guard`, `merge-guard`, `notify`. A name outside that set is refused rather than treated as an unknown guard, since a typo would otherwise turn a guard off silently. The ones a harness does not declare are named at launch - see "What a harness must be able to do" in [development.md](development.md). |
| `briefing_args` | `?args` | (empty) | The flag that carries the briefing to a harness taking it on the command line - for Claude Code, `--append-system-prompt`. `dejima-harness-wrapper` reads the rendered briefing and passes it as a single value, so every invocation carries it and not only the entrypoint's. Set, the session-start hook stops carrying the briefing and reduces to the session id, which is the one thing that does not exist until the harness starts. |
| `briefing_path` | `?homepath` | (empty) | Where this harness reads its briefing from, relative to `$HOME`, for a harness that has no session-start hook to be handed it through. Set, `entrypoint.sh` renders the briefing into that path root-owned and read-only before the session starts, and refuses to start it at all if that fails. Empty for a harness that registers a hook instead, which is how Claude Code gets it. |
| `briefing_path` | `?homepath` | (empty) | Where this harness reads its briefing from, relative to `$HOME`, for a harness that has no session-start hook to be handed it through. Set, `entrypoint.sh` renders the briefing into that path root-owned and read-only before the session starts, and refuses to start it at all if that fails. Empty for a harness that takes the briefing on the command line (`briefing_args`, which is how Claude Code gets it) or that can be handed it through a session-start hook. |
| `no_confirm_args` | `?template` | (empty) | The flags that make the harness run without confirming each tool call. Required in practice: dejima refuses to launch a harness that names none, because unattended operation is the premise the container is built on (R1 in [development.md](development.md)). |
| `settings_args` | `?template` | (empty) | How this harness is told to read dejima's own settings layer, mounted at `/etc/dejima-settings.json`. Empty for a harness that takes its overrides some other way. |
| `keys` | `?list:keyspec` | (empty) | This harness's own `[harness.<name>]` config schema - same grammar as a forge's `keys`. |
@@ -299,6 +298,13 @@ Compatibility is not a list anyone maintains: it is the backend's `api_style`
against the harness's `api_styles`, checked at launch. This table is what those
declarations currently work out to.
It answers whether dejima will pair the two, which is a question about
dialects. Whether the endpoint then serves the request is the endpoint's to
answer, and for a Claude subscription credential the answer depends on the
harness - see [A subscription credential is Claude
Code's](#a-subscription-credential-is-claude-codes-and-anthropic-enforces-that)
below.
| Backend | `claude-code` | `cline` | Credential | You configure |
| --- | --- | --- | --- | --- |
| `anthropic` | yes | yes | OAuth, refreshed and written back | nothing, once you have logged in on the host |
@@ -316,6 +322,54 @@ Adding a backend does not change this table by hand: a new directory whose
`api_style` is one a harness already declares works with that harness the day
it lands.
### A subscription credential is Claude Code's, and Anthropic enforces that
`backends/anthropic` reads the OAuth credential Claude Code writes when you
sign in with a Claude subscription. **Anthropic serves that credential to
Claude Code and refuses other clients, per model.** Observed on a Max
subscription: `claude-haiku-4-5` is served, `claude-opus-5` and
`claude-sonnet-5` are refused, while an otherwise identical request from
Claude Code succeeds.
The refusal arrives as **HTTP 429 `rate_limit_error`**, with a body whose
message is the word `Error`. It is indistinguishable from a quota problem
from the inside, which is worth knowing before you spend an afternoon on
your usage graphs: the account can be nowhere near any limit and every
request will still be refused.
So with `[core] harness = cline` and `backend = anthropic`, expect Haiku to
work and the larger models not to. For those, point cline at a backend whose
credential is yours to spend rather than a subscription's:
```
[harness.cline]
backend = anthropic-api-key # console billing, key held on the host
# or
backend = openrouter
```
`claude-code` with `backend = anthropic` is unaffected - that pairing is the
one Anthropic is serving.
**dejima does not work around this**, and that is a limit on what dejima does
rather than an opinion about the attempt.
The credential proxy substitutes the credential and changes nothing else: the
header block the API receives is the harness's own, down to not adding an
`Accept-Encoding` the client did not send. Getting past this gate would mean
sending a system prompt the harness never wrote, so that the request presents
as a different product - which is the one thing the proxy is built not to do,
and would put a second answer to "which client is this" inside the component
whose whole job is to pass the first one through unchanged.
It would also be brittle in a way that costs the operator rather than dejima:
it works until the shape it copies changes, and the failure lands on their
account.
Which models are gated is Anthropic's to change, and the table above is an
observation on one subscription rather than a documented policy - if it moves,
this section moves with it.
**Which backend a launch uses is the harness's setting**, `[harness.<name>]
backend`, overridable for one launch with `--backend`. Per harness because
that is how it is used: one harness against Anthropic and another against
@@ -391,8 +445,8 @@ known until the container is actually running.
### How the briefing reaches the session
**A session-start hook is a size-limited channel, which is why it is no longer
the only route.** Claude Code persists a large `SessionStart` payload to a file
**A session-start hook is a size-limited channel, which is why it is not the
only route.** Claude Code persists a large `SessionStart` payload to a file
and injects a short preview in its place: measured in a dejima container, 9KB
arrived whole and 21KB did not. A composed briefing plus a project's own
`.dejima.md` runs well past that, so most of the briefing silently never
@@ -554,6 +608,41 @@ can be pointed at any endpoint, including a model you serve yourself - and
expect to be the person who finds the next crack.
### Model backend maturity
The same caveat the harnesses and forges get, and for the same reason: four
backends in one table invites the reading that each got the same amount of
use, and they did not.
**`anthropic` is the one dejima was built around.** The credential proxy, the
in-container terminator, the refresh-and-write-back - all of it was designed
against a subscription login and generalised afterwards. It has been used for
real work continuously, which is the coverage no test substitutes for.
**`anthropic-api-key` works and has not been leaned on.** It was verified end
to end on a real machine: the model answers, billing shows as API usage, the
key stays on the host and the container holds only a placeholder. That is one
confirmed launch rather than months of use, and the difference matters for the
same reason it does above.
**`openrouter` is at the same level.** Built from the same manifest shape,
exercised against a fake upstream and through a full launch, and confirmed
against the real endpoint. What has not happened yet is a long tail of
sessions through it, so expect the rough edges that only volume finds.
**`self-hosted` runs no proxy at all**, which makes it the simplest of the
four and the one with least to go wrong in dejima: there is no credential to
withhold, so the session reaches the endpoint directly and dejima's only job
is refusing an address that is not host-local. It has been run against a local
model. What it does not get is any of the credential machinery's protection,
because there is nothing to protect.
If you are choosing with no other reason to prefer one, and you have a
subscription, `anthropic` is the path with the most miles on it. The other
three are supported in the same sense the second harness is: built
deliberately, tested, and newer than the thing they sit beside.
### Forge integration maturity
The same caveat the harnesses get, for the same reason: two forges listed in
+7 -4
View File
@@ -46,11 +46,14 @@ at all.
`test/runtime.bats` needs Docker, which a sandbox does not have. It is the only
thing that exercises the mounts, the firewall and the entrypoint end to end, so
a release is exactly when not running it stops being acceptable. Either run it
on the host, or **check that the privileged CI job ran** - it is pinned to one
self-hosted runner and queues silently when that runner is down, so a pull
request can sit with the runtime half neither green nor red.
on the host, or **read the pull request's checks**: green means every job
finished and passed, `runtime.bats` among them. Yellow or grey means the
privileged job has not run - it is pinned to one self-hosted runner and queues
silently when that runner is down.
"CI covers it" is not "it passed."
So the answer is the colour. Green is verified end to end; say so. Anything
else is a run that has not happened, and reporting it as passing is what this
paragraph exists to prevent.
## 2. Security review
+59 -13
View File
@@ -52,12 +52,11 @@ running.
## The bind address is the one thing to get right
`docker/init-firewall.sh` deliberately ACCEPTs container OUTPUT to the
container's default-route address - the Docker bridge gateway, which is your
host. That is the one host address a sandbox can reach at all. Combine it
with the fact above (a tmux client is a host shell) and the consequence is
direct: **a front door the sandbox can reach is a compromised session's own
escape hatch.**
`docker/init-firewall.sh` deliberately ACCEPTs OUTPUT to the session's
default-route address - the Docker bridge gateway, which is your host. That is
the one host address a sandbox can reach at all. Combine it with the fact above
(a tmux client is a host shell) and the consequence is direct: **a front door
the sandbox can reach is a compromised session's own escape hatch.**
So:
@@ -542,6 +541,46 @@ nvim split separator resizes the split. Neither needs any server-side
configuration - they are stock tmux and nvim behaviour; the page's only
contribution is delivering the drag.
### A scroll gesture jumps too far, and the amount is tmux's
A scroll gesture is sent as wheel notches, one per row of finger travel. What a
notch is then worth belongs to whoever receives it, and this page is not it:
when the pane is scrolling its own history, tmux is.
**Find out what yours does before changing anything:**
```sh
tmux list-keys -T copy-mode-vi | grep WheelUpPane
```
Stock tmux scrolls five lines (`send-keys -X -N 5 scroll-up`), which is a fifth
of a desktop terminal and better than half a phone one. A configuration that
binds `halfpage-up` instead - a common enough idiom that it is worth naming -
scrolls half the pane, so twenty lines in a forty-line one. That is the case
this section exists for: on a phone it throws the screen on the smallest
movement of a thumb, and placing a particular line takes several tries.
Set it to a few lines, in your own `~/.tmux.conf`:
```tmux
bind -T copy-mode-vi WheelUpPane select-pane \; send -X -N 4 scroll-up
bind -T copy-mode-vi WheelDownPane select-pane \; send -X -N 4 scroll-down
bind -T copy-mode WheelUpPane select-pane \; send -X -N 4 scroll-up
bind -T copy-mode WheelDownPane select-pane \; send -X -N 4 scroll-down
```
Both tables, because which one is active follows `mode-keys`. `scroll-up` takes
no amount of its own, so the `-N` repeat count is the amount. It applies to
every client of that tmux server, phone and desktop alike - which is the reason
it is not something dejima sets for you: `dejima-attach` joins the tmux session
you launched from, and its configuration is yours.
Nothing in dejima can make the step smaller from this side. The page can only
choose how many notches to send, and sending fewer means dragging further for
each one - which trades a jumpy scroll for a stiff one rather than fixing
either. An application reading the mouse directly, rather than through tmux,
picks its own figure and there is no binding for that at all.
### Toolbar
```
@@ -798,13 +837,20 @@ what the outer proxy sends.
## Notifications
`dejima` registers `hooks/dejima-notify.sh` as a `Stop` hook for a
remote-enabled session, into the throwaway settings override layer it already
generates - never into your real `~/.claude/settings.json`. Your own hooks
keep running alongside it, since Claude Code merges hooks across layers rather
than replacing. The layer is mounted read-only, so a session cannot
unregister its own hook. The hook writes one empty file named `done` into
this run's marker directory: no content, no stdin, no network.
**Only for a harness that declares the `notify` guard**, because a
notification needs a session-lifecycle signal to hang off and not every
harness has one. Claude Code does; Cline does not, and a remote-enabled Cline
session gets attach and the web terminal but no push. The launch says which
guards a harness is going without, so that is visible rather than a
notification that silently never arrives.
Where it is declared, `dejima` registers `hooks/dejima-notify.sh` as a `Stop`
hook for a remote-enabled session, into the throwaway settings override layer
it already generates - never into your real `~/.claude/settings.json`. Your
own hooks keep running alongside it, since Claude Code merges hooks across
layers rather than replacing. The layer is mounted read-only, so a session
cannot unregister its own hook. The hook writes one empty file named `done`
into this run's marker directory: no content, no stdin, no network.
**One push per stop, and not a second one a minute later.** The hook and the
watcher both understand a `waiting` event as well, and Claude Code's
+5 -1
View File
@@ -57,7 +57,11 @@ doing any work.
hostile?** The field says no for untrusted code, and tiers gVisor and
per-workload VM kernels above it. dejima's answer is that escape moves a
layer - true where the layer exists. See
[Which deployment this describes](threat-model.md#which-deployment-this-describes).
[Which deployment this describes](threat-model.md#which-deployment-this-describes)
and [Why a container, and not a microVM](threat-model.md#why-a-container-and-not-a-microvm),
which is where the reasoning is written down so a sweep can contradict it.
The live half of this question is question 5: whether a current escape
clears this configuration's floor.
2. **Does a name-based egress allowlist hold?** It holds against an agent that
must resolve a name. It does not hold against exfiltration through an
allowed domain or against DNS query-name channels, both of which are listed
+172 -46
View File
@@ -271,7 +271,7 @@ In that configuration the provider directories are in the exit-time audit's
TCB list, alongside `bin/`, `hooks/`, `docker/`, `test/` and `tools/`. They
hold no code and nothing executes them, but what they hold decides what the
next launch permits: a forge's `fixed_hosts` reaches `DEJIMA_FORGE_HOSTS`,
which `entrypoint.sh` joins into the domains `init-firewall.sh` allowlists, so
which `firewall-up.sh` joins into the domains `init-firewall.sh` allowlists, so
a line added to a manifest widens the egress boundary on the next run.
`tools/*/tool.conf` is the same class, and is read by the host rather than the
container: it names a tarball URL, the sha256 checked against it and the
@@ -291,29 +291,31 @@ can make; it is one the audit reports. See
- Running the harness with its permission prompts off removes your chance to
review tool calls before they run. Only point this at trusted repositories.
- The mounted project itself has **no write protection**. `deny-dangerous-
bash.sh`, `git-push-guard.sh` and `merge-guard.sh` are regex
pattern-matching on the literal Bash command string - a fast-fail guard
against an overeager agent doing something obviously destructive, not a
boundary against one that's actively trying to get around them (a
different scripting language, an encoded command, editing `.git/config`
directly all sail right through).
Nothing here stops a compromised or badly-instructed session from
modifying or deleting the real working copy it's mounted against.
- The mounted project itself has **no write protection**. The guards are
fast-fail checks against an overeager agent doing something obviously
destructive, not a boundary against one actively trying to get around them.
`deny-dangerous-bash.sh` is regex pattern-matching on the literal Bash
command string, so a different scripting language, an encoded command or
editing `.git/config` directly all sail right through. The push and merge
guards shadow `git` and the forge CLI on `PATH` and read argv, so quoting
and pipelines stop mattering - but a session that means to get round one can
call `/usr/bin/git` directly. Nothing here stops a compromised or
badly-instructed session from modifying or deleting the real working copy
it's mounted against.
- That same read-write access to the mounted project is also a
host-code-execution vector, not just a data-destruction one: a
compromised session could plant `.git/hooks/post-commit` (or
`pre-push`), set `core.hooksPath`, or write a
`.claude/settings.local.json` with a malicious hook command, into the
project. Any of those run unsandboxed on the host the next time you run
`git` or open Claude Code in that repo - no network egress required, so
`git` or open your harness in that repo - no network egress required, so
the firewall doesn't see it either. Same underlying persistence pattern
as the `~/.claude/hooks` and `~/.claude.json` risks above, just through
as the harness config risks above, just through
the project mount instead of the config mount. "Only point this at
trusted repositories" (above) covers input trust; this is about the
sandbox writing a persistence payload into an otherwise-trusted repo.
The workspace's own `.git/hooks` directory is mounted read-only
(same pattern as the `~/.claude` code directories below), so planting a hook
(same pattern as the harness's own code directories below), so planting a hook
file directly is closed - accepted breakage: installing hooks
*in-session* (`husky`, `pre-commit install`) fails, which is the
point. `core.hooksPath` and `.claude/settings.local.json` aren't
@@ -498,6 +500,16 @@ approximation of its name.
## One project's session cannot reach another's
The property is the same for every harness; the mechanism is not, because it
depends on how the harness keys its own state. Claude Code stores a directory
per project and dejima mounts a slice of it. Cline stores one flat database
indexing every session it has ever run, with the project as a field inside the
record, so there is no slice to take - dejima gives each workspace a data
directory of its own instead. Both reach the same place: a session sees its
own project's history and no other's.
### Claude Code: a slice of your own tree
- `~/.claude/projects` (session transcripts and per-project memory) is
**not** mounted as a tree. A session gets the workspace's own slug
directory plus one for each live git worktree nested under it,
@@ -551,6 +563,31 @@ approximation of its name.
That costs undo history for that session if it is later resumed on the
host, and it is the reason this cannot be scoped as completely as
`projects/`, where the workspace's own slug is known at launch.
### Cline: a directory dejima owns, one per workspace
- `~/.cline/data` is **not** mounted. Cline indexes every session it has ever
run in one `sessions.db`, with the project a session belonged to as a field
inside the record rather than a directory above it, so there is no
per-project subtree to slice: mounting your data directory would put every
project's transcripts in every session, which is this section's whole
subject.
A launch instead creates `<[harness.cline] state_dir>/<workspace slug>` on
the host and mounts *that* at `~/.cline/data`. Every session under it belongs
to this project by construction rather than by a filter that could be wrong,
which is why Cline clears this requirement more cleanly than Claude Code
rather than less.
The cost is that the directory is dejima's rather than yours: a session
started inside the sandbox is not offered back to a host-side Cline, and one
you started on the host is not visible inside. There is no import or export
([#301](https://gitbox.branderson.io/dejima/dejima/issues/301)), and the
briefing tells the session so, so it will not offer you a resume command that
cannot work.
### Whichever harness is selected
- Epitaphs - the summary a session leaves when its context is compacted away -
are kept host-side in `[epitaph] dir`, and that directory is never mounted. A session can neither read what earlier
sessions concluded nor edit what this one is about to record, which is the
@@ -589,7 +626,7 @@ it.
| **Proxied, refreshing** (`credential = anthropic-oauth`) | A fake credential file whose secrets are placeholders. The real one is read host-side per request. | The placeholder. | Use the API as you, through the proxy, while the session runs. |
| **Proxied, static key** (`credential = static`) | A placeholder key in the harness's own model configuration, and the endpoint's real hostname. | The placeholder. | The same. |
| **A backend with no credential** (`credential = none`, a model you serve) | Nothing but the endpoint's address. It needs no credential, so there is none to withhold. | Nothing. | Reach that endpoint, which is why it has to be one you allowlisted. |
| **No proxy** (`[credentials] proxy = off`, or a Claude Code login the selected backend cannot serve) | The real credential file, mounted. | **The credential itself**, durable and usable offline. | Everything the credential allows, for as long as it is valid. |
| **No proxy** (`[credentials] proxy = off`, or `[backend.<name>] proxy = off`) | The real credential file, mounted. | **The credential itself**, durable and usable offline. | Everything the credential allows, for as long as it is valid. |
**The first three keep the credential out; the fourth does not.** That is the
whole of the difference, and it is why `proxy = off` is described here as a
@@ -604,8 +641,16 @@ the host and injected per request. On the API-key path the container gets
`ANTHROPIC_API_KEY=sandbox-credential-proxy-placeholder` and no credential file
at all.
What lands in the fourth row is `proxy = off`, and a login whose shape no
selected backend serves.
**Only `proxy = off` lands in the fourth row, and only where you wrote it.**
A credential the selected backend cannot serve - a Claude Code signed in with
a console API token, whose file holds no `claudeAiOauth` block, against
`backends/anthropic` - is a refusal, naming the backend, the file, the shape
it expected and the two ways forward. A kill switch that can engage itself is
not one, which is why this row is a kill switch rather than an option.
The refusal is scoped to a credential that *exists* and cannot be served. An
absent one mounts nothing and downgrades nothing - that is a host where the
harness has not been signed in yet, and it still launches.
**The proxy is switched per backend, not globally.** `[backend.<name>] proxy`
falls back to `[credentials] proxy` when unset. One backend whose credential
@@ -739,6 +784,14 @@ prerequisite. Sign in on the host first; see the README's
Refreshing an expired credential is the same: on the host, not from inside a
session, where the credential deliberately never goes.
### The refreshing OAuth path, in detail
The `backends/anthropic` arrangement, at the level of what the proxy actually
does. The machinery is not Anthropic's - the credential's kind, which header
carries it, what must not travel beside it are all arguments a backend
supplies - but it is worth reading through one backend rather than in the
abstract, and this is the one with the most miles on it.
- The Anthropic OAuth credential (`~/.claude/.credentials.json`) never
enters the container. It isn't mounted: `~/.claude` is not shared as a
whole (see the mount inventory below), so there is no path from
@@ -795,7 +848,7 @@ session, where the credential deliberately never goes.
after an upgrade, as `UNABLE_TO_VERIFY_LEAF_SIGNATURE`,
`ERR_TLS_CERT_ALTNAME_INVALID`, or a pin-specific error. What
distinguishes pinning from a merely broken certificate is that
`curl --cacert /etc/dejima-anthropic-tls/cert.pem https://api.anthropic.com/v1/messages`
`curl --cacert /etc/dejima-credential-tls/cert.pem https://api.anthropic.com/v1/messages`
still succeeds from inside the container while Claude Code does not: the
certificate is fine, the client is refusing it. **This is not a reason to
set `[credentials] proxy = off`.** That kill switch mounts the real,
@@ -824,7 +877,13 @@ session, where the credential deliberately never goes.
real credential into the container. Rung one is a supported, tested mode,
not an improvised workaround; if you reach the third, treat it as a
temporary state rather than a new baseline.
## What the container sees of `~/.claude`
## What the container sees of Claude Code's `~/.claude`
One harness's inventory, because there is no shared one to give: what a
harness keeps where, and which of it is safe to mount, is the harness's own
answer and each plugin gives it. Cline's is the table in
[configuration.md](configuration.md#what-comes-in-from-your-host); the
reasoning below is what both are built on.
- `~/.claude` is **not** shared with the container as a whole. Its contents
are enumerated in `docker-compose.yml`, in three classes, and anything not
@@ -847,10 +906,10 @@ session, where the credential deliberately never goes.
approval step, skills can ship executable scripts, and
commands/agents/output-styles are prompt text loaded into a later host
session, so without this a compromised session could plant a backdoored
hook - including by unlinking one of `install.sh`'s hook symlinks and
dropping a plain file in its place, since the dynamic per-target mounts
only protect symlink targets that resolve *outside* `~/.claude`, never
this directory itself - tamper with plugin code, or drop a malicious
hook - including by unlinking one of your own hook symlinks and dropping a
plain file in its place, since the dynamic per-target mounts only protect
symlink targets that resolve *outside* `~/.claude`, never this directory
itself - tamper with plugin code, or drop a malicious
skill/command/agent/output-style file. Any of those would then run or
load **unsandboxed on the host** the next time Claude Code starts
there, turning a single compromised sandbox session into persistent
@@ -958,15 +1017,52 @@ session, where the credential deliberately never goes.
SSH-agent/token story documented above. Keep credentials out of your
global gitconfig, or expect them to be reachable from inside the
sandbox.
- **The egress filter is not in the container the session runs in.** A launch
starts two: a filter container that owns the network namespace and installs
the packet filter, and the sandbox, which joins that namespace with
`network_mode: container:` rather than getting one of its own. Capabilities
are per process rather than per namespace, so the sandbox cannot alter the
filter bounding it even at uid 0 - measured, not reasoned: `iptables` and
`ipset` both return `Operation not permitted` to a joiner that lacks
`NET_ADMIN`.
Two things follow. The namespace has its rules before anything is created in
it, so there is no window in which a session holds an interface and no
filter; `bin/dejima` waits for the filter container to say it is up and
refuses the launch otherwise. And killing the filter container leaves the
sandbox holding loopback alone - no network at all, rather than an unfiltered
one.
Nothing a session runs ever executes in the filter container. It holds the
privilege; the one beside it holds the session. Each launch gets a network of
its own, so concurrent sessions are separated at the link layer as well.
A launch removes both on the way out, and reconciles at the start against
whatever a `SIGKILL` or a restarted host left behind - a filter container
with no session in its namespace, older than the window in which a pair is
still being built. What that reclaims is address space rather than safety: a
leaked filter container filters a namespace nothing is in, and Docker's
address pool is finite enough that exhausting it fails a later launch with an
error naming neither cause nor remedy.
- The sandbox's own user (matching your host user; see "Config parity" in
the README) has no `sudo`/setuid path back to root once the container is up:
`entrypoint.sh` runs as root, sets up the firewall directly, then drops to
that user via `gosu` before execing the configured command (`[core] command`,
or the selected harness's own if that is unset). A compromised session can't
`entrypoint.sh` runs as root, prepares the session's own state, then drops to
that user before execing the configured command (`[core] command`, or the
selected harness's own if that is unset). A compromised session can't
re-run `init-firewall.sh` with a wider allowlist to open its own
exfiltration path. Verified: capabilities (`NET_ADMIN`/`NET_RAW`) are
cleared from the effective/permitted sets on the `gosu` drop, and that
user gets a permission error running `iptables` directly.
exfiltration path: that script runs in the container beside it, so there is
no copy of the allowlist within reach to re-run against. Verified: that user
gets a permission error running `iptables` directly.
- **The session's capability bounding set is empty**, not merely its effective
one. The distinction is the whole of it: an empty effective set is what
changing uid gives you anyway, while the bounding set is what a process that
reached uid 0 in that tree would recover its capabilities from. So the two
claims above - no path back to root, and no capability if there were one -
hold separately rather than one resting on the other. The drop and the uid
change happen in one `capsh` process because they have to: the bounding set
can only be reduced while `CAP_SETPCAP` is still held, and changing uid first
gives it away. The same applies to `log-shipper.sh`, the one root process
that outlives the entrypoint.
- A forge credential reaches the container as `-e NAME`, never
`-e NAME=value`. The value comes from the launcher's own environment, so it
sits in `/proc/<pid>/environ` (mode 0400, owner only) rather than in
@@ -974,17 +1070,45 @@ session, where the credential deliberately never goes.
anyone. `docker inspect` still shows the resolved value to whoever can
reach the daemon - that is daemon access rather than any process at all,
and it is not something the launcher can change.
- The container runs with `no-new-privileges` and an explicit capability
floor - `cap_drop: ALL` plus the ones it actually uses: what the
entrypoint's root phase needs, and `KILL`. `KILL` is there for
`dejima-allow --container`, not for the entrypoint - adding a domain to a
running session signals dnsmasq, and dnsmasq runs as its own user. The list
itself is in `docker/docker-compose.yml`, which is where it stays correct. The first means a setuid binary or a file capability cannot raise
- **Each container runs with `no-new-privileges` and a capability floor of its
own**, `cap_drop: ALL` plus what that container actually uses. The two lists
are the arrangement stated as configuration:
The session container declares **no network capability at all** - not
`NET_ADMIN`, not `NET_RAW`. It is inside a namespace the filter container
owns and has already installed the rules in, and capabilities are per
process, so uid 0 in there is refused by the kernel rather than by policy.
What it keeps is what its root phase does before the session starts: write
and chown files, and drop privilege once. `SETPCAP` is there to spend rather
than to use - it is what lets the entrypoint take the rest of the list away
again before execing the session, and since Linux 4.3 it grants nothing a
process does not already hold.
The filter container holds the network capabilities. The session's list is in
`docker/docker-compose.yml` and the filter's is in `bin/dejima`, each beside
the container it describes.
`KILL` is on both lists, for unrelated reasons, and it is the one worth
reading twice. The filter container needs it because adding a domain to a
running session signals dnsmasq, which runs as its own user. The session
container needs it because `init: true` makes PID 1 an init that forwards
signals to the session - and the entrypoint changes uid in place before
exec'ing it, so that is uid 0 signalling a process whose real and saved uids
are the sandbox user's. Without the capability every forwarded signal is
`EPERM`, tini treats a failed forward as fatal, and an ordinary terminal
resize ends the session.
`no-new-privileges` means a setuid binary or a file capability cannot raise
privileges on exec, which is the shape any escalation from the session user
would have to take; the second means the capabilities nothing here uses were
never in the bounding set to be regained. Both are asserted against a running
container rather than against the compose file, and the capability list the
test uses is read out of that file so the two cannot drift.
would have to take. The floor means the capabilities nothing uses were never
in the bounding set to be regained. Both are asserted against running
containers rather than against the files, and both lists the tests use are
read out of those files so neither can drift.
What a floor describes is a container's **root phase**. A launch runs with
`init: true`, so PID 1 is the init that reaps for the session and it holds
that container's floor for as long as the container lives; the session is its
child and holds nothing.
- The approval store (`${DEJIMA_CONFIG_DIR:-$HOME/.config/dejima}`,
see
[Global and per-project domains and dependencies](../README.md#global-and-per-project-domains-and-dependencies)
@@ -1095,11 +1219,13 @@ default:
- DNS resolution via a local proxy (see "DNS is allowlisted too")
- the Docker host itself (not its whole subnet)
- GitHub's published IP ranges, port 443 only (see "GitHub push" below)
- `registry.npmjs.org` and `platform.claude.com` (the harness and its
updates), `release-assets.githubusercontent.com` (GitHub release assets, a
separate CDN from github.com's own IPs, and where a good deal of tooling
fetches its binaries); `api.anthropic.com` when the credential proxy is off
(kill switch or API-key auth)
- `registry.npmjs.org`, plus whatever the selected harness declares as its own
(`platform.claude.com` for Claude Code; Cline declares none, so a session
falling back to Cline's hosted endpoints fails to connect, which is the
right outcome); `release-assets.githubusercontent.com` (GitHub release
assets, a separate CDN from github.com's own IPs, and where a good deal of
tooling fetches its binaries); and the selected backend's API endpoint when
the credential proxy is off for it
That is the whole built-in list, and it is meant to stay that way: it covers
what the sandbox itself cannot run without, not what a project might want.
@@ -1213,9 +1339,9 @@ Internal hosts named before the container starts (`[forge.gitea] ssh_host`,
`api`, `[logging] loki_url`, and any globally or per-project approved domain)
are already exempted and unaffected by this.
The sandbox-context.sh `SessionStart` hook tells the agent to ask for this
by name when a task is blocked on a single missing domain, rather than
stopping the whole session over it.
The session briefing tells the agent to ask for this by name when a task is
blocked on a single missing domain, rather than stopping the whole session
over it.
### The firewall bounds the container, not the harness
+74
View File
@@ -263,6 +263,80 @@ repository's behalf.
**What this repository can do about that is say so**, which is the whole of
this section. Nothing in dejima can bound its own host.
## Why a container, and not a microVM
The most frequent question about this project.
The short answer is that a microVM is the stronger boundary and nothing here
disputes it. Container escape is the least likely of the six threats above and
the only one that needs an exploit at all, and the layer it lands on is already
bounded by a control enforced from outside the guest. The effort went there
rather than into a harder container.
**There is already a VM here**, which is what the usual framing misses. It is
put as container versus microVM, as though the alternative were a container
with nothing underneath. On the deployment this document describes, dejima runs
inside a devbox VM whose rule set is enforced from the hypervisor. So the choice
is not one boundary against two. It is an outer VM enforced from outside the
guest, against that plus an inner one managed by software running on the box it
is protecting - inside the blast radius of the row it is meant to bound. A
boundary enforced from outside is worth more than one enforced by the thing
inside it, and that is most of the answer.
**The field's ordering is not in dispute.** gVisor's syscall interposition and
a per-workload VM kernel are both stronger than a namespaced container.
Firecracker is what AWS runs Lambda on, for the reason that applies here too:
untrusted code, multi-tenant, on shared hardware. The disagreement is about
where marginal effort goes, not about which primitive is stronger.
### What a stronger runtime would and would not change
It would not touch the five threats ranked above escape. Two of them would get
*harder*, because both are enforced by how the container is configured rather
than by what isolates it:
- **One project's session cannot reach another's**, because each path crossing
the boundary is named individually rather than mounting a tree
([#104](https://gitbox.branderson.io/dejima/dejima/issues/104)). Under a VM
each becomes a filesystem daemon.
- **The container sees an agent socket, never your key.** That is a live host
socket, and a VM has no equivalent to hand it one.
One would get easier: egress rules on a tap device sit where the guest holds no
capability to touch them. That is available without changing the runtime, which
is what [#305](https://gitbox.branderson.io/dejima/dejima/issues/305) does.
**And "swap the runtime" understates the work**, because several controls are
implemented *in* Docker rather than merely hosted by it. The dependency
approval is a derived image build; the tooling reaches live sessions through
it; the capability floor is an argument about Docker's model. Porting them is a
rewrite of the parts that *are* the security argument, in a project that says
at the top that none of it has been reviewed by anyone else.
### What would change the answer
The decision is a judgement about effort, not a door held shut, and these are
the things that would reopen it:
- **Kata Containers is the cheap path if this reasoning is wrong.** It is an
OCI runtime, so the compose file, the mounts and the tooling survive, and it
can use Firecracker underneath. A per-launch switch rather than a fork.
- **Pointing dejima at projects chosen by someone else.** That contradicts an
assumption stated at the top of this document, and reorders the ranked list.
- **A container escape in the wild that clears this configuration's floor**:
non-root session user, `no-new-privileges`, `cap_drop: ALL` and a short list
added back. The class recurs, and whether a live one clears that floor is
asked on a schedule in
[research-review.md](research-review.md#the-standing-questions) rather than
assumed either way.
What is done instead is depth below the container, which is
[the stack](#the-stack-and-what-each-piece-buys): two of the three layers under
dejima are enforced where the guest cannot reach them, and the third bounds a
compromise in time. A sandbox that reaches for a microVM and stops there has
nothing underneath it, so an escape from the VM ends its argument. Here it is a
row with controls of its own.
## What this repository does not claim
- **That the egress allowlist bounds what reaches the model.** It bounds what
+3
View File
@@ -1,3 +1,6 @@
They can continue this exact session outside the container by running on
the host:
{{resume_command}}
(session history is shared via the bind-mounted ~/.claude, so it will pick
+9 -9
View File
@@ -1,10 +1,10 @@
export CLINE_DATA_DIR={{harness_state_dir}}
cline history # find this session's id
cline --id <session-id>
This session cannot be continued outside dejima, so do not offer that or ask
the operator to try it. It CAN be continued by launching dejima again on this
project: this project's Cline state - sessions, transcripts, tasks - is kept
on the host in a directory of its own and survives the container being
replaced, so the next launch picks up where this one left off.
(the session id is deliberately absent from this briefing: Cline mints one when
a run starts, which is after this text was written, so `cline history` is where
to read it. CLINE_DATA_DIR has to be set because this project's Cline state is
kept in that directory on the host rather than in ~/.cline/data - Cline indexes
every session it has ever run in a single database, so dejima gives each
project its own and one project's history is never another's context.)
(Cline indexes every session it has ever run in a single database, so dejima
gives each project its own rather than sharing one. That directory is
dejima's, not Cline's own, and pointing a host-side Cline at it is not a
supported path - which is why resuming outside is not on offer.)
+4 -2
View File
@@ -14,7 +14,9 @@ install = npm:cline
# Documents/Cline/Rules is where the briefing is staged. That path is not a
# guess and not what Cline's documentation says: ~/Documents/Cline/Rules
# reaches the model on Linux and ~/Cline/Rules does not.
image_dirs = .cline .cline/data Documents Documents/Cline Documents/Cline/Rules
# .agents and .cline/hooks are the operator's own config, mounted from the
# host by the plugin; they need a mount point in the image to land on.
image_dirs = .cline .cline/data .cline/hooks .agents .agents/skills .agents/hooks Documents Documents/Cline Documents/Cline/Rules
# DO_NOT_TRACK and DISABLE_TELEMETRY are both honoured; CLINE_NO_AUTO_UPDATE
# stops a session upgrading its own harness mid-run, which would replace a
@@ -89,7 +91,7 @@ no_confirm_args = --auto-approve true
# meant a model the operator serves - so there is no single value to record,
# and recording the wrong one would write a proxied endpoint into the config
# of a session that never used one. Making the two coherent is its own change.
keys = backend:?provider:backend state_dir:path=~/.local/share/dejima/cline model:?identifier context_window:?int:512:100000000
keys = backend:?provider:backend state_dir:path=~/.local/share/dejima/cline model:?modelid context_window:?int:512:100000000
# Deliberately empty: resuming needs the state directory's path as well as the
# session id, briefing placeholders do not nest, and `template` forbids the
+10 -5
View File
@@ -35,11 +35,16 @@ session_id="${1:-}"
resume_id="${session_id:-<your session id>}"
project_dir="${2:-$PWD}"
# /etc/hostname in a docker container is the container's own ID, which
# docker exec accepts directly - substituting it into the briefing below
# means the agent states its real container instead of guessing (a wrong
# guess that matches *another* running sandbox makes dejima-allow
# "succeed" against the wrong container).
# The id of this launch, read from the only place a session can see one.
#
# Not this container's own id, and worth being exact about: Docker names a
# container that joined another's network namespace after the container it
# joined, so what a session reads here is its FILTER container's id. That is
# still the right thing to put in the briefing - `dejima-allow` takes either
# half of the pair and derives the other - and it is what the agent has, so
# substituting it means stating a real id rather than guessing one. A wrong
# guess that matched another running sandbox would make dejima-allow "succeed"
# against somebody else's session.
container_id=$(cat /etc/hostname 2>/dev/null)
container_id="${container_id:-<container-id>}"
+92 -19
View File
@@ -25,28 +25,92 @@ input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command // empty')
cwd=$(echo "$input" | jq -r '.cwd // empty')
# Only care about `git push` invocations.
if ! [[ "$command" =~ (^|[[:space:]&\|;])git([[:space:]]+-C[[:space:]]+[^[:space:]]+)?[[:space:]]+push([[:space:]]|$) ]]; then
exit 0
fi
# Only care about `git push` invocations - found by walking tokens rather than
# by matching a shape.
#
# The pattern this replaced recognised `git push` and `git -C <dir> push` and
# nothing else, so every other spelling of git's own options - `git -c k=v
# push`, `git --git-dir=... push`, `git --no-pager push` - was not a push as
# far as this hook was concerned, and it exited 0 before any check ran. The
# PATH shadow in docker/git-guard.sh walks argv and caught them regardless,
# which is why this was a quiet gap in the earlier warning rather than an open
# one.
#
# Split on the shell separators first, because a push can be the second half
# of a compound command, and only the segment that STARTS with git is a git
# invocation - "echo push" is not.
push_seen=0
segment=""
IFS=$'\n' read -rd '' -a _segments < <(
printf '%s' "$command" | sed 's/&&/\n/g; s/||/\n/g; s/;/\n/g; s/|/\n/g'
printf '\0')
for seg in ${_segments[@]+"${_segments[@]}"}; do
read -ra _t <<< "$seg"
[ "${#_t[@]}" -gt 0 ] || continue
[ "${_t[0]}" = git ] || continue
_i=1
while [ "$_i" -lt "${#_t[@]}" ]; do
case "${_t[$_i]}" in
-c|-C|--exec-path|--git-dir|--work-tree|--namespace|--super-prefix)
_i=$((_i + 1)) ;;
-*) ;;
push) push_seen=1; segment="$seg"; break ;;
*) break ;;
esac
_i=$((_i + 1))
done
[ "$push_seen" -eq 1 ] && break
done
[ "$push_seen" -eq 1 ] || exit 0
# Everything below reads the git invocation, not the whole command line.
command="$segment"
repo_dir="$cwd"
if [[ "$command" =~ git[[:space:]]+-C[[:space:]]+([^[:space:]]+) ]]; then
repo_dir="${BASH_REMATCH[1]}"
fi
# Positionally parse everything after "push": first non-flag token is the
# remote, second (if any) is the refspec. Word-splitting rather than a full
# shell parse, so quoting edge cases aren't handled - same pragmatic
# tradeoff as the sibling deny-dangerous-bash.sh denylist.
after_push="${command#*push}"
read -ra tokens <<< "$after_push"
# One pass over the whole command, the way the shadow walks argv: skip git's
# own options until the first token that IS the subcommand, then take the
# first non-flag token as the remote and the second as the refspec.
#
# Splitting on the first occurrence of the substring "push" is what this
# replaced, and it split inside `remote.origin.pushurl=...`, a branch named
# push-fix, and anything else carrying the word. What came out was a nonsense
# remote, which then took the unresolvable path below.
#
# Word-splitting rather than a full shell parse, so quoting edge cases are not
# handled - the same pragmatic tradeoff as the sibling
# deny-dangerous-bash.sh denylist, and the reason the unresolvable case
# refuses rather than guesses.
#
# `-c key=value` is kept rather than dropped: git resolves where a push goes
# from the config the push runs under, so asking without these answers for a
# different configuration. `git -c remote.origin.pushurl=... push origin
# branch` is that case.
config_overrides=()
positional=()
for tok in "${tokens[@]}"; do
case "$tok" in
-*) continue ;;
*) positional+=("$tok") ;;
esac
read -ra tokens <<< "$command"
t=0
seen_push=0
while [ "$t" -lt "${#tokens[@]}" ]; do
tok="${tokens[$t]}"
if [ "$seen_push" -eq 0 ]; then
case "$tok" in
-c) t=$((t + 1))
[ "$t" -lt "${#tokens[@]}" ] && config_overrides+=(-c "${tokens[$t]}") ;;
-C|--exec-path|--git-dir|--work-tree|--namespace|--super-prefix)
t=$((t + 1)) ;;
push) seen_push=1 ;;
*) ;;
esac
else
case "$tok" in
-*) ;;
*) positional+=("$tok") ;;
esac
fi
t=$((t + 1))
done
remote="origin"
@@ -58,11 +122,20 @@ if [ "${#positional[@]}" -ge 2 ]; then
refspec="${positional[1]}"
fi
remote_url=$(git -C "$repo_dir" remote get-url "$remote" 2>/dev/null)
# --push: the URL the push will actually use. remote.<name>.pushurl wins over
# remote.<name>.url when it is set, and reading the latter checks a host the
# push is not going to. See docker/git-guard.sh, which asks the same question.
remote_url=$(git ${config_overrides[@]+"${config_overrides[@]}"} \
-C "$repo_dir" remote get-url --push "$remote" 2>/dev/null)
if [ -z "$remote_url" ]; then
# Can't resolve a remote from here - let git produce the real error
# rather than block or guess.
exit 0
# Refused, not passed through. A remote that does not resolve is usually a
# typo git would reject in a moment anyway - but it is also what a
# disagreement between this parser and git's own looks like, and the
# failure of that disagreement has to be a refusal rather than a push
# nobody checked. docker/git-guard.sh takes the same direction; the two
# answering differently was the bug.
echo "Blocked by git-push-guard.sh: cannot resolve the remote '$remote' to a URL, so there is nothing to check this push against. Name a remote that exists." >&2
exit 2
fi
host=$(echo "$remote_url" | sed -E 's#^[a-zA-Z]+://([^/@]+@)?([^/:]+).*#\2#; s#^[^@/]+@([^:/]+)[:/].*#\1#')
+4 -4
View File
@@ -41,11 +41,11 @@ if [ "${DEJIMA_BRIEFING_VIA_ARGS:-0}" = "1" ]; then
fi
# The image's copy first, because that is the one that exists in a real
# session: this file reaches the container through the ~/.claude/hooks mount,
# and install.sh links it there one file at a time, so its sibling in the repo
# is not alongside it. The sibling is the fallback so the hook can be run
# session: this file is baked in beside it and registered by absolute path
# into the sandbox's --settings overlay, so nothing about it depends on the
# operator's ~/.claude. The sibling is the fallback so the hook can be run
# against a checkout - which is what the test suite does - and readlink -f is
# what turns the linked path back into the repo one.
# what turns a linked path back into the repo one.
#
# Missing or unreadable degrades to no briefing rather than failing the hook:
# a SessionStart hook that exits non-zero drops the whole session's context,
+40 -21
View File
@@ -1,6 +1,9 @@
#!/bin/bash
# Idempotent installer for dejima. Registers the selected harness's guard
# hooks wherever that harness reads them from, and puts
# Idempotent installer for dejima. Writes NOTHING to the harness's own
# configuration: every hook dejima uses is baked into the image and registered
# per launch into a settings layer of dejima's own, so installing this does not
# change how the harness behaves outside a sandbox. What it still does is take
# back what older versions put there. It puts
# bin/dejima, bin/dejima-allow, bin/dejima-dep, bin/dejima-project,
# bin/dejima-audit, bin/dejima-share and the opt-in remote-access scripts on
# PATH. Safe to re-run - every step is a no-op if already done, and every
@@ -127,9 +130,14 @@ else
_starter_extra_keys="$(_config_extra_keys_for forge gitea)"
fi
# Seeded from any legacy variables still exported, so the one-time
# migration is a review rather than a retyping. Everything else is
# written commented-out at its schema default, so the file doubles as
# the reference for what can be set.
# migration is a review rather than a retyping.
#
# Only what is seeded. This file used to carry every key commented out at
# its schema default, so it doubled as the reference - which meant a second
# copy of the defaults, in comments nothing regenerates, drifting against
# the schema as keys were added. defaults.conf beside it is that reference
# now, complete and rewritten by every ./install.sh, and this file holds
# only what the operator has actually decided.
{
printf '# dejima configuration. See README.md.\n'
printf '# Every key below is shown at its default; uncomment to change one.\n'
@@ -151,11 +159,6 @@ else
[ -n "$_key" ] || continue
_leaf="${_key##*.}"
_sec="${_key%.*}"
_default="$(config_default "$_key")"
if [ "$_sec" != "$_section" ]; then
printf '\n[%s]\n' "$_sec"
_section="$_sec"
fi
_seed=""
case "$_key" in
forge.gitea.ssh_host) _seed="${GITEA_SSH_HOST:-}" ;;
@@ -183,24 +186,40 @@ else
[ -n "${XDG_DATA_HOME:-}" ] && _seed="$XDG_DATA_HOME/dejima/baselines"
;;
esac
if [ -n "$_seed" ]; then
printf '%s = %s\n' "$_leaf" "$_seed"
else
printf '# %s = %s\n' "$_leaf" "$_default"
[ -n "$_seed" ] || continue
# The header is written with the first key that lands under it, so
# a section nothing seeded leaves no empty stanza behind.
if [ "$_sec" != "$_section" ]; then
printf '\n[%s]\n' "$_sec"
_section="$_sec"
fi
printf '%s = %s\n' "$_leaf" "$_seed"
done < <(_config_keys; [ -z "$_starter_extra_keys" ] || printf '%s\n' "$_starter_extra_keys")
} > "$CONFIG_FILE"
chmod 600 "$CONFIG_FILE"
fi
# The pinned defaults, rebuilt: keys this release added appended, keys it
# retired dropped, everything already decided left where it is. This is the
# only place that reports a shipped default having moved, because this is when
# it moves - you pulled and re-ran this. A launch checking would be a standing
# condition in front of every one.
# The blank line is the rebuild's, not this script's: on a run with nothing to
# add, drop or report it says nothing, and an unconditional `echo` here left a
# second blank line between two paragraphs that were already separated.
config_defaults_rebuild
# Guard registration, after the starter config above rather than before it:
# where dejima's guards go, and in what shape, is the selected harness's
# business, and on a fresh install that selection is the one just seeded.
# Registering before reading it would mean writing one harness's config for
# an operator who has chosen another.
#
# Delegated to the harness's plugin, which is also what gates each guard on
# the harness having declared it (see `guards` in its manifest).
# Nothing to register: the sandbox's hooks are baked into the image and
# registered per launch into its own settings overlay. What is delegated to
# the plugin is the host-side cleanup an upgrade needs - taking back what
# older versions wrote into the harness's config - which still has to know
# which harness is selected.
echo
source "$SCRIPT_DIR/bin/dejima-harness-lib.sh"
# A config that does not parse leaves config_get empty for EVERY key, so
@@ -209,20 +228,20 @@ source "$SCRIPT_DIR/bin/dejima-harness-lib.sh"
# fault, on stderr, which is the answer to a question this cannot answer.
_harness=""
if config_exists && ! config_validate; then
echo "$CONFIG_FILE could not be read, so no guard hooks were registered."
echo "$CONFIG_FILE could not be read, so no harness host-side setup was checked."
echo "Fix what is reported above and re-run ./install.sh."
elif ! _harness="$(config_get core harness 2>/dev/null)" || [ -z "$_harness" ]; then
_harness=""
echo "No [core] harness is set in $CONFIG_FILE, so no guard hooks were"
echo "registered. Set one and re-run ./install.sh."
echo "No [core] harness is set in $CONFIG_FILE, so no harness host-side"
echo "setup was checked. Set one and re-run ./install.sh."
else
DEJIMA_HARNESS_NAME="$_harness"
harness_plugin_load "$_harness"
if declare -F harness_register_guards >/dev/null 2>&1; then
echo "Registering $_harness's guard hooks"
echo "Checking $_harness's host-side setup"
harness_register_guards "$SCRIPT_DIR" "$BACKUP_DIR"
else
echo "Harness '$_harness' installs no guard hooks."
echo "Harness '$_harness' needs nothing on the host."
echo
fi
fi
+716 -85
View File
@@ -20,6 +20,7 @@ setup() {
unset GITEA_SSH_HOST GITEA_API GITEA_TOKEN_FILE GITEA_TOKEN GH_TOKEN_FILE \
GH_TOKEN SANDBOX_CMD SANDBOX_SSH_KEY SANDBOX_SHARE_DIR SANDBOX_EXTRA_MOUNTS \
SANDBOX_NVIM_CONFIG SANDBOX_CREDENTIAL_PROXY SANDBOX_ANTHROPIC_TRANSPORT \
SANDBOX_CREDENTIAL_TRANSPORT \
SANDBOX_LOG_CONVERSATION LOKI_URL ENABLE_FIREWALL SSH_KNOWN_HOSTS \
ALLOW_GITHUB_PUSH DEJIMA_AUDIT_DIR DEJIMA_AUDIT_BASELINE_DIR \
DEJIMA_AUDIT_KEEP DEJIMA_AUDIT_STRICT DEJIMA_AUDIT_STATUSLINE \
@@ -218,6 +219,232 @@ write_config() {
esac
}
# --- the pinned defaults layer ------------------------------------------------
#
# defaults.conf holds what dejima's defaults were when this machine first saw
# each key, so a release that changes one cannot move a session whose config
# never changed. The operator's file overrides it; the schema answers only for
# a key it has no line for.
write_defaults() { printf '%s\n' "$@" > "$CONFIG_DIR/defaults.conf"; }
@test "the operator's value beats the pinned one, which beats the schema" {
write_config '[core]' 'firewall = off'
write_defaults '[core]' 'firewall = on' 'workflow = branch-push' \
'[audit]' 'keep = 3'
# Theirs.
run lib config_get core firewall
[ "$output" = "off" ] || { echo "$output"; return 1; }
# Pinned, over a schema that says local-only and 10.
run lib config_get core workflow
[ "$output" = "branch-push" ] || { echo "$output"; return 1; }
run lib config_get audit keep
[ "$output" = "3" ] || { echo "$output"; return 1; }
# Schema, for a key nothing has pinned.
run lib config_get audit diffs
[ "$output" = "on" ] || { echo "$output"; return 1; }
}
@test "config_origin names which of the three answered" {
write_config '[core]' 'firewall = off'
write_defaults '[core]' 'workflow = branch-push'
run lib config_origin core firewall
[ "$output" = "user" ] || { echo "firewall: $output"; return 1; }
run lib config_origin core workflow
[ "$output" = "default" ] || { echo "workflow: $output"; return 1; }
run lib config_origin audit diffs
[ "$output" = "schema" ] || { echo "diffs: $output"; return 1; }
}
@test "a pinned key is not one the operator set" {
# The trap the whole two-array split exists for. Ten callers of
# config_is_set mean "did the operator write this" - the ssh_key
# deprecation refusal, identity-over-forge precedence, and the ttyd knobs
# where unset means the page decides. A defaults.conf naming every key
# would answer yes to all of them.
write_config '[core]' 'firewall = off'
write_defaults '[core]' 'workflow = branch-push' '[remote-access]' \
'ttyd_button_colors = on'
run lib config_is_set core firewall
[ "$status" -eq 0 ] || { echo "the operator's own key read as unset"; return 1; }
run lib config_is_set core workflow
[ "$status" -ne 0 ] || { echo "a pinned key read as one the operator set"; return 1; }
run lib config_is_set remote-access ttyd_button_colors
[ "$status" -ne 0 ] || { echo "a pinned ttyd knob read as one the operator set"; return 1; }
}
@test "no pinned layer at all is not an error" {
# A checkout that has never been launched. The schema answers for
# everything until there is a file.
write_config '[core]' 'firewall = on'
[ ! -e "$CONFIG_DIR/defaults.conf" ]
run lib config_get audit keep
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[ "$output" = "10" ]
}
@test "the pinned layer is skipped line by line where the operator's is refused" {
# An unknown key here is one dejima RETIRED, on a machine whose
# defaults.conf predates the release that dropped it. The operator did not
# write it and is told not to edit the file, so refusing would leave them a
# launch that will not start and nothing to do about it.
write_config '[core]' 'firewall = on'
write_defaults '[core]' 'workflow = branch-push' 'retired_key = whatever' \
'share_dir = ' '[gone-axis]' 'something = 1' \
'[audit]' 'keep = 3' 'this line is malformed'
# It still launches, and the good lines still count.
run lib config_get core workflow
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[ "$output" = "branch-push" ]
# Including one after the unknown section, or a stale section would take
# the rest of the file with it.
run lib config_get audit keep
[ "$output" = "3" ] || { echo "keep: $output"; return 1; }
# A value the schema refuses falls through rather than being honoured:
# share_dir is not optional, so an empty one is not a value.
run lib config_origin core share_dir
[ "$output" = "schema" ] || { echo "share_dir origin: $output"; return 1; }
# And the count is available for the launch to name once.
run lib config_defaults_stale
[ "$output" -ge 4 ] || { echo "counted $output stale lines"; return 1; }
}
@test "the operator's own file is still refused line by line" {
# The leniency above is for the file they cannot edit. Theirs is theirs.
write_defaults '[core]' 'workflow = branch-push'
printf '[core]\nharness = claude-code\nnonsense = 1\n' > "$CONFIG_DIR/config"
run lib config_get core forge
[ "$status" -ne 0 ] || { echo "an unknown key in the operator's file was accepted"; return 1; }
[[ "$output" == *"unknown key"* ]] || { echo "$output"; return 1; }
}
@test "a launch pins the defaults once, and says so only that time" {
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
[ ! -e "$CONFIG_DIR/defaults.conf" ]
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[ -f "$CONFIG_DIR/defaults.conf" ] || { echo "nothing was pinned"; return 1; }
[[ "$output" == *"Pinned dejima's current defaults"* ]] \
|| { echo "created the file without saying so: $output"; return 1; }
# It is dejima's own, not the operator's: 0600 and a header saying so.
[ "$(stat -c '%a' "$CONFIG_DIR/defaults.conf")" = "600" ]
grep -q 'NOT yours to edit' "$CONFIG_DIR/defaults.conf"
# A second launch is silent about it, and does not rewrite it: a standing
# line on every launch is one an operator learns to scroll past.
local before; before="$(cat "$CONFIG_DIR/defaults.conf")"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" != *"Pinned dejima"* ]] \
|| { echo "said it again: $output"; return 1; }
[ "$before" = "$(cat "$CONFIG_DIR/defaults.conf")" ] \
|| { echo "a launch rewrote the pinned file"; return 1; }
rm -rf "$workspace"
}
@test "what a launch pins is every defaulted key, and no key without one" {
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
local f="$CONFIG_DIR/defaults.conf"
# A defaulted core key, a defaulted key of a harness that is NOT selected -
# pinning only the selected one leaves the next harness an operator picks
# handing them its current defaults - and one of a backend.
grep -q '^keep = 10$' "$f" || { echo "no [audit] keep"; cat "$f"; return 1; }
grep -q '^\[harness.cline\]$' "$f" || { echo "no unselected harness"; cat "$f"; return 1; }
grep -q '^\[backend.anthropic\]$' "$f" || { echo "no backend"; cat "$f"; return 1; }
# And nothing that has no default, because there is nothing to pin: those
# are exactly the keys docs/configuration.md marks required.
grep -q '^harness = ' "$f" && { echo "pinned a key with no default"; return 1; }
grep -q '^model = ' "$f" && { echo "pinned a key with no default"; return 1; }
# It reads back with nothing skipped, which a hand-kept renderer would
# drift out of.
run lib config_defaults_stale
[ "$output" = "0" ] || { echo "the file it wrote has $output unreadable lines"; return 1; }
rm -rf "$workspace"
}
@test "a launch names a pinned key this dejima has retired, and carries on" {
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
printf '[core]\nworkflow = local-only\nretired_key = 1\n' > "$CONFIG_DIR/defaults.conf"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "a retired pinned key stopped the launch: $output"; return 1; }
[[ "$output" == *"no longer reads"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"./install.sh"* ]] \
|| { echo "named the problem without the fix: $output"; return 1; }
rm -rf "$workspace"
}
@test "install.sh rebuilds the pinned file without moving what is in it" {
stub_docker
run_install
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
local f="$CONFIG_DIR/defaults.conf"
[ -f "$f" ] || { echo "install.sh pinned nothing"; return 1; }
# A value already decided, a key this release would add, and a key it has
# retired - the three things a rebuild has to get right at once.
sed -i 's/^keep = 10$/keep = 25/' "$f"
sed -i '/^diffs = on$/d' "$f"
printf '\n[core]\nretired_thing = 1\n' >> "$f"
run_install
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
grep -q '^keep = 25$' "$f" || { echo "a rebuild moved a pinned value"; cat "$f"; return 1; }
grep -q '^diffs = on$' "$f" || { echo "a rebuild did not add a new key"; return 1; }
grep -q 'retired_thing' "$f" && { echo "a rebuild kept a retired key"; return 1; }
# Pruning is not the tidier half: an unknown key is one dejima cannot
# read, so a file that only grew would collect them.
run lib config_defaults_stale
[ "$output" = "0" ] || { echo "$output unreadable lines survived the rebuild"; return 1; }
}
@test "install.sh names a default that has moved, and does not take it" {
stub_docker
run_install
sed -i 's/^keep = 10$/keep = 25/' "$CONFIG_DIR/defaults.conf"
run_install
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"yours stays 25"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"dejima now ships 10"* ]] || { echo "$output"; return 1; }
# Named, not adopted, and the file it points at for taking one is the
# operator's - never the pinned file, which the next rebuild rewrites.
grep -q '^keep = 25$' "$CONFIG_DIR/defaults.conf" \
|| { echo "install.sh adopted the shipped default"; return 1; }
[[ "$output" == *"$CONFIG_DIR/config"* ]] || { echo "$output"; return 1; }
}
@test "the starter config carries only what was seeded, not every key commented" {
# It used to write every key commented at its schema default, which was a
# second copy of the defaults in comments nothing regenerates.
# defaults.conf is that reference now.
stub_docker
run_install
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
local c="$CONFIG_DIR/config"
grep -q '^harness = claude-code$' "$c" || { echo "the selection is not written"; cat "$c"; return 1; }
grep -qE '^# [a-z_]+ = ' "$c" && { echo "still writing commented defaults:"; cat "$c"; return 1; }
# And no stanza left behind by a section nothing seeded. Comments and
# blanks dropped first: the header prose names sections in prose.
grep -vE '^\s*(#|$)' "$c" | awk '
/^\[/ { if (open) { print "empty: " prev; bad = 1 } open = 1; prev = $0; next }
{ open = 0 }
END { if (open) { print "empty: " prev; bad = 1 } exit bad }
' || { echo "an empty section survived:"; cat "$c"; return 1; }
[ "$(grep -c . "$c")" -gt 0 ]
}
@test "config_get returns the schema default when the key is absent" {
write_config '[core]' 'firewall = on'
run lib config_get audit keep
@@ -485,6 +712,17 @@ write_config() {
[ "$(printf '%s\n' "$output" | wc -l)" -eq "$expected" ]
}
@test "--print-config inspects without pinning anything" {
# A query that creates a file as a side effect is not a query. Nothing is
# lost by waiting: with nothing pinned every key resolves through the
# schema, which is what the first real launch then pins.
write_config '[core]' 'firewall = on'
run "$REPO_ROOT/bin/dejima" --print-config
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[ ! -e "$CONFIG_DIR/defaults.conf" ] \
|| { echo "--print-config created the pinned file"; return 1; }
}
@test "warming the config cache does not swallow the reason it is invalid" {
# bin/dejima parses the config once in its own shell before anything reads
# a key, so the parse survives into the subshells that do the reading. That
@@ -675,16 +913,23 @@ _identity_fixture() {
@test "--harness changes what the session is actually told, not just the printed config" {
# The flag has to reach the composed briefing, or it would select a harness
# for the container while the session was briefed about a different one.
# Cline's fragment names its own resume command, which Claude Code's does
# not, so the two are distinguishable.
# What distinguishes them is what each says about resuming: Claude Code
# offers a command, Cline rules it out. Checked in both directions, so a
# briefing that somehow carried both would not pass either.
write_config '[core]' 'harness = claude-code' 'forge = none' 'workflow = local-only' \
'[harness.cline]' 'model = m'
run "$REPO_ROOT/bin/dejima" --print-briefing
[[ "$output" != *"CLINE_DATA_DIR"* ]] || { echo "default briefed as cline"; return 1; }
[[ "$output" == *"claude --resume"* ]] \
|| { echo "the default is not briefed as claude-code: $output"; return 1; }
[[ "$output" != *"cannot be continued outside dejima"* ]] \
|| { echo "default briefed as cline"; return 1; }
run "$REPO_ROOT/bin/dejima" --harness cline --print-briefing
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"CLINE_DATA_DIR"* ]] \
[[ "$output" == *"cannot be continued outside dejima"* ]] \
|| { echo "the briefing is still the default harness's: $output"; return 1; }
[[ "$output" != *"claude --resume"* ]] \
|| { echo "the cline briefing still offers Claude Code's resume: $output"; return 1; }
}
@test "--print-config refuses an invalid config rather than printing defaults" {
@@ -1863,6 +2108,65 @@ EOF
rm -rf "$workspace" "$RW_HOME"
}
# The guard named ~/.claude literally, so a Cline operator could hand a
# session write access to the hooks and skills their own machine runs next.
# Every path here comes from the plugin or its manifest rather than from a
# list in bin/dejima, which is what makes the second harness covered without
# anyone having remembered it.
@test "the selected harness's own host config is guarded, whichever harness" {
_rw_setup
workspace="$(mktemp -d)"
# Created first: a missing directory is refused for being missing, which
# would pass this test without the overlap rule ever running.
mkdir -p "$RW_HOME/.agents/skills" "$RW_HOME/.cline/hooks" \
"$RW_HOME/.local/share/dejima/cline" \
"$RW_HOME/.claude/projects" "$RW_HOME/.claude/plugins"
# A config dir the plugin mounts, a seeded file's directory, and the
# state root the manifest declares as a `path` key - one of each way a
# path reaches the list.
for guarded in "$RW_HOME/.agents" "$RW_HOME/.cline" \
"$RW_HOME/.local/share/dejima/cline"; do
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'harness = cline' \
'[harness.cline]' 'backend = anthropic' 'model = m' \
'[mounts]' "read_write = $guarded"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "accepted a writable mount over $guarded"; return 1; }
[[ "$output" == *"Refusing"* ]] \
|| { echo "wrong failure for $guarded: $output"; return 1; }
done
# Claude Code's, which the literal used to cover. projects/ is a manifest
# `path` key and plugins/ is reached only through a seed destination, so
# both would be missed by a list built from mounted directories alone.
for guarded in "$RW_HOME/.claude" "$RW_HOME/.claude/projects" \
"$RW_HOME/.claude/plugins"; do
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write = $guarded"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "accepted a writable mount over $guarded"; return 1; }
[[ "$output" == *"Refusing"* ]] \
|| { echo "wrong failure for $guarded: $output"; return 1; }
done
rm -rf "$workspace" "$RW_HOME"
}
# Refusing everything would pass the test above, and a read_write mount is a
# supported feature rather than a thing to break in the course of guarding it.
@test "a read_write entry outside the harness's config is still accepted" {
_rw_setup
workspace="$(mktemp -d)"
rw="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'harness = cline' \
'[harness.cline]' 'backend = anthropic' 'model = m' \
'[mounts]' "read_write = $rw"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
grep -qxF "$rw:$rw" "$docker_log" \
|| { echo "not mounted read-write:"; cat "$docker_log"; return 1; }
rm -rf "$workspace" "$rw" "$RW_HOME"
}
@test "the audit and baseline stores are guarded, not just the obvious paths" {
# Named explicitly because a regression that dropped them from the guarded
# list would otherwise pass every other test here.
@@ -1917,6 +2221,139 @@ EOF
rm -rf "$workspace" "$RW_HOME"
}
@test "a read_write_per_project entry mounts this project's slice at the path it names" {
_rw_setup
pp="$(mktemp -d)"
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write_per_project = $pp"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
# The container gets the path the operator named; the host gives it one
# directory of that path, keyed the same way share_dir and the audit store
# are. Both halves asserted, because either alone is satisfied by the
# arrangement this replaces.
slug="$(printf '%s' "$workspace" | sed 's/[^a-zA-Z0-9]/-/g')"
grep -qxF "$pp/projects/$slug:$pp" "$docker_log" \
|| { echo "not mounted as a per-project slice:"; grep "$pp" "$docker_log"; return 1; }
run grep -qxF "$pp:$pp" "$docker_log"
[ "$status" -ne 0 ] \
|| { echo "the whole directory was handed over as well"; return 1; }
[ -d "$pp/projects/$slug" ] || { echo "the slice was never created"; return 1; }
rm -rf "$pp" "$workspace" "$RW_HOME" "$docker_log"
}
@test "two projects get different slices of one read_write_per_project entry" {
# The whole point, and not deducible from one launch: the same declared
# directory has to give two workspaces two directories, or it is a shared
# pile with extra steps.
_rw_setup
pp="$(mktemp -d)"
ws_a="$(mktemp -d)"; ws_b="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write_per_project = $pp"
_rw_launch "$ws_a"; [ "$status" -eq 0 ] || { echo "$output"; return 1; }
a_log="$docker_log"
_rw_launch "$ws_b"; [ "$status" -eq 0 ] || { echo "$output"; return 1; }
a="$(grep -oE "$pp/projects/[^:]+" "$a_log" | head -1)"
b="$(grep -oE "$pp/projects/[^:]+" "$docker_log" | head -1)"
[ -n "$a" ] && [ -n "$b" ] || { echo "no slice mounted for one of them"; return 1; }
[ "$a" != "$b" ] \
|| { echo "both projects were given the same directory: $a"; return 1; }
rm -rf "$pp" "$ws_a" "$ws_b" "$RW_HOME" "$a_log" "$docker_log"
}
@test "read_write is refused when it names a read_write_per_project root" {
# The share guard's reason, one directory over: handing over the root that
# holds every project's slice puts back the pile the slicing removed.
_rw_setup
pp="$(mktemp -d)"
workspace="$(mktemp -d)"
mkdir -p "$pp/projects"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write = $pp/projects" "read_write_per_project = $pp"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "the pile was handed back: $output"; return 1; }
[[ "$output" == *"holds one directory per project"* ]] || { echo "$output"; return 1; }
rm -rf "$pp" "$workspace" "$RW_HOME" "$docker_log"
}
@test "readonly is refused when it names a read_write_per_project root" {
_rw_setup
pp="$(mktemp -d)"
workspace="$(mktemp -d)"
mkdir -p "$pp/projects"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "readonly = $pp/projects" "read_write_per_project = $pp"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "every project's slice was readable: $output"; return 1; }
rm -rf "$pp" "$workspace" "$RW_HOME" "$docker_log"
}
@test "a read_write_per_project entry overlapping a protected path is refused" {
# Slicing does not make a guarded store safe to hand over - it only makes
# less of it reachable, which is not the property the guard is about.
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write_per_project = $CONFIG_DIR"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "the approval store was mounted: $output"; return 1; }
[[ "$output" == *"only how much of it there is"* ]] || { echo "$output"; return 1; }
rm -rf "$workspace" "$RW_HOME" "$docker_log"
}
@test "the same path in read_write and read_write_per_project is refused" {
# Not by a duplicate check: the two mean different things, so naming a path
# in both makes it an ancestor of its own per-project root, and the refusal
# that fires is the one about handing over every project's directory. That
# is the right answer, and it says which list the path belongs in.
_rw_setup
pp="$(mktemp -d)"
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write = $pp" "read_write_per_project = $pp"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"holds one directory per project"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"one list or the other and not in both"* ]] || { echo "$output"; return 1; }
rm -rf "$pp" "$workspace" "$RW_HOME" "$docker_log"
}
@test "a read_write_per_project entry that is not an existing directory is refused" {
# The slice is dejima's to create; the root is not. A path that is not
# there is a typo, and creating it would turn the typo into a directory.
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write_per_project = /nonexistent/specs"
_rw_launch "$workspace"
[ "$status" -ne 0 ]
[[ "$output" == *"not an existing directory"* ]] || { echo "$output"; return 1; }
[ ! -d /nonexistent/specs ]
rm -rf "$workspace" "$RW_HOME" "$docker_log"
}
@test "--print-briefing names a per-project mount as this project's own" {
# A separate sentence from the read_write one, because the read_write
# sentence is not true of these: a session told "these host directories at
# their own paths" would believe the whole directory is behind the mount.
pp="$(mktemp -d)"
rw="$(mktemp -d)"
write_config '[core]' 'forge = none' 'workflow = local-only' \
'[mounts]' "read_write = $rw" "read_write_per_project = $pp"
run "$REPO_ROOT/bin/dejima" --print-briefing
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"at their own paths"*"$rw"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"THIS project's own directory"*"$pp"* ]] || { echo "$output"; return 1; }
# And composing a briefing leaves nothing behind: the slice belongs to a
# launch, not to a diagnostic that prints one.
[ ! -d "$pp/projects" ] || { echo "--print-briefing created the slice"; return 1; }
rm -rf "$pp" "$rw"
}
@test "a path in both read_write and readonly is refused rather than resolved by mount order" {
_rw_setup
d="$(mktemp -d)"
@@ -2381,35 +2818,89 @@ _epitaph_three() {
"$REPO_ROOT/backends" "$proot/"
sed -i 's/^guards .*/guards = bash-deny/' \
"$proot/harnesses/claude-code/harness.conf"
run_install DEJIMA_PROVIDER_ROOT="$proot"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
run jq -r '[.hooks.PreToolUse[]?.hooks[]?.command] | join(" ")' \
"$CONFIG_DIR/.claude/settings.json"
[[ "$output" == *"deny-dangerous-bash.sh"* ]] || { echo "$output"; return 1; }
[[ "$output" != *"git-push-guard.sh"* ]] \
|| { echo "registered an undeclared guard: $output"; return 1; }
[[ "$output" != *"merge-guard.sh"* ]] \
|| { echo "registered an undeclared guard: $output"; return 1; }
rm -rf "$proot"
# The gating moved to the settings overlay with the registration itself,
# so this asks the overlay what it registered rather than the host.
local ov; ov="$(mktemp)"
DEJIMA_PROVIDER_ROOT="$proot" HOME="$CONFIG_DIR" bash -c '
source "'"$REPO_ROOT"'/bin/dejima-provider-lib.sh"
source "'"$REPO_ROOT"'/bin/dejima-harness-lib.sh"
DEJIMA_HARNESS_NAME=claude-code
harness_plugin_load claude-code
harness_hook harness_prepare_config "$1"
' _ "$ov" >/dev/null 2>&1
local cmds; cmds="$(jq -r '[.hooks.PreToolUse[]?.hooks[]?.command] | join(" ")' "$ov")"
[[ "$cmds" == *"deny-dangerous-bash.sh"* ]] \
|| { echo "the declared guard was not registered: $cmds"; rm -rf "$proot" "$ov"; return 1; }
[[ "$cmds" != *"git-push-guard.sh"* ]] \
|| { echo "registered an undeclared guard: $cmds"; rm -rf "$proot" "$ov"; return 1; }
[[ "$cmds" != *"merge-guard.sh"* ]] \
|| { echo "registered an undeclared guard: $cmds"; rm -rf "$proot" "$ov"; return 1; }
rm -rf "$proot" "$ov"
}
@test "install.sh registers every guard when the harness declares them all" {
# The shipped harness, unmodified: the behaviour this replaced, kept.
@test "install.sh writes nothing to the operator's harness config" {
# The shipped harness, unmodified. Every guard reaches a session through
# the sandbox's own settings overlay, so installing dejima changes nothing
# about how the harness behaves outside a sandbox - including the one hook
# that used to be registered there deliberately.
run_install
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
local h
for h in sandbox-context.sh git-push-guard.sh merge-guard.sh dejima-notify.sh \
deny-dangerous-bash.sh; do
[ ! -e "$CONFIG_DIR/.claude/hooks/$h" ] \
|| { echo "$h was linked into the operator's hooks directory"; return 1; }
done
# And no registration either. The file may not exist at all, which is the
# strongest form of this - so its absence counts as passing.
if [ -f "$CONFIG_DIR/.claude/settings.json" ]; then
local cmds
cmds="$(jq -r '[.hooks[]?[]?.hooks[]?.command] | join(" ")' \
"$CONFIG_DIR/.claude/settings.json")"
[ -z "$cmds" ] || { echo "install.sh registered hooks on the host: $cmds"; return 1; }
fi
}
# The half that was missing when the registrations moved into the overlay:
# every test above asks what the overlay got, and none asked what the launch
# then SAYS about it. So the check that reads the operator's file kept
# reporting all four guards missing - correctly, since nothing writes there
# any more - and told the operator to run ./install.sh, which strips the very
# registrations it was looking for.
@test "a launch with nothing in the operator's settings does not claim the guards are off" {
_rw_setup
workspace="$(mktemp -d)"
# The state a correct install now leaves: settings.json present, dejima
# nowhere in it. An empty file would not do - that is unparseable to
# Claude Code and a different case.
printf '{}\n' > "$RW_HOME/.claude/settings.json"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'harness = claude-code'
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" != *"not in force this session"* ]] \
|| { echo "claimed the guards were off: $output"; return 1; }
rm -rf "$workspace" "$RW_HOME"
# The positive half, or the assertion above passes just as well on a
# launch that registered nothing anywhere. Read from the overlay the
# plugin composes, which is where they now live.
local ov; ov="$(mktemp)"
HOME="$CONFIG_DIR" bash -c '
source "'"$REPO_ROOT"'/bin/dejima-provider-lib.sh"
source "'"$REPO_ROOT"'/bin/dejima-harness-lib.sh"
DEJIMA_HARNESS_NAME=claude-code
harness_plugin_load claude-code
harness_hook harness_prepare_config "$1"
' _ "$ov" >/dev/null 2>&1
local cmds
cmds="$(jq -r '[.hooks.PreToolUse[]?.hooks[]?.command,
.hooks.SessionStart[]?.hooks[]?.command] | join(" ")' \
"$CONFIG_DIR/.claude/settings.json")"
cmds="$(jq -r '[.hooks[]?[]?.hooks[]?.command] | join(" ")' "$ov")"
local h
for h in sandbox-context.sh git-push-guard.sh merge-guard.sh deny-dangerous-bash.sh; do
[[ "$cmds" == *"$h"* ]] || { echo "$h not registered: $cmds"; return 1; }
[[ "$cmds" == *"$h"* ]] \
|| { echo "$h is in force nowhere: $cmds"; rm -f "$ov"; return 1; }
done
# Linked for the read-only hooks mount, but registered per session by
# bin/dejima rather than here, where it would fire for host sessions too.
[ -L "$CONFIG_DIR/.claude/hooks/dejima-notify.sh" ]
[[ "$cmds" != *"dejima-notify.sh"* ]] \
|| { echo "notify registered host-wide: $cmds"; return 1; }
rm -f "$ov"
}
@test "install.sh registers no guards when no harness is selected" {
@@ -2458,58 +2949,6 @@ _epitaph_three() {
rm -rf "$workspace"
}
@test "a launch says so when the harness's hooks were never registered" {
# install.sh registers them gated on [core] harness. An operator who set
# that key without re-running it gets no briefing and no guards, on every
# launch, with nothing saying why.
_rw_setup
workspace="$(mktemp -d)"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
# _rw_setup writes a settings.json with no hooks in it at all.
_rw_launch "$workspace"
[[ "$output" == *"not in force this session"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"the session briefing"* ]] || { echo "$output"; return 1; }
rm -rf "$workspace"
}
@test "a launch names the one guard a hand-edited config dropped" {
# The realistic failure is all-or-nothing, so a check on the briefing
# alone would pass here - and a session would run without the merge
# guard, silently, which is what the report exists to prevent.
_rw_setup
workspace="$(mktemp -d)"
jq -n '{hooks: {
SessionStart: [{matcher: "startup", hooks: [{type: "command",
command: "$HOME/.claude/hooks/sandbox-context.sh"}]}],
PreToolUse: [{matcher: "Bash", hooks: [
{type: "command", command: "$HOME/.claude/hooks/git-push-guard.sh"},
{type: "command", command: "$HOME/.claude/hooks/deny-dangerous-bash.sh"}]}]}}' \
> "$RW_HOME/.claude/settings.json"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
_rw_launch "$workspace"
[[ "$output" == *"merge-guard"* ]] || { echo "$output"; return 1; }
[[ "$output" != *"the session briefing"* ]] \
|| { echo "named something that is registered: $output"; return 1; }
rm -rf "$workspace"
}
@test "a launch stays quiet when the harness's hooks are registered" {
_rw_setup
workspace="$(mktemp -d)"
jq -n '{hooks: {
SessionStart: [{matcher: "startup", hooks: [{type: "command",
command: "$HOME/.claude/hooks/sandbox-context.sh"}]}],
PreToolUse: [{matcher: "Bash", hooks: [
{type: "command", command: "$HOME/.claude/hooks/git-push-guard.sh"},
{type: "command", command: "$HOME/.claude/hooks/merge-guard.sh"},
{type: "command", command: "$HOME/.claude/hooks/deny-dangerous-bash.sh"}]}]}}' \
> "$RW_HOME/.claude/settings.json"
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only'
_rw_launch "$workspace"
[[ "$output" != *"not in force this session"* ]] || { echo "$output"; return 1; }
rm -rf "$workspace"
}
# --- the harness layer ----------------------------------------------------
@test "the selected harness is built into a layer of its own, and the session runs on it" {
@@ -2721,10 +3160,30 @@ _upd_cache() { printf '%s/.local/share/dejima/update-check' "$HOME"; }
[ "$status" -eq 0 ]
[[ "$output" == *"origin/trunk"* ]] \
|| { echo "does not name what it is behind: $output"; return 1; }
# The path, because the checkout that is behind is not necessarily the
# The paths, because the checkout that is behind is not necessarily the
# directory the operator is standing in when they read this.
[[ "$output" == *"git -C $UPD_CHECKOUT pull"* ]] \
|| { echo "does not say how to update: $output"; return 1; }
# install.sh too, because pulling does not re-link what a new release
# adds on PATH.
[[ "$output" == *"$UPD_CHECKOUT/install.sh"* ]] \
|| { echo "does not say to re-run install.sh: $output"; return 1; }
}
@test "the notice is set off by a blank line either side" {
_upd_fixture
_upd_commit "$UPD_ORIGIN" second
# Read from the file the tool wrote: bats' run strips the blank lines at
# either end of what it captures, and those are the thing being asserted -
# they are what keeps the launch's startup lines and image build from
# reading as part of the notice.
local out="$UPD_DIR/notice"
"$UPD_CHECKOUT/bin/dejima-update-check" >"$out" 2>&1
grep -q "commits this checkout" "$out" || { cat "$out"; return 1; }
[ -z "$(head -n 1 "$out")" ] \
|| { echo "no blank line before it: $(cat "$out")"; return 1; }
[ -z "$(tail -n 1 "$out")" ] \
|| { echo "no blank line after it: $(cat "$out")"; return 1; }
}
@test "the commit count is given only when the commits are actually here" {
@@ -3089,7 +3548,7 @@ EOF
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"Recorded [harness.claude-code] backend = anthropic"* ]] \
[[ "$output" == *"wrote a line into"* ]] && [[ "$output" == *"backend = anthropic"* ]] \
|| { echo "the migration was silent: $output"; return 1; }
# In the operator's file, so the next launch reads it rather than assuming
# it again.
@@ -3099,7 +3558,7 @@ EOF
# And it happens once. A second launch finds the value and says nothing.
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" != *"Recorded [harness"* ]] \
[[ "$output" != *"wrote a line into"* ]] \
|| { echo "the migration ran again: $output"; return 1; }
[ "$(grep -c 'backend = anthropic' "$CONFIG_DIR/config")" -eq 1 ] \
|| { echo "the value was written twice:"; cat "$CONFIG_DIR/config"; return 1; }
@@ -3198,7 +3657,7 @@ EOF
stub="$(mktemp -d)"; log="$(mktemp)"
cat > "$stub/docker" <<EOF
#!/bin/sh
env | grep '^SANDBOX_ANTHROPIC' >> "$log"
env | grep -E '^SANDBOX_(ANTHROPIC|CREDENTIAL)' >> "$log"
printf '%s\n' "\$@" >> "$log"
exit 0
EOF
@@ -3207,7 +3666,7 @@ EOF
run "$REPO_ROOT/bin/dejima" "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
grep -qE '^SANDBOX_ANTHROPIC_PROXY_SOCKET=.+' "$log" \
grep -qE '^SANDBOX_CREDENTIAL_PROXY_SOCKET=.+' "$log" \
|| { echo "the proxy did not start:"; cat "$log"; return 1; }
grep -q -- "-v $RW_HOME/.claude/.credentials.json:" "$log" \
&& { echo "the real credential file was mounted"; return 1; }
@@ -3240,7 +3699,7 @@ EOF
stub="$(mktemp -d)"; log="$(mktemp)"
cat > "$stub/docker" <<EOF
#!/bin/sh
env | grep '^SANDBOX_ANTHROPIC' >> "$log"
env | grep -E '^SANDBOX_(ANTHROPIC|CREDENTIAL)' >> "$log"
printf '%s\n' "\$@" >> "$log"
exit 0
EOF
@@ -3364,7 +3823,7 @@ EOF
# as a copy - so the copy has to lose the key while the proxy gains it.
_console_launch
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
grep -qE '^SANDBOX_ANTHROPIC_PROXY_SOCKET=.+' "$CLOG" \
grep -qE '^SANDBOX_CREDENTIAL_PROXY_SOCKET=.+' "$CLOG" \
|| { echo "the proxy did not start:"; cat "$CLOG"; return 1; }
[ "$(jq -r '.primaryApiKey // "absent"' "$CSTAGED")" = "absent" ] \
|| { echo "the real key reached the container"; return 1; }
@@ -3390,7 +3849,7 @@ EOF
|| { echo "the downgrade did not deliver the credential"; return 1; }
[[ "$output" == *"proxy is off"* ]] || { echo "$output"; return 1; }
# And no proxy was started for it.
grep -qE '^SANDBOX_ANTHROPIC_PROXY_SOCKET=.+' "$CLOG" \
grep -qE '^SANDBOX_CREDENTIAL_PROXY_SOCKET=.+' "$CLOG" \
&& { echo "a proxy ran for a backend with proxy = off"; return 1; }
rm -rf "$workspace" "$CSTUB" "$CLOG" "$CSTAGED"
}
@@ -3791,3 +4250,175 @@ JSON
grep -q 'CANARY' <<< "$output" && { echo "a value leaked"; return 1; }
rm -rf "$d"
}
@test "the migration writes into the operator's existing section, not a second one" {
# Reported from a real launch: the config already had a
# [harness.claude-code] section, and dejima appended a second one holding
# only the migrated key. It parses, and it reads as a mistake dejima made
# in the operator's own file.
_rw_setup
workspace="$(mktemp -d)"
printf '[core]\nharness = claude-code\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.claude-code]\nprojects_dir = ~/.claude/projects\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[ "$(grep -c '^\[harness\.claude-code\]' "$CONFIG_DIR/config")" -eq 1 ] \
|| { echo "a second section was appended:"; cat "$CONFIG_DIR/config"; return 1; }
grep -qx 'backend = anthropic' "$CONFIG_DIR/config" \
|| { echo "the key was not written:"; cat "$CONFIG_DIR/config"; return 1; }
# The key the operator already had is untouched, and still in that section.
grep -qx 'projects_dir = ~/.claude/projects' "$CONFIG_DIR/config" \
|| { echo "an existing key was lost:"; cat "$CONFIG_DIR/config"; return 1; }
# And the file keeps its own permissions rather than a fresh temp file's.
[ "$(stat -c '%a' "$CONFIG_DIR/config")" = "$(stat -c '%a' "$RW_KEY")" ] \
|| echo "note: config mode is now $(stat -c '%a' "$CONFIG_DIR/config")"
rm -rf "$workspace"
}
@test "a key dejima moved says where it went, not just that it is unknown" {
# base_url left the harness for the backend in the provider axis. An
# operator who had it gets "unknown key", which is true and useless: it
# does not distinguish a typo from a move, and the answer is in a document
# they have no reason to think they need.
_rw_setup
printf '[core]\nharness = cline\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.cline]\nmodel = m\nbase_url = http://127.0.0.1:8080/v1\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
HOME="$RW_HOME" run "$REPO_ROOT/bin/dejima" --print-config
[ "$status" -ne 0 ] || { echo "an unknown key was accepted: $output"; return 1; }
[[ "$output" == *"unknown key"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"backend = self-hosted"* ]] \
|| { echo "it does not name where the key went: $output"; return 1; }
[[ "$output" == *"[backend.self-hosted]"* ]] \
|| { echo "it does not name the new section: $output"; return 1; }
}
@test "a long orphaned-share list is sampled, not printed whole" {
# Reported: ninety entries pushed everything about the run off the screen.
# It is a standing condition an operator clears once, so it gets a sample.
_rw_setup
workspace="$(mktemp -d)"
mkdir -p "$RW_HOME/share"
local i
for i in $(seq 1 31); do : > "$RW_HOME/share/leftover-$i.md"; done
write_config '[core]' "ssh_key = $RW_KEY" 'forge = none' 'workflow = local-only' \
'harness = claude-code' 'share_dir = ~/share'
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"no session can see any more"* ]] || { echo "$output"; return 1; }
[ "$(grep -c 'leftover-' <<< "$output")" -le 8 ] \
|| { echo "the whole list was printed:"; echo "$output"; return 1; }
[[ "$output" == *"and 23 more"* ]] \
|| { echo "it does not say how many were left out: $output"; return 1; }
rm -rf "$workspace"
}
@test "a notice pauses before the build output scrolls it away" {
# The positive half. Without it, the test below passes just as well when
# the pause does not exist at all - which is exactly how it read after an
# accidental revert wiped the feature and left its guard test green.
_rw_setup
workspace="$(mktemp -d)"
printf '[core]\nharness = claude-code\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.claude-code]\nbackend = anthropic\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
STUB_DIR="$(mktemp -d)"
printf '#!/bin/sh\necho BUILD-OUTPUT-STARTS\nexit 0\n' > "$STUB_DIR/docker"
chmod +x "$STUB_DIR/docker"
HOME="$RW_HOME" PATH="$STUB_DIR:$PATH" SSH_AUTH_SOCK= \
run python3 "$BATS_TEST_DIRNAME/fixtures/answer-prompt.py" \
--marker "Press Enter" "" -- "$REPO_ROOT/bin/dejima" "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"Press Enter to continue"* ]] \
|| { echo "no pause before the build: $output"; return 1; }
# And it is a pause, not a stop: the build runs once answered.
[[ "$output" == *"BUILD-OUTPUT-STARTS"* ]] \
|| { echo "answering did not continue: $output"; return 1; }
# The pause comes AFTER the notice, or it has not protected anything.
[[ "${output%%Press Enter*}" == *"ssh_key is deprecated"* ]] \
|| { echo "the pause came before the notice: $output"; return 1; }
rm -rf "$workspace" "$STUB_DIR"
}
@test "--no-pause reaches the prompt without a keypress, and still says it" {
# Starting eight sessions from a tmuxinator layout: every one has a
# terminal, so the pause fires on every one, and the operator wants them
# all at a prompt rather than eight keys to press. The notices still
# print - skipping the wait is not skipping the telling.
_rw_setup
workspace="$(mktemp -d)"
printf '[core]\nharness = claude-code\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.claude-code]\nbackend = anthropic\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
STUB_DIR="$(mktemp -d)"
printf '#!/bin/sh\necho BUILD-OUTPUT-STARTS\nexit 0\n' > "$STUB_DIR/docker"
chmod +x "$STUB_DIR/docker"
# A real terminal and NO answer: without the flag this would sit at the
# prompt until the fixture gave up and killed it.
HOME="$RW_HOME" PATH="$STUB_DIR:$PATH" SSH_AUTH_SOCK= \
run python3 "$BATS_TEST_DIRNAME/fixtures/answer-prompt.py" \
--marker "nothing-matches-this" -- \
"$REPO_ROOT/bin/dejima" --no-pause "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" != *"Press Enter"* ]] \
|| { echo "--no-pause still waited: $output"; return 1; }
[[ "$output" == *"BUILD-OUTPUT-STARTS"* ]] \
|| { echo "it never reached the build: $output"; return 1; }
# The notice is still printed; only the wait is skipped.
[[ "$output" == *"ssh_key is deprecated"* ]] \
|| { echo "--no-pause silenced the notice: $output"; return 1; }
# And it did not merely get killed for hanging.
[[ "$output" != *"never exited"* ]] || { echo "it hung: $output"; return 1; }
rm -rf "$workspace" "$STUB_DIR"
}
@test "an unattended launch never waits for a keystroke nobody will press" {
# The pause before the build exists so a notice can be read. With no
# terminal there is nobody to read it, and blocking would hang every
# scheduled or remote launch that has a deprecation set.
_rw_setup
workspace="$(mktemp -d)"
# [core] ssh_key is a deprecation, so a notice fires on this launch.
printf '[core]\nharness = claude-code\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.claude-code]\nbackend = anthropic\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
_rw_launch "$workspace"
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"ssh_key is deprecated"* ]] \
|| { echo "the fixture raised no notice: $output"; return 1; }
[[ "$output" != *"Press Enter"* ]] \
|| { echo "it waited for input with no terminal: $output"; return 1; }
rm -rf "$workspace"
}
@test "an invalid config reports its reason once, not once per parsing context" {
# The early validation runs suppressed and, on failure, used to drop the
# cache so the next caller would parse and report. The next caller is
# usually a subshell - $(config_get ...) - whose cache dies with it, so
# every parsing context reported the same problem. One line each was
# merely odd; a message with a hint under it printed twenty lines.
_rw_setup
printf '[core]\nharness = cline\nssh_key = %s\nforge = none\nworkflow = local-only\n[harness.cline]\nmodel = m\nbase_url = http://127.0.0.1:8080/v1\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
HOME="$RW_HOME" run "$REPO_ROOT/bin/dejima" --print-config
[ "$status" -ne 0 ] || { echo "an invalid config launched: $output"; return 1; }
[ "$(grep -c 'unknown key' <<< "$output")" -eq 1 ] \
|| { echo "reported $(grep -c 'unknown key' <<< "$output") times:"; echo "$output"; return 1; }
# And on the launch path, which parses in more places than --print-config.
workspace="$(mktemp -d)"
_rw_launch "$workspace"
[ "$status" -ne 0 ] || { echo "an invalid config launched: $output"; return 1; }
[ "$(grep -c 'unknown key' <<< "$output")" -eq 1 ] \
|| { echo "reported $(grep -c 'unknown key' <<< "$output") times:"; echo "$output"; return 1; }
rm -rf "$workspace"
}
@test "--help still answers when the config is invalid" {
# The fix above must not become an exit: flags are not parsed yet at that
# point, and someone whose config is broken is exactly who needs --help.
_rw_setup
printf '[core]\nharness = cline\nssh_key = %s\n[harness.cline]\nbase_url = x\n' \
"$RW_KEY" > "$CONFIG_DIR/config"
HOME="$RW_HOME" run "$REPO_ROOT/bin/dejima" --help
[ "$status" -eq 0 ] || { echo "--help failed on a broken config: $output"; return 1; }
[[ "$output" == *"dejima - run an agent harness"* ]] || { echo "$output"; return 1; }
}
+54 -4
View File
@@ -6,7 +6,7 @@ point - an unattended launch must not block on a question nobody will see. So
a test that drives the interactive path needs a pty rather than a pipe, or it
exercises the non-interactive branch while claiming to test the other one.
Usage: answer-prompt.py <answer-per-prompt>... -- <command> [args...]
Usage: answer-prompt.py [--marker TEXT] <answer-per-prompt>... -- <command> [args...]
Each answer is sent when the child writes a line ending in the prompt marker.
Everything the child wrote is printed on exit, and the child's exit status is
@@ -15,12 +15,27 @@ this program's.
import os
import pty
import signal
import re
import select
import sys
import time
# The default is the credential scan's prompt. --marker takes another, so a
# test for a different prompt does not need a second copy of this.
MARKER = "[s/a/o/r]"
TIMEOUT = 60.0
# dejima pauses before the image build when it printed a notice worth reading.
# That is not the prompt any test here is about - it is ambient, and every
# launch fixture that sets [core] ssh_key raises it - so it is answered
# automatically rather than costing every caller an extra argument.
AMBIENT = "Press Enter to continue"
# An IDLE timeout: how long to wait with no output before giving up. Generous
# because the thing it guards against is a command that never finishes, and
# any finite bound catches that - while a tight one just times the machine.
# Sixty seconds was enough on an idle box and not enough under the full gate,
# where every suite runs at once (#295).
TIMEOUT = 240.0
def main():
@@ -28,7 +43,13 @@ def main():
print("usage: answer-prompt.py <answer>... -- <command>...", file=sys.stderr)
return 2
split = sys.argv.index("--")
answers = list(sys.argv[1:split])
args = list(sys.argv[1:split])
global MARKER
if "--marker" in args:
i = args.index("--marker")
MARKER = args[i + 1]
del args[i:i + 2]
answers = args
command = sys.argv[split + 1:]
if not command:
print("no command given", file=sys.stderr)
@@ -64,11 +85,40 @@ def main():
# marker appearing inside prose does not consume an answer.
if pending and MARKER in text:
os.write(fd, (pending.pop(0) + "\n").encode())
elif AMBIENT in text and AMBIENT != MARKER:
os.write(fd, b"\n")
_, status = os.waitpid(pid, 0)
# The read loop ends when the child stops WRITING, which is not when it
# stops running: dejima does its exit audit and stops its shipper after
# the last thing it prints. So give it a grace period to finish before
# concluding anything - killing it there reported a child that was merely
# busy as a hang, and left it taking SIGPIPE on a pty nobody was reading.
#
# Only then kill, because an unanswered prompt is the other way this ends
# and waiting on that turns a failing test into a hung suite. The caller
# is told which it was.
stuck = False
status = 0
grace = time.time() + 60.0
try:
while True:
done, status = os.waitpid(pid, os.WNOHANG)
if done != 0:
break
if time.time() >= grace:
stuck = True
os.kill(pid, signal.SIGKILL)
_, status = os.waitpid(pid, 0)
break
time.sleep(0.1)
except OSError:
status = 0
sys.stdout.write("".join(out))
if pending:
sys.stdout.write("\n[answer-prompt: %d answer(s) never used]\n" % len(pending))
if stuck:
sys.stdout.write("\n[answer-prompt: the command never exited - killed. "
"It was probably waiting at a prompt nothing answered.]\n")
return os.waitstatus_to_exitcode(status) if hasattr(os, "waitstatus_to_exitcode") \
else (status >> 8)
+34
View File
@@ -6,6 +6,8 @@
# records the request body)
# GET /oauth-hits -> number of refresh calls so far (text/plain)
# GET /oauth-last -> JSON body of the most recent refresh request
# * /status-429 -> 429, chunked, retry-after: 41 (a rate limiter's shape)
# * /status-429-gzip -> the same, gzip-encoded (what a client asking for gzip gets)
# * /status-503 -> 503, body "upstream-error"
# * /echo-401-once -> 401 on the first call ever, then echoes
# GET /sse -> two SSE events 2s apart, no Content-Length
@@ -62,6 +64,38 @@ class Handler(BaseHTTPRequestHandler):
self._send(200, str(STATE["oauth_hits"]).encode(), "text/plain")
elif self.path == "/oauth-last":
self._send(200, json.dumps(STATE["oauth_last"]).encode())
elif self.path == "/status-429-gzip":
# gzip + chunked + retry-after: what a rate limiter answers a
# client that asked for gzip, which every Node harness does. The
# proxy forwards the client's Accept-Encoding verbatim, so this is
# the shape it actually meets - and the first version wrote those
# bytes to the operator's terminal.
import gzip as _gzip
b = _gzip.compress(
b'{"type":"error","error":{"type":"rate_limit_error","message":"slow down"}}')
self.send_response(429)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Encoding", "gzip")
self.send_header("retry-after", "41")
self.send_header("Transfer-Encoding", "chunked")
self.end_headers()
self.wfile.write(b"%x\r\n" % len(b) + b + b"\r\n0\r\n\r\n")
elif self.path == "/status-429":
# Chunked, with no Content-Length, and a retry-after - the framing
# a rate limiter actually uses, and the one the proxy's first
# attempt at logging could not read a body out of.
self.send_response(429)
self.send_header("Content-Type", "application/json")
self.send_header("retry-after", "41")
self.send_header("request-id", "req_011CehAZUPXFbQGikXfM3Mp6")
# The ids a real response also carries, so the test that they stay
# out of the log has something to stay out of.
self.send_header("anthropic-organization-id", "e528bbab-dead-beef")
self.send_header("anthropic-workspace-id", "wrkspc_01MpMcAs9xg5")
self.send_header("Transfer-Encoding", "chunked")
self.end_headers()
b = b'{"type":"error","error":{"type":"rate_limit_error","message":"slow down"}}'
self.wfile.write(b"%x\r\n" % len(b) + b + b"\r\n0\r\n\r\n")
elif self.path == "/status-503":
self._send(503, b"upstream-error", "text/plain")
elif self.path == "/echo-401-once":
+26 -5
View File
@@ -276,6 +276,28 @@ def received():
return b""
def await_received(predicate, timeout=15.0):
"""Wait for what the container received to satisfy predicate.
The third instance of the same bug in this file - see await_raw and the
reclaim wait above. A byte written to the master pty has to reach the
client, cross into the container's stand-in and be appended to a file
before the check can see it, and pumping for a fixed 0.8s and then looking
was timing the machine rather than waiting for the thing. It failed in CI
exactly that way: the check for ^C saw the tail of the line typed before
it, because ^C had not arrived yet.
Returns the predicate's answer either way, so a real failure still fails
rather than hanging until the suite's own timeout.
"""
end = time.time() + timeout
while time.time() < end:
if predicate(received()):
return True
pump(0.05)
return predicate(received())
def check(name, ok, detail=""):
print(("PASS " + name) if ok else ("FAIL %s %s" % (name, detail)))
if not ok:
@@ -332,13 +354,12 @@ try:
before = received()
send("typed\n")
pump(0.8)
check("input-reaches-the-resumed-session", received() != before)
check("input-reaches-the-resumed-session",
await_received(lambda got: got != before))
before = received()
send("\x03")
pump(0.8)
check("ctrl-c-still-reaches-the-session", received().endswith(b"\x03"),
check("ctrl-c-still-reaches-the-session",
await_received(lambda got: got.endswith(b"\x03")),
repr(received()[-4:]))
# The finding, asserted: the client is stopped by SIGSTOP, which it cannot
+382
View File
@@ -0,0 +1,382 @@
#!/usr/bin/env bats
# How a launch is arranged: the containers it starts, in what order, on what
# network, and what it takes down again.
#
# The subject is bin/dejima's side of the filter container - the extra
# container per launch that owns the network namespace and the packet filter,
# which the sandbox joins and has no capability to alter. Whether the filter
# actually filters is runtime.bats's question and needs a real Docker; whether
# the launcher builds the arrangement that puts one there is this file's, and
# needs only a stub.
#
# Everything here runs against a `docker` that records its argv and exits 0, so
# a launch completes without a daemon. That makes the ORDER of the calls, and
# the flags on each, the thing being asserted.
setup() {
REPO_ROOT="$BATS_TEST_DIRNAME/.."
SANDBOX_DIR="$REPO_ROOT/docker"
LIB="$REPO_ROOT/bin/dejima-project-lib.sh"
CONFIG_DIR="$(mktemp -d)"
RUNTIME_DIR="$(mktemp -d)"
export DEJIMA_CONFIG_DIR="$CONFIG_DIR"
export XDG_RUNTIME_DIR="$RUNTIME_DIR"
}
teardown() {
rm -rf "$CONFIG_DIR" "$RUNTIME_DIR" ${LAUNCH_DIR:+"$LAUNCH_DIR"} ${PROJ:+"$PROJ"}
}
# A `docker` that logs one line per invocation and succeeds at everything,
# including the readiness probe. Tests that need a failure override it.
stub_launch() {
LAUNCH_DIR="$(mktemp -d)"
mkdir -p "$LAUNCH_DIR/home/.claude"
echo '{}' > "$LAUNCH_DIR/home/.claude/settings.json"
cat > "$LAUNCH_DIR/docker" <<'EOF'
#!/bin/bash
echo "$*" >> "${SANDBOX_TEST_DOCKER_LOG:-/dev/null}"
exit 0
EOF
chmod +x "$LAUNCH_DIR/docker"
: > "$LAUNCH_DIR/sandbox-key"
chmod 600 "$LAUNCH_DIR/sandbox-key"
PROJ="$(mktemp -d)"
}
launch() {
local conf
conf="$(bash -c 'source "$1"; config_path' _ "$LIB")"
mkdir -p "$(dirname "$conf")"
printf '[core]\nharness = claude-code\nupdate_check = off\nssh_key = %s\n' \
"$LAUNCH_DIR/sandbox-key" >> "$conf"
HOME="$LAUNCH_DIR/home" PATH="$LAUNCH_DIR:$PATH" \
SANDBOX_TEST_DOCKER_LOG="$LAUNCH_DIR/docker-log" \
SSH_AUTH_SOCK= ALLOWED_DOMAINS= \
"${DEJIMA_BIN:-$REPO_ROOT/bin/dejima}" "$@"
}
log_line() { grep -- "$1" "$LAUNCH_DIR/docker-log" | tail -1; }
# 1-indexed position of the last line matching a pattern, for ordering claims.
log_pos() { grep -n -- "$1" "$LAUNCH_DIR/docker-log" | tail -1 | cut -d: -f1; }
@test "a launch creates a network of its own and a filter container on it" {
stub_launch
launch "$PROJ"
local net; net="$(log_line 'network create')"
[ -n "$net" ] || { echo "no network was created"; return 1; }
[[ "$net" =~ dejima-run-[0-9a-f]{16} ]] \
|| { echo "the network is not named for this run: $net"; return 1; }
[[ "$net" == *"--label dejima.run="* ]] \
|| { echo "the network carries no run label, so nothing can reconcile it: $net"; return 1; }
local run; run="$(log_line 'run -d --init')"
[ -n "$run" ] || { echo "no filter container was started"; return 1; }
[[ "$run" =~ --name\ dejima-filter-[0-9a-f]{16} ]] \
|| { echo "the filter container is not named for this run: $run"; return 1; }
[[ "$run" == *"--entrypoint /usr/local/bin/filter-entrypoint.sh"* ]] \
|| { echo "the filter container does not run the filter entrypoint: $run"; return 1; }
# One network per launch, and the filter container on that one - not on
# whatever bridge Docker would have picked. dns-proxy.sh forwards to the
# embedded resolver at 127.0.0.11, which only exists on a user-defined
# network, so this is load-bearing rather than tidiness.
local id; id="$(sed -E 's/.*dejima-run-([0-9a-f]{16}).*/\1/' <<< "$net")"
[[ "$run" == *"--network dejima-run-$id"* ]] \
|| { echo "the filter container is not on this launch's network: $run"; return 1; }
}
@test "the sandbox joins the filter container's namespace rather than getting one" {
stub_launch
launch "$PROJ"
# The compose file is what carries it, from an environment variable the
# launcher exports - so both halves are asserted. Either alone passes on an
# arrangement where the session still has a network of its own.
grep -qE '^\s*network_mode: \$\{SANDBOX_NETNS_CONTAINER' "$SANDBOX_DIR/docker-compose.yml" \
|| { echo "the compose file does not join a namespace"; return 1; }
# And what it falls back to when nothing supplies one. Only a `docker
# compose` invocation by hand reaches this, but a default naming a real
# network is a sandbox that comes up working with unfiltered egress, and
# nothing about it looks wrong. `none` fails the same case visibly.
grep -qE '^\s*network_mode: \$\{SANDBOX_NETNS_CONTAINER:-none\}\s*$' \
"$SANDBOX_DIR/docker-compose.yml" \
|| { echo "the network_mode default is not fail-closed"; return 1; }
local run; run="$(log_line 'run -d --init')"
local id; id="$(sed -E 's/.*--name dejima-filter-([0-9a-f]{16}).*/\1/' <<< "$run")"
[ -n "$id" ]
run grep -c "SANDBOX_NETNS_CONTAINER" "$REPO_ROOT/bin/dejima"
[ "$status" -eq 0 ]
grep -q 'export SANDBOX_NETNS_CONTAINER="container:\$SANDBOX_FILTER_CONTAINER"' \
"$REPO_ROOT/bin/dejima" \
|| { echo "the launcher does not point the sandbox at the filter container"; return 1; }
}
@test "the filter container comes up before the session, not beside it" {
# The ordering IS the control. A namespace that gets its rules after
# something is already running in it has a window where a session holds an
# interface and no filter, which is what this arrangement exists to remove
# by construction rather than to bound by argument.
stub_launch
launch "$PROJ"
local net_at filter_at ready_at session_at
net_at="$(log_pos 'network create')"
filter_at="$(log_pos 'run -d --init')"
ready_at="$(log_pos 'dejima-firewall-ready')"
session_at="$(log_pos ' run --rm ')"
[ -n "$net_at" ] && [ -n "$filter_at" ] && [ -n "$ready_at" ] && [ -n "$session_at" ] \
|| { echo "one of the four steps never happened"; cat "$LAUNCH_DIR/docker-log"; return 1; }
[ "$net_at" -lt "$filter_at" ] \
|| { echo "the filter container started before its network existed"; return 1; }
[ "$filter_at" -lt "$ready_at" ] \
|| { echo "readiness was probed before the filter container was started"; return 1; }
[ "$ready_at" -lt "$session_at" ] \
|| { echo "the session started before the filter was confirmed up"; return 1; }
}
@test "a filter container that never comes up refuses the launch" {
# The failure this is really about is the quiet one: a launcher that waited,
# gave up, and started the session anyway would produce a working sandbox
# with no egress control, and nothing downstream would notice.
stub_launch
cat > "$LAUNCH_DIR/docker" <<'EOF'
#!/bin/bash
echo "$*" >> "${SANDBOX_TEST_DOCKER_LOG:-/dev/null}"
case "$*" in
# The marker never appears, and the container is reported gone - which is
# what a firewall that refused to start leaves behind.
*dejima-firewall-ready*) exit 1 ;;
*inspect*State.Running*) echo false; exit 0 ;;
*logs*) echo "init-firewall.sh: DNS lookup for registry.npmjs.org failed"; exit 0 ;;
esac
exit 0
EOF
chmod +x "$LAUNCH_DIR/docker"
run launch "$PROJ"
[ "$status" -ne 0 ] \
|| { echo "the launch succeeded with no egress control"; return 1; }
[[ "$output" == *"did not come up"* ]] \
|| { echo "it refused without saying why: $output"; return 1; }
# And it hands over what the filter container said, or the operator is left
# with a refusal and nowhere to look.
[[ "$output" == *"registry.npmjs.org"* ]] \
|| { echo "the refusal does not carry the filter container's own output: $output"; return 1; }
run grep -c -- ' run --rm ' "$LAUNCH_DIR/docker-log"
[ "$output" = "0" ] \
|| { echo "the session was started anyway"; return 1; }
}
@test "the launch takes its own container and network down again" {
stub_launch
launch "$PROJ"
local run id
run="$(log_line 'run -d --init')"
id="$(sed -E 's/.*--name dejima-filter-([0-9a-f]{16}).*/\1/' <<< "$run")"
[ -n "$id" ]
grep -q -- "rm -f dejima-filter-$id" "$LAUNCH_DIR/docker-log" \
|| { echo "the filter container was left running"; return 1; }
grep -q -- "network rm dejima-run-$id" "$LAUNCH_DIR/docker-log" \
|| { echo "the network was left behind"; return 1; }
# After the session, not before it. Docker permits removing a namespace
# owner from under a live joiner, so this order is the launcher's to keep.
local session_at rm_at
session_at="$(log_pos ' run --rm ')"
rm_at="$(log_pos "rm -f dejima-filter-$id")"
[ "$session_at" -lt "$rm_at" ] \
|| { echo "the filter container was removed before the session ran"; return 1; }
}
@test "the filter container runs the base image, never a project's derived one" {
# It is the privileged half of the pair. A project's declared dependencies
# are installed into the derived image for the session to use, and there is
# no reason for any of them to be present in the container holding
# NET_ADMIN.
stub_launch
launch "$PROJ"
local run; run="$(log_line 'run -d --init')"
[[ "$run" =~ localhost/dejima:[^[:space:]-]+$ ]] \
|| { echo "the filter container's image is not the plain base tag: $run"; return 1; }
}
@test "the filter container declares the network capabilities and drops the rest" {
stub_launch
launch "$PROJ"
local run; run="$(log_line 'run -d --init')"
[[ "$run" == *"--cap-drop ALL"* ]] \
|| { echo "the filter container keeps Docker's default set: $run"; return 1; }
[[ "$run" == *"--security-opt no-new-privileges:true"* ]] \
|| { echo "no-new-privileges is missing from the filter container: $run"; return 1; }
local cap
for cap in NET_ADMIN NET_RAW KILL SETPCAP; do
[[ "$run" == *"--cap-add $cap"* ]] \
|| { echo "the filter container cannot do its job without $cap: $run"; return 1; }
done
}
@test "every variable the firewall path reads is passed to the filter container" {
# The drift guard this arrangement needs most. The sandbox gets its
# environment from docker-compose.yml; the filter container is started with
# `docker run` and gets nothing that is not named on that command line.
#
# So a firewall script that starts reading a new variable does not fail - it
# reads an empty one, and allowlists less than it was told to, which
# presents as a domain the operator approved being unreachable rather than
# as anything about this. Derived from the scripts rather than listed here,
# so the test cannot drift from them either.
stub_launch
launch "$PROJ"
local run; run="$(log_line 'run -d --init')"
[ -n "$run" ]
local v missing=""
while read -r v; do
[ -n "$v" ] || continue
[[ "$run" == *"-e $v"* ]] || missing="$missing $v"
done < <(cat "$SANDBOX_DIR/firewall-up.sh" "$SANDBOX_DIR/dns-proxy.sh" \
"$SANDBOX_DIR/init-firewall.sh" "$SANDBOX_DIR/fixed-domains.sh" \
"$SANDBOX_DIR/log-shipper.sh" \
| grep -oE '\$\{?(ALLOW[A-Z_]*|DEJIMA_[A-Z_]*|ENABLE_[A-Z_]*|GH_TOKEN|LOKI_URL|SANDBOX_[A-Z_]*)' \
| tr -d '${' | sort -u \
| grep -vE '^(EXTRA_ALLOWED_DOMAINS|SANDBOX_TEST.*)$')
[ -z "$missing" ] \
|| { echo "the firewall path reads these, and the filter container is not given them:$missing"; return 1; }
# And the other half of the same failure, which the flag alone cannot show.
# `docker run -e NAME` takes the value from the launcher's environment, so
# a name that is assigned but never exported passes an empty one - the
# filter container then allowlists less than it was told to, and what an
# operator sees is a domain they approved being unreachable, with nothing
# pointing here.
#
# Not hypothetical: `export DEJIMA_FORGE_HOSTS` is a line that had to be
# added by hand when the filter container was introduced, because until
# then that variable had only ever needed to reach the sandbox as
# `-e NAME=value`, which carries its own value.
#
# Continuations are flattened first, because the exports here run to
# several lines; and `export` is matched anywhere on a line rather than at
# its start, because two of these are exported after a `;` on the line that
# assigns them.
local exported unexported=""
exported="$(sed -z 's/\\\n[[:space:]]*/ /g' "$REPO_ROOT/bin/dejima" \
| grep -oE 'export [A-Za-z_][A-Za-z0-9_ ]*')"
[ -n "$exported" ] || { echo "found no exports in bin/dejima at all"; return 1; }
while read -r v; do
[ -n "$v" ] || continue
grep -qE "(^|[[:space:]])$v([[:space:]]|\$)" <<< "$exported" \
|| unexported="$unexported $v"
done < <(grep -oE '^\s+-e [A-Z_]+' "$REPO_ROOT/bin/dejima" | awk '{print $2}' | sort -u)
[ -z "$unexported" ] \
|| { echo "passed as -e NAME but never exported, so the value is empty:$unexported"; return 1; }
}
# A `docker` that reports one filter container and one network, with whatever
# age, joiner and identity a test needs, and records every removal.
#
# Each of these tests is about a branch that decides NOT to remove something,
# and a reconciler that removed nothing at all would pass every one of them -
# so the first test here is the one that proves the mechanism fires.
stub_orphan() { # <age-seconds> <joined-by|"">
local age="$1" joiner="$2"
stub_launch
# Each query answers in the format Docker really answers it in, and the two
# differ: `Created` is a string field on a container and a time.Time on a
# network, so a template prints the second through String() and appends a
# timezone NAME. One format for both is what let the network half of the
# reconciler pass a test while reaping nothing.
cat > "$LAUNCH_DIR/docker" <<EOF
#!/bin/bash
echo "\$*" >> "\${SANDBOX_TEST_DOCKER_LOG:-/dev/null}"
epoch=\$(( \$(date +%s) - $age ))
made=\$(date -u -d "@\$epoch" +%Y-%m-%dT%H:%M:%S.000000000Z)
made_go=\$(date -u -d "@\$epoch" '+%Y-%m-%d %H:%M:%S.000000000 +0000 UTC')
case "\$*" in
# The running containers, and what namespace each is in.
"ps -q") [ -n "$joiner" ] && echo j0 ; exit 0 ;;
*HostConfig.NetworkMode*) [ -n "$joiner" ] && echo "container:$joiner" ; exit 0 ;;
# The candidates.
*"ps -aq --filter label=dejima.filter"*) echo orphan0 ; exit 0 ;;
*"{{.Id}} {{.Name}} {{.Created}}"*) echo "orphan0 /dejima-filter-old \$made" ; exit 0 ;;
*"network ls -q --filter label=dejima.run"*) echo net0 ; exit 0 ;;
*"{{.Name}} {{.Created}}"*) echo "dejima-run-old \$made_go" ; exit 0 ;;
esac
exit 0
EOF
chmod +x "$LAUNCH_DIR/docker"
}
@test "a filter container nothing is joined to, left over from before, is removed" {
stub_orphan 6000 ""
launch "$PROJ"
grep -q -- 'rm -f orphan0' "$LAUNCH_DIR/docker-log" \
|| { echo "the orphaned filter container was left running"; return 1; }
grep -q -- 'network rm dejima-run-old' "$LAUNCH_DIR/docker-log" \
|| { echo "its network was left behind"; return 1; }
}
@test "the reconcile says what it removed, so a leak is not silently routine" {
stub_orphan 6000 ""
run launch "$PROJ"
[[ "$output" == *"left behind"* ]] \
|| { echo "an orphan was removed with nothing said about it: $output"; return 1; }
}
@test "a filter container with a session still in its namespace is left alone" {
# The one that matters on a host running several sessions: reaping this is
# taking the network out from under somebody's running agent.
stub_orphan 6000 orphan0
launch "$PROJ"
run grep -c -- 'rm -f orphan0' "$LAUNCH_DIR/docker-log"
[ "$output" = "0" ] \
|| { echo "a filter container with a live session was removed"; return 1; }
}
@test "a filter container younger than the grace is left alone" {
# A pair being built right now by a concurrent launch: between `docker run`
# for the filter and `docker compose run` for the session, a healthy filter
# container has no joiner. Age is what tells that apart from abandonment.
stub_orphan 5 ""
launch "$PROJ"
run grep -c -- 'rm -f orphan0' "$LAUNCH_DIR/docker-log"
[ "$output" = "0" ] \
|| { echo "a filter container still being paired was removed"; return 1; }
run grep -c -- 'network rm dejima-run-old' "$LAUNCH_DIR/docker-log"
[ "$output" = "0" ] \
|| { echo "a network still being attached to was removed"; return 1; }
}
@test "a docker that cannot answer the reconcile does not fail the launch" {
# It runs before the launch's own network and container, so an error here
# would refuse a session over tidying up. The launch that follows reports
# its own failures.
stub_launch
cat > "$LAUNCH_DIR/docker" <<'EOF'
#!/bin/bash
echo "$*" >> "${SANDBOX_TEST_DOCKER_LOG:-/dev/null}"
case "$*" in
ps*|*inspect*|*network\ ls*) echo "Cannot connect to the Docker daemon" >&2; exit 1 ;;
esac
exit 0
EOF
chmod +x "$LAUNCH_DIR/docker"
run launch "$PROJ"
[ "$status" -eq 0 ] \
|| { echo "a failing reconcile refused the launch: $output"; return 1; }
grep -q -- ' run --rm ' "$LAUNCH_DIR/docker-log" \
|| { echo "the session never started"; return 1; }
}
+75 -1
View File
@@ -31,6 +31,11 @@ if [ "\$1" = ps ]; then
exit 0
fi
case "\$*" in
# A session container shares a filter container's network namespace, and
# that is where the dnsmasq and the ipsets are. dejima-allow derives the
# one from the other rather than being told, so a stub that answers this
# with nothing is a session with no filter to add a domain to.
*inspect*NetworkMode*) echo "container:dejima-test-filter"; exit 0 ;;
*dig*) echo 10.0.0.1; exit 0 ;;
*curl*) exit $2 ;;
*) exit 0 ;;
@@ -651,6 +656,66 @@ EOF
grep -qx 'crates.io' "$(store_of "$PROJ")/allowed-domains"
}
@test "dejima-allow takes the filter container's id, which is what a session reads" {
# A session asked for its own container id runs `cat /etc/hostname`, and
# Docker names a container that joined another's network namespace after
# the container it joined - so the id an agent hands its operator is the
# FILTER container's. That id has to work, or the one command every
# briefing tells an agent to ask for fails on the id the briefing gave it.
STUB_DIR="$(mktemp -d)"
cat > "$STUB_DIR/docker" <<'EOF'
#!/bin/bash
echo "$*" >> "${DOCKER_CALL_LOG:-/dev/null}"
case "$*" in
# Named container is a filter: it owns a network rather than joining one.
*inspect*NetworkMode*c1*) echo "dejima-run-abcd" ;;
*inspect*'{{.Id}}'*c1*) echo "filterid" ;;
# And one running container is in its namespace.
"ps -q") echo sessionid ;;
*'{{.Id}} {{.HostConfig.NetworkMode}}'*) echo "sessionid container:filterid" ;;
*dig*) echo 10.0.0.1 ;;
esac
exit 0
EOF
chmod +x "$STUB_DIR/docker"
PATH="$STUB_DIR:$PATH" DOCKER_CALL_LOG="$STUB_DIR/calls" \
run "$REPO_ROOT/bin/dejima-allow" --container c1 crates.io
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
# Asserted on the calls rather than the messages: which container each
# half runs in is the whole point, and a message could name either while
# the exec went to the wrong one.
grep -q 'exec -u root c1 ipset add' "$STUB_DIR/calls" \
|| { echo "the ipset add did not go to the filter container:"; cat "$STUB_DIR/calls"; return 1; }
grep -q 'exec sessionid curl' "$STUB_DIR/calls" \
|| { echo "the probe did not run in the session container:"; cat "$STUB_DIR/calls"; return 1; }
rm -rf "$STUB_DIR"
}
@test "dejima-allow refuses a container that is neither half of a pair" {
# A launch predating the split has a namespace of its own and no filter
# container in it. The useful answer is what to do instead, not a docker
# exec that fails somewhere inside a heredoc.
STUB_DIR="$(mktemp -d)"
cat > "$STUB_DIR/docker" <<'EOF'
#!/bin/bash
case "$*" in
*inspect*NetworkMode*) echo "bridge"; exit 0 ;;
*inspect*'{{.Id}}'*) echo "loneid"; exit 0 ;;
"ps -q") exit 0 ;;
esac
exit 0
EOF
chmod +x "$STUB_DIR/docker"
PATH="$STUB_DIR:$PATH" run "$REPO_ROOT/bin/dejima-allow" --container c1 crates.io
[ "$status" -ne 0 ]
[[ "$output" == *"neither a running session nor the filter container"* ]] \
|| { echo "$output"; return 1; }
[[ "$output" == *"dejima-allow --project crates.io"* ]] \
|| { echo "the refusal does not say what to do instead: $output"; return 1; }
rm -rf "$STUB_DIR"
}
@test "dejima-allow --global persists without needing a container" {
run "$REPO_ROOT/bin/dejima-allow" --global example.com
[ "$status" -eq 0 ]
@@ -704,6 +769,7 @@ stub_docker_rebind() {
cat > "$STUB_DIR/docker" <<'EOF'
#!/bin/bash
case "$*" in
*inspect*NetworkMode*) echo "container:dejima-test-filter"; exit 0 ;;
*dig*@127.0.0.11*) echo 10.0.0.1 ;;
esac
exit 0
@@ -737,7 +803,15 @@ EOF
# The rebind branch above must not swallow the ordinary failure: a typo'd
# or dead name gets no answer from the upstream either.
STUB_DIR="$(mktemp -d)"
printf '#!/bin/bash\nexit 0\n' > "$STUB_DIR/docker"
# Answers where the filter container is and nothing else, so every lookup
# comes back empty - which is the case this is about.
cat > "$STUB_DIR/docker" <<'EOF'
#!/bin/bash
case "$*" in
*inspect*NetworkMode*) echo "container:dejima-test-filter" ;;
esac
exit 0
EOF
chmod +x "$STUB_DIR/docker"
run env PATH="$STUB_DIR:$PATH" \
"$REPO_ROOT/bin/dejima-allow" --container c1 nowhere.example.com
+197 -11
View File
@@ -292,8 +292,8 @@ teardown() {
@test "forwarder bridges TCP to the proxy's unix socket" {
start_proxy
SANDBOX_ANTHROPIC_PROXY_SOCKET="$SOCK" SANDBOX_ANTHROPIC_PROXY_PORT=18399 \
SANDBOX_ANTHROPIC_TRANSPORT=loopback \
SANDBOX_CREDENTIAL_PROXY_SOCKET="$SOCK" SANDBOX_CREDENTIAL_PROXY_PORT=18399 \
SANDBOX_CREDENTIAL_TRANSPORT=loopback \
node "$REPO_ROOT/docker/credential-proxy-forwarder.js" &
FWD_PID=$!
ok=""
@@ -358,11 +358,11 @@ PYEOF
# ANTHROPIC_BASE_URL at all, then pipes raw bytes into the same unix socket
# the loopback mode uses - the host proxy cannot tell the two apart.
start_forwarder() { # start_forwarder <transport> <port>; extra env passes through
SANDBOX_ANTHROPIC_PROXY_SOCKET="$SOCK" \
SANDBOX_ANTHROPIC_TRANSPORT="$1" \
SANDBOX_ANTHROPIC_PROXY_PORT="$2" \
SANDBOX_ANTHROPIC_TLS_CERT="$TD/cert.pem" \
SANDBOX_ANTHROPIC_TLS_KEY="$TD/key.pem" \
SANDBOX_CREDENTIAL_PROXY_SOCKET="$SOCK" \
SANDBOX_CREDENTIAL_TRANSPORT="$1" \
SANDBOX_CREDENTIAL_PROXY_PORT="$2" \
SANDBOX_CREDENTIAL_TLS_CERT="$TD/cert.pem" \
SANDBOX_CREDENTIAL_TLS_KEY="$TD/key.pem" \
node "$REPO_ROOT/docker/credential-proxy-forwarder.js" 2>"$TD/fwd-stderr" &
FWD_PID=$!
for _ in $(seq 1 50); do
@@ -435,12 +435,12 @@ make_cert() {
#
# The port override is belt-and-braces: the cert check precedes the listen
# today, so a fall-through lands on an unused port if that ever changes.
run env -u SANDBOX_ANTHROPIC_TLS_CERT -u SANDBOX_ANTHROPIC_TLS_KEY \
SANDBOX_ANTHROPIC_PROXY_SOCKET="$SOCK" SANDBOX_ANTHROPIC_TRANSPORT=tls \
SANDBOX_ANTHROPIC_PROXY_PORT=18398 \
run env -u SANDBOX_CREDENTIAL_TLS_CERT -u SANDBOX_CREDENTIAL_TLS_KEY \
SANDBOX_CREDENTIAL_PROXY_SOCKET="$SOCK" SANDBOX_CREDENTIAL_TRANSPORT=tls \
SANDBOX_CREDENTIAL_PROXY_PORT=18398 \
node "$REPO_ROOT/docker/credential-proxy-forwarder.js"
[ "$status" -ne 0 ]
[[ "$output" == *"SANDBOX_ANTHROPIC_TLS_CERT"* ]]
[[ "$output" == *"SANDBOX_CREDENTIAL_TLS_CERT"* ]]
}
@test "an oversized request body is refused rather than read into host RAM" {
@@ -630,3 +630,189 @@ start_static() {
[[ "$output" == *"oauth-endpoint"* ]]
[ ! -S "$SOCK" ]
}
# The proxy is the only thing that sees both the request the session made and
# the answer the API gave. It forwarded a rejection verbatim and recorded
# nothing, so a session that spun and then errored left the operator with
# nothing to act on - reported from a real cline launch against the anthropic
# backend.
@test "an upstream rejection is recorded, and still reaches the session whole" {
start_proxy --log "$TD/proxy.log"
run pcurl -i "http://localhost/status-503"
[ "$status" -eq 0 ]
# /status-503 answers without a Content-Length. The first version read the
# body only where upstream declared a small one, and the first real
# rejection it met - a rate limiter - recorded the status and nothing
# else, which is the half an operator cannot act on.
# Byte for byte: what the session sees is what the API said, not the
# proxy's summary of it.
[[ "$output" == *"503"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"upstream-error"* ]] \
|| { echo "the body did not reach the client: $output"; return 1; }
[ -s "$TD/proxy.log" ] || { echo "nothing was recorded"; return 1; }
grep -q '503' "$TD/proxy.log" || { echo "$(cat "$TD/proxy.log")"; return 1; }
grep -q 'upstream-error' "$TD/proxy.log" \
|| { echo "recorded the status without the reason: $(cat "$TD/proxy.log")"; return 1; }
}
@test "a request the API accepted records nothing at all" {
# The success path must stay silent, and must not read the body to decide:
# logging every request would put the operator's traffic in a file and
# would buffer a streaming response to do it.
start_proxy --log "$TD/proxy.log"
run pcurl "http://localhost/v1/messages" -d '{"model":"x"}'
[ "$status" -eq 0 ]
[ ! -s "$TD/proxy.log" ] \
|| { echo "a successful request was logged: $(cat "$TD/proxy.log")"; return 1; }
}
@test "with no log file the diagnostics still go somewhere" {
# A proxy run by hand has no file to read afterwards, so stderr is right
# there. Losing the message because no --log was passed would make the
# by-hand case the one with no diagnostics.
start_proxy
run pcurl "http://localhost/status-503"
[ "$status" -eq 0 ]
grep -q '503' "$TD/stderr" \
|| { echo "nothing on stderr: $(cat "$TD/stderr")"; return 1; }
}
@test "a rate limiter's retry-after is named, not left among the headers" {
# Three 429s four seconds apart is what a real launch produced, and the
# actionable part of one is not in the body.
start_proxy --log "$TD/proxy.log"
run pcurl -i "http://localhost/status-429"
[ "$status" -eq 0 ]
grep -q 'retry-after=41' "$TD/proxy.log" \
|| { echo "$(cat "$TD/proxy.log")"; return 1; }
# The identifier Anthropic support asks for. A real rate-limited call came
# back with a body of {"message":"Error"} - the word Error and nothing
# else - so on that response this is the only actionable thing there is.
grep -q 'request-id=req_011CehAZUPXFbQGikXfM3Mp6' "$TD/proxy.log" \
|| { echo "no request id: $(cat "$TD/proxy.log")"; return 1; }
# And not the ids that name the operator's org. This line gets pasted
# into bug reports.
grep -qi 'workspace\|organization' "$TD/proxy.log" \
&& { echo "an account identifier reached the log"; return 1; }
grep -q 'rate_limit_error' "$TD/proxy.log" \
|| { echo "the body did not reach the log: $(cat "$TD/proxy.log")"; return 1; }
# And the client still gets both.
[[ "$output" == *"retry-after: 41"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"rate_limit_error"* ]] || { echo "$output"; return 1; }
}
@test "a compressed rejection is logged as text, not as bytes" {
# The client's own Accept-Encoding is forwarded verbatim, so a harness
# that asks for gzip gets a compressed error body - and the first version
# of this logging wrote those bytes out, which reached the operator as
# mojibake and a bash warning about a null byte in a command
# substitution. Reported from a real launch.
start_proxy --log "$TD/proxy.log"
run pcurl -i --compressed "http://localhost/status-429-gzip"
[ "$status" -eq 0 ]
grep -q 'slow down' "$TD/proxy.log" \
|| { echo "the message did not survive decompression: $(cat "$TD/proxy.log")"; return 1; }
# Nothing unprintable reaches the file at all. This is the half that has
# to hold whatever the encoding: upstream text landing on the operator's
# terminal is what dejima-audit already refuses to do unescaped.
[ -z "$(tr -d '\11\12\15\40-\176' < "$TD/proxy.log")" ] \
|| { echo "unprintable bytes reached the log"; od -c "$TD/proxy.log" | head -3; return 1; }
# And the client still received the compressed bytes untouched.
[[ "$output" == *"slow down"* ]] || { echo "$output"; return 1; }
}
@test "an encoding the stdlib cannot read says so rather than printing bytes" {
# br and zstd have no stdlib decoder. Naming the encoding is more use than
# the bytes, and the bytes are the thing this exists to keep off a
# terminal.
run python3 -c '
import sys; sys.path.insert(0, "'"$REPO_ROOT"'/bin")
import importlib.util, importlib.machinery
# The proxy has no .py suffix, so the loader has to be named rather than
# inferred from the extension.
loader = importlib.machinery.SourceFileLoader("p", "'"$REPO_ROOT"'/bin/dejima-credential-proxy")
spec = importlib.util.spec_from_loader("p", loader)
m = importlib.util.module_from_spec(spec); loader.exec_module(m)
print(m._readable(b"\x1f\x8b\x00\x01\x02", "br"))
print(m._readable(b"\x00\x01\x02not gzip at all", "gzip"))
print(m._readable(b"plain \x00\x07text", ""))
'
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"br-encoded"* ]] || { echo "$output"; return 1; }
[[ "$output" == *"undecodable"* ]] || { echo "$output"; return 1; }
# Control characters become spaces rather than being dropped, so a
# message is not silently re-joined into a different one. The exact run
# length is not the point; that none of them survives is.
[[ "$output" == *"plain"*"text"* ]] || { echo "$output"; return 1; }
}
@test "brotli is read when the host can, and named when it cannot" {
# What a Node client actually negotiates. gzip was the first guess and
# the real one came back br - so the encoding this could not read was the
# common case, not an edge.
#
# Optional on purpose: this runs on the host as the operator, and a
# diagnostic is not worth a hard dependency. So the test asserts whichever
# half this host can demonstrate, and the note has to name the fix.
run python3 -c '
import sys, importlib.util, importlib.machinery
l = importlib.machinery.SourceFileLoader("p", "'"$REPO_ROOT"'/bin/dejima-credential-proxy")
m = importlib.util.module_from_spec(importlib.util.spec_from_loader("p", l)); l.exec_module(m)
try:
import brotli as b
except ImportError:
try:
import brotlicffi as b
except ImportError:
b = None
if b is None:
print("ABSENT " + m._readable(b"\x1b\x0e\x00\xf8\x25", "br"))
else:
print("PRESENT " + m._readable(b.compress(b"slow down"), "br"))
'
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
case "$output" in
PRESENT*) [[ "$output" == *"slow down"* ]] \
|| { echo "a decoder was available and the message did not survive: $output"; return 1; } ;;
ABSENT*) [[ "$output" == *"br-encoded"* ]] \
|| { echo "$output"; return 1; }
# Naming the encoding is not enough on its own: the operator
# is one install away from the message, and the line has to
# say so.
[[ "$output" == *"brotli"* ]] \
|| { echo "the note does not say what would fix it: $output"; return 1; } ;;
*) echo "unexpected: $output"; return 1 ;;
esac
# Either way, no bytes.
[ -z "$(printf '%s' "$output" | tr -d '\11\12\15\40-\176')" ] \
|| { echo "unprintable output survived"; return 1; }
}
@test "nothing unprintable reaches the diagnostics file, whatever wrote it" {
# Asserted at the sink rather than on one producer. bin/dejima prints this
# file to the operator's terminal after a session ends, so it carries text
# an upstream API chose and - through the request path and exception
# messages - text the session chose. Filtering it where it is written
# covers a producer added later; filtering it in one formatter does not.
#
# CPython refuses a control character in a URL today, in two places, and
# reprs what it refuses. That is a coincidence this should not rest on.
run python3 -c '
import importlib.util, importlib.machinery, tempfile, os
l = importlib.machinery.SourceFileLoader("p", "'"$REPO_ROOT"'/bin/dejima-credential-proxy")
m = importlib.util.module_from_spec(importlib.util.spec_from_loader("p", l)); l.exec_module(m)
d = tempfile.mkdtemp(); f = os.path.join(d, "log")
m._diag(f, "path=/v1/\x1b[2J\x1b[1;31mred\x1b[0m\x07 null=\x00 tab=\t")
raw = open(f, "rb").read()
print("BYTES", sum(1 for b in raw if b < 32 and b != 10))
print(raw.decode().strip())
'
[ "$status" -eq 0 ] || { echo "$output"; return 1; }
[[ "$output" == *"BYTES 0"* ]] \
|| { echo "control bytes reached the file: $output"; return 1; }
# And the text around them survives, so a sanitised line is still a
# readable one rather than a row of spaces.
[[ "$output" == *"path=/v1/"* ]] && [[ "$output" == *"red"* ]] \
|| { echo "$output"; return 1; }
}
+74 -11
View File
@@ -10,13 +10,43 @@
set -uo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
base="${1:-main}"
# The remote-tracking ref by default, not the local branch. Everything this
# prints is derived from base..head - the manual checks from which paths the
# diff touches, the rollback list from which config keys it adds - so a base
# behind the real one silently reports a different release. That is not
# hypothetical: two passes ran against a local `main` 260 commits behind
# origin/main and reported keys and a trust-anchor domain that had shipped
# releases earlier. A gate answering confidently about the wrong diff is worse
# than one that does not run.
base="${1:-}"
if [ -z "$base" ]; then
if git rev-parse --verify --quiet origin/main >/dev/null 2>&1; then
base=origin/main
else
base=main
fi
fi
head="${2:-HEAD}"
# Guarded, because everything below is relative to it: a cd that failed
# silently would have this reporting on some other directory's suites and
# diff, which for a release gate is the worst way to be wrong.
cd "$root" || { echo "cannot enter $root" >&2; exit 1; }
# A named base that is behind its own upstream is refused rather than used.
# Passing `main` explicitly is the ordinary thing to do and is exactly how the
# stale-base runs happened, so this has to catch the argument as well as the
# default.
base_upstream="$(git rev-parse --abbrev-ref --symbolic-full-name "$base@{upstream}" 2>/dev/null || true)"
if [ -n "$base_upstream" ]; then
behind="$(git rev-list --count "$base..$base_upstream" 2>/dev/null || echo 0)"
if [ "${behind:-0}" -gt 0 ]; then
echo "release-pass: '$base' is $behind commit(s) behind $base_upstream." >&2
echo "Everything below is derived from $base..$head, so this would report on" >&2
echo "a release that is not the one being made. Fetch, or name $base_upstream." >&2
exit 1
fi
fi
case "${1:-}" in
-h|--help)
echo "Usage: test/release-pass.sh [base] [head]"
@@ -65,9 +95,11 @@ if docker info >/dev/null 2>&1; then
else
fail "no Docker here - test/runtime.bats did NOT run"
echo " It is the only thing that exercises mounts, the firewall and"
echo " the entrypoint end to end. Run it on the host, or check that"
echo " the privileged CI job RAN rather than queued: it is pinned to"
echo " one self-hosted runner and queues silently when that is down."
echo " the entrypoint end to end. Run it on the host, or read the"
echo " pull request's checks: GREEN means every job finished and"
echo " passed, this one among them. Yellow or grey means the"
echo " privileged job is still queued - it is pinned to one"
echo " self-hosted runner and queues silently when that is down."
fi
# --- what a person has to do, chosen by what the release touches -------------
@@ -105,6 +137,9 @@ touches '^(harnesses/|bin/harness/|docker/harness-wrapper)' &&
manual "Launch each affected harness against a real model."
touches '^(bin/dejima-attach|bin/dejima-ttyd|systemd/)' &&
manual "Attach over the web front door and detach again."
touches '^tools/' &&
manual "Launch with the affected tool included and use it. A tool is
layered into the image and put on PATH; nothing here runs one."
touches '^\.dejima/allowed-domains$' &&
manual "A domain here is read from main by the CI hardener and widens every
future CI job on that runner. Say in the PR what it is for."
@@ -133,10 +168,29 @@ added="$(comm -13 \
# The singular is spelled out rather than derived: "harnesses" does not lose
# an s to become "harness", and a manifest is named for the singular.
#
# Every axis, including backends: the newest one is exactly the one a stale
# list would miss, because a list is only ever updated by whoever remembers.
# Every axis there is, and the list is checked against the tree below rather
# than trusted: the newest axis is exactly the one a hand-kept list misses,
# because a list is only ever updated by whoever remembers. tools is an axis
# like the rest - `[core] tools = rtk` on a dejima that does not ship rtk is
# refused the same way an unknown harness is.
DEJIMA_RELEASE_AXES="harnesses:harness forges:forge workflows:workflow backends:backend tools:tool"
# The singular is spelled out above rather than derived - "harnesses" does not
# lose an s to become "harness", and a manifest is named for the singular - so
# this is the check that the spelling out has not fallen behind the tree.
for _d in */; do
_d="${_d%/}"
case "$_d" in
harnesses|forges|workflows|backends|tools) ;;
*) continue ;;
esac
case " $DEJIMA_RELEASE_AXES " in
*" $_d:"*) ;;
*) fail "$_d/ is a provider axis this script does not check for rollback" ;;
esac
done
new_providers=""
for pair in harnesses:harness forges:forge workflows:workflow backends:backend; do
for pair in $DEJIMA_RELEASE_AXES; do
axis="${pair%%:*}"
one="${pair#*:}"
[ -d "$axis" ] || continue
@@ -153,7 +207,7 @@ done
# backend` is one: adopting it is what makes the rollback refuse, and nothing
# said so.
new_keys=""
for pair in harnesses:harness forges:forge workflows:workflow backends:backend; do
for pair in $DEJIMA_RELEASE_AXES; do
axis="${pair%%:*}"
one="${pair#*:}"
[ -d "$axis" ] || continue
@@ -172,7 +226,15 @@ done
if [ -n "$added" ] || [ -n "$new_providers" ] || [ -n "$new_keys" ]; then
[ -z "$added" ] || printf ' %s\n' $added
[ -z "$new_providers" ] || printf ' [%s] as a config section\n' $new_providers
# How an older dejima refuses a new provider differs by axis, and saying
# "as a config section" for all of them was wrong for tools: a tool has no
# keys and so no section. It is refused through the value that names it.
for entry in $new_providers; do
case "$entry" in
tool.*) printf ' [core] tools = %s\n' "${entry#tool.}" ;;
*) printf ' [%s] as a config section\n' "$entry" ;;
esac
done
for entry in $new_keys; do
printf ' %s %s\n' "${entry%%|*}" "${entry#*|}"
done
@@ -181,6 +243,7 @@ else
fi
note "Then"
echo " Say in the release PR what was run and what was not. A privileged job"
echo " that queued is not a job that passed."
echo " Say in the release PR what was run and what was not. Green checks mean"
echo " the privileged job ran; a queued one is yellow or grey, and is not a"
echo " job that passed."
exit "$status"
+73 -22
View File
@@ -215,6 +215,30 @@ run_line() { grep -- ' run --rm ' "$LAUNCH_DIR/docker-log" | tail -1; }
rm -rf "$PROJ"
}
@test "an inherited state dir and run id are not what the exit trap deletes" {
# cleanup() removes "$DEJIMA_STATE_DIR/debounce/$DEJIMA_RUN_ID-{waiting,done}".
# With remote access off nothing used to assign either name, so both came
# from the caller's environment if it had them - and the trap then removed
# a path of the environment's choosing. Both are bound by dejima before the
# trap is installed now, so the join can only ever name a path it made.
#
# Two canaries, because either name alone being dejima's is enough to miss
# the path: the removal needs both halves to come from the environment.
stub_launch
local canary="$LAUNCH_DIR/canary"
mkdir -p "$canary/debounce"
: > "$canary/debounce/deadbeefdeadbeef-waiting"
: > "$canary/debounce/deadbeefdeadbeef-done"
DEJIMA_STATE_DIR="$canary" DEJIMA_RUN_ID=deadbeefdeadbeef launch "$PROJ"
[ -f "$canary/debounce/deadbeefdeadbeef-waiting" ] \
|| { echo "the trap removed a file named by the environment"; return 1; }
[ -f "$canary/debounce/deadbeefdeadbeef-done" ] \
|| { echo "the trap removed a file named by the environment"; return 1; }
rm -rf "$PROJ"
}
@test "with remote access configured a registry entry is written and removed on exit" {
stub_launch
write_remote_config
@@ -420,11 +444,21 @@ EOF
write_remote_config
# The EXIT trap removes the entry, so snapshot it from inside the run:
# the stub stands in for the container, and runs while it still exists.
#
# Matched on the session's own compose run rather than on every docker
# call. A launch makes several - a build, this launch's filter container,
# and two removals from the exit trap - and snapshotting on each meant the
# last one won. Those two removals run after the entry is gone, so what
# this read was an empty directory.
cat > "$LAUNCH_DIR/docker" <<EOF
#!/bin/bash
echo "\$*" >> "\${SANDBOX_TEST_DOCKER_LOG:-/dev/null}"
rm -rf "$LAUNCH_DIR/sessions-snapshot"
cp -r "$RUNTIME_DIR/dejima/sessions" "$LAUNCH_DIR/sessions-snapshot" 2>/dev/null || true
case "\$*" in
*" run --rm "*)
rm -rf "$LAUNCH_DIR/sessions-snapshot"
cp -r "$RUNTIME_DIR/dejima/sessions" "$LAUNCH_DIR/sessions-snapshot" 2>/dev/null || true
;;
esac
exit 0
EOF
chmod +x "$LAUNCH_DIR/docker"
@@ -2734,10 +2768,14 @@ nginx_blocks() {
}
@test "install.sh links the remote scripts and the notify hook, registers neither, and enables nothing" {
# The hook is linked by the harness plugin now - which file it is, and
# where the harness reads it from, is the harness's business - while the
# CLIs stay install.sh's, being dejima's own.
grep -q '_link_hook dejima-notify.sh' "$REPO_ROOT/bin/harness/claude-code.sh"
# The hook is baked into the image and registered by absolute path, so
# install.sh puts nothing of it on the host - which file it is, and where
# a session reads it from, is the harness plugin's business. The CLIs stay
# install.sh's, being dejima's own.
grep -q 'COPY hooks/dejima-notify.sh /usr/local/lib/dejima/hooks/dejima-notify.sh' \
"$REPO_ROOT/docker/Dockerfile"
grep -q '_link_hook' "$REPO_ROOT/bin/harness/claude-code.sh" \
&& { echo "install.sh still links hooks into ~/.claude/hooks"; return 1; }
grep -q '^link_bin dejima-attach$' "$REPO_ROOT/install.sh"
grep -q '^link_bin dejima-ttyd$' "$REPO_ROOT/install.sh"
grep -q '^link_bin dejima-notify-watch$' "$REPO_ROOT/install.sh"
@@ -2769,13 +2807,25 @@ nginx_blocks() {
# $output, and this is a statement about what THIS run printed.
[[ "$output" == *"nothing is listening"* ]]
# bin/dejima registers $HOME/.claude/hooks/dejima-notify.sh per session,
# and ~/.claude/hooks is what gets mounted read-only into the container.
# Without this link every notification hook is an exit-127.
[ -L "$FAKE_HOME/.claude/hooks/dejima-notify.sh" ]
[ "$(readlink -f "$FAKE_HOME/.claude/hooks/dejima-notify.sh")" \
= "$(readlink -f "$REPO_ROOT/hooks/dejima-notify.sh")" ]
[ -x "$FAKE_HOME/.claude/hooks/dejima-notify.sh" ]
# The notify hook is baked into the image and registered per session by
# its absolute path there, so nothing about it lands on the host. Without
# the baked copy every notification hook would be an exit-127.
[ ! -e "$FAKE_HOME/.claude/hooks/dejima-notify.sh" ] \
|| { echo "install.sh still puts the notify hook on the host"; return 1; }
# Asserted on what the registration PRODUCES rather than on the source
# text: the path is a variable there, and a grep for the literal passes or
# fails on how it happens to be spelled rather than on where it points.
local st; st="$(mktemp)"; echo '{}' > "$st"
bash -c '
source "'"$REPO_ROOT"'/bin/dejima-provider-lib.sh"
source "'"$REPO_ROOT"'/bin/dejima-harness-lib.sh"
harness_plugin_load claude-code
harness_hook harness_register_notify "$1"
' _ "$st" >/dev/null 2>&1
[ "$(jq -r '.hooks.Stop[0].hooks[0].command' "$st")" \
= "/usr/local/lib/dejima/hooks/dejima-notify.sh done" ] \
|| { echo "notify is not registered at its baked path: $(cat "$st")"; rm -f "$st"; return 1; }
rm -f "$st"
local b
for b in dejima-attach dejima-ttyd dejima-notify-watch; do
[ -L "$FAKE_HOME/.local/bin/$b" ]
@@ -2783,14 +2833,15 @@ nginx_blocks() {
[ -x "$FAKE_HOME/.local/bin/$b" ]
done
# Positive first: an absence assertion against a settings.json that did
# not get written would pass on its own.
run jq -e '[.hooks[]?[]?.hooks[]?.command] | any(test("sandbox-context.sh"))' \
"$FAKE_HOME/.claude/settings.json"
[ "$status" -eq 0 ]
run jq -e '[.hooks[]?[]?.hooks[]?.command] | any(test("dejima-notify"))' \
"$FAKE_HOME/.claude/settings.json"
[ "$status" -ne 0 ]
# install.sh registers nothing in the harness's config now, so there is
# nothing positive to check there - the settings file may not exist at
# all. The positive assertion that matters moved above: the notify hook IS
# registered, at its baked path, in the sandbox's own overlay.
if [ -f "$FAKE_HOME/.claude/settings.json" ]; then
run jq -e '[.hooks[]?[]?.hooks[]?.command] | any(test("dejima-notify"))' \
"$FAKE_HOME/.claude/settings.json"
[ "$status" -ne 0 ]
fi
# Nothing was enabled, and nothing under the runtime dir was created: the
# feature stays off until the operator sets [remote-access] enabled = on.
@@ -2801,7 +2852,7 @@ nginx_blocks() {
run env HOME="$FAKE_HOME" PATH="$STUB_DIR:$PATH" "$REPO_ROOT/install.sh"
[ "$status" -eq 0 ]
[ ! -e "$FAKE_HOME/.dejima-backup" ]
[ -L "$FAKE_HOME/.claude/hooks/dejima-notify.sh" ]
[ ! -e "$FAKE_HOME/.claude/hooks/dejima-notify.sh" ]
# And with one, it may not: re-running the installer after a git pull is
# exactly what an operator with a front door already up does, and telling
+546 -229
View File
File diff suppressed because it is too large Load Diff
+11 -6
View File
@@ -27,12 +27,17 @@ list_scripts() {
ls test/*.sh 2>/dev/null || true
} | sort -u | while read -r f; do
[ -f "$f" ] || continue
# Harness plugins are sourced, not executed, so they carry no shebang
# and the discovery below would drop them - silently, which is the
# worst version of that. They are in the trusted computing base, so
# they are included by name and the -s bash below tells shellcheck
# what they are.
case "$f" in bin/harness/*.sh) printf '%s\n' "$f"; continue ;; esac
# Sourced fragments are not executed, so they carry no shebang and the
# discovery below would drop them - silently, which is the worst
# version of that. Harness plugins are one kind; docker/ has two more,
# and they are not incidental: caps-lib.sh holds the drop that decides
# what a session's capability set is, and fixed-domains.sh is the seam
# keeping the DNS allowlist and the ipset allowlist from drifting.
#
# Matched by directory rather than by name, because a list is a thing
# to forget to add to. Everything under docker/ is in the trusted
# computing base; the -s bash below tells shellcheck what these are.
case "$f" in bin/harness/*.sh|docker/*.sh) printf '%s\n' "$f"; continue ;; esac
head -1 "$f" | grep -qE '^#!.*(bash|sh)' && printf '%s\n' "$f"
done
}
+993 -88
View File
File diff suppressed because it is too large Load Diff
+96
View File
@@ -0,0 +1,96 @@
'use strict';
const { test } = require('node:test');
const assert = require('node:assert');
require('../src/gestures.js');
const { createGestures } = globalThis.DEJIMA.gestures;
const CELL = 20; // rows are 20px tall in every world below
// An element that records the listeners createGestures attaches, so a test can
// fire a touch sequence at it without a DOM.
function makeElement() {
const listeners = {};
return {
addEventListener: (type, fn) => { (listeners[type] = listeners[type] || []).push(fn); },
fire: (type, event) => { (listeners[type] || []).forEach((fn) => fn(event)); }
};
}
function touchEvent(points) {
return {
touches: points.map((p) => ({ clientX: p.x, clientY: p.y })),
preventDefault: function () { this.defaultPrevented = true; },
defaultPrevented: false
};
}
// reporting: whether the application has asked for mouse reports, which is
// what decides who receives a notch and so what one is worth.
function makeWorld(reporting) {
const element = makeElement();
const scrolled = []; // this page's own scrollback, one row per entry
const wheeled = []; // notches sent to the application
const gestures = createGestures({
element: element,
term: {
scrollLines: (n) => scrolled.push(n),
getSelection: () => ''
},
mouse: {
cellHeight: () => CELL,
enabled: () => !!reporting,
cellAt: () => ({ col: 1, row: 1 }),
wheel: (cell, up) => wheeled.push(up ? 'up' : 'down'),
altScreen: () => false,
press: () => {}, motion: () => {}, release: () => {}
},
dragMode: () => false,
onCopy: () => {}
});
gestures.attach();
return {
element, scrolled, wheeled,
// A one-finger drag of `rows` rows, downward, which pulls earlier output
// into view. Delivered as one touchmove: scrollBy accumulates travel, so
// the split into events is not what the count under test depends on.
dragDown: function (rows) {
element.fire('touchstart', touchEvent([{ x: 100, y: 100 }]));
element.fire('touchmove', touchEvent([{ x: 100, y: 100 + rows * CELL }]));
element.fire('touchend', touchEvent([]));
}
};
}
// One notch per row of finger travel, whichever side receives the notch.
// What a notch is then WORTH belongs to the receiver: this page moves one row,
// and tmux's copy mode moves five until its binding says otherwise.
test('scrollback moves one row per row of finger travel', () => {
const w = makeWorld(false);
w.dragDown(10);
assert.equal(w.scrolled.length, 10);
assert.ok(w.scrolled.every((n) => n === -1), 'dragging down goes back in history');
assert.equal(w.wheeled.length, 0, 'no application is listening');
});
test('an application gets one notch per row of finger travel', () => {
const w = makeWorld(true);
w.dragDown(10);
assert.equal(w.wheeled.length, 10);
assert.ok(w.wheeled.every((d) => d === 'up'), 'dragging down scrolls up');
assert.equal(w.scrolled.length, 0, 'the page did not also scroll itself');
});
test('travel shorter than a row sends nothing rather than rounding up', () => {
const w = makeWorld(true);
w.element.fire('touchstart', touchEvent([{ x: 100, y: 200 }]));
w.element.fire('touchmove', touchEvent([{ x: 100, y: 200 + CELL / 2 }]));
assert.equal(w.wheeled.length, 0);
});
test('dragging up scrolls forward again', () => {
const w = makeWorld(true);
w.element.fire('touchstart', touchEvent([{ x: 100, y: 300 }]));
w.element.fire('touchmove', touchEvent([{ x: 100, y: 300 - 3 * CELL }]));
assert.deepEqual(w.wheeled, ['down', 'down', 'down']);
});