Why does strings.any_prefix_match failed to match an input #581
Answered
by
johanfylling
ylbeethoven
asked this question in
OPA and Rego
-
Hi, I am trying to understand why below rego can't pass the validation on rego playground package envoy.authz
import rego.v1
allow_path_prefix := "/a"
allow if {
strings.any_prefix_match(input.attributes.request.http.path, allow_path_prefix)
} when the input is {
"input": {
"attributes": {
"request": {
"http": {
"path": "/anything"
}
}
}
}
} It works if I use the path string package envoy.authz
import rego.v1
allow_path_prefix := "/a"
allow if {
strings.any_prefix_match("/anything", allow_path_prefix)
} isn't |
Beta Was this translation helpful? Give feedback.
Answered by
johanfylling
Apr 22, 2024
Replies: 1 comment 1 reply
-
The Rego playground doesn't expect an outer If you change the input JSON to {
"attributes": {
"request": {
"http": {
"path": "/anything"
}
}
}
} as in: https://play.openpolicyagent.org/p/9CN3VEixkU, your code should evaluate as expected. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ylbeethoven
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Rego playground doesn't expect an outer
input
attribute in the provided input JSON document; this is something you use when e.g. passing parameters to the REST query API, but not to the playground.If you change the input JSON to
as in: https://play.openpolicyagent.org/p/9CN3VEixkU, your code should evaluate as expected.