Skip to content

Commit 21f2559

Browse files
authored
Merge pull request #78 from edera-dev/feature/subroot-jails
feature(subroot-jails): add a few features enabling easy use of subroot jails
2 parents 01e6443 + 12fecc3 commit 21f2559

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

bin/styrojail.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ struct Cli {
3434
#[arg(long)]
3535
no_default_mounts: bool,
3636

37+
/// Path to rootfs (default: /)
38+
#[arg(long, default_value = "/")]
39+
rootfs: String,
40+
41+
/// Whether the rootfs should be readonly (default: true)
42+
#[arg(long)]
43+
no_rootfs_readonly: bool,
44+
3745
/// Additional bind-mounts for the jail
3846
#[arg(long, value_name = "HOSTPATH:JAILPATH", value_parser = parse_mount)]
3947
mount: Vec<CliMountSpec>,
@@ -148,16 +156,15 @@ fn to_styrolite_mount(m: &CliMountSpec) -> StyroMountSpec {
148156
fn main() -> Result<()> {
149157
let (uid, gid) = current_ids();
150158

151-
let cli = Cli::parse();
159+
let mut cli = Cli::parse();
152160
let mut builder = CreateRequestBuilder::new()
153-
.set_rootfs("/")
154-
.set_rootfs_readonly(true)
161+
.set_rootfs(&cli.rootfs)
162+
.set_rootfs_readonly(!cli.no_rootfs_readonly)
155163
.set_skip_two_stage_userns(true)
156164
.set_executable(&cli.program)
157165
.set_uid(uid)
158166
.set_gid(gid)
159167
.set_setgroups_deny(true)
160-
.set_working_directory(std::env::current_dir()?.as_os_str().to_str().unwrap_or("/"))
161168
.set_workload_id(format!("styrojail-{}", std::process::id()).as_str())
162169
.push_uid_mapping(IdMapping {
163170
base_nsid: uid,
@@ -176,6 +183,13 @@ fn main() -> Result<()> {
176183
.push_namespace(Namespace::Ipc)
177184
.push_namespace(Namespace::Mount);
178185

186+
if cli.rootfs == "/" {
187+
builder = builder
188+
.set_working_directory(std::env::current_dir()?.as_os_str().to_str().unwrap_or("/"))
189+
} else {
190+
cli.no_default_mounts = true;
191+
}
192+
179193
let args_ref: Vec<&str> = cli.args.iter().map(|s| s.as_str()).collect();
180194
builder = builder.set_arguments(args_ref);
181195

0 commit comments

Comments
 (0)