Skip to content

docker-entrypoint.sh fails if config file is mounted as read-only #368

Closed
@st3v

Description

@st3v

Background

When deploying RabbitMQ to Kubernetes it is pretty common to mount a configMap that contains a rabbitmq.conf file inside the container. As of Kubernetes 1.9.4 configMaps are always mounted as read-only (see changelog for K8s 1.9.4). That change was made to address a CVE. Now the problem is that docker-entrypoint.sh tries to write to the rabbitmq config whenever certain environment variables are set in the container (e.g. RABBITMQ_DEFAULT_USER). Obviously, this fails when the file gets mounted as read-only.

Happy Case 🙂

Kubernetes pods start and run perfectly fine as long as I don't set one of the magic env vars that causes docker-entrypoint.sh to write to the mounted /etc/rabbitmq/rabbitmq.conf.

$ kubectl apply -f https://bit.ly/2lTBBki
configmap/rabbitmq-config created
statefulset.apps/rabbitmq created

$ kubectl get pod
NAME         READY   STATUS    RESTARTS   AGE
rabbitmq-0   1/1     Running   0          27s

Sad Case 😢

Pods don't start as soon as I set RABBITMQ_DEFAULT_USER. The pod logs show that sed couldn't write to the mounted directory.

$ kubectl apply -f https://bit.ly/2koRD5s
configmap/rabbitmq-config created
statefulset.apps/rabbitmq created

$ kubectl get pod
NAME         READY   STATUS   RESTARTS   AGE
rabbitmq-0   0/1     Error    2          20s

$ kubectl logs rabbitmq-0
sed: couldn't open temporary file /etc/rabbitmq/seda5g8kq: Read-only file system

Difference between both cases

$ diff <(curl -sSL https://bit.ly/2lTBBki 2>&1) <(curl -sSL https://bit.ly/2koRD5s 2>&1)
51a52,54
>         env:
>           - name: RABBITMQ_DEFAULT_USER
>             value: bunny

Workaround

  • Add an initContainer to the pod that copies the config file to a write-able location
  • Have the RabbitMQ container pick up the config file from that location

Example: https://gist.github.com/st3v/ffefe94c84c196d90a420bb561f2878f#file-repro_workaround-yaml

Desired Behavior

I'd argue that the RabbitMQ docker image should add out-of-the-box support for read-only config files. The workaround using an initContainer is kinda hacky and shouldn't be necessary for something that is arguably a pretty common use case given the Kubernetes behavior described above.

Resources

YAML files used above: https://gist.github.com/st3v/ffefe94c84c196d90a420bb561f2878f

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions