Skip to content

Commit

Permalink
Only be root when necessary, so that --user works
Browse files Browse the repository at this point in the history
  • Loading branch information
yosifkit committed Jan 15, 2016
1 parent e47798c commit 39be622
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ ENV PATH /usr/lib/rabbitmq/bin:$PATH

RUN echo '[{rabbit, [{loopback_users, []}]}].' > /etc/rabbitmq/rabbitmq.config

# set home so that any `--user` knows where to put the erlang cookie
ENV HOME /var/lib/rabbitmq

VOLUME /var/lib/rabbitmq

# add a symlink to the .erlang.cookie in /root so we can "docker exec rabbitmqctl ..." without gosu
Expand Down
11 changes: 6 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
set -e

# allow the container to be stated with `--user`
if [ "$1" = 'rabbitmq-server' -a "$(id -u)" = '0' ]; then
chown -R rabbitmq /var/lib/rabbitmq
exec gosu rabbitmq "$BASH_SOURCE" "$@"
fi

ssl=
if [ "$RABBITMQ_SSL_CERT_FILE" -a "$RABBITMQ_SSL_KEY_FILE" -a "$RABBITMQ_SSL_CA_FILE" ]; then
ssl=1
Expand All @@ -22,7 +28,6 @@ if [ "$RABBITMQ_ERLANG_COOKIE" ]; then
else
echo "$RABBITMQ_ERLANG_COOKIE" > "$cookieFile"
chmod 600 "$cookieFile"
chown rabbitmq "$cookieFile"
fi
fi

Expand Down Expand Up @@ -126,7 +131,6 @@ if [ "$1" = 'rabbitmq-server' ]; then
# Create combined cert
cat "$RABBITMQ_SSL_CERT_FILE" "$RABBITMQ_SSL_KEY_FILE" > /tmp/combined.pem
chmod 0400 /tmp/combined.pem
chown rabbitmq /tmp/combined.pem

# More ENV vars for make clustering happiness
# we don't handle clustering in this script, but these args should ensure
Expand All @@ -135,9 +139,6 @@ if [ "$1" = 'rabbitmq-server' ]; then
export RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-pa '$ERL_SSL_PATH' -proto_dist inet_tls -ssl_dist_opt server_certfile /tmp/combined.pem -ssl_dist_opt server_secure_renegotiate true client_secure_renegotiate true"
export RABBITMQ_CTL_ERL_ARGS="$RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS"
fi

chown -R rabbitmq /var/lib/rabbitmq
set -- gosu rabbitmq "$@"
fi

exec "$@"

3 comments on commit 39be622

@renewooller
Copy link

Choose a reason for hiding this comment

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

FYI - this change seems to have broken it:
$ cat rmqEnv.sh
RABBITMQ_DEFAULT_PASS=password
RABBITMQ_DEFAULT_USER=nightlife
PATH=/usr/lib/rabbitmq/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RABBITMQ_LOGS=-
RABBITMQ_SASL_LOGS=-
RABBITMQ_VERSION=3.6.0
RABBITMQ_DEBIAN_VERSION=3.6.0-1
HOME=/var/lib/rabbitmq

$ docker run -v /ecs/rmq-data:/var/lib/rabbitmq --env-file=./rmqEnv.sh -p 15672:15672 -p 5672:5672 rabbitmq:3-management

/docker-entrypoint.sh: line 56: /etc/rabbitmq/rabbitmq.config: Permission denied

@ihortymoshenko
Copy link

Choose a reason for hiding this comment

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

@yosifkit
Copy link
Member Author

Choose a reason for hiding this comment

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

This was fixed in 90918b0, and pushed with docker-library/official-images#1390. So you should be able to docker pull a fixed image.

Please sign in to comment.