runnerd_core/
isolation.rs1use std::fmt;
7
8use bollard::models::HostConfig;
9
10use crate::api::{Check, CheckStatus};
11use crate::config;
12
13pub trait Isolation: Send + Sync + fmt::Debug {
15 fn name(&self) -> &'static str;
17 fn is_unsafe(&self) -> bool;
19 fn configure(&self, host_config: &mut HostConfig);
21}
22
23#[derive(Debug)]
25pub struct Sysbox;
26
27impl Isolation for Sysbox {
28 fn name(&self) -> &'static str {
29 "sysbox"
30 }
31
32 fn is_unsafe(&self) -> bool {
33 false
34 }
35
36 fn configure(&self, host_config: &mut HostConfig) {
37 host_config.runtime = Some("sysbox-runc".to_owned());
38 host_config.privileged = Some(false);
39 }
40}
41
42#[derive(Debug)]
44pub struct UnsafeDind;
45
46impl Isolation for UnsafeDind {
47 fn name(&self) -> &'static str {
48 "unsafe-dind"
49 }
50
51 fn is_unsafe(&self) -> bool {
52 true
53 }
54
55 fn configure(&self, host_config: &mut HostConfig) {
56 host_config.runtime = Some("runc".to_owned());
58 host_config.privileged = Some(true);
59 }
60}
61
62pub fn backend(isolation: config::Isolation) -> &'static dyn Isolation {
64 match isolation {
65 config::Isolation::Sysbox => &Sysbox,
66 config::Isolation::UnsafeDind => &UnsafeDind,
67 }
68}
69
70const MODULES_STAT_REFUSED: &str = "failed to stat mount source at /lib/modules/";
72
73fn missing_modules_release(error: &str) -> Option<&str> {
76 let (_, after) = error.split_once(MODULES_STAT_REFUSED)?;
77 if !after.contains("no such file or directory") {
78 return None;
79 }
80 let release = after.split(['/', ':']).next()?;
81 (!release.is_empty()).then_some(release)
82}
83
84pub fn start_failure(runner: &str, docker_error: &str) -> String {
88 match missing_modules_release(docker_error) {
89 Some(release) => format!(
90 "cannot start {runner}: the running kernel's modules are gone (/lib/modules/{release} does not exist), \
91 most likely removed by a package upgrade; reboot to run the installed kernel. Docker said: {docker_error}"
92 ),
93 None => format!("cannot start {runner}: {docker_error}"),
94 }
95}
96
97pub fn modules_check(release: &str, present: bool) -> Check {
100 if present {
101 return Check {
102 name: "kernel modules".to_owned(),
103 status: CheckStatus::Pass,
104 detail: format!("/lib/modules/{release} exists"),
105 fix: None,
106 };
107 }
108 Check {
109 name: "kernel modules".to_owned(),
110 status: CheckStatus::Fail,
111 detail: format!(
112 "/lib/modules/{release} does not exist, which sysbox mounts into every runner, so no runner starts; a \
113 package upgrade removes it while that kernel runs"
114 ),
115 fix: Some("reboot to run the installed kernel".to_owned()),
116 }
117}
118
119#[cfg(test)]
120mod tests;