-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-compose.yml
executable file
·259 lines (255 loc) · 11.3 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
version: "3.8"
services:
mailserver:
image: mailserver/docker-mailserver:11.1.0
mem_limit: 4G
mem_reservation: 2G
restart: on-failure:40
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "5m"
hostname: mail
domainname: ${DOMAIN_NAME}
dns: 1.1.1.1
stop_grace_period: 1m
networks:
mail_infra_network:
aliases:
- mail-server.${DOMAIN_NAME}
- imap.${DOMAIN_NAME}
- smtp.${DOMAIN_NAME}
- ldap.${DOMAIN_NAME}
- pop.${DOMAIN_NAME}
ports:
- "25:25" # SMTP (explicit TLS => STARTTLS)
- "143:143" # IMAP4 (explicit TLS => STARTTLS)
- "465:465" # ESMTP (implicit TLS)
- "587:587" # ESMTP (explicit TLS => STARTTLS)
- "993:993" # IMAP4 (implicit TLS)
- "110:110" # POP3
- "995:995" # POP3 (with TLS)
- "4190:4190" # Sieve filters
- "4177:4177" # Dovecot replication
volumes:
- ${MAIL_DATA_DIR}:/var/mail
- ${MAIL_STATE_DIR}:/var/mail-state
- ${MAIL_LOGS_DIR}:/var/log/mail
- ${MAIL_CONFIGS_DIR}:/tmp/docker-mailserver/
- ${USER_PATCHES_FILE:-./user-patches.sh}:/tmp/docker-mailserver/user-patches.sh:ro
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror3:/acme.sh/${DOMAIN_NAME}/
- ./cron/sa-learn:/etc/cron.d/sa-learn:ro
environment:
TZ: UTC
OVERRIDE_HOSTNAME: ${OVERRIDE_HOSTNAME}
ENABLE_SPAMASSASSIN: "1"
ENABLE_SPAMASSASSIN_KAM: "1"
SPAMASSASSIN_SPAM_TO_INBOX: "1"
ENABLE_CLAMAV: "1"
ENABLE_AMAVIS: "1"
ENABLE_FAIL2BAN: "1"
ENABLE_POSTGREY: "1"
ENABLE_POP3: "1"
ENABLE_MANAGESIEVE: "1"
ONE_DIR: "1"
LOG_LEVEL: "${LOG_LEVEL:-warn}"
ENABLE_LDAP: "1"
POSTGREY_DELAY: "${POSTGREY_DELAY:-300}"
LDAP_SERVER_HOST: "ldap.${DOMAIN_NAME}"
LDAP_SEARCH_BASE: "ou=people,${LDAP_BASE_DN}"
LDAP_BIND_DN: "cn=admin,${LDAP_BASE_DN}"
LDAP_BIND_PW: ${LDAP_ADMIN_PASSWORD}
LDAP_QUERY_FILTER_USER: "(&(mail=%s)(mailEnabled=TRUE))"
LDAP_QUERY_FILTER_GROUP: "(&(mailGroupMember=%s)(mailEnabled=TRUE))"
LDAP_QUERY_FILTER_ALIAS: "(|(&(mailAlias=%s)(objectClass=PostfixBookMailAccount))(&(mailAlias=%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE)))"
LDAP_QUERY_FILTER_DOMAIN: "(|(&(mail=*@%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE))(&(mailGroupMember=*@%s)(objectClass=PostfixBookMailAccount)(mailEnabled=TRUE))(&(mailalias=*@%s)(objectClass=PostfixBookMailAccount)))"
DOVECOT_PASS_FILTER: "(&(objectClass=PostfixBookMailAccount)(mail=%n@%d))"
DOVECOT_USER_FILTER: "(&(objectClass=PostfixBookMailAccount)(mail=%n@%d))"
DOVECOT_DEFAULT_PASS_SCHEME: "SSHA256"
TLS_LEVEL: "intermediate"
SASLAUTHD_LDAP_START_TLS: "no"
SASLAUTHD_LDAP_TLS_CHECK_PEER: "yes"
SASLAUTHD_LDAP_TLS_CACERT_FILE: "/acme.sh/${DOMAIN_NAME}/ca.cer"
ENABLE_SASLAUTHD: "1"
SASLAUTHD_MECHANISMS: "ldap"
SASLAUTHD_LDAP_SERVER: "ldaps://ldap.${DOMAIN_NAME}"
SASLAUTHD_LDAP_BIND_DN: "cn=admin,${LDAP_BASE_DN}"
SASLAUTHD_LDAP_PASSWORD: ${LDAP_ADMIN_PASSWORD}
SASLAUTHD_LDAP_SEARCH_BASE: "ou=people,${LDAP_BASE_DN}"
# For some odd reason %d is empty and %r containts the domain
# See: https://campus.barracuda.com/solution/50160000000GYmFAAW
SASLAUTHD_LDAP_FILTER: "(&(objectClass=PostfixBookMailAccount)(mail=%U@%r))"
SASLAUTHD_LDAP_AUTH_METHOD: "custom"
SASLAUTHD_LDAP_PASSWORD_ATTR: "saslUserPassword"
POSTFIX_MESSAGE_SIZE_LIMIT: "100000000"
DOVECOT_TLS: "yes"
DOVECOT_TLS_CACERT_FILE: "/acme.sh/${DOMAIN_NAME}/ca.cer"
DOVECOT_TLS_CERT_FILE: "/acme.sh/${DOMAIN_NAME}/fullchain.cer"
DOVECOT_TLS_KEY_FILE: "/acme.sh/${DOMAIN_NAME}/${DOMAIN_NAME}.key"
DOVECOT_TLS_VERIFY_CLIENT: "allow"
DOVECOT_ADM_PASS: "${DOVECOT_ADM_PASS}"
DOVECOT_REPLICA_SERVER: "${DOVECOT_REPLICA_SERVER}"
LDAP_START_TLS: "yes"
SSL_TYPE: "manual"
SSL_CERT_PATH: "/acme.sh/${DOMAIN_NAME}/fullchain.cer"
SSL_KEY_PATH: "/acme.sh/${DOMAIN_NAME}/${DOMAIN_NAME}.key"
# Daily report & reporting
POSTMASTER_ADDRESS: "${POSTMASTER_ADDRESS}"
VIRUS_ADMIN_EMAIL: "${VIRUS_ADMIN_EMAIL}"
VIRUS_X_HEADER_LINE: "${VIRUS_X_HEADER_LINE}"
PFLOGSUMM_RECIPIENT: "${PFLOGSUMM_RECIPIENT}"
PFLOGSUMM_TRIGGER: daily_cron
LOGWATCH_INTERVAL: daily
LOGWATCH_RECIPIENT: "${LOGWATCH_RECIPIENT}"
# Fail2ban config to allow IPs to make failed attempts
FAIL2BAN_IGNORE_IPS: "${FAIL2BAN_IGNORE_IPS}"
FAIL2BAN_DST_EMAIL: "${FAIL2BAN_DST_EMAIL}"
FAIL2BAN_SENDER_EMAIL: "${FAIL2BAN_SENDER_EMAIL}"
FAIL2BAN_SENDER_NAME: "${FAIL2BAN_SENDER_NAME}"
cap_add:
- NET_ADMIN
healthcheck:
test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
timeout: 3s
retries: 0
depends_on:
- openldap
- acme
openldap:
build: ./dockers/docker-openldap
restart: on-failure:5
mem_limit: 2G
mem_reservation: 100M
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "1m"
dns_search: ${DOMAIN_NAME}
hostname: ldap.${DOMAIN_NAME}
domainname: ldap.${DOMAIN_NAME}
healthcheck:
test: 'ldapwhoami -Z -D "cn=$${LDAP_READONLY_USER_USERNAME},$${LDAP_BASE_DN}" -w "$${LDAP_READONLY_USER_PASSWORD}"'
start_period: 10s
interval: 30s
timeout: 5s
retries: 3
networks:
mail_infra_network:
aliases:
- ldap.${DOMAIN_NAME}
environment:
# 256 to enable debug
# See: https://www.openldap.org/doc/admin24/slapdconf2.html
LDAP_LOG_LEVEL: 0
LDAP_OPENLDAP_GID: 0
LDAP_OPENLDAP_UID: 0
LDAP_TLS: "true"
LDAP_TLS_CRT_FILENAME: "${DOMAIN_NAME}.cer"
LDAP_TLS_KEY_FILENAME: "${DOMAIN_NAME}.key"
LDAP_TLS_CA_CRT_FILENAME: "ca.cer"
LDAP_TLS_CIPHER_SUITE: "NORMAL"
LDAP_TLS_VERIFY_CLIENT: "allow"
LDAP_TLS_ENFORCE: "true"
LDAP_ORGANISATION: ${LDAP_ORGANISATION}
LDAP_DOMAIN: "${DOMAIN_NAME}"
LDAP_BASE_DN: "${LDAP_BASE_DN}"
LDAP_ADMIN_PASSWORD: ${LDAP_ADMIN_PASSWORD}
LDAP_CONFIG_PASSWORD: ${LDAP_CONFIG_PASSWORD}
LDAP_READONLY_USER: "true"
LDAP_READONLY_USER_USERNAME: "ldap-ro"
LDAP_READONLY_USER_PASSWORD: ${LDAP_READONLY_PASSWORD}
LDAP_REMOVE_CONFIG_AFTER_SETUP: "false"
# LDAP_SEED_INTERNAL_LDIF_PATH: "/tmp/ldap-custom-ldif"
LDAP_SEED_INTERNAL_SCHEMA_PATH: "/tmp/ldap-custom-schema"
tty: true
stdin_open: true
volumes:
- ${LDAP_DATA_DIR}:/var/lib/ldap
- ${LDAP_SLAPD_DIR}:/etc/ldap/slapd.d
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror2/ca.cer:/container/service/slapd/assets/certs/ca.cer
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror2/fullchain.cer:/container/service/slapd/assets/certs/${DOMAIN_NAME}.cer
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror2/${DOMAIN_NAME}.key:/container/service/slapd/assets/certs/${DOMAIN_NAME}.key
- ${LDAP_CUSTOM_SCHEMA_DIR:-./data/ldap-custom-schema}:/tmp/ldap-custom-schema
# - ${LDAP_CUSTOM_LDIF_DIR:-./data/ldap-custom-ldif}:/tmp/ldap-custom-ldif
ports:
- "${LDAP_PORT:-389}:389"
- "${LDAPS_PORT:-636}:636"
depends_on:
acme:
condition: service_healthy
phpldapadmin:
image: osixia/phpldapadmin:latest
mem_limit: 512M
mem_reservation: 100M
restart: on-failure:5
logging:
driver: "json-file"
options:
max-file: "1"
max-size: "200k"
networks:
mail_infra_network:
aliases:
- ldap-admin.${DOMAIN_NAME}
healthcheck:
test: 'php -r ''$$c = is_string(file_get_contents("https://localhost?ping=pong", false, stream_context_create(["ssl" => ["verify_peer"=> false, "verify_peer_name"=> true, "peer_name"=> "${DOMAIN_NAME}", "peer_fingerprint" => openssl_x509_fingerprint(file_get_contents("/container/service/phpldapadmin/assets/apache2/certs/fullchain.cer")) ]]))); echo $$c; exit($$c === true ? 0 : 1);'''
interval: 30s
timeout: 3s
retries: 3
environment:
PHPLDAPADMIN_LDAP_HOSTS: "#PYTHON2BASH:[{'ldap.${DOMAIN_NAME}': [{'server': [{'tls': True}]},{'login': [{'bind_id': 'cn=admin,${LDAP_BASE_DN}'}]}]}]"
PHPLDAPADMIN_HTTPS_CRT_FILENAME: "fullchain.cer"
PHPLDAPADMIN_HTTPS_KEY_FILENAME: "${DOMAIN_NAME}.key"
PHPLDAPADMIN_HTTPS_CA_CRT_FILENAME: "ca.cer"
PHPLDAPADMIN_LDAP_CLIENT_TLS_REQCERT: "try"
PHPLDAPADMIN_LDAP_CLIENT_TLS: "true"
PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME: "ca.cer"
PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME: "fullchain.cer"
PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME: "${DOMAIN_NAME}.key"
volumes:
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror1:/container/service/phpldapadmin/assets/apache2/certs
- ${ACME_HOME_DIR}/${DOMAIN_NAME}-mirror1:/container/service/ldap-client/assets/certs
ports:
- "${PHPLDAPADMIN_SSL_PORT:-8080}:443"
depends_on:
openldap:
condition: service_healthy
acme:
condition: service_healthy
acme:
image: neilpang/acme.sh:latest
mem_limit: 512M
mem_reservation: 10M
restart: on-failure:15
logging:
driver: "json-file"
options:
max-file: "2"
max-size: "200k"
volumes:
- ./scripts:/scripts:ro
- ${ACME_HOME_DIR}:/acme.sh
working_dir: /scripts/
healthcheck:
test: ["CMD", "sh", "/scripts/healthcheck.sh"]
start_period: 10s
interval: 30s
timeout: 2s
retries: 30
environment:
# CloudFlare
CF_Key: ${CF_API_KEY}
CF_Email: ${CF_API_EMAIL}
DOMAIN_NAME: ${DOMAIN_NAME}
DOMAIN_NAMES: "${DOMAIN_NAMES}"
DNS_API: "dns_cf"
ACME_SH_EMAIL: "[email protected]"
ACME_COMMAND_ARGUMENTS: ${ACME_COMMAND_ARGUMENTS:---dns dns_cf}
entrypoint: /bin/sh
command: /scripts/acme.sh-docker.sh
networks:
mail_infra_network:
driver: bridge
name: infrastructure_mail_infra_network