Skip to content

Commit

Permalink
Merge pull request coreos#1343 from jlebon/pr/prefix-ssh-keys-write
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebon authored Apr 20, 2022
2 parents 56eccf5 + 78538da commit 9297e87
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/exec/util/passwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,19 @@ func translateV2_1PasswdUserGroupSliceToStringSlice(groups []types.Group) []stri
// creating any directories in fp as needed.
func writeAuthKeysFile(u *user.User, fp string, keys []byte) error {
if err := as_user.MkdirAll(u, filepath.Dir(fp), 0700); err != nil {
return err
return fmt.Errorf("creating parent dirs for %q: %w", fp, err)
}

f, err := as_user.OpenFile(u, fp, unix.O_WRONLY|unix.O_CREAT|unix.O_TRUNC, 0600)
if err != nil {
return err
return fmt.Errorf("opening file %q as user %s and group %s: %w", fp, u.Uid, u.Gid, err)
}
if _, err = f.Write(keys); err != nil {
return err
f.Close() // ignore errors
return fmt.Errorf("writing file %q: %w", fp, err)
}
if err := f.Close(); err != nil {
return err
return fmt.Errorf("closing file %q: %w", fp, err)
}
return nil
}
Expand Down

0 comments on commit 9297e87

Please sign in to comment.