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:
- Type-safe expression language with compile-time validation
- Built-in test framework validated at startup
- Fail-closed security model (errors deny access)
- Case-insensitive header lookups
- Minimal overhead (compiled WASM)
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.yml
experimental:
plugins:
http-authz-policy-middleware:
moduleName: github.com/andrewkroh/http-authz-policy-middleware
version: v0.0.3Traefik 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: 403
denyBody: "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: falsemethod- 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 operators
header(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 startup
Test Case Schema:
name(string) - Test descriptionrequest(object) - Mock request withmethod,path,host,headersexpect(boolean) - Expected result (true = allow, false = deny)
Complete Traefik configurations in examples/:
- team-based-access.yml - Team membership authorization
- path-restrictions.yml - API path restrictions
- combined-rules.yml - Complex boolean logic
MIT
