Skip to content

Commit 041a18c

Browse files
committed
Fail dw webhook if controller does not have permissions to manage type
Reject DevWorkspaces that use Kubernetes/OpenShift components that define objects the DevWorkspace Operator's service account does not have permissions to manage. This is done to give the user a clearer error message when DWO needs additional permissions. Signed-off-by: Angel Misevski <[email protected]>
1 parent c1006d1 commit 041a18c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

webhook/workspace/handler/kubernetes.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,36 @@ func (h *WebhookHandler) validatePermissionsOnObject(ctx context.Context, req ad
109109
if username == "" {
110110
username = req.UserInfo.UID
111111
}
112-
113112
if !sar.Status.Allowed {
114113
return fmt.Errorf("user %s does not have permissions to work with objects of kind %s defined in component %s", username, typeMeta.GroupVersionKind().String(), componentName)
115114
}
116115

116+
ssar := &authv1.LocalSubjectAccessReview{
117+
ObjectMeta: metav1.ObjectMeta{
118+
Namespace: req.Namespace,
119+
},
120+
Spec: authv1.SubjectAccessReviewSpec{
121+
ResourceAttributes: &authv1.ResourceAttributes{
122+
Namespace: req.Namespace,
123+
Verb: "*",
124+
Group: typeMeta.GroupVersionKind().Group,
125+
Version: typeMeta.GroupVersionKind().Version,
126+
Resource: resourceType,
127+
},
128+
User: h.ControllerSAName,
129+
UID: h.ControllerUID,
130+
},
131+
}
132+
if err := h.Client.Create(ctx, ssar); err != nil {
133+
return fmt.Errorf("failed to create subjectaccessreview for request: %w", err)
134+
}
135+
136+
if !ssar.Status.Allowed {
137+
return fmt.Errorf("devworkspace controller serviceaccount does not have permissions to manage "+
138+
"kind %s defined in component %s -- an administrator needs to grant the devworkspace operator "+
139+
"permissions ('*') %s to use this DevWorkspace", kind, componentName, typeMeta.GroupVersionKind().String())
140+
}
141+
117142
return nil
118143
}
119144

0 commit comments

Comments
 (0)