Skip to content

Commit

Permalink
Add SecurityContext to job container
Browse files Browse the repository at this point in the history
Signed-off-by: raul <[email protected]>
  • Loading branch information
raulcabello committed Oct 17, 2023
1 parent 5f3ad58 commit dad4c59
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions internal/cmd/controller/controllers/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ func (h *handler) OnChange(gitrepo *fleet.GitRepo, status fleet.GitRepoStatus) (
WorkingDir: "/workspace/source",
VolumeMounts: volumeMounts,
Env: envs,
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: &[]bool{false}[0],
ReadOnlyRootFilesystem: &[]bool{true}[0],
Privileged: &[]bool{false}[0],
RunAsNonRoot: &[]bool{true}[0],
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}},
},
},
},
NodeSelector: map[string]string{"kubernetes.io/os": "linux"},
Expand Down Expand Up @@ -600,9 +610,15 @@ func volumes(
gitrepo *fleet.GitRepo,
configMap *corev1.ConfigMap,
) ([]corev1.Volume, []corev1.VolumeMount) {
const (
emptyDirTmpVolumeName = "fleet-tmp-empty-dir"
emptyDirHomeVolumeName = "fleet-home-empty-dir"
configVolumeName = "config"
)

volumes := []corev1.Volume{
{
Name: "config",
Name: configVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Expand All @@ -611,13 +627,33 @@ func volumes(
},
},
},
{
Name: emptyDirTmpVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
{
Name: emptyDirHomeVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
}

volumeMounts := []corev1.VolumeMount{
{
Name: "config",
Name: configVolumeName,
MountPath: "/run/config",
},
{
Name: emptyDirTmpVolumeName,
MountPath: "/tmp",
},
{
Name: emptyDirHomeVolumeName,
MountPath: "/home/fleet-apply",
},
}

if gitrepo.Spec.HelmSecretNameForPaths != "" {
Expand Down

0 comments on commit dad4c59

Please sign in to comment.