Skip to content

[management, proxy] Add OR mode for reverse proxy access restrictions - #6887

Open
lixmal wants to merge 4 commits into
mainfrom
reverse-proxy-allow-match-or
Open

[management, proxy] Add OR mode for reverse proxy access restrictions#6887
lixmal wants to merge 4 commits into
mainfrom
reverse-proxy-allow-match-or

Conversation

@lixmal

@lixmal lixmal commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Describe your changes

Access restrictions on reverse-proxy services currently combine the different allowlists with AND, so a connection must match every configured allowlist. That makes rules like "allow country X OR CIDR Y" impossible to express, and adding a CIDR allowlist silently denies country-allowed clients (and vice versa). This adds an allow_match option to control how the allowlists combine.

  • Add allow_match to access restrictions: all (default, AND) requires matching every allowlist, any (OR) requires matching at least one, e.g. an allowed country or an allowed CIDR
  • Keep blocklists as a hard deny regardless of the mode, and fall back to all for an empty or unknown value so behavior never loosens unexpectedly
  • Preserve existing behavior for services with no allow_match set (treated as all)

Issue ticket number and link

#5862

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

netbirdio/docs#884

Summary by CodeRabbit

  • New Features
    • Added allow_match to access restrictions to control allowlist combination: all (AND) or any (OR), with all as default.
  • Bug Fixes
    • Improved validation and consistent legacy/empty handling for allow_match.
    • Fixed service restriction loading from storage so configured restrictions persist correctly.
  • Tests
    • Added coverage for allow/deny semantics, API/proto round-trips, geo/crowd control behavior, validation failures, and storage persistence.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds allow_match to access restriction contracts, management conversions, persistence loading, and proxy filters. The proxy supports default all or explicit any allowlist evaluation while preserving blocklist, geolocation, and CrowdSec enforcement.

Changes

Access restriction matching

Layer / File(s) Summary
Restriction API and proto contracts
shared/management/http/api/openapi.yml, shared/management/http/api/types.gen.go, shared/management/proto/proxy_service.proto
Defines allow_match, its all/any values, default behavior, and generated API/proto representations.
Management model mapping and validation
management/internals/modules/reverseproxy/service/service.go, management/internals/modules/reverseproxy/service/service_test.go
Stores, copies, validates, and converts AllowMatch across model, API, and proto representations, with round-trip and invalid-value tests.
Service restriction persistence
management/server/store/sql_store.go, management/server/store/sql_store_service_test.go
Loads serialized service restrictions from storage and verifies that restriction fields, including AllowMatch, round-trip through account retrieval.
Proxy filter propagation and evaluation
proxy/server.go, proxy/internal/restrict/restrict.go, proxy/internal/restrict/restrict_test.go
Passes AllowMatch into filters, defaults unknown values to all, implements any-mode block and allow evaluation, and tests matching precedence and CrowdSec enforcement.

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

Sequence Diagram(s)

sequenceDiagram
  participant ManagementAPI
  participant ProxyServer
  participant RestrictFilter
  participant GeoLookup
  participant CrowdSec
  ManagementAPI->>ProxyServer: provide allow_match restriction
  ProxyServer->>RestrictFilter: pass AllowMatch in FilterConfig
  RestrictFilter->>RestrictFilter: normalize mode and check blocklists
  RestrictFilter->>GeoLookup: resolve country when required
  GeoLookup-->>RestrictFilter: country result or unavailable
  RestrictFilter->>CrowdSec: evaluate IP after allow decision
  CrowdSec-->>RestrictFilter: enforcement result
Loading

Possibly related PRs

  • netbirdio/netbird#6886: Updates the service restriction database hydration path and related round-trip coverage.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is mostly complete, but it incorrectly checks the no-API-change checkbox for a feature that changes public API, proto, and behavior. Uncheck that box and either add the required discussion link or explicitly acknowledge that this change modifies public API, protobufs, and behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding an OR mode for reverse-proxy access restrictions, though the bracketed scope prefix is noisy.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reverse-proxy-allow-match-or

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
management/internals/modules/reverseproxy/service/service.go (1)

825-829: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve allow_match when it is the only restriction.

Both omission predicates ignore r.AllowMatch, so an explicit allow_match without CIDR/country/CrowdSec fields is silently omitted from both API and proto output.

  • management/internals/modules/reverseproxy/service/service.go#L825-L829: include r.AllowMatch == "" in the early-return condition.
  • management/internals/modules/reverseproxy/service/service.go#L855-L859: apply the same condition to proto conversion.
  • management/internals/modules/reverseproxy/service/service_test.go#L1305-L1338: add an allow-match-only conversion test asserting both outputs remain non-nil.
Proposed fix
-       r.CrowdSecMode == "" {
+       r.CrowdSecMode == "" && r.AllowMatch == "" {
        return nil
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@management/internals/modules/reverseproxy/service/service.go` around lines
825 - 829, Preserve an allow-match-only restriction in both conversion paths. In
management/internals/modules/reverseproxy/service/service.go lines 825-829,
update restrictionsToAPI to also require r.AllowMatch == "" before returning
nil; apply the same condition in the proto conversion at lines 855-859. In
management/internals/modules/reverseproxy/service/service_test.go lines
1305-1338, add a conversion test with only AllowMatch set and assert both API
and proto outputs are non-nil.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@management/internals/modules/reverseproxy/service/service.go`:
- Around line 825-829: Preserve an allow-match-only restriction in both
conversion paths. In
management/internals/modules/reverseproxy/service/service.go lines 825-829,
update restrictionsToAPI to also require r.AllowMatch == "" before returning
nil; apply the same condition in the proto conversion at lines 855-859. In
management/internals/modules/reverseproxy/service/service_test.go lines
1305-1338, add a conversion test with only AllowMatch set and assert both API
and proto outputs are non-nil.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c3824b8d-a0f1-4cb0-8205-1b4ccda989c6

📥 Commits

Reviewing files that changed from the base of the PR and between 1e5b0a5 and 40cdfda.

⛔ Files ignored due to path filters (1)
  • shared/management/proto/proxy_service.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (8)
  • management/internals/modules/reverseproxy/service/service.go
  • management/internals/modules/reverseproxy/service/service_test.go
  • proxy/internal/restrict/restrict.go
  • proxy/internal/restrict/restrict_test.go
  • proxy/server.go
  • shared/management/http/api/openapi.yml
  • shared/management/http/api/types.gen.go
  • shared/management/proto/proxy_service.proto

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

Release artifacts

Built for PR head 2355d49 in workflow run #17919.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI GTK3 artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

@lixmal
lixmal force-pushed the reverse-proxy-allow-match-or branch from f05f3fc to 2355d49 Compare August 19, 2026 10:05
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant