Skip to content

Commit 686b5ea

Browse files
committed
Use 1000 as default application user
Allows to overwrite user by defining: DOKKU_USER_ID or use random by setting DOKKU_RANDOM_USER_ID
1 parent 58f02bc commit 686b5ea

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bundle/
2+
.git/
3+
vendor/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.tgz
22
build-dir/buildpacks/*
3+
.bundle/
4+
vendor/

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ TAG ?= $(shell git rev-parse --abbrev-ref HEAD)
33

44
build:
55
docker build -t "$(IMAGE):$(TAG)" .
6+
7+
test:
8+
bundle install --deployment
9+
docker build -t progrium/buildstep .
10+
bundle exec cucumber --exclude features/apps

builder/builder

+32-14
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,39 @@ mkdir -p $cache_root
88
mkdir -p $buildpack_root
99
mkdir -p $build_root/.profile.d
1010

11-
user_id=$((RANDOM+1000))
12-
user_name="u${user_id}"
11+
# Use 1000 as default user
12+
if [[ -n "$DOKKU_RANDOM_USER_ID" ]]; then
13+
DOKKU_USER_ID="${DOKKU_USER_ID:-$((RANDOM+1000))}"
14+
else
15+
DOKKU_USER_ID="${DOKKU_USER_ID:-1000}"
16+
fi
1317

14-
# Create a random user
15-
/usr/sbin/addgroup --quiet --gid $user_id $user_name
16-
/usr/sbin/adduser --shell /bin/bash \
17-
--disabled-password \
18-
--force-badname \
19-
--no-create-home \
20-
--uid $user_id \
21-
--gid $user_id \
22-
--gecos '' \
23-
--quiet \
24-
--home $app_dir \
25-
$user_name
18+
if [[ "$DOKKU_USER_ID" -ne "0" ]]; then
19+
user_id="$DOKKU_USER_ID"
20+
user_name="u${user_id}"
21+
22+
echo $'\e[1G----->' "Using $user_name to run an application"
23+
24+
# Create a random user
25+
/usr/sbin/addgroup --quiet --gid $user_id $user_name
26+
/usr/sbin/adduser --shell /bin/bash \
27+
--disabled-password \
28+
--force-badname \
29+
--no-create-home \
30+
--uid $user_id \
31+
--gid $user_id \
32+
--gecos '' \
33+
--quiet \
34+
--home $app_dir \
35+
$user_name
36+
else
37+
user_id="0"
38+
user_name="root"
39+
40+
echo $'\e[1G----->' " Using ROOT to run an application (potentially insecure)"
41+
42+
/usr/sbin/usermod --home $app_dir root
43+
fi
2644

2745
# Grant the user access to all required paths before
2846
# running the compile phase as non-privileged user.

0 commit comments

Comments
 (0)