Skip to content

Commit b54f2e3

Browse files
committed
Update securityContexts for pods
* Device-plugin does not need to mount /dev anymore. * Set USER in Dockerfile.rtl-sdr * Set securityContext for spawned rtl-sdr pod with: - runAsNonRoot: true - readOnlyRootFilesystem: true - runAsUser: 65532 Signed-off-by: Fredrik Lönnegren <[email protected]>
1 parent b438e57 commit b54f2e3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Dockerfile.rtl-sdr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ RUN mkdir /sysroot && \
55
zypper --non-interactive --installroot /sysroot install -y rtl-sdr
66

77
FROM scratch AS final
8+
USER 65532:65532
89
COPY --from=build /sysroot /

config/device-plugin/device-plugin.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,9 @@ spec:
3737
volumeMounts:
3838
- name: dp
3939
mountPath: /var/lib/kubelet/device-plugins
40-
- name: dev
41-
mountPath: /dev
4240
serviceAccountName: device-plugin
4341
terminationGracePeriodSeconds: 10
4442
volumes:
4543
- name: dp
4644
hostPath:
4745
path: /var/lib/kubelet/device-plugins
48-
- name: dev
49-
hostPath:
50-
path: /dev

internal/controller/rtlsdrreceiver_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ func (r *RtlSdrReceiverReconciler) createPod(ctx context.Context, receiver *radi
127127

128128
args = append(args, "-p", strconv.Itoa(listenPort))
129129

130+
t := true
131+
userID := int64(65532)
132+
130133
pod.Name = receiver.Name
131134
pod.Namespace = receiver.Namespace
132135
pod.Spec = corev1.PodSpec{
@@ -142,6 +145,11 @@ func (r *RtlSdrReceiverReconciler) createPod(ctx context.Context, receiver *radi
142145
RtlSdrResourceName: *resource.NewQuantity(1, resource.DecimalSI),
143146
},
144147
},
148+
SecurityContext: &corev1.SecurityContext{
149+
RunAsNonRoot: &t,
150+
ReadOnlyRootFilesystem: &t,
151+
RunAsUser: &userID,
152+
},
145153
},
146154
},
147155
}

0 commit comments

Comments
 (0)