ConnectorsOpenClaw

OpenClaw advanced setup

Set up OpenClaw beyond the default: shared machines, admin-installed plugin, separate OS accounts, gateway token, device pairing and Bedrock VPC endpoints.

The OpenClaw page covers the default layout: DefenseClaw and OpenClaw run as one OS account with the plugin DefenseClaw manages. This page covers the other layouts and the settings they need.

You wantSection
Several accounts on one machine, each with its own pairSame user, own ports
Check what setup will refuse before you run itSetup preflight
An OpenClaw account that cannot change the plugin codeAdministrator-installed plugin
OpenClaw and DefenseClaw as two OS accountsSeparate users
Give or fix the token DefenseClaw uses to reach OpenClawOpenClaw gateway token
OpenClaw without token authentication, or fewer scopesDevice pairing, Operator scopes
Bedrock through AWS PrivateLinkBedrock through a VPC endpoint

Same user, own ports

Run the DefenseClaw gateway and the OpenClaw gateway as the same OS user, one account per pair. The plugin runs inside OpenClaw and reads that user's ~/.defenseclaw, and the DefenseClaw gateway connects to OpenClaw with that user's OpenClaw token.

On a shared machine, give each account its own ports:

GatewayKeys
DefenseClawgateway.api_port and guardrail.port in config.yaml
OpenClawgateway.port in openclaw.json

If you move the OpenClaw gateway to another port later, run defenseclaw setup openclaw again, or defenseclaw setup gateway --port <port>.

DefenseClaw checks the listener before it sends a token, so a process of another account that takes a port while a gateway restarts gets nothing:

  • The plugin sends the DefenseClaw token and provider keys only to a loopback gateway.host. localhost means 127.0.0.1. With any other host it sends nothing, and defenseclaw doctor fails the OpenClaw gateway.host row.
  • The listener must prove it holds the same token (/api/v1/hook-listener-proof). The gateway answers that proof only to its own OS account.
  • A listener that answers without the proof is not an outage: in every policy a tool check is blocked and a model call fails as in a closed-mode outage. A proof that finds nothing listening, or times out, is an outage and follows the saved outage mode.
  • Tool checks prove the very connection that carries the token. Model calls, health checks and telemetry prove the listener right before each request, so a process that takes the port in that gap (well under a millisecond on loopback) could still receive one request.
  • Before it connects to a loopback OpenClaw gateway port, the DefenseClaw gateway checks who owns the listener: the same account or root on Linux, the same account on macOS. Otherwise it sends nothing, keeps retrying, and defenseclaw doctor names the step.

Setup preflight

Setup checks every file it is about to change before it changes any. When a check fails it stops, changes nothing and prints the reason and the fix. Run the same check yourself before setup or an upgrade:

defenseclaw-gateway connector openclaw preflight

It prints openclaw preflight: ok and exits 0, or prints the reason on stderr and exits 1.

RefusalFix
The OpenClaw home, its extensions folder, openclaw.json or the folder that holds it belongs to another account, or its owner cannot write it.Run the gateway as the account that owns the OpenClaw home, or use the separate-user layout.
extensions/defenseclaw belongs to another account. It looks like an administrator-installed plugin.Set connectors.openclaw.plugin_install to external and connectors.openclaw.plugin_dir to it, or remove it.
With plugin_install: external, the plugin folder or a folder above it is not owned by root (SYSTEM or Administrators on Windows), can be written by a group or others, or holds a link or a file that is not a plain file.Run export-plugin again as root (Administrator-installed plugin).
With plugin_install: external, the files are not exactly the plugin of this build: one is missing, added or different.Run export-plugin again after the upgrade.
plugin_dir is the folder DefenseClaw manages inside the OpenClaw home.Put the administrator copy outside the OpenClaw home.
The connector-scoped plugin credential cannot be issued, for example because the DefenseClaw data folder is not protected.Run defenseclaw doctor. Setup does not fall back to the gateway token.
On Windows, OpenClaw is older than 2026.8.35.Run npm install -g openclaw@latest.

Administrator-installed plugin

By default setup writes the plugin into extensions/defenseclaw in the OpenClaw home. When the OpenClaw account must not be able to change the plugin code, an administrator installs the plugin once. DefenseClaw then checks it and registers it, and never writes or deletes it.

Export the plugin as root

Write the plugin of this build into a new or empty folder named defenseclaw, outside the OpenClaw home:

defenseclaw-gateway connector openclaw export-plugin --dir /opt/defenseclaw-openclaw/defenseclaw

Keep the folder and every folder above it owned by root and not writable by group or others. Do not put links in it.

Turn on the external plugin

As the DefenseClaw account:

defenseclaw config set connectors.openclaw.plugin_dir /opt/defenseclaw-openclaw/defenseclaw
defenseclaw config set connectors.openclaw.plugin_install external
defenseclaw setup openclaw --restart

Export again after every DefenseClaw upgrade

Setup refuses a plugin that is not exactly the plugin of the gateway, and export-plugin refuses a folder that is not empty. As root:

rm -rf /opt/defenseclaw-openclaw/defenseclaw
defenseclaw-gateway connector openclaw export-plugin --dir /opt/defenseclaw-openclaw/defenseclaw

Rules:

  • plugin_dir is a clean absolute path that ends in a folder named defenseclaw, the plugin id. Config refuses anything else.
  • The files must match the build byte for byte, with no file missing and none added. A plugin from another build fails the preflight, and the message names both versions.
  • Teardown (defenseclaw setup remove openclaw --force for the last connector, defenseclaw guardrail disable) removes the DefenseClaw entries from openclaw.json and never deletes the folder. The administrator removes it.
  • A managed copy left in extensions/defenseclaw is removed when the DefenseClaw account owns it, so OpenClaw does not load two plugins with one id. If another account owns it, setup leaves it and prints a notice.
  • To go back, run defenseclaw config unset connectors.openclaw.plugin_install and defenseclaw config unset connectors.openclaw.plugin_dir, then run setup again.

The plugin code is protected, openclaw.json is not. The account that runs OpenClaw can still edit its own openclaw.json, for example to remove the plugin entry.

Separate users (Linux and macOS)

Use this layout when OpenClaw runs as its own OS account and the DefenseClaw gateway runs as another. The OpenClaw account owns openclaw.json and cannot read the DefenseClaw data folder. The layout needs the administrator-installed plugin, so the OpenClaw account cannot change plugin code.

  • Native Windows does not support it: config refuses plugin_account there.
  • Both accounts must be local accounts (in /etc/passwd and /etc/group, or the macOS local directory). The gateway does not resolve directory (AD, LDAP, SSSD) accounts for plugin_account and plugin_token_group.

The examples use openclaw for the OpenClaw account and defenseclaw for the DefenseClaw account.

Prepare the accounts as root

groupadd openclaw-plugin
usermod -aG openclaw-plugin openclaw        # the plugin reads the credential
usermod -aG openclaw-plugin defenseclaw     # the gateway gives the file to the group
install -d -o defenseclaw -m 0755 /etc/defenseclaw-openclaw
npm install -g --prefix /usr/local openclaw@2026.8.35   # both accounts can run it

Install OpenClaw where the DefenseClaw account can run it, such as /usr/local/bin: setup reads the OpenClaw version to choose the hook mode. An OpenClaw under the OpenClaw account's home (npm -g --prefix ~/.local) cannot be run by the DefenseClaw account, so setup uses proxy mode, without the native hooks or the prompt gate, and says so.

Edit the DefenseClaw config

Edit these keys in config.yaml directly. plugin_account, plugin_token_file and plugin_token_group are valid only together, so defenseclaw config set refuses them one at a time.

connectors:
  openclaw:
    plugin_install: external
    plugin_dir: /opt/defenseclaw-openclaw/defenseclaw
    plugin_account: openclaw
    plugin_token_file: /etc/defenseclaw-openclaw/plugin.token
    plugin_token_group: openclaw-plugin

Also set claw.home_dir and claw.config_file to the OpenClaw home and openclaw.json of the OpenClaw account.

Give DefenseClaw the OpenClaw gateway token

Put the OpenClaw gateway token (gateway.auth.token of the OpenClaw account) in the DefenseClaw account's ~/.defenseclaw/.env as OPENCLAW_GATEWAY_TOKEN=..., mode 0600. The DefenseClaw gateway reads openclaw.json for the token only when that file is readable, which in this layout it usually is not.

Run setup and merge the block

Setup in this layout does not edit openclaw.json. It saves the block to merge in openclaw-merge.json in the DefenseClaw data folder. When it can read openclaw.json and the file lacks part of the DefenseClaw entry, setup fails, lists what is missing and prints the block on one line. For example:

{
  "plugins": {
    "load": { "paths": ["/opt/defenseclaw-openclaw/defenseclaw"] },
    "entries": {
      "defenseclaw": {
        "enabled": true,
        "hooks": { "allowConversationAccess": true },
        "config": {
          "tokenFile": "/etc/defenseclaw-openclaw/plugin.token",
          "sidecarHost": "127.0.0.1",
          "sidecarPort": 18970,
          "guardrailPort": 4000,
          "hookMode": "hybrid"
        }
      }
    }
  }
}
  • The hookMode line and the hooks grant are absent in proxy mode. An approvals.plugin block follows when human approval is on.
  • If your openclaw.json has a plugins.allow list, add defenseclaw to it. Do not create one: it is an exclusive allowlist.

The OpenClaw account, or an administrator, merges the block into openclaw.json and restarts the OpenClaw gateway. Then run defenseclaw setup openclaw --no-restart again and restart the DefenseClaw unit. defenseclaw status shows the hook mode only once the plugin has called the gateway; until then it reads unverified and names the step.

Install the two units

Before you enable the DefenseClaw unit, stop the gateway that defenseclaw init started (defenseclaw-gateway stop as the DefenseClaw account), so the unit starts it on the ports in config.yaml.

# /etc/systemd/system/defenseclaw-gateway.service
[Unit]
Description=DefenseClaw gateway
After=network-online.target

[Service]
Type=forking
User=defenseclaw
Group=defenseclaw
TimeoutStartSec=300
ExecStart=/usr/local/bin/defenseclaw-gateway start
ExecStop=/usr/local/bin/defenseclaw-gateway stop
Restart=on-failure

[Install]
WantedBy=multi-user.target
# /etc/systemd/system/openclaw-gateway.service
[Unit]
Description=OpenClaw gateway
After=defenseclaw-gateway.service
Wants=defenseclaw-gateway.service

[Service]
User=openclaw
Group=openclaw
ExecStart=/usr/local/bin/openclaw gateway run
# OpenClaw exits 0 when a config change needs a full restart.
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target

Adjust the paths to your install.

How the layout works

  • DefenseClaw writes no file in the OpenClaw home. Setup publishes the plugin credential to plugin_token_file. When the DefenseClaw account can read openclaw.json, setup also checks that the block is merged. It usually cannot, because OpenClaw rewrites the file with mode 0600 on every config change; setup then says it did not check the file.
  • The folder of plugin_token_file must exist, must not be a link, must be owned by the DefenseClaw account (never the OpenClaw account) and must not be writable by group or others.
  • The credential file is mode 0640, group plugin_token_group (required). Both accounts must be in that group, and it must not be a group every account is in (such as staff or users). DefenseClaw writes a temporary file and renames it over the target, so the plugin never reads half a token and a planted link is replaced, not followed.
  • The plugin cannot read config.yaml. It takes the gateway address, the guardrail proxy port and the credential file from its own entry in openclaw.json, and the mode, human approval, approval timeout, verdict wait and prompt gate from GET /api/v1/openclaw/runtime. Turning connectors.openclaw.hooks.prompt_gate on or off needs no change to openclaw.json.
  • The listener proof answers the DefenseClaw account and plugin_account, and the DefenseClaw gateway accepts an OpenClaw gateway that listens as plugin_account.

Run the gateway under the unit

The DefenseClaw unit starts the gateway the way defenseclaw setup and defenseclaw doctor expect: as a daemon with its gateway.pid. Do not run defenseclaw-gateway in the foreground from a unit; setup then reports that another process holds the gateway port.

  • Run defenseclaw setup and defenseclaw setup remove with --no-restart, then restart through systemd (sudo systemctl restart defenseclaw-gateway), so the gateway stays under the unit.
  • The gateway watchdog, which runs in the unit, starts a crashed gateway again within about a minute. With a daemonizing start, systemd does not track the gateway process itself.
  • Setup never restarts the OpenClaw gateway in this layout. Restart it as the OpenClaw account or with its unit.

defenseclaw-gateway start waits about a minute for the gateway to answer, and up to three minutes while its setup steps keep making progress. On a slow or busy host the command then prints STILL STARTING and leaves the gateway running. Run by systemd as the unit's ExecStart it exits 0, so the unit becomes active and Restart=on-failure does not loop. Run from a terminal, a script or as defenseclaw-gateway restart it exits 1. What a hook call does until the gateway answers is in the gateway outage table. Check defenseclaw-gateway status as the DefenseClaw account.

With SELinux enforcing (RHEL, Fedora), systemd cannot run a binary from a home folder: the unit fails with status=203/EXEC because the file does not have the bin_t label. Put defenseclaw-gateway outside a home folder, as the unit above does with /usr/local/bin:

  • Copy it with sudo install -m 0755 <path-to>/defenseclaw-gateway /usr/local/bin/. A mv from ~/.local/bin keeps the home label, so run sudo restorecon -v /usr/local/bin/defenseclaw-gateway after it.
  • Or label its folder: sudo semanage fcontext -a -t bin_t '/home/defenseclaw/.local/bin(/.*)?', then sudo restorecon -Rv /home/defenseclaw/.local/bin. semanage comes from policycoreutils-python-utils, which a minimal RHEL 9 does not install.
  • A chcon -t bin_t alone is lost at the next relabel.

Tear the layout down

  1. As the DefenseClaw account, run defenseclaw setup remove openclaw --yes --no-restart (add --force when OpenClaw is the only connector), then sudo systemctl restart defenseclaw-gateway, or defenseclaw-gateway connector teardown --connector openclaw. This deletes the published credential and openclaw-merge.json and prints which entries to remove. It does not touch openclaw.json. A setup that fails keeps openclaw-merge.json, because it is the block you merge before you run setup again.
  2. As the OpenClaw account or an administrator, remove plugins.entries.defenseclaw, defenseclaw from a plugins.allow list if you added it, and the plugin_dir path from plugins.load.paths, then restart the OpenClaw gateway. Until you do, the plugin has no credential and blocks every tool call.
  3. As an administrator, delete the plugin_dir folder when you no longer need it.

OpenClaw gateway token

The DefenseClaw gateway connects to the OpenClaw gateway over a WebSocket and signs in with the OpenClaw gateway token. This token is only for that connection. It is not the DefenseClaw API token (DEFENSECLAW_GATEWAY_TOKEN): the DefenseClaw API refuses it with 401, so an OpenClaw plugin or agent tool that reads openclaw.json cannot use it to allow a blocked tool or stop the gateway. Scripts that call the DefenseClaw API use DEFENSECLAW_GATEWAY_TOKEN.

DefenseClaw takes the token from OPENCLAW_GATEWAY_TOKEN (the gateway's environment, then ~/.defenseclaw/.env). Without it, DefenseClaw reads gateway.auth.token from openclaw.json:

  • A plain string is used as it is.
  • A secret reference with "source": "env" is read from that variable in the environment of the shell that runs init or setup.
  • DefenseClaw cannot read other secret sources, such as "source": "store". For those, init and setup print a warning and finish.

DefenseClaw refuses an env reference to a variable that holds one of its own credentials:

  • a key in ~/.defenseclaw/.env, other than OPENCLAW_GATEWAY_TOKEN and DEFENSECLAW_GATEWAY_TOKEN;
  • a variable named by an api_key_env setting;
  • a credential that defenseclaw keys list names, such as SPLUNK_ACCESS_TOKEN;
  • an LLM provider key name, such as OPENAI_API_KEY or AWS_BEARER_TOKEN_BEDROCK;
  • a name that starts with DEFENSECLAW_, or contains API_KEY, SECRET, PASSWORD, ACCESS_KEY, PRIVATE_KEY or SESSION_TOKEN.

DefenseClaw saves a token it reads to ~/.defenseclaw/.env (mode 0600) as OPENCLAW_GATEWAY_TOKEN. When OpenClaw rejects the token, DefenseClaw reads openclaw.json again and saves the new value under the same name only. If it could not read the token, give it yourself and restart the gateway:

defenseclaw keys set OPENCLAW_GATEWAY_TOKEN
defenseclaw-gateway restart

You can also set OPENCLAW_GATEWAY_TOKEN in the environment of the gateway. A config whose gateway.token_env is still OPENCLAW_GATEWAY_TOKEN makes defenseclaw doctor warn; defenseclaw doctor --fix changes it to DEFENSECLAW_GATEWAY_TOKEN.

Device pairing

DefenseClaw connects to the OpenClaw gateway as the operator client gateway-client. With token authentication (gateway.auth.mode: token, what install.sh and setup use) OpenClaw accepts the connection on the token and keeps no device record: openclaw devices list stays empty and no step is needed. DefenseClaw never writes OpenClaw's pairing files.

Device pairing applies only when OpenClaw pairs devices for the connection, for example a gateway without token authentication. OpenClaw then approves a new device on a loopback connection by itself. It asks you to approve it when:

  • the connection is not loopback;
  • gateway.nodes.pairing.autoApproveLocal is false;
  • a device asks for more scopes than OpenClaw approved.

DefenseClaw keeps retrying meanwhile. defenseclaw doctor and defenseclaw-gateway status show the device ID and the step:

openclaw devices list
openclaw devices approve REQUEST_ID

Run openclaw devices list right before you approve: OpenClaw gives a new request ID when the device retries with changed details.

OpenClaw operator scopes

DefenseClaw asks OpenClaw for these scopes:

ScopeWhat DefenseClaw uses it for
operator.readRead the config, tool catalog and skill status, and receive session events (sessions.subscribe).
operator.writeSend DefenseClaw security notices into a session (sessions.send).
operator.approvalsAnswer OpenClaw exec approvals (exec.approval.resolve).
operator.adminChange OpenClaw's config to disable a blocked skill, plugin or MCP server (config.patch, skills.update).

operator.admin is optional. With connectors.openclaw.operator_admin: false DefenseClaw asks for the other three only.

  • A blocked skill, plugin or MCP server is still refused by DefenseClaw admission and inspection, but OpenClaw is not told to disable it.
  • The alert and audit row say openclaw_remediation_unavailable, and defenseclaw status and defenseclaw doctor show OpenClaw remediation: off (no operator.admin). The same happens when OpenClaw refuses config.patch or skills.update for the missing scope.
  • With device pairing, approve a scope upgrade for the admin scope with openclaw devices approve, or set operator_admin: false and restart the gateway.

Bedrock through a VPC endpoint

When bedrock-runtime.<region>.amazonaws.com resolves to an AWS PrivateLink (VPC interface) endpoint, the proxy refuses the private address and every turn fails. The agent shows DefenseClaw refused a private LLM endpoint; if you trust it, run: defenseclaw guardrail allow-private-upstream <host>, and defenseclaw doctor warns with a Private upstream row. Allow the endpoint; the command restarts a running gateway:

defenseclaw guardrail allow-private-upstream bedrock-runtime.us-east-1.amazonaws.com