Skip to content

Commit 8a7f05b

Browse files
committed
rootless support (maybe?)
1 parent 37b0cf5 commit 8a7f05b

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎src/config.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ nestify::nest! {
209209
#[serde(default)]
210210
pub userns_mode: String,
211211

212+
#[serde(default)]
213+
#[schema(inline)]
214+
pub rootless: #[derive(ToSchema, Deserialize, Serialize, DefaultFromSerde)] pub struct DockerRootless {
215+
#[serde(default)]
216+
pub enabled: bool,
217+
},
218+
212219
#[serde(default)]
213220
#[schema(inline)]
214221
pub log_config: #[derive(ToSchema, Deserialize, Serialize, DefaultFromSerde)] pub struct DockerLogConfig {

‎src/instance/executor/docker/mod.rs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ fn host_config(
129129
),
130130
}),
131131
network_mode: Some("none".to_string()),
132-
userns_mode: string_to_option(&config.docker.userns_mode),
132+
userns_mode: if config.docker.rootless.enabled {
133+
Some(format!(
134+
"keep-id:uid={},gid={}",
135+
data.image_uid, data.image_gid
136+
))
137+
} else {
138+
string_to_option(&config.docker.userns_mode)
139+
},
133140
..Default::default()
134141
}
135142
}
@@ -637,17 +644,23 @@ impl super::ContainerExecutor for DockerExecutor {
637644
let data = database.data.read().await.clone();
638645
let data_dir = self.app_config.data_path(data.uuid);
639646

647+
let rootless = self.app_config.load().docker.rootless.enabled;
648+
640649
self.pull_image(&data.image).await?;
641650
tokio::fs::create_dir_all(data_dir.join("volumes")).await?;
642651
for mapping in &data.volumes {
643652
let host_path = mapping.host_path(&self.app_config, data.uuid);
644653
tokio::fs::create_dir_all(&host_path).await?;
645-
std::os::unix::fs::chown(&host_path, Some(data.image_uid), Some(data.image_gid))?;
654+
if !rootless {
655+
std::os::unix::fs::chown(&host_path, Some(data.image_uid), Some(data.image_gid))?;
656+
}
646657
}
647658

648659
let socket_dir = self.app_config.socket_path(data.uuid);
649660
tokio::fs::create_dir_all(&socket_dir).await?;
650-
std::os::unix::fs::chown(&socket_dir, Some(data.image_uid), Some(data.image_gid))?;
661+
if !rootless {
662+
std::os::unix::fs::chown(&socket_dir, Some(data.image_uid), Some(data.image_gid))?;
663+
}
651664

652665
let config = container_config(&data, &self.app_config, self.host_mounts());
653666

0 commit comments

Comments
 (0)