@@ -19,6 +19,8 @@ import (
1919 "strconv"
2020 "strings"
2121
22+ "k8s.io/utils/pointer"
23+
2224 ctrl "sigs.k8s.io/controller-runtime"
2325
2426 defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
@@ -45,7 +47,7 @@ type CheClusterSpec struct {
4547 // +optional
4648 // +operator-sdk:csv:customresourcedefinitions:type=spec,order=1
4749 // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Development environments"
48- // +kubebuilder:default:={storage: {pvcStrategy: per-user}, defaultNamespace: {template: <username>-che, autoProvision: true}, secondsOfInactivityBeforeIdling:1800, secondsOfRunBeforeIdling:-1, startTimeoutSeconds:300, maxNumberOfWorkspacesPerUser:-1}
50+ // +kubebuilder:default:={storage: {pvcStrategy: per-user}, defaultNamespace: {template: <username>-che, autoProvision: true}, secondsOfInactivityBeforeIdling:1800, secondsOfRunBeforeIdling:-1, startTimeoutSeconds:300, maxNumberOfWorkspacesPerUser:-1, disableContainerRunCapabilities:true }
4951 DevEnvironments CheClusterDevEnvironments `json:"devEnvironments"`
5052 // Che components configuration.
5153 // +optional
@@ -149,12 +151,23 @@ type CheClusterDevEnvironments struct {
149151 //
150152 // +optional
151153 DisableContainerBuildCapabilities * bool `json:"disableContainerBuildCapabilities,omitempty"`
154+ // Disables container run capabilities.
155+ // Can be enabled on OpenShift version 4.20 or later.
156+ // When set to `false`, the value from `devEnvironments.security.containerSecurityContext`
157+ // is ignored, and instead the SecurityContext defined in
158+ // `devEnvironments.containerRunConfiguration.containerSecurityContext` is applied.
159+ // +optional
160+ // +kubebuilder:default:=true
161+ DisableContainerRunCapabilities * bool `json:"disableContainerRunCapabilities,omitempty"`
152162 // Workspace security configuration.
153163 // +optional
154164 Security WorkspaceSecurityConfig `json:"security,omitempty"`
155165 // Container build configuration.
156166 // +optional
157167 ContainerBuildConfiguration * ContainerBuildConfiguration `json:"containerBuildConfiguration,omitempty"`
168+ // Container run configuration.
169+ // +optional
170+ ContainerRunConfiguration * ContainerRunConfiguration `json:"containerRunConfiguration,omitempty"`
158171 // ServiceAccount to use by the DevWorkspace operator when starting the workspaces.
159172 // +optional
160173 // +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
@@ -559,9 +572,10 @@ type WorkspaceSecurityConfig struct {
559572 // If set, defined values are merged into the default PodSecurityContext configuration.
560573 // +optional
561574 PodSecurityContext * corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
562- // Container SecurityContext used by all workspace-related containers.
563- // If set, defined values are merged into the default Container SecurityContext configuration.
564- // Requires devEnvironments.disableContainerBuildCapabilities to be set to `true` in order to take effect.
575+ // Defines the SecurityContext applied to all workspace-related containers.
576+ // When set, the specified values are merged with the default SecurityContext configuration.
577+ // This setting takes effect only if both `devEnvironments.disableContainerBuildCapabilities`
578+ // and `devEnvironments.disableContainerRunCapabilities` are set to `true`.
565579 // +optional
566580 ContainerSecurityContext * corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
567581}
@@ -873,6 +887,26 @@ type ContainerBuildConfiguration struct {
873887 OpenShiftSecurityContextConstraint string `json:"openShiftSecurityContextConstraint,omitempty"`
874888}
875889
890+ type ContainerRunConfiguration struct {
891+ // Specifies the OpenShift SecurityContextConstraint used to run containers.
892+ // +kubebuilder:validation:Required
893+ // +kubebuilder:default:=container-run
894+ OpenShiftSecurityContextConstraint string `json:"openShiftSecurityContextConstraint,omitempty"`
895+ // Extra annotations applied to all workspace pods, in addition to those defined
896+ // in `devEnvironments.workspacePodAnnotations`. Enables `/dev/fuse` for access to the fuse driver
897+ // and `/dev/net/tun` for safe network access.
898+ // +optional
899+ // +kubebuilder:default:={"io.kubernetes.cri-o.Devices": "/dev/fuse,/dev/net/tun"}
900+ WorkspacesPodAnnotations map [string ]string `json:"workspacesPodAnnotations,omitempty"`
901+ // SecurityContext applied to all workspace containers when run capabilities are enabled.
902+ // The default `procMount: "Unmasked"` is set because the pod runs in a user namespace,
903+ // which safely isolates the container's `/proc` from the host. This allows the container
904+ // to modify its own sysctl settings for configuring networking for nested containers.
905+ // +optional
906+ // +kubebuilder:default:={procMount: "Unmasked", allowPrivilegeEscalation: true, capabilities: {add: {"SETGID", "SETUID"}}}
907+ ContainerSecurityContext * corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
908+ }
909+
876910// Configuration for Traefik within the Che gateway pod.
877911type Traefik struct {
878912 // The log level for the Traefik container within the gateway pod: `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`, or `PANIC`. The default value is `INFO`
@@ -1068,6 +1102,10 @@ func (c *CheCluster) IsAccessTokenConfigured() bool {
10681102 return c .GetIdentityToken () == constants .AccessToken
10691103}
10701104
1105+ func (c * CheCluster ) IsContainerRunCapabilitiesEnabled () bool {
1106+ return ! pointer .BoolDeref (c .Spec .DevEnvironments .DisableContainerRunCapabilities , constants .DefaultDisableContainerRunCapabilities )
1107+ }
1108+
10711109// IsContainerBuildCapabilitiesEnabled returns true if container build capabilities are enabled.
10721110// If value is not set in the CheCluster CR, then the default value is used.
10731111func (c * CheCluster ) IsContainerBuildCapabilitiesEnabled () bool {
@@ -1084,10 +1122,6 @@ func (c *CheCluster) IsContainerBuildCapabilitiesEnabled() bool {
10841122 return ! disableContainerBuildCapabilitiesParsed
10851123}
10861124
1087- func (c * CheCluster ) IsOpenShiftSecurityContextConstraintSet () bool {
1088- return c .Spec .DevEnvironments .ContainerBuildConfiguration != nil && c .Spec .DevEnvironments .ContainerBuildConfiguration .OpenShiftSecurityContextConstraint != ""
1089- }
1090-
10911125func (c * CheCluster ) IsCheFlavor () bool {
10921126 return defaults .GetCheFlavor () == constants .CheFlavor
10931127}
0 commit comments