Skip to content

fix(sans): count only network interfaces as zones for SANS-FW-003 - #1024

Open
intigenesis wants to merge 5 commits into
EvilBit-Labs:mainfrom
intigenesis:fix/sans-fw-003-network-zones
Open

intigenesis wants to merge 5 commits into
EvilBit-Labs:mainfrom
intigenesis:fix/sans-fw-003-network-zones

Conversation

@intigenesis

Copy link
Copy Markdown
Collaborator

Pull Request

Description

OPNsense writes pseudo-interfaces into <interfaces> on every save (plugins_interfaces in plugins.inc): lo0 always, one entry per interface group, the OpenVPN and WireGuard group entries while those services run, and enc0 while IPsec does. Each is enabled and marked <virtual>1</virtual>. SANS-FW-003 (Network Zone Separation) counted every enabled interface, so lo0 made a firewall whose only network is WAN pass. The interface inventory finding counted them the same way.

Both now count through a new analysis.IsNetworkZone, which leaves out interfaces marked virtual, as OPNsense itself does when it wants its real interfaces (legacy_config_get_interfaces(['virtual' => false])), interface group entries, which stand for their members, and interfaces assigned to a loopback device (lo1 and up, which the operator can create and assign with no virtual flag). An IPsec VTI is registered without the virtual flag and is a routed interface to a remote network, so it still counts, as do assigned VLAN, bridge, LAGG, OpenVPN and WireGuard devices. The inventory text now reads "N enabled network interface(s)".

Five commits:

  1. fix(sans): count only network interfaces as zones for SANS-FW-003 adds the predicate and uses it in SANS-FW-003 and the interface inventory.
  2. fix(sans): leave assigned loopback devices out of SANS-FW-003 zones adds the loopback case, the "network interface(s)" inventory wording, and tests that pin which assigned devices count.
  3. docs(firewall): describe FIREWALL-063 as a count of network interfaces updates the control's description.
  4. docs(compliance): use the shared SANS check text and move zone notes rewrites the "Implemented SANS Controls" rows and the SANS checks list, and adds the zone paragraph to the Network Architecture subsection and a FIREWALL-063 paragraph to the controls reference.
  5. docs(compliance): drop the remaining SANS placeholder text updates the SANS intro, the status key and Planned Features.

The compliance standards page described all four implemented SANS controls as placeholders that always return compliant. It now marks SANS-FW-001 to SANS-FW-004 as Implemented and says what each one looks at, and it drops the Placeholder status from the status key and "Real SANS Check Logic" from Planned Features. The SANS intro now says the plugin defines SANS-FW-001 to SANS-FW-025, and that some of them report Unknown.

pfSense does not write lo0 or group entries into <interfaces>; the same predicate applies to it unchanged.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation only)
  • Refactoring (no functional changes, code improvements)
  • Performance improvement (improves performance without changing functionality)
  • Test addition/update (adding or updating tests)
  • Build/CI change (changes to build system or CI configuration)

Related Issues

Testing

Pre-submission Checklist

  • Code Quality: All code follows Go formatting standards (gofmt)
  • Linting: All linting issues resolved (golangci-lint)
  • Tests: Tests pass with >80% coverage (go test ./...)
  • Error Handling: Proper error handling with context implemented
  • Logging: Structured logging used where appropriate
  • Documentation: New functions and types documented following Go conventions
  • Dependencies: Dependencies properly managed (go mod tidy)
  • Security: No hardcoded secrets or credentials
  • Input Validation: Input validation implemented where needed

Test Commands Executed

just test
just lint
just completeness-check deadcode-check
just check
go test ./internal/plugins/sans/ -run ZoneSeparation -v
go test ./internal/plugins/firewall/ -run InterfaceInventory_SkipsPseudoInterfaces -v
go test ./internal/analysis/ -run 'IsNetworkZone|CountNetworkZones' -v

Test Results

All of the above pass. With the previous SANS and inventory checks, the four WAN-only cases of TestSANSPlugin_ZoneSeparation_PseudoInterfacesAreNotZones (with lo0, with an interface group, with the VPN pseudo-interfaces, with an assigned loopback) and both cases of TestFirewallPlugin_InterfaceInventory_SkipsPseudoInterfaces fail. The cases for assigned VLAN, bridge, LAGG, OpenVPN and WireGuard devices pass before and after. No golden file changes.

With testdata/sample.config.5.xml edited to disable LAN (the repro in the issue), opndossier audit wan-only.xml --mode blue --format json -o audit.json --force reports SANS-FW-003 as PASS and 2 enabled interface(s) before the change, and FAIL and 1 enabled network interface(s) after it.

Changes Made

Files Modified

  • internal/analysis/zones.go (new): IsNetworkZone and CountNetworkZones
  • internal/plugins/sans/checks.go: checkZoneSeparation counts network zones
  • internal/plugins/firewall/checks_inventory.go: the interface inventory check and its description count network interfaces
  • docs/compliance-standards.md: SANS intro; SANS-FW-001 to SANS-FW-004 status and descriptions in the "Implemented SANS Controls" table and the SANS checks list; zone paragraph in the Network Architecture subsection; Placeholder removed from the status key; "Real SANS Check Logic" removed from Planned Features
  • docs/firewall-security-controls-reference.md: a paragraph on what FIREWALL-063 counts, below the Configuration Inventory table
  • internal/plugins/firewall/controls.go: FIREWALL-063 description
  • Tests: internal/analysis/zones_test.go, internal/plugins/sans/zone_separation_test.go, internal/plugins/firewall/interface_inventory_zones_test.go; checks_inventory_test.go updated for the new wording

Key Changes

  • lo0, assigned loopback devices, interface group entries, and the OpenVPN, WireGuard and IPsec pseudo-interfaces no longer count as zones or as enabled interfaces in the inventory.
  • The FIREWALL-063 inventory description reads "N enabled network interface(s)".
  • The converted model is unchanged: these entries are still exported with virtual and type set.

Review Checklist

For Reviewers

  • Code Quality: Code follows project conventions and Go standards
  • Architecture: Changes align with project architecture patterns
  • Security: No security vulnerabilities introduced
  • Performance: No performance regressions
  • Documentation: Documentation updated if needed
  • Testing: Adequate test coverage provided
  • Breaking Changes: Breaking changes properly documented

For Contributors

  • Self Review: Code has been self-reviewed
  • Commit Messages: Follow conventional commit format
  • Branch Naming: Branch follows naming convention (feat/, fix/, docs/, etc.)
  • Scope: Changes are focused and not too broad
  • Dependencies: No unnecessary dependencies added

Documentation

Documentation Updates

  • README.md

  • CONTRIBUTING.md

  • docs/development/standards.md

  • docs/development/architecture.md

  • Project specification files

  • docs/compliance-standards.md: the SANS intro, the SANS-FW-001 to SANS-FW-004 rows and checks list, the zone paragraph, the status key and Planned Features.

  • docs/firewall-security-controls-reference.md: a paragraph on what FIREWALL-063 counts and leaves out.

API Changes

None in pkg/. internal/analysis gains IsNetworkZone and CountNetworkZones.

Breaking Changes

None.

Migration Guide

Not applicable.

Security Considerations

Closes a false pass on a high-severity control: a single-network firewall read as segmented.

Performance Impact

None.

Acceptance Criteria

  • SANS-FW-003 fails on a firewall whose only enabled network is WAN, with lo0 present or a loopback device assigned
  • Interface group entries and VPN pseudo-interfaces do not count as zones
  • Assigned VLAN, bridge, LAGG, OpenVPN and WireGuard devices count as zones
  • The interface inventory count matches the zones SANS-FW-003 counts

Additional Notes

The red-mode enumeration count (enumeration_data.interfaces) and the blue configuration summary count every configured interface, lo0 included. They count configured interfaces rather than enabled zones, and are left for a separate change.

The FIREWALL-063 row in the summary table of docs/firewall-security-controls-reference.md still reads "Reports enabled interfaces and their types" on this branch. The dnsmasq PR rewrites that row to describe the count, so this PR leaves it alone and the two merge cleanly; the paragraph below the table states which interfaces are counted.

Labels

  • bug-fix

AI disclosure

Used Claude Code (claude-opus-5-5) to draft the SANS-FW-003 zone counting fix and its tests. All changes reviewed locally before push. Followed process per AI_POLICY.md.

OPNsense writes pseudo-interfaces into <interfaces> on every save:
lo0 always, one entry per interface group, the OpenVPN and WireGuard
groups while those services run, and enc0 while IPsec does. Each is
enabled, so SANS-FW-003 (Network Zone Separation) counted lo0 as a
second zone and passed on a firewall whose only network was WAN. The
interface inventory finding counted them the same way.

Both now count through analysis.IsNetworkZone, which leaves out
interfaces marked virtual, as OPNsense does when it wants its real
interfaces, and interface group entries. An IPsec VTI is not marked
virtual and still counts.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
OPNsense lets the operator create loopback devices lo1 and up and
assign one as an optN interface. The assignment carries no virtual
flag, so a WAN-only firewall with an assigned loopback still passed
SANS-FW-003. IsNetworkZone now also leaves out an interface whose
device is a loopback device. Tests pin that VLAN, bridge, LAGG, OpenVPN
and WireGuard devices assigned as interfaces still count.

The interface inventory text now says it counts network interfaces,
and the compliance docs no longer describe SANS-FW-003 as a
placeholder that always passes.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
FIREWALL-063 was described as reporting enabled interfaces and their
types. It reports a count, and since the SANS-FW-003 zone change that
count leaves out loopback devices, interface groups and the VPN
pseudo-interfaces. Update the control description and the controls
reference to match.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
Replace the "Implemented SANS Controls" rows and the SANS checks list
with text that holds for every SANS check as implemented, and describe
what SANS-FW-003 does not count as a zone at the end of the Network
Architecture subsection instead.

In the controls reference, restore the Configuration Inventory table
and state the FIREWALL-063 counting rule in a paragraph below it.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
The SANS intro still said the plugin defines four placeholder
controls, the status key still defined a Placeholder status no control
carries, and Planned Features still listed replacing placeholder stubs.
Replace them with the shared text the other branches carry.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes

    • Firewall inventory and SANS zone-separation checks now count enabled network interfaces while excluding loopbacks, interface groups, and virtual interfaces that do not represent network zones.
    • Assigned VLAN, bridge, LAGG, VPN, and IPsec interfaces can contribute to the network-zone count.
  • Documentation

    • Updated the SANS compliance guide to describe implemented controls, check behavior, and how network zones are counted.
    • Clarified interface-counting guidance in the firewall controls reference.

Walkthrough

The change adds shared classification and counting for enabled network interfaces. Firewall inventory and SANS-FW-003 use the network-zone count. Tests cover interface exclusions and included devices, and documentation describes the updated counting rules and SANS control status.

Changes

Network Zone Counting

Layer / File(s) Summary
Classify and count network zones
internal/analysis/zones.go, internal/analysis/zones_test.go
IsNetworkZone excludes disabled, virtual, group, and loopback interfaces. CountNetworkZones counts qualifying interfaces and returns zero for a nil device. Tests cover the classification and count.
Use network zones in firewall inventory
internal/plugins/firewall/checks_inventory.go, internal/plugins/firewall/controls.go, internal/plugins/firewall/checks_inventory_test.go, internal/plugins/firewall/interface_inventory_zones_test.go, docs/firewall-security-controls-reference.md
The firewall inventory check and finding description use the network-zone count. Tests cover pseudo-interface exclusions. Reference documentation describes the counting rule.
Apply network-zone count to SANS-FW-003
internal/plugins/sans/checks.go, internal/plugins/sans/zone_separation_test.go, docs/compliance-standards.md
SANS-FW-003 applies its two-zone threshold to network zones. Tests cover excluded pseudo-interfaces and included network-carrying devices. The documentation updates SANS control statuses and descriptions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: type:bug, go, documentation, testing

Merge Risk: Minimal · up to a3ad5

The change makes SANS-FW-003 and the interface inventory count only real network interfaces, so a WAN-only firewall now fails the zone-separation check. No concrete merge-blocking risk remains. The CI vulnerability scan failure concerns the Go toolchain version, not this change.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title follows the conventional commit format (type fix, scope sans, lowercase description) and names the main change: SANS-FW-003 zone counting now uses network interfaces only. The title matches …
Description check Passed The description follows the repository template closely. It has a filled Description, Type of Change (Bug fix and Test update checked), Related Issues (Closes #1023), Testing with commands and results…
Linked Issues check Passed Issue #1023 asks that SANS-FW-003 not count lo0, interface group entries, VPN pseudo-interfaces, or an assigned loopback as zones, and that the interface inventory count match. At head, `analysis.IsNe…
Out of Scope Changes check Passed Code changes are connected to #1023: the new predicate and helpers (internal/analysis/zones.go and zones_test.go), the SANS-FW-003 check, the inventory check and its wording, the FIREWALL-063 descript…
Go Exported-Symbol Godoc Passed The check covers exported identifiers in non-test production .go files changed by this PR. The only new exported identifiers are in internal/analysis/zones.go, a new production file: - IsNetworkZone…
Full details: Title check

Explanation

The title follows the conventional commit format (type fix, scope sans, lowercase description) and names the main change: SANS-FW-003 zone counting now uses network interfaces only. The title matches the changeset and the linked issue #1023.

Full details: Description check

Explanation

The description follows the repository template closely. It has a filled Description, Type of Change (Bug fix and Test update checked), Related Issues (Closes #1023), Testing with commands and results, Changes Made with file list and key changes, Acceptance Criteria, and Additional Notes. Some template sections are left as placeholders or unchecked: the Test Results section is filled, but Documentation Updates has unchecked boxes and a separate bullet list, Breaking Changes and Migration Guide are filled, and Performance Impact and Security Considerations are filled. Overall the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #1023 asks that SANS-FW-003 not count lo0, interface group entries, VPN pseudo-interfaces, or an assigned loopback as zones, and that the interface inventory count match. At head, analysis.IsNetworkZone (internal/analysis/zones.go) returns true only for enabled, non-virtual interfaces that are not Type group and whose PhysicalIf does not match ^lo\d+$. lo0 and OPNsense group and VPN pseudo-entries carry virtual and are excluded. Assigned lo1+ devices are excluded by device name. CountNetworkZones backs both SANS-FW-003 (checkZoneSeparation, internal/plugins/sans/checks.go) and the FIREWALL-063 inventory (internal/plugins/firewall/checks_inventory.go), so the two counts agree. Assigned VLAN, bridge, LAGG, OpenVPN, WireGuard and IPsec VTI devices remain counted, as the PR acceptance criteria require. Unit tests and the SANS and firewall tests named in the PR description cover these cases. I did not re-run the tests. The reported test results are author claims. The code evidence supports the requirement.

Full details: Out of Scope Changes check

Explanation

Code changes are connected to #1023: the new predicate and helpers (internal/analysis/zones.go and zones_test.go), the SANS-FW-003 check, the inventory check and its wording, the FIREWALL-063 description, and matching tests. The docs changes describe the counting rule and the SANS-FW-001 to SANS-FW-004 checks. Those docs go beyond the issue text, including the Planned Features and status-key edits. They describe behavior of the checks in this change, and I found no concrete unrelated change. Red-mode and blue summary counts are explicitly left unchanged and are not part of this PR.

Full details: Go Exported-Symbol Godoc

Explanation

The check covers exported identifiers in non-test production .go files changed by this PR. The only new exported identifiers are in internal/analysis/zones.go, a new production file: - IsNetworkZone (zones.go:33) has the doc comment on lines 18-32, which starts with "IsNetworkZone reports whether...". The comment directly precedes the func with no blank line. - CountNetworkZones (zones.go:40) has the doc comment on lines 38-39, which starts with "CountNetworkZones returns...". The comment directly precedes the func with no blank line. The unexported interfaceTypeGroup and loopbackDevice are out of scope. The other production changes (internal/plugins/sans/checks.go, internal/plugins/firewall/checks_inventory.go, internal/plugins/firewall/controls.go) add no new exported declarations. The diff only removes a local var enabled and changes a description string. Test files are exempt. No generated files or main package entry points are involved.

Finishing Touches

Simplify code

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

WAN stands ready, counted clear
Loopback leaves no phantom peer
Zones align in tests and code
SANS checks the network road
The docs now chart the counting mode

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: EvilBit-Labs/opnDossier
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: a03145d
  • Layers: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c12f29bf-afcf-424c-9a80-006a3d1c5321
Commits

Reviewing files that changed from the base of the PR and between a03145d and a3ad500.

Files selected for processing: 10

  • docs/compliance-standards.md
  • docs/firewall-security-controls-reference.md
  • internal/analysis/zones.go
  • internal/analysis/zones_test.go
  • internal/plugins/firewall/checks_inventory.go
  • internal/plugins/firewall/checks_inventory_test.go
  • internal/plugins/firewall/controls.go
  • internal/plugins/firewall/interface_inventory_zones_test.go
  • internal/plugins/sans/checks.go
  • internal/plugins/sans/zone_separation_test.go
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 4 protections blocking · waiting on 🙋 you

Protection Waiting on
🔴 🚦 Auto-queue 🙋 you
🟢 Enforce conventional commit —
🟢 Full CI must pass —
🟢 Do not merge outdated PRs —

🔴 🚦 Auto-queue

This rule is failing.

When all merge protections are satisfied and these conditions match, this pull request will be queued automatically.

  • any of:
    • all of:
      • author = dosubot[bot]
      • base = main
      • label != do-not-merge
    • all of:
      • -files ~= ^(?!\.github/workflows/)
      • author = dependabot[bot]
      • base = main
      • label != do-not-merge
    • all of:
      • author = dependabot[bot]
      • base = main
      • label != do-not-merge

Show 3 satisfied protections

🟢 Enforce conventional commit

Require conventional commit format per https://www.conventionalcommits.org/en/v1.0.0/. Skipped for dependabot and dosubot.

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?!?:

🟢 Full CI must pass

All CI checks must pass. Activates for non-bot authors, or dependabot when files exist outside .github/workflows/.

  • check-success = Build
  • check-success = Coverage
  • check-success = Integration Tests
  • check-success = Lint
  • check-success = Test (macos-latest, stable)
  • check-success = Test (ubuntu-latest, stable)
  • check-success = Test (windows-latest, stable)

🟢 Do not merge outdated PRs

Make sure PRs are within 10 commits of the base branch before merging

  • #commits-behind <= 10

@mergify

mergify Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@coderabbitai coderabbitai Bot added documentation Improvements or additions to documentation go Pull requests that update go code testing Test infrastructure and test-related issues type:bug Bug or defect that needs fixing labels Nov 14, 2026
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation go Pull requests that update go code testing Test infrastructure and test-related issues type:bug Bug or defect that needs fixing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SANS-FW-003 counts lo0 and interface group entries as zones, so a single-network firewall passes

1 participant