Skip to content

Commit

Permalink
feat: restricted security context
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone committed Jan 6, 2023
1 parent 171ee6d commit 46c16c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
33 changes: 27 additions & 6 deletions controllers/resources/bentorequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -1170,6 +1171,17 @@ echo "Done"
})
}

restrictedSecurityContext := &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.BoolPtr(false),
RunAsNonRoot: pointer.BoolPtr(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
}

initContainers := []corev1.Container{
{
Name: "bento-downloader",
Expand All @@ -1179,9 +1191,10 @@ echo "Done"
"-c",
bentoDownloadCommand,
},
VolumeMounts: volumeMounts,
Resources: downloaderContainerResources,
EnvFrom: downloaderContainerEnvFrom,
VolumeMounts: volumeMounts,
Resources: downloaderContainerResources,
EnvFrom: downloaderContainerEnvFrom,
SecurityContext: restrictedSecurityContext,
},
}

Expand Down Expand Up @@ -1294,9 +1307,10 @@ echo "Done"
"-c",
modelDownloadCommand,
},
VolumeMounts: volumeMounts,
Resources: downloaderContainerResources,
EnvFrom: downloaderContainerEnvFrom,
VolumeMounts: volumeMounts,
Resources: downloaderContainerResources,
EnvFrom: downloaderContainerEnvFrom,
SecurityContext: restrictedSecurityContext,
})
}

Expand Down Expand Up @@ -1498,6 +1512,7 @@ echo "Done"
Env: envs,
TTY: true,
Stdin: true,
SecurityContext: restrictedSecurityContext,
}

if opt.BentoRequest.Spec.ImageBuilderContainerResources != nil {
Expand All @@ -1517,6 +1532,12 @@ echo "Done"
Containers: []corev1.Container{
container,
},
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: pointer.BoolPtr(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
},
},
}

Expand Down
20 changes: 10 additions & 10 deletions helm/yatai-image-builder/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ serviceAccount:

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
podSecurityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault

securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL

service:
type: ClusterIP
Expand Down

0 comments on commit 46c16c9

Please sign in to comment.