Skip to content

Commit 0c9be91

Browse files
committed
feat: add SELinux autorelabel trigger for RHEL-family distros
Create /.autorelabel during image build so the first boot triggers a full filesystem relabel. This is required because SELinux contexts from the Docker build don't match the policy loaded at boot time.
1 parent c02fa47 commit 0c9be91

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

grub_common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ func (g *grubCommon) prepare(ctx context.Context, dev, root, cmdline string) (cl
6767
return
6868
}
6969

70+
// Trigger SELinux relabel on first boot for RHEL-family distros.
71+
// The filesystem contexts from the Docker build don't match the
72+
// policy loaded at boot, so a relabel is required.
73+
if isRhelFamily(g.r.ID) {
74+
if err = os.WriteFile(filepath.Join(root, ".autorelabel"), []byte{}, perm); err != nil {
75+
return
76+
}
77+
}
78+
7079
if err = os.MkdirAll(filepath.Join(root, "boot", g.name), os.ModePerm); err != nil {
7180
return
7281
}

0 commit comments

Comments
 (0)