
A Traefik middleware plugin that performs attribute-based authorization on HTTP requests using a type-safe expression language.
This plugin enables fine-grained access control based on HTTP request attributes (method, path, host, headers) using a custom expression language. Expressions are compiled and type-checked at Traefik startup, catching configuration errors before they reach production.
Key Features:
Try the expression language in your browser at the online playground. You can write expressions, configure mock requests, and see evaluation results instantly — no Traefik installation required.
Add the plugin to your Traefik static configuration:
# traefik.ymlexperimental:plugins:http-authz-policy-middleware:moduleName: github.com/andrewkroh/http-authz-policy-middlewareversion: v0.0.2
Traefik will download the plugin from the Plugin Catalog on startup.
http:middlewares:team-auth:plugin:authz:expression: 'contains(headerList("X-Auth-User-Teams"), "platform-eng")'denyStatusCode: 403denyBody: "Access denied: requires platform-eng team membership"tests:- name: "platform-eng team allowed"request:headers:X-Auth-User-Teams: "platform-eng,devops"expect: true- name: "other teams denied"request:headers:X-Auth-User-Teams: "marketing"expect: false
method - HTTP request method (GET, POST, etc.)path - Request pathhost - Request host==, != - String equality/inequalitystartsWith, endsWith - String prefix/suffix matchcontains - Substring matchmatches - Regex match (RE2 syntax)AND, OR, NOT - Boolean operatorsheader(name) - Get first header value (empty string if missing)headerValues(name) - Get all header values as arrayheaderList(name) - Get header value split by comma into arraycontains(list, item) - Check if array contains itemanyOf(list, item1, item2, ...) - Check if array contains any of the itemsallOf(list, item1, item2, ...) - Check if array contains all of the items# Method check
method == "GET"
# Path-based access
path startsWith "/api/admin"
# Team membership
contains(headerList("X-Auth-User-Teams"), "platform-eng")
# Complex logic
(method == "GET" OR method == "HEAD") AND path startsWith "/public"
# Regex
matches(path, "^/api/v[0-9]+/.*")
# Multiple teams
anyOf(headerList("X-Auth-User-Teams"), "platform-eng", "devops", "sre")
Middleware Configuration:
expression (string, required) - Authorization expressiondenyStatusCode (int, default: 403) - HTTP status for denied requestsdenyBody (string, default: "Forbidden") - Response body for denied requeststests (array, optional) - Test cases validated at startupTest Case Schema:
name (string) - Test descriptionrequest (object) - Mock request with method, path, host, headersexpect (boolean) - Expected result (true = allow, false = deny)Complete Traefik configurations in examples/:
MIT