Skip to content

Commit 0b2199c

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs: Handle fs-verity disabled insall/updates
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 32643e8 commit 0b2199c

10 files changed

Lines changed: 72 additions & 25 deletions

File tree

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ use schemars::JsonSchema;
9494
use serde::{Deserialize, Serialize};
9595

9696
use crate::parsers::bls_config::{BLSConfig, BLSConfigType};
97-
use crate::parsers::grub_menuconfig::MenuEntry;
9897
use crate::task::Task;
9998
use crate::{
10099
bootc_composefs::repo::get_imgref,
@@ -119,6 +118,7 @@ use crate::{
119118
},
120119
spec::{Bootloader, Host},
121120
};
121+
use crate::{parsers::grub_menuconfig::MenuEntry, store::BootedComposefs};
122122

123123
use crate::install::{RootSetup, State};
124124

@@ -155,7 +155,14 @@ pub(crate) enum BootSetupType<'a> {
155155
),
156156
),
157157
/// For `bootc upgrade`
158-
Upgrade((&'a Storage, &'a ComposefsFilesystem, &'a Host)),
158+
Upgrade(
159+
(
160+
&'a Storage,
161+
&'a BootedComposefs,
162+
&'a ComposefsFilesystem,
163+
&'a Host,
164+
),
165+
),
159166
}
160167

161168
#[derive(
@@ -532,7 +539,7 @@ pub(crate) fn setup_composefs_bls_boot(
532539
)
533540
}
534541

535-
BootSetupType::Upgrade((storage, fs, host)) => {
542+
BootSetupType::Upgrade((storage, booted_cfs, fs, host)) => {
536543
let sysroot_parent = get_sysroot_parent_dev(&storage.physical_root)?;
537544
let bootloader = host.require_composefs_booted()?.bootloader.clone();
538545

@@ -551,7 +558,12 @@ pub(crate) fn setup_composefs_bls_boot(
551558
};
552559

553560
// Copy all cmdline args, replacing only `composefs=`
554-
let param = format!("{COMPOSEFS_CMDLINE}={id_hex}");
561+
let param = if booted_cfs.cmdline.insecure {
562+
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
563+
} else {
564+
format!("{COMPOSEFS_CMDLINE}={id_hex}")
565+
};
566+
555567
let param =
556568
Parameter::parse(&param).context("Failed to create 'composefs=' parameter")?;
557569
cmdline.add_or_modify(&param);
@@ -1083,7 +1095,7 @@ pub(crate) fn setup_composefs_uki_boot(
10831095
)
10841096
}
10851097

1086-
BootSetupType::Upgrade((storage, _, host)) => {
1098+
BootSetupType::Upgrade((storage, booted_cfs, _, host)) => {
10871099
let sysroot = Utf8PathBuf::from("/sysroot"); // Still needed for root_path
10881100
let sysroot_parent = get_sysroot_parent_dev(&storage.physical_root)?;
10891101
let bootloader = host.require_composefs_booted()?.bootloader.clone();
@@ -1092,7 +1104,7 @@ pub(crate) fn setup_composefs_uki_boot(
10921104
sysroot,
10931105
get_esp_partition(&sysroot_parent)?.0,
10941106
bootloader,
1095-
false,
1107+
booted_cfs.cmdline.insecure,
10961108
None,
10971109
)
10981110
}
@@ -1224,8 +1236,11 @@ pub(crate) async fn setup_composefs_boot(
12241236
root_setup: &RootSetup,
12251237
state: &State,
12261238
image_id: &str,
1239+
insecure: bool,
12271240
) -> Result<()> {
1228-
let repo = open_composefs_repo(&root_setup.physical_root)?;
1241+
let mut repo = open_composefs_repo(&root_setup.physical_root)?;
1242+
repo.set_insecure(insecure);
1243+
12291244
let mut fs = create_composefs_filesystem(&repo, image_id, None)?;
12301245
let entries = fs.transform_for_boot(&repo)?;
12311246
let id = fs.commit_image(&repo, None)?;
@@ -1296,6 +1311,7 @@ pub(crate) async fn setup_composefs_boot(
12961311
&state.source.imageref.name,
12971312
))
12981313
.await?,
1314+
insecure,
12991315
)
13001316
.await?;
13011317

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ pub(crate) async fn get_etc_diff(storage: &Storage, booted_cfs: &BootedComposefs
2424

2525
// Mount the booted EROFS image to get pristine etc
2626
let sysroot_fd = storage.physical_root.reopen_as_ownedfd()?;
27-
let composefs_fd = mount_composefs_image(&sysroot_fd, &booted_composefs.verity, false)?;
27+
let composefs_fd = mount_composefs_image(
28+
&sysroot_fd,
29+
&booted_composefs.verity,
30+
booted_cfs.cmdline.insecure,
31+
)?;
2832

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

@@ -68,7 +72,11 @@ pub(crate) async fn composefs_backend_finalize(
6872

6973
// Mount the booted EROFS image to get pristine etc
7074
let sysroot_fd = storage.physical_root.reopen_as_ownedfd()?;
71-
let composefs_fd = mount_composefs_image(&sysroot_fd, &booted_composefs.verity, false)?;
75+
let composefs_fd = mount_composefs_image(
76+
&sysroot_fd,
77+
&booted_composefs.verity,
78+
booted_cfs.cmdline.insecure,
79+
)?;
7280

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

crates/lib/src/bootc_composefs/repo.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +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,
2627
) -> Result<(String, impl FsVerityHashValue)> {
2728
let rootfs_dir = &root_setup.physical_root;
2829

2930
crate::store::ensure_composefs_dir(rootfs_dir)?;
3031

31-
let repo = open_composefs_repo(rootfs_dir)?;
32+
let mut repo = open_composefs_repo(rootfs_dir)?;
33+
repo.set_insecure(insecure);
3234

3335
let OstreeExtImgRef {
3436
name: image_name,
@@ -71,6 +73,7 @@ pub(crate) fn get_imgref(transport: &str, image: &str) -> String {
7173
pub(crate) async fn pull_composefs_repo(
7274
transport: &String,
7375
image: &String,
76+
insecure: bool,
7477
) -> Result<(
7578
crate::store::ComposefsRepository,
7679
Vec<ComposefsBootEntry<Sha512HashValue>>,
@@ -79,7 +82,8 @@ pub(crate) async fn pull_composefs_repo(
7982
)> {
8083
let rootfs_dir = Dir::open_ambient_dir("/sysroot", ambient_authority())?;
8184

82-
let repo = open_composefs_repo(&rootfs_dir).context("Opening composefs repo")?;
85+
let mut repo = open_composefs_repo(&rootfs_dir).context("Opening composefs repo")?;
86+
repo.set_insecure(insecure);
8387

8488
let final_imgref = get_imgref(transport, image);
8589

@@ -91,7 +95,9 @@ pub(crate) async fn pull_composefs_repo(
9195

9296
tracing::info!("ID: {id}, Verity: {}", verity.to_hex());
9397

94-
let repo = open_composefs_repo(&rootfs_dir)?;
98+
let mut repo = open_composefs_repo(&rootfs_dir)?;
99+
repo.set_insecure(insecure);
100+
95101
let mut fs: crate::store::ComposefsFilesystem =
96102
create_composefs_filesystem(&repo, &id, None)
97103
.context("Failed to create composefs filesystem")?;

crates/lib/src/bootc_composefs/selinux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ 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, false)?;
79+
let composefs_fd = mount_composefs_image(&sysroot_fd, depl_id, booted_cmdline.insecure)?;
8080
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;
8181

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

crates/lib/src/bootc_composefs/soft_reboot.rs

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

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

111-
let cmdline = Cmdline::from(format!("{COMPOSEFS_CMDLINE}={deployment_id}"));
111+
let cmdline = if booted_cfs.cmdline.insecure {
112+
Cmdline::from(format!("{COMPOSEFS_CMDLINE}=?{deployment_id}"))
113+
} else {
114+
Cmdline::from(format!("{COMPOSEFS_CMDLINE}={deployment_id}"))
115+
};
112116

113117
let args = bootc_initramfs_setup::Args {
114118
cmd: vec![],

crates/lib/src/bootc_composefs/state.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub(crate) fn initialize_state(
8787
erofs_id: &String,
8888
state_path: &Utf8PathBuf,
8989
initialize_var: bool,
90+
insecure: bool,
9091
) -> Result<()> {
9192
let sysroot_fd = open(
9293
sysroot_path.as_std_path(),
@@ -95,7 +96,8 @@ pub(crate) fn initialize_state(
9596
)
9697
.context("Opening sysroot")?;
9798

98-
let composefs_fd = bootc_initramfs_setup::mount_composefs_image(&sysroot_fd, &erofs_id, false)?;
99+
let composefs_fd =
100+
bootc_initramfs_setup::mount_composefs_image(&sysroot_fd, &erofs_id, insecure)?;
99101

100102
let tempdir = TempMount::mount_fd(composefs_fd)?;
101103

@@ -234,6 +236,7 @@ pub(crate) async fn write_composefs_state(
234236
boot_type: BootType,
235237
boot_digest: String,
236238
container_details: &ImgConfigManifest,
239+
insecure: bool,
237240
) -> Result<()> {
238241
let state_path = root_path
239242
.join(STATE_DIR_RELATIVE)
@@ -256,6 +259,7 @@ pub(crate) async fn write_composefs_state(
256259
&deployment_id.to_hex(),
257260
&state_path,
258261
staged.is_none(),
262+
insecure,
259263
)?;
260264

261265
let ImageReference {

crates/lib/src/bootc_composefs/status.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub(crate) struct ImgConfigManifest {
5555
/// A parsed composefs command line
5656
#[derive(Clone)]
5757
pub(crate) struct ComposefsCmdline {
58-
#[allow(dead_code)]
5958
pub insecure: bool,
6059
pub digest: Box<str>,
6160
}

crates/lib/src/bootc_composefs/update.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ pub(crate) async fn do_upgrade(
251251
) -> Result<()> {
252252
start_finalize_stated_svc()?;
253253

254-
let (repo, entries, id, fs) = pull_composefs_repo(&imgref.transport, &imgref.image).await?;
254+
let (repo, entries, id, fs) = pull_composefs_repo(
255+
&imgref.transport,
256+
&imgref.image,
257+
booted_cfs.cmdline.insecure,
258+
)
259+
.await?;
255260

256261
let Some(entry) = entries.iter().next() else {
257262
anyhow::bail!("No boot entries!");
@@ -267,15 +272,15 @@ pub(crate) async fn do_upgrade(
267272

268273
let boot_digest = match boot_type {
269274
BootType::Bls => setup_composefs_bls_boot(
270-
BootSetupType::Upgrade((storage, &fs, &host)),
275+
BootSetupType::Upgrade((storage, booted_cfs, &fs, &host)),
271276
repo,
272277
&id,
273278
entry,
274279
&mounted_fs,
275280
)?,
276281

277282
BootType::Uki => setup_composefs_uki_boot(
278-
BootSetupType::Upgrade((storage, &fs, &host)),
283+
BootSetupType::Upgrade((storage, booted_cfs, &fs, &host)),
279284
repo,
280285
&id,
281286
entries,
@@ -293,6 +298,7 @@ pub(crate) async fn do_upgrade(
293298
boot_type,
294299
boot_digest,
295300
img_manifest_config,
301+
booted_cfs.cmdline.insecure,
296302
)
297303
.await?;
298304

crates/lib/src/install.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,12 @@ 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) = initialize_composefs_repository(state, rootfs).await?;
1912+
let (id, verity) =
1913+
initialize_composefs_repository(state, rootfs, state.composefs_options.insecure)
1914+
.await?;
19131915
tracing::info!("id: {id}, verity: {}", verity.to_hex());
19141916

1915-
setup_composefs_boot(rootfs, state, &id).await?;
1917+
setup_composefs_boot(rootfs, state, &id, state.composefs_options.insecure).await?;
19161918
} else {
19171919
ostree_install(state, rootfs, cleanup).await?;
19181920
}

crates/lib/src/parsers/bls_config.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::collections::HashMap;
1313
use std::fmt::Display;
1414
use uapi_version::Version;
1515

16+
use crate::bootc_composefs::status::ComposefsCmdline;
1617
use crate::composefs_consts::COMPOSEFS_CMDLINE;
1718

1819
#[derive(Debug, PartialEq, Eq, Default)]
@@ -189,15 +190,16 @@ impl BLSConfig {
189190

190191
let kv = cmdline
191192
.find(COMPOSEFS_CMDLINE)
192-
.ok_or(anyhow::anyhow!("No composefs= param"))?;
193+
.ok_or_else(|| anyhow::anyhow!("No composefs= param"))?;
193194

194195
let value = kv
195196
.value()
196-
.ok_or(anyhow::anyhow!("Empty composefs= param"))?;
197+
.ok_or_else(|| anyhow::anyhow!("Empty composefs= param"))?;
197198

198-
let value = value.to_owned();
199+
let cfs_cmdline = ComposefsCmdline::new(value);
199200

200-
Ok(value)
201+
// TODO(Johan-Liebert1): We lose the info here that this is insecure
202+
Ok(cfs_cmdline.digest.to_string().clone())
201203
}
202204

203205
BLSConfigType::Unknown => anyhow::bail!("Unknown config type"),

0 commit comments

Comments
 (0)