Skip to content

Commit 2384aad

Browse files
cli/composefs: Change composefs options
Remove `--boot` option as we can get it from the image itself. Allow `--insecure` option to `--composefs-native` to make fsverity validation optional in case the filesystem does not support it. Signed-off-by: Johan-Liebert1 <[email protected]>
1 parent b0e43a8 commit 2384aad

File tree

1 file changed

+67
-30
lines changed

1 file changed

+67
-30
lines changed

crates/lib/src/install.rs

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ impl From<&ComposefsBootEntry<Sha256HashValue>> for BootType {
288288

289289
#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize, PartialEq, Eq)]
290290
pub(crate) struct InstallComposefsOpts {
291-
#[clap(long, value_enum, default_value_t)]
292-
pub(crate) boot: BootType,
291+
#[clap(long, default_value_t)]
292+
pub(crate) insecure: bool,
293293
}
294294

295295
#[cfg(feature = "install-to-disk")]
@@ -608,17 +608,12 @@ impl FromStr for MountSpec {
608608
impl InstallToDiskOpts {
609609
pub(crate) fn validate(&self) -> Result<()> {
610610
if !self.composefs_native {
611-
// Reject using --boot without --composefs
612-
if self.composefs_opts.boot != BootType::default() {
613-
anyhow::bail!("--boot must not be provided without --composefs");
611+
// Reject using --insecure without --composefs
612+
if self.composefs_opts.insecure != false {
613+
anyhow::bail!("--insecure must not be provided without --composefs");
614614
}
615615
}
616616

617-
// Can't add kargs to UKI
618-
if self.composefs_opts.boot == BootType::Uki && self.config_opts.karg.is_some() {
619-
anyhow::bail!("Cannot pass kargs to UKI");
620-
}
621-
622617
Ok(())
623618
}
624619
}
@@ -1592,7 +1587,7 @@ pub fn read_file<ObjectID: FsVerityHashValue>(
15921587

15931588
pub(crate) enum BootSetupType<'a> {
15941589
/// For initial setup, i.e. install to-disk
1595-
Setup(&'a RootSetup),
1590+
Setup((&'a RootSetup, &'a State)),
15961591
/// For `bootc upgrade`
15971592
Upgrade,
15981593
}
@@ -1608,10 +1603,18 @@ pub(crate) fn setup_composefs_bls_boot(
16081603
let id_hex = id.to_hex();
16091604

16101605
let (root_path, cmdline_refs) = match setup_type {
1611-
BootSetupType::Setup(root_setup) => {
1606+
BootSetupType::Setup((root_setup, state)) => {
16121607
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
16131608
let mut cmdline_options = String::from(root_setup.kargs.join(" "));
1614-
cmdline_options.push_str(&format!(" composefs={id_hex}"));
1609+
1610+
match &state.composefs_options {
1611+
Some(opt) if opt.insecure => {
1612+
cmdline_options.push_str(&format!(" composefs=?{id_hex}"));
1613+
}
1614+
None | Some(..) => {
1615+
cmdline_options.push_str(&format!(" composefs={id_hex}"));
1616+
}
1617+
};
16151618

16161619
(root_setup.physical_root_path.clone(), cmdline_options)
16171620
}
@@ -1766,16 +1769,26 @@ pub(crate) fn setup_composefs_uki_boot(
17661769
id: &Sha256HashValue,
17671770
entry: ComposefsBootEntry<Sha256HashValue>,
17681771
) -> Result<()> {
1769-
let (root_path, esp_device) = match setup_type {
1770-
BootSetupType::Setup(root_setup) => {
1772+
let (root_path, esp_device, is_insecure_from_opts) = match setup_type {
1773+
BootSetupType::Setup((root_setup, state)) => {
1774+
if let Some(v) = &state.config_opts.karg {
1775+
if v.len() > 0 {
1776+
tracing::warn!("kargs passed for UKI will be ignored");
1777+
}
1778+
}
1779+
17711780
let esp_part = root_setup
17721781
.device_info
17731782
.partitions
17741783
.iter()
17751784
.find(|p| p.parttype.as_str() == ESP_GUID)
17761785
.ok_or_else(|| anyhow!("ESP partition not found"))?;
17771786

1778-
(root_setup.physical_root_path.clone(), esp_part.node.clone())
1787+
(
1788+
root_setup.physical_root_path.clone(),
1789+
esp_part.node.clone(),
1790+
state.composefs_options.as_ref().map(|x| x.insecure),
1791+
)
17791792
}
17801793

17811794
BootSetupType::Upgrade => {
@@ -1788,7 +1801,7 @@ pub(crate) fn setup_composefs_uki_boot(
17881801
anyhow::bail!("Could not find parent device for mountpoint /sysroot");
17891802
};
17901803

1791-
(sysroot, get_esp_partition(&parent)?.0)
1804+
(sysroot, get_esp_partition(&parent)?.0, None)
17921805
}
17931806
};
17941807

@@ -1809,7 +1822,27 @@ pub(crate) fn setup_composefs_uki_boot(
18091822
ComposefsBootEntry::Type2(type2_entry) => {
18101823
let uki = read_file(&type2_entry.file, &repo).context("Reading UKI")?;
18111824
let cmdline = uki::get_cmdline(&uki).context("Getting UKI cmdline")?;
1812-
let (composefs_cmdline, _) = get_cmdline_composefs::<Sha256HashValue>(cmdline)?;
1825+
let (composefs_cmdline, insecure) = get_cmdline_composefs::<Sha256HashValue>(cmdline)?;
1826+
1827+
// If the UKI cmdline does not match what the user has passed as cmdline option
1828+
// NOTE: This will only be checked for new installs and now upgrades/switches
1829+
if let Some(is_insecure_from_opts) = is_insecure_from_opts {
1830+
match is_insecure_from_opts {
1831+
true => {
1832+
if !insecure {
1833+
tracing::warn!(
1834+
"--insecure passed as option but UKI cmdline does not support it"
1835+
)
1836+
}
1837+
}
1838+
1839+
false => {
1840+
if insecure {
1841+
tracing::warn!("UKI cmdline has composefs set as insecure")
1842+
}
1843+
}
1844+
}
1845+
}
18131846

18141847
let boot_label = uki::get_boot_label(&uki).context("Getting UKI boot label")?;
18151848

@@ -1991,17 +2024,21 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
19912024
anyhow::bail!("No boot entries!");
19922025
};
19932026

1994-
let Some(composefs_opts) = &state.composefs_options else {
1995-
anyhow::bail!("Could not find options for composefs")
1996-
};
1997-
1998-
match composefs_opts.boot {
1999-
BootType::Bls => {
2000-
setup_composefs_bls_boot(BootSetupType::Setup(&root_setup), repo, &id, entry)?
2001-
}
2002-
BootType::Uki => {
2003-
setup_composefs_uki_boot(BootSetupType::Setup(&root_setup), repo, &id, entry)?
2004-
}
2027+
let boot_type = BootType::from(&entry);
2028+
2029+
match boot_type {
2030+
BootType::Bls => setup_composefs_bls_boot(
2031+
BootSetupType::Setup((&root_setup, &state)),
2032+
repo,
2033+
&id,
2034+
entry,
2035+
)?,
2036+
BootType::Uki => setup_composefs_uki_boot(
2037+
BootSetupType::Setup((&root_setup, &state)),
2038+
repo,
2039+
&id,
2040+
entry,
2041+
)?,
20052042
};
20062043

20072044
write_composefs_state(
@@ -2013,7 +2050,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
20132050
signature: None,
20142051
},
20152052
false,
2016-
composefs_opts.boot,
2053+
boot_type,
20172054
)?;
20182055

20192056
Ok(())

0 commit comments

Comments
 (0)