Repository navigation
Website content en overview reference pixiu other user httpfilter opa
alanxtl edited this page Sep 20, 2026
·
1 revision
关联资料(可能以 Java / Pixiu 为主)。原文按来源版本保留;使用前请读 版本与升级。 来源:原文 · 提交
84b35ebdab20· 返回目录
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.
- Loads a Rego module string from
config.policy. - Builds a Rego query from
config.entrypoint. - For each incoming request, constructs an
inputobject and evaluates the query. - If the query result is
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)-
Meaning: The Rego module source code (inline string). Loaded via
rego.Module("policy.rego", policy). -
Datatype:
string(multiline YAML recommended with|). - Notes: File paths or bundle URIs are not supported.
-
Meaning: The Rego module source code (inline string). Loaded via
-
entrypoint(string, required)-
Meaning: The Rego query string passed to
rego.Query(...). Should be a valid query likedata.<package>.<rule>(e.g.,data.http.authz.allow). -
Datatype:
string.
-
Meaning: The Rego query string passed to
- If the query result is a non-empty set whose first expression value is
true, the request continues. - Otherwise (empty results or value ≠
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"-
Return type must be boolean: Only
trueallows; objects (e.g.,{allow: true}) will not be interpreted specially. - No custom deny status/body: The filter does not map policy outputs to HTTP status or body.
-
Module-only loading: Policies are loaded from the inline
policystring only.
-
Denied unexpectedly: Confirm the query is correct (e.g.,
data.http.authz.allow), and that the policy returnstruefor the giveninput. -
Policy compile errors: Validate the Rego module with
opa evallocally before embedding. -
Nil/empty results: Re-check access to
headers/query(they are maps of lists), and confirm path/method match.