PromucFlow_constructor/deploy/docker/scripts/run-java.sh
Shrikant Sharat Kandula 5e35c1fdae
feat: Support for proxy authentication (#20929)
Appsmith supports running with a HTTP proxy, that can be configured with
`HTTP_PROXY` or `HTTPS_PROXY` env variables. Like this:

```sh
HTTP_PROXY=http://myproxy:8080
HTTPS_PROXY=http://myproxy:8443
```

However, this proxy support didn't support authentication. This PR
implements that. Now, proxy with authentication can be configured like
this:

```sh
HTTP_PROXY=http://user:password@myproxy:8080
HTTPS_PROXY=http://user:password@myproxy:8080
```

This is not syntax or standards invented by Appsmith. This is the
standard way proxy is usually configured.

Fixes #16330

🍰
2023-02-24 14:53:08 +05:30

72 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
set -o noglob
declare -a proxy_args
proxy_configured=0
match-proxy-url() {
# Examples:
# http://proxy.example.com:8080/
# http://user:pass@proxyhost:123
# http://proxyhost:123
[[ $1 =~ ^http://(([^@:]*):([^@]*)?@)?([^@:]*):([0-9]+)/?$ ]]
proxy_user="${BASH_REMATCH[2]-}"
proxy_pass="${BASH_REMATCH[3]-}"
proxy_host="${BASH_REMATCH[4]-}"
proxy_port="${BASH_REMATCH[5]-}"
[[ -n $proxy_host ]]
}
if match-proxy-url "${HTTP_PROXY-}"; then
proxy_args+=(-Dhttp.proxyHost="$proxy_host" -Dhttp.proxyPort="$proxy_port")
if [[ -n $proxy_user ]]; then
proxy_args+=(-Dhttp.proxyUser="$proxy_user")
fi
if [[ -n $proxy_pass ]]; then
proxy_args+=(-Dhttp.proxyPassword="$proxy_pass")
fi
proxy_configured=1
fi
if match-proxy-url "${HTTPS_PROXY-}"; then
proxy_args+=(-Dhttps.proxyHost="$proxy_host" -Dhttps.proxyPort="$proxy_port")
if [[ -n $proxy_user ]]; then
proxy_args+=(-Dhttps.proxyUser="$proxy_user")
fi
if [[ -n $proxy_pass ]]; then
proxy_args+=(-Dhttps.proxyPassword="$proxy_pass")
fi
proxy_configured=1
fi
if [[ -z "${NO_PROXY-}" ]]; then
# A default for this value is set in entrypoint.sh script.
# If this variable is not set, just set it to empty string.
NO_PROXY=""
fi
if [[ $proxy_configured == 1 ]]; then
proxy_args+=(-Djava.net.useSystemProxies=true -Dhttp.nonProxyHosts="${NO_PROXY//,/|}")
fi
# Wait until RTS started and listens on port 8091
while ! curl --fail --silent localhost/rts-api/v1/health-check; do
echo 'Waiting for RTS to start ...'
sleep 1
done
echo 'RTS started.'
# Ref -Dlog4j2.formatMsgNoLookups=true https://spring.io/blog/2021/12/10/log4j2-vulnerability-and-spring-boot
exec java ${APPSMITH_JAVA_ARGS:-} ${APPSMITH_JAVA_HEAP_ARG:-} \
--add-opens java.base/java.time=ALL-UNNAMED \
-Dserver.port=8080 \
-Djava.security.egd=file:/dev/./urandom \
-Dlog4j2.formatMsgNoLookups=true \
"${proxy_args[@]}" \
-jar server.jar