[proxy,management] Return 404, 403 or 401 for refused private service requests
Describe your changes
Every refusal of a private service was a 403. That confirms the service exists to callers that cannot reach it, and an Agent Networks user refused for a missing policy gets the same answer as any other refusal.
Refusal status now depends on who is asking:
| Caller | Status |
|---|---|
| Outside the account's overlay, or another account's peer | 404 |
| Account peer that can reach another private service | 403 |
| Account peer with no private access, or a blocked/pending owner | 404 |
Peer outside the Agent Networks policies (not_in_group on the gateway) | 401 |
Management unreachable during ValidateTunnelPeer | 503 |
The proxy never receives private services' access groups, so management answers the "can it reach another private service" question in a new ValidateTunnelPeerResponse.has_private_access field, set on not_in_group denials. An older management leaves it false, so the proxy answers 404 rather than 403. Refusals made before tunnel validation (IP restriction, blocked path) stay 403 for a peer in the account's roster and become 404 otherwise.
Which requests are allowed does not change. Refusals still close the connection and stay attributed to auth in the access log, and an auth-originated 404 or 503 now counts as a failed authentication there.
The 401 carries no WWW-Authenticate header, so browsers show no prompt and OAuth-aware clients start no discovery flow. LLM SDKs treat 401 as a bad API key, so agent CLIs may suggest logging in again. Provider-level policy denials (no_authorised_provider) stay 403.
Issue ticket number and link
NET-1994
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)
- I ran and tested this change locally — I did not rely on CI to find out whether it works
- This PR has a single purpose (not a fix + refactor + feature in one)
- This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. 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)
The change only affects the HTTP status of requests the proxy already refuses; no configuration, API or user-facing setting changes.
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit
- Bug Fixes
- Private-service access denials now return status codes based on the caller and request context. Some denials appear as not found, while others return forbidden or unauthorized; tunnel-validation failures return service unavailable. A forbidden response is used when the peer has access to another private service or is blocked by an IP restriction.
- Authentication access logs now distinguish authentication refusals from other not-found and service-unavailable responses, improving how refusal outcomes are recorded.