Comprehensive tutorial series for OpenClaw AI agent gateway
Best practices for maintaining security in a multi-user OpenClaw deployment.
Already covered, but worth repeating:
{
session: {
dmScope: "per-channel-peer", // REQUIRED
},
}
Memory files can contain sensitive information. Control access:
{
agents: {
defaults: {
memorySearch: {
// Only search in main/private sessions
scope: {
default: "deny",
rules: [
{ action: "allow", match: { chatType: "direct" } },
],
},
},
},
},
}
Limit what sessions an agent can see:
{
tools: {
sessions: {
// "self" — only current session
// "tree" — current + spawned sub-agents (default)
// "agent" — all sessions for this agent
// "all" — all sessions (dangerous!)
visibility: "tree",
},
},
}
In multi-user deployments:
{
tools: {
sessions: {
visibility: "self", // Most restrictive
},
},
}
Start with pairing, then lock down:
{
channels: {
telegram: {
// New users go through pairing
dmPolicy: "pairing",
// After approval, add to permanent allowlist
// (optional, for faster reconnection)
allowFrom: [
"123456789", // Approved user 1
"987654321", // Approved user 2
],
},
},
}
Control who can trigger the bot in groups:
{
channels: {
telegram: {
groupPolicy: "allowlist",
groupAllowFrom: ["123456789"], // Only this user can trigger in groups
groups: {
"-1001234567890": {
// Per-group override
allowFrom: ["123456789", "555555555"],
},
},
},
},
}
Route different forum topics to different agents:
{
channels: {
telegram: {
groups: {
"-1001234567890": {
topics: {
"1": { agentId: "main" }, // General
"3": { agentId: "support" }, // Support requests
"5": { agentId: "admin" }, // Admin only
},
},
},
},
},
}
{
tools: {
// Base profile
profile: "coding", // fs, runtime, sessions, memory
// Explicit denials
deny: [
"browser", // No browser automation
"exec", // No shell commands (use bash instead)
"group:automation", // No cron/gateway tools
],
},
}
{
agents: {
list: [
{
id: "support",
tools: {
profile: "messaging", // Only messaging tools
deny: ["group:fs"], // No file access
},
},
{
id: "coder",
tools: {
profile: "coding",
allow: ["browser"], // This agent can use browser
},
},
],
},
}
Run agents in restricted environments:
{
agents: {
list: [
{
id: "untrusted",
sandbox: {
enabled: true,
workspaceAccess: "rw", // "rw" | "ro" | "none"
network: "restricted", // "full" | "restricted" | "none"
tools: {
deny: ["exec", "process"],
},
},
},
],
},
}
Require human approval for dangerous commands:
{
tools: {
exec: {
approvals: {
enabled: true,
policy: "allowlist", // "allowlist" | "always" | "never"
allowlist: [
"git status",
"git diff",
"npm test",
],
},
},
},
channels: {
telegram: {
execApprovals: {
enabled: true,
approvers: ["123456789"], // Only these users can approve
target: "dm", // Send approval requests to DM
},
},
},
}
MEMORY.md should only load in private sessions:
// This is default behavior, but worth understanding:
// MEMORY.md is loaded only in "main session" (direct chat with owner)
// It is NOT loaded in:
// - Group chats
// - Shared sessions
// - Sub-agent runs (unless explicitly passed)
{
agents: {
defaults: {
memorySearch: {
scope: {
default: "deny",
rules: [
// Allow in DMs only
{ action: "allow", match: { chatType: "direct" } },
// Deny in specific channels
{ action: "deny", match: { keyPrefix: "discord:channel:" } },
],
},
},
},
},
}
{
logging: {
level: "info", // "debug" for more detail
// Log security-relevant events
events: {
sessionCreate: true,
sessionAccess: true,
toolExecution: true,
approvalRequests: true,
},
},
}
# Watch for security events
openclaw logs --follow | grep -E "(auth|session|approval|denied)"
# Export logs for review
openclaw logs --since "24h" --output audit.log
# Suspicious patterns:
# - Same session accessed by different IPs
# - Repeated auth failures
# - Unusual tool usage patterns
# - Cross-session tool calls
grep -E "(denied|unauthorized|failed)" ~/.openclaw/logs/*.log
session.dmScope set to per-channel-peer or stricterdmPolicy set to pairing or allowlistgroupPolicy set to allowlist (not open)// ❌ DANGEROUS
{
channels: {
telegram: {
groupPolicy: "open",
groups: { "*": { requireMention: false } },
},
},
}
// ✅ SAFER
{
channels: {
telegram: {
groupPolicy: "allowlist",
groupAllowFrom: ["trusted_user_id"],
groups: {
"-specific_group": { requireMention: true },
},
},
},
}
// ❌ DANGEROUS — any user can browse all sessions
{
tools: {
sessions: { visibility: "all" },
},
}
// ✅ SAFER
{
tools: {
sessions: { visibility: "self" },
},
}
// ❌ DANGEROUS — agent can run any command
{
tools: {
profile: "full",
},
}
// ✅ SAFER
{
tools: {
profile: "coding",
exec: {
approvals: { enabled: true, policy: "allowlist" },
},
},
}
# 1. Stop gateway immediately
openclaw gateway stop
# 2. Check recent sessions
openclaw sessions list
# 3. Review logs for cross-session access
grep "session" ~/.openclaw/logs/*.log | tail -100
# 4. Identify affected sessions
# 5. Notify affected users if necessary
# 6. Fix configuration
# 7. Restart with tightened security
# 1. Rotate key at provider (OpenAI, Anthropic, etc.)
# 2. Update environment variable
export ANTHROPIC_API_KEY="new-key"
# 3. Restart gateway
openclaw gateway restart
# 4. Review logs for unauthorized usage
| Area | Recommended Setting |
|---|---|
| Session isolation | dmScope: "per-channel-peer" |
| DM access | dmPolicy: "pairing" |
| Group access | groupPolicy: "allowlist" |
| Session visibility | visibility: "self" or "tree" |
| Tool profile | "coding" or "messaging" (not "full") |
| Exec approvals | enabled: true |
You’ve completed Session Management! Continue to Memory Systems to learn about building effective long-term memory →