Skip to content

Commit

Permalink
include cluster name in authz SubjectAccessReview in webhooks
Browse files Browse the repository at this point in the history
On-behalf-of: @SAP [email protected]
  • Loading branch information
xrstf committed Nov 13, 2024
1 parent ab5c3a6 commit 2ec0f78
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
authorizationcel "k8s.io/apiserver/pkg/authorization/cel"
"k8s.io/apiserver/pkg/endpoints/request"
genericfeatures "k8s.io/apiserver/pkg/features"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/apiserver/pkg/util/webhook"
Expand Down Expand Up @@ -196,6 +197,14 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
}
}

clusterName, err := request.ClusterNameFrom(ctx)
if err == nil {
if r.Spec.Extra == nil {
r.Spec.Extra = map[string]authorizationv1.ExtraValue{}
}
r.Spec.Extra["authentication.kubernetes.io/cluster-name"] = authorizationv1.ExtraValue{clusterName.Path().String()}
}

if attr.IsResourceRequest() {
r.Spec.ResourceAttributes = resourceAttributesFrom(attr)
} else {
Expand Down

0 comments on commit 2ec0f78

Please sign in to comment.