Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Change Operator and Builder Pod user as non root 1000 #4407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN tar -xC ${MVNW_DIR} -f ${MVNW_DIR}mvnw.tar \
# Used by mvnw to download maven dist into it
ENV MAVEN_USER_HOME="${MAVEN_HOME}"
# Install a default mvnw distribution at build time and prepare the config for formatting log
RUN ${MVNW_DIR}/mvnw --version | grep "Maven home:" | sed 's/Maven home: //' >> ${MVNW_DIR}default \
RUN ${MVNW_DIR}mvnw --version | grep "Maven home:" | sed 's/Maven home: //' >> ${MVNW_DIR}default \
&& cp -r /usr/share/maven/lib/. $(cat ${MVNW_DIR}default)/lib \
&& rm $(cat ${MVNW_DIR}default)/lib/maven-slf4j-provider*
ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=${MAVEN_HOME}/conf/logback.xml"
Expand All @@ -44,8 +44,10 @@ ADD build/_maven_output /tmp/local/m2
ADD build/_kamelets /kamelets

RUN mkdir -p /etc/maven/m2 \
&& chgrp -R 0 /etc/maven/m2 \
&& chgrp -R 1000 /etc/maven/m2 \
&& chmod -R g=u /etc/maven/m2 \
&& chgrp -R 1000 /tmp/local/m2 \
&& chmod -R g=u /tmp/local/m2 \
&& chgrp -R 0 /kamelets \
&& chmod -R g=u /kamelets \
&& chgrp -R 0 ${MAVEN_HOME} \
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/build/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var (

func newBuildPod(ctx context.Context, c ctrl.Reader, build *v1.Build) (*corev1.Pod, error) {
var ugfid int64 = 1000
var nonRoot bool = true
pod := &corev1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.String(),
Expand All @@ -131,9 +132,10 @@ func newBuildPod(ctx context.Context, c ctrl.Reader, build *v1.Build) (*corev1.P
ServiceAccountName: platform.BuilderServiceAccount,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &ugfid,
RunAsGroup: &ugfid,
FSGroup: &ugfid,
RunAsUser: &ugfid,
RunAsGroup: &ugfid,
FSGroup: &ugfid,
RunAsNonRoot: &nonRoot,
},
},
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client,
d.Spec.Template.Spec.Containers[0].Args = append(d.Spec.Template.Spec.Containers[0].Args,
fmt.Sprintf("--health-port=%d", cfg.Health.Port))
d.Spec.Template.Spec.Containers[0].LivenessProbe.HTTPGet.Port = intstr.FromInt(int(cfg.Health.Port))
var ugfid int64 = 1000
var nonRoot bool = true
d.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{
FSGroup: &ugfid,
RunAsGroup: &ugfid,
RunAsUser: &ugfid,
RunAsNonRoot: &nonRoot,
}
}
}

Expand Down