Skip to content

Commit 51d0812

Browse files
authored
Add extra field when doing SubjectAccessReview (#265)
Pass UserInfo.Extra fields when constructing the SubjectAccessReview for the requesting user in the WorkerResourceTemplate validating webhook. Previously, the webhook only forwarded User and Groups to the SAR spec. This omitted the Extra field, which cloud providers like GKE use to carry IAM identity information (e.g. iam.gke.io/user-assertion). Without it, the SAR could not evaluate permissions granted via GKE IAM or GCP group membership, only direct RBAC bindings to a specific username were recognized. deployed to one GKE cluster, people with GKE IAM Admin permission can create/update/delete WorkerResourceTemplate resource without granting Kubernetes built-in RBAC bindings
1 parent 24f1d21 commit 51d0812

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

api/v1alpha1/workerresourcetemplate_webhook.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strings"
99

10+
authenticationv1 "k8s.io/api/authentication/v1"
1011
authorizationv1 "k8s.io/api/authorization/v1"
1112
apierrors "k8s.io/apimachinery/pkg/api/errors"
1213
"k8s.io/apimachinery/pkg/api/meta"
@@ -390,6 +391,19 @@ func isEmptyMap(v interface{}) bool {
390391
return ok && len(m) == 0
391392
}
392393

394+
// convertUserInfoExtra converts an authentication ExtraValue map to an authorization ExtraValue map.
395+
// Both types are []string under the hood; the conversion preserves all values exactly.
396+
func convertUserInfoExtra(extra map[string]authenticationv1.ExtraValue) map[string]authorizationv1.ExtraValue {
397+
if len(extra) == 0 {
398+
return nil
399+
}
400+
out := make(map[string]authorizationv1.ExtraValue, len(extra))
401+
for k, v := range extra {
402+
out[k] = authorizationv1.ExtraValue(v)
403+
}
404+
return out
405+
}
406+
393407
// validateWithAPI performs API-dependent validation: RESTMapper scope check and
394408
// SubjectAccessReview for both the requesting user and the controller service account.
395409
// verb is the RBAC verb to check ("create" on create/update, "delete" on delete).
@@ -456,6 +470,11 @@ func (v *WorkerResourceTemplateValidator) validateWithAPI(ctx context.Context, w
456470
Spec: authorizationv1.SubjectAccessReviewSpec{
457471
User: req.UserInfo.Username,
458472
Groups: req.UserInfo.Groups,
473+
// Some authentication plugins like GKE's IAM plugin rely on certain fields being
474+
// present in the UserInfo.Extra field, so here we make sure to copy any extra
475+
// field values from the authentication request into the extra field of the
476+
// authorization review.
477+
Extra: convertUserInfoExtra(req.UserInfo.Extra),
459478
ResourceAttributes: &authorizationv1.ResourceAttributes{
460479
Namespace: wrt.Namespace,
461480
Verb: verb,

0 commit comments

Comments
 (0)