Skip to content

Commit

Permalink
virtme-ng-init: hide additional sudo settings
Browse files Browse the repository at this point in the history
Try to keep sudo settings as simple as possible and rely only on our
custom /etc/sudoers.

This can help to prevent potential permissions errors while using sudo
inside a virtme-ng guest.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
  • Loading branch information
Andrea Righi committed Feb 22, 2024
1 parent 49615ab commit a0d6fee
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ const SYSTEM_MOUNTS: &[MountInfo] = &[
flags: (libc::MS_NOSUID | libc::MS_NODEV) as usize,
fsdata: "",
},
MountInfo {
source: "tmpfs",
target: "/var/lib/sudo",
fs_type: "tmpfs",
flags: (libc::MS_NOSUID | libc::MS_NODEV) as usize,
fsdata: "",
},
MountInfo {
source: "tmpfs",
target: "/var/lib/apt",
Expand Down Expand Up @@ -329,6 +336,9 @@ fn generate_sudoers() -> io::Result<()> {
if let Ok(user) = env::var("virtme_user") {
content += &format!("{} ALL = (ALL) NOPASSWD: ALL\n", user);
}
if !Path::new("/etc/sudoers").exists() {
utils::create_file("/etc/sudoers", 0o0440, "").unwrap_or_else(|_| {});
}
utils::create_file(fname, 0o0440, &content).ok();
utils::do_mount(fname, "/etc/sudoers", "", libc::MS_BIND as usize, "");
Ok(())
Expand Down

0 comments on commit a0d6fee

Please sign in to comment.