Skip to content

Commit

Permalink
files: don't run setfiles with -i
Browse files Browse the repository at this point in the history
We shouldn't need to run `setfiles` with `-i`, which causes `setfiles`
to ignore files that do not exist. All the files which we pass to
`setfiles` should exist, and it should be a hard error if `setfiles`
fails to find and relabel the file we wrote.

This dates from coreos#632, where we
added `/var/home` and `/var/roothome` for OSTree-based systems. We
actually don't need to special-case OSTree systems at all anymore.

The `/var/home` and `/var/roothome` directories themselves are now
handled by `ignition-ostree-populate-var.service`. All we need to take
care of here is to relabel the homedir files we created for each user.
This is distro-agnostic.
  • Loading branch information
jlebon committed Jun 4, 2020
1 parent 58f67d6 commit e43af22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions internal/exec/stages/files/passwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,23 @@ func (s *stage) createPasswd(config types.Config) error {
}

s.relabel(deglobbed...)
s.relabel(
"/etc/.pwd.lock",
// for OSTree-based systems
"/var/home",
"/var/roothome",
)
s.relabel("/etc/.pwd.lock")
for _, user := range config.Passwd.Users {
if user.NoCreateHome != nil && *user.NoCreateHome == true {
continue
}
if user.Name == "root" {
rootdir_deglobbed, err := s.expandGlobList("/root/*")
if err != nil {
return err
}
s.relabel(rootdir_deglobbed...)
} else if user.HomeDir != nil && *user.HomeDir != "" {
s.relabel(filepath.Join(*user.HomeDir))
} else {
s.relabel(filepath.Join("/home", user.Name))
}
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/util/selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (ut Util) RelabelFiles(patterns []string) error {
return err
}

cmd := exec.Command(distro.SetfilesCmd(), "-vFi0", "-r", ut.DestDir, file_contexts, "-f", "-")
cmd := exec.Command(distro.SetfilesCmd(), "-vF0", "-r", ut.DestDir, file_contexts, "-f", "-")
cmd.Stdin = strings.NewReader(strings.Join(patterns, "\000") + "\000")
if _, err := ut.Logger.LogCmd(cmd, "relabeling %d patterns", len(patterns)); err != nil {
return err
Expand Down

0 comments on commit e43af22

Please sign in to comment.