Skip to content

Commit 3330cb7

Browse files
bors[bot]MikailBag
andauthored
Merge #52
52: Update shared items config r=MikailBag a=MikailBag - Make naming more consistent - Add a name parameter (it can be later used in a backend-specific configuration) Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
2 parents bd70b82 + 36c9ae8 commit 3330cb7

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

minion-cli/src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn parse_env_item(src: &str) -> Result<EnvItem, &'static str> {
1616
})
1717
}
1818

19-
fn parse_path_exposition_item(src: &str) -> Result<minion::SharedDir, String> {
19+
fn parse_path_exposition_item(src: &str) -> Result<minion::SharedItem, String> {
2020
let parts = src.splitn(3, ':').collect::<Vec<_>>();
2121
if parts.len() != 3 {
2222
return Err(format!(
@@ -32,16 +32,17 @@ fn parse_path_exposition_item(src: &str) -> Result<minion::SharedDir, String> {
3232
));
3333
}
3434
let kind = match amask {
35-
"rwx" => minion::SharedDirKind::Full,
36-
"r-x" => minion::SharedDirKind::Readonly,
35+
"rwx" => minion::SharedItemKind::Full,
36+
"r-x" => minion::SharedItemKind::Readonly,
3737
_ => {
3838
return Err(format!(
3939
"unknown access mask {}. rwx or r-x expected",
4040
amask
4141
));
4242
}
4343
};
44-
Ok(minion::SharedDir {
44+
Ok(minion::SharedItem {
45+
id: None,
4546
src: parts[0].to_string().into(),
4647
dest: parts[2].to_string().into(),
4748
kind,
@@ -96,7 +97,7 @@ struct ExecOpt {
9697
long = "expose",
9798
parse(try_from_str = parse_path_exposition_item)
9899
)]
99-
exposed_paths: Vec<minion::SharedDir>,
100+
exposed_paths: Vec<minion::SharedItem>,
100101

101102
/// Process working dir, relative to `isolation_root`
102103
#[structopt(short = "p", long = "pwd", default_value = "/")]
@@ -133,7 +134,7 @@ async fn main() {
133134
max_alive_process_count: options.num_processes.min(u32::max_value() as usize) as u32,
134135
memory_limit: options.memory_limit as u64,
135136
isolation_root: options.isolation_root.into(),
136-
exposed_paths: options.exposed_paths,
137+
shared_items: options.exposed_paths,
137138
cpu_time_limit: Duration::from_millis(u64::from(options.time_limit)),
138139
real_time_limit: Duration::from_millis(u64::from(options.time_limit * 3)),
139140
})

minion-ffi/src/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub struct SandboxOptions {
102102
pub process_limit: u32,
103103
pub memory_limit: u32,
104104
pub isolation_root: *const c_char,
105-
pub shared_directories: *const SharedDirectoryAccess,
105+
pub shared_items: *const SharedItem,
106106
}
107107

108108
#[derive(Clone)]
@@ -161,19 +161,20 @@ pub unsafe extern "C" fn minion_sandbox_create(
161161
options: SandboxOptions,
162162
out: &mut *mut Sandbox,
163163
) -> ErrorCode {
164-
let mut exposed_paths = Vec::new();
164+
let mut shared_items = Vec::new();
165165
unsafe {
166-
let mut p = options.shared_directories;
166+
let mut p = options.shared_items;
167167
while !(*p).host_path.is_null() {
168-
let opt = minion::SharedDir {
168+
let opt = minion::SharedItem {
169+
id: None,
169170
src: get_string((*p).host_path).into(),
170171
dest: get_string((*p).sandbox_path).into(),
171172
kind: match (*p).kind {
172-
SharedDirectoryAccessKind::Full => minion::SharedDirKind::Full,
173-
SharedDirectoryAccessKind::Readonly => minion::SharedDirKind::Readonly,
173+
SharedItemAccessKind::Full => minion::SharedItemKind::Full,
174+
SharedItemAccessKind::Readonly => minion::SharedItemKind::Readonly,
174175
},
175176
};
176-
exposed_paths.push(opt);
177+
shared_items.push(opt);
177178
p = p.offset(1);
178179
}
179180
}
@@ -190,7 +191,7 @@ pub unsafe extern "C" fn minion_sandbox_create(
190191
options.real_time_limit.nanoseconds,
191192
),
192193
isolation_root,
193-
exposed_paths,
194+
shared_items,
194195
};
195196
let d = backend.0.new_sandbox(opts);
196197
let d = d.unwrap();
@@ -250,24 +251,24 @@ pub struct ChildProcessOptions {
250251
}
251252

252253
#[repr(C)]
253-
pub enum SharedDirectoryAccessKind {
254+
pub enum SharedItemAccessKind {
254255
Full,
255256
Readonly,
256257
}
257258

258259
#[repr(C)]
259-
pub struct SharedDirectoryAccess {
260-
pub kind: SharedDirectoryAccessKind,
260+
pub struct SharedItem {
261+
pub kind: SharedItemAccessKind,
261262
pub host_path: *const c_char,
262263
pub sandbox_path: *const c_char,
263264
}
264265

265266
// minion-ffi will never modify host_path or sandbox_path, so no races can occur
266-
unsafe impl Sync for SharedDirectoryAccess {}
267+
unsafe impl Sync for SharedItem {}
267268

268269
#[no_mangle]
269-
pub static SHARED_DIRECTORY_ACCESS_FIN: SharedDirectoryAccess = SharedDirectoryAccess {
270-
kind: SharedDirectoryAccessKind::Full, //doesn't matter
270+
pub static SHARED_DIRECTORY_ACCESS_FIN: SharedItem = SharedItem {
271+
kind: SharedItemAccessKind::Full, //doesn't matter
271272
host_path: std::ptr::null(),
272273
sandbox_path: std::ptr::null(),
273274
};

minion-tests/src/worker.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ async fn inner_main(test_cases: &[&'static dyn TestCase]) {
2121
max_alive_process_count: test_case.process_count_limit(),
2222
memory_limit: MEMORY_LIMIT_IN_BYTES,
2323
isolation_root: tempdir.path().to_path_buf(),
24-
exposed_paths: vec![minion::SharedDir {
24+
shared_items: vec![minion::SharedItem {
25+
id: None,
2526
src: std::env::current_exe().unwrap(),
2627
dest: "/me".into(),
27-
kind: minion::SharedDirKind::Readonly,
28+
kind: minion::SharedItemKind::Readonly,
2829
}],
2930
};
3031
let sandbox = backend.new_sandbox(opts).expect("can not create sandbox");

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ pub use command::Command;
5151
///
5252
/// Warning: this type is __unstable__ (i.e. not covered by SemVer) and __non-portable__
5353
#[derive(Serialize, Deserialize, Debug, Clone)]
54-
pub enum SharedDirKind {
54+
pub enum SharedItemKind {
5555
Readonly,
5656
Full,
5757
}
5858

5959
#[derive(Serialize, Deserialize, Debug, Clone)]
60-
pub struct SharedDir {
60+
pub struct SharedItem {
61+
/// Optional identifier.
62+
/// It can be used to provide additional backend-specific settings.
63+
pub id: Option<String>,
6164
/// Path on system
6265
pub src: PathBuf,
6366
/// Path for child
6467
pub dest: PathBuf,
65-
pub kind: SharedDirKind,
68+
pub kind: SharedItemKind,
6669
}
6770

6871
/// This struct is returned by `Sandbox::resource_usage`
@@ -86,7 +89,7 @@ pub struct SandboxOptions {
8689
/// Specifies total wall-clock timer limit for whole sandbox
8790
pub real_time_limit: Duration,
8891
pub isolation_root: PathBuf,
89-
pub exposed_paths: Vec<SharedDir>,
92+
pub shared_items: Vec<SharedItem>,
9093
}
9194

9295
impl SandboxOptions {
@@ -99,11 +102,11 @@ impl SandboxOptions {
99102
}
100103

101104
fn postprocess(&mut self) {
102-
let mut paths = std::mem::replace(&mut self.exposed_paths, Vec::new());
105+
let mut paths = std::mem::replace(&mut self.shared_items, Vec::new());
103106
for x in &mut paths {
104107
x.dest = self.make_relative(&x.dest).to_path_buf();
105108
}
106-
std::mem::swap(&mut paths, &mut self.exposed_paths);
109+
std::mem::swap(&mut paths, &mut self.shared_items);
107110
}
108111
}
109112

src/linux/jail_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{linux::util::Pid, SharedDir};
1+
use crate::{linux::util::Pid, SharedItem};
22
use rand::seq::SliceRandom;
33
use serde::{Deserialize, Serialize};
44
use std::{ffi::OsString, os::unix::io::RawFd, path::PathBuf, time::Duration};
@@ -14,7 +14,7 @@ pub(crate) struct JailOptions {
1414
/// Possible value: time_limit * 3.
1515
pub(crate) real_time_limit: Duration,
1616
pub(crate) isolation_root: PathBuf,
17-
pub(crate) exposed_paths: Vec<SharedDir>,
17+
pub(crate) shared_items: Vec<SharedItem>,
1818
pub(crate) jail_id: String,
1919
pub(crate) watchdog_chan: RawFd,
2020
pub(crate) allow_mount_ns_failure: bool,

src/linux/sandbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl LinuxSandbox {
171171
cpu_time_limit: options.cpu_time_limit,
172172
real_time_limit: options.real_time_limit,
173173
isolation_root: options.isolation_root.clone(),
174-
exposed_paths: options.exposed_paths.clone(),
174+
shared_items: options.shared_items.clone(),
175175
jail_id: jail_id.clone(),
176176
watchdog_chan: write_end,
177177
allow_mount_ns_failure: settings.allow_unsupported_mount_namespace,

src/linux/zygote/setup.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
Error,
1010
},
11-
SharedDir, SharedDirKind,
11+
SharedItem, SharedItemKind,
1212
};
1313
use nix::sys::signal;
1414
use std::{
@@ -49,7 +49,7 @@ fn configure_dir(dir_path: &Path) -> Result<(), Error> {
4949
Ok(())
5050
}
5151

52-
fn expose_dir(jail_root: &Path, system_path: &Path, alias_path: &Path, kind: SharedDirKind) {
52+
fn expose_item(jail_root: &Path, system_path: &Path, alias_path: &Path, kind: SharedItemKind) {
5353
let bind_target = jail_root.join(alias_path);
5454
fs::create_dir_all(&bind_target).unwrap();
5555
let stat = fs::metadata(&system_path)
@@ -72,7 +72,7 @@ fn expose_dir(jail_root: &Path, system_path: &Path, alias_path: &Path, kind: Sha
7272
err_exit("mount");
7373
}
7474

75-
if let SharedDirKind::Readonly = kind {
75+
if let SharedItemKind::Readonly = kind {
7676
let rem_ret = libc::mount(
7777
ptr::null(),
7878
bind_target.as_ptr(),
@@ -87,10 +87,10 @@ fn expose_dir(jail_root: &Path, system_path: &Path, alias_path: &Path, kind: Sha
8787
}
8888
}
8989

90-
pub(crate) fn expose_dirs(expose: &[SharedDir], jail_root: &Path) {
90+
pub(crate) fn expose_items(expose: &[SharedItem], jail_root: &Path) {
9191
// mount --bind
9292
for x in expose {
93-
expose_dir(jail_root, &x.src, &x.dest, x.kind.clone())
93+
expose_item(jail_root, &x.src, &x.dest, x.kind.clone())
9494
}
9595
}
9696

@@ -183,7 +183,7 @@ fn setup_time_watch(
183183
}
184184

185185
fn setup_expositions(options: &JailOptions) {
186-
expose_dirs(&options.exposed_paths, &options.isolation_root);
186+
expose_items(&options.shared_items, &options.isolation_root);
187187
}
188188

189189
fn setup_panic_hook() {

0 commit comments

Comments
 (0)