The Complete Production SOP: How to Deploy and Run UFW (Uncomplicated Firewall) Host Security Policies in Autonomous AI Agents
Deploy and automate UFW host security policies in Codex, Claude Code, & Cursor. Master SSH rate limiting, CIDR allowlists, and lockout prevention SOPs.
Technical Overview & Architectural Context
Autonomous DevOps agents managing Linux host security frequently make fatal configuration errors when interacting with UFW directly. The most common catastrophic failure occurs when an agent executes 'ufw enable' before explicitly whitelisting the active administrative port, instantly terminating SSH sessions and severing remote management access. Furthermore, without deterministic constraints, agents routinely introduce insecure catch-all rules like 'ufw allow any', fail to enforce CIDR-restricted boundaries for critical database backends (e.g., PostgreSQL or Redis), and omit connection rate limiting needed to mitigate brute-force attempts. The ufw-uncomplicated-firewall-rules skill injects a strict procedural safeguard into agent context. It forces runtimes such as Codex, Claude Code, Cursor, and Windsurf to execute a battle-tested sequence: enforce default-deny incoming policies, verify active SSH bindings with rate limiting ('ufw limit 22/tcp' or 'ufw allow OpenSSH'), apply precise subnet masks to private interfaces, and validate the ruleset using 'ufw status numbered' prior to final deployment. This eliminates server lockouts and configuration drift in automated CI/CD and host-provisioning pipelines.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into agent runtime search paths.
Autonomous coding assistants inspect standardized skill directories (`.agents/skills`, `.claude/skills`, or `.cursor/rules`) to match natural language triggers against task definitions. In this step, we pull the authoritative SKILL.md file directly into your workspace or user-level agent profile.
mkdir -p ~/.agents/skills/ufw-uncomplicated-firewall-rules && cat <<'EOF' > ~/.agents/skills/ufw-uncomplicated-firewall-rules/SKILL.md
---
name: "ufw-uncomplicated-firewall-rules"
description: "Configure, manage, and verify simple host-based Linux firewall policies via UFW."
metadata:
author: "Canonical"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "setup ufw firewall"
- "rate limit ssh ufw"
- "ufw allow from ip"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---
# UFW (Uncomplicated Firewall) Host Security Policies
Administers Ubuntu/Debian firewalls with UFW: default deny policies, opening ports with service profiles (OpenSSH, Nginx Full), IP CIDR allowlists, rate limiting SSH brute-force attempts, and auditing ufw status numbered.
## Execution SOP & Rules
1. Set baseline policies: `ufw default deny incoming` && `ufw default allow outgoing`.
2. Allow SSH before enabling firewall: `ufw allow OpenSSH` or `ufw limit 22/tcp`.
3. Allow specific IP access: `ufw allow from <trusted_ip> to any port <port> proto tcp`.
4. Enable firewall: `ufw --force enable` and inspect rules: `ufw status verbose numbered`.
EOF---
name: "ufw-uncomplicated-firewall-rules"
description: "Configure, manage, and verify simple host-based Linux firewall policies via UFW."
metadata:
author: "Canonical"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "setup ufw firewall"
- "rate limit ssh ufw"
- "ufw allow from ip"
---Mounting the skill at the project root (`./.cursor/rules` or `./.agents/skills`) rather than globally prevents cross-project context pollution and limits token consumption to devops tasks.
Ensure that `shell_exec` is enabled for system firewall provisioning scripts, but leave `net_access: false` inside the agent skill sandbox to prevent outbound command injection.
Configuring Trusted Subnets & Environmental Parameters
Declare VPC subnets, bastion IPs, and custom SSH ports safely using environment files without hardcoding infrastructure secrets.
Firewall rules must dynamically reference environment-specific subnets (e.g., VPC CIDR blocks, database client IPs) rather than relying on guessed default values. Inject these values via an environment file that the agent reads during variable substitution.
cat <<'EOF' >> .env.firewall
BASTION_IP="203.0.113.15"
VPC_CIDR="10.0.1.0/24"
SSH_PORT="22"
POSTGRES_PORT="5432"
EOF
echo ".env.firewall" >> .gitignoreUse strict CIDR notations (e.g., /32 for single host, /24 for subnets) in .env files to prevent autonomous agents from defaulting to broad 0.0.0.0/0 exposure.
Always append `.env.firewall` to `.gitignore`. Committing internal IP topology and port allocations creates an architectural reconnaissance vector for attackers.
Intent Matching & Trigger Invocation
Invoke deterministic firewall orchestration using natural language prompts matched against SKILL.md triggers.
Agent runtimes match semantic intent to the frontmatter triggers (`setup ufw firewall`, `rate limit ssh ufw`, `ufw allow from ip`). Prompting the agent with matching terminology guarantees immediate loading of the SOP and enforces step-by-step verification.
Include the phrase 'setup ufw firewall' or 'rate limit ssh ufw' verbatim in your prompt to trigger the deterministic SOP and skip hallucinated rule orders.
Never prompt with 'enable ufw right now'. This can lead LLMs to issue `ufw enable` before parsing network interfaces, causing an immediate SSH lockout.
Verification, Linting & Output Quality Gate
Run deterministic dry-run audits and verify numbered status tables before finalizing configuration changes.
The skill mandates executing verification checks using `ufw status numbered` and checking `/etc/default/ufw` to guarantee that IPv6 settings and packet forwarding rules match security baselines.
sudo ufw status verbose && sudo ufw status numberedRequest the agent to output the status list in numbered format so individual rules can be audited and cleanly removed using `ufw delete <number>` without index mismatches.
Check `/etc/ufw/ufw.conf` after agent updates. If `ENABLED=no`, the rules are registered in iptables tables but are inactive upon reboot.
Real-World Scenario: Automating Production Bastion & PostgreSQL Firewall Isolation
“setup ufw firewall for our production web node: enforce default deny incoming, rate limit ssh on port 22, allow incoming traffic on ports 80 and 443 for web clients, and ufw allow from ip 10.0.1.50 to any port 5432 proto tcp for our reporting database.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to query or modify firewall state through UFW without root privileges or a configured sudoers grant.
echo "$USER ALL=(ALL) NOPASSWD: /usr/sbin/ufw" | sudo tee /etc/sudoers.d/ufw-agent-access && sudo chmod 0440 /etc/sudoers.d/ufw-agent-accessRoot Cause: The agent executed `ufw enable` interactively in a non-interactive TTY subshell, causing the process to hang indefinitely waiting for STDIN.
sudo ufw --force enableFrequently Asked Questions (UFW (Uncomplicated Firewall) Host Security Policies SOP)
Q:Can I use UFW (Uncomplicated Firewall) Host Security Policies across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the open SKILL.md specification. You can place the file in project-level `.agents/skills/` or runtime-specific locations like `.cursor/rules/` to ensure Codex, Claude Code CLI, Cursor, and Windsurf all parse the exact same SOP.
Q:How does UFW (Uncomplicated Firewall) Host Security Policies prevent context window overflow during long agent sessions?
The skill encapsulates rules in compact imperative instructions rather than raw iptables configuration dumps. By enforcing structured status outputs (`ufw status numbered`), the agent only consumes tokens for concise tabular lines instead of thousands of verbose iptables chains.
Q:Does this skill require escalated root or container permissions?
Yes, system firewall manipulation requires root access on the Linux host. However, the skill has a 98/100 Security Score because its instructions restrict execution to safe UFW commands and recommend using scoped sudoers entries rather than granting unrestricted root shell access to the agent.
Ready to equip your autonomous agent with UFW (Uncomplicated Firewall) Host Security Policies?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.