Skip to content

Commit 760fea1

Browse files
authored
chore: run BackupRepo precheck job with non-root user (#9713)
1 parent a361045 commit 760fea1

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

controllers/dataprotection/backuprepo_controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ func (r *BackupRepoReconciler) runPreCheckJobForMounting(reconCtx *reconcileCont
759759
job.Name = reconCtx.preCheckResourceName()
760760
job.Namespace = namespace
761761
_, err = createObjectIfNotExist(reconCtx.Ctx, r.Client, job, func() error {
762-
runAsUser := int64(0)
763762
job.Spec = batchv1.JobSpec{
764763
Template: corev1.PodTemplateSpec{
765764
Spec: corev1.PodSpec{
@@ -777,7 +776,7 @@ func (r *BackupRepoReconciler) runPreCheckJobForMounting(reconCtx *reconcileCont
777776
}},
778777
SecurityContext: &corev1.SecurityContext{
779778
AllowPrivilegeEscalation: boolptr.False(),
780-
RunAsUser: &runAsUser,
779+
RunAsNonRoot: boolptr.True(),
781780
},
782781
}},
783782
Volumes: []corev1.Volume{{
@@ -838,7 +837,6 @@ func (r *BackupRepoReconciler) runPreCheckJobForTool(reconCtx *reconcileContext,
838837
job.Name = reconCtx.preCheckResourceName()
839838
job.Namespace = namespace
840839
_, err = createObjectIfNotExist(reconCtx.Ctx, r.Client, job, func() error {
841-
runAsUser := int64(0)
842840
job.Spec = batchv1.JobSpec{
843841
Template: corev1.PodTemplateSpec{
844842
Spec: corev1.PodSpec{
@@ -858,7 +856,7 @@ datasafed rm %s`, precheckFilePath, precheckFilePath, precheckFilePath),
858856
},
859857
SecurityContext: &corev1.SecurityContext{
860858
AllowPrivilegeEscalation: boolptr.False(),
861-
RunAsUser: &runAsUser,
859+
RunAsNonRoot: boolptr.True(),
862860
},
863861
}},
864862
ServiceAccountName: saName,

pkg/dataprotection/utils/backuprepo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/apecloud/kubeblocks/pkg/constant"
2929
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
3030
dptypes "github.com/apecloud/kubeblocks/pkg/dataprotection/types"
31+
"github.com/apecloud/kubeblocks/pkg/dataprotection/utils/boolptr"
3132
viper "github.com/apecloud/kubeblocks/pkg/viperx"
3233
)
3334

@@ -152,6 +153,10 @@ func injectDatasafedInstaller(podSpec *corev1.PodSpec) {
152153
ImagePullPolicy: corev1.PullPolicy(viper.GetString(constant.KBImagePullPolicy)),
153154
Command: []string{"/bin/sh", "-c", fmt.Sprintf("/scripts/install-datasafed.sh %s", datasafedBinMountPath)},
154155
VolumeMounts: []corev1.VolumeMount{sharedVolumeMount},
156+
SecurityContext: &corev1.SecurityContext{
157+
AllowPrivilegeEscalation: boolptr.False(),
158+
RunAsNonRoot: boolptr.True(),
159+
},
155160
}
156161
intctrlutil.InjectZeroResourcesLimitsIfEmpty(&initContainer)
157162
podSpec.InitContainers = append(podSpec.InitContainers, initContainer)

0 commit comments

Comments
 (0)