add uid support

This commit is contained in:
askiiart 2025-02-11 11:24:08 -06:00
parent 522d12929b
commit aa037e9453
Signed by untrusted user who does not match committer: askiiart
GPG key ID: 6A32977DAF31746A
5 changed files with 22 additions and 1 deletions

11
Cargo.lock generated
View file

@ -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"

View file

@ -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"] }

View file

@ -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]

View file

@ -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;
}

View file

@ -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),