Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit f3a145e

Browse files
committed
Make containers more secure: don't expose application ports to outside world instead use internal container address with internal container port
1 parent 1f7e1d0 commit f3a145e

3 files changed

Lines changed: 36 additions & 23 deletions

File tree

dokku

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,41 @@ case "$1" in
9393
# start the app
9494
if is_image_buildstep_based "$IMAGE_GENERIC:$TAG"; then
9595
# buildstep
96-
INT_PORT="$APP_PORT"
97-
id=$(docker run --cidfile="$(get_cid_file_name app)" -d -p "$INT_PORT" -e PORT="$INT_PORT" --name="$(get_app_container_name app)" $DOCKER_ARGS "$IMAGE_GENERIC:$TAG" /start)
98-
addr=$(docker port $id "$INT_PORT")
99-
EXT_ADDR="${addr%:*}"
100-
EXT_PORT="${addr#*:}"
96+
id=$(docker run --cidfile="$(get_cid_file_name app)" -d --name="$(get_app_container_name app)" $DOCKER_ARGS "$IMAGE_GENERIC:$TAG" /start)
10197
else
10298
# Dockerfile
103-
EXT_PORT=""
104-
INT_PORT=""
105-
EXT_ADDR=""
106-
id=$(docker run --cidfile="$(get_cid_file_name app)" -d -P --env-file=<(: | pluginhook env-vars "$APP") --name="$(get_app_container_name app)" $DOCKER_ARGS "$IMAGE_GENERIC:$TAG")
107-
sleep 5s
108-
for test_port in 80 8080 "$APP_PORT"; do
109-
if addr=$(docker port $id "$test_port" 2>/dev/null); then
110-
INT_PORT="$test_port"
111-
EXT_ADDR="${addr%:*}"
112-
EXT_PORT="${addr#*:}"
113-
fi
114-
done
99+
id=$(docker run --cidfile="$(get_cid_file_name app)" -d --env-file=<(: | pluginhook env-vars "$APP") --name="$(get_app_container_name app)" $DOCKER_ARGS "$IMAGE_GENERIC:$TAG")
115100
fi
116101

102+
EXT_IP="$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$id")"
103+
EXT_PORT=""
104+
INT_PORT=""
105+
106+
for CONTAINER_PORT in $(docker inspect --format '{{range $p, $conf := .NetworkSettings.Ports}}{{$p}} {{end}}' "$id"); do
107+
case "$CONTAINER_PORT" in
108+
"5000/tcp")
109+
EXT_PORT="5000"
110+
INT_PORT="5000"
111+
break
112+
;;
113+
114+
"8080/tcp")
115+
EXT_PORT="8080"
116+
INT_PORT="8080"
117+
break
118+
;;
119+
120+
"80/tcp")
121+
EXT_PORT="80"
122+
INT_PORT="80"
123+
break
124+
;;
125+
126+
*)
127+
;;
128+
esac
129+
done
130+
117131
if [[ "$EXT_PORT" == "" ]] || [[ "$INT_PORT" == "" ]]; then
118132
echo -n > "$DOKKU_ROOT/$APP/URL"
119133
verbose "No external HTTP port published"
@@ -130,15 +144,15 @@ case "$1" in
130144

131145
if [[ "$PREBOOT" != "" ]]; then
132146
verbose "Running pre-flight checks..."
133-
if ! pluginhook check-preboot "$APP" "$id" "$EXT_PORT"
147+
if ! pluginhook check-preboot "$APP" "$id" "$EXT_PORT" "$EXT_IP"
134148
then
135149
stop_and_remove_container "$id"
136150
fail "Application failed to deploy!"
137151
fi
138152
fi
139153

140-
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$EXT_PORT" > "$DOKKU_ROOT/$APP/URL"
141-
pluginhook post-deploy "$APP" "$EXT_PORT" "$INT_PORT"
154+
echo "http://$EXT_IP:$EXT_PORT" > "$DOKKU_ROOT/$APP/URL"
155+
pluginhook post-deploy "$APP" "$EXT_PORT" "$INT_PORT" "$EXT_IP"
142156
info2 "Application deployed:"
143157
verbose "$(dokku url $APP)"
144158
fi

plugins/dokku_common

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22

3-
APP_PORT="${APP_PORT:=5000}"
43
BUILDSTEP_IMAGE="${BUILDSTEP_IMAGE:=ayufan/dokku-alt-buildstep:foreman}"
54

65
set -eo pipefail

plugins/nginx-vhosts/post-deploy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "$(dirname $0)/vars"
44

5-
APP="$1"; PORT="$2"; INT_PORT="$3"
5+
APP="$1"; PORT="$2"; INT_PORT="$3"; IP="${4:-127.0.0.1}"
66
[[ "$INT_PORT" != "" ]] || INT_PORT="$APP_PORT"
77
WILDCARD_SSL="$DOKKU_ROOT/ssl"
88
SSL="$DOKKU_ROOT/$APP/ssl"
@@ -129,7 +129,7 @@ EOF
129129
}
130130

131131
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf
132-
upstream $APP { server 127.0.0.1:$PORT; }
132+
upstream $APP { server $IP:$PORT; }
133133
EOF
134134

135135
if [[ "$hostname" != "" ]]; then

0 commit comments

Comments
 (0)