|
| 1 | +--- |
| 2 | +title: Domain Filtering |
| 3 | +description: Control network access with allowlists, blocklists, and wildcard patterns. |
| 4 | +--- |
| 5 | + |
| 6 | +Control which domains your AI agents can access using allowlists and blocklists. This guide covers all domain filtering options including wildcard patterns and file-based configuration. |
| 7 | + |
| 8 | +## How domain matching works |
| 9 | + |
| 10 | +Domains automatically match all subdomains: |
| 11 | + |
| 12 | +```bash |
| 13 | +# Allowing github.com permits: |
| 14 | +# ✓ github.com |
| 15 | +# ✓ api.github.com |
| 16 | +# ✓ raw.githubusercontent.com |
| 17 | +# ✗ example.com (not in allowlist) |
| 18 | + |
| 19 | +sudo awf --allow-domains github.com -- curl https://api.github.com |
| 20 | +``` |
| 21 | + |
| 22 | +:::tip |
| 23 | +You don't need to list every subdomain. Adding the base domain covers all subdomains automatically. |
| 24 | +::: |
| 25 | + |
| 26 | +## Allowlist options |
| 27 | + |
| 28 | +### Command-line flag |
| 29 | + |
| 30 | +Use `--allow-domains` with a comma-separated list: |
| 31 | + |
| 32 | +```bash |
| 33 | +sudo awf --allow-domains github.com,npmjs.org,googleapis.com -- <command> |
| 34 | +``` |
| 35 | + |
| 36 | +### File-based allowlist |
| 37 | + |
| 38 | +Use `--allow-domains-file` for managing large domain lists: |
| 39 | + |
| 40 | +```bash |
| 41 | +# Create a domains file |
| 42 | +cat > allowed-domains.txt << 'EOF' |
| 43 | +# GitHub domains |
| 44 | +github.com |
| 45 | +api.github.com |
| 46 | +
|
| 47 | +# NPM registry |
| 48 | +npmjs.org, registry.npmjs.org |
| 49 | +
|
| 50 | +# Wildcard patterns |
| 51 | +*.googleapis.com |
| 52 | +EOF |
| 53 | + |
| 54 | +# Use the file |
| 55 | +sudo awf --allow-domains-file allowed-domains.txt -- <command> |
| 56 | +``` |
| 57 | + |
| 58 | +**File format:** |
| 59 | +- One domain per line or comma-separated |
| 60 | +- Comments start with `#` (full line or inline) |
| 61 | +- Empty lines are ignored |
| 62 | +- Whitespace is trimmed |
| 63 | + |
| 64 | +### Combining methods |
| 65 | + |
| 66 | +You can use both flags together - domains are merged: |
| 67 | + |
| 68 | +```bash |
| 69 | +sudo awf \ |
| 70 | + --allow-domains github.com \ |
| 71 | + --allow-domains-file my-domains.txt \ |
| 72 | + -- <command> |
| 73 | +``` |
| 74 | + |
| 75 | +## Wildcard patterns |
| 76 | + |
| 77 | +Use `*` to match multiple domains: |
| 78 | + |
| 79 | +```bash |
| 80 | +# Match any subdomain of github.com |
| 81 | +--allow-domains '*.github.com' |
| 82 | + |
| 83 | +# Match api-v1.example.com, api-v2.example.com, etc. |
| 84 | +--allow-domains 'api-*.example.com' |
| 85 | + |
| 86 | +# Combine plain domains and wildcards |
| 87 | +--allow-domains 'github.com,*.googleapis.com,api-*.example.com' |
| 88 | +``` |
| 89 | + |
| 90 | +:::caution |
| 91 | +Use quotes around patterns to prevent shell expansion of `*`. |
| 92 | +::: |
| 93 | + |
| 94 | +**Pattern matching rules:** |
| 95 | + |
| 96 | +| Pattern | Matches | Does Not Match | |
| 97 | +|---------|---------|----------------| |
| 98 | +| `*.github.com` | `api.github.com`, `raw.github.com` | `github.com` | |
| 99 | +| `api-*.example.com` | `api-v1.example.com`, `api-test.example.com` | `api.example.com` | |
| 100 | +| `github.com` | `github.com`, `api.github.com` | `notgithub.com` | |
| 101 | + |
| 102 | +**Security restrictions:** |
| 103 | +- Overly broad patterns like `*`, `*.*`, or `*.*.*` are rejected |
| 104 | +- Patterns are case-insensitive (DNS is case-insensitive) |
| 105 | + |
| 106 | +## Blocklist options |
| 107 | + |
| 108 | +Block specific domains while allowing others. **Blocked domains take precedence over allowed domains.** |
| 109 | + |
| 110 | +### Basic blocklist usage |
| 111 | + |
| 112 | +```bash |
| 113 | +# Allow example.com but block internal.example.com |
| 114 | +sudo awf \ |
| 115 | + --allow-domains example.com \ |
| 116 | + --block-domains internal.example.com \ |
| 117 | + -- curl https://api.example.com # ✓ allowed |
| 118 | + |
| 119 | +sudo awf \ |
| 120 | + --allow-domains example.com \ |
| 121 | + --block-domains internal.example.com \ |
| 122 | + -- curl https://internal.example.com # ✗ blocked |
| 123 | +``` |
| 124 | + |
| 125 | +### Blocklist with wildcards |
| 126 | + |
| 127 | +```bash |
| 128 | +# Allow all of example.com except internal-* subdomains |
| 129 | +sudo awf \ |
| 130 | + --allow-domains example.com \ |
| 131 | + --block-domains 'internal-*.example.com' \ |
| 132 | + -- curl https://api.example.com # ✓ allowed |
| 133 | + |
| 134 | +# Allow broad pattern, block sensitive subdomains |
| 135 | +sudo awf \ |
| 136 | + --allow-domains '*.example.com' \ |
| 137 | + --block-domains '*.secret.example.com' \ |
| 138 | + -- curl https://api.example.com # ✓ allowed |
| 139 | +``` |
| 140 | + |
| 141 | +### File-based blocklist |
| 142 | + |
| 143 | +```bash |
| 144 | +# Create a blocklist file |
| 145 | +cat > blocked-domains.txt << 'EOF' |
| 146 | +# Internal services that should never be accessed |
| 147 | +internal.example.com |
| 148 | +admin.example.com |
| 149 | +
|
| 150 | +# Block all subdomains of sensitive.org |
| 151 | +*.sensitive.org |
| 152 | +EOF |
| 153 | + |
| 154 | +# Use the blocklist file |
| 155 | +sudo awf \ |
| 156 | + --allow-domains example.com,sensitive.org \ |
| 157 | + --block-domains-file blocked-domains.txt \ |
| 158 | + -- <command> |
| 159 | +``` |
| 160 | + |
| 161 | +### Combining all options |
| 162 | + |
| 163 | +```bash |
| 164 | +sudo awf \ |
| 165 | + --allow-domains github.com \ |
| 166 | + --allow-domains-file allowed.txt \ |
| 167 | + --block-domains internal.github.com \ |
| 168 | + --block-domains-file blocked.txt \ |
| 169 | + -- <command> |
| 170 | +``` |
| 171 | + |
| 172 | +## Common use cases |
| 173 | + |
| 174 | +### AI agent with API access |
| 175 | + |
| 176 | +Allow an AI agent to access specific APIs while blocking internal services: |
| 177 | + |
| 178 | +```bash |
| 179 | +sudo awf \ |
| 180 | + --allow-domains 'api.openai.com,*.github.com' \ |
| 181 | + --block-domains 'internal.github.com,admin.github.com' \ |
| 182 | + -- npx @github/copilot@latest --prompt "Analyze this code" |
| 183 | +``` |
| 184 | + |
| 185 | +### CI/CD pipeline restrictions |
| 186 | + |
| 187 | +Restrict network access during builds: |
| 188 | + |
| 189 | +```bash |
| 190 | +sudo awf \ |
| 191 | + --allow-domains npmjs.org,registry.npmjs.org,github.com \ |
| 192 | + --block-domains-file ci-blocklist.txt \ |
| 193 | + -- npm install && npm test |
| 194 | +``` |
| 195 | + |
| 196 | +### MCP server isolation |
| 197 | + |
| 198 | +Test MCP servers with controlled network access: |
| 199 | + |
| 200 | +```bash |
| 201 | +sudo awf \ |
| 202 | + --allow-domains arxiv.org,api.github.com \ |
| 203 | + -- npx @github/copilot@latest \ |
| 204 | + --mcp-server ./my-mcp-server.js \ |
| 205 | + --prompt "Search for papers" |
| 206 | +``` |
| 207 | + |
| 208 | +## Normalization |
| 209 | + |
| 210 | +Domains are normalized before matching: |
| 211 | + |
| 212 | +- **Case-insensitive**: `GitHub.COM` = `github.com` |
| 213 | +- **Whitespace trimmed**: `" github.com "` = `github.com` |
| 214 | +- **Trailing dots removed**: `github.com.` = `github.com` |
| 215 | +- **Protocols stripped**: `https://github.com` = `github.com` |
| 216 | + |
| 217 | +```bash |
| 218 | +# These are all equivalent |
| 219 | +--allow-domains github.com |
| 220 | +--allow-domains " GitHub.COM. " |
| 221 | +--allow-domains "https://github.com" |
| 222 | +``` |
| 223 | + |
| 224 | +## Debugging domain filtering |
| 225 | + |
| 226 | +### Enable debug logging |
| 227 | + |
| 228 | +See which domains are being allowed or blocked: |
| 229 | + |
| 230 | +```bash |
| 231 | +sudo awf \ |
| 232 | + --allow-domains github.com \ |
| 233 | + --block-domains internal.github.com \ |
| 234 | + --log-level debug \ |
| 235 | + -- <command> |
| 236 | +``` |
| 237 | + |
| 238 | +### Check Squid logs |
| 239 | + |
| 240 | +View traffic decisions after execution: |
| 241 | + |
| 242 | +```bash |
| 243 | +# Find blocked requests |
| 244 | +sudo grep "TCP_DENIED" /tmp/squid-logs-*/access.log |
| 245 | + |
| 246 | +# Find allowed requests |
| 247 | +sudo grep "TCP_TUNNEL" /tmp/squid-logs-*/access.log |
| 248 | +``` |
| 249 | + |
| 250 | +### Use the logs command |
| 251 | + |
| 252 | +```bash |
| 253 | +# View recent traffic with formatting |
| 254 | +awf logs |
| 255 | + |
| 256 | +# Filter to blocked requests only |
| 257 | +awf logs --format json | jq 'select(.isAllowed == false)' |
| 258 | +``` |
| 259 | + |
| 260 | +## See also |
| 261 | + |
| 262 | +- [CLI Reference](/gh-aw-firewall/reference/cli-reference) - Complete option documentation |
| 263 | +- [Security Architecture](/gh-aw-firewall/reference/security-architecture) - How filtering works |
0 commit comments