Skip to content
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions api/v1alpha1/workerresourcetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

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

// convertUserInfoExtra converts an authentication ExtraValue map to an authorization ExtraValue map.
// Both types are []string under the hood; the conversion preserves all values exactly.
func convertUserInfoExtra(extra map[string]authenticationv1.ExtraValue) map[string]authorizationv1.ExtraValue {
if len(extra) == 0 {
return nil
}
out := make(map[string]authorizationv1.ExtraValue, len(extra))
for k, v := range extra {
out[k] = authorizationv1.ExtraValue(v)
}
return out
}

// validateWithAPI performs API-dependent validation: RESTMapper scope check and
// SubjectAccessReview for both the requesting user and the controller service account.
// verb is the RBAC verb to check ("create" on create/update, "delete" on delete).
Expand Down Expand Up @@ -456,6 +470,7 @@ func (v *WorkerResourceTemplateValidator) validateWithAPI(ctx context.Context, w
Spec: authorizationv1.SubjectAccessReviewSpec{
User: req.UserInfo.Username,
Groups: req.UserInfo.Groups,
Extra: convertUserInfoExtra(req.UserInfo.Extra),
Comment thread
jaypipes marked this conversation as resolved.
Outdated
ResourceAttributes: &authorizationv1.ResourceAttributes{
Namespace: wrt.Namespace,
Verb: verb,
Expand Down