Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions build/scripts/orchestrated/proxy-docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ fi

envsubst < /tmp/proxy_nginx/includes/http-upstream.conf > /tmp/http-upstream.conf
envsubst < /etc/nginx/includes/ds-common.conf | tee /tmp/proxy_nginx/includes/ds-common.conf > /dev/null
sed "s,\(set \+\$secure_link_secret\).*,\1 "${SECURE_LINK_SECRET:-verysecretstring}";," -i /tmp/proxy_nginx/conf.d/ds.conf
# The secret ends up in nginx's "set $secure_link_secret ...;" line through sed;
# characters such as a backslash, comma, ; or whitespace would break that line.
case "${SECURE_LINK_SECRET:-}" in
*[!A-Za-z0-9._~+=/:@%!*^-]*)
echo "ERROR: SECURE_LINK_SECRET may only contain letters, digits and . _ ~ + = / : @ % ! * ^ -" >&2
exit 1
;;
esac
# sed and htpasswd get secrets on stdin, not as arguments: the arguments of a
# process can be read by other users of the host and end up in audit logs.
printf '%s\n' "s,\(set \+\$secure_link_secret\).*,\1 ${SECURE_LINK_SECRET:-verysecretstring};," \
| sed -f /dev/stdin -i /tmp/proxy_nginx/conf.d/ds.conf
sed "s/\(client_max_body_size\).*/\1 $NGINX_CLIENT_MAX_BODY_SIZE;/" -i /tmp/proxy_nginx/includes/ds-common.conf

if [[ ! -f "/proc/net/if_inet6" ]]; then
Expand Down Expand Up @@ -53,7 +64,7 @@ if [[ -n "$INFO_ALLOWED_IP" ]]; then
fi

if [[ -n "$INFO_ALLOWED_USER" ]]; then
htpasswd -c -b /tmp/auth "${INFO_ALLOWED_USER}" "${INFO_ALLOWED_PASSWORD:-password}"
printf '%s\n' "${INFO_ALLOWED_PASSWORD:-password}" | htpasswd -c -i /tmp/auth "${INFO_ALLOWED_USER}"
sed -i '/(info)/a\ auth_basic \"Authentication Required\"\;' /tmp/proxy_nginx/includes/ds-docservice.conf
sed -i '/auth_basic/a\ auth_basic_user_file \/tmp\/auth\;' /tmp/proxy_nginx/includes/ds-docservice.conf
fi
Expand Down
61 changes: 46 additions & 15 deletions build/scripts/standalone/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ if [ -z "${SECURE_LINK_SECRET:-}" ]; then
chmod 600 "$SECURE_LINK_SECRET_FILE"
fi
fi
# The secret ends up in nginx's "set $secure_link_secret ...;" line through sed.
# A backslash, comma, &, ;, #, $, quote, brace or whitespace there breaks that
# line, so every download fails while /healthcheck still reports OK.
case "$SECURE_LINK_SECRET" in
*[!A-Za-z0-9._~+=/:@%!*^-]*)
echo "ERROR: SECURE_LINK_SECRET may only contain letters, digits and . _ ~ + = / : @ % ! * ^ -" >&2
exit 1
;;
esac

# --------------------------------------------------------------------
# WOPI keypair (only generate/read when WOPI_ENABLED=true).
Expand Down Expand Up @@ -192,8 +201,20 @@ fi
#
# Booleans are coerced via string comparison ($var == "true") so malformed
# input degrades to false rather than crashing jq.
# --------------------------------------------------------------------
jq_filter='.'
#
# Secrets come in through jq's environment ($ENV), not through --arg: the
# arguments of a process can be read by other users of the host and end up
# in process audit logs, its environment can't and doesn't.
# --------------------------------------------------------------------
jq_filter='$ENV.EO_JQ_JWT_SECRET as $jwtSecret
| $ENV.EO_JQ_JWT_SECRET_INBOX as $jwtSecretInbox
| $ENV.EO_JQ_JWT_SECRET_OUTBOX as $jwtSecretOutbox
| $ENV.EO_JQ_DB_PASS as $dbPass
| $ENV.EO_JQ_REDIS_PASS as $redisPass
| $ENV.EO_JQ_AMQP_URI as $amqpUri
| $ENV.EO_JQ_WOPI_PRIV as $wopiPriv
| $ENV.EO_JQ_SECURE_LINK_SECRET as $secureLinkSecret
| .'

jq_set() { jq_filter="$jq_filter | $*"; }

Expand Down Expand Up @@ -247,6 +268,10 @@ if [ "$WOPI_ENABLED" = "true" ]; then
jq_set '.wopi.exponentOld = ($wopiExp | tonumber? // $wopiExp)'
fi

# Secret of the signed links to cached files. Replaces the whole storage
# block, as documentserver-update-securelink.sh did.
jq_set '.storage = { "fs": { "secretString": $secureLinkSecret } }'

# Request filtering
[ "$USE_UNAUTHORIZED_STORAGE" = "true" ] && \
jq_set '.services.CoAuthoring.requestDefaults.rejectUnauthorized = false'
Expand Down Expand Up @@ -296,30 +321,31 @@ case "$AMQP_VHOST_PATH" in
esac
AMQP_URI_VALUE="${AMQP_URI:-amqp://${AMQP_USER:-guest}:${AMQP_PWD:-guest}@${AMQP_HOST}:${AMQP_PORT}${AMQP_VHOST_PATH}}"

EO_JQ_JWT_SECRET="$JWT_SECRET" \
EO_JQ_JWT_SECRET_INBOX="$JWT_SECRET_INBOX" \
EO_JQ_JWT_SECRET_OUTBOX="$JWT_SECRET_OUTBOX" \
EO_JQ_DB_PASS="${DB_PWD:-}" \
EO_JQ_REDIS_PASS="${REDIS_SERVER_PASS:-}" \
EO_JQ_AMQP_URI="$AMQP_URI_VALUE" \
EO_JQ_WOPI_PRIV="$WOPI_PRIVATE_KEY_DATA" \
EO_JQ_SECURE_LINK_SECRET="$SECURE_LINK_SECRET" \
jq \
--arg jwtEnabled "$JWT_ENABLED" \
--arg jwtEnabledInbox "$JWT_ENABLED_INBOX" \
--arg jwtEnabledOutbox "$JWT_ENABLED_OUTBOX" \
--arg jwtInBody "$JWT_IN_BODY" \
--arg jwtSecret "$JWT_SECRET" \
--arg jwtSecretInbox "$JWT_SECRET_INBOX" \
--arg jwtSecretOutbox "$JWT_SECRET_OUTBOX" \
--arg jwtHeaderInbox "$JWT_HEADER_INBOX" \
--arg jwtHeaderOutbox "$JWT_HEADER_OUTBOX" \
--arg dbType "$DB_TYPE" \
--arg dbHost "$DB_HOST" \
--arg dbPort "$DB_PORT" \
--arg dbName "$DB_NAME" \
--arg dbUser "$DB_USER" \
--arg dbPass "${DB_PWD:-}" \
--arg redisHost "$REDIS_SERVER_HOST" \
--arg redisPort "$REDIS_SERVER_PORT" \
--arg redisUser "${REDIS_SERVER_USER:-}" \
--arg redisPass "${REDIS_SERVER_PASS:-}" \
--arg redisDb "${REDIS_SERVER_DB:-}" \
--arg amqpUri "$AMQP_URI_VALUE" \
--arg wopiEnabled "$WOPI_ENABLED" \
--arg wopiPriv "$WOPI_PRIVATE_KEY_DATA" \
--arg wopiPub "$WOPI_PUBLIC_KEY_DATA" \
--arg wopiMod "$WOPI_MODULUS" \
--arg wopiExp "${WOPI_EXPONENT:-65537}" \
Expand All @@ -332,6 +358,8 @@ jq \
"$jq_filter" \
"$CONFIG_FILE" > "${CONFIG_FILE}.tmp"
mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE"
# The services read this file as ds (documentserver-update-securelink.sh used to do this).
chown ds:ds "$CONFIG_FILE" 2>/dev/null || true

# --------------------------------------------------------------------
# log4js level
Expand Down Expand Up @@ -388,9 +416,13 @@ if [ ! -f /proc/net/if_inet6 ] && [ -f "$NGINX_DS_CONF" ]; then
sed -i '/listen[[:space:]]\+\[::[0-9]*\].\+/d' "$NGINX_DS_CONF"
fi

# Apply SECURE_LINK_SECRET via the bundled helper (also patches nginx ds.conf)
if command -v documentserver-update-securelink.sh >/dev/null 2>&1; then
documentserver-update-securelink.sh -s "$SECURE_LINK_SECRET" -r false || true
# Give nginx the secret of the signed links; $CONFIG_FILE got it above.
# documentserver-update-securelink.sh is not used here because it takes the
# secret as an argument. sed reads its script from stdin for the same reason
# (printf is a shell builtin, so the secret is in no argument list).
if [ -f "$NGINX_DS_CONF" ]; then
printf '%s\n' "s,\(set \+\$secure_link_secret\).*,\1 ${SECURE_LINK_SECRET};," \
| sed -i -f /dev/stdin "$NGINX_DS_CONF" || true
fi

# --------------------------------------------------------------------
Expand All @@ -417,8 +449,7 @@ enable_supervisor_program() {
# JWT_ENABLED=false also disables signing in the example.
# --------------------------------------------------------------------
if [ -d "$EXAMPLE_CONF_DIR" ]; then
jq -n \
--arg secret "$JWT_SECRET" \
EO_JQ_JWT_SECRET="$JWT_SECRET" jq -n \
--arg header "$JWT_HEADER" \
--arg jwtEnabled "$JWT_ENABLED" \
--arg maxFileSize "$MAX_FILE_SIZE" \
Expand All @@ -429,7 +460,7 @@ if [ -d "$EXAMPLE_CONF_DIR" ]; then
"maxFileSize": ($maxFileSize | tonumber? // $maxFileSize),
"token": {
"enable": ($jwtEnabled == "true"),
"secret": $secret,
"secret": $ENV.EO_JQ_JWT_SECRET,
"authorizationHeader": $header
}
}
Expand Down
Loading