Skip to content

Commit 0ca885f

Browse files
andrewdunndevcgwalters
authored andcommitted
install: Reject a config stateroot on composefs-only images
The composefs backend only uses the `default` stateroot. #2544 made `--stateroot` fail with it and left a stateroot from the install configuration unchecked, since an image may set one for its ostree installs. An image that ships a UKI, or selects composefs itself with no ostree prepare-root.conf, can't be installed with ostree, so its configured stateroot was always ignored and the install still landed in `default`. Check the configured stateroot for those images too, unless `--stateroot` is passed. With `--composefs-backend` on an image that can also be installed with ostree, it's still ignored. Assisted-by: AI Signed-off-by: Andrew Dunn <andrew@dunn.dev>
1 parent d0a449a commit 0ca885f

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

‎crates/lib/src/install.rs‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,13 @@ pub(crate) struct InstallComposefsOpts {
438438
impl InstallComposefsOpts {
439439
/// Check that the options fit together, once `composefs_backend` says
440440
/// whether the composefs backend is used (passed, or selected by the image).
441+
/// `config_stateroot` comes from the install configuration; the caller
442+
/// passes `None` when `--stateroot` overrides it.
441443
pub(crate) fn validate(
442444
&self,
443445
bootloader: Option<&Bootloader>,
444446
stateroot: Option<&str>,
447+
config_stateroot: Option<&str>,
445448
) -> Result<()> {
446449
if self.composefs_backend {
447450
let default = ostree_container::deploy::STATEROOT_DEFAULT;
@@ -450,6 +453,11 @@ impl InstallComposefsOpts {
450453
"--stateroot {stateroot} is not supported with the composefs backend, which only uses {default}"
451454
);
452455
}
456+
if let Some(stateroot) = config_stateroot.filter(|&s| s != default) {
457+
anyhow::bail!(
458+
"stateroot {stateroot} in the install configuration is not supported with the composefs backend, which only uses {default}"
459+
);
460+
}
453461
} else {
454462
anyhow::ensure!(
455463
!matches!(bootloader, Some(Bootloader::Ukiboot)),
@@ -1869,9 +1877,17 @@ async fn prepare_install(
18691877
)?;
18701878
tracing::debug!("Composefs default: {composefs_default}");
18711879
composefs_options.composefs_backend |= composefs_required || composefs_default;
1880+
// An image may set a stateroot in its install configuration for its ostree
1881+
// installs, so only check it when the image can't be installed with ostree.
1882+
let config_stateroot = install_config
1883+
.as_ref()
1884+
.and_then(|c| c.stateroot.as_deref())
1885+
.filter(|_| config_opts.stateroot.is_none())
1886+
.filter(|_| composefs_required || composefs_default);
18721887
composefs_options.validate(
18731888
config_opts.bootloader.as_ref(),
18741889
config_opts.stateroot.as_deref(),
1890+
config_stateroot,
18751891
)?;
18761892

18771893
composefs_options.validate_bound_images(config_opts.bound_images, &rootfs)?;
@@ -3284,7 +3300,7 @@ mod tests {
32843300
},
32853301
};
32863302
assert_eq!(
3287-
opts.validate(bootloader.as_ref(), stateroot).is_ok(),
3303+
opts.validate(bootloader.as_ref(), stateroot, None).is_ok(),
32883304
valid,
32893305
"{opts:?} {bootloader:?} {stateroot:?}"
32903306
);
@@ -3295,9 +3311,24 @@ mod tests {
32953311
..Default::default()
32963312
};
32973313
assert_eq!(
3298-
opts.validate(None, Some("myroot")).unwrap_err().to_string(),
3314+
opts.validate(None, Some("myroot"), None)
3315+
.unwrap_err()
3316+
.to_string(),
32993317
"--stateroot myroot is not supported with the composefs backend, which only uses default"
33003318
);
3319+
3320+
assert!(opts.validate(None, None, Some("default")).is_ok());
3321+
assert!(
3322+
InstallComposefsOpts::default()
3323+
.validate(None, None, Some("myroot"))
3324+
.is_ok()
3325+
);
3326+
assert_eq!(
3327+
opts.validate(None, None, Some("myroot"))
3328+
.unwrap_err()
3329+
.to_string(),
3330+
"stateroot myroot in the install configuration is not supported with the composefs backend, which only uses default"
3331+
);
33013332
}
33023333

33033334
#[test]

0 commit comments

Comments
 (0)