Skip to content

Commit 72fd1c4

Browse files
committed
Security: ignore file ownership when extracting Go
Certain Go tarballs specified that some files, such as the `go` binary, were supposed to be owned by a non-root user. When running as root, dp-golang extracted those files and preserved ownership, which lead to those files being writable by a non-root user. At the very least, this affected Go tarballs on macOS before 1.21. This switches to extracting the tarballs with `tar`’s `--no-same-owner` and `--no-same-permissions` flags.
1 parent 9581912 commit 72fd1c4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
44

55
## main branch
66

7+
### Security fix
8+
9+
Certain Go tarballs, e.g. version 1.20.14 for macOS/Darwin, had files owned by
10+
non-root users:
11+
12+
❯ curl -SsL https://go.dev/dl/go1.20.14.darwin-amd64.tar.gz | tar -tzvf - | head -3
13+
drwxr-xr-x 0 0 0 0 Feb 2 10:19 go/
14+
-rw-r--r-- 0 gopher wheel 1339 Feb 2 10:09 go/CONTRIBUTING.md
15+
-rw-r--r-- 0 gopher wheel 1479 Feb 2 10:09 go/LICENSE
16+
17+
In this case, the non-root user in question mapped to the first user created on
18+
the macOS system (UID 501).
19+
20+
When running as root, previous versions of dp-golang would preserve file
21+
ownership when extracting the tarball, even if `owner` was set to something
22+
else. **This meant that files, such as the `go` binary, ended up being writable
23+
by a non-root user.**
24+
25+
This version of dp-golang enables [`tar`]’s `--no-same-owner` and
26+
`--no-same-permissions` flags, which cause files to be extracted as the user
27+
running Puppet, or as the user/group specified in the Puppet code.
28+
29+
**This will not fix existing installs** unless you update the Go version, or
30+
otherwise prompt Puppet to reinstall.
31+
32+
[`tar`]: https://www.man7.org/linux/man-pages/man1/tar.1.html
33+
734
## Release 1.2.6
835

936
* Synced with [PDK][].

manifests/from_tarball.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
ensure => present,
110110
extract => true,
111111
extract_path => $go_dir,
112-
extract_flags => '--strip-components 1 -xf',
112+
extract_flags => '--strip-components 1 --no-same-owner --no-same-permissions -xf',
113113
user => $owner,
114114
group => $group,
115115
source => $source,

0 commit comments

Comments
 (0)