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

ItemPathOwner and mode
Binaries/opt/defenseclaw/bin: defenseclaw-gateway, defenseclaw-hook, defenseclaw-sensor-helper, and defenseclaw-acp when presentroot, 0755
Managed OpenCode plugin/opt/defenseclaw/share/opencode/index.jsroot, 0644
Config/etc/defenseclaw/config.yamlroot:defenseclaw, 0640
Policies/etc/defenseclaw/policiesroot:defenseclaw, 0750
Secrets/etc/defenseclaw/secretsSee Secrets
Target manifest/etc/defenseclaw/hook-guardian/targets.yaml (the enumerator writes it)Directory root:defenseclaw, 0750
Runtime descriptor/etc/defenseclaw/managed-runtime.jsonroot, 0644
Machine-policy summary/etc/defenseclaw/machine-policy.jsonReadable 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 configroot, 0700
Sensor helper state/var/lib/defenseclaw-sensor: the policy names loaded into Tetragon, their state and a pause recordroot, 0700
Gateway data/var/lib/defenseclawdefenseclaw, 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.sockDirectory 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 availabilityroot, 0755
Sandbox state/var/lib/defenseclaw/sandbox/, and /etc/defenseclaw/openshell/gateway.toml when enterprise.openshell is setdefenseclaw, 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

UnitRuns asWhat it does
defenseclaw-gateway.servicedefenseclaw, no capabilitiesPolicy engine and hook API. Type=notify, 60 s watchdog, Restart=always. Config, binaries and ledger are read-only to it
defenseclaw-gateway-api.socketPID 1Listens on 127.0.0.1:18970
defenseclaw-gateway-hook.socketPID 1Listens on /run/defenseclaw-hook/hook.sock
defenseclaw-hook-guardian.serviceroot, bounded capabilitiesAlways 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.servicerootOne immediate reconcile, on demand
defenseclaw-hook-enumerator.serviceroot, homes read-onlyRewrites the target manifest every five minutes (in auto enrollment mode)
defenseclaw-sensor-helper.servicerootAnswers the gateway's fixed AI Discovery requests. Starts after tetragon.service and reads a running Tetragon
defenseclaw-enterprise-apply.pathPID 1Runs ensure --reason path when the config, secrets or policies change
defenseclaw-enterprise-verify.timerPID 1Runs verify daily, with up to one hour of random delay
defenseclaw-sandbox.socket, .service, defenseclaw-openshell-gateway.serviceEach user (systemd user units)The user's sandbox daemon and, in setup mode, OpenShell gateway (Sandboxes)
hands over sockets
runs per tool call
asks over hook.sock
TrustedZ0 · Admin and OS (root)
UntrustedZ4 · User session (the user)
RestrictedZ2 · Gateway (defenseclaw)
systemdholds both sockets
AI agentruns as the user
defenseclaw-hookchecks the socket owner
Gatewayallows or blocks

List view for small screens. Use the expand button to open the drawing.

TrustedZ0 · Admin and OS (root)

  1. systemdholds both sockets
    • hands over socketsGatewayZ2

UntrustedZ4 · User session (the user)

  1. AI agentruns as the user
    • runs per tool calldefenseclaw-hook
  2. defenseclaw-hookchecks the socket owner
    • asks over hook.sockGatewayZ2

RestrictedZ2 · Gateway (defenseclaw)

  1. Gatewayallows or blocks
AgentConnectorGateway
Linux. systemd opens 127.0.0.1:18970 and /run/defenseclaw-hook/hook.sock at boot and keeps them open while the gateway restarts, so a hook that connects mid-restart waits for the real gateway. The hook sends nothing until it has checked that root or defenseclaw owns the socket, and the gateway learns the caller's uid from the kernel.
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)
writes
reads
starts
repairs hooks
PrivilegedZ1 · Services (root)
ProtectedZ3 · Admin-owned files
UntrustedZ4 · User session
Enumeratorlists the users
Guardianchecks every minute
runs as the userPer-user workershort-lived
Target manifesttargets.yaml
Agent configin the user's home

List view for small screens. Use the expand button to open the drawing.

PrivilegedZ1 · Services (root)

  1. Guardianchecks every minute
    • readsTarget manifestZ3
    • startsPer-user worker
  2. Enumeratorlists the users
    • writesTarget manifestZ3
  3. runs as the userPer-user workershort-lived
    • repairs hooksAgent configZ4

ProtectedZ3 · Admin-owned files

  1. Target manifesttargets.yaml

UntrustedZ4 · User session

  1. Agent configin the user's home
Linux. The enumerator lists the users to protect in /etc/defenseclaw/hook-guardian/targets.yaml. Every minute the guardian, which runs as root, starts a short-lived worker as each listed user, and the worker puts back DefenseClaw's hooks in that user's agent config. Root never writes a user's files with its own rights.
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 namesOwner
30-defenseclaw-tetragon.conf, 40-defenseclaw-agent-prefixes.conf, 50-defenseclaw-paths.conf, 60-defenseclaw-credentials.conf, 70-defenseclaw-network.confDefenseClaw. Do not edit them; verify does not report them as overrides
Every other nameYou. 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

TopicDetail
SELinuxSupported, 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 warningsstatus 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 modePreview. RHEL 9 in FIPS mode with the rpm
Application controlWith 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.

systemdSecrets
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.

ServiceCapability bounding set
GatewayEmpty
GuardianCAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_KILL CAP_SETGID CAP_SETUID
EnumeratorThe 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). status and verify list such drop-ins as the warning unit_drop_in.
  • These fail status and verify: any other setting in a drop-in DefenseClaw did not write (User, ProtectHome, ExecStart, ReadWritePaths), an Environment line that sets a DEFENSECLAW_* or loader variable, and an empty Environment= line.
  • The managed gateway reads /etc/defenseclaw/config.yaml and /var/lib/defenseclaw only, and ignores DEFENSECLAW_CONFIG and DEFENSECLAW_HOME.
sudo systemctl show defenseclaw-gateway.service \
  -p User -p NoNewPrivileges -p CapabilityBoundingSet \
  -p ProtectSystem -p ProtectHome -p ReadOnlyPaths -p ReadWritePaths

User 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 HIGH runtime alert (enterprise_managed_policy_view_unverified, source managed_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_namespace login) 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:

SettingWhat can stop working
user.max_user_namespaces=0Codex's workspace sandbox, RootlessKit and rootless containers, a standard user's unshare -Ur
kernel.yama.ptrace_scope=2OpenShell 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=0
  • kernel.unprivileged_userns_clone=0 (Debian kernels)
  • kernel.apparmor_restrict_unprivileged_userns=1 and kernel.apparmor_restrict_unprivileged_unconfined=1 together

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 stateThe 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 hostuser.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 flagStock host with either warning
detect.sh --require-healthyHealthy; the warnings go to standard error
detect.sh --require-security-completeunhealthy

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 socket

The 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 unverified

A 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 --update

On 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 --update

Stage without starting

sudo "$PAYLOAD/defenseclaw-gateway" enterprise linux ensure --payload "$PAYLOAD" --no-start --json

For 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 --update

Check it as the service user

sudo -u defenseclaw /opt/defenseclaw/bin/defenseclaw-gateway --version-json

fapolicyd 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 --json

Check 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 --update

Users 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_MIN from /etc/login.defs (1000 when unset);
  • local accounts above UID_MAX (60000 when unset). enterprise.enrollment.uid_min changes the minimum, and uid_max caps local and directory accounts alike;
  • accounts with a nologin shell, unless in include_users;
  • accounts whose home is outside /home and /var/home. Add roots with enterprise.enrollment.home_roots; include_users does not override this;
  • accounts in exclude_users or exempt_users, and accounts the group filters leave out;
  • root, uid 65534 and nobody, always.

See Enrollment.

Per-user installs

On a computer with /etc/defenseclaw/managed-runtime.json, the per-user product refuses to run:

Per-user actionResult
install.shRefuses and changes nothing
defenseclaw upgradeRefuses
Per-user gatewayRefuses to start
Per-user CLI on the PATHRefuses per-user commands, exit 3
Managed defenseclaw launcherShows 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, mode 0751). The vendor policies in /opt/defenseclaw/share/policies go.
  • When an account keeps sandboxes: /var/lib/defenseclaw/sandbox and /var/lib/defenseclaw/redaction-correlation.key, with the root-only records /var/lib/defenseclaw-enterprise/openshell-state.kept.json and /var/lib/defenseclaw-enterprise/retained-state.json and the marker /var/lib/defenseclaw/.defenseclaw-retained. They are root-owned while the service account is gone; the next ensure adopts 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 ~/.defenseclaw holds config.yaml, .env, audit.db, previous/, .venv/ or installer/), --purge leaves that folder and its binaries as they are. The result names the account (kept the DefenseClaw per-user data of user <name> ...) with a per_user_state_remaining warning.
  • 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 in per_user_state_remaining; that user runs defenseclaw setup again if its hooks are missing.
  • Accounts covered only by machine policy (not in the enrollment manifest) are purged the same way when their ~/.defenseclaw holds 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-backups first. 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 commandEffect
apt remove defenseclaw-enterpriseRuns 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-enterpriseRuns 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-enterpriseSame 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

HostCommand
Packageensure --from-package --config <file>
Tarball without fapolicyd"$PAYLOAD/defenseclaw-gateway" enterprise linux ensure --payload "$PAYLOAD" --config <file>
Tarball with fapolicydThe 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).