Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Allow complex file modes for debs and apks. #395

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ func copyToTarAndDigest(file *files.Content, tw *tar.Writer, sizep *int64) error
return err
}

// tar.FileInfoHeader only uses file.Mode().Perm() which masks the mode with
// 0o777 which we don't want because we want to be able to set the suid bit.
header.Mode = int64(file.Mode())
header.Name = files.ToNixPath(file.Destination[1:])
header.Uname = file.FileInfo.Owner
header.Gname = file.FileInfo.Group
Expand Down
4 changes: 4 additions & 0 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ func copyToTarAndDigest(file *files.Content, tw *tar.Writer, md5w io.Writer) (in
log.Print(err)
return 0, err
}

// tar.FileInfoHeader only uses file.Mode().Perm() which masks the mode with
// 0o777 which we don't want because we want to be able to set the suid bit.
header.Mode = int64(file.Mode())
header.Format = tar.FormatGNU
header.Name = normalizePath(file.Destination)
header.Uname = file.FileInfo.Owner
Expand Down
2 changes: 2 additions & 0 deletions testdata/acceptance/apk.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -d /var/log/whatever
RUN test -d /usr/share/foo
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
Expand All @@ -55,6 +56,7 @@ RUN echo wat >> /etc/foo/whatever.conf
RUN apk del foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/sbin/fake
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
RUN test ! -d /var/log/whatever
Expand Down
4 changes: 4 additions & 0 deletions testdata/acceptance/core.complex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ contents:
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
- src: ./testdata/fake
dst: /usr/sbin/fake
file_info:
mode: 04755
empty_folders:
- /var/log/whatever
- /usr/share/foo
Expand Down
3 changes: 2 additions & 1 deletion testdata/acceptance/deb.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -d /var/log/whatever
RUN test -d /usr/share/foo
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
Expand All @@ -58,12 +59,12 @@ RUN echo wat >> /etc/foo/whatever.conf
RUN dpkg -r foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/sbin/fake
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
RUN test ! -d /var/log/whatever
RUN test ! -d /usr/share/foo


# ---- signed test ----
FROM test_base AS signed
COPY keys/pubkey.gpg /usr/share/debsig/keyrings/9890904DFB2EC88A/debsig.gpg
Expand Down
2 changes: 2 additions & 0 deletions testdata/acceptance/rpm.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -d /var/log/whatever
RUN test -d /usr/share/foo
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
RUN test -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test -f /tmp/pretrans-proof
Expand All @@ -59,6 +60,7 @@ RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /usr/sbin/fake
RUN test -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof
RUN test ! -d /var/log/whatever
Expand Down
1 change: 1 addition & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ contents:
- src: path/to/foo
dst: /usr/local/foo
file_info:
# Make sure that the mode is specified in octal, e.g. 0644 instead of 644.
mode: 0644
mtime: 2008-01-02T15:04:05Z
owner: notRoot
Expand Down