Skip to content

socket sharing between containers denied by selinux when using "--systemd=always" #8216

@ah83

Description

@ah83

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

/kind bug

Description

A container named "server" runs for example a memcached which is listening on a unix domain socket.
The socket is stored in a bind mounted directory (-v /var/local/container-volumes/data:/data:z).
A second container named "client" starts with exactly same bind mount to access the memcached socket as a client.

When the client container starts with the option "--systemd=always" and then tries to access the socket
/data/sockets/memcached.socket, the access will be denied by SELinux.
Without "--systemd=always" everything works as expected.

Steps to reproduce the issue:

  1. Run server container
mkdir -p /var/local/container-volumes/data/sockets
chmod 700 /var/local/container-volumes
chmod 700 /var/local/container-volumes/data/sockets
podman run --name server -it --rm -v /var/local/container-volumes/data:/data:z centos:8 /bin/bash
yum install memcached
memcached -u root -s /data/sockets/memcached.socket
  1. Run client container with "--systemd always" and try to connect to socket
podman run --name client -it --rm --systemd always -v /var/local/container-volumes/data:/data:z centos:8 /bin/bash
yum install socat
socat -v UNIX-CONNECT:/data/sockets/memcached.socket STDIN
2020/11/02 10:26:46 socat[56] E connect(5, AF=1 "/data/sockets/memcached.socket", 32): Permission denied
  1. Run client container without "--systemd always" and try to connect to socket
podman run --name client -it --rm  -v /var/local/container-volumes/data:/data:z centos:8 /bin/bash
yum install socat
socat -v UNIX-CONNECT:/data/sockets/memcached.socket STDIN

Works as expected!

Describe the results you received:

SELinux error msg on the container host

type=AVC msg=audit(1604312588.452:67274): avc:  denied  { connectto } for  pid=148723 comm="socat" path="/data/sockets/memcached.socket" scontext=system_u:system_r:container_init_t:s0:c603,c1008 tcontext=system_u:system_r:container_t:s0:c175,c654 tclass=unix_stream_socket permissive=-1

socat error msg

2020/11/02 10:26:46 socat[56] E connect(5, AF=1 "/data/sockets/memcached.socket", 32): Permission denied

Describe the results you expected:

Access to the unix socket.

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

memcached is only used to show the issue and reproduce it.
In my production setup i share the sockets of a sssd container to provide nss and pam services for 200 containers per host.
There is no viable alternative to sharing the socket this way and the "client" container must use systemd,
because there are running multiple services inside the container.
This setup worked in previous versions of podman.

Output of podman version:

Version:      2.1.1
API Version:  2.0.0
Go Version:   go1.13.15
Built:        Wed Oct 28 13:38:47 2020
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.16.1
  cgroupManager: systemd
  cgroupVersion: v1
  conmon:
    package: conmon-2.0.21-1.el8.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.21, commit: fa5f92225c4c95759d10846106c1ebd325966f91-dirty'
  cpus: 8
  distribution:
    distribution: '"centos"'
    version: "8"
  eventLogger: journald
  hostname: xxxx
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 4.18.0-193.19.1.el8_2.x86_64
  linkmode: dynamic
  memFree: 9583423488
  memTotal: 16643891200
  ociRuntime:
    name: runc
    package: runc-1.0.0-145.rc91.git24a3cf8.el8.x86_64
    path: /usr/bin/runc
    version: 'runc version spec: 1.0.2-dev'
  os: linux
  remoteSocket:
    path: /run/podman/podman.sock
  rootless: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 2147479552
  swapTotal: 2147479552
  uptime: 74h 7m 51.92s (Approximately 3.08 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 30
    paused: 0
    running: 8
    stopped: 22
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /data/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageStore:
    number: 1796
  runRoot: /var/run/containers/storage
  volumePath: /data/containers/storage/volumes
version:
  APIVersion: 2.0.0
  Built: 1603888727
  BuiltTime: Wed Oct 28 13:38:47 2020
  GitCommit: ""
  GoVersion: go1.13.15
  OsArch: linux/amd64
  Version: 2.1.1

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

podman-2.1.1-10.el8.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes

Additional environment details (AWS, VirtualBox, physical, etc.):

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.locked - please file new issue/PRAssist humans wanting to comment on an old issue or PR with locked comments.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions