Skip to content

Commit

Permalink
Fix downloaded artifact permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJosh9000 committed Jul 22, 2024
1 parent ff1bdc3 commit d226261
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions agent/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (
headerUserAgent = "User-Agent"
)

// Real umask set by init func in download_unix.go. 0o022 is a common default.
var umask = os.FileMode(0o022)

type DownloadConfig struct {
// The actual URL to get the file from
URL string
Expand Down Expand Up @@ -184,6 +187,13 @@ func (d Download) try(ctx context.Context) error {
return fmt.Errorf("copying data to temp file (%T: %w)", err, err)
}

// os.CreateTemp uses 0o600 permissions, but in the past we used os.Create
// which uses 0x666. Since these are set at open time, they are restricted
// by umask.
if err := temp.Chmod(0o666 &^ umask); err != nil {
return fmt.Errorf("setting file permissions (%T: %w)", err, err)
}

// close must succeed for the file to be considered properly written.
if err := temp.Close(); err != nil {
return fmt.Errorf("closing temp file (%T: %w)", err, err)
Expand Down
15 changes: 15 additions & 0 deletions agent/download_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build unix

package agent

import (
"os"

"golang.org/x/sys/unix"
)

func init() {
// Can't read the current umask(2) without changing it.
umask = os.FileMode(unix.Umask(int(umask)))
unix.Umask(int(umask))
}

0 comments on commit d226261

Please sign in to comment.