Skip to content

Commit f4e157d

Browse files
sprtdanmihai1
authored andcommitted
agent: Make /dev/sev-guest available to containers (#36)
This makes it so that any container has access to /dev/sev-guest out of the box with no privileges required. Since /dev/sev-guest isn't available yet, I've validated this change using /dev/cpu_dma_latency (original chmod 600) by: 1. Verifying that the device is present in the container. 2. Verifying that reading from the device from a container yields the same result as from the VM context. Signed-off-by: Aurélien Bombo <[email protected]>
1 parent a3f1f3a commit f4e157d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/agent/rustjail/src/container.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ lazy_static! {
151151
};
152152

153153
pub static ref DEFAULT_DEVICES: Vec<LinuxDevice> = {
154-
vec![
154+
let mut devices = vec![
155155
LinuxDevice {
156156
path: "/dev/null".to_string(),
157157
r#type: "c".to_string(),
@@ -206,7 +206,23 @@ lazy_static! {
206206
uid: Some(0xffffffff),
207207
gid: Some(0xffffffff),
208208
},
209-
]
209+
];
210+
211+
let sev_guest_path = "/dev/sev-guest";
212+
if let Ok(sev_guest_attr) = fs::metadata(sev_guest_path) {
213+
let sev_guest_devid = sev_guest_attr.rdev();
214+
devices.push(LinuxDevice {
215+
path: sev_guest_path.to_string(),
216+
r#type: "c".to_string(),
217+
major: stat::major(sev_guest_devid) as i64,
218+
minor: stat::minor(sev_guest_devid) as i64,
219+
file_mode: Some(0o666),
220+
uid: Some(sev_guest_attr.uid()),
221+
gid: Some(sev_guest_attr.gid()),
222+
});
223+
};
224+
225+
devices
210226
};
211227

212228
pub static ref SYSTEMD_CGROUP_PATH_FORMAT:Regex = Regex::new(r"^[\w\-.]*:[\w\-.]*:[\w\-.]*$").unwrap();

0 commit comments

Comments
 (0)