Skip to content

pkg/archive: Unpack() use 0755 permissions for missing directories#42016

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:archive_permissions
Feb 17, 2021
Merged

pkg/archive: Unpack() use 0755 permissions for missing directories#42016
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:archive_permissions

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

together with #41984, this fixes #41978 If I create a compressed tar ball with etc/password in it
replaces/closes #41990

Commit edb62a3 / #35541 fixed a bug in MkdirAllAndChown() that caused the specified permissions to not be applied correctly. As a result of that bug, the configured umask would be applied.

When extracting archives, Unpack() used 0777 permissions when creating missing parent directories for files that were extracted. Before edb62a3, this resulted in actual permissions of the directories to be 0755 on most configurations (using a default 022 umask).

Creating these directories should not depend on the host's umask configuration. This patch changes the permissions to 0755 to match the previous behavior, and to reflect the original intent of using 0755 as default.

- Description for the changelog

Fix permissions for newly created dirs in ADD

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Copy Markdown
Member Author

@tonistiigi @cpuguy83 PTAL

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhatdan
Copy link
Copy Markdown
Contributor

rhatdan commented Feb 12, 2021

LGTM

@tonistiigi
Copy link
Copy Markdown
Member

Could we have a test for this? Preferably one that also passes pre-19.03.15 and 20.10.2 .

@thaJeztah thaJeztah force-pushed the archive_permissions branch 2 times, most recently from b20974d to 6474e38 Compare February 17, 2021 14:33
@thaJeztah
Copy link
Copy Markdown
Member Author

@tonistiigi added a test;

  • test fails if I revert the fix from this PR
  • test passes if I both revert the fix from this PR and revert edb62a3

Commit edb62a3 fixed a bug in MkdirAllAndChown()
that caused the specified permissions to not be applied correctly. As a result
of that bug, the configured umask would be applied.

When extracting archives, Unpack() used 0777 permissions when creating missing
parent directories for files that were extracted.
Before edb62a3, this resulted in actual
permissions of those directories to be 0755 on most configurations (using a
default 022 umask).

Creating these directories should not depend on the host's umask configuration.
This patch changes the permissions to 0755 to match the previous behavior,
and to reflect the original intent of using 0755 as default.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Copy Markdown
Member Author

s390x failure is unrelated

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83 cpuguy83 merged commit e403ab8 into moby:master Feb 17, 2021
@thaJeztah thaJeztah deleted the archive_permissions branch February 17, 2021 18:58
@gknuppe
Copy link
Copy Markdown

gknuppe commented Jul 8, 2021

This change is making /tmp directory be created without write permission for other users than root. So, it's making some images that runs as non-root user to fail due to EACCES on /tmp directory. Is that possible to configure the permission to be used instead of assuming 0755 ? or at least for /tmp directory?

@thaJeztah
Copy link
Copy Markdown
Member Author

@gknuppe this is on images you created, or are you seeing this on images you pulled from (e.g.) Docker Hub? do you have an example image where this is happening in? I guess it depends on wether or not the rootfs has a directory defined for /tmp. Trying some images, I do see 0777 permissions for /tmp.

for i in alpine ubuntu debian; do docker run --rm -u 123:456 $i ls -la /tmp; done
total 8
drwxrwxrwt    2 root     root          4096 Jan 30  2019 .
drwxr-xr-x    1 root     root          4096 Jul  8 14:45 ..
total 8
drwxrwxrwt 2 root root 4096 Mar  7  2019 .
drwxr-xr-x 1 root root 4096 Jul  8 14:45 ..
total 8
drwxrwxrwt 2 root root 4096 Feb 28  2019 .
drwxr-xr-x 1 root root 4096 Jul  8 14:45 ..

@gknuppe
Copy link
Copy Markdown

gknuppe commented Jul 12, 2021

Thanks for the follow up.
I found such situation using mongo:4.4.2-bionic image with stable version of docker for debian buster distro. (docker-ce 20.10.6 and containerd.io 1.4.6-1) and here is what I found:

  • pulled such image with docker-ce 20.10.6 and contianerd.io 1.4.6-1
$ docker pull mongo:4.4.2-bionic
4.4.2-bionic: Pulling from library/mongo
f22ccc0b8772: Pull complete
3cf8fb62ba5f: Pull complete
e80c964ece6a: Pull complete
329e632c35b3: Pull complete
3e1bd1325a3d: Pull complete
4aa6e3d64a4a: Pull complete
035bca87b778: Pull complete
874e4e43cb00: Pull complete
08cb97662b8b: Pull complete
f623ce2ba1e1: Pull complete
f100ac278196: Pull complete
6f5539f9b3ee: Pull complete
Digest: sha256:0381c2f8662810dca294439f53b68ea98b8434559c5ecd50acadc90eb2dda2ce
Status: Downloaded newer image for mongo:4.4.2-bionic
docker.io/library/mongo:4.4.2-bionic
$ docker run --rm -ti --entrypoint=/bin/bash mongo:4.4.2-bionic
root@876afed4b2d5:/# ls -la / | grep tmp
drwxr-xr-t   1 root root   4096 Nov 26  2020 tmp
  • double checked the same image in another environment with docker-ce 19.03.12 and containerd.io 1.2.13-2 and the issue was not observed:
$ docker pull mongo:4.4.2-bionic
4.4.2-bionic: Pulling from library/mongo
f22ccc0b8772: Pull complete
3cf8fb62ba5f: Pull complete
e80c964ece6a: Pull complete
329e632c35b3: Pull complete
3e1bd1325a3d: Pull complete
4aa6e3d64a4a: Pull complete
035bca87b778: Pull complete
874e4e43cb00: Pull complete
08cb97662b8b: Pull complete
f623ce2ba1e1: Pull complete
f100ac278196: Pull complete
6f5539f9b3ee: Pull complete
Digest: sha256:0381c2f8662810dca294439f53b68ea98b8434559c5ecd50acadc90eb2dda2ce
Status: Downloaded newer image for mongo:4.4.2-bionic
docker.io/library/mongo:4.4.2-bionic
$ docker run --rm -ti --entrypoint=/bin/bash mongo:4.4.2-bionic
root@c8c5a9169017:/# ls -la / | grep tmp
drwxrwxrwt   1 root root   4096 Nov 26  2020 tmp
  • read release notes and found this fix. So, I decided to make a test with some previous version (I chose 20.10.2)
  • downgrade docker-ce to 20.10.2 and containerd.io to 1.4.3-1, tested again and the issue is still occurring
  • deleted images and downloaded mongo:4.4.2-bionic again and the issue vanished
$ docker rmi mongo:4.4.2-bionic 
Untagged: mongo:4.4.2-bionic
Untagged: mongo@sha256:0381c2f8662810dca294439f53b68ea98b8434559c5ecd50acadc90eb2dda2ce
Deleted: sha256:3068f6bb852ef596c20ca7ccbcd34df94f02d6035a2d83aea1e20e1781ba19b8
Deleted: sha256:ad127f54246fa452c5e783d7895f5de32aa050ca113c26f33cd70d3e321e0b77
Deleted: sha256:df411d930f08ff19c01fff7498a7c161ffe353027d1ee0be99aef4150ef2f237
Deleted: sha256:9da06454ee6eff2960465ba510f4180810bd95d22caa65d958923aeccaa12a12
Deleted: sha256:4fc8092849352849654c290a66285e0b989f01e73a95f869a8ee9bb2eadaebf6
Deleted: sha256:4545ce32b03c37edb33aedeac6ad411047ed6dd94650697e2465db1a86507f93
Deleted: sha256:9abb615f3c3c97191bf206d3228b5bd0978e370394e71984a0d183efb0e0bd9c
Deleted: sha256:eb6c9f1a2a53c149123b96a258dcd25c29b0b8c1709b8a326bc6b9ebaa43dec8
Deleted: sha256:1acc9a7abd496942e1469e91d2f7d2b7d9e0c696f2b392ef1e85d2eaef91e96b
Deleted: sha256:2589aa72cefbcd28ecbf0798bf2ca438af965daedbbb434e8f92d4bb2d689831
Deleted: sha256:9459b6a89846db0723e467610b841e6833dbb2aae6133319a91f2f70c388afac
Deleted: sha256:9a9311f7fcddf94f7476ce89f9703e8360e8cf347ef486a280735f5cf98888cd
Deleted: sha256:b43408d5f11b7b2faf048ae4eb25c296536c571fb2f937b4f1c3883386e93d64
$ docker pull mongo:4.4.2-bionic
4.4.2-bionic: Pulling from library/mongo
f22ccc0b8772: Pull complete
3cf8fb62ba5f: Pull complete
e80c964ece6a: Pull complete
329e632c35b3: Pull complete
3e1bd1325a3d: Pull complete
4aa6e3d64a4a: Pull complete
035bca87b778: Pull complete
874e4e43cb00: Pull complete
08cb97662b8b: Pull complete
f623ce2ba1e1: Pull complete
f100ac278196: Pull complete
6f5539f9b3ee: Pull complete
Digest: sha256:0381c2f8662810dca294439f53b68ea98b8434559c5ecd50acadc90eb2dda2ce
Status: Downloaded newer image for mongo:4.4.2-bionic
docker.io/library/mongo:4.4.2-bionic
$ docker run --rm -ti --entrypoint=/bin/bash mongo:4.4.2-bionic
root@3c602f3f2a30:/# ls -la / | grep tmp
drwxrwxrwt   1 root root   4096 Nov 26  2020 tmp

So, I'm not sure if this is the change that caused that issue, but downloading such image with newer version of docker-ce and containerd.io, /tmp directory does not have sufficient permissions to allow running services as non-root user.
This is the most related change I found that may have caused such issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If I create a compressed tar ball with etc/password in it.

5 participants