Skip to content

feat: isolate agent runtime and restrict egress - #3

Merged
steipete merged 7 commits into
mainfrom
feat/egress-lockdown
Jul 5, 2026
Merged

steipete merged 7 commits into
mainfrom
feat/egress-lockdown

Conversation

@steipete

@steipete steipete commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Crabhelm now installs the OpenClaw runtime under a dedicated, unprivileged crabhelm-agent system account and applies a root-owned nftables policy before any credentials are delivered.

The policy is scoped to the agent UID, so bootstrap, SSH, and other host services remain reachable. Agent egress is limited to loopback, DNS, NTP, DHCP, IPv6 neighbor discovery, and TCP 443; IPv4 and IPv6 instance-metadata endpoints are denied explicitly, followed by a final agent-UID drop.

Security model

  • required is the default and unknown values fail closed; off is the explicit escape hatch.
  • The agent account has no sudo access and cannot modify the root-owned policy, verifier, units, readiness state, or credentials-generation markers.
  • A boot-persistent egress unit runs before network bring-up, and both install completion and readiness verify the live ruleset rather than trusting a marker.
  • The hardened system service drops capabilities, protects the host filesystem, and grants write access only to the agent home.
  • Reinstalls stop the managed service and all remaining agent-UID processes before replacing credentials or runtime state; readiness additionally verifies that systemd's live MainPID belongs to the isolated account.
  • The IMDS deny rules precede every allow rule. There is no established-flow bypass.

Testing

  • pnpm check: 144 Node tests and 16 workerd/Vitest tests green, plus TypeScript, Worker bundle, and Wrangler dry-run checks.
  • Real AWS c7a.large Crabbox validation using the generated production bootstrap: fresh install and upgrade rerun; egress and agent units enabled; service MainPID owned by the isolated UID; no agent sudo; live nft rules verified; IMDS and plain HTTP denied for the agent; HTTPS allowed; host plain HTTP and the SSH control path remained reachable.

This supersedes the original host-global, fail-open proposal. It now provides an actual privilege boundary without risking loss of appliance management access.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b862d5d78c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread worker/bootstrap.ts Resolved
Comment thread worker/bootstrap.ts Resolved
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer review hold: the current appliance runs OpenClaw under the same principal that can mutate the nftables policy (root or passwordless sudo), so a compromised agent can remove or rewrite the proposed egress boundary. The required service also does not fail boot/network closed, and readiness validates a marker rather than the live ruleset.

I prepared and tested narrower idempotency, persistence, rollback, and reconvergence fixes locally, but did not push them because they would still imply a security boundary the appliance does not provide. The PR needs an architectural revision: run the agent as a separate unprivileged user, keep network policy ownership outside that principal, and gate boot/readiness on the live enforced ruleset. The two existing review threads remain unresolved until that redesign lands.

@steipete
steipete changed the base branch from feat/credential-rotation to main July 5, 2026 20:40
@steipete steipete changed the title feat: allowlist agent-workspace egress before credentials land feat: isolate agent runtime and restrict egress Jul 5, 2026
@steipete
steipete merged commit 8530e40 into main Jul 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32e6a1f935

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread worker/bootstrap.ts
Comment on lines +1284 to +1285
/bin/bash "$agent_work/bundle/guest-install.sh"
"\${egress_privileged[@]}" /bin/rm -rf "$agent_work"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clean the agent workdir on failed installs

If guest-install.sh exits nonzero in this production path, set -e aborts before this cleanup runs, leaving $agent_work/credentials.env and the managed spec under /var/lib/crabhelm-agent/bootstrap-$$. That file contains the model/provider credential plus the short-lived runtime token; add a trap or cleanup before invoking the agent install so failed package/policy installs do not persist copied credentials in the agent home.

Useful? React with 👍 / 👎.

Comment thread worker/bootstrap.ts
Comment on lines +1274 to +1276
CRABHELM_CREDENTIAL_FILE="$agent_work/credentials.env" \
CRABHELM_MANAGED_SPEC_FILE="$agent_work/managed-spec.json" \
CRABHELM_POLICY_HASH="$CRABHELM_POLICY_HASH" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the credential refresh env for agent install

In the root appliance path this run_as_agent invocation is the only environment passed to guest-install.sh, but it omits CRABHELM_CREDENTIAL_REFRESH_URL and CRABHELM_BOOTSTRAP_TOKEN; checked /usr/sbin/runuser --help, and inherited environment is reset unless --preserve-environment is used. As a result the refresh block in guest-install.sh is skipped, so a slow offline npm/plugin install can write the originally fetched 10-minute runtime token after it has expired and the runtime bridge will fail to authenticate.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant