Skip to content

Commit 3f9ad25

Browse files
authored
Merge pull request #3486 from embik/permission-claims-v1alpha2
Move permission claim object selectors from APIExport to APIBinding
2 parents fff9339 + cda9df1 commit 3f9ad25

File tree

45 files changed

+2092
-1082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2092
-1082
lines changed

cli/pkg/bind/plugin/bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (b *BindOptions) parsePermissionClaim(claim string, accepted bool) error {
235235
parsedClaim.State = apisv1alpha2.ClaimRejected
236236
}
237237
// TODO(mjudeikis): Once we add support for selectors/
238-
parsedClaim.All = true
238+
parsedClaim.Selector = apisv1alpha2.PermissionClaimSelector{MatchAll: true}
239239

240240
if accepted {
241241
b.acceptedPermissionClaims = append(b.acceptedPermissionClaims, parsedClaim)

cli/pkg/workspace/plugin/use.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func findUnresolvedPermissionClaims(out io.Writer, apiBindings []apisv1alpha2.AP
430430
var found, ack, verbsMatch bool
431431
var verbsExpected, verbsActual sets.Set[string]
432432
for _, specClaim := range binding.Spec.PermissionClaims {
433-
if !exportedClaim.Equal(specClaim.PermissionClaim) {
433+
if !exportedClaim.EqualGRI(specClaim.PermissionClaim) {
434434
continue
435435
}
436436
found = true

cli/pkg/workspace/plugin/use_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,14 @@ func (b *bindingBuilder) WithPermissionClaim(group, resource, identityHash strin
961961
}
962962

963963
pc := apisv1alpha2.AcceptablePermissionClaim{
964-
PermissionClaim: apisv1alpha2.PermissionClaim{
965-
GroupResource: apisv1alpha2.GroupResource{
966-
Group: group,
967-
Resource: resource,
964+
ScopedPermissionClaim: apisv1alpha2.ScopedPermissionClaim{
965+
PermissionClaim: apisv1alpha2.PermissionClaim{
966+
GroupResource: apisv1alpha2.GroupResource{
967+
Group: group,
968+
Resource: resource,
969+
},
970+
IdentityHash: identityHash,
968971
},
969-
IdentityHash: identityHash,
970972
},
971973
}
972974

config/crds/apis.kcp.io_apibindings.yaml

Lines changed: 132 additions & 101 deletions
Large diffs are not rendered by default.

config/crds/apis.kcp.io_apiexports.yaml

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ spec:
399399
Its purpose is to determine the added permissions that a service provider may
400400
request and that a consumer may accept and allow the service provider access to.
401401
properties:
402-
all:
403-
description: |-
404-
all claims all resources for the given group/resource.
405-
This is mutually exclusive with resourceSelector.
406-
type: boolean
407402
group:
408403
default: ""
409404
description: |-
@@ -412,6 +407,7 @@ spec:
412407
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
413408
type: string
414409
identityHash:
410+
default: ""
415411
description: |-
416412
This is the identity for a given APIExport that the APIResourceSchema belongs to.
417413
The hash can be found on APIExport and APIResourceSchema's status.
@@ -425,31 +421,6 @@ spec:
425421
not provided by an api export.
426422
pattern: ^[a-z][-a-z0-9]*[a-z0-9]$
427423
type: string
428-
resourceSelector:
429-
description: resourceSelector is a list of claimed resource
430-
selectors.
431-
items:
432-
properties:
433-
name:
434-
description: |-
435-
name of an object within a claimed group/resource.
436-
It matches the metadata.name field of the underlying object.
437-
If namespace is unset, all objects matching that name will be claimed.
438-
maxLength: 253
439-
minLength: 1
440-
pattern: ^([a-z0-9][-a-z0-9_.]*)?[a-z0-9]$
441-
type: string
442-
namespace:
443-
description: |-
444-
namespace containing the named object. Matches metadata.namespace field.
445-
If "name" is unset, all objects from the namespace are being claimed.
446-
minLength: 1
447-
type: string
448-
type: object
449-
x-kubernetes-validations:
450-
- message: at least one field must be set
451-
rule: has(self.__namespace__) || has(self.name)
452-
type: array
453424
verbs:
454425
description: |-
455426
verbs is a list of supported API operation types (this includes
@@ -464,10 +435,6 @@ spec:
464435
- resource
465436
- verbs
466437
type: object
467-
x-kubernetes-validations:
468-
- message: either "all" or "resourceSelector" must be set
469-
rule: (has(self.all) && self.all) != (has(self.resourceSelector)
470-
&& size(self.resourceSelector) > 0)
471438
type: array
472439
x-kubernetes-list-map-keys:
473440
- group

pkg/admission/apibinding/apibinding_admission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func validateOverhangingPermissionClaims(_ context.Context, _ admission.Attribut
347347
for _, o := range overhanging {
348348
var found bool
349349
for _, pc := range v2Claims {
350-
if pc.Equal(o) {
350+
if pc.EqualGRI(o) {
351351
found = true
352352

353353
break

pkg/admission/apibinding/apibinding_admission_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
598598
Group: "foo",
599599
Resource: "bar",
600600
},
601-
All: true,
602601
IdentityHash: "baz",
603602
Verbs: []string{"get", "list"},
604603
}}
@@ -632,7 +631,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
632631
Group: "foo",
633632
Resource: "bar",
634633
},
635-
All: true,
636634
IdentityHash: "baz",
637635
Verbs: []string{"get", "list"},
638636
},
@@ -641,7 +639,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
641639
Group: "foo",
642640
Resource: "baz",
643641
},
644-
All: true,
645642
IdentityHash: "bar",
646643
Verbs: []string{"get"},
647644
},

pkg/admission/apiexport/admission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func validateOverhangingPermissionClaims(_ context.Context, _ admission.Attribut
218218
for _, o := range overhanging {
219219
var found bool
220220
for _, pc := range v2Claims {
221-
if pc.Equal(o) {
221+
if pc.EqualGRI(o) {
222222
found = true
223223

224224
break

pkg/admission/apiexport/admission_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
433433
Group: "foo",
434434
Resource: "bar",
435435
},
436-
All: true,
437436
IdentityHash: "baz",
438437
Verbs: []string{"get", "list"},
439438
}}
@@ -465,7 +464,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
465464
Group: "foo",
466465
Resource: "bar",
467466
},
468-
All: true,
469467
IdentityHash: "baz",
470468
Verbs: []string{"get", "list"},
471469
},
@@ -474,7 +472,6 @@ func TestValidateOverhangingPermissionClaims(t *testing.T) {
474472
Group: "foo",
475473
Resource: "baz",
476474
},
477-
All: true,
478475
IdentityHash: "bar",
479476
Verbs: []string{"get"},
480477
},

pkg/admission/permissionclaims/mutating_permission_claims.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (m *mutatingPermissionClaims) Admit(ctx context.Context, a admission.Attrib
8989
return err
9090
}
9191

92-
expectedLabels, err := m.permissionClaimLabeler.LabelsFor(ctx, clusterName, a.GetResource().GroupResource(), a.GetName())
92+
expectedLabels, err := m.permissionClaimLabeler.LabelsFor(ctx, clusterName, a.GetResource().GroupResource(), a.GetName(), u.GetLabels())
9393
if err != nil {
9494
return err
9595
}
@@ -129,7 +129,7 @@ func (m *mutatingPermissionClaims) Validate(ctx context.Context, a admission.Att
129129
return err
130130
}
131131

132-
expectedLabels, err := m.permissionClaimLabeler.LabelsFor(ctx, clusterName, a.GetResource().GroupResource(), a.GetName())
132+
expectedLabels, err := m.permissionClaimLabeler.LabelsFor(ctx, clusterName, a.GetResource().GroupResource(), a.GetName(), u.GetLabels())
133133
if err != nil {
134134
return err
135135
}

0 commit comments

Comments
 (0)