Trying to user OPA with Istio in Minikube, rego rules not working like expected #575
-
Hi, I followed all these steps and it's working. Now I am trying to user OPA for my test application in minikube. So I changed:
I would now like to have a rule that only allows access to /photogallery via my local web application: test.com/fogogalerie should be allowed, all other paths should not. When I add the rule: apiVersion: v1
kind: ConfigMap
metadata:
name: opa-policy
data:
policy.rego: |
package istio.authz
import input.attributes.request.http as http_request
import input.parsed_path
default allow = false
allow {
parsed_path[0] == "health"
http_request.method == "GET"
}
allow {
"path" == "/fotogalerie"
} I get this in the browser:
when I got to https://test.com/fotogalerie So why is it not working? What I tried so far:
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: webserver
spec:
selector:
matchLabels:
app: webserver
action: CUSTOM
provider:
name: opa-ext-authz-grpc
rules:
- to:
- operation:
notPaths: ["/health"] Desired result: I would like to perform authorization queries with OPA, e.g. depending on which browser is being used, which role is currently logged on, etc. But first I would be satisfied if access via /photogallery is allowed and all other accesses are not, so that I can see that OPA also works with my setting. I am thankful for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hi there @AnnikaTestumgebung 👋 Hmm, if setting Not related to your issue, but there's a mistake in the rule here, where you're comparing two strings that will never be equal: allow {
"path" == "/fotogalerie"
}` I guess you meant to get the path from the Using Regal for linting is a good way to catch mistakes like that :) |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I have not found out exactly where to insert these lines (--component-log-level ext_authz:trace). I tried to insert the argument directly into the istio-gateway via Edit in the minikube dahsboard to the istio-ingressgateway, but that doesn't work. How did you insert the argument? And I would like to know how I can make the rego policy only affect the webserver pod? I'm only asking because even that hasn't helped me to call the application only via firefox, as I intended as a test for OPA. With the hope that my questions here will bring me closer to a solution: If I add the policy mentioned above to allow access only with firefox browser, it happens that the whole application gets the error above: upstream connect error or disconnect/reset before headers. reset reason: connection termination
So my questions are:
And the logs from the ops-sidecar:
I understand that the last added code seems to be wrong, but it works with the quick_start example ... |
Beta Was this translation helpful? Give feedback.
I've been summoned 👀 Do you know if you can change the arguments that envoy is started with? If so, adding
to its arguments would give you more detailed logs about the communication between envoy and opa-envoy-plugin. This helped me in the past, but I don't know enough Istio to tell you how to wire it up :/