@@ -21,6 +21,7 @@ import (
2121 dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
2222 appsv1 "k8s.io/api/apps/v1"
2323 corev1 "k8s.io/api/core/v1"
24+ networkingv1 "k8s.io/api/networking/v1"
2425 "k8s.io/apimachinery/pkg/api/resource"
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627)
@@ -285,6 +286,9 @@ type WorkspaceConfig struct {
285286 // Overrides defines configuration options for `container-overrides` and
286287 // `pod-overrides` DevWorkspace attributes.
287288 Overrides * OverrideConfig `json:"overrides,omitempty"`
289+ // NetworkPolicy defines configuration options for the NetworkPolicy provisioned
290+ // for each DevWorkspace.
291+ NetworkPolicy * NetworkPolicyConfig `json:"networkPolicy,omitempty"`
288292}
289293
290294type WebhookConfig struct {
@@ -320,6 +324,43 @@ type PersistentHomeConfig struct {
320324 DisableInitContainer * bool `json:"disableInitContainer,omitempty"`
321325}
322326
327+ // NetworkPolicyConfig defines the NetworkPolicy the DevWorkspace Operator provisions for
328+ // DevWorkspaces. One NetworkPolicy is created per DevWorkspace and applies to that
329+ // workspace's pods only. The policy is owned by its DevWorkspace and is removed along
330+ // with it.
331+ //
332+ // The name, labels, podSelector and policyTypes of the NetworkPolicy are controlled by
333+ // the DevWorkspace Operator; only the ingress and egress rules are configurable.
334+ type NetworkPolicyConfig struct {
335+ // Enabled determines whether a NetworkPolicy is provisioned for each DevWorkspace.
336+ // Disabled by default. Changing this field does not immediately affect existing
337+ // DevWorkspaces: changing the DevWorkspaceOperatorConfig does not enqueue the
338+ // DevWorkspaces it affects, so the new value is applied to a DevWorkspace the next
339+ // time that DevWorkspace is reconciled for any reason. Restarting a workspace is not
340+ // required. Both enabling and disabling apply to running and stopped DevWorkspaces
341+ // alike.
342+ Enabled * bool `json:"enabled,omitempty"`
343+ // Ingress defines the ingress rules applied to DevWorkspace pods. If this field is not
344+ // specified, the default ingress rules of the DevWorkspace Operator apply. On OpenShift,
345+ // the defaults allow traffic from the operator's own namespace and from the OpenShift
346+ // monitoring, ingress, and host-network namespaces, and deny all other ingress traffic.
347+ // On Kubernetes, the default allows all ingress traffic, since the namespace of the
348+ // cluster's ingress controller is not known to the operator; administrators are expected
349+ // to replace this with rules appropriate to their cluster.
350+ // If this field is specified as an empty list, all ingress traffic to DevWorkspace pods
351+ // is denied. If this field is specified as a non-empty list, exactly those rules apply
352+ // and the default rules no longer apply.
353+ // +kubebuilder:validation:Optional
354+ Ingress []networkingv1.NetworkPolicyIngressRule `json:"ingress,omitempty"`
355+ // Egress defines the egress rules applied to DevWorkspace pods. If this field is not
356+ // specified, the default egress rule of the DevWorkspace Operator applies, which allows
357+ // all egress traffic. If this field is specified as an empty list, all egress traffic
358+ // from DevWorkspace pods is denied. If this field is specified as a non-empty list,
359+ // exactly those rules apply and the default rule no longer applies.
360+ // +kubebuilder:validation:Optional
361+ Egress []networkingv1.NetworkPolicyEgressRule `json:"egress,omitempty"`
362+ }
363+
323364type Proxy struct {
324365 // HttpProxy is the URL of the proxy for HTTP requests, in the format http://USERNAME:PASSWORD@SERVER:PORT/. To ignore
325366 // automatically detected proxy settings for the cluster, set this field to an empty string ("")
0 commit comments