-
Notifications
You must be signed in to change notification settings - Fork 49
Fixes #1875 - Add Nginx SMTP dummy #1883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bwbroersma
wants to merge
2
commits into
internetstandards:main
Choose a base branch
from
bwbroersma:gh1883-add-nginx-smtp-dummy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
|
|
||
| ME=$(basename "$0") | ||
|
|
||
| entrypoint_log() { | ||
| if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then | ||
| echo "$@" | ||
| fi | ||
| } | ||
|
|
||
| ensure_output_writable() { | ||
| local test_dir=$1 | ||
| if [ ! -w "$test_dir" ]; then | ||
| entrypoint_log "$ME: ERROR: $template_dir exists, but $test_dir is not writable" | ||
| exit 0 | ||
| fi | ||
| } | ||
|
|
||
| add_extra_block() { | ||
| local extra=$1 | ||
| local extra_output_dir=$2 | ||
| local conffile="/etc/nginx/nginx.conf" | ||
|
|
||
| if grep -q -E "\s*$extra\s*\{" "$conffile"; then | ||
| entrypoint_log "$ME: $conffile contains a $extra block; include $extra_output_dir/*.conf to enable $extra templates" | ||
| else | ||
| # check if the file can be modified, e.g. not on a r/o filesystem | ||
| touch "$conffile" 2>/dev/null || { entrypoint_log "$ME: info: can not modify $conffile (read-only file system?)"; exit 0; } | ||
| entrypoint_log "$ME: Appending $extra block to $conffile to include $extra_output_dir/*.conf" | ||
| cat << END >> "$conffile" | ||
| # added by "$ME" on "$(date)" | ||
| $extra { | ||
| include $extra_output_dir/*.conf; | ||
| } | ||
| END | ||
| fi | ||
| } | ||
|
|
||
| write_template_conf() { | ||
| local select_suffix=$1 | ||
| local conf_output_dir=$2 | ||
| local template relative_path output_path subdir | ||
| find "$template_dir" -follow -type f -name "*$select_suffix" -print | while read -r template; do | ||
| relative_path="${template#"$template_dir/"}" | ||
| output_path="$conf_output_dir/${relative_path%"$select_suffix"}" | ||
| subdir=$(dirname "$relative_path") | ||
| # create a subdirectory where the template file exists | ||
| mkdir -p "$conf_output_dir/$subdir" | ||
| entrypoint_log "$ME: Running envsubst on $template to $output_path" | ||
| envsubst "$defined_envs" < "$template" > "$output_path" | ||
| done | ||
| } | ||
|
|
||
| auto_envsubst() { | ||
| local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}" | ||
| local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}" | ||
| local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}" | ||
| local mail_suffix="${NGINX_ENVSUBST_MAIL_TEMPLATE_SUFFIX:-.mail-template}" | ||
| local mail_output_dir="${NGINX_ENVSUBST_MAIL_OUTPUT_DIR:-/etc/nginx/mail-conf.d}" | ||
| local stream_suffix="${NGINX_ENVSUBST_STREAM_TEMPLATE_SUFFIX:-.stream-template}" | ||
| local stream_output_dir="${NGINX_ENVSUBST_STREAM_OUTPUT_DIR:-/etc/nginx/stream-conf.d}" | ||
| local filter="${NGINX_ENVSUBST_FILTER:-}" | ||
|
|
||
| local defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null )) | ||
| [ -d "$template_dir" ] || return 0 | ||
| ensure_output_writable "$output_dir" | ||
| write_template_conf "$suffix" "$output_dir" | ||
|
|
||
| # Print the first file with the stream suffix, this will be false if there are none | ||
| if test -n "$(find "$template_dir" -name "*$stream_suffix" -print -quit)"; then | ||
| mkdir -p "$stream_output_dir" | ||
| ensure_output_writable "$stream_output_dir" | ||
| add_extra_block "stream" "$stream_output_dir" | ||
| write_template_conf "$stream_suffix" "$stream_output_dir" | ||
| fi | ||
| if test -n "$(find "$template_dir" -name "*$mail_suffix" -print -quit)"; then | ||
| mkdir -p "$mail_output_dir" | ||
| ensure_output_writable "$mail_output_dir" | ||
| add_extra_block "mail" "$mail_output_dir" | ||
| write_template_conf "$mail_suffix" "$mail_output_dir" | ||
| fi | ||
| } | ||
|
|
||
| auto_envsubst | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| server_name ${SMTP_EHLO_DOMAIN}; | ||
| auth_http http://${SMTP_AUTH_HTTP_ENDPOINT}/; | ||
|
|
||
| starttls only; | ||
|
|
||
| include conf.d/tls.conf; | ||
|
|
||
| server { | ||
| listen 25; | ||
| listen [::]:25; | ||
| protocol smtp; | ||
| smtp_capabilities "SIZE 1099511627776" ENHANCEDSTATUSCODES 8BITMIME DSN SMTPUTF8 REQUIRETLS; | ||
| } |
11 changes: 11 additions & 0 deletions
11
docker/webserver/nginx_templates/smtp_auth_http.conf.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # for mail auth_http | ||
| server { | ||
| listen ${SMTP_AUTH_HTTP_ENDPOINT}; | ||
| location / { | ||
| default_type text/plain; | ||
| add_header Auth-Status "Login not supported since this is a dummy nginx smtp handler"; | ||
| add_header Auth-Error-Code "550 5.3.5"; | ||
| add_header Auth-Wait 1; | ||
| return 200; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here why this file is needed and link to the nginx docker upstream PR, so we known where it is based on and if/when it can be removed in favor of upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.