The dgp.filter.http.opa filter delegates authorization decisions to Open Policy Agent (OPA) via a Rego policy. This filter evaluates requests and determines whether to allow or deny based on the policy defined in Rego. The policy is provided as an inline Rego module and evaluated using OPA’s built-in query engine.
config.policy.config.entrypoint.input object and evaluates the query.true, the request is allowed. Otherwise, the request is denied.There is no built-in support for external policy files or URIs, custom HTTP status codes, or custom error bodies.
Add the filter under your HTTP connection manager’s http_filters list.
filters:
- name: dgp.filter.httpconnectionmanager
config:
route_config:
# ... your routes
http_filters:
- name: dgp.filter.http.opa
config:
policy: |
package http.authz
default allow = false
allow {
input.method == "GET"
input.path == "/status"
}
entrypoint: "data.http.authz.allow"
# HTTP proxy filter should be after OPA filter
- name: dgp.filter.http.proxy
config:
# ... proxy config
policy (string, required)rego.Module("policy.rego", policy).string (multiline YAML recommended with |).entrypoint (string, required)rego.Query(...). Should be a valid query like data.<package>.<rule> (e.g., data.http.authz.allow).string.true, the request continues.true), the filter stops (request denied).The filter constructs an input object with the following keys, which correspond to the HTTP request.
input.method # HTTP method string
input.path # URL path (string)
input.headers # map[string][]string
input.client_ip # string
input.query # map[string][]string (URL query)
input.host # string
input.remote_addr # string
input.user_agent # string
input.route # route entry object (opaque to policy; structure may change)
input.api # API object (opaque)
input.params # route params map
1) Allow only GET /status
- name: dgp.filter.http.opa
config:
policy: |
package http.authz
default allow = false
allow { input.method == "GET"; input.path == "/status" }
entrypoint: "data.http.authz.allow"
2) Allow requests with a specific header value
- name: dgp.filter.http.opa
config:
policy: |
package http.authz
default allow = false
allow {
input.headers["x-api-key"][0] == "secret"
}
entrypoint: "data.http.authz.allow"
true allows; objects (e.g., {allow: true}) will not be interpreted specially.policy string only.data.http.authz.allow), and that the policy returns true for the given input.opa eval locally before embedding.headers/query (they are maps of lists), and confirm path/method match.