@@ -21,6 +21,7 @@ import (
2121 corev1 "k8s.io/api/core/v1"
2222 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323 "k8s.io/apimachinery/pkg/util/intstr"
24+ "k8s.io/apimachinery/pkg/version"
2425 "k8s.io/utils/pointer"
2526
2627 wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
@@ -62,6 +63,7 @@ type startWorkspaceContext struct {
6263 IDEPort int32 `json:"idePort"`
6364 SupervisorPort int32 `json:"supervisorPort"`
6465 Headless bool `json:"headless"`
66+ ServerVersion * version.Info `json:"serverVersion"`
6567}
6668
6769// createWorkspacePod creates the actual workspace pod based on the definite workspace pod and appropriate
@@ -278,12 +280,13 @@ func createDefiniteWorkspacePod(sctx *startWorkspaceContext) (*corev1.Pod, error
278280 "prometheus.io/scrape" : "true" ,
279281 "prometheus.io/path" : "/metrics" ,
280282 "prometheus.io/port" : strconv .Itoa (int (sctx .IDEPort )),
281- "container.apparmor.security.beta.kubernetes.io/workspace" : "unconfined" ,
282283 // prevent cluster-autoscaler from removing a node
283284 // https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#what-types-of-pods-can-prevent-ca-from-removing-a-node
284285 "cluster-autoscaler.kubernetes.io/safe-to-evict" : "false" ,
285286 }
286287
288+ configureAppamor (sctx , annotations , workspaceContainer )
289+
287290 for k , v := range sctx .Workspace .Annotations {
288291 annotations [k ] = v
289292 }
@@ -689,7 +692,7 @@ func createDefaultSecurityContext() (*corev1.SecurityContext, error) {
689692 return res , nil
690693}
691694
692- func newStartWorkspaceContext (ctx context.Context , cfg * config.Configuration , ws * workspacev1.Workspace ) (res * startWorkspaceContext , err error ) {
695+ func newStartWorkspaceContext (ctx context.Context , cfg * config.Configuration , ws * workspacev1.Workspace , serverVersion * version. Info ) (res * startWorkspaceContext , err error ) {
693696 // we deliberately do not shadow ctx here as we need the original context later to extract the TraceID
694697 span , _ := tracing .FromContext (ctx , "newStartWorkspaceContext" )
695698 defer tracing .FinishSpan (span , & err )
@@ -711,9 +714,25 @@ func newStartWorkspaceContext(ctx context.Context, cfg *config.Configuration, ws
711714 IDEPort : 23000 ,
712715 SupervisorPort : 22999 ,
713716 Headless : ws .IsHeadless (),
717+ ServerVersion : serverVersion ,
714718 }, nil
715719}
716720
721+ func configureAppamor (sctx * startWorkspaceContext , annotations map [string ]string , workspaceContainer * corev1.Container ) {
722+ // pre K8s 1.30 we need to set the apparmor profile to unconfined as an annotation
723+ if sctx .ServerVersion .Major <= "1" && sctx .ServerVersion .Minor <= "30" {
724+ annotations ["container.apparmor.security.beta.kubernetes.io/workspace" ] = "unconfined"
725+ } else {
726+
727+ // TODO: set AppArmorProfile field here, if the K8s minor version is >= 30
728+ // Ref: https://pkg.go.dev/k8s.io/[email protected] /core/v1#SecurityContext 729+ // and https://pkg.go.dev/k8s.io/[email protected] /core/v1#AppArmorProfile 730+ // and https://pkg.go.dev/k8s.io/[email protected] /core/v1#AppArmorProfileType 731+ //
732+ // requires we update k8s libraries to 0.30.8
733+ }
734+ }
735+
717736// validCookieChars contains all characters which may occur in an HTTP Cookie value (unicode \u0021 through \u007E),
718737// without the characters , ; and / ... I did not find more details about permissible characters in RFC2965, so I took
719738// this list of permissible chars from Wikipedia.
0 commit comments