Skip to content

IP 白名单示例 ​

源代码位于 examples/ip-allowlist/。

内网 + 指定 IP(按域名) ​

yaml
# Route-level IP allowlist: only listed sources may reach the host.
# Default (no rules[].waf.allow/deny) stays unrestricted.
version: v1
port: 8080

rules:
  - host: admin.example.com
    backend:
      service:
        name: admin-console
        port: 8080
        protocol: http
    waf:
      # Per-route WAF must be enabled for the IP phase to run.
      enabled: true
      # IP-only mode: do not run the built-in attack signatures.
      disable_builtin: true
      allow:
        - 10.0.0.0/8
        - 172.16.0.0/12
        - 203.0.113.7/32

  - host: internal-api.example.com
    backend:
      service:
        name: internal-api
        port: 8080
        protocol: http
    waf:
      enabled: true
      disable_builtin: true
      allow:
        - 10.0.0.0/8
        - 192.168.0.0/16

  # No waf.allow/deny -> unrestricted (unchanged default behaviour).
  - host: app.example.com
    backend:
      service:
        name: app
        port: 8080
        protocol: http

位于 LB 后面(trusted_proxies) ​

yaml
# Behind a load balancer: trust X-Forwarded-For only from proxy networks.
# The client IP is the rightmost XFF hop that is not itself a trusted proxy.
version: v1
port: 8080

waf:
  trusted_proxies:
    - 10.0.0.0/8
    - 172.16.0.0/12

rules:
  - host: admin.example.com
    backend:
      service:
        name: admin-console
        port: 8080
        protocol: http
    waf:
      enabled: true
      disable_builtin: true
      allow:
        - 203.0.113.0/24

允许网段 + 单独拒绝一个 IP ​

yaml
# deny wins over allow: block one office IP even though its /24 is allowed.
version: v1
port: 8080

rules:
  - host: pay.example.com
    backend:
      service:
        name: pay
        port: 8080
        protocol: http
    waf:
      enabled: true
      disable_builtin: true
      allow:
        - 203.0.113.0/24
      deny:
        - 203.0.113.66/32

精确单个 IP ​

yaml
# Exact single-IP allowlist (a bare IP is treated as /32 or /128).
version: v1
port: 8080

rules:
  - host: ops.example.com
    backend:
      service:
        name: ops-console
        port: 8080
        protocol: http
    waf:
      enabled: true
      disable_builtin: true
      allow:
        - 203.0.113.7

校验 ​

bash
ingress validate -c examples/ip-allowlist/ingress.yaml

语义详解见 WAF 指南。

Released under the MIT License.