Skip to content

Commit 253854b

Browse files
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 9801dd1 commit 253854b

11 files changed

Lines changed: 70 additions & 46 deletions

File tree

crates/initramfs/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,13 @@ fn open_root_fs(path: &Path) -> Result<OwnedFd> {
262262
/// * name - Name of the EROFS image to be mounted
263263
/// * insecure - Whether fsverity is optional or not
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}")
@@ -809,7 +809,7 @@ fn write_pe_to_esp(
809809
file_path: &Utf8Path,
810810
pe_type: PEType,
811811
uki_id: &Sha512HashValue,
812-
is_insecure_from_opts: bool,
812+
missing_fsverity_allowed: bool,
813813
mounted_efi: impl AsRef<Path>,
814814
bootloader: &Bootloader,
815815
) -> Result<Option<UKIInfo>> {
@@ -822,17 +822,19 @@ fn write_pe_to_esp(
822822
if matches!(pe_type, PEType::Uki) {
823823
let cmdline = uki::get_cmdline(&efi_bin).context("Getting UKI cmdline")?;
824824

825-
let (composefs_cmdline, insecure) =
825+
let (composefs_cmdline, missing_verity_allowed_cmdline) =
826826
get_cmdline_composefs::<Sha512HashValue>(cmdline).context("Parsing composefs=")?;
827827

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

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

@@ -1077,7 +1079,8 @@ pub(crate) fn setup_composefs_uki_boot(
10771079
id: &Sha512HashValue,
10781080
entries: Vec<ComposefsBootEntry<Sha512HashValue>>,
10791081
) -> Result<String> {
1080-
let (root_path, esp_device, bootloader, is_insecure_from_opts, uki_addons) = match setup_type {
1082+
let (root_path, esp_device, bootloader, missing_fsverity_allowed, uki_addons) = match setup_type
1083+
{
10811084
BootSetupType::Setup((root_setup, state, postfetch, ..)) => {
10821085
state.require_no_kargs_for_uki()?;
10831086

@@ -1087,7 +1090,7 @@ pub(crate) fn setup_composefs_uki_boot(
10871090
root_setup.physical_root_path.clone(),
10881091
esp_part.node.clone(),
10891092
postfetch.detected_bootloader.clone(),
1090-
state.composefs_options.insecure,
1093+
state.composefs_options.allow_missing_verity,
10911094
state.composefs_options.uki_addon.as_ref(),
10921095
)
10931096
}
@@ -1101,7 +1104,7 @@ pub(crate) fn setup_composefs_uki_boot(
11011104
sysroot,
11021105
get_esp_partition(&sysroot_parent)?.0,
11031106
bootloader,
1104-
booted_cfs.cmdline.insecure,
1107+
booted_cfs.cmdline.allow_missing_fsverity,
11051108
None,
11061109
)
11071110
}
@@ -1152,7 +1155,7 @@ pub(crate) fn setup_composefs_uki_boot(
11521155
utf8_file_path,
11531156
entry.pe_type,
11541157
&id,
1155-
is_insecure_from_opts,
1158+
missing_fsverity_allowed,
11561159
esp_mount.dir.path(),
11571160
&bootloader,
11581161
)?;
@@ -1231,10 +1234,10 @@ pub(crate) async fn setup_composefs_boot(
12311234
root_setup: &RootSetup,
12321235
state: &State,
12331236
image_id: &str,
1234-
insecure: bool,
1237+
allow_missing_fsverity: bool,
12351238
) -> Result<()> {
12361239
let mut repo = open_composefs_repo(&root_setup.physical_root)?;
1237-
repo.set_insecure(insecure);
1240+
repo.set_insecure(allow_missing_fsverity);
12381241

12391242
let mut fs = create_composefs_filesystem(&repo, image_id, None)?;
12401243
let entries = fs.transform_for_boot(&repo)?;
@@ -1306,7 +1309,7 @@ pub(crate) async fn setup_composefs_boot(
13061309
&state.source.imageref.name,
13071310
))
13081311
.await?,
1309-
insecure,
1312+
allow_missing_fsverity,
13101313
)
13111314
.await?;
13121315

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,7 +23,7 @@ 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

@@ -32,7 +32,7 @@ pub(crate) async fn initialize_composefs_repository(
3232
.context("Creating dir composefs")?;
3333

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

3737
let OstreeExtImgRef {
3838
name: image_name,
@@ -75,7 +75,7 @@ pub(crate) fn get_imgref(transport: &str, image: &str) -> String {
7575
pub(crate) async fn pull_composefs_repo(
7676
transport: &String,
7777
image: &String,
78-
insecure: bool,
78+
allow_missing_fsverity: bool,
7979
) -> Result<(
8080
crate::store::ComposefsRepository,
8181
Vec<ComposefsBootEntry<Sha512HashValue>>,
@@ -85,7 +85,7 @@ pub(crate) async fn pull_composefs_repo(
8585
let rootfs_dir = Dir::open_ambient_dir("/sysroot", ambient_authority())?;
8686

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

9090
let final_imgref = get_imgref(transport, image);
9191

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

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

103103
let mut fs: crate::store::ComposefsFilesystem =
104104
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

@@ -806,10 +810,10 @@ mod tests {
806810
fn test_composefs_parsing() {
807811
const DIGEST: &str = "8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52";
808812
let v = ComposefsCmdline::new(DIGEST);
809-
assert!(!v.insecure);
813+
assert!(!v.allow_missing_fsverity);
810814
assert_eq!(v.digest.as_ref(), DIGEST);
811815
let v = ComposefsCmdline::new(&format!("?{}", DIGEST));
812-
assert!(v.insecure);
816+
assert!(v.allow_missing_fsverity);
813817
assert_eq!(v.digest.as_ref(), DIGEST);
814818
}
815819

crates/lib/src/bootc_composefs/update.rs

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

@@ -296,7 +296,7 @@ pub(crate) async fn do_upgrade(
296296
boot_type,
297297
boot_digest,
298298
img_manifest_config,
299-
booted_cfs.cmdline.insecure,
299+
booted_cfs.cmdline.allow_missing_fsverity,
300300
)
301301
.await?;
302302

crates/lib/src/install.rs

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

390390
/// The bootloader to use.
391391
#[clap(long, requires = "composefs_backend")]
@@ -1887,12 +1887,21 @@ async fn install_to_filesystem_impl(
18871887
if state.composefs_options.composefs_backend {
18881888
// Load a fd for the mounted target physical root
18891889

1890-
let (id, verity) =
1891-
initialize_composefs_repository(state, rootfs, state.composefs_options.insecure)
1892-
.await?;
1890+
let (id, verity) = initialize_composefs_repository(
1891+
state,
1892+
rootfs,
1893+
state.composefs_options.allow_missing_verity,
1894+
)
1895+
.await?;
18931896
tracing::info!("id: {id}, verity: {}", verity.to_hex());
18941897

1895-
setup_composefs_boot(rootfs, state, &id, state.composefs_options.insecure).await?;
1898+
setup_composefs_boot(
1899+
rootfs,
1900+
state,
1901+
&id,
1902+
state.composefs_options.allow_missing_verity,
1903+
)
1904+
.await?;
18961905
} else {
18971906
ostree_install(state, rootfs, cleanup).await?;
18981907
}

0 commit comments

Comments
 (0)