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

VOLUME are mounted as noexec #4318

Closed
ensc opened this issue Oct 22, 2019 · 18 comments · Fixed by #4329
Closed

VOLUME are mounted as noexec #4318

ensc opened this issue Oct 22, 2019 · 18 comments · Fixed by #4329
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@ensc
Copy link

ensc commented Oct 22, 2019

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

VOLUME in Dockerfile are mounted as noexec. This is unexpected, breaks existing systems. and derives from original docker (moby-engine-18.06.3) .

E.g.

FROM alpine:latest

VOLUME /var/tmp

RUN \
    printf "#! /bin/sh\ntrue" > /xtest

ENTRYPOINT ["/bin/sh", "-c", "install -m 0755 /xtest /var/tmp/xtest && /var/tmp/xtest"]

causes

$ podman run 819b47518da77b8f38430ecf9662924042a84de96377145893ca7e1988f222b1
/bin/sh: /var/tmp/xtest: Permission denied

while docker works fine

# docker run 3131c893800b
#

cat /proc/mounts within the container shows, that noexec mount flags are set for the /var/tmp bind mount.

Steps to reproduce the issue:

  1. build a pod with VOLUME

Describe the results you received:

Volume is mounted without noexec flags

Describe the results you expected:

Volume is mounted with noexec flag.

Additional information you deem important (e.g. issue happens only occasionally):

*** podman inspect output ***

        "Config": {
            "Volumes": {
                "/var/tmp": {}
            }

Output of podman version:

$ podman version
Version:            1.6.1
RemoteAPI Version:  1
Go Version:         go1.12.9
OS/Arch:            linux/amd64

Output of podman info --debug:

debug:
  compiler: gc
  git commit: ""
  go version: go1.12.9
  podman version: 1.6.1
host:
  BuildahVersion: 1.11.2
  CgroupVersion: v1
  Conmon:
    package: conmon-2.0.1-1.fc30.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.1, commit: 4346fbe0b2634b05857973bdf663598081240374'
  Distribution:
    distribution: fedora
    version: "30"
  MemFree: 17307926528
  MemTotal: 33257033728
  OCIRuntime:
    package: runc-1.0.0-93.dev.gitb9b6cc6.fc30.x86_64
    path: /usr/bin/runc
    version: |-
      runc version 1.0.0-rc8+dev
      commit: e3b4c1108f7d1bf0d09ab612ea09927d9b59b4e3
      spec: 1.0.1-dev
  SwapFree: 4294963200
  SwapTotal: 4294963200
  arch: amd64
  cpus: 8
  eventlogger: journald
  hostname: ensc-virt.intern.sigma-chemnitz.de
  kernel: 5.2.18-200.fc30.x86_64
  os: linux
  rootless: true
  slirp4netns:
    Executable: /usr/bin/slirp4netns
    Package: slirp4netns-0.4.0-4.git19d199a.fc30.x86_64
    Version: |-
      slirp4netns version 0.4.0-beta.2
      commit: 19d199a6ca424fcf9516320a327cedad85cf4dfb
  uptime: 22h 10m 26.75s (Approximately 0.92 days)
registries:
  blocked: null
  insecure: null
  search:
  - docker.io
  - registry.fedoraproject.org
  - quay.io
  - registry.access.redhat.com
  - registry.centos.org
store:
  ConfigFile: /home/ensc/.config/containers/storage.conf
  ContainerStore:
    number: 9
  GraphDriverName: vfs
  GraphOptions: {}
  GraphRoot: /.local/home/ensc/.local/share/containers/storage
  GraphStatus: {}
  ImageStore:
    number: 33
  RunRoot: /run/user/505
  VolumePath: /.local/home/ensc/.local/share/containers/storage/volumes

Package info (e.g. output of rpm -q podman or apt list podman):

podman-1.6.1-2.fc30.x86_64
@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 22, 2019
@mheon
Copy link
Member

mheon commented Oct 22, 2019

Podman flags: rw,nosuid,nodev,noexec,relatime,seclabel
Docker flags: rw,relatime,seclabel

@rhatdan I'm inclined to leave the defaults for volumes we explicitly specify (-v and --mount) the same, but there's no way to adjust mount options for image volumes. Do we want to mirror Docker and strip everything, or just get rid of noexec?

@rhatdan
Copy link
Member

rhatdan commented Oct 23, 2019

Strip noexec.
The nodev we have added for images to /usr/share/containers/storage.conf by default. And nodev is just good to have for a security purposes. We don't want containers trusted random devices. Same argument could be made for nosuid.

I think noexec is the most overrated security mechanism for mount points, since it easy to bypass by using scripting languages like bash, python, perl, ruby, awk ...

mheon added a commit to mheon/libpod that referenced this issue Oct 23, 2019
This matches Docker more closely, but retains the more important
protections of nosuid/nodev.

Fixes containers#4318

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
@nicholasbishop
Copy link

Is there any workaround for this bug until my distro (Fedora) includes the fix?

@mheon
Copy link
Member

mheon commented Oct 30, 2019

You can create a volume and mount it over the path for the image volume, making sure to specify exec in the mount options so it's not mounted noexec.

We're in the process of cutting a new release, so a version of Podman with this fix will be available soon.

@nicholasbishop
Copy link

Just an FYI, I tried out a recent build of podman and while volumes specified with VOLUME are now mounted exec, volumes mounted with podman run --volume are still noexec. Not sure if that's expected behavior or not.

@mheon
Copy link
Member

mheon commented Nov 14, 2019 via email

@rhatdan
Copy link
Member

rhatdan commented Nov 16, 2019

Does that default match Docker?

@nicholasbishop
Copy link

No, Docker defaults to exec.

rh-container-bot pushed a commit to lsm5/podman that referenced this issue Nov 17, 2019
This matches Docker more closely, but retains the more important
protections of nosuid/nodev.

Fixes containers#4318

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
@rhatdan
Copy link
Member

rhatdan commented Nov 18, 2019

Ok I think we should match docker.

@rhatdan rhatdan reopened this Nov 18, 2019
@rhatdan
Copy link
Member

rhatdan commented Nov 23, 2019

#4557 documents the defaults.

@klaus4040
Copy link

Maybe my brain shorts out after days getting into podman, but in podman 1.9.1 I think there is something wrong with image volumes and default options. The image defines a volume and podman finds it
DEBU[0000] Adding image volume at /var/atlassian/application-data/bitbucket
and i bind a volume of my own to it
-v bbvolume:/var/atlassian/application-data/bitbucket
yet in the end the defaults are ignored and noexec is used.
"Binds": [ "bbvolume:/var/atlassian/application-data/bitbucket:rw,rprivate,noexec,nosuid,nodev,rbind" ],
If I find time tomorrow to set up an IDE I can walk through the code easier than here directly in the source files ... setting exec manually works

@mheon
Copy link
Member

mheon commented May 5, 2020

I think that's fully expected - the image volume is overridden by your volume mount, and your named volume defaults to noexec. Right now, only image volumes default to exec. There has been significant talk about this, though, and I think my resistance to having the default be exec is crumbling.

@klaus4040
Copy link

k thanks, the container instructions by atlassian at docker.io with docker in mind don't tell to use the exec option, yet without the container doesn't start properly, so there is an inconsistency with docker then (propably, haven't checked).

@joelddiaz
Copy link

Ok I think we should match docker.

Quoting @rhatdan above. So is the intention to match Docker behavior regarding default mount flags? Because the Podman docs specifically state that you will get 'noexec' by default (differing from Docker).

@mheon
Copy link
Member

mheon commented May 13, 2020

I don't want to promise we will match completely; the utility of noexec is questionable and we may remove it, but I see definite value in nodev and nosuid and I don't think we'll be dropping those.

We presently also include noexec but I think we'll be dropping it by default (probably in v2.0)

@rhatdan
Copy link
Member

rhatdan commented May 13, 2020

I agree with removing noexec, keeping nosuid and nodev makes sense.

@mheon
Copy link
Member

mheon commented May 19, 2020

#6280 flips the default to off for named volumes.

@kallisti5
Copy link

kallisti5 commented May 21, 2020

oh wow.. this one was obnoxious to track down and not super obvious. All of our CI started breaking.

Pretty much compiling anything within a named volume requires exec (autoconf does a bunch of gcc compiler checks which execute test binaries)

leoluk added a commit to monogon-dev/monogon that referenced this issue Mar 30, 2021
This leaves us with only git_repository rules not being cached,
the worst offender being the edk2 recursive submodule clone.

See: bazelbuild/bazel#5116

gazelle's repo lookup (running `go list`) is also not cached, even if the
repositories themselves are.

We can eliminate most of the remaining rebuild time by mounting
the entire execroot, however, this is currently foiled by a podman bug
(Bazel needs to execute lots of binaries inside the root):

containers/podman#4318

Test Plan:
Ran `bazel build scripts:launch`, recreated container, ran it again.

Build times decreased significantly:

    INFO: Elapsed time: 279.951s, Critical Path: 119.05s
    INFO: 477 processes: 476 linux-sandbox, 1 local.
    INFO: Build completed successfully, 497 total actions

X-Origin-Diff: phab/D206
GitOrigin-RevId: 2d17a7eeb5d8b70ad4e26c13a0c6b31c4edfb33f
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants