15 Commits

Author SHA1 Message Date
snyk-bot
8bc41dbba9 fix: Dockerfile to reduce vulnerabilities
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-ALPINE315-OPENSSL-5661569
- https://snyk.io/vuln/SNYK-ALPINE315-OPENSSL-5661569
2023-06-07 03:14:47 +00:00
Tsuyoshi Yamasaki
193a9292ad fix: Update some actions to run on Node 16 instead of Node 12. 2023-03-16 12:32:54 -05:00
Tsuyoshi Yamasaki
5990535987 fix: Update some actions to run on Node 16 instead of Node 12. 2023-03-16 12:32:54 -05:00
snyk-bot
98e6ef216a fix: Update Dockerfile base image to alpine 3.15
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-ALPINE313-OPENSSL-2941811
- https://snyk.io/vuln/SNYK-ALPINE313-OPENSSL-2941811
2022-07-07 21:10:07 -05:00
Joost van den Broek
5ba18a151e feat: Add IPv6 support 2022-06-29 18:58:42 -05:00
Nasser
ceab4779d9 feat: Add message_size_limit option (#86)
* feat: Add MESSAGE_SIZE_LIMIT configuration option (PR #86)
2022-06-20 16:38:09 -05:00
Juan Luis Baptiste
1426f26546 Fix fix: tag doc in PR tempalte. 2022-05-13 10:06:21 -05:00
Juan Luis Baptiste
7d8086dd01 Add usage comments to bug and PR templates
to tell users to remove unncesary parts before submitting.
2022-05-13 10:05:01 -05:00
Andrey Andreev
7a9b9513a7 fix: read passwords from files 2022-05-13 09:22:27 -05:00
Nico Weichbrodt
a80ceca118 feat: Allow disabling SMTPUTF8 2022-04-20 22:59:41 -05:00
linucksrox
f280c00f87 feat: Add ENV option to enable subject line logging 2022-04-04 16:40:35 -05:00
nick
f831f935b9 Correct sasl_passwd file creation method 2021-07-08 21:23:43 -05:00
nick
222d3fad72 feat: Parameterize destination config value 2021-07-08 21:23:43 -05:00
BuildTools
8011cddf8a feat: Add support to load username from file 2021-05-22 21:54:18 -05:00
Juan Luis Baptiste
543ac4aa8d Added a pull request template 2021-05-22 20:27:08 -05:00
8 changed files with 124 additions and 23 deletions

View File

@@ -28,3 +28,15 @@
# Optional: This will rewrite the from address overwriting it with the specified address for all email being relayed. # Optional: This will rewrite the from address overwriting it with the specified address for all email being relayed.
#OVERWRITE_FROM="Your Name" <email@company.com> #OVERWRITE_FROM="Your Name" <email@company.com>
# Optional: This will use allow you to set a custom $mydestination value. Default is localhost.
#DESTINATION=
# Optional: This will output the subject line of messages in the log.
#LOG_SUBJECT=yes
# Optional: This will disable (no) or enable (yes) the use of SMTPUTF8
#SMTPUTF8_ENABLE=no
# Optional: This will use allow you to set a custom $message_size_limit value. Default is 10240000.
#MESSAGE_SIZE_LIMIT=

View File

@@ -6,12 +6,14 @@ labels: ''
assignees: '' assignees: ''
--- ---
<!-- BEFORE SUBMITTING YOUR PR, PLEASE REMOVE THIS TEXT -->
<!-- REMOVE START -->
**Reporting a bug** **Reporting a bug**
First of all, this is **not** a problem reporting forum, only report if you are pretty sure what you are experiencing is a bug with this image, not a configuration issue, for that you can use the [Github discussions section](https://github.com/juanluisbaptiste/docker-postfix/discussions) and we will do our best to help you to figure out what's going on with your setup. First of all, this is **not** a problem reporting forum, only report if you are pretty sure what you are experiencing is a bug with this image, not a configuration issue, for that you can use the [Github discussions section](https://github.com/juanluisbaptiste/docker-postfix/discussions) and we will do our best to help you to figure out what's going on with your setup.
Also be sure you are using the latest image by doing _docker pull juanluisbaptiste/postfix:latest_. Also be sure you are using the latest image by doing _docker pull juanluisbaptiste/postfix:latest_.
<!-- REMOVE END -->
**Please include the contents of:** **Please include the contents of:**

39
.github/pull_request_template.md vendored Normal file
View File

@@ -0,0 +1,39 @@
<!-- BEFORE SUBMITTING YOUR PR, PLEASE REMOVE THIS TEXT -->
<!-- REMOVE START -->
# Creating a Pull Request
We use github actions to do automatic [semantic versioning](https://github.com/semantic-release/semantic-release), so please use the following nomenclature for the commit message according to the type of change:
* Prefix with `feat:`, and it will trigger a minor version bump.
* Prefix with `fix:`, and it will trigger a patch version bump.
* Prefix with `BREAKING CHANGE:`, and it will trigger a major version bump.
<!-- REMOVE END -->
## Description of the change
<!--Please be very clear on the intention of the modifications included in the pull request.-->
<!--If it is a bug, explain what is the issue at hand and how you are fixing it. -->
<!--If it is an improvement, explain why do you think it is needed and the benefits it brings to the project. -->
<!--Ideally I would recommend to create an issue first to discuss the new feature with the developers.-->
## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
## Types of Changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation (adding or updating documentation)
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My change requires a change to the documentation and I have updated the documentation accordingly.
- [ ] My change adds a new configuration variable and I have updated the `.env.example` file accordingly.
And lastly, many thanks for taking your time to help us improve this project !

View File

@@ -11,7 +11,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
token: ${{ secrets.API_GITHUB_TOKEN }} token: ${{ secrets.API_GITHUB_TOKEN }}
@@ -28,19 +28,19 @@ jobs:
alpine alpine
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v2
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v3.3.1
with: with:
push: true push: true
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64

View File

@@ -13,23 +13,23 @@ jobs:
steps: steps:
- name: Checkout with token - name: Checkout with token
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
token: ${{ secrets.API_GITHUB_TOKEN }} token: ${{ secrets.API_GITHUB_TOKEN }}
- name: Checkout without token - name: Checkout without token
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v2
- name: Docker Build Test - name: Docker Build Test
run: docker buildx build --load --tag test:test --file ./Dockerfile ./ run: docker buildx build --load --tag test:test --file ./Dockerfile ./
- name: Version - name: Version
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
uses: cycjimmy/semantic-release-action@v2.5.3 uses: cycjimmy/semantic-release-action@v3
with: with:
semantic_version: 17.4 semantic_version: 17.4
env: env:

View File

@@ -1,5 +1,5 @@
#Dockerfile for a Postfix email relay service #Dockerfile for a Postfix email relay service
FROM alpine:3.13 FROM alpine:3
MAINTAINER Juan Luis Baptiste juan.baptiste@gmail.com MAINTAINER Juan Luis Baptiste juan.baptiste@gmail.com
RUN apk update && \ RUN apk update && \

View File

@@ -66,12 +66,25 @@ The following env variable(s) are optional.
* `SMTP_PASSWORD_FILE` Setting this to a mounted file containing the password, to avoid passwords in env variables. Used like * `SMTP_PASSWORD_FILE` Setting this to a mounted file containing the password, to avoid passwords in env variables. Used like
-e SMTP_PASSWORD_FILE=/secrets/smtp_password -e SMTP_PASSWORD_FILE=/secrets/smtp_password
-v $(pwd)/secrets/:/secrets/ -v $(pwd)/secrets/:/secrets/
* `SMTP_USERNAME_FILE` Setting this to a mounted file containing the username, to avoid usernames in env variables. Used like
-e SMTP_USERNAME_FILE=/secrets/smtp_username
-v $(pwd)/secrets/:/secrets/
* `ALWAYS_ADD_MISSING_HEADERS` This is related to the [always\_add\_missing\_headers](http://www.postfix.org/postconf.5.html#always_add_missing_headers) Postfix option (default: `no`). If set to `yes`, Postfix will always add missing headers among `From:`, `To:`, `Date:` or `Message-ID:`. * `ALWAYS_ADD_MISSING_HEADERS` This is related to the [always\_add\_missing\_headers](http://www.postfix.org/postconf.5.html#always_add_missing_headers) Postfix option (default: `no`). If set to `yes`, Postfix will always add missing headers among `From:`, `To:`, `Date:` or `Message-ID:`.
* `OVERWRITE_FROM` This will rewrite the from address overwriting it with the specified address for all email being relayed. Example settings: * `OVERWRITE_FROM` This will rewrite the from address overwriting it with the specified address for all email being relayed. Example settings:
OVERWRITE_FROM=email@company.com OVERWRITE_FROM=email@company.com
OVERWRITE_FROM="Your Name" <email@company.com> OVERWRITE_FROM="Your Name" <email@company.com>
* `DESTINATION` This will define a list of domains from which incoming messages will be accepted.
* `LOG_SUBJECT` This will output the subject line of messages in the log.
* `SMTPUTF8_ENABLE` This will enable (default) or disable support for SMTPUTF8. Valid values are `no` to disable and `yes` to enable. Not setting this variable will use the postfix default, which is `yes`.
* `MESSAGE_SIZE_LIMIT` This will change the default limit of 10240000 bytes (10MB).
To use this container from anywhere, the 25 port or the one specified by `SMTP_PORT` needs to be exposed to the docker host server: To use this container from anywhere, the 25 port or the one specified by `SMTP_PORT` needs to be exposed to the docker host server:
docker run -d --name postfix -p "25:25" \ docker run -d --name postfix -p "25:25" \

47
run.sh
View File

@@ -13,8 +13,9 @@ function add_config_value() {
postconf -e "${key} = ${value}" postconf -e "${key} = ${value}"
} }
# Read password from file to avoid unsecure env variables # Read password and username from file to avoid unsecure env variables
if [ -n "${SMTP_PASSWORD_FILE}" ]; then [ -f "${SMTP_PASSWORD_FILE}" ] && read SMTP_PASSWORD < ${SMTP_PASSWORD_FILE} || echo "SMTP_PASSWORD_FILE defined, but file not existing, skipping."; fi if [ -n "${SMTP_PASSWORD_FILE}" ]; then [ -e "${SMTP_PASSWORD_FILE}" ] && SMTP_PASSWORD=$(cat "${SMTP_PASSWORD_FILE}") || echo "SMTP_PASSWORD_FILE defined, but file not existing, skipping."; fi
if [ -n "${SMTP_USERNAME_FILE}" ]; then [ -e "${SMTP_USERNAME_FILE}" ] && SMTP_USERNAME=$(cat "${SMTP_USERNAME_FILE}") || echo "SMTP_USERNAME_FILE defined, but file not existing, skipping."; fi
[ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1 [ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1
[ -z "${SERVER_HOSTNAME}" ] && echo "SERVER_HOSTNAME is not set" && exit 1 [ -z "${SERVER_HOSTNAME}" ] && echo "SERVER_HOSTNAME is not set" && exit 1
@@ -29,7 +30,7 @@ DOMAIN=`echo ${SERVER_HOSTNAME} | awk 'BEGIN{FS=OFS="."}{print $(NF-1),$NF}'`
add_config_value "maillog_file" "/dev/stdout" add_config_value "maillog_file" "/dev/stdout"
add_config_value "myhostname" ${SERVER_HOSTNAME} add_config_value "myhostname" ${SERVER_HOSTNAME}
add_config_value "mydomain" ${DOMAIN} add_config_value "mydomain" ${DOMAIN}
add_config_value "mydestination" 'localhost' add_config_value "mydestination" "${DESTINATION:-localhost}"
add_config_value "myorigin" '$mydomain' add_config_value "myorigin" '$mydomain'
add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}" add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}"
add_config_value "smtp_use_tls" "yes" add_config_value "smtp_use_tls" "yes"
@@ -48,6 +49,9 @@ if [ "${SMTP_PORT}" = "465" ]; then
add_config_value "smtp_tls_security_level" "encrypt" add_config_value "smtp_tls_security_level" "encrypt"
fi fi
# Bind to both IPv4 and IPv4
add_config_value "inet_protocols" "all"
# Create sasl_passwd file with auth credentials # Create sasl_passwd file with auth credentials
if [ ! -f /etc/postfix/sasl_passwd -a ! -z "${SMTP_USERNAME}" ]; then if [ ! -f /etc/postfix/sasl_passwd -a ! -z "${SMTP_USERNAME}" ]; then
grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1 grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1
@@ -60,24 +64,49 @@ fi
#Set header tag #Set header tag
if [ ! -z "${SMTP_HEADER_TAG}" ]; then if [ ! -z "${SMTP_HEADER_TAG}" ]; then
postconf -e "header_checks = regexp:/etc/postfix/header_tag" postconf -e "header_checks = regexp:/etc/postfix/header_checks"
echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" > /etc/postfix/header_tag echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" >> /etc/postfix/header_checks
echo "Setting configuration option SMTP_HEADER_TAG with value: ${SMTP_HEADER_TAG}" echo "Setting configuration option SMTP_HEADER_TAG with value: ${SMTP_HEADER_TAG}"
fi fi
#Enable logging of subject line
if [ "${LOG_SUBJECT}" == "yes" ]; then
postconf -e "header_checks = regexp:/etc/postfix/header_checks"
echo -e "/^Subject:/ WARN" >> /etc/postfix/header_checks
echo "Enabling logging of subject line"
fi
#Check for subnet restrictions #Check for subnet restrictions
nets='10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16' nets='10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16'
if [ ! -z "${SMTP_NETWORKS}" ]; then if [ ! -z "${SMTP_NETWORKS}" ]; then
declare ipv6re="^((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|\
([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|\
([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|\
([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|\
:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}|\
::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|\
(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|\
(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3})$"
for i in $(sed 's/,/\ /g' <<<$SMTP_NETWORKS); do for i in $(sed 's/,/\ /g' <<<$SMTP_NETWORKS); do
if grep -Eq "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}" <<<$i ; then if grep -Eq "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}" <<<$i ; then
nets+=", $i" nets+=", $i"
elif grep -Eq "$ipv6re" <<<$i ; then
readarray -d \/ -t arr < <(printf '%s' "$i")
nets+=", [${arr[0]}]/${arr[1]}"
else else
echo "$i is not in proper IPv4 subnet format. Ignoring." echo "$i is not in proper IPv4 or IPv6 subnet format. Ignoring."
fi fi
done done
fi fi
add_config_value "mynetworks" "${nets}" add_config_value "mynetworks" "${nets}"
# Set SMTPUTF8
if [ ! -z "${SMTPUTF8_ENABLE}" ]; then
postconf -e "smtputf8_enable = ${SMTPUTF8_ENABLE}"
echo "Setting configuration option smtputf8_enable with value: ${SMTPUTF8_ENABLE}"
fi
if [ ! -z "${OVERWRITE_FROM}" ]; then if [ ! -z "${OVERWRITE_FROM}" ]; then
echo -e "/^From:.*$/ REPLACE From: $OVERWRITE_FROM" > /etc/postfix/smtp_header_checks echo -e "/^From:.*$/ REPLACE From: $OVERWRITE_FROM" > /etc/postfix/smtp_header_checks
postmap /etc/postfix/smtp_header_checks postmap /etc/postfix/smtp_header_checks
@@ -85,6 +114,12 @@ if [ ! -z "${OVERWRITE_FROM}" ]; then
echo "Setting configuration option OVERWRITE_FROM with value: ${OVERWRITE_FROM}" echo "Setting configuration option OVERWRITE_FROM with value: ${OVERWRITE_FROM}"
fi fi
# Set message_size_limit
if [ ! -z "${MESSAGE_SIZE_LIMIT}" ]; then
postconf -e "message_size_limit = ${MESSAGE_SIZE_LIMIT}"
echo "Setting configuration option message_size_limit with value: ${MESSAGE_SIZE_LIMIT}"
fi
#Start services #Start services
# If host mounting /var/spool/postfix, we need to delete old pid file before # If host mounting /var/spool/postfix, we need to delete old pid file before