Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/virtual/apiexport/authorizer/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ func (a *boundAPIAuthorizer) Authorize(ctx context.Context, attr authorizer.Attr
}
}

allowedVerbs := apiBindingVerbs.Intersection(apiExportVerbs)
// a wildcard on either side allows everything the other side allows.
var allowedVerbs sets.Set[string]
switch {
case apiExportVerbs.Has(wildcardVerb):
allowedVerbs = apiBindingVerbs
case apiBindingVerbs.Has(wildcardVerb):
allowedVerbs = apiExportVerbs
default:
allowedVerbs = apiBindingVerbs.Intersection(apiExportVerbs)
}

if !allowedVerbs.HasAny(attr.GetVerb(), wildcardVerb) {
// if the requested verb is not found, the claim cannot be used.
Expand Down
110 changes: 110 additions & 0 deletions pkg/virtual/apiexport/authorizer/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,116 @@ func TestBoundAPIAuthorizer(t *testing.T) {
},
expectedDecision: authorizer.DecisionAllow,
},
{
name: "list request to the API bound via permission claims allowing wildcard on the APIExport only",
attr: &authorizer.AttributesRecord{
User: &user.DefaultInfo{},
APIGroup: "foo",
Resource: "bar",
Verb: "list",
},
apidomainKey: apidomainKey,
getAPIBindingByExport: func(clusterName, apiExportName, apiExportCluster string) (*apisv1alpha2.APIBinding, error) {
return &apisv1alpha2.APIBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: apisv1alpha2.APIBindingSpec{
PermissionClaims: []apisv1alpha2.AcceptablePermissionClaim{
{
ScopedPermissionClaim: apisv1alpha2.ScopedPermissionClaim{
PermissionClaim: apisv1alpha2.PermissionClaim{
GroupResource: apisv1alpha2.GroupResource{
Group: "foo",
Resource: "bar",
},
Verbs: []string{"get", "list"},
},
Selector: apisv1alpha2.PermissionClaimSelector{
MatchAll: true,
},
},
State: apisv1alpha2.ClaimAccepted,
},
},
},
}, nil
},
getAPIExport: func(clusterName, apiExportName string) (*apisv1alpha2.APIExport, error) {
return &apisv1alpha2.APIExport{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: apisv1alpha2.APIExportSpec{
PermissionClaims: []apisv1alpha2.PermissionClaim{
{
GroupResource: apisv1alpha2.GroupResource{
Group: "foo",
Resource: "bar",
},
Verbs: []string{"*"},
},
},
},
}, nil
},
expectedDecision: authorizer.DecisionAllow,
},
{
name: "list request to the API bound via permission claims allowing wildcard on the APIBinding only",
attr: &authorizer.AttributesRecord{
User: &user.DefaultInfo{},
APIGroup: "foo",
Resource: "bar",
Verb: "list",
},
apidomainKey: apidomainKey,
getAPIBindingByExport: func(clusterName, apiExportName, apiExportCluster string) (*apisv1alpha2.APIBinding, error) {
return &apisv1alpha2.APIBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: apisv1alpha2.APIBindingSpec{
PermissionClaims: []apisv1alpha2.AcceptablePermissionClaim{
{
ScopedPermissionClaim: apisv1alpha2.ScopedPermissionClaim{
PermissionClaim: apisv1alpha2.PermissionClaim{
GroupResource: apisv1alpha2.GroupResource{
Group: "foo",
Resource: "bar",
},
Verbs: []string{"*"},
},
Selector: apisv1alpha2.PermissionClaimSelector{
MatchAll: true,
},
},
State: apisv1alpha2.ClaimAccepted,
},
},
},
}, nil
},
getAPIExport: func(clusterName, apiExportName string) (*apisv1alpha2.APIExport, error) {
return &apisv1alpha2.APIExport{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
Spec: apisv1alpha2.APIExportSpec{
PermissionClaims: []apisv1alpha2.PermissionClaim{
{
GroupResource: apisv1alpha2.GroupResource{
Group: "foo",
Resource: "bar",
},
Verbs: []string{"get", "list"},
},
},
},
}, nil
},
expectedDecision: authorizer.DecisionAllow,
},
{
name: "list request to the API bound via permission claims allowing wildcard (rejected claim)",
attr: &authorizer.AttributesRecord{
Expand Down
Loading