Skip to content

Commit

Permalink
stages/files: filter out non-existent paths before relabeling
Browse files Browse the repository at this point in the history
The code that handles systemd unit enablement via preset will no op if
disabling a systemd unit that is already disabled, which means that we
wouldn't create a preset file in that case. But we did mark the preset
file as needing relabeling unconditionally. Since `setfiles` errors out
if you pass it a path that doesn't exist, this would break boot.

Fix this by filtering out all entries that don't exist right before we
call `setfiles`. Another approach would've been to only mark the file
for relabeling if we actually did write the file, but this is more
complex than it seems because the relabeling logic needs to know what
is the first component in the path that had to be created. So we'd need
logic both before and after file creation.

This isn't user-reported; we hit this in a CI test.
  • Loading branch information
jlebon committed Jan 16, 2024
1 parent d525610 commit 162d1a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ nav_order: 9

### Features



### Changes

- Require Go 1.20+

### Bug fixes

- Fix failure when config only disables units already disabled


## Ignition 2.17.0 (2023-11-20)

Starting with this release, ignition-validate binaries are signed with the
Expand Down
14 changes: 13 additions & 1 deletion internal/exec/stages/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package files
import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/coreos/ignition/v2/config/v3_5_experimental/types"
Expand Down Expand Up @@ -170,7 +171,18 @@ func (s *stage) relabelFiles() error {

keys := make([]string, 0, len(s.toRelabel))
for key := range s.toRelabel {
keys = append(keys, key)
// Filter out non-existent entries; some of the code that mark files for
// relabeling may not actually end up creating those files in the end.
if _, err := os.Stat(key); err == nil {
keys = append(keys, key)
} else if !errors.Is(err, os.ErrNotExist) {
return err
}
}

if len(keys) == 0 {
return nil
}

return s.RelabelFiles(keys)
}

0 comments on commit 162d1a6

Please sign in to comment.