-
Notifications
You must be signed in to change notification settings - Fork 75
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
[RFC] Add support for selecting policies based on namespace labels #157
Conversation
PolicyNamespaceSelector is used for selecting policies in all namespaces that match the list of labels and their values. When not specified, it defaults to selecting the policies present in the same namespace as the ImageUpdateAutomation. Signed-off-by: Stefan Prodan <[email protected]>
b0508f3
to
c4b80c4
Compare
It would be nice if we have a construct for scan-all or something equivalent which can enable the updation Policy to all namespaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change! This will work fine for our situation, although there is a drawback. In order to suspend or enable image update automation for a given namespace, one has to add or remove a label to the namespace itself. We restrict our teams' access to modify the definitions of namespaces they operate in, in order to ensure the security related annotations (for kiam or kubernetes-external-secrets, for example) stay intact. So the teams will not be able to suspend/re-enable image automation updates on their own. It can be an obstacle, but not an insurmountable one - one can write a simple controller to watch for some condition within the namespaces and update the namespace labels accordingly.
They can, either by suspending the |
Signed-off-by: Stefan Prodan <[email protected]>
c4b80c4
to
2fc7b05
Compare
At my first glance, this proposal seems reasonable and enables behavior that platform admins would otherwise need a custom controller for. I think it composes well with the myriad of mechanisms we've gone over for Source Policy. (fluxcd/flux2#582 (comment)) |
Any reason |
Can be anything, it's up to the user to decide what labels to use, |
@stealthybox that's not the case, the |
Sorry @stefanprodan You're likely right that the behavior is inconsequential, but I'd consider using an impersonated user on that client for auditing and to prevent any information disclosure |
Hi, we tested this out in one of our dev clusters, and it appears to be working. Would love to see this get merged. Is there a chance it will be accepted as a solution? |
I have tested the pr now and it works. Thanks :) Maybe the other way around, to enable all namespaces by default, and disabling namespaces explicitly where auto update is not wanted, would be a nice option too. |
No secrets are fetched from other namespaces, but who is to say that image names are not sensitive? If I've understood the implementation here: given access to create an automation in any namespace, I can exfiltrate image names for image repositories that I don't have access to, from any other namespace.
This is different from the grant of access as proposed in .. I can't find it .. source access lists. In that model, the bearer of access (GitRepository) grants access to resources in other namespaces. In this design, access is claimed by resources in other namespaces. For that reason, I don't think this is consistent with Flux2's multi-tenant model, after all.
@rverma-nsl The implementation here has a special meaning for a missing
|
@squaremo how would you do this if the image URL is not in your repo? The only way to view the image names is in the commit message, but if an image is not in Git then it will not get printed I guess. |
Set up a git repo with any resource YAML in it, give a field an update marker naming the policy you want to read, then make an |
Who would you know the policy name if you don't have access to the namespaces where those are? |
You might have to guess it. The point is, it turns security by access control into security by obscurity. Would it be acceptable, say, for secrets in any namespace to be accessible to anyone who can guess the right name? (rhetorical question) |
Ok closing this, back to the drawing board. |
@davisford @monotek Would it work equally well for you if you could refer to a GitRepository in another namespace? |
@squaremo I'm puzzled by why we would require a To me, a Just as a side-note, because the controllers don't yet implement native auth against cloud image repositories (we use ECR), I also have to run the CronJob to refresh the secret in every single namespace too. |
@squaremo I think it would work too, but feels a bit odd, defining several |
@davisford This PR would have let you create an
@monotek Perhaps it feels odd given your use case, but for better or worse this situation is the norm in Kubernetes. For example, if you use the same image repository in different namespaces, you have to provide an imagePullSecret in each of those namespaces. Specifically with |
Having different committers per team/namespace might indeed be helpful :) |
This would work well for my use case. A Kustomization |
It would work -- having a separate |
The current solution is to run the CronJob in the flux-system namespace or some other admin only NS, then use Kyverno or other solutions to replicate the secret in all the namespaces that you want. See https://kyverno.io/docs/writing-policies/generate/#generating-resources-into-existing-namespaces |
@davisford |
@stefanprodan are we likely to see any workable solution to this in the near future with this solution being dropped, or will copying the |
New RFC here fluxcd/image-reflector-controller#162 |
Problem
In the current implementation, users are forced into placing all the image automation objects in the same namespace because the
ImageUpdateAutomation
selects only theImagePolicies
in the same namespace as itself. This means users have to copy the image pull secrets from their original namespaces into flux-system or copy the Git auth secret in all apps namespaces.@vladlosev explains why this limitation is a blocker in #151
Many other users face similar problems as seen in #85.
Proposed solution
To allow an
ImageUpdateAutomation
to applyImagePolicies
across the cluster, a label selector can be used to specify which namespaces the controller should look for policies.The
PolicyNamespaceSelector
is optional, when not specified the controller behaves like before, when only theImageUpdateAutomation
namespace is taking into considerations when selecting the image policies.In regards to multi-tenancy, this feature doesn't present any risks as no sensitive information is fetched from other namespaces.
Example
Assuming you have two app namespaces each with an image policy:
Instead of creating a pair of
ImageUpdateAutomation/GitRepository
in each namespace and copy the Git auth secret, you would use the namespace labelflux-auto: enabled
to select the policies in theImageUpdateAutomation
(that's in flux-system namespace):Feedback & Testing
Please comment on this PR and let us know your thoughts about this feature.
To install the controller with the
policyNamespaceSelector
capability:kubectl -n flux-system set image deployment/image-automation-controller \ manager=docker.io/stefanprodan/image-automation-controller:policy-selector.1