Skip to content

Comments

fix(security): harden installation with scoped sudo, fail2ban, and auto-updates#11

Merged
alauppe merged 2 commits intoopenclaw:mainfrom
alauppe:fix/security-hardening
Feb 6, 2026
Merged

fix(security): harden installation with scoped sudo, fail2ban, and auto-updates#11
alauppe merged 2 commits intoopenclaw:mainfrom
alauppe:fix/security-hardening

Conversation

@alauppe
Copy link
Member

@alauppe alauppe commented Feb 1, 2026

Summary

This PR addresses critical security concerns in the recommended installation method.

Critical Fixes

1. Scoped Sudo Access (was: full NOPASSWD root)

Before:

clawdbot ALL=(ALL) NOPASSWD: ALL

After:

clawdbot ALL=(ALL) NOPASSWD: /usr/bin/systemctl start clawdbot
clawdbot ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop clawdbot
clawdbot ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart clawdbot
# ... etc (only service management + tailscale)

Why: If the Clawdbot application were compromised, the attacker previously had full root access. Now they can only manage the clawdbot service.

2. Dynamic UID in Systemd Template (was: hardcoded 1000)

Before:

Environment="XDG_RUNTIME_DIR=/run/user/1000"

After:

Environment="XDG_RUNTIME_DIR=/run/user/{{ clawdbot_uid_value | default('1000') }}"

Why: UID 1000 is not guaranteed. If clawdbot user gets a different UID, the service would fail.

New Security Features

3. Fail2ban for SSH Protection

  • Installed and configured automatically
  • 5 failed SSH attempts → 1 hour ban
  • Protects against brute-force attacks on the exposed SSH port

4. Unattended-Upgrades for Automatic Security Updates

  • Security-only updates enabled
  • Automatic reboots disabled (admin controls when to reboot)
  • Reduces time window for known vulnerabilities

Documentation Updates

  • docs/security.md: Expanded to document all 8 security layers with verification commands
  • README.md: Updated features list and added security note about auditing before production use
  • AGENTS.md: Added security rationale and documented known limitations

Known Limitations (Documented)

These are noted in documentation but not fixed in this PR:

Issue Status Notes
macOS incomplete Documented No launchd/pf, needs testing
IPv6 disabled Documented Review if network uses IPv6
curl|bash pattern Documented Recommend clone+audit for production

Testing

  • YAML syntax validated
  • Reviewed against Ansible best practices
  • Tested on fresh Debian 12 VM
  • Tested on fresh Ubuntu 22.04 VM
  • Verified fail2ban activates
  • Verified unattended-upgrades configured
  • Verified scoped sudo works for service management
  • Verified Tailscale commands work with new sudo rules

Files Changed

  • roles/clawdbot/tasks/user.yml - Scoped sudo permissions
  • roles/clawdbot/tasks/firewall-linux.yml - Added fail2ban + unattended-upgrades
  • roles/clawdbot/handlers/main.yml - Added fail2ban restart handler
  • roles/clawdbot/templates/clawdbot-host.service.j2 - Dynamic UID, updated description
  • docs/security.md - Comprehensive security documentation
  • README.md - Updated features and security note
  • AGENTS.md - Security rationale and limitations

T5-AndyML and others added 2 commits January 31, 2026 19:29
…to-updates

Security improvements:

1. CRITICAL: Scope sudo access for clawdbot user
   - Changed from 'ALL=(ALL) NOPASSWD: ALL' to specific commands only
   - Now limited to: systemctl for clawdbot service, tailscale, journalctl
   - Prevents full root compromise if application is exploited

2. CRITICAL: Fix hardcoded UID in systemd template
   - Changed XDG_RUNTIME_DIR from /run/user/1000 to dynamic
   - Uses clawdbot_uid_value variable with fallback

3. Add fail2ban for SSH brute-force protection
   - 5 failed attempts = 1 hour ban
   - Protects against automated attacks on exposed SSH

4. Add unattended-upgrades for automatic security updates
   - Security-only updates enabled by default
   - Automatic reboots disabled (manual control)

5. Update documentation
   - security.md: Document all 8 security layers
   - README.md: Add security features to list
   - AGENTS.md: Document security rationale and known limitations

Known limitations documented:
- macOS support incomplete (no launchd/pf)
- IPv6 disabled in Docker
- curl|bash pattern inherent risks

Signed-off-by: Andrew Lauppe <andy@t5tele.com>
- Add documentation to sudoers explaining security rationale
- Include instructions for operators to expand permissions if needed
- Scope tailscale to: status, up, down, ip, version, ping, whois
- Add note about up/down allowing flags like --advertise-exit-node
- Document daemon-reload affecting all units
- Remove redundant fail2ban config (logpath, duplicate maxretry/bantime)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alauppe alauppe merged commit b75be9f into openclaw:main Feb 6, 2026
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.

2 participants