Skip to content

Commit 54961c3

Browse files
committed
idxd: Make root filesystem read-only
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
1 parent b5009ed commit 54961c3

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

build/docker/intel-idxd-config-initcontainer.Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 Intel Corporation. All Rights Reserved.
1+
# Copyright 2021-2022 Intel Corporation. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -57,8 +57,11 @@ RUN ldconfig && mkdir -p /licenses/accel-config
5757
COPY --from=builder /usr/bin/accel-config /usr/bin/
5858
COPY --from=builder /accel-config.tar.gz /licenses/accel-config/
5959

60-
ADD demo/idxd-init.sh /idxd-init/
60+
ADD demo/idxd-init.sh /usr/local/bin/
6161
ADD demo/dsa.conf /idxd-init/
62+
ADD demo/iaa.conf /idxd-init/
63+
64+
RUN mkdir /idxd-init/scratch
6265

6366
WORKDIR /idxd-init
64-
ENTRYPOINT bash idxd-init.sh
67+
ENTRYPOINT bash /usr/local/bin/idxd-init.sh

demo/idxd-init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ for i in $(accel-config list --idle | jq '.[].dev' | sed -ne "s/\"$DEV\([0-9]\+\
2828

2929
[ -f "conf/$DEV-$NODE_NAME.conf" ] && config="conf/$DEV-$NODE_NAME.conf"
3030

31-
sed "s/X/${i}/g" < "$config" > "$dev.conf"
31+
sed "s/X/${i}/g" < "$config" > scratch/"$dev.conf"
3232

33-
cmd accel-config load-config -e -c "$dev.conf"
33+
cmd accel-config load-config -e -c scratch/"$dev.conf"
3434

3535
done

deployments/dsa_plugin/overlays/dsa_initcontainer/dsa_initcontainer.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ spec:
1414
fieldPath: spec.nodeName
1515
image: intel/intel-idxd-config-initcontainer:devel
1616
securityContext:
17+
readOnlyRootFilesystem: true
1718
privileged: true
1819
volumeMounts:
1920
- mountPath: /sys/devices
2021
name: sys-devices
2122
- mountPath: /idxd-init/conf
2223
name: intel-dsa-config-volume
24+
- mountPath: /idxd-init/scratch
25+
name: scratch
2326
volumes:
2427
- name: sys-devices
2528
hostPath:
2629
path: /sys/devices
2730
- name: intel-dsa-config-volume
2831
configMap:
2932
name: intel-dsa-config
33+
- name: scratch
34+
emptyDir: {}

deployments/iaa_plugin/overlays/iaa_initcontainer/iaa_initcontainer.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ spec:
1616
value: "iaa"
1717
image: intel/intel-idxd-config-initcontainer:devel
1818
securityContext:
19+
readOnlyRootFilesystem: true
1920
privileged: true
2021
volumeMounts:
2122
- mountPath: /sys/devices
2223
name: sys-devices
2324
- mountPath: /idxd-init/conf
2425
name: intel-iaa-config-volume
26+
- mountPath: /idxd-init/scratch
27+
name: scratch
2528
volumes:
2629
- name: sys-devices
2730
hostPath:
2831
path: /sys/devices
2932
- name: intel-iaa-config-volume
3033
configMap:
3134
name: intel-iaa-config
35+
- name: scratch
36+
emptyDir: {}

pkg/controllers/dsa/controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func removeInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.DsaDevicePlugin)
9898
newVolumes := []v1.Volume{}
9999

100100
for _, volume := range ds.Spec.Template.Spec.Volumes {
101-
if volume.Name == "intel-dsa-config-volume" || volume.Name == "sys-devices" {
101+
if volume.Name == "intel-dsa-config-volume" || volume.Name == "sys-devices" || volume.Name == "scratch" {
102102
continue
103103
}
104104

@@ -130,13 +130,18 @@ func addInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.DsaDevicePlugin) {
130130
},
131131
},
132132
SecurityContext: &v1.SecurityContext{
133-
Privileged: &yes,
133+
ReadOnlyRootFilesystem: &yes,
134+
Privileged: &yes,
134135
},
135136
VolumeMounts: []v1.VolumeMount{
136137
{
137138
Name: "sys-devices",
138139
MountPath: "/sys/devices",
139140
},
141+
{
142+
Name: "scratch",
143+
MountPath: "/idxd-init/scratch",
144+
},
140145
},
141146
})
142147
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{
@@ -147,6 +152,12 @@ func addInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.DsaDevicePlugin) {
147152
},
148153
},
149154
})
155+
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{
156+
Name: "scratch",
157+
VolumeSource: v1.VolumeSource{
158+
EmptyDir: &v1.EmptyDirVolumeSource{},
159+
},
160+
})
150161

151162
if dp.Spec.ProvisioningConfig != "" {
152163
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{

pkg/controllers/iaa/controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func removeInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.IaaDevicePlugin)
9696
newVolumes := []v1.Volume{}
9797

9898
for _, volume := range ds.Spec.Template.Spec.Volumes {
99-
if volume.Name == "intel-iaa-config-volume" || volume.Name == "sys-devices" {
99+
if volume.Name == "intel-iaa-config-volume" || volume.Name == "sys-devices" || volume.Name == "scratch" {
100100
continue
101101
}
102102

@@ -128,13 +128,18 @@ func addInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.IaaDevicePlugin) {
128128
},
129129
},
130130
SecurityContext: &v1.SecurityContext{
131-
Privileged: &yes,
131+
ReadOnlyRootFilesystem: &yes,
132+
Privileged: &yes,
132133
},
133134
VolumeMounts: []v1.VolumeMount{
134135
{
135136
Name: "sys-devices",
136137
MountPath: "/sys/devices",
137138
},
139+
{
140+
Name: "scratch",
141+
MountPath: "/idxd-init/scratch",
142+
},
138143
},
139144
})
140145
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{
@@ -145,6 +150,12 @@ func addInitContainer(ds *apps.DaemonSet, dp *devicepluginv1.IaaDevicePlugin) {
145150
},
146151
},
147152
})
153+
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{
154+
Name: "scratch",
155+
VolumeSource: v1.VolumeSource{
156+
EmptyDir: &v1.EmptyDirVolumeSource{},
157+
},
158+
})
148159

149160
if dp.Spec.ProvisioningConfig != "" {
150161
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, v1.Volume{

0 commit comments

Comments
 (0)