-
Notifications
You must be signed in to change notification settings - Fork 459
Implement subresources in VWs #4342
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
base: main
Are you sure you want to change the base?
Changes from all commits
9a0035f
c4e51af
012ebe1
0381bad
f4aebc2
7106c64
5f3f522
07811b9
39a8008
610db7e
4aba907
4243015
caa2147
ddf4fc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
|
@@ -177,6 +178,17 @@ func (o *apiBindingAdmission) Admit(ctx context.Context, a admission.Attributes, | |
| ab.SetLabels(lbls) | ||
| } | ||
|
|
||
| // subresource claims have no selector, set a matchAll so users | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user cannot set matchlabels/-expression; I added a CEL rule for that. |
||
| // don't have to repeat it for every subresource | ||
| if v2, ok := ab.(*apiBindingV1alpha2); ok { | ||
| for i := range v2.binding.Spec.PermissionClaims { | ||
| pc := &v2.binding.Spec.PermissionClaims[i] | ||
| if strings.Contains(pc.Resource, "/") { | ||
| pc.Selector.MatchAll = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // write back | ||
| raw, err := ab.ToUnstructured() | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,20 +131,25 @@ func (a *boundAPIAuthorizer) Authorize(ctx context.Context, attr authorizer.Attr | |
| // check if a resource claim for this resource has been accepted and has correct verbs. | ||
| // normalize the requested group/resource to handle the events.k8s.io ↔ core/v1 equivalence. | ||
| normalizedGR := permissionclaim.NormalizeEventGroupResource(schema.GroupResource{Group: attr.GetAPIGroup(), Resource: attr.GetResource()}) | ||
| // subresource status is implicitly granted with its parent resource. | ||
| // others must be claimed explicitly | ||
|
Comment on lines
+134
to
+135
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this always the case?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we just never checked for subresource permissions because only implemented status so far. E.g. we could gate the implicit status on a feature gate, but that isn't really nice.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Albeit not on paper, but the "spirit" of offering a service is for the consumer to give the spec, and provider to update the status - so I think it's assumed the provider needs access to that at all times, even when claiming. So if we're looking for an excuse to keep these perms implicit, I think this could be one :D but it does sound a bit weak.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean yeah but for resources exported via an APIExport we are already implicitly claiming the resource and the subresources^^ |
||
| claimedResource := normalizedGR.Resource | ||
| if sub := attr.GetSubresource(); sub != "" && sub != "status" { | ||
| claimedResource = normalizedGR.Resource + "/" + sub | ||
| } | ||
| for _, permissionClaim := range apiBinding.Spec.PermissionClaims { | ||
| if permissionClaim.State != apisv1alpha2.ClaimAccepted { | ||
| // if the claim is not accepted it cannot be used. | ||
| continue | ||
| } | ||
|
|
||
| if permissionClaim.Group == normalizedGR.Group && permissionClaim.Resource == normalizedGR.Resource { | ||
| if permissionClaim.Group == normalizedGR.Group && permissionClaim.Resource == claimedResource { | ||
| apiBindingVerbs := sets.New(permissionClaim.Verbs...) | ||
| apiExportVerbs := sets.New[string]() | ||
|
|
||
| apiExportVerbs := sets.New[string]() | ||
| for _, exportPermpermissionClaim := range apiExport.Spec.PermissionClaims { | ||
| if exportPermpermissionClaim.EqualGRI(permissionClaim.PermissionClaim) { | ||
| apiExportVerbs.Insert(exportPermpermissionClaim.Verbs...) | ||
|
|
||
| break | ||
| } | ||
| } | ||
|
|
||
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.
Does this meant that if I claim named resource
virtualmachineI will get all othervirtualmachinessubresources?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.
It just means that you can apply a selector on top of the selectors for the parent resource.
e.g. you have the
virtualmachinesresource with labelmy.exposed.resources=trueand then you claim the subresourcevirtualmachines/sshyou cannot apply another label filter on top.I had that implemented and I see some use for it (I mentioned that in the description) but I don't think that too many people will use it.
The story is basically "when you claim a subresource you must have access to its parent".
Hence the CEL validation that the selector must be matchall.