Skip to content

Commit 9d9b8ce

Browse files
authored
[FLINK-37881] Drop gosu in favour of Dockerfile USER
1 parent 055a578 commit 9d9b8ce

2 files changed

Lines changed: 11 additions & 33 deletions

File tree

Dockerfile-ubuntu.template

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ RUN set -ex; \
2424
apt-get -y install gpg libsnappy1v5 gettext-base libjemalloc-dev; \
2525
rm -rf /var/lib/apt/lists/*
2626

27-
# Grab gosu for easy step-down from root
28-
ENV GOSU_VERSION 1.11
29-
RUN set -ex; \
30-
wget -nv -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)"; \
31-
wget -nv -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc"; \
32-
export GNUPGHOME="$(mktemp -d)"; \
33-
for server in hkps://keys.openpgp.org $(shuf -e \
34-
keyserver.ubuntu.com \
35-
hkp://keyserver.ubuntu.com:80 \
36-
pgp.mit.edu) ; do \
37-
gpg --batch --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
38-
done && \
39-
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
40-
gpgconf --kill all; \
41-
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
42-
chmod +x /usr/local/bin/gosu; \
43-
gosu nobody true
44-
4527
# Configure Flink version
4628
ENV FLINK_TGZ_URL=%%BINARY_DOWNLOAD_URL%% \
4729
FLINK_ASC_URL=%%ASC_DOWNLOAD_URL%% \
@@ -88,6 +70,7 @@ RUN set -ex; \
8870
"-rmKV" "taskmanager.host=localhost";
8971

9072
# Configure container
73+
USER flink
9174
COPY docker-entrypoint.sh /
9275
ENTRYPOINT ["/docker-entrypoint.sh"]
9376
EXPOSE 6123 8081

docker-entrypoint.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,9 @@ COMMAND_HISTORY_SERVER="history-server"
2525
JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-$(hostname -f)}
2626
CONF_FILE_DIR="${FLINK_HOME}/conf"
2727

28-
drop_privs_cmd() {
29-
if [ $(id -u) != 0 ]; then
30-
# Don't need to drop privs if EUID != 0
31-
return
32-
elif [ -x /sbin/su-exec ]; then
33-
# Alpine
34-
echo su-exec flink
35-
else
36-
# Others
37-
echo gosu flink
28+
check_priv_user() {
29+
if [ $(id -u) == 0 ]; then
30+
echo "WARNING: Running as root user is not recommended. Please use a non-root user to run Flink."
3831
fi
3932
}
4033

@@ -146,6 +139,8 @@ maybe_enable_jemalloc() {
146139
fi
147140
}
148141

142+
check_priv_user
143+
149144
maybe_enable_jemalloc
150145

151146
copy_plugins_if_required
@@ -163,28 +158,28 @@ elif [ "$1" = "jobmanager" ]; then
163158

164159
echo "Starting Job Manager"
165160

166-
exec $(drop_privs_cmd) "$FLINK_HOME/bin/jobmanager.sh" start-foreground "${args[@]}"
161+
exec "$FLINK_HOME/bin/jobmanager.sh" start-foreground "${args[@]}"
167162
elif [ "$1" = ${COMMAND_STANDALONE} ]; then
168163
args=("${args[@]:1}")
169164

170165
echo "Starting Job Manager"
171166

172-
exec $(drop_privs_cmd) "$FLINK_HOME/bin/standalone-job.sh" start-foreground "${args[@]}"
167+
exec "$FLINK_HOME/bin/standalone-job.sh" start-foreground "${args[@]}"
173168
elif [ "$1" = ${COMMAND_HISTORY_SERVER} ]; then
174169
args=("${args[@]:1}")
175170

176171
echo "Starting History Server"
177172

178-
exec $(drop_privs_cmd) "$FLINK_HOME/bin/historyserver.sh" start-foreground "${args[@]}"
173+
exec "$FLINK_HOME/bin/historyserver.sh" start-foreground "${args[@]}"
179174
elif [ "$1" = "taskmanager" ]; then
180175
args=("${args[@]:1}")
181176

182177
echo "Starting Task Manager"
183178

184-
exec $(drop_privs_cmd) "$FLINK_HOME/bin/taskmanager.sh" start-foreground "${args[@]}"
179+
exec "$FLINK_HOME/bin/taskmanager.sh" start-foreground "${args[@]}"
185180
fi
186181

187182
args=("${args[@]}")
188183

189184
# Running command in pass-through mode
190-
exec $(drop_privs_cmd) "${args[@]}"
185+
exec "${args[@]}"

0 commit comments

Comments
 (0)