-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-compose.yml
executable file
·298 lines (285 loc) · 12.8 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
version: "3.8"
services:
dns-server:
image: hickorydns/hickory-dns:latest
environment:
RUST_LOG: debug
dns:
- "10.222.222.1"
hostname: dns.mail-server.intranet
dns_search: mail-server.intranet.
networks:
mail_infra_network:
ipv4_address: 10.222.222.1
volumes:
- ./internal-dns/named.toml:/etc/named.toml:ro
- ./internal-dns/zones/:/var/named/zones/:ro
mailserver:
image: ${IMAGE_TAG:-ghcr.io/datacenters-network/mails/mailserver:latest}
mem_limit: 4G
mem_reservation: 2G
restart: on-failure:40
stop_grace_period: 1m
dns:
- "10.222.222.1"
hostname: emails.mail-server.intranet
dns_search: mail-server.intranet.
networks:
mail_infra_network:
ipv4_address: 10.222.222.2
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
- "8080:8080" # JMAP
volumes:
- ${MAILSERVER_DATA_DIR}:/opt/stalwart-mail
- ./config.toml:/etc/config.toml:ro
- ${MAILSERVER_KEYS_DIR}:/etc/opendkim/keys/
#- ${MAIL_DATA_DIR}:/var/mail
#- ${MAIL_STATE_DIR}:/var/mail-state
- ${MAIL_LOGS_DIR}:/var/log/mail
#- ${MAIL_CONFIGS_DIR}:/tmp/docker-mailserver/
# TODO: delete the file
#- ${USER_PATCHES_FILE:-./user-patches.sh}:/tmp/docker-mailserver/user-patches.sh:ro
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/fullchain.cer:/etc/ssl/mail-server/server.cer:ro
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/${DOMAIN_NAME}.key:/etc/ssl/mail-server/server.key:ro
# TODO: delete
#- ${DOVECOT_REPLICATION_SSL_VOLUME:-./empty-volume}:/etc/ssl/replication/:ro
#- ./rspamd/local.d/phishing.conf:/etc/rspamd/local.d/phishing.conf:ro
#- ./rspamd/local.d/mx_check.conf:/etc/rspamd/local.d/mx_check.conf:ro
# See: https://github.com/docker-mailserver/docker-mailserver/issues/2636
#- ./rspamd/local.d/dmarc-reports.conf:/etc/rspamd/local.d/dmarc-reports.conf:ro
#- ./rspamd/local.d/actions.conf:/etc/rspamd/local.d/actions.conf:ro
#- ./rspamd/local.d/milter_headers.conf:/etc/rspamd/local.d/milter_headers.conf:ro
#- ./rspamd/local.d/groups.conf:/etc/rspamd/local.d/groups.conf:ro
#- ./rspamd/local.d/multimap.conf:/etc/rspamd/local.d/multimap.conf:ro
#- ./rspamd/local.d/worker-controller.inc:/etc/rspamd/local.d/worker-controller.inc:ro
#- ./rspamd/local.d/dkim_signing.conf:/etc/rspamd/local.d/dkim_signing.conf:ro
#- ./rspamd/local.d/history_redis.conf:/etc/rspamd/local.d/history_redis.conf:ro
#- ./rspamd/local.d/settings.conf:/etc/rspamd/local.d/settings.conf:ro
#- ./rspamd/local.d/rbl.conf:/etc/rspamd/local.d/rbl.conf:ro
# maps
#- ./rspamd/maps.d/mx_whitelist.inc:/etc/rspamd/maps.d/mx_whitelist.inc:ro
#- ./rspamd/maps.d/local_wl_domain.map:/etc/rspamd/maps.d/local_wl_domain.map:ro
#- ./rspamd/maps.d/local_wl_from.map:/etc/rspamd/maps.d/local_wl_from.map:ro
#- ./cron/rspamd-learn:/etc/cron.d/rspamd-learn:ro
environment:
TZ: UTC
OAUTH_KEY: "CHANGE-ME"
SMTP_GREETING: "Datacenters Network emails"
DKIM_SELECTOR: "mail"
LDAP_SERVER_HOST: "ldap://ldap.mail-server.intranet" # Must match the hostname for SSL verification
LDAP_SEARCH_BASE: "ou=people,${LDAP_BASE_DN}"
LDAP_BIND_DN: "cn=admin,${LDAP_BASE_DN}"
LDAP_BIND_PW: ${LDAP_ADMIN_PASSWORD}
SSL_CERT_PATH: "file:///etc/ssl/mail-server/server.cer"
SSL_KEY_PATH: "file:///etc/ssl/mail-server/server.key"
healthcheck:
test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
timeout: 3s
retries: 10
start_period: 20s
depends_on:
openldap:
condition: service_healthy
acme:
condition: service_healthy
# netcap: https://stackoverflow.com/a/35485119/5155484
# getpcaps <pid>
# https://book.hacktricks.xyz/linux-hardening/privilege-escalation/linux-capabilities
#cap_add:
# - NET_ADMIN # fail2ban, spamd
# - NET_RAW # spamd
# - NET_BIND_SERVICE # dovecot, spamd
# - CHOWN # dovecot, spamd
# - DAC_OVERRIDE # dovecot, spamd
# - SYS_CHROOT # dovecot, spamd
# - SETUID # dovecot, spamd
# - SETGID # dovecot, spamd
# - KILL # dovecot, spamd
# - FOWNER # spamd
# - FSETID # spamd
# - SETPCAP # spamd
# - MKNOD # spamd
# - AUDIT_WRITE # spamd
# - SETFCAP # spamd
security_opt:
- no-new-privileges:true
#cap_drop:
# - ALL
openldap:
image: docker.io/botsudo/docker-openldap
restart: on-failure:5
mem_limit: 1G
mem_reservation: 100M
logging:
driver: "json-file"
options:
max-file: "5"
max-size: "1m"
dns:
- "10.222.222.1"
hostname: ldap.mail-server.intranet
dns_search: mail-server.intranet.
networks:
mail_infra_network:
ipv4_address: 10.222.222.3
healthcheck:
test: 'ldapwhoami -D "cn=$${DOCKER_LDAP_HEALTHCHECK_USERNAME}" -w "$${DOCKER_LDAP_HEALTHCHECK_PASSWORD}"'
start_period: 5s
interval: 30s
timeout: 5s
retries: 3
environment:
# 256 to enable debug
# See: https://www.openldap.org/doc/admin24/slapdconf2.html
LDAP_LOG_LEVEL: ${LDAP_LOG_LEVEL:-0}
LDAP_OPENLDAP_GID: 0
LDAP_OPENLDAP_UID: 0
LDAP_TLS_CRT_FILENAME: "/container/service/slapd/assets/certs/server.cer"
LDAP_TLS_KEY_FILENAME: "/container/service/slapd/assets/certs/server.key"
LDAP_TLS_CA_CRT_FILENAME: "/container/service/slapd/assets/certs/ca.cer"
LDAP_TLS_CIPHER_SUITE: "HIGH:MEDIUM:-SSLv2"
# never | allow | try | demand
LDAP_TLS_VERIFY_CLIENT: "try"
LDAP_BASE_DN: "${LDAP_BASE_DN}"
LDAP_AUTH_BASE_DN: "ou=people,${LDAP_BASE_DN}"
LDAP_ADMIN_PASSWORD: ${LDAP_ADMIN_PASSWORD}
LDAP_CONFIG_PASSWORD: ${LDAP_CONFIG_PASSWORD}
LDAP_MONITOR_PASSWORD: ${LDAP_MONITOR_PASSWORD}
# Only used by healthcheck command defined above
DOCKER_LDAP_HEALTHCHECK_USERNAME: ${DOCKER_LDAP_HEALTHCHECK_USERNAME}
DOCKER_LDAP_HEALTHCHECK_PASSWORD: ${DOCKER_LDAP_HEALTHCHECK_PASSWORD}
# Add ldaps:/// to SSL listen
LDAP_LISTEN_URLS: "ldap:/// ldapi:/// ldaps:///"
volumes:
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/ca.cer:/etc/ssl/certs/ca-certificates.crt:ro
- ${LDAP_DATA_DIR}:/var/lib/openldap/openldap-data
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/ca.cer:/container/service/slapd/assets/certs/ca.cer:ro
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/fullchain.cer:/container/service/slapd/assets/certs/server.cer:ro
- ${ACME_HOME_DIR}/${DOMAIN_NAME}/${DOMAIN_NAME}.key:/container/service/slapd/assets/certs/server.key:ro
# TODO: remove it
#- ${SASLAUTHD_SOCKET_FILE}:/var/run/saslauthd/mux
ports:
- "${LDAP_PORT:-389}:389"
- "${LDAPS_PORT:-636}:636"
depends_on:
acme:
condition: service_healthy
security_opt:
- no-new-privileges:true
phpldapadmin:
image: ghcr.io/sudo-bot/docker-phpldapadmin/docker-phpldapadmin:latest
mem_limit: 512M
mem_reservation: 100M
dns:
- "10.222.222.1"
hostname: phpldapadmin.mail-server.intranet
dns_search: mail-server.intranet.
networks:
mail_infra_network:
ipv4_address: 10.222.222.4
restart: on-failure:5
environment:
PHPLDAPADMIN_LDAP_HOSTS: "#PYTHON2BASH:[{'ldap.mail-server.intranet': [{'server': [{'tls': True}]},{'login': [{'bind_id': 'cn=admin,${LDAP_BASE_DN}'}]}]}]"
#PHPLDAPADMIN_HTTPS_CRT_FILENAME: "phpldapadmin-certificate.crt"
#PHPLDAPADMIN_HTTPS_KEY_FILENAME: "phpldapadmin-certificate.key"
#PHPLDAPADMIN_HTTPS_CA_CRT_FILENAME: "${PHPLDAPADMIN_HTTPS_CA_CRT_FILENAME:-phpldapadmin-ca.crt}"
#PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME: "ca.cer"
#volumes:
# web UI (phpldapadmin-ca.crt, phpldapadmin-certificate.key, phpldapadmin-certificate.crt)
#- ${ACME_HOME_DIR}/${DOMAIN_NAME}/ca.cer:/etc/ssl/server-certificate/ca.cer:ro
#- ${ACME_HOME_DIR}/${DOMAIN_NAME}/fullchain.cer:/etc/ssl/server-certificate/server.cer:ro
#- ${ACME_HOME_DIR}/${DOMAIN_NAME}/${DOMAIN_NAME}.key:/etc/ssl/server-certificate/server.key:ro
#- ${PHP_LDAP_ADMIN_CERTS_DIR}:/container/service/phpldapadmin/assets/apache2/certs
# LDAP client
#- ${ACME_HOME_DIR}/${DOMAIN_NAME}/ca.cer:/container/service/ldap-client/assets/certs/ca.cer:ro
ports:
- "${PHPLDAPADMIN_SSL_PORT:-8080}:80"
depends_on:
openldap:
condition: service_healthy
acme:
condition: service_healthy
security_opt:
- no-new-privileges:true
acme:
image: docker.io/neilpang/acme.sh:3.0.7
dns:
- "10.222.222.1"
hostname: acme.mail-server.intranet
dns_search: mail-server.intranet.
networks:
mail_infra_network:
ipv4_address: 10.222.222.5
mem_limit: 512M
mem_reservation: 10M
restart: on-failure:15
volumes:
- ./scripts:/scripts:ro
- ${ACME_HOME_DIR}:/acme.sh
working_dir: /scripts/
healthcheck:
test: ["CMD", "sh", "/scripts/healthcheck.sh"]
start_period: 10s
interval: ${ACME_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: "${ACME_SH_EMAIL:-}"
ACME_SH_EAB_KID: "${ACME_SH_EAB_KID:-}"
ACME_SH_EAB_HMAC: "${ACME_SH_EAB_HMAC:-}"
ACME_COMMAND_ARGUMENTS: ${ACME_COMMAND_ARGUMENTS:-}
ACME_ISSUE_ARGUMENTS: ${ACME_ISSUE_ARGUMENTS:-}
ACTIVATE_VOLSWAGEN: ${ACTIVATE_VOLSWAGEN:-}
entrypoint: /bin/sh
command: /scripts/acme.sh-docker.sh
security_opt:
- no-new-privileges:true
#crowdsec:
# image: crowdsecurity/crowdsec:v1.5.5
# dns_search: ""
# restart: always
# environment:
# DISABLE_LOCAL_API: "true"
# #DISABLE_SCENARIOS: "crowdsecurity/ssh-bf crowdsecurity/ssh-slow-bf"
# AGENT_USERNAME: "${CROWDSEC_AGENT_USERNAME}"
# AGENT_PASSWORD: "${CROWDSEC_AGENT_PASSWORD}"
# LOCAL_API_URL: "${CROWDSEC_AGENT_LOCAL_API_URL}"
# CUSTOM_HOSTNAME: emails
# depends_on:
# mailserver:
# condition: service_healthy
# volumes:
# - ${CROWDSEC_DB_DIR}:/var/lib/crowdsec/data/
# - ${CROWDSEC_CONFIG_DIR}:/etc/crowdsec/
# - "${MAILS_LOG_DIR}:/var/log/mails:ro"
# - ./crowdsec/acquis.yaml:/etc/crowdsec/acquis.yaml:ro
# - ./crowdsec/profiles.yaml:/etc/crowdsec/profiles.yaml:ro
# - ./crowdsec/scenarios/postfix-dovecot-hackers.yaml:/etc/crowdsec/scenarios/postfix-dovecot-hackers.yaml:ro
# - ./crowdsec/parsers/postfix-extended.yaml:/etc/crowdsec/parsers/s01-parse/postfix-extended.yaml:ro
# - ./crowdsec/parsers/dovecot-extended.yaml:/etc/crowdsec/parsers/s01-parse/dovecot-extended.yaml:ro
# - ./crowdsec/notifications/telegram.yaml:/etc/crowdsec/notifications/http.yaml:ro
# networks:
# mail_infra_network:
networks:
mail_infra_network:
name: infrastructure_mail_infra_network
ipam:
driver: default
config:
- subnet: 10.222.222.0/28
ip_range: 10.222.222.0/28
gateway: 10.222.222.14