Skip to content

Commit 4043db3

Browse files
committed
Ignore Kubernetes/OpenShift components that have deployByDefault=false
Since deployByDefault=false components are not intended to be deployed when the DevWorkspace is started, remove restrictions/checks on these components -- i.e. URI is allowed, and we don't check RBAC permissions. These components are meant to be deployed later, e.g. via an apply command, and so verifying RBAC permissions on them is up to the tool used to apply them (e.g. by using the user's token to apply the resources). Signed-off-by: Angel Misevski <[email protected]>
1 parent e1269d6 commit 4043db3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/library/kubernetes/util.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func filterForKubeLikeComponents(components []dw.Component) ([]dw.Component, err
4343
if k8sLikeComponent.Inlined == "" {
4444
continue
4545
}
46-
k8sLikeComponents = append(k8sLikeComponents, component)
46+
if k8sLikeComponent.GetDeployByDefault() {
47+
k8sLikeComponents = append(k8sLikeComponents, component)
48+
}
4749
}
4850
return k8sLikeComponents, nil
4951
}

webhook/workspace/handler/kubernetes.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import (
2929
func (h *WebhookHandler) validateKubernetesObjectPermissionsOnCreate(ctx context.Context, req admission.Request, wksp *dwv2.DevWorkspaceTemplateSpec) error {
3030
kubeComponents := getKubeComponentsFromWorkspace(wksp)
3131
for componentName, component := range kubeComponents {
32+
if !component.GetDeployByDefault() {
33+
// Intended to be applied later, will not be handled by DWO. It's up to whoever applies it to make
34+
// sure that's safe to do (e.g. by using the user's token to apply the yaml)
35+
continue
36+
}
3237
if component.Uri != "" {
3338
return fmt.Errorf("kubenetes components specified via URI are unsupported")
3439
}
@@ -47,6 +52,12 @@ func (h *WebhookHandler) validateKubernetesObjectPermissionsOnUpdate(ctx context
4752
oldKubeComponents := getKubeComponentsFromWorkspace(oldWksp)
4853

4954
for componentName, newComponent := range newKubeComponents {
55+
if !newComponent.GetDeployByDefault() {
56+
// Intended to be applied later, will not be handled by DWO. It's up to whoever applies it to make
57+
// sure that's safe to do (e.g. by using the user's token to apply the yaml)
58+
continue
59+
}
60+
5061
if newComponent.Uri != "" {
5162
return fmt.Errorf("kubenetes components specified via URI are unsupported")
5263
}
@@ -179,6 +190,9 @@ func (h *WebhookHandler) validateKubernetesObjectPermissionsOnCreate_v1alpha1(ct
179190
if component.Inlined == "" {
180191
return fmt.Errorf("kubernetes component does not define inlined content")
181192
}
193+
// v1alpha1 DevWorkspace/DevWorkspaceTemplates do not have a deployByDefault field, and the default
194+
// value in v1alpha2 is false (i.e. do not deploy at start time); however, for safety we check permissions
195+
// even if the object will not be deployed (v1alpha1 should not be used, in general)
182196
if err := h.validatePermissionsOnObject(ctx, req, componentName, component.Inlined); err != nil {
183197
return err
184198
}
@@ -198,6 +212,9 @@ func (h *WebhookHandler) validateKubernetesObjectPermissionsOnUpdate_v1alpha1(ct
198212
return fmt.Errorf("kubernetes component does not define inlined content")
199213
}
200214

215+
// v1alpha1 DevWorkspace/DevWorkspaceTemplates do not have a deployByDefault field, and the default
216+
// value in v1alpha2 is false (i.e. do not deploy at start time); however, for safety we check permissions
217+
// even if the object will not be deployed (v1alpha1 should not be used, in general)
201218
oldComponent, ok := oldKubeComponents[componentName]
202219
if !ok || oldComponent.Inlined != newComponent.Inlined {
203220
// Review new components

0 commit comments

Comments
 (0)