Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rooz"
version = "0.154.3"
version = "0.155.0"
edition = "2024"

[dependencies]
Expand Down
7 changes: 7 additions & 0 deletions src/api/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ echo '[install] {}: {}'
Ok(())
}

pub async fn default_uid(&self, container_id: &str) -> Result<i32, AnyError> {
let output = self
.output("default-uid", container_id, None, Some(vec!["id", "-u"]))
.await?;
Ok(output.trim().parse::<i32>()?)
}

pub async fn ensure_user(&self, container_id: &str) -> Result<(), AnyError> {
let ensure_user_cmd = inject(
format!(
Expand Down
42 changes: 23 additions & 19 deletions src/api/workspace/enter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl<'a> WorkspaceApi<'a> {
shell: Option<Vec<&str>>,
container_name: Option<&str>,
root: bool,
chown: bool,
) -> Result<String, AnyError> {
let container_name = container_name.unwrap_or(constants::DEFAULT_CONTAINER_NAME);
let enter_labels = Labels::from(&[
Expand Down Expand Up @@ -101,25 +102,28 @@ impl<'a> WorkspaceApi<'a> {
self.api.exec.ensure_user(container_id).await?;
}

let real_mounts = if is_work_container {
&config.real_mounts
} else {
&config.sidecars[container_name].real_mounts
};

let chown_uid = if is_work_container {
&config.uid
} else {
&config.sidecars[container_name]
.uid
.unwrap_or_else(|| panic!("TODO: read default uid from the image"))
};

for (target, _) in real_mounts {
self.api
.exec
.chown(&container_id, chown_uid, target.as_str())
.await?;
if chown {
let real_mounts = if is_work_container {
&config.real_mounts
} else {
&config.sidecars[container_name].real_mounts
};

let chown_uid = if is_work_container {
config.uid
} else {
match config.sidecars[container_name].uid {
Some(uid) => uid,
None => self.api.exec.default_uid(container_id).await?,
}
};

for (target, _) in real_mounts {
self.api
.exec
.chown(&container_id, &chown_uid, target.as_str())
.await?;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ pub struct EnterParams {
pub work_dir: Option<String>,
#[arg(short, long)]
pub container: Option<String>,
#[arg(
long,
help = "Chowns the container's volume mounts to the user the container runs as"
)]
pub chown: bool,
}

#[derive(Parser, Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/cmd/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ impl<'a> WorkspaceApi<'a> {
Some(cfg.shell.iter().map(|v| v.as_str()).collect::<Vec<_>>()),
None,
root,
false,
)
.await?;

Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ async fn main() -> Result<(), AnyError> {
root,
work_dir,
container,
chown,
}),
..
} => {
Expand All @@ -176,6 +177,7 @@ async fn main() -> Result<(), AnyError> {
shell.as_deref().map(|v| vec![v.as_ref()]),
container.as_deref(),
root,
chown,
)
.await?;
}
Expand Down