Linux reference
Look up standalone DefenseClaw on Linux: paths, systemd units, SELinux and secrets, the gateway sandbox, fapolicyd tarball installs and uninstall.
This page holds the detail behind Linux standalone deployment. Install from that page; come here for paths, units and edge cases.
Layout
| Item | Path | Owner and mode |
|---|---|---|
| Binaries | /opt/defenseclaw/bin: defenseclaw-gateway, defenseclaw-hook, defenseclaw-sensor-helper, and defenseclaw-acp when present | root, 0755 |
| Managed OpenCode plugin | /opt/defenseclaw/share/opencode/index.js | root, 0644 |
| Config | /etc/defenseclaw/config.yaml | root:defenseclaw, 0640 |
| Policies | /etc/defenseclaw/policies | root:defenseclaw, 0750 |
| Secrets | /etc/defenseclaw/secrets | See Secrets |
| Target manifest | /etc/defenseclaw/hook-guardian/targets.yaml (the enumerator writes it) | Directory root:defenseclaw, 0750 |
| Runtime descriptor | /etc/defenseclaw/managed-runtime.json | root, 0644 |
| Machine-policy summary | /etc/defenseclaw/machine-policy.json | Readable by users |
| Lifecycle state | /var/lib/defenseclaw-enterprise: lock, snapshots, deployment record, last-package-result.json, last-activation-failure.log, the last applied and a rejected config | root, 0700 |
| Sensor helper state | /var/lib/defenseclaw-sensor: the policy names loaded into Tetragon, their state and a pause record | root, 0700 |
| Gateway data | /var/lib/defenseclaw | defenseclaw, 0700 |
| Authorization ledger | /var/lib/defenseclaw-hook-guardian, with each user's latest AI Discovery scan in ai-discovery/ | root:defenseclaw, 0750 |
| Logs | /var/log/defenseclaw: empty unless a jsonl destination writes there. Services log to the journal (Logs and events) | defenseclaw, 0750 |
| Hook socket | /run/defenseclaw-hook/hook.sock | Directory defenseclaw, 0755. Socket 0666: every user may connect, and the gateway authorizes each caller by uid |
| Sandbox launcher | /usr/bin/defenseclaw, a link to defenseclaw-gateway that offers users only the commands in Managed command availability | root, 0755 |
| Sandbox state | /var/lib/defenseclaw/sandbox/, and /etc/defenseclaw/openshell/gateway.toml when enterprise.openshell is set | defenseclaw, 0600 files; root |
The gateway runs as the defenseclaw system account, created with
systemd-sysusers or useradd. An existing defenseclaw account with a login
shell is refused, because whoever signs in as it could stop the gateway. Remove it
with userdel defenseclaw or give it /usr/sbin/nologin, then run ensure again.
Units
| Unit | Runs as | What it does |
|---|---|---|
defenseclaw-gateway.service | defenseclaw, no capabilities | Policy engine and hook API. Type=notify, 60 s watchdog, Restart=always. Config, binaries and ledger are read-only to it |
defenseclaw-gateway-api.socket | PID 1 | Listens on 127.0.0.1:18970 |
defenseclaw-gateway-hook.socket | PID 1 | Listens on /run/defenseclaw-hook/hook.sock |
defenseclaw-hook-guardian.service | root, bounded capabilities | Always running. Reconciles each user's hooks every minute through a worker that runs as that user; the worker also runs the user's AI Discovery scan. Every 5 seconds it checks the hook binary, Claude Code's 90-defenseclaw.json drop-in and DefenseClaw's part of Codex requirements.toml. If one is gone or changed it logs tamper: and starts defenseclaw-enterprise-apply.service, whose ensure puts it back |
defenseclaw-hook-guardian-reconcile.service | root | One immediate reconcile, on demand |
defenseclaw-hook-enumerator.service | root, homes read-only | Rewrites the target manifest every five minutes (in auto enrollment mode) |
defenseclaw-sensor-helper.service | root | Answers the gateway's fixed AI Discovery requests. Starts after tetragon.service and reads a running Tetragon |
defenseclaw-enterprise-apply.path | PID 1 | Runs ensure --reason path when the config, secrets or policies change |
defenseclaw-enterprise-verify.timer | PID 1 | Runs verify daily, with up to one hour of random delay |
defenseclaw-sandbox.socket, .service, defenseclaw-openshell-gateway.service | Each user (systemd user units) | The user's sandbox daemon and, in setup mode, OpenShell gateway (Sandboxes) |
List view for small screens. Use the expand button to open the drawing.
TrustedZ0 · Admin and OS (root)
- systemdholds both sockets
- hands over socketsGatewayZ2
UntrustedZ4 · User session (the user)
- AI agentruns as the user
- runs per tool calldefenseclaw-hook
- defenseclaw-hookchecks the socket owner
- asks over hook.sockGatewayZ2
RestrictedZ2 · Gateway (defenseclaw)
- Gatewayallows or blocks
Text version of this diagram
Trusted: Z0 · Admin and OS (root)
- systemd: holds both sockets (component)
- hands over sockets to Gateway (Z2 · Gateway (defenseclaw))
Untrusted: Z4 · User session (the user)
- AI agent: runs as the user (agent)
- runs per tool call to defenseclaw-hook
- defenseclaw-hook: checks the socket owner (connector)
- asks over hook.sock to Gateway (Z2 · Gateway (defenseclaw))
Restricted: Z2 · Gateway (defenseclaw)
- Gateway: allows or blocks (gateway)
List view for small screens. Use the expand button to open the drawing.
PrivilegedZ1 · Services (root)
- Guardianchecks every minute
- readsTarget manifestZ3
- startsPer-user worker
- Enumeratorlists the users
- writesTarget manifestZ3
- runs as the userPer-user workershort-lived
- repairs hooksAgent configZ4
ProtectedZ3 · Admin-owned files
- Target manifesttargets.yaml
UntrustedZ4 · User session
- Agent configin the user's home
Text version of this diagram
Privileged: Z1 · Services (root)
- Guardian: checks every minute (component)
- reads to Target manifest (Z3 · Admin-owned files)
- starts to Per-user worker
- Enumerator: lists the users (component)
- writes to Target manifest (Z3 · Admin-owned files)
- Per-user worker: short-lived (component). A short-lived process the guardian starts with the user's own uid and gid. It does every read and write inside the user's home, so root never touches those files itself.
- repairs hooks to Agent config (Z4 · User session)
Protected: Z3 · Admin-owned files
- Target manifest: targets.yaml (policy layer)
Untrusted: Z4 · User session
- Agent config: in the user's home (agent)
Drop-ins
The package installs units in /usr/lib/systemd/system; a tarball install writes
them to /etc/systemd/system. Put host-specific drop-ins in
/etc/systemd/system/<unit>.d/.
| Drop-in names | Owner |
|---|---|
30-defenseclaw-tetragon.conf, 40-defenseclaw-agent-prefixes.conf, 50-defenseclaw-paths.conf, 60-defenseclaw-credentials.conf, 70-defenseclaw-network.conf | DefenseClaw. Do not edit them; verify does not report them as overrides |
| Every other name | You. The lifecycle never touches it. Use 00- to 29- or 80- to 99- (for example 80-site-proxy.conf) and leave defenseclaw out of the name |
SELinux, FIPS and secrets
| Topic | Detail |
|---|---|
| SELinux | Supported, for unconfined and confined users. Where SELinux is enabled the lifecycle loads a small defenseclaw policy module (semodule -l). It labels the hook socket defenseclaw_hook_sock_t and the gateway binary defenseclaw_gateway_exec_t, so the gateway runs in its own domain, defenseclaw_gateway_t. Every user domain may connect to that domain and to no other service; the gateway still authorizes each caller by uid. Uninstall removes the module |
| SELinux warnings | status and verify warn selinux_module_missing while confined users cannot reach the socket. The lifecycle warns selinux_relabel or selinux_module if relabeling or loading fails |
| FIPS mode | Preview. RHEL 9 in FIPS mode with the rpm |
| Application control | With fapolicyd, package-database trust covers the deb and rpm once fapolicyd has loaded them; if the package install reports payload_invalid, restart fapolicyd (Limits). A tarball needs its own trust entries (Tarball with fapolicyd) |
If a payload install reports that the staged gateway could not run, check
fapolicyd trust, SELinux policy, execute permission and noexec mount options.
The systemd version decides how the gateway reads secrets. It also decides how much
of the units' sandboxing applies: systemd ignores directives it does not know, so
RHEL 8 (Preview) runs without ProtectHostname, ProtectKernelLogs, ProtectClock,
ProtectProc and ProcSubset. The Linux threat model
lists each.
| systemd | Secrets |
|---|---|
| 247 or later | /etc/defenseclaw/secrets is root:root 0700, each file 0600. The gateway receives them through LoadCredential= |
| 239 to 246 | /etc/defenseclaw/secrets is root:defenseclaw 0750, each file 0640 |
Gateway sandbox
The gateway unit runs with an empty capability bounding set and a strict systemd
sandbox: NoNewPrivileges, ProtectSystem=strict, ProtectHome=true, private
devices and /tmp, ProtectProc=invisible, no SUID or namespace changes, and the
@system-service system-call set. Config, binaries and the ledger are read-only to it.
| Service | Capability bounding set |
|---|---|
| Gateway | Empty |
| Guardian | CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_KILL CAP_SETGID CAP_SETUID |
| Enumerator | The guardian's set without CAP_DAC_OVERRIDE |
Do not edit the units. Put host-specific settings in a drop-in, and never widen the gateway sandbox.
- A drop-in may set ordering, resource limits, restart and timeout tuning, and
host environment (a proxy, a CA bundle).
statusandverifylist such drop-ins as the warningunit_drop_in. - These fail
statusandverify: any other setting in a drop-in DefenseClaw did not write (User,ProtectHome,ExecStart,ReadWritePaths), anEnvironmentline that sets aDEFENSECLAW_*or loader variable, and an emptyEnvironment=line. - The managed gateway reads
/etc/defenseclaw/config.yamland/var/lib/defenseclawonly, and ignoresDEFENSECLAW_CONFIGandDEFENSECLAW_HOME.
sudo systemctl show defenseclaw-gateway.service \
-p User -p NoNewPrivileges -p CapabilityBoundingSet \
-p ProtectSystem -p ProtectHome -p ReadOnlyPaths -p ReadWritePathsUser namespaces
On most distributions as shipped (Ubuntu 24.04 and RHEL 9 included), status
and verify warn unprivileged_user_namespaces, unprivileged_ptrace or both,
and report security_complete: false.
Why it matters
A standard user who can create a private user and mount namespace, or trace their
own processes (for example with PRoot), can start an agent with its own view of the
machine-policy files, the runtime descriptor and /run/defenseclaw-hook. That
agent never calls the hook, so its tool calls are outside your enforcement
(Residual risks).
What DefenseClaw checks
- At start, and whenever a vendor policy file or the runtime descriptor changes, the gateway compares the digest of exactly the policy files the vendor reads with the digest pinned in the administrator-owned runtime descriptor. Drop-ins the vendor ignores are left out. The hook does no policy-view work on a call.
- When the view is missing, changed or unreadable, managed hook calls are still
inspected under the managed policy. The gateway raises a
HIGHruntime alert (enterprise_managed_policy_view_unverified, sourcemanaged_hook) in the audit log: once when the view changes, and with each call, rate limited. - Only a hook with no trusted runtime descriptor refuses.
- A hook in a private user namespace, where it cannot verify the gateway's
listener, is refused. So is a traced hook. A private mount view alone (for
example a
pam_namespacelogin) is not refused. - The gateway reads the host's files, so it cannot see a private view inside one agent process. An agent that omitted its managed hook before launch makes no call to inspect.
After an administrator or MDM changes a vendor machine-policy file or adds a
drop-in, run sudo /opt/defenseclaw/bin/defenseclaw-gateway enterprise linux reconcile --json
(or ensure). It pins the new view once DefenseClaw verifies it and names the
connector in changes; until then, hooks keep enforcing and raise the alert.
The apply unit does not watch vendor policy paths. The daily verify timer reports
drift but does not repair it.
Optional kernel hardening
DefenseClaw never writes host-wide kernel or sysctl settings. An administrator may apply optional hardening with their own host management tools after testing the host's workloads. These settings can break other work:
| Setting | What can stop working |
|---|---|
user.max_user_namespaces=0 | Codex's workspace sandbox, RootlessKit and rootless containers, a standard user's unshare -Ur |
kernel.yama.ptrace_scope=2 | OpenShell Docker sandboxes, a standard user's gdb and strace |
On Ubuntu 24.04 you can close only the namespace route with
kernel.apparmor_restrict_unprivileged_unconfined=1, which also restricts
bubblewrap-based command sandboxes. Neither setting stops a modified agent client,
or loader and runtime preloads (LD_PRELOAD, LD_AUDIT, NODE_OPTIONS=--require).
Use application control such as fapolicyd for those.
status and verify report the live kernel values. They do not treat old boot
markers or a prior value as proof of current protection.
Which setting the warning names
unprivileged_user_namespaces goes silent when any one of these holds:
user.max_user_namespaces=0kernel.unprivileged_userns_clone=0(Debian kernels)kernel.apparmor_restrict_unprivileged_userns=1andkernel.apparmor_restrict_unprivileged_unconfined=1together
If it cannot read user.max_user_namespaces, it says so and asks you to check
the kernel setting. Otherwise the text depends on the host:
| Host state | The warning names |
|---|---|
kernel.apparmor_restrict_unprivileged_userns=1, unconfined restriction 0 or absent (the Ubuntu 24.04 default) | kernel.apparmor_restrict_unprivileged_unconfined=1 or user.max_user_namespaces=0, and says an unconfined process can still switch profile with aa-exec |
| Any other host | user.max_user_namespaces=0, or restricting unprivileged user namespaces with SELinux or AppArmor |
unprivileged_ptrace goes silent when kernel.yama.ptrace_scope is 2 or 3.
Otherwise it asks for kernel.yama.ptrace_scope=2, because a tracer such as
PRoot can rewrite the paths an agent opens.
| Detection flag | Stock host with either warning |
|---|---|
detect.sh --require-healthy | Healthy; the warnings go to standard error |
detect.sh --require-security-complete | unhealthy |
What a private-namespace refusal looks like
An agent started inside a private user namespace (for example with unshare or
a sandbox tool) is refused, not allowed. Its hook call is blocked with:
this agent runs in a private user namespace (for example one started with unshare or a sandbox tool), where DefenseClaw cannot check it or reach its hook socketThe user sees "Start the agent from your normal login session; if this
continues, contact your administrator." The gateway records an auth-failure audit
row with reason enterprise_managed_user_namespace, and writes this line to its
journal:
[sidecar-api] hook socket refused uid=1001 connector="codex" route=<route> reason=enterprise_managed_user_namespace: the agent process context is unsafe or unverifiedA traced hook is refused the same way ("this agent's hook is being traced, so
another process may change the policy paths it reads"). To find these, search
the gateway journal for hook socket refused.
Tarball install with fapolicyd
On hosts with fapolicyd, the tarball needs two trust entries: one for the staged
payload folder and one for the installed tree /opt/defenseclaw/. Stage the
payload first (step 3b).
Trust the staged payload
After the first extraction, and before running the gateway:
sudo fapolicyd-cli --file add "$PAYLOAD/" --trust-file defenseclaw && sudo fapolicyd-cli --updateOn a rerun with the same untouched folder, reuse the entry. If you extract the tarball again into that folder or change its files, update the entry instead:
sudo fapolicyd-cli --file update "$PAYLOAD/" --trust-file defenseclaw && sudo fapolicyd-cli --updateStage without starting
sudo "$PAYLOAD/defenseclaw-gateway" enterprise linux ensure --payload "$PAYLOAD" --no-start --jsonFor an upgrade or rerun, start this while the gateway service is active.
Trust the installed tree
On a fresh install, add the entry. On an upgrade or rerun, update the existing
entry; add would append entries rather than refresh matching paths.
# Fresh install:
sudo fapolicyd-cli --file add /opt/defenseclaw/ --trust-file defenseclaw && sudo fapolicyd-cli --update
# Upgrade or rerun:
# sudo fapolicyd-cli --file update /opt/defenseclaw/ --trust-file defenseclaw && sudo fapolicyd-cli --updateCheck it as the service user
sudo -u defenseclaw /opt/defenseclaw/bin/defenseclaw-gateway --version-jsonfapolicyd updates are asynchronous. If this is denied just after --update, retry
once fapolicyd finishes syncing. It must succeed before the next step.
Start and verify
sudo "$PAYLOAD/defenseclaw-gateway" enterprise linux ensure --payload "$PAYLOAD" --json
sudo /opt/defenseclaw/bin/defenseclaw-gateway enterprise linux verify --jsonCheck that defenseclaw-gateway.service is active.
After you delete the payload folder, remove its trust entry:
sudo fapolicyd-cli --file delete "$PAYLOAD/" --trust-file defenseclaw && sudo fapolicyd-cli --updateUsers who are enrolled
The enumerator finds accounts through NSS, so directory users (LDAP, SSSD, Active Directory) count as well as local ones. It skips:
- accounts below
UID_MINfrom/etc/login.defs(1000 when unset); - local accounts above
UID_MAX(60000 when unset).enterprise.enrollment.uid_minchanges the minimum, anduid_maxcaps local and directory accounts alike; - accounts with a nologin shell, unless in
include_users; - accounts whose home is outside
/homeand/var/home. Add roots withenterprise.enrollment.home_roots;include_usersdoes not override this; - accounts in
exclude_usersorexempt_users, and accounts the group filters leave out; root, uid 65534 andnobody, always.
See Enrollment.
Per-user installs
On a computer with /etc/defenseclaw/managed-runtime.json, the per-user product
refuses to run:
| Per-user action | Result |
|---|---|
install.sh | Refuses and changes nothing |
defenseclaw upgrade | Refuses |
| Per-user gateway | Refuses to start |
Per-user CLI on the PATH | Refuses per-user commands, exit 3 |
Managed defenseclaw launcher | Shows the account's own connectors with status, and offers sandbox and guardrail profile views (Managed command availability). Refuses doctor, alerts, tui and per-user configuration commands with exit 2, naming the administrator status, verify and audit export commands |
Nothing migrates a per-user install, and a config.yaml it left in
~/.defenseclaw is not the policy the device enforces.
A per-user gateway still running holds the managed port 127.0.0.1:18970 unless
its user moved it. The install then stops before it changes anything with
api_port_held, naming the process and the kill command. The package install
completes, with the error in last-package-result.json. Stop that gateway or move
it, then run /opt/defenseclaw/bin/defenseclaw-gateway enterprise linux ensure --from-package.
A per-user gateway on another port keeps running; the install, status and verify
name each such account with per_user_gateway_running.
Remove
The commands are on Linux standalone deployment. This section lists what each one keeps.
What a plain uninstall keeps
- Each user's
~/.defenseclaw. - Your policies in
/etc/defenseclaw/policies(root-owned, mode0751). The vendor policies in/opt/defenseclaw/share/policiesgo. - When an account keeps sandboxes:
/var/lib/defenseclaw/sandboxand/var/lib/defenseclaw/redaction-correlation.key, with the root-only records/var/lib/defenseclaw-enterprise/openshell-state.kept.jsonand/var/lib/defenseclaw-enterprise/retained-state.jsonand the marker/var/lib/defenseclaw/.defenseclaw-retained. They are root-owned while the service account is gone; the nextensureadopts them. - Administrator entries in vendor machine-policy files. DefenseClaw's own entries and each user's DefenseClaw hook registrations are removed first.
If the sensor helper loaded policies into Tetragon, uninstall deletes those
defenseclaw-* policies before removing any file
(Remove the policies, or downgrade). The result's
kept: line names accounts that still have ~/.defenseclaw or per-user binaries.
If uninstall reports an error, it keeps the deployment record, config and state so
you can fix the cause and rerun.
What --purge adds
--purge also stops each enrolled user's per-user gateway and removes
~/.defenseclaw, the empty agent folders DefenseClaw created, the per-user
binaries in ~/.local/bin, DefenseClaw's wheels in ~/.cache/uv, and your
policies in /etc/defenseclaw/policies.
- An account's own install stays. If an enrolled account had its own DefenseClaw
install before the enrollment (its
~/.defenseclawholdsconfig.yaml,.env,audit.db,previous/,.venv/orinstaller/),--purgeleaves that folder and its binaries as they are. The result names the account (kept the DefenseClaw per-user data of user <name> ...) with aper_user_state_remainingwarning. - What the enrollment changed is put back. With or without
--purge, the uninstall restores the own install's hook scripts and settings, connector backups, hook contract lock and session cache, byte for byte. It also restores each agent config those backups name, if the file did not change while managed. A changed config stays and is named inper_user_state_remaining; that user runsdefenseclaw setupagain if its hooks are missing. - Accounts covered only by machine policy (not in the enrollment manifest) are
purged the same way when their
~/.defenseclawholds only what DefenseClaw wrote there. - Accounts the deployment never enrolled keep their DefenseClaw files. The result lists each on
a
kept:warning; delete those files with the account's owner. - Backups for removed connectors move to
~/.defenseclaw-removed-connector-backupsfirst. If that move fails, the purge stops without deleting anything.
A machine uninstall never deletes or moves an account's own data.
Pass --purge in the same run as the uninstall. A plain uninstall removes the
enrollment record a later --purge needs, and a purge after it warns
per_user_state_remaining. To clean up afterward, run
ensure --from-package --config <file> and then uninstall --purge, or delete the
files by hand.
Package removal
On a package host uninstall leaves the package's binaries and units, so dpkg or
rpm still lists defenseclaw-enterprise. Removing the package runs uninstall:
| Package command | Effect |
|---|---|
apt remove defenseclaw-enterprise | Runs plain uninstall, then removes the package files and /opt/defenseclaw/share/policies. The config, most state and the defenseclaw account go, also after a failed package install that rolled back. /etc/defenseclaw/policies, each user's ~/.defenseclaw and any kept sandbox store and key stay |
apt purge defenseclaw-enterprise | Runs the same plain uninstall, then deletes what it left of /etc/defenseclaw, /var/lib/defenseclaw (including sandbox and redaction-correlation.key), /var/lib/defenseclaw-hook-guardian and /var/log/defenseclaw, plus lifecycle state except the root-owned lifecycle.lock. It does not purge enrolled accounts' homes; run lifecycle --purge first |
dnf remove defenseclaw-enterprise | Same as apt remove, including the sandbox store and key that an account's kept sandboxes leave behind. Delete /etc/defenseclaw/policies by hand when you no longer need it |
After apt purge, sandboxes that accounts kept in their homes are no longer known to
a later install. Before you purge, have each owner save the work with
defenseclaw sandbox pull NAME --apply (or --branch or --patch-out FILE).
If uninstall refuses before any change (uninstall_precheck_refused) or stops
before removing the binaries (uninstall_incomplete), apt or dnf fails and keeps
the package files. The result stays in last-package-result.json. Fix the cause it
names, then run the removal again.
On a tarball host, uninstall --purge removes the deployment, including
/opt/defenseclaw. Removing the deployment does not change the running kernel, and
DefenseClaw creates no files under /etc/sysctl.d.
Turn it on again
| Host | Command |
|---|---|
| Package | ensure --from-package --config <file> |
| Tarball without fapolicyd | "$PAYLOAD/defenseclaw-gateway" enterprise linux ensure --payload "$PAYLOAD" --config <file> |
| Tarball with fapolicyd | The two-stage flow, passing --config <file> to both ensure calls |
After an uninstall or reinstall, ask users to restart their agents
(agent_sessions_restart_required).
Linux standalone deployment
Install the standalone DefenseClaw enterprise services on Linux from the deb or rpm package or the payload tarball, check the result, and remove them.
Tetragon on a Linux fleet
Roll DefenseClaw out to Linux hosts that already run Tetragon: harden Tetragon, turn on Plane C, move from observe to enforce by ring, and roll back.