From 6e46d9af5361921f7de360fae7ca52d64563f827 Mon Sep 17 00:00:00 2001 From: Adam0Brien Date: Tue, 11 Apr 2023 14:20:50 +0100 Subject: [PATCH] exec: Change MountFS to only relabel dirs that didnt exist This PR introduces a new change to how ignition mounts filesystems, Now when file systems are being mounted ignition will relabel directories if they did not exist previously. Whereas before file systems could be relabelled if they did/didnt exist previously Fix #1452 --- docs/release-notes.md | 1 + internal/exec/stages/mount/mount.go | 20 ++++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 501cda2430..46f0220212 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -26,6 +26,7 @@ Starting with this release, ignition-validate binaries are signed with the - Clarify documentation of `passwordHash` fields - Correctly document Tang `advertisement` field as optional - Fix failure disabling nonexistent unit with systemd ≥ 252 +- Don't relabel a mount point that already exists ### Test changes diff --git a/internal/exec/stages/mount/mount.go b/internal/exec/stages/mount/mount.go index fd59e80a58..8898bcf007 100644 --- a/internal/exec/stages/mount/mount.go +++ b/internal/exec/stages/mount/mount.go @@ -123,29 +123,25 @@ func (s stage) mountFs(fs types.Filesystem) error { return err } - var firstMissing string - if distro.SelinuxRelabel() { - var err error - firstMissing, err = util.FindFirstMissingPathComponent(path) + if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { + firstMissing, err := util.FindFirstMissingPathComponent(path) if err != nil { return err } - } - if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { // Record created directories for use by the files stage. // NotateMkdirAll() is relative to the DestDir. if err := s.NotateMkdirAll(relpath, 0755); err != nil { return err } - } else if err != nil { - return err - } - if distro.SelinuxRelabel() { - if err := s.RelabelFiles([]string{firstMissing}); err != nil { - return err + if distro.SelinuxRelabel() { + if err := s.RelabelFiles([]string{firstMissing}); err != nil { + return err + } } + } else if err != nil { + return err } args := translateOptionSliceToString(fs.MountOptions, ",")