Skip to content

Commit e38525e

Browse files
committed
Remove systemd's device filter configuration if any
We remove systemd's filter but it might be added back by systemd if we don't get rid of these config completely.
1 parent 7059bf7 commit e38525e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/runc/container.rs

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ impl Container {
8585
}
8686
});
8787

88+
// runc configures systemd to also perform device filtering.
89+
// The removal of systemd's filtering is insufficient since after daemon-reload (or maybe
90+
// some other triggers as well), systemd will reconcile and add it back, which disrupts
91+
// container-hotplug's operation.
92+
// So we'll also go ahead and remove these configuration files. Ignore errors if any since
93+
// the cgroup might be handled by runc directly if `--cgroup-manager=cgroupfs` is used.
94+
let cgroup_name = state
95+
.cgroup_paths
96+
.unified
97+
.file_name()
98+
.context("cgroup doesn't have file name")?
99+
.to_str()
100+
.context("cgroup name is not UTF-8")?;
101+
let _ = std::fs::remove_file(format!("/run/systemd/transient/{cgroup_name}.d/50-DeviceAllow.conf"));
102+
let _ = std::fs::remove_file(format!("/run/systemd/transient/{cgroup_name}.d/50-DevicePolicy.conf"));
103+
88104
let cgroup_device_filter: Box<dyn DeviceAccessController + Send> =
89105
if let Some(device_cgroup) = &state.cgroup_paths.devices {
90106
Box::new(DeviceAccessControllerV1::new(device_cgroup)?)

0 commit comments

Comments
 (0)