mirror of
				https://github.com/traefik/traefik.git
				synced 2025-10-31 00:11:38 +01:00 
			
		
		
		
	
		
			
				
	
	
	
		
			3.0 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.0 KiB
		
	
	
	
	
	
	
	
title, description
| title | description | 
|---|---|
| Open Policy Agent | Traefik Hub API Gateway - The Open Policy Agent (OPA) middleware that allows you to restrict access to your services. | 
!!! info "Traefik Hub Feature" This middleware is available exclusively in Traefik Hub. Learn more about Traefik Hub's advanced features.
Traefik Hub comes with an Open Policy Agent middleware that allows you to restrict access to your services. It also allows you to enrich request headers with data extracted from policies. The OPA middleware works as an OPA agent.
!!! note "OPA Version"
This middleware uses the [v1.3.0 of the OPA specification](https://www.openpolicyagent.org/docs).
Configuration Example
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: opa-allow-jwt-claim
  namespace: apps
spec:
  plugin:
    opa:
      policy: |
        package example.policies
        allow {
          [_, encoded] := split(input.headers.Authorization, " ")
          [header, payload, signature] = io.jwt.decode(encoded)
          payload["email"] == "bibi@example.com"
        }
      forwardHeaders:
        Group: data.package.grp
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: opa-deny-json
  namespace: apps
spec:
  plugin:
    opa:
      policy: |
        package example.policies
        default allow = false
        json_content {
          input.headers["Accept"] == "application/json"
        }
        allow {
          not json_content
        }
      allow: data.example.policies.allow
Configuration Options
| Field | Description | Default | Required | 
|---|---|---|---|
| policy | Path or the content of a policy file. | "" | No (one of policyorbundlePathmust be set) | 
| bundlePath | The bundlePathoption should contain the path to an OPA bundle. | "" | No (one of policyorbundlePathmust be set) | 
| allow | The allowoption sets the expression to evaluate that determines if the request should be authorized. | "" | No (one of alloworforwardHeadersmust be set) | 
| forwardHeaders | The forwardHeadersoption sets the HTTP headers to add to requests and populates them with the result of the given expression. | "" | No (one of alloworforwardHeadersmust be set) | 
{!traefik-for-business-applications.md!}