Skip to content

Conversation

@Mossaka
Copy link
Collaborator

@Mossaka Mossaka commented Oct 23, 2025

  • Update installation instructions and wrapper script for awf
  • clean up unused github actions
  • refactor: remove end-to-end tests for firewall and add unit tests for CLI, Docker manager, and host iptables
  • feat: add comprehensive firewall robustness test suite and GitHub Actions workflow

Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
… CLI, Docker manager, and host iptables

Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
…ions workflow

Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
@Mossaka Mossaka requested a review from Copilot October 23, 2025 03:16
Comment on lines +15 to +114
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: |
npm install
npm run build

- name: Make wrapper available globally with sudo
run: |
# Create sudo wrapper script for iptables manipulation
sudo tee /usr/local/bin/awf > /dev/null <<EOF
#!/bin/bash
exec $(which node) $GITHUB_WORKSPACE/dist/cli.js "\$@"
EOF
sudo chmod +x /usr/local/bin/awf
which awf
awf --version

- name: Pull required Docker images
run: |
echo "Pulling images to avoid timeouts during tests..."
docker pull curlimages/curl:latest
docker pull alpine:latest
docker pull dannydirect/tinyproxy:latest

- name: Run robustness test suite
run: |
chmod +x scripts/ci/test-firewall-robustness.sh
sudo ./scripts/ci/test-firewall-robustness.sh

- name: Cleanup awf resources
if: always()
run: |
chmod +x scripts/ci/cleanup.sh
sudo ./scripts/ci/cleanup.sh || true

- name: Upload test logs
if: always()
uses: actions/upload-artifact@v4
with:
name: robustness-test-logs
path: |
/tmp/firewall-test-*.log
/tmp/firewall-obs-test.log
/tmp/copilot-logs-*
/tmp/squid-logs-*
if-no-files-found: warn

- name: Test Summary
if: always()
run: |
echo "=========================================="
echo "Firewall Robustness Test Suite"
echo "=========================================="
echo ""
echo "This test validates comprehensive security scenarios:"
echo ""
echo "Test Categories:"
echo " 1. Happy-path basics (exact domains, subdomains, case insensitivity)"
echo " 2. Deny cases (IP literals, non-standard ports, SSH blocking)"
echo " 3. Redirect behavior (cross-domain vs same-domain)"
echo " 4. Protocol edges (HTTP/2, bypass attempts, DoH, metadata endpoints)"
echo " 5. IPv4/IPv6 parity"
echo " 6. Git operations (HTTPS allowed, SSH blocked)"
echo " 7. Security corner cases (SNI/Host mismatch, multicast)"
echo " 8. Docker container egress:"
echo " - Basic egress control"
echo " - Network modes (bridge, host, none)"
echo " - DNS controls"
echo " - Proxy pivot attempts"
echo " - Container-to-container bounce"
echo " - UDP, QUIC, multicast"
echo " - Metadata protection"
echo " - Privilege abuse (NET_ADMIN, privileged)"
echo " - SNI/Host mismatch"
echo " - Custom networks"
echo " - Build-time egress"
echo " - IPv6 from containers"
echo " 9. Observability (audit log validation)"
echo ""
echo "Key security validations:"
echo " - L7 filtering for HTTP/HTTPS traffic"
echo " - Host header spoofing protection"
echo " - Container network isolation"
echo " - Metadata endpoint blocking (AWS/GCP)"
echo " - Privilege escalation prevention"
echo " - Comprehensive audit logging"
echo ""
echo "Test logs uploaded as artifacts (if generated)"
echo "=========================================="

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 3 months ago

The most effective fix is to add a permissions block to this workflow, preferably at the root level (just below the workflow on: block) so that it applies to all jobs unless a job-specific override is specified. For this workflow, the minimum required permission is usually contents: read, since it checks out code and uploads artifacts but does not need to write to repository contents, issues, or pull requests. This can be done in .github/workflows/test-firewall-robustness.yml by inserting typically:

permissions:
  contents: read

on a new line after the on: section (after line 12). This limits the GITHUB_TOKEN permissions for all jobs, adhering to least privilege.

No new library imports or definitions are needed; this is a YAML configuration change only.


Suggested changeset 1
.github/workflows/test-firewall-robustness.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/test-firewall-robustness.yml b/.github/workflows/test-firewall-robustness.yml
--- a/.github/workflows/test-firewall-robustness.yml
+++ b/.github/workflows/test-firewall-robustness.yml
@@ -10,6 +10,9 @@
     # Run daily at 2 AM UTC to catch any regressions
     - cron: '0 2 * * *'
 
+permissions:
+  contents: read
+
 jobs:
   robustness-tests:
     runs-on: ubuntu-latest
EOF
@@ -10,6 +10,9 @@
# Run daily at 2 AM UTC to catch any regressions
- cron: '0 2 * * *'

permissions:
contents: read

jobs:
robustness-tests:
runs-on: ubuntu-latest
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive integration test suite for firewall robustness and refactors the test infrastructure. The changes remove end-to-end tests in favor of unit tests for core components, add a new robustness test script covering extensive security scenarios, clean up unused GitHub Actions workflows, and update documentation to reflect the new testing approach.

Key changes:

  • Added unit tests for CLI, Docker manager, and host iptables components
  • Introduced comprehensive firewall robustness test suite with 50+ test scenarios
  • Removed obsolete end-to-end and integration test files
  • Cleaned up 6 unused GitHub Actions workflows

Reviewed Changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/host-iptables.test.ts New unit tests for host iptables functionality
src/docker-manager.test.ts New unit tests for Docker manager and compose generation
src/cli.test.ts New unit tests for CLI argument parsing and validation
src/tests/firewall.e2e.test.ts Removed end-to-end firewall tests
src/tests/cli.test.ts Removed old CLI integration tests
src/tests/cli.integration.test.ts Removed old CLI integration tests
scripts/ci/test-firewall-robustness.sh New comprehensive robustness test script with 50+ scenarios
scripts/ci/README.md Updated documentation for new test script
docs/QUICKSTART.md Updated documentation references
README.md Updated installation instructions
CLAUDE.md Updated wrapper script setup with improved clarity
.github/workflows/test-firewall-robustness.yml New workflow for robustness tests
.github/workflows/*.yml Removed 6 obsolete workflow files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if [[ $exit_code -ne 0 ]]; then
# Check for test setup errors first (these should cause the test to fail)
# Exclude matches from the "[entrypoint] Executing command:" line to avoid false positives
if grep -v "^\[entrypoint\] Executing command:" "$log_file" 2>/dev/null | grep -qiE "Failed to resolve IP|Couldn't parse CURLOPT_RESOLVE|command not found"; then
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The complex grep pipeline with regex patterns should be extracted into a helper function for better readability and maintainability. Consider creating a check_test_setup_error function.

Copilot uses AI. Check for mistakes.

# Verify it was blocked (not a different error)
# Note: HTTP 400 errors from Squid often indicate blocked IP literal access
if grep -qiE "denied|forbidden|403|ERR_ACCESS_DENIED|connection.*refused|proxy.*error|timeout|timed out|Empty reply|Failed to connect|Connection reset|Could not resolve host|error: 400|returned error: 400" "$log_file" 2>/dev/null; then
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The lengthy regex pattern for detecting blocked requests is hard to maintain. Consider defining these patterns as an array at the top of the script for easier modification and documentation of each pattern's purpose.

Copilot uses AI. Check for mistakes.
@Mossaka
Copy link
Collaborator Author

Mossaka commented Oct 24, 2025

@copilot the integration test failed with

Pre-test cleanup...

==========================================
Cleaning up Docker resources...
==========================================
===========================================
Cleaning up awf resources
===========================================
Removing awf containers by name...
Stopping docker compose services...
Cleaning up host-level iptables rules...
Removing awf-net network...
Pruning unused containers...
Total reclaimed space: 0B
Pruning unused networks...
Removing temporary work directories...
✓ Cleanup complete
===========================================

==========================================
Firewall Robustness Test Suite
==========================================
Base allowed domains: github.com,api.github.com,httpbin.org


==========================================
1. HAPPY-PATH BASICS
==========================================

[TEST] Allow exact domain
  Allowed: github.com
  Command: curl -fsS https://github.com/robots.txt
  Expected: SUCCESS
  ✗ FAIL - Command failed with exit code 124
  Log: /tmp/firewall-test-allow-exact-domain.log

==========================================
Cleaning up Docker resources...
==========================================
===========================================
Cleaning up awf resources
===========================================
Removing awf containers by name...
Stopping docker compose services...
Cleaning up host-level iptables rules...
  - Removing FW_WRAPPER rules from DOCKER-USER chain...
Chain FW_WRAPPER (0 references)
target     prot opt source               destination         
  - Removing FW_WRAPPER chain...
Removing awf-net network...
awf-net
Pruning unused containers...
Total reclaimed space: 0B
Pruning unused networks...
Removing temporary work directories...
✓ Cleanup complete
===========================================
Error: Process completed with exit code 1.

can you please fix it

Copy link
Contributor

Copilot AI commented Oct 24, 2025

@Mossaka I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you.

@Mossaka Mossaka merged commit b7ddd6f into main Oct 27, 2025
5 of 6 checks passed
@Mossaka Mossaka deleted the mossaka/test branch October 27, 2025 18:06
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