Skip to content

Commit 0ac8003

Browse files
authored
Merge pull request #220 from pelias/docker_permissions
deprecate manually assigning DOCKER_USER
2 parents d21b7d8 + 680f5e1 commit 0ac8003

18 files changed

Lines changed: 28 additions & 27 deletions

File tree

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ You will need to have a [modern version of `docker`](https://docs.docker.com/eng
4040

4141
This project supports Linux and Mac OSX operatings systems. Windows is currently [not supported](https://github.com/pelias/docker/issues/124).
4242

43+
### Permissions
44+
45+
In order to ensure security, Pelias docker containers, and the `pelias` helper script, will not run as a root user!
46+
47+
Be sure you are running as a non-root user and that this user can execute `docker` commands. See the Docker documentation article [Manage Docker as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) to do this.
48+
4349
## Requirements for Linux
4450
- Install `util-linux` using your distribution's package manager
4551
- Alpine Linux: `sudo apk add util-linux`
@@ -95,12 +101,6 @@ mkdir ./data
95101
sed -i '/DATA_DIR/d' .env
96102
echo 'DATA_DIR=./data' >> .env
97103

98-
# configure docker to write files as your local user
99-
# see: https://github.com/pelias/docker#variable-docker_user
100-
# note: use 'gsed' instead of 'sed' on a Mac
101-
sed -i '/DOCKER_USER/d' .env
102-
echo "DOCKER_USER=$(id -u)" >> .env
103-
104104
# run build
105105
pelias compose pull
106106
pelias elastic start
@@ -183,7 +183,6 @@ Then use your text editor to modify the `.env` file to reflect your new path, it
183183
```bash
184184
COMPOSE_PROJECT_NAME=pelias
185185
DATA_DIR=/tmp/pelias
186-
DOCKER_USER=1000
187186
```
188187

189188
You can then list the environment variables to ensure they have been correctly set:
@@ -200,9 +199,7 @@ Note: changing the `COMPOSE_PROJECT_NAME` variable is not advisable unless you k
200199

201200
### Variable: DOCKER_USER
202201

203-
All processes in Pelias containers are run as non-root users. By default, the UID of the processes will be `1000`, which is the first user ID on _most_ Linux systems and is likely to be a good option. However, if restricting file permissions in your data directory to a different user or group is important, this can be overridden by setting the `DOCKER_USER` variable.
204-
205-
This variable can take just a UID or a UID:GID combination such as `1000:1000`. See the [docker-compose](https://docs.docker.com/compose/compose-file/#domainname-hostname-ipc-mac_address-privileged-read_only-shm_size-stdin_open-tty-user-working_dir) and [docker run](https://docs.docker.com/engine/reference/run/#user) documentation on controlling Docker container users for more information.
202+
This variable is no longer used, and will be ignored. If you still have it in your `.env` file, you can safely remove it.
206203

207204
## CLI commands
208205

lib/env.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,26 @@ set -e;
44
# disable verbose logging
55
ENV_DISPLAY_WARNINGS=false
66

7+
# ensure docker runs containers as the current user (even when running with sudo)
8+
# note: SUDO_USER is not portable to all systems but its the best we've got.
9+
function set_docker_user(){
10+
CURRENT_USER=$(id -u ${SUDO_USER-${USER}}):$(id -g ${SUDO_USER-${USER}})
11+
if [ ! -z "${DOCKER_USER}" ] && [ "${DOCKER_USER}" != "${CURRENT_USER}" ]; then
12+
2>&1 printf "WARNING: The DOCKER_USER env var is deprecated, using %s.\n" ${CURRENT_USER}
13+
2>&1 echo "Remove the DOCKER_USER line from your .env file to silence this message."
14+
fi
15+
export DOCKER_USER="${CURRENT_USER}";
16+
}
17+
718
# ensure the user environment is correctly set up
819
function env_check(){
20+
if [ "${DOCKER_USER}" = "0:0" ]; then
21+
echo "You are running as root"
22+
echo "This is insecure and not supported by Pelias."
23+
echo "Please try again as a non-root user."
24+
exit 1
25+
fi
26+
927
if [ -z "${DATA_DIR}" ]; then
1028
echo "You must set the DATA_DIR env var to a valid directory on your local machine."
1129
echo
@@ -49,5 +67,7 @@ function env_load_stream(){
4967
# fi
5068
# fi
5169

70+
set_docker_user
71+
5272
# ensure the user env is correctly set up
5373
env_check

projects/australia/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/australia
3-
DOCKER_USER=1000

projects/belgium/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
2-
DOCKER_USER=1000
32
DATA_DIR=/tmp/pelias/belgium

projects/brazil/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/brazil
3-
DOCKER_USER=1000

projects/france/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/france
3-
DOCKER_USER=1000

projects/jamaica/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/jamaica
3-
DOCKER_USER=1000

projects/los-angeles-metro/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/los-angeles-metro
3-
DOCKER_USER=1000

projects/netherlands/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
2-
DOCKER_USER=1000
32
DATA_DIR=/tmp/pelias/netherlands

projects/new-york-city/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
COMPOSE_PROJECT_NAME=pelias
22
DATA_DIR=/tmp/pelias/new-york-city
3-
DOCKER_USER=1000

0 commit comments

Comments
 (0)