kubewarden / audit-scanner

Reports evaluation of existing Kubernetes resources with your already deployed Kubewarden policies.
https://kubewarden.io
Apache License 2.0
7 stars 8 forks source link

Reports are not updated after last policy removal #263

Closed kravciak closed 5 months ago

kravciak commented 5 months ago

I have a CA policy that produces audit-report on the namespace. When I delete this policy audit report on namespace is not removed / retriggered, leaving behind clusterpolicyreport.

To reproduce:

Current state:

Clusterpolicyreport for default namespace with 1 FAIL is not removed, UI points to non-existent policy

Expexted state:

Clusterpolicyreport results from non-existent policies are cleaned

flavio commented 5 months ago

To whoever takes that, there must be something wrong with owner references and cluster admission policies.

jvanz commented 5 months ago

I can see the issue. The report is still with one failed result after delete the policy and triggering the audit scanner job again. The problem is not in the owner reference. The owner reference is set to the audited resource. Which makes sense considering that the report can store result from multiple policies. I believe the problem is that we update the report only when we have some audit result. We need to update the audit scanner to remove result from gone policies. I'll take a look in the audit scanner code how to do that.