Logging Gatekeeper Policy Constraint Violations (Warn) #303
Unanswered
MarkVLK
asked this question in
Gatekeeper
Replies: 1 comment 2 replies
-
@MarkVLK There shouldn't be any difference for There are few ways to troubleshoot this. 1, You can see how many violations your {"level":"info","ts":1667875283.0518973,"logger":"controller","msg":"audit results for constraint","process":"audit","audit_id":"2022-11-08T02:41:21Z","event_type":"constraint_audited","constraint_group":"constraints.gatekeeper.sh","constraint_api_version":"v1beta1","constraint_kind":"K8sAllowedRepos","constraint_name":"prod-repo-is-openpolicyagent","constraint_namespace":"","constraint_action":"warn","constraint_status":"enforced","constraint_violations":"10"}
{"level":"info","ts":1667875342.9665437,"logger":"controller","msg":"container <opa> has an invalid image repo <gcr.io/smythe-kpc/testbuilds/opa:0.9.2>, allowed repos are [\"openpolicyagent\"]","process":"audit","audit_id":"2022-11-08T02:42:21Z","details":{},"event_type":"violation_audited","constraint_group":"constraints.gatekeeper.sh","constraint_api_version":"v1beta1","constraint_kind":"K8sAllowedRepos","constraint_name":"prod-repo-is-openpolicyagent","constraint_namespace":"","constraint_action":"warn","resource_group":"","resource_api_version":"v1","resource_kind":"Pod","resource_namespace":"default","resource_name":"opa"}
Here is an example output in the log: {"level":"info","ts":1667875112.8724792,"logger":"webhook","msg":"denied admission","process":"admission","event_type":"violation","constraint_name":"prod-repo-is-openpolicyagent","constraint_group":"constraints.gatekeeper.sh","constraint_api_version":"v1beta1","constraint_kind":"K8sAllowedRepos","constraint_action":"warn","resource_group":"","resource_api_version":"v1","resource_kind":"Pod","resource_namespace":"default","resource_name":"opa","request_username":"kubernetes-admin"} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Ahead of enabling new constraints, I'd like to use the warn
enforcementAction
and then query logs I'm capturing to identify how frequently, if at all, various warn constraint violations are occurring. However, I'm not seeing any warn logs and I'm unsure if it's because I'm not capturing the correct logs, or there's just no resources violating the constraints I have set to warn.I see in this documentation that there should be a constraint_audited event type, but I wasn't sure if that fired for warning events too or only if Gatekeeper is actively blocking resources not passing constraints (deny enforcement action). I don't see any constraint_audited events in logs, but I do see many audit_started and audit_finished events.
I also noticed the same docs say
but my logs curiously seem to only be seeing things from the stderr stream for Gatekeeper. Again, I'm not sure if this is due to a misconfiguration on my end or if there's just nothing being printed to stdout to capture in logs.
Any pointers would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions