Skip to content

Commit

Permalink
[CWS] Fix CWS instrumentation user (#23629)
Browse files Browse the repository at this point in the history
* [CWS] fix CWS instrumentation user

* [CWS] fix CWS instrumentation tests
  • Loading branch information
Gui774ume authored Mar 11, 2024
1 parent ac8dfc6 commit dfa32f3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfiles/cws-instrumentation/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM scratch
ARG TARGETARCH
COPY --chmod=0755 cws-instrumentation.$TARGETARCH /cws-instrumentation
USER 10000
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
cwsInstrumentationPodAnotationReady = "ready"
cwsInjectorInitContainerName = "cws-instrumentation"
cwsUserSessionDataMaxSize = 1024
cwsInjectorInitContainerUser = int64(10000)
cwsInjectorInitContainerGroup = int64(10000)

// PodLabelEnabled is used to label pods that should be instrumented or skipped by the CWS mutating webhook
PodLabelEnabled = "admission.datadoghq.com/cws-instrumentation.enabled"
Expand Down Expand Up @@ -449,6 +451,9 @@ func injectCWSInitContainer(pod *corev1.Pod, resources *corev1.ResourceRequireme
}
}

runAsUser := cwsInjectorInitContainerUser
runAsGroup := cwsInjectorInitContainerGroup

initContainer := corev1.Container{
Name: cwsInjectorInitContainerName,
Image: image,
Expand All @@ -459,6 +464,11 @@ func injectCWSInitContainer(pod *corev1.Pod, resources *corev1.ResourceRequireme
MountPath: cwsMountPath,
},
},
// Set a default user and group to support pod deployments with a `runAsNonRoot` security context
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
}
if resources != nil {
initContainer.Resources = *resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ func Test_injectCWSCommandInstrumentation(t *testing.T) {

func Test_injectCWSPodInstrumentation(t *testing.T) {
commonRegistry := "gcr.io/datadoghq"
runAsUser := cwsInjectorInitContainerUser
runAsGroup := cwsInjectorInitContainerGroup

type args struct {
pod *corev1.Pod
Expand Down Expand Up @@ -499,6 +501,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand All @@ -522,6 +528,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand All @@ -545,6 +555,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand Down Expand Up @@ -579,6 +593,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand Down Expand Up @@ -639,6 +657,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand Down Expand Up @@ -679,6 +701,10 @@ func Test_injectCWSPodInstrumentation(t *testing.T) {
MountPath: cwsMountPath,
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},
},
wantInstrumentation: true,
},
Expand Down

0 comments on commit dfa32f3

Please sign in to comment.