Skip to content

Add Go firewall logs parser mirroring JavaScript implementation#2350

Merged
pelikhan merged 6 commits intomainfrom
copilot/add-golang-firewall-parser
Oct 25, 2025
Merged

Add Go firewall logs parser mirroring JavaScript implementation#2350
pelikhan merged 6 commits intomainfrom
copilot/add-golang-firewall-parser

Conversation

Copy link
Contributor

Copilot AI commented Oct 25, 2025

Implements a Go firewall logs parser that extracts network access patterns from proxy logs, mirroring the existing JavaScript parser in pkg/workflow/js/parse_firewall_logs.cjs. Integrates into both logs and audit commands with structured output.

Implementation

Core Parser (pkg/cli/firewall_log.go)

  • Parses 10-field space-separated format: timestamp client_ip:port domain dest_ip:port proto method status decision url user_agent
  • Field-for-field validation matching JS regex patterns (timestamp, IP:port, domain, status, decision)
  • Classifies requests as allowed/denied based on status codes (200/206/304 vs 403/407) and proxy decisions (TCP_TUNNEL/TCP_HIT vs NONE_NONE/TCP_DENIED)
  • Aggregates per-domain statistics (allowed/denied counts)

Data Structures

  • FirewallAnalysis - structured analysis result with totals, domain lists, per-domain stats
  • FirewallLogSummary - aggregates across multiple workflow runs
  • DomainRequestStats - tracks allowed/denied counts per domain

Integration Points

  • Modified ProcessedRun, RunSummary, DownloadResult to include FirewallAnalysis
  • Added analyzeFirewallLogs() to artifact download pipeline (parallel to existing access log analysis)
  • Extended logs report with buildFirewallLogSummary() for cross-run aggregation
  • Automatic console/JSON rendering via struct tags

Example Output

Console:

🔥 Firewall Log Analysis
Total Requests   : 8
Allowed Requests : 5
Denied Requests  : 3

JSON:

{
  "firewall_log": {
    "total_requests": 8,
    "allowed_requests": 5,
    "denied_requests": 3,
    "allowed_domains": ["api.github.com:443", "pypi.org:443"],
    "denied_domains": ["blocked.example.com:443"],
    "requests_by_domain": {
      "api.github.com:443": {"allowed": 2, "denied": 0}
    }
  }
}

Testing

  • 17 unit tests covering valid/invalid field formats, malformed lines, partial fields
  • 2 integration tests for real-world parsing and multi-run aggregation
  • Smart caching in run_summary.json with version tracking

Reference: https://github.com/githubnext/gh-aw/actions/runs/18795259023

Original prompt

Here’s a cleaned and precise prompt for gh-aw:

Update the logs and the audit command to add a Golang base parser for the firewall logs. This parser should mirror the existing JavaScript firewall logs parser. It must extract firewall information into a structured object and attach it to the logs or audit result, which will then be rendered to console or JSON.

Key requirements:

  • Implement a Go (Golang) base parser for firewall logs.
  • Use the JavaScript firewall logs parser as a reference for fields, normalization, and error handling.
  • Output a structured object (strongly typed in Go) representing the parsed firewall data.
  • Integrate the structured object into:
    • logs pipeline (so it appears in logs output)
    • audit command result (so it appears in audit output)
  • Ensure both console rendering and JSON serialization include the new structured firewall data.
  • Add unit tests covering:
    • successful parses
    • malformed lines
    • partial/missing fields
  • Maintain backward compatibility for existing logs/audit outputs.
  • Provide minimal performance overhead when the parser is disabled/not applicable.
  • Include documentation/comments describing:
    • expected input format(s)
    • field mapping parity with the JavaScript parser
    • examples of console and JSON outputs

Deliverables:

  • Go parser implementation (package: logs or audit subpackage as appropriate).
  • Wiring into logs and audit command flows.
  • Tests for the parser and integration points.
  • Updates to any compile/lint workflows if new files or packages are added.

Uae this run https://github.com/githubnext/gh-aw/actions/runs/18795259023


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits October 25, 2025 00:26
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…commands

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update logs and audit command to add Golang firewall parser Add Go firewall logs parser mirroring JavaScript implementation Oct 25, 2025
Copilot AI requested a review from pelikhan October 25, 2025 00:51
@pelikhan pelikhan marked this pull request as ready for review October 25, 2025 00:54
Copilot AI review requested due to automatic review settings October 25, 2025 00:54
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

Copy link
Contributor

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 implements a Go firewall logs parser that mirrors the existing JavaScript implementation in pkg/workflow/js/parse_firewall_logs.cjs. The parser extracts network access patterns from proxy logs and integrates them into both the logs and audit commands with structured console and JSON output.

Key Changes:

  • Added comprehensive firewall log parsing with field-for-field validation matching JavaScript regex patterns
  • Implemented request classification (allowed/denied) based on status codes and proxy decisions
  • Integrated firewall analysis into artifact download pipeline with automatic aggregation across workflow runs

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/cli/firewall_log.go Core parser implementation with validation, classification, and analysis logic
pkg/cli/firewall_log_test.go Unit tests covering valid/invalid formats, malformed lines, and aggregation
pkg/cli/firewall_log_integration_test.go Integration tests for real-world parsing and multi-run aggregation
pkg/cli/logs_report.go Added FirewallLogSummary struct and buildFirewallLogSummary() function
pkg/cli/logs.go Integrated firewall analysis into ProcessedRun, RunSummary, and DownloadResult
pkg/cli/audit.go Added firewall log analysis to audit command workflow
docs/src/content/docs/reference/frontmatter-full.md Removed outdated firewall feature flag documentation
.github/workflows/research.lock.yml Updated JavaScript parser with enhanced validation
FIREWALL_LOG_PARSER_IMPLEMENTATION.md Comprehensive implementation documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 69bb819 into main Oct 25, 2025
53 checks passed
@pelikhan pelikhan deleted the copilot/add-golang-firewall-parser branch October 25, 2025 01:04
github-actions bot added a commit that referenced this pull request Oct 25, 2025
Update CLI documentation to reflect recent feature additions:

- Document firewall log parsing in --parse flag (PR #2349, #2350)
  - Logs and audit commands now generate firewall.md files
  - JSON output includes firewall analysis

- Update --dependabot documentation (PR #2359)
  - Added pip and Go ecosystem support
  - Clarified command detection patterns

- Add repository feature validation section (PR #2347)
  - Compile validates discussions/issues enabled
  - Prevents runtime failures for incompatible workflows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

3 participants