Skip to content

Commit b50ffc4

Browse files
authored
Merge pull request #961 from HuijingHei/fix-grub-permission
grubconfig: set `/boot/grub2/grub.cfg` file mode to `0600`
2 parents 26a039a + e944eef commit b50ffc4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ jobs:
8686
fi
8787
sudo ls /mnt/EFI/centos/{grub.cfg,${shim}}
8888
sudo umount /mnt
89+
# check /boot/grub2/grub.cfg permission
90+
root_part=$(sudo sfdisk -l -J "${device}" | jq -r '.partitiontable.partitions[] | select(.name == "root").node')
91+
sudo mount "${root_part}" /mnt/
92+
sudo ls /mnt/boot/grub2/grub.cfg
93+
[ $(sudo stat -c "%a" /mnt/boot/grub2/grub.cfg) == "600" ]
94+
sudo umount /mnt
8995
sudo losetup -D "${device}"
9096
sudo rm -f myimage.raw
9197
@@ -99,3 +105,4 @@ jobs:
99105
--disable-selinux --replace=alongside /target
100106
# Verify we injected static configs
101107
jq -re '.["static-configs"].version' /boot/bootupd-state.json
108+
[ $(sudo stat -c "%a" /boot/grub2/grub.cfg) == "600" ]

src/grubconfigs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const DROPINDIR: &str = "configs.d";
1717
const GRUBENV: &str = "grubenv";
1818
pub(crate) const GRUBCONFIG: &str = "grub.cfg";
1919
pub(crate) const GRUBCONFIG_BACKUP: &str = "grub.cfg.backup";
20+
// File mode for /boot/grub2/grub.config
21+
// https://github.com/coreos/bootupd/issues/952
22+
const GRUBCONFIG_FILE_MODE: u32 = 0o600;
2023

2124
/// Install the static GRUB config files.
2225
#[context("Installing static GRUB configs")]
@@ -67,7 +70,7 @@ pub(crate) fn install(
6770

6871
let grub2dir = bootdir.sub_dir(GRUB2DIR)?;
6972
grub2dir
70-
.write_file_contents("grub.cfg", 0o644, config.as_bytes())
73+
.write_file_contents("grub.cfg", GRUBCONFIG_FILE_MODE, config.as_bytes())
7174
.context("Copying grub-static.cfg")?;
7275
println!("Installed: grub.cfg");
7376

0 commit comments

Comments
 (0)