Skip to content

Commit 0ff7a95

Browse files
Johan-Liebert1cgwalters
authored andcommitted
cli: Change insecure param to allow_missing_fsverity
`allow_missing_fsverity` conveys the intent in a much better way than just `insecure` Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent e7ff6c9 commit 0ff7a95

11 files changed

Lines changed: 73 additions & 49 deletions

File tree

crates/initramfs/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,17 @@ fn open_root_fs(path: &Path) -> Result<OwnedFd> {
258258
/// Prepares a floating mount for composefs and returns the fd
259259
///
260260
/// # Arguments
261-
/// * sysroot - fd for /sysroot
262-
/// * name - Name of the EROFS image to be mounted
263-
/// * insecure - Whether fsverity is optional or not
261+
/// * sysroot - fd for /sysroot
262+
/// * name - Name of the EROFS image to be mounted
263+
/// * allow_missing_fsverity - Whether to allow mount without fsverity support
264264
#[context("Mounting composefs image")]
265-
pub fn mount_composefs_image(sysroot: &OwnedFd, name: &str, insecure: bool) -> Result<OwnedFd> {
265+
pub fn mount_composefs_image(
266+
sysroot: &OwnedFd,
267+
name: &str,
268+
allow_missing_fsverity: bool,
269+
) -> Result<OwnedFd> {
266270
let mut repo = Repository::<Sha512HashValue>::open_path(sysroot, "composefs")?;
267-
repo.set_insecure(insecure);
271+
repo.set_insecure(allow_missing_fsverity);
268272
let rootfs = repo
269273
.mount(name)
270274
.context("Failed to mount composefs image")?;

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub(crate) fn setup_composefs_bls_boot(
519519

520520
cmdline_options.extend(&root_setup.kargs);
521521

522-
let composefs_cmdline = if state.composefs_options.insecure {
522+
let composefs_cmdline = if state.composefs_options.allow_missing_verity {
523523
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
524524
} else {
525525
format!("{COMPOSEFS_CMDLINE}={id_hex}")
@@ -558,7 +558,7 @@ pub(crate) fn setup_composefs_bls_boot(
558558
};
559559

560560
// Copy all cmdline args, replacing only `composefs=`
561-
let param = if booted_cfs.cmdline.insecure {
561+
let param = if booted_cfs.cmdline.allow_missing_fsverity {
562562
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
563563
} else {
564564
format!("{COMPOSEFS_CMDLINE}={id_hex}")
@@ -811,7 +811,7 @@ fn write_pe_to_esp(
811811
file_path: &Utf8Path,
812812
pe_type: PEType,
813813
uki_id: &Sha512HashValue,
814-
is_insecure_from_opts: bool,
814+
missing_fsverity_allowed: bool,
815815
mounted_efi: impl AsRef<Path>,
816816
bootloader: &Bootloader,
817817
) -> Result<Option<UKIInfo>> {
@@ -824,17 +824,19 @@ fn write_pe_to_esp(
824824
if matches!(pe_type, PEType::Uki) {
825825
let cmdline = uki::get_cmdline(&efi_bin).context("Getting UKI cmdline")?;
826826

827-
let (composefs_cmdline, insecure) =
827+
let (composefs_cmdline, missing_verity_allowed_cmdline) =
828828
get_cmdline_composefs::<Sha512HashValue>(cmdline).context("Parsing composefs=")?;
829829

830830
// If the UKI cmdline does not match what the user has passed as cmdline option
831831
// NOTE: This will only be checked for new installs and now upgrades/switches
832-
match is_insecure_from_opts {
833-
true if !insecure => {
834-
tracing::warn!("--insecure passed as option but UKI cmdline does not support it");
832+
match missing_fsverity_allowed {
833+
true if !missing_verity_allowed_cmdline => {
834+
tracing::warn!(
835+
"--allow-missing-fsverity passed as option but UKI cmdline does not support it"
836+
);
835837
}
836838

837-
false if insecure => {
839+
false if missing_verity_allowed_cmdline => {
838840
tracing::warn!("UKI cmdline has composefs set as insecure");
839841
}
840842

@@ -1080,7 +1082,8 @@ pub(crate) fn setup_composefs_uki_boot(
10801082
id: &Sha512HashValue,
10811083
entries: Vec<ComposefsBootEntry<Sha512HashValue>>,
10821084
) -> Result<String> {
1083-
let (root_path, esp_device, bootloader, is_insecure_from_opts, uki_addons) = match setup_type {
1085+
let (root_path, esp_device, bootloader, missing_fsverity_allowed, uki_addons) = match setup_type
1086+
{
10841087
BootSetupType::Setup((root_setup, state, postfetch, ..)) => {
10851088
state.require_no_kargs_for_uki()?;
10861089

@@ -1090,7 +1093,7 @@ pub(crate) fn setup_composefs_uki_boot(
10901093
root_setup.physical_root_path.clone(),
10911094
esp_part.node.clone(),
10921095
postfetch.detected_bootloader.clone(),
1093-
state.composefs_options.insecure,
1096+
state.composefs_options.allow_missing_verity,
10941097
state.composefs_options.uki_addon.as_ref(),
10951098
)
10961099
}
@@ -1104,7 +1107,7 @@ pub(crate) fn setup_composefs_uki_boot(
11041107
sysroot,
11051108
get_esp_partition(&sysroot_parent)?.0,
11061109
bootloader,
1107-
booted_cfs.cmdline.insecure,
1110+
booted_cfs.cmdline.allow_missing_fsverity,
11081111
None,
11091112
)
11101113
}
@@ -1155,7 +1158,7 @@ pub(crate) fn setup_composefs_uki_boot(
11551158
utf8_file_path,
11561159
entry.pe_type,
11571160
&id,
1158-
is_insecure_from_opts,
1161+
missing_fsverity_allowed,
11591162
esp_mount.dir.path(),
11601163
&bootloader,
11611164
)?;
@@ -1236,10 +1239,10 @@ pub(crate) async fn setup_composefs_boot(
12361239
root_setup: &RootSetup,
12371240
state: &State,
12381241
image_id: &str,
1239-
insecure: bool,
1242+
allow_missing_fsverity: bool,
12401243
) -> Result<()> {
12411244
let mut repo = open_composefs_repo(&root_setup.physical_root)?;
1242-
repo.set_insecure(insecure);
1245+
repo.set_insecure(allow_missing_fsverity);
12431246

12441247
let mut fs = create_composefs_filesystem(&repo, image_id, None)?;
12451248
let entries = fs.transform_for_boot(&repo)?;
@@ -1311,7 +1314,7 @@ pub(crate) async fn setup_composefs_boot(
13111314
&state.source.imageref.name,
13121315
))
13131316
.await?,
1314-
insecure,
1317+
allow_missing_fsverity,
13151318
)
13161319
.await?;
13171320

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) async fn get_etc_diff(storage: &Storage, booted_cfs: &BootedComposefs
2727
let composefs_fd = mount_composefs_image(
2828
&sysroot_fd,
2929
&booted_composefs.verity,
30-
booted_cfs.cmdline.insecure,
30+
booted_cfs.cmdline.allow_missing_fsverity,
3131
)?;
3232

3333
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;
@@ -75,7 +75,7 @@ pub(crate) async fn composefs_backend_finalize(
7575
let composefs_fd = mount_composefs_image(
7676
&sysroot_fd,
7777
&booted_composefs.verity,
78-
booted_cfs.cmdline.insecure,
78+
booted_cfs.cmdline.allow_missing_fsverity,
7979
)?;
8080

8181
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;

crates/lib/src/bootc_composefs/repo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ pub(crate) fn open_composefs_repo(rootfs_dir: &Dir) -> Result<crate::store::Comp
2323
pub(crate) async fn initialize_composefs_repository(
2424
state: &State,
2525
root_setup: &RootSetup,
26-
insecure: bool,
26+
allow_missing_fsverity: bool,
2727
) -> Result<(String, impl FsVerityHashValue)> {
2828
let rootfs_dir = &root_setup.physical_root;
2929

3030
crate::store::ensure_composefs_dir(rootfs_dir)?;
3131

3232
let mut repo = open_composefs_repo(rootfs_dir)?;
33-
repo.set_insecure(insecure);
33+
repo.set_insecure(allow_missing_fsverity);
3434

3535
let OstreeExtImgRef {
3636
name: image_name,
@@ -73,7 +73,7 @@ pub(crate) fn get_imgref(transport: &str, image: &str) -> String {
7373
pub(crate) async fn pull_composefs_repo(
7474
transport: &String,
7575
image: &String,
76-
insecure: bool,
76+
allow_missing_fsverity: bool,
7777
) -> Result<(
7878
crate::store::ComposefsRepository,
7979
Vec<ComposefsBootEntry<Sha512HashValue>>,
@@ -83,7 +83,7 @@ pub(crate) async fn pull_composefs_repo(
8383
let rootfs_dir = Dir::open_ambient_dir("/sysroot", ambient_authority())?;
8484

8585
let mut repo = open_composefs_repo(&rootfs_dir).context("Opening composefs repo")?;
86-
repo.set_insecure(insecure);
86+
repo.set_insecure(allow_missing_fsverity);
8787

8888
let final_imgref = get_imgref(transport, image);
8989

@@ -96,7 +96,7 @@ pub(crate) async fn pull_composefs_repo(
9696
tracing::info!("ID: {id}, Verity: {}", verity.to_hex());
9797

9898
let mut repo = open_composefs_repo(&rootfs_dir)?;
99-
repo.set_insecure(insecure);
99+
repo.set_insecure(allow_missing_fsverity);
100100

101101
let mut fs: crate::store::ComposefsFilesystem =
102102
create_composefs_filesystem(&repo, &id, None)

crates/lib/src/bootc_composefs/selinux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ fn get_selinux_policy_for_deployment(
7676
let (deployment_root, _mount_guard) = if *booted_cmdline.digest == *depl_id {
7777
(Dir::open_ambient_dir("/", ambient_authority())?, None)
7878
} else {
79-
let composefs_fd = mount_composefs_image(&sysroot_fd, depl_id, booted_cmdline.insecure)?;
79+
let composefs_fd =
80+
mount_composefs_image(&sysroot_fd, depl_id, booted_cmdline.allow_missing_fsverity)?;
8081
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;
8182

8283
(erofs_tmp_mnt.fd.try_clone()?, Some(erofs_tmp_mnt))

crates/lib/src/bootc_composefs/soft_reboot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(crate) async fn prepare_soft_reboot_composefs(
108108

109109
create_dir_all(NEXTROOT).context("Creating nextroot")?;
110110

111-
let cmdline = if booted_cfs.cmdline.insecure {
111+
let cmdline = if booted_cfs.cmdline.allow_missing_fsverity {
112112
Cmdline::from(format!("{COMPOSEFS_CMDLINE}=?{deployment_id}"))
113113
} else {
114114
Cmdline::from(format!("{COMPOSEFS_CMDLINE}={deployment_id}"))

crates/lib/src/bootc_composefs/state.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) fn initialize_state(
8787
erofs_id: &String,
8888
state_path: &Utf8PathBuf,
8989
initialize_var: bool,
90-
insecure: bool,
90+
allow_missing_fsverity: bool,
9191
) -> Result<()> {
9292
let sysroot_fd = open(
9393
sysroot_path.as_std_path(),
@@ -96,8 +96,11 @@ pub(crate) fn initialize_state(
9696
)
9797
.context("Opening sysroot")?;
9898

99-
let composefs_fd =
100-
bootc_initramfs_setup::mount_composefs_image(&sysroot_fd, &erofs_id, insecure)?;
99+
let composefs_fd = bootc_initramfs_setup::mount_composefs_image(
100+
&sysroot_fd,
101+
&erofs_id,
102+
allow_missing_fsverity,
103+
)?;
101104

102105
let tempdir = TempMount::mount_fd(composefs_fd)?;
103106

@@ -236,7 +239,7 @@ pub(crate) async fn write_composefs_state(
236239
boot_type: BootType,
237240
boot_digest: String,
238241
container_details: &ImgConfigManifest,
239-
insecure: bool,
242+
allow_missing_fsverity: bool,
240243
) -> Result<()> {
241244
let state_path = root_path
242245
.join(STATE_DIR_RELATIVE)
@@ -259,7 +262,7 @@ pub(crate) async fn write_composefs_state(
259262
&deployment_id.to_hex(),
260263
&state_path,
261264
staged.is_none(),
262-
insecure,
265+
allow_missing_fsverity,
263266
)?;
264267

265268
let ImageReference {

crates/lib/src/bootc_composefs/status.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) struct ImgConfigManifest {
5555
/// A parsed composefs command line
5656
#[derive(Clone)]
5757
pub(crate) struct ComposefsCmdline {
58-
pub insecure: bool,
58+
pub allow_missing_fsverity: bool,
5959
pub digest: Box<str>,
6060
}
6161

@@ -68,21 +68,25 @@ struct DeploymentBootInfo<'a> {
6868

6969
impl ComposefsCmdline {
7070
pub(crate) fn new(s: &str) -> Self {
71-
let (insecure, digest_str) = s
71+
let (allow_missing_fsverity, digest_str) = s
7272
.strip_prefix('?')
7373
.map(|v| (true, v))
7474
.unwrap_or_else(|| (false, s));
7575
ComposefsCmdline {
76-
insecure,
76+
allow_missing_fsverity,
7777
digest: digest_str.into(),
7878
}
7979
}
8080
}
8181

8282
impl std::fmt::Display for ComposefsCmdline {
8383
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84-
let insecure = if self.insecure { "?" } else { "" };
85-
write!(f, "{}={}{}", COMPOSEFS_CMDLINE, insecure, self.digest)
84+
let allow_missing_fsverity = if self.allow_missing_fsverity { "?" } else { "" };
85+
write!(
86+
f,
87+
"{}={}{}",
88+
COMPOSEFS_CMDLINE, allow_missing_fsverity, self.digest
89+
)
8690
}
8791
}
8892

@@ -808,10 +812,10 @@ mod tests {
808812
fn test_composefs_parsing() {
809813
const DIGEST: &str = "8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52";
810814
let v = ComposefsCmdline::new(DIGEST);
811-
assert!(!v.insecure);
815+
assert!(!v.allow_missing_fsverity);
812816
assert_eq!(v.digest.as_ref(), DIGEST);
813817
let v = ComposefsCmdline::new(&format!("?{}", DIGEST));
814-
assert!(v.insecure);
818+
assert!(v.allow_missing_fsverity);
815819
assert_eq!(v.digest.as_ref(), DIGEST);
816820
}
817821

crates/lib/src/bootc_composefs/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub(crate) async fn do_upgrade(
254254
let (repo, entries, id, fs) = pull_composefs_repo(
255255
&imgref.transport,
256256
&imgref.image,
257-
booted_cfs.cmdline.insecure,
257+
booted_cfs.cmdline.allow_missing_fsverity,
258258
)
259259
.await?;
260260

@@ -298,7 +298,7 @@ pub(crate) async fn do_upgrade(
298298
boot_type,
299299
boot_digest,
300300
img_manifest_config,
301-
booted_cfs.cmdline.insecure,
301+
booted_cfs.cmdline.allow_missing_fsverity,
302302
)
303303
.await?;
304304

crates/lib/src/install.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub(crate) struct InstallComposefsOpts {
390390
/// Make fs-verity validation optional in case the filesystem doesn't support it
391391
#[clap(long, default_value_t, requires = "composefs_backend")]
392392
#[serde(default)]
393-
pub(crate) insecure: bool,
393+
pub(crate) allow_missing_verity: bool,
394394

395395
/// Name of the UKI addons to install without the ".efi.addon" suffix.
396396
/// This option can be provided multiple times if multiple addons are to be installed.
@@ -1909,12 +1909,21 @@ async fn install_to_filesystem_impl(
19091909
if state.composefs_options.composefs_backend {
19101910
// Load a fd for the mounted target physical root
19111911

1912-
let (id, verity) =
1913-
initialize_composefs_repository(state, rootfs, state.composefs_options.insecure)
1914-
.await?;
1912+
let (id, verity) = initialize_composefs_repository(
1913+
state,
1914+
rootfs,
1915+
state.composefs_options.allow_missing_verity,
1916+
)
1917+
.await?;
19151918
tracing::info!("id: {id}, verity: {}", verity.to_hex());
19161919

1917-
setup_composefs_boot(rootfs, state, &id, state.composefs_options.insecure).await?;
1920+
setup_composefs_boot(
1921+
rootfs,
1922+
state,
1923+
&id,
1924+
state.composefs_options.allow_missing_verity,
1925+
)
1926+
.await?;
19181927
} else {
19191928
ostree_install(state, rootfs, cleanup).await?;
19201929
}

0 commit comments

Comments
 (0)