runnerd_core/
isolation.rs1use std::fmt;
5
6use bollard::models::HostConfig;
7
8use crate::config;
9
10pub trait Isolation: Send + Sync + fmt::Debug {
12 fn name(&self) -> &'static str;
14 fn is_unsafe(&self) -> bool;
16 fn configure(&self, host_config: &mut HostConfig);
18}
19
20#[derive(Debug)]
22pub struct Sysbox;
23
24impl Isolation for Sysbox {
25 fn name(&self) -> &'static str {
26 "sysbox"
27 }
28
29 fn is_unsafe(&self) -> bool {
30 false
31 }
32
33 fn configure(&self, host_config: &mut HostConfig) {
34 host_config.runtime = Some("sysbox-runc".to_owned());
35 host_config.privileged = Some(false);
36 }
37}
38
39#[derive(Debug)]
41pub struct UnsafeDind;
42
43impl Isolation for UnsafeDind {
44 fn name(&self) -> &'static str {
45 "unsafe-dind"
46 }
47
48 fn is_unsafe(&self) -> bool {
49 true
50 }
51
52 fn configure(&self, host_config: &mut HostConfig) {
53 host_config.runtime = Some("runc".to_owned());
55 host_config.privileged = Some(true);
56 }
57}
58
59pub fn backend(isolation: config::Isolation) -> &'static dyn Isolation {
61 match isolation {
62 config::Isolation::Sysbox => &Sysbox,
63 config::Isolation::UnsafeDind => &UnsafeDind,
64 }
65}
66
67#[cfg(test)]
68mod tests;