Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

IP-based filtering

Page as Markdown

Block or allow traffic based on the client IP address or CIDR range.

About IP-based filtering

Not all traffic to your apps is legitimate. Malicious actors, botnets, and malicious IP address ranges can target your services with brute-force attacks, credential stuffing, or reconnaissance. Without IP-level filtering at the gateway proxy, these requests reach your app and can consume its resources.

Solo Enterprise for agentgateway lets you block or allow traffic based on the client IP address by using the Coraza REMOTE_ADDR variable in a WAFPolicy. IP filtering rules run in the earliest phase (phase:1), so blocked requests are rejected before the request body is buffered or forwarded to the upstream.

The REMOTE_ADDR variable is set to the socket-level peer IP address of the immediate downstream connection. This is the client that opened the connection to the gateway, or the last proxy hop in front of the gateway, such as a cloud load balancer. The agentgateway proxy does not use the X-Forwarded-For header to determine the value of REMOTE_ADDR. Keep this in mind when your gateway sits behind one or more proxies: the value that the WAF matches is the address of the proxy that connects to the gateway, not the original client.

Note

Because REMOTE_ADDR reflects the connection peer, the CIDR ranges that you match against depend on your network topology. Choose the ranges based on the source addresses that your gateway actually observes on inbound connections.

You can use IP filtering rules alongside CRS and custom rules in the same WAFPolicy to create a multi-layer defense-in-depth system.

Before you begin

  1. Set up an agentgateway proxy.
  2. Install the httpbin sample app.
  1. Enable the WAF server for your GatewayClass.
  2. Get the external address of the gateway and save it in an environment variable.
    export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy -o=jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}")
    echo $INGRESS_GW_ADDRESS
    kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 8080:80

Configure IP-based filtering

Use Coraza’s REMOTE_ADDR variable to block specific client IP addresses or CIDR ranges.

  1. Create a WAFPolicy that blocks requests from the 198.51.100.0/24 CIDR range.

    kubectl apply -f- <<EOF
    apiVersion: waf.solo.io/v1alpha1
    kind: WAFPolicy
    metadata:
      name: httpbin-waf
      namespace: httpbin
    spec:
      ruleEngineSettings:
        inline: |
          SecRuleEngine On
      customDirectives:
        - inline: |
            SecRule REMOTE_ADDR "@ipMatch 198.51.100.0/24" "id:1001,phase:1,deny,status:403,msg:'blocked IP'"
    EOF
    SettingDescription
    @ipMatchCoraza operator that matches IP addresses or CIDR ranges. Accepts a comma-separated list, for example 10.0.0.0/8,172.16.0.0/12.
    phase:1Evaluates the rule during request headers processing, before the body is buffered.
  2. Create an EnterpriseAgentgatewayPolicy to attach the WAFPolicy to the httpbin HTTPRoute.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: httpbin-waf-ip
      namespace: httpbin
    spec:
      targetRefs:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
          name: httpbin
      traffic:
        entWAF:
          wafPolicyRef:
            name: httpbin-waf
    EOF
  3. Verify that the policy is accepted and attached.

    kubectl get enterpriseagentgatewaypolicy httpbin-waf-ip -n httpbin -o yaml

    Output:

    conditions:
     - lastTransitionTime: ""
       message: Policy accepted
       observedGeneration: 1
       reason: Valid
       status: "True"
       type: Accepted
     - lastTransitionTime: ""
       message: Attached to all targets
       observedGeneration: 1
       reason: Attached
       status: "True"
       type: Attached

    Both the Accepted and Attached conditions must be True.

  4. Send a request from an address that is not in the blocked range. Verify that you get a 200 response.

    curl -i http://$INGRESS_GW_ADDRESS:80/status/200 -H "host: www.example.com"
    curl -i localhost:8080/status/200 -H "host: www.example.com"

    Example output:

    HTTP/1.1 200 OK
    ...
    

    Requests that originate from the 198.51.100.0/24 range are denied with a 403 response. To confirm blocking behavior, adjust the CIDR range in the WAFPolicy to match the source address that your gateway observes on inbound connections, then send another request.

Cleanup

You can optionally remove the resources that you set up as part of this guide.
kubectl delete wafpolicy -n httpbin httpbin-waf
kubectl delete enterpriseagentgatewaypolicy -n httpbin httpbin-waf-ip

Other configurations

The following examples show common IP filtering patterns that you can adapt for your own WAFPolicy. They are reference snippets to integrate into a policy, not complete steps that you apply as-is.

IP allowlisting

Instead of blocking malicious IP addresses, you can invert the logic to allow only trusted IP addresses. The !@ipMatch negation denies any request with a source IP address that is not in the allowlist.

apiVersion: waf.solo.io/v1alpha1
kind: WAFPolicy
metadata:
  name: ip-allowlist
  namespace: httpbin
spec:
  ruleEngineSettings:
    inline: |
      SecRuleEngine On
  customDirectives:
    - inline: |
        SecRule REMOTE_ADDR "!@ipMatch 203.0.113.0/24,198.51.100.50" \
          "phase:1,deny,status:403,id:1,msg:'IP not in allowlist'"

Per-route IP allowlists with sectionName

In multi-team environments, different routes might need independent IP address restrictions. Use the sectionName in the EnterpriseAgentgatewayPolicy to add WAF rules to specific HTTPRoute routes. This setup allows you to make updates to your WAF rules without impacting other teams.

apiVersion: waf.solo.io/v1alpha1
kind: WAFPolicy
metadata:
  name: ip-allowlist-team-a
  namespace: httpbin
spec:
  ruleEngineSettings:
    inline: |
      SecRuleEngine On
  customDirectives:
    - inline: |
        SecRule REMOTE_ADDR "!@ipMatch 203.0.113.0/24" \
          "phase:1,deny,status:403,id:1,msg:'IP not in team-a allowlist'"
---
apiVersion: waf.solo.io/v1alpha1
kind: WAFPolicy
metadata:
  name: ip-allowlist-team-b
  namespace: httpbin
spec:
  ruleEngineSettings:
    inline: |
      SecRuleEngine On
  customDirectives:
    - inline: |
        SecRule REMOTE_ADDR "!@ipMatch 198.51.100.0/24" \
          "phase:1,deny,status:403,id:1,msg:'IP not in team-b allowlist'"

Then attach each policy to its route rule:

apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayPolicy
metadata:
  name: waf-team-a
  namespace: httpbin
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: httpbin-route
      sectionName: team-a
  traffic:
    entWAF:
      wafPolicyRef:
        name: ip-allowlist-team-a
---
apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayPolicy
metadata:
  name: waf-team-b
  namespace: httpbin
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: httpbin-route
      sectionName: team-b
  traffic:
    entWAF:
      wafPolicyRef:
        name: ip-allowlist-team-b

Combining IP filtering with attack detection

You can layer IP filtering with additional rules in the same WAFPolicy for defense in depth. For example, combine an IP allowlist with SQL injection and XSS detection so that even allowed IPs are still inspected for malicious payloads.

apiVersion: waf.solo.io/v1alpha1
kind: WAFPolicy
metadata:
  name: ip-allowlist-with-attack-detection
  namespace: httpbin
spec:
  ruleEngineSettings:
    inline: |
      SecRuleEngine On
  customDirectives:
    - inline: |
        SecRule REMOTE_ADDR "!@ipMatch 203.0.113.0/24,198.51.100.50" \
          "phase:1,deny,status:403,id:1,msg:'IP not in allowlist'"
    - inline: |
        SecRule QUERY_STRING "@rx (?i:union.*select|select.*from|drop\s+table|insert\s+into)" \
          "phase:1,deny,status:403,id:2,msg:'SQL injection detected'"
    - inline: |
        SecRule QUERY_STRING "@rx (?i:%3Cscript|<script|javascript:|onerror=|onload=)" \
          "phase:1,deny,status:403,id:3,msg:'XSS detected'"

Next