-
Notifications
You must be signed in to change notification settings - Fork 69
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 ACL support for allowing cross-namespace access to image repository #162
Conversation
- add `AccessFrom` to ImageRepositorySpec for granting cross-namespace access to repositories - change `ImageRepositoryRef` type from local reference to namespaced reference Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
When a policy refers to a repository in a different namespace, the controller checks if the policy namespace labels match any of the selectors defined on the ImageRepository object. If the namespace where the policy resides, doesn't have labels or the labels don't match the repository ACL, then the controller sets the policy ready status to false and the reason to AccessDenied. The access denied error message is set on the ready condition message and logged before the controller rejects the policy. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Is it possible to gain access to an |
Yes in the same way it's possible to access an app endpoint cross-namespace guarded by a network policy. I should've specify that this proposal is inspired by the Kubernetes NetworkPolicy API.
Given our tenancy approach showcased here https://github.com/fluxcd/flux2-multi-tenancy this is not possible, a tenant can't create its own namespaces nor it can change the labels of an existing namespace. In regards to fluxcd/flux2#582, a tenant has access to namespaced objects (due to the role binding) so it can't alter namespaces unless the cluster admins explicitly grants this permission. |
Seems to be controversial there, too: kubernetes/kubernetes#88253 There is a decent solution that arose in that issue: let people select namespaces by name. That way, if you care you can at least close that loophole (and if you don't, just select everything). Namespaces have a label with their name, in Kubernetes 1.21. |
Yes, I don't expect everyone to be on 1.21 but we should document this in the API spec docs and tell people to use the readonly name label if they upgrade. |
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.
Presumably much of this can move to fluxcd/pkg/ at some point, since it's pretty general. In the meantime, I think
- the meaning of no selectors; and,
- using metav1 for doing the matching
are worth addressing (either with changes or comments here ..)
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
@squaremo I've added the Kubernetes readony label to docs, hopefully people will change their selectors once they upgrade to 1.21. |
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.
One typo, and the remaining question over what no selectors means.
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
I'm building up some new clusters and migrating our workloads from flux v1 to v2. This route makes more logical sense to me as I can now keep a set of apps, repo secrets, and associated It is also helpful as we restrict engineer teams by namespace. This will help avoid needing access across namespaces or relying on another team to manage flux. |
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.
OK cool, looks good to me. I'm glad to have an answer for the people who ask after this! Thank you Stefan 🍇
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.
LGTM, looking forward to seeing this translated to a fluxcd/pkg
contribution :-)
Problem
In the current implementation, users are forced into placing all the image automation objects in the same namespace because the
ImagePolicy
can refer to anImageRepository
only 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.Initial proposal: fluxcd/flux2#582 (comment)
Issues: fluxcd/image-automation-controller#85 fluxcd/image-automation-controller#151
Proposed solution
To allow an
ImagePolicy
to refer anImageRepository
across the cluster, theImageRepositoryRef
type changes fromLocaObjectReference
toNamespacedObjectReference
.The
ImageRepositoryRef.Namespace
is optional, when not specified, the controller behaves like before: it looks for theImageRepository
in the same namespace as theImagePolicy
.To grant access to an
ImageRepository
to policies in other namespaces, the owner of theImageRepository
has to specify a list of label selectors that match the namespaces of theImagePolicy
objects.When a policy refers to a repository in a different namespace, the controller checks if the policy namespace labels match any of the selectors defined on the ImageRepository object. If the namespace where the policy resides doesn't have labels or the labels don't match the repository ACL, then the controller sets the policy
Ready
status to false and the reason toAccessDenied
. The access denied error message is set on theReady
condition message and logged before the controller rejects the policy.Example
Assuming you have an
apps
namespace where the image pull secrets are. Instead of creating all image automation objects in theapps
namespace and copy the Git auth secret fromflux-system
intoapps
, you can only define theImageRepository
inapps
and grant access toImagePolicies
defined influx-system
namespace:The
ImagePolicies
defined influx-system
namespace can now reference theapp1
repository fromapps
namespace:If the owner of an
ImageRepository
wants to grant access to the repo for all namespaces in a cluster, this can be done with an emptymatchLabels
:Feedback & Testing
Please comment on this PR and let us know your thoughts about this feature.
To install the controller with the ACL capability:
kubectl apply -k https://github.com/fluxcd/image-reflector-controller/config/crd?ref=image-acl