Skip to content

Commit cf70d5f

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 cf70d5f

File tree

1 file changed

+70
-30
lines changed

1 file changed

+70
-30
lines changed

crates/lib/src/install.rs

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ 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+
#[serde(default)]
293+
pub(crate) insecure: bool,
293294
}
294295

295296
#[cfg(feature = "install-to-disk")]
@@ -317,9 +318,11 @@ pub(crate) struct InstallToDiskOpts {
317318
pub(crate) via_loopback: bool,
318319

319320
#[clap(long)]
321+
#[serde(default)]
320322
pub(crate) composefs_native: bool,
321323

322324
#[clap(flatten)]
325+
#[serde(flatten)]
323326
pub(crate) composefs_opts: InstallComposefsOpts,
324327
}
325328

@@ -608,17 +611,12 @@ impl FromStr for MountSpec {
608611
impl InstallToDiskOpts {
609612
pub(crate) fn validate(&self) -> Result<()> {
610613
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");
614+
// Reject using --insecure without --composefs
615+
if self.composefs_opts.insecure != false {
616+
anyhow::bail!("--insecure must not be provided without --composefs");
614617
}
615618
}
616619

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-
622620
Ok(())
623621
}
624622
}
@@ -1592,7 +1590,7 @@ pub fn read_file<ObjectID: FsVerityHashValue>(
15921590

15931591
pub(crate) enum BootSetupType<'a> {
15941592
/// For initial setup, i.e. install to-disk
1595-
Setup(&'a RootSetup),
1593+
Setup((&'a RootSetup, &'a State)),
15961594
/// For `bootc upgrade`
15971595
Upgrade,
15981596
}
@@ -1608,10 +1606,18 @@ pub(crate) fn setup_composefs_bls_boot(
16081606
let id_hex = id.to_hex();
16091607

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

16161622
(root_setup.physical_root_path.clone(), cmdline_options)
16171623
}
@@ -1766,16 +1772,26 @@ pub(crate) fn setup_composefs_uki_boot(
17661772
id: &Sha256HashValue,
17671773
entry: ComposefsBootEntry<Sha256HashValue>,
17681774
) -> Result<()> {
1769-
let (root_path, esp_device) = match setup_type {
1770-
BootSetupType::Setup(root_setup) => {
1775+
let (root_path, esp_device, is_insecure_from_opts) = match setup_type {
1776+
BootSetupType::Setup((root_setup, state)) => {
1777+
if let Some(v) = &state.config_opts.karg {
1778+
if v.len() > 0 {
1779+
tracing::warn!("kargs passed for UKI will be ignored");
1780+
}
1781+
}
1782+
17711783
let esp_part = root_setup
17721784
.device_info
17731785
.partitions
17741786
.iter()
17751787
.find(|p| p.parttype.as_str() == ESP_GUID)
17761788
.ok_or_else(|| anyhow!("ESP partition not found"))?;
17771789

1778-
(root_setup.physical_root_path.clone(), esp_part.node.clone())
1790+
(
1791+
root_setup.physical_root_path.clone(),
1792+
esp_part.node.clone(),
1793+
state.composefs_options.as_ref().map(|x| x.insecure),
1794+
)
17791795
}
17801796

17811797
BootSetupType::Upgrade => {
@@ -1788,7 +1804,7 @@ pub(crate) fn setup_composefs_uki_boot(
17881804
anyhow::bail!("Could not find parent device for mountpoint /sysroot");
17891805
};
17901806

1791-
(sysroot, get_esp_partition(&parent)?.0)
1807+
(sysroot, get_esp_partition(&parent)?.0, None)
17921808
}
17931809
};
17941810

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

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

@@ -1991,17 +2027,21 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
19912027
anyhow::bail!("No boot entries!");
19922028
};
19932029

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-
}
2030+
let boot_type = BootType::from(&entry);
2031+
2032+
match boot_type {
2033+
BootType::Bls => setup_composefs_bls_boot(
2034+
BootSetupType::Setup((&root_setup, &state)),
2035+
repo,
2036+
&id,
2037+
entry,
2038+
)?,
2039+
BootType::Uki => setup_composefs_uki_boot(
2040+
BootSetupType::Setup((&root_setup, &state)),
2041+
repo,
2042+
&id,
2043+
entry,
2044+
)?,
20052045
};
20062046

20072047
write_composefs_state(
@@ -2013,7 +2053,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
20132053
signature: None,
20142054
},
20152055
false,
2016-
composefs_opts.boot,
2056+
boot_type,
20172057
)?;
20182058

20192059
Ok(())

0 commit comments

Comments
 (0)