-
Notifications
You must be signed in to change notification settings - Fork 759
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
Expanded resource not evaluated for constraint #2485
Comments
@davis-haba can you PTAL? |
One issue with the docs It looks like https://github.com/open-policy-agent/gatekeeper/blob/master/pkg/target/match_schema.go If possible, we should auto-generate that file from https://github.com/open-policy-agent/gatekeeper/blob/bed335f5c220e962922c887631a497f5bebe89ae/pkg/mutation/match/match.go To avoid future code duplication issues. Though a missing source field should default to gatekeeper/pkg/mutation/match/match.go Lines 288 to 293 in bed335f
which means it should not lead to non-enforcement. Can you post the contents of (I realize you posted links for some of this but actual data from the cluster is more authoritative):
? |
(actual resources as taken from the cluster with their status fields would be most helpful) |
Config
ExpansionTemplate
ConstraintTemplate
Constraint
Deployment
Helm values
|
Thanks for the data! I think the issue is that the expanded resource has no
specifically:
We should probably have something that generates object names, since I think this will be a common problem. In the interim, you could try:
or
If either of those work, we're on the right track. |
@maxsmythe you're right that did the trick! just my luck I picked one of the few policies that uses the objects name. I'm trying to think of what the best solution for that would be.
I didn't notice anything in the logs when this was occurring, perhaps there is an opportunity somewhere in the expansion controller to log something about the activity to make troubleshooting easier. |
+1 as there's less impact to policy authors and it further helps identify that violation is caused by an expanded/generated resource. |
Would a suitable workaround until this is fixed to rely on the enforcementAction in the ExpansionTemplate to override the Constraints enforcement policy, and then set the Constraint to dry-run with the goal of only generation violations for the generated resources to reduce the number of violations.
Edit: Nvm it looks like dryrun still generates violations & events for the non-expanded objects in dryrun, so I guess I will need to wait for an official patch. |
Yeah, I don't think there is currently a workaround for split enforcement action.
Yeah, one thought: since deployments create pods with the deployment name as its prefix, using the parent resource name as a default value could play well with prefix-based name matching. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
Still active. The PRs with fixes are not merged yet. |
What steps did you take and what happened:
Enable feature in helm chart via
enableGeneratorResourceExpansion: true
, confirm it is enabled by inspecting deployment container args for audit + webhook.Configure the
source
field on a constraint template under the match criteria but the field is ignored/removed when applying edit.Since docs say default is "All" for match source, apply update anyway to a Deployment which should result in a violation, the update succeeds. When scaling up the same deployment a violation is created on the pod directly instead of the generated resource.
What did you expect to happen:
The docs state the source field on the match API, present in the Mutation and ConstraintTemplate kinds so I assume it should be possible to configure the
.spec.match.source
field on a constraint and the violation should occur when updating the deployment since it is part of the ExpansionTemplate configured (I used the example from docs but changed enforcementAction to deny).https://open-policy-agent.github.io/gatekeeper/website/docs/expansion/#match-source
https://open-policy-agent.github.io/gatekeeper/website/docs/expansion/#expansiontemplate
Anything else you would like to add:
The source field doesn't seem to be present in the constraint CRDs generated by gatekeeper. The
source
field under.spec.match
disappears after applying an update to a constraint (or creating a fresh one). ExpansionTemplate doesn't seem to be evaluated for some reason.kubectl version
): v1.23.5The text was updated successfully, but these errors were encountered: