Skip to content

Commit

Permalink
internal/exec/*: preserve special mode bits for a given file/dir
Browse files Browse the repository at this point in the history
This allows Ignition to preserve the special mode bits for specs >=
3.4.0

Fixes: coreos#1301
  • Loading branch information
sohankunkerkar committed Mar 2, 2022
1 parent 682101e commit 46e3ce5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/exec/stages/files/filesystemEntries.go
Expand Up @@ -393,6 +393,7 @@ func (s stage) getOrderedCreationList(config types.Config) ([]filesystemEntry, e
// Map from paths in the config to where they resolve for duplicate checking
paths := map[string]string{}
for _, d := range config.Storage.Directories {
d.Mode = cutil.IntToPtr(int(util.ToFileMode(uint32(int(*d.Mode)))))
path, err := s.JoinPath(d.Path)
if err != nil {
return nil, err
Expand All @@ -407,6 +408,7 @@ func (s stage) getOrderedCreationList(config types.Config) ([]filesystemEntry, e
}

for _, f := range config.Storage.Files {
f.Mode = cutil.IntToPtr(int(util.ToFileMode(uint32(int(*f.Mode)))))
path, err := s.JoinPath(f.Path)
if err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions internal/exec/util/file.go
Expand Up @@ -169,6 +169,24 @@ func (u Util) SetPermissions(mode *int, node types.Node) error {
return nil
}

// ToFileMode converts Go permission bits to POSIX permission bits.
func ToFileMode(m uint32) os.FileMode {
mode := os.FileMode(m & 0000777)

if m&unix.S_ISGID != 0 {
mode |= os.ModeSetgid

}
if m&unix.S_ISUID != 0 {
mode |= os.ModeSetuid
}
if m&unix.S_ISVTX != 0 {
mode |= os.ModeSticky
}

return mode
}

// PerformFetch performs a fetch operation generated by PrepareFetch, retrieving
// the file and writing it to disk. Any encountered errors are returned.
func (u Util) PerformFetch(f FetchOp) error {
Expand Down

0 comments on commit 46e3ce5

Please sign in to comment.