Skip to content

Commit 7306b32

Browse files
authored
Add config option to disable user RBAC checks in create webhook (#117)
This would enable a cluster configuration where a user has permission to create AppWrappers that contains pods, deployments, etc. but do not have the ability to create pods or deployments directly (as Kueue does not have the ability to enforce quotas on these resources).
1 parent 8e982a4 commit 7306b32

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

internal/webhook/appwrapper_webhook.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -182,33 +182,35 @@ func (w *AppWrapperWebhook) validateAppWrapperCreate(ctx context.Context, aw *wo
182182
}
183183

184184
// 3. RBAC check: Perform SubjectAccessReview to verify user is entitled to create component
185-
ra := authv1.ResourceAttributes{
186-
Namespace: aw.Namespace,
187-
Verb: "create",
188-
Group: gvk.Group,
189-
Version: gvk.Version,
190-
Resource: w.lookupResource(gvk),
191-
}
192-
sar := &authv1.SubjectAccessReview{
193-
Spec: authv1.SubjectAccessReviewSpec{
194-
ResourceAttributes: &ra,
195-
User: userInfo.Username,
196-
UID: userInfo.UID,
197-
Groups: userInfo.Groups,
198-
}}
199-
if len(userInfo.Extra) > 0 {
200-
sar.Spec.Extra = make(map[string]authv1.ExtraValue, len(userInfo.Extra))
201-
for k, v := range userInfo.Extra {
202-
sar.Spec.Extra[k] = authv1.ExtraValue(v)
185+
if w.Config.UserRBACAdmissionCheck {
186+
ra := authv1.ResourceAttributes{
187+
Namespace: aw.Namespace,
188+
Verb: "create",
189+
Group: gvk.Group,
190+
Version: gvk.Version,
191+
Resource: w.lookupResource(gvk),
203192
}
204-
}
205-
sar, err = w.SubjectAccessReviewer.Create(ctx, sar, metav1.CreateOptions{})
206-
if err != nil {
207-
allErrors = append(allErrors, field.InternalError(compPath.Child("template"), err))
208-
} else {
209-
if !sar.Status.Allowed {
210-
reason := fmt.Sprintf("User %v is not authorized to create %v in %v", userInfo.Username, ra.Resource, ra.Namespace)
211-
allErrors = append(allErrors, field.Forbidden(compPath.Child("template"), reason))
193+
sar := &authv1.SubjectAccessReview{
194+
Spec: authv1.SubjectAccessReviewSpec{
195+
ResourceAttributes: &ra,
196+
User: userInfo.Username,
197+
UID: userInfo.UID,
198+
Groups: userInfo.Groups,
199+
}}
200+
if len(userInfo.Extra) > 0 {
201+
sar.Spec.Extra = make(map[string]authv1.ExtraValue, len(userInfo.Extra))
202+
for k, v := range userInfo.Extra {
203+
sar.Spec.Extra[k] = authv1.ExtraValue(v)
204+
}
205+
}
206+
sar, err = w.SubjectAccessReviewer.Create(ctx, sar, metav1.CreateOptions{})
207+
if err != nil {
208+
allErrors = append(allErrors, field.InternalError(compPath.Child("template"), err))
209+
} else {
210+
if !sar.Status.Allowed {
211+
reason := fmt.Sprintf("User %v is not authorized to create %v in %v", userInfo.Username, ra.Resource, ra.Namespace)
212+
allErrors = append(allErrors, field.Forbidden(compPath.Child("template"), reason))
213+
}
212214
}
213215
}
214216

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type AppWrapperConfig struct {
3232
ManageJobsWithoutQueueName bool `json:"manageJobsWithoutQueueName,omitempty"`
3333
EnableKueueIntegrations bool `json:"enableKueueIntegrations,omitempty"`
3434
DisableChildAdmissionCtrl bool `json:"disableChildAdmissionCtrl,omitempty"`
35+
UserRBACAdmissionCheck bool `json:"userRBACAdmissionCheck,omitempty"`
3536
FaultTolerance *FaultToleranceConfig `json:"faultTolerance,omitempty"`
3637
}
3738

@@ -77,6 +78,7 @@ func NewAppWrapperConfig() *AppWrapperConfig {
7778
ManageJobsWithoutQueueName: true,
7879
EnableKueueIntegrations: true,
7980
DisableChildAdmissionCtrl: false,
81+
UserRBACAdmissionCheck: true,
8082
FaultTolerance: &FaultToleranceConfig{
8183
WarmupGracePeriod: 5 * time.Minute,
8284
FailureGracePeriod: 1 * time.Minute,

0 commit comments

Comments
 (0)