Skip to content

Commit 40073f7

Browse files
committed
container: Allow disabling the overwrite of /etc files
Whilst certainly handy for boulder, this is breaking our moss invocations of triggers, and prevents a read-only mount of /etc. With this change, we fix the behaviour for moss itself, and retain the old behaviour for boulder. Signed-off-by: Ikey Doherty <[email protected]>
1 parent c4f30e1 commit 40073f7

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

crates/container/src/lib.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ pub struct Container {
3030
networking: bool,
3131
hostname: Option<String>,
3232
ignore_host_sigint: bool,
33+
override_accounts: bool,
3334
}
3435

3536
impl Container {
37+
/// Create a new Contaienr using the default options
3638
pub fn new(root: impl Into<PathBuf>) -> Self {
3739
Self {
3840
root: root.into(),
@@ -41,16 +43,19 @@ impl Container {
4143
networking: false,
4244
hostname: None,
4345
ignore_host_sigint: false,
46+
override_accounts: true,
4447
}
4548
}
4649

50+
/// Override the working directory
4751
pub fn work_dir(self, work_dir: impl Into<PathBuf>) -> Self {
4852
Self {
4953
work_dir: Some(work_dir.into()),
5054
..self
5155
}
5256
}
5357

58+
/// Create a read-write bind mount
5459
pub fn bind_rw(mut self, host: impl Into<PathBuf>, guest: impl Into<PathBuf>) -> Self {
5560
self.binds.push(Bind {
5661
source: host.into(),
@@ -60,6 +65,7 @@ impl Container {
6065
self
6166
}
6267

68+
/// Create a read-only bind mount
6369
pub fn bind_ro(mut self, host: impl Into<PathBuf>, guest: impl Into<PathBuf>) -> Self {
6470
self.binds.push(Bind {
6571
source: host.into(),
@@ -69,20 +75,30 @@ impl Container {
6975
self
7076
}
7177

78+
/// Configure networking availability
7279
pub fn networking(self, enabled: bool) -> Self {
7380
Self {
7481
networking: enabled,
7582
..self
7683
}
7784
}
7885

86+
/// Override hostname (via /etc/hostname)
7987
pub fn hostname(self, hostname: impl ToString) -> Self {
8088
Self {
8189
hostname: Some(hostname.to_string()),
8290
..self
8391
}
8492
}
8593

94+
/// Override the system accounts (`/etc/{passwd,group}`) for builders
95+
pub fn override_accounts(self, configure: bool) -> Self {
96+
Self {
97+
override_accounts: configure,
98+
..self
99+
}
100+
}
101+
86102
/// Ignore `SIGINT` from the parent process. This allows it to be forwarded to a
87103
/// spawned process inside the container by using [`forward_sigint`].
88104
pub fn ignore_host_sigint(self, ignore: bool) -> Self {
@@ -92,6 +108,7 @@ impl Container {
92108
}
93109
}
94110

111+
/// Run `f` as a container process payload
95112
pub fn run<E>(self, mut f: impl FnMut() -> Result<(), E>) -> Result<(), Error>
96113
where
97114
E: std::error::Error + 'static,
@@ -192,6 +209,7 @@ impl Container {
192209
}
193210
}
194211

212+
/// Reenter the container
195213
fn enter<E>(
196214
container: &Container,
197215
sync: (i32, i32),
@@ -216,14 +234,17 @@ where
216234
f().map_err(|e| ContainerError::Run(Box::new(e)))
217235
}
218236

237+
/// Setup the container
219238
fn setup(container: &Container) -> Result<(), ContainerError> {
220239
if container.networking {
221240
setup_networking(&container.root)?;
222241
}
223242

224243
pivot(&container.root, &container.binds)?;
225244

226-
setup_root_user()?;
245+
if container.override_accounts {
246+
setup_root_user()?;
247+
}
227248

228249
if let Some(hostname) = &container.hostname {
229250
sethostname(hostname)?;
@@ -236,6 +257,7 @@ fn setup(container: &Container) -> Result<(), ContainerError> {
236257
Ok(())
237258
}
238259

260+
/// Pivot the process into the rootfs
239261
fn pivot(root: &Path, binds: &[Bind]) -> Result<(), ContainerError> {
240262
const OLD_PATH: &str = "old_root";
241263

crates/moss/src/client/postblit.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use triggers::{
1919
TriggerCommand,
2020
};
2121

22-
use crate::{environment, Installation};
22+
use crate::Installation;
2323

2424
use super::{create_root_links, PendingFile};
2525

@@ -77,11 +77,10 @@ pub(crate) async fn handle_postblits(
7777
/// `staging_dir` for the `/usr` tree, and execution is performed within a clone-based
7878
/// container.
7979
fn execute_trigger(install: &Installation, trigger: &TriggerCommand) -> Result<(), Error> {
80-
// TODO: Use bind_ro for etc
8180
let isolation = Container::new(install.isolation_dir())
8281
.networking(false)
83-
.hostname(environment::NAME)
84-
.bind_rw(install.root.join("etc"), "/etc")
82+
.override_accounts(false)
83+
.bind_ro(install.root.join("etc"), "/etc")
8584
.bind_rw(install.staging_path("usr"), "/usr")
8685
.work_dir("/");
8786

0 commit comments

Comments
 (0)