2021-11-23 04:09:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2022-03-09 07:08:48 +00:00
|
|
|
set -o errexit
|
|
|
|
|
set -o nounset
|
|
|
|
|
set -o pipefail
|
|
|
|
|
set -o xtrace
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2022-03-24 00:34:38 +00:00
|
|
|
ssl_conf_path="/appsmith-stacks/data/certificate/conf"
|
2022-03-09 07:08:48 +00:00
|
|
|
|
2022-03-24 09:10:42 +00:00
|
|
|
mkdir -pv "$ssl_conf_path"
|
|
|
|
|
|
2022-03-24 00:34:38 +00:00
|
|
|
cat <<EOF > "$ssl_conf_path/options-ssl-nginx.conf"
|
|
|
|
|
# This file contains important security parameters. If you modify this file
|
|
|
|
|
# manually, Certbot will be unable to automatically provide future security
|
|
|
|
|
# updates. Instead, Certbot will print and log an error message with a path to
|
|
|
|
|
# the up-to-date file that you will need to refer to when manually updating
|
|
|
|
|
# this file.
|
|
|
|
|
|
|
|
|
|
ssl_session_cache shared:le_nginx_SSL:10m;
|
|
|
|
|
ssl_session_timeout 1440m;
|
|
|
|
|
ssl_session_tickets off;
|
|
|
|
|
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
|
ssl_prefer_server_ciphers off;
|
|
|
|
|
|
|
|
|
|
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
cat <<EOF > "$ssl_conf_path/ssl-dhparams.pem"
|
|
|
|
|
-----BEGIN DH PARAMETERS-----
|
|
|
|
|
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
|
|
|
|
|
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
|
|
|
|
|
87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
|
|
|
|
|
YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
|
|
|
|
|
7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
|
|
|
|
|
ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
|
|
|
|
|
-----END DH PARAMETERS-----
|
|
|
|
|
EOF
|
|
|
|
|
|
2022-07-21 07:33:35 +00:00
|
|
|
if [[ -z "${APPSMITH_ALLOWED_FRAME_ANCESTORS-}" ]]; then
|
2022-10-04 09:50:45 +00:00
|
|
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
|
|
|
|
|
export APPSMITH_ALLOWED_FRAME_ANCESTORS="'self'"
|
2022-07-21 07:33:35 +00:00
|
|
|
else
|
2022-10-04 09:50:45 +00:00
|
|
|
# Remove any extra rules that may be present in the frame ancestors value. This is to prevent this env variable from
|
|
|
|
|
# being used to inject more rules to the CSP header. If needed, that should be supported/solved separately.
|
|
|
|
|
export APPSMITH_ALLOWED_FRAME_ANCESTORS="${APPSMITH_ALLOWED_FRAME_ANCESTORS%;*}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z "${APPSMITH_DISABLE_IFRAME_WIDGET_SANDBOX-}" ]]; then
|
|
|
|
|
# For backwards compatibility, if this is not set to anything, we default to no sandbox for iframe widgets.
|
|
|
|
|
export APPSMITH_DISABLE_IFRAME_WIDGET_SANDBOX="true"
|
2022-07-21 07:33:35 +00:00
|
|
|
fi
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
# Check exist certificate with given custom domain
|
2022-03-24 07:47:36 +00:00
|
|
|
# Heroku not support for custom domain, only generate HTTP config if deploying on Heroku
|
2023-08-09 16:18:58 +00:00
|
|
|
use_https=0
|
2022-04-08 09:49:11 +00:00
|
|
|
if [[ -n ${APPSMITH_CUSTOM_DOMAIN-} ]] && [[ -z ${DYNO-} ]]; then
|
2023-08-09 16:18:58 +00:00
|
|
|
use_https=1
|
2022-03-24 07:47:36 +00:00
|
|
|
if ! [[ -e "/etc/letsencrypt/live/$APPSMITH_CUSTOM_DOMAIN" ]]; then
|
|
|
|
|
source "/opt/appsmith/init_ssl_cert.sh"
|
2022-04-08 09:49:11 +00:00
|
|
|
if ! init_ssl_cert "$APPSMITH_CUSTOM_DOMAIN"; then
|
|
|
|
|
echo "Status code from init_ssl_cert is $?"
|
2023-08-09 16:18:58 +00:00
|
|
|
use_https=0
|
2022-04-08 09:49:11 +00:00
|
|
|
fi
|
2022-03-24 07:47:36 +00:00
|
|
|
fi
|
2021-11-23 04:09:13 +00:00
|
|
|
fi
|
|
|
|
|
|
2023-09-27 08:08:47 +00:00
|
|
|
/opt/appsmith/templates/nginx-app.conf.sh "$use_https" "${APPSMITH_CUSTOM_DOMAIN-}"
|
|
|
|
|
|
|
|
|
|
cp -r /opt/appsmith/editor/* "$NGINX_WWW_PATH"
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2023-05-19 12:45:49 +00:00
|
|
|
apply-env-vars() {
|
|
|
|
|
original="$1"
|
|
|
|
|
served="$2"
|
|
|
|
|
node -e '
|
|
|
|
|
const fs = require("fs")
|
|
|
|
|
const content = fs.readFileSync("'"$original"'", "utf8").replace(
|
|
|
|
|
/\b__(APPSMITH_[A-Z0-9_]+)__\b/g,
|
|
|
|
|
(placeholder, name) => (process.env[name] || "")
|
|
|
|
|
)
|
|
|
|
|
fs.writeFileSync("'"$served"'", content)
|
|
|
|
|
'
|
2023-05-31 09:57:12 +00:00
|
|
|
pushd "$(dirname "$served")"
|
|
|
|
|
gzip --keep --force "$(basename "$served")"
|
|
|
|
|
popd
|
2023-05-19 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-27 08:08:47 +00:00
|
|
|
apply-env-vars /opt/appsmith/editor/index.html "$NGINX_WWW_PATH/index.html"
|
2021-11-23 04:09:13 +00:00
|
|
|
|
2022-03-24 08:17:25 +00:00
|
|
|
exec nginx -g "daemon off;error_log stderr info;"
|