Skip to content

feat: add IP whitelist support via CIDR networks#3549

Closed
masterbpro wants to merge 1 commit intoprometheus:masterfrom
masterbpro:master
Closed

feat: add IP whitelist support via CIDR networks#3549
masterbpro wants to merge 1 commit intoprometheus:masterfrom
masterbpro:master

Conversation

@masterbpro
Copy link

Adds optional IP whitelist support to the HTTP server

New flags:
--web.allowed-networks
--web.whitelist-config

--web.allowed-networks accepts a comma-separated list of CIDR networks.
Single IPs are accepted and treated as /32 (IPv4) or /128 (IPv6).

If configured, requests from non-matching IPs receive HTTP 403.
If not configured, behavior remains unchanged.

Whitelist applies to both:

  • /metrics
  • /

Client IP resolution:

IP is resolved in the following order:

  • Custom headers defined in YAML (whitelist.ip_headers)
  • Default headers (if none configured):
    • X-Forwarded-For (first IP is used)
    • X-Real-IP
    • X-Forwarded
  • Fallback to RemoteAddr

Examples:

Allow single network:
./node_exporter --web.allowed-networks=10.0.0.0/24

Allow multiple networks:
./node_exporter --web.allowed-networks=10.0.0.0/24,192.168.1.0/24

Allow single host:
./node_exporter --web.allowed-networks=10.0.0.10

With IPv6:
./node_exporter --web.allowed-networks=2001:db8::/32

Using YAML configuration:
./node_exporter --web.whitelist-config=/etc/node_exporter/whitelist.yaml

Example YAML:

  whitelist:
    allowed_networks:
      - "10.0.0.0/24"
      - "192.168.1.0/24"
    ip_headers:
      - "X-Forwarded-For"
      - "X-Real-IP"

Signed-off-by: masterbpro <iserver12345@gmail.com>
@SuperQ
Copy link
Member

SuperQ commented Feb 14, 2026

Sorry, no, we don't want to support this here. This is what firewalls are for.

@SuperQ SuperQ closed this Feb 14, 2026
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