Use HTTP methods and paths in policy rules

Big picture

Use Calico network policy for Istio-enabled apps to restrict ingress traffic that matches HTTP methods or paths.

Value

Istio is ideal for applying policy for operational goals and for security that operates at the application layer. However, for security goals inside and outside the cluster, Calico network policy is required. Using special Calico network policy designed for Istio-enabled apps, you can restrict ingress traffic inside and outside pods using HTTP methods (for example, GET requests).

Concepts

HTTP match criteria: ingress traffic only

Calico network policy supports restricting traffic based on HTTP methods and paths only for ingress traffic.

Before you begin…

Enable application layer policy

How to

Restrict ingress traffic using HTTP match criteria

In the following example, the trading app is allowed ingress traffic only for HTTP GET requests that match the exact path /projects/calico, or that begins with the prefix, /users.

  1. apiVersion: projectcalico.org/v3
  2. kind: GlobalNetworkPolicy
  3. metadata:
  4. name: customer
  5. spec:
  6. selector: app == 'tradingapp'
  7. ingress:
  8. - action: Allow
  9. http:
  10. methods: ['GET']
  11. paths:
  12. - exact: '/projects/calico'
  13. - prefix: '/users'
  14. egress:
  15. - action: Allow