-
Notifications
You must be signed in to change notification settings - Fork 204
Filter out BLS entries not managed by bootc #2243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,7 @@ use crate::{ | |
| }, | ||
| }, | ||
| composefs_consts::{ | ||
| ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX, | ||
| TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED, | ||
| BLS_ENTRY_PREFIX, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX, TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED | ||
| }, | ||
| parsers::bls_config::{BLSConfig, BLSConfigType}, | ||
| spec::Bootloader, | ||
|
|
@@ -240,6 +239,15 @@ fn create_staged_bls_entries(boot_dir: &Dir, entries: &Vec<(String, BLSConfig)>) | |
| staged_entries.atomic_write(filename, new_entry.to_string().as_bytes())?; | ||
| } | ||
|
|
||
| let original_entries = boot_dir.open_dir(TYPE1_ENT_PATH)?; | ||
| for entry in original_entries.entries()? { | ||
| let entry = entry?; | ||
| let entry_name = entry.file_name(); | ||
| if entry.file_type()?.is_file() && !entry_name.to_string_lossy().starts_with(BLS_ENTRY_PREFIX) { | ||
| original_entries.copy(entry.file_name(), &staged_entries, entry_name)?; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error context would be nice here |
||
| } | ||
| } | ||
|
|
||
| fsync(staged_entries.reopen_as_ownedfd()?).context("fsync") | ||
| } | ||
|
|
||
|
|
@@ -394,3 +402,58 @@ pub(crate) async fn prepend_custom_prefix( | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use anyhow::Result; | ||
| use cap_std_ext::{cap_std, dirext::CapStdExtDirExt}; | ||
| use crate::bootc_composefs::backwards_compat::bcompat_boot::*; | ||
| use crate::parsers::bls_config::parse_bls_config; | ||
|
|
||
| #[test] | ||
| fn test_create_staged_bls_entries() -> Result<()> { | ||
| let tempdir = cap_std_ext::cap_tempfile::tempdir(cap_std::ambient_authority())?; | ||
|
|
||
| let entry1 = r#" | ||
| title Fedora 42.20250623.3.1 (CoreOS) | ||
| version fedora-42.0 | ||
| sort-key 1 | ||
| linux /boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/vmlinuz-5.14.10 | ||
| initrd /boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/initramfs-5.14.10.img | ||
| options root=UUID=abc123 rw composefs=7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6 | ||
| "#; | ||
| let entry2 = r#" | ||
| title Fedora 41.20250214.2.0 (CoreOS) | ||
| version fedora-42.0 | ||
| sort-key 2 | ||
| efi /EFI/Linux/f7415d75017a12a387a39d2281e033a288fc15775108250ef70a01dcadb93346.efi | ||
| options root=UUID=abc123 rw composefs=febdf62805de2ae7b6b597f2a9775d9c8a753ba1e5f09298fc8fbe0b0d13bf01 | ||
| "#; | ||
| let entry3 = r#" | ||
| title Test | ||
| version 1 | ||
| sort-key 9 | ||
| efi /EFI/boot/test.efi | ||
| "#; | ||
|
|
||
| tempdir.create_dir_all("loader/entries")?; | ||
| tempdir.atomic_write("loader/entries/bootc_entry1.conf", entry1)?; | ||
| tempdir.atomic_write("loader/entries/bootc_entry2.conf", entry2)?; | ||
| tempdir.atomic_write("loader/entries/entry3.conf", entry3)?; | ||
|
|
||
| let entries = vec![ | ||
| ("bootc_entry1.conf".to_string(), parse_bls_config(entry1).unwrap()), | ||
| ("bootc_entry2.conf".to_string(), parse_bls_config(entry2).unwrap()), | ||
| ]; | ||
|
|
||
| create_staged_bls_entries(&tempdir, &entries).unwrap(); | ||
|
|
||
| assert!(tempdir.exists("loader/entries.staged/bootc_entry1.conf")); | ||
| assert!(tempdir.exists("loader/entries.staged/bootc_entry2.conf")); | ||
| assert!(tempdir.exists("loader/entries.staged/entry3.conf")); | ||
|
|
||
| assert_eq!(str::from_utf8(&tempdir.read("loader/entries.staged/entry3.conf")?[..])?, entry3); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,9 @@ pub(crate) const TYPE1_BOOT_DIR_PREFIX: &str = "bootc_composefs-"; | |
| /// The prefix for names of UKI and UKI Addons | ||
| pub(crate) const UKI_NAME_PREFIX: &str = TYPE1_BOOT_DIR_PREFIX; | ||
|
|
||
| /// The prefix for BLS file entries | ||
| pub(crate) const BLS_ENTRY_PREFIX: &str = "bootc_"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to change that from
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this anymore? |
||
|
|
||
| /// Prefix for OCI tags owned by bootc in the composefs repository. | ||
| /// | ||
| /// Tags are created as `localhost/bootc-<manifest_digest>` to act as GC roots | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
entries_utf8to avoidto_string_lossybelow