diff --git a/Cargo.lock b/Cargo.lock index e009b27..2352608 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -564,6 +564,7 @@ dependencies = [ "thiserror", "tokio", "toml", + "users", "uuid", ] @@ -1777,6 +1778,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index a91d93a..8696816 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,5 @@ sqlx = { version = "0.8.3", features = ["postgres", "runtime-tokio"] } thiserror = "2.0.11" tokio = { version = "1.43.0", features = ["full"] } toml = "0.8.19" +users = "0.11.0" uuid = { version = "1.11.0", features = ["v7", "fast-rng"] } diff --git a/gregory.example.toml b/gregory.example.toml index 4c28e68..819639b 100644 --- a/gregory.example.toml +++ b/gregory.example.toml @@ -12,7 +12,8 @@ max-threads = 10 revision = "2" threads = 6 image = "docker.io/library/debian" - commands = ["echo hi", "sleep 2.432", "echo helloooooooooo"] + commands = ["echo hi", "sleep 2.432", "whoami"] + uid = 1000 volumes = ["librewolf"] [packages.librewolf.packaging.fedora] diff --git a/src/data.rs b/src/data.rs index dd1d470..5cbb2a3 100644 --- a/src/data.rs +++ b/src/data.rs @@ -4,6 +4,7 @@ use crate::errors::Error; use serde::Deserialize; use std::time; use std::{collections::HashMap, fs, thread}; +use users::get_current_uid; /// The config for gregory #[derive(Debug, Clone, Deserialize)] @@ -74,6 +75,8 @@ pub(crate) struct Job { pub(crate) privileged: bool, #[serde(default = "shell")] pub(crate) shell: String, + #[serde(default = "uid")] + pub(crate) uid: u64, } /// Holds the data for a certain package's config @@ -171,3 +174,7 @@ pub(crate) fn data() -> String { pub(crate) fn dependencies() -> Vec<String> { return Vec::new(); } + +pub(crate) fn uid() -> u64 { + return get_current_uid() as u64; +} diff --git a/src/main.rs b/src/main.rs index 2fc0eeb..978480f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,6 +180,7 @@ fn run_job(conf: &Config, job_id: String, job: Job) -> JobExitStatus { let mut cmd_args: Vec<String> = vec![ "run".to_string(), "--rm".to_string(), + format!("--user={}", job.uid), format!("--name={job_id}-{run_id}"), format!("--cpus={threads}"), format!("--privileged={}", job.privileged),