Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when "error(s) occurred while compiling module(s)" #267

Closed
yuzhouliu9 opened this issue Oct 17, 2024 · 9 comments
Closed

Fail when "error(s) occurred while compiling module(s)" #267

yuzhouliu9 opened this issue Oct 17, 2024 · 9 comments

Comments

@yuzhouliu9
Copy link

yuzhouliu9 commented Oct 17, 2024

Running OPA 0.54.0 and kube-mgmt v8.3.0

We frequently see errors like these from kube-mgmt

level=info msg="Added policy opa/opa-istio-whitelist-rego-policy/opa-istio-whitelist.rego, err=code invalid_parameter: error(s) occurred while compiling module(s)"

It is a problem from our .rego that we will address.

But the issue is that kube-mgmt container continues on even with the error. The rules we've defined are not enforced on this OPA pod.
Is there a way to fail the container when this error occurs?

@eshepelyuk
Copy link
Contributor

eshepelyuk commented Oct 17, 2024

there is no way to fail kube-mgmt container, whatever you mean with fail.

@yuzhouliu9
Copy link
Author

The behavior we observe is that when the invalid_parameter error occurs, the .rego defined is not enforced. Thus defeating the purpose of having OPA.

kube-mgmt container should restart or error. This is a better signal than just logging this error.

@eshepelyuk
Copy link
Contributor

eshepelyuk commented Oct 17, 2024

if kube-mgmt pod restarts on such error, it will re apply the same incorrect rego from the same ConfigMap and will receive the same error.

So, what is the purpose of restart ?

@yuzhouliu9
Copy link
Author

yuzhouliu9 commented Oct 17, 2024

It will signal to the operator something is wrong immediately.

Think of it from a user perspective:

  1. A single error line occurs in kube-mgmt container. OPA rules for that .rego is not enforced.
  2. OPA pod is ready, starts serving requests. Lots of logs generated indicating all is well, and that single log is buried.
  3. Then one day a request that was supposed to be denied by OPA is allowed in. The operator has to look through all the OPA logs to find that one line from 60 days ago when kube-mgmt started to find the cause.

This is what happened in our case.

@eshepelyuk
Copy link
Contributor

eshepelyuk commented Oct 17, 2024

  • kube-mgmt watches ConfigMaps and applies their content to running OPA instance
  • if error happens, kube-mgmt adds an openpolicyagent.org/kube-mgmt-status annotation to ConfigMap and logs the error
  • if you want to react quickly on incorrect OPAs, you should configure your observability tools\CD pipelines to monitor ConfigMap containing OPA sources for the value of status annotation

@eshepelyuk eshepelyuk closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2024
@yuzhouliu9
Copy link
Author

yuzhouliu9 commented Oct 17, 2024

If there are multiple OPA pods, does openpolicyagent.org/kube-mgmt-status annotation get overwritten by newer pods?

@eshepelyuk
Copy link
Contributor

If there are multiple OPA pods, does openpolicyagent.org/kube-mgmt-status annotation get overwritten by newer pods?

kube mgmt doesn't support scaling opa pods
#194

@yuzhouliu9
Copy link
Author

yuzhouliu9 commented Oct 17, 2024

We deploy multiple replica OPA pods with opa and kube-mgmt container 1:1.

I was not aware this is unsupported. Not supporting multiple replicas seems like a huge gap for something that's supposed to be kubernetes native?

It seems almost impossible to me that there are production use cases with a single OPA pod.

@eshepelyuk
Copy link
Contributor

This is OSS
You're always welcome to address the issue by providing PR.

@open-policy-agent open-policy-agent locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants