gatekeeper icon indicating copy to clipboard operation
gatekeeper copied to clipboard

Mutation to replace image registry

Open ritazh opened this issue 2 years ago • 12 comments

    Another scenario  for a more dynamic mutation is replacing image registry per cluster env. 

For instance, you define kube manifests once, let’s say it uses image grafana/grafana .

Based on the kube cluster it deploys to, mutation webhook can change/prepend the image registry to use private one.

Alternatively user would deploy custom mutation webhook or worst case, clobber the deployment manifests for each env.

This is highly desirable and kyverno policy engine has lot of maturity on it.

Originally posted by @tahirraza in https://github.com/open-policy-agent/gatekeeper/issues/1134#issuecomment-1296086434

ritazh avatar Nov 02 '22 21:11 ritazh

Thank you for creating the issue. I'd be happy to do jump in as needed.

tahirraza avatar Nov 04 '22 17:11 tahirraza

Slack thread: https://openpolicyagent.slack.com/archives/CDTN970AX/p1667097854495169

tahirraza avatar Nov 08 '22 02:11 tahirraza

A change to support this is in flight: https://github.com/open-policy-agent/gatekeeper/pull/2429

davis-haba avatar Dec 09 '22 00:12 davis-haba

Above PR seems merged. What's ETA for this in the future release ?

tahirraza avatar Feb 19 '23 05:02 tahirraza

Is it possible to use AssignImage, to replace the registry using a condition? For example, I want to replace any container image using docker.io to internal-registry.io. With the current implementation, my understanding it's all or nothing so any pod & container that is matched would get replaced, so it is not possible to set this type of condition? I do not want to replace registries other than docker.io, and do not want to define a hundred AssignImage instances to select specific containers/pods.

It would be nice to have some condition tests, similar to Assigns pathTests except they would need to be tests on the image registry, repo, or tag.

ctml91 avatar Apr 04 '23 16:04 ctml91

Testing the value-to-be-modified has safety implications WRT convergence, risking turning mutation into a Turing machine:

https://github.com/orgs/open-policy-agent/discussions/15

I agree that there is a usability limitation here, though.

One thought would be to allow filtering (or other tests) on the container name, which would be immutable. I'm not sure container name is always a good proxy/sorting function for which images need re-writing, but curious if it would map on to your use case?

Kubernetes is also looking at hosted mutation (similar to the CEL KEP for hosted validation). I'm curious to see what their conclusions are before investing too deeply into mutations, as that has the potential to significantly disrupt the use cases/value proposition of webhook-based mutation.

maxsmythe avatar Apr 05 '23 01:04 maxsmythe

One thought would be to allow filtering (or other tests) on the container name, which would be immutable.

Would this be a new field or reuse pathTests?

ritazh avatar Apr 05 '23 05:04 ritazh

An extension of the location spec. Something like spec.containers[name:~^regexPrefix.*].image (not saying exactly that syntax)

maxsmythe avatar Apr 05 '23 19:04 maxsmythe

@davis-haba are we okay to close this with #2429?

sozercan avatar Apr 05 '23 21:04 sozercan

I'm not sure container name is always a good proxy/sorting function for which images need re-writing, but curious if it would map on to your use case?

Unfortunately it would really only work for me based on the original image registry. As new workloads get deployed I'd have to keep creating new instances of AssignImage, I would end up with about 300 of these.

Good to know about the hosted mutation, thank you. if you know of any area it's actively being discussed I'd love to follow along.

ctml91 avatar Apr 05 '23 23:04 ctml91

Let me ask what the status of the discussion is and where/how to engage.

maxsmythe avatar Apr 06 '23 23:04 maxsmythe

It sounds like the most likely channel is sig-api-machinery's google group:

https://groups.google.com/g/kubernetes-sig-api-machinery

There's some early thought being put into the shape of things and to better understand the problem.

maxsmythe avatar Apr 13 '23 02:04 maxsmythe