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

python installation issues on docker snap #81

Open
greatquux opened this issue Nov 1, 2022 · 13 comments
Open

python installation issues on docker snap #81

greatquux opened this issue Nov 1, 2022 · 13 comments

Comments

@greatquux
Copy link

Install docker snap and create an Ubuntu 22.10 container, and try to install python, you will get an error:
Setting up python3.10-minimal (3.10.7-1) ...
[Errno 13] Permission denied: '/usr/lib/python3.10/pycache/future.cpython-310.pyc.139786761293248'dpkg: error processing package python3.10-minimal (--configure):
installed python3.10-minimal package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
python3.10-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

See
https://forums.docker.com/t/bug-on-apt-install-permission-denied/100196/6
for discussion. Apparently only a problem with the snap version.

@greatquux
Copy link
Author

BTW once I did find where my daemon.json file was, I switched to using the vfs engine and did not have any further problems with python. But I think the issue should be fixed for overlay2.

@mgajda
Copy link

mgajda commented Feb 16, 2023

@plars
Copy link

plars commented Feb 27, 2023

For now, you can work around this by using the vfs storage-driver instead:

  • edit /var/snap/docker/current/config/daemon.json and replace "overlay2" with "vfs" for the storage-driver
  • run sudo snap restart docker

@kurapov-peter
Copy link

Observing the same issue here

@zhsj zhsj self-assigned this Mar 20, 2023
@zhsj
Copy link
Contributor

zhsj commented Mar 20, 2023

The issue can be easily triggered with following command

docker run --rm ubuntu:devel sh -c 'mkdir -p /usr/lib/python3/__pycache__; echo 1 > /usr/lib/python3/__pycache__/x.pyc.1'

This seems to caused by the apparmor policy.

Maybe this one?

https://github.com/snapcore/snapd/blob/19c123f2b3f67c6e79e1f0a2af7c0721194b3a70/interfaces/apparmor/template.go#L108

deny /usr/lib/python3*/{,**/}__pycache__/**.pyc.[0-9]* w,

But I'm out of idea why the kernel doesn't use the path which is translated after overlayfs.

@zhsj
Copy link
Contributor

zhsj commented Mar 21, 2023

Mar 20 18:27:58 lunar-vm2 kernel: audit: type=1400 audit(1679336878.729:17246): apparmor="DENIED" operation="open" class="file" profile="snap.docker.dockerd" name="/usr/lib/python3/__pycache__/x.pyc.1" pid=1629 comm="sh" requested_mask="w" denied_mask="w" fsuid=0 ouid=0

Looks like it's indeed blocked by the snap apparmor.

My guess is that the realChroot patch https://github.com/docker-snap/docker-snap/blob/8e57d1fdee6d4b31f9a2f389c6081451d8bd3191/dockerd-patches/snappy-real-chroot.patch#L9-L14 doesn't work now. Maybe it's broken since docker was split to containerd and runc?

zhsj added a commit to zhsj/docker-snap that referenced this issue Mar 22, 2023
Updates canonical#81

Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
zhsj added a commit to zhsj/docker-snap that referenced this issue Mar 22, 2023
This is simliar to patches/engine/snappy-real-chroot.patch.
Fixes canonical#81

Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
zhsj added a commit to zhsj/docker-snap that referenced this issue Mar 22, 2023
Updates canonical#81

Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
zhsj added a commit to zhsj/docker-snap that referenced this issue Mar 22, 2023
This is simliar to patches/engine/snappy-real-chroot.patch.
Fixes canonical#81

Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
zhsj added a commit to zhsj/docker-snap that referenced this issue Mar 22, 2023
Updates canonical#81

Signed-off-by: Shengjing Zhu <shengjing.zhu@canonical.com>
@zhsj
Copy link
Contributor

zhsj commented Mar 22, 2023

Hmm, this issue doesn't present on ubuntu 20.04. So I fail to add a regression test in GitHub actions.

@zhsj
Copy link
Contributor

zhsj commented Mar 22, 2023

It happens when I use 5.19 kernel (the HWE version) in Ubuntu 22.04.

@zhsj
Copy link
Contributor

zhsj commented Mar 22, 2023

So I have a patch (#116) to workaround it. But it looks dangerous.

After #116, snap.docker.dockerd profile is applied to the whole path (like /var/snap/docker/common/var-lib-docker/overlay2/...).
But docker-default profile is also applied to that.

Compared to the old behavior on kernel 5.15 (without the patch), snap.docker.dockerd profile is applied to whole path, while docker-default profile is applied to the path in container (like /usr/lib/python3/__pycache__/...)

@xnox do you have some thoughts wrt the kernel?

@xnox
Copy link
Contributor

xnox commented Mar 22, 2023

In recent kernels there is overlay mitigations available so it should be possible to make this work. Will need to check this with apparmor maintainer

@zhsj
Copy link
Contributor

zhsj commented May 4, 2023

So far I see it fails from Ubuntu kernel 5.19.0-1001.1, working on 5.18.0-1001.1.

However I didn't find any working Debian kernel for this snap :/ (old versions fail with cgroup/bpf thing, new versions fail for this issue).

So my guess is that the docker-snap only works with some Ubuntu specific overlayfs patches, which is lost since Ubuntu kernel 5.19.

@xnox
Copy link
Contributor

xnox commented May 16, 2023

So far I see it fails from Ubuntu kernel 5.19.0-1001.1, working on 5.18.0-1001.1.

However I didn't find any working Debian kernel for this snap :/ (old versions fail with cgroup/bpf thing, new versions fail for this issue).

So my guess is that the docker-snap only works with some Ubuntu specific overlayfs patches, which is lost since Ubuntu kernel 5.19.

we do have some feature changes and regressions in overlayfs & shiftfs which both might be at play here.

This is very much annoying.

xnox added a commit to xnox/snapd that referenced this issue May 16, 2023
Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside hte docker container, and both are denied. Whilst former
is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895
xnox added a commit to xnox/snapd that referenced this issue May 17, 2023
Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.
xnox added a commit to xnox/snapd that referenced this issue May 17, 2023
Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.
xnox added a commit to xnox/snapd that referenced this issue May 18, 2023
Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.
xnox added a commit to xnox/snapd that referenced this issue May 18, 2023
Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.
@xnox
Copy link
Contributor

xnox commented May 18, 2023

with snapd built with canonical/snapd#12822 this seems to work for me now. Waiting to see if snapd team will agree on the approach.

@zhsj zhsj removed their assignment May 18, 2023
mvo5 added a commit to canonical/snapd that referenced this issue Jul 18, 2023
* interfaces: Allow suppressing pycache deny rule

Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.

* Fix comment typo

---------

Co-authored-by: Michael Vogt <mvo@ubuntu.com>
alexmurray pushed a commit to alexmurray/snapd that referenced this issue Oct 17, 2023
* interfaces: Allow suppressing pycache deny rule

Fully confined snaps, and docker containers, look very similar. As
moveroot/pivotroot/chroot is changed, and apparmor confinement
applied. Yet confined snaps constantly try to write to .pyc files of
the base snap, whereas docker containers are trying to write .pyc
files inside the child docker containers... and yet both are
denied. Whilst former is undesired, the latter is very confusing.

Attempt to address
canonical/docker-snap#81 without
disrupting intent of LP: #1496895

Introduce a new inline template replacement for pycache deny rules
(such that all existing snippet tests remain intact), and make
docker-support interface suppress pycache deny rules.

* Fix comment typo

---------

Co-authored-by: Michael Vogt <mvo@ubuntu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants