mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-05-01 03:28:39 +02:00
Optimized DKIM and DNS for mailu and Letsencrypt. Solved some bugs
This commit is contained in:
parent
f4db4ca6ea
commit
fa9831ef08
@ -39,3 +39,6 @@ All roles follow a consistent naming convention using a *primary prefix* and a *
|
|||||||
| system- | Roles for system configuration, hardening, and operating system tuning (security, storage optimization, timers) |
|
| system- | Roles for system configuration, hardening, and operating system tuning (security, storage optimization, timers) |
|
||||||
| update- | Roles managing software update processes (package updates, Docker updates, repository management) |
|
| update- | Roles managing software update processes (package updates, Docker updates, repository management) |
|
||||||
| user- | Roles managing system users, accounts, and user-specific configuration (home directories, permissions) |
|
| user- | Roles managing system users, accounts, and user-specific configuration (home directories, permissions) |
|
||||||
|
|
||||||
|
# Implement the following roles
|
||||||
|
- Implement docker role for [radicle](https://radicle.xyz/)
|
@ -1,13 +1,49 @@
|
|||||||
|
- name: Check if DKIM private key file exists in the antispam container
|
||||||
|
command: >
|
||||||
|
docker compose exec -T antispam
|
||||||
|
test -f {{mailu_dkim_key_path}}
|
||||||
|
register: dkim_key_file_stat
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
args:
|
||||||
|
chdir: "{{ docker_compose.directories.instance }}"
|
||||||
|
|
||||||
- name: Generate DKIM key
|
- name: Generate DKIM key
|
||||||
command: >
|
command: >
|
||||||
docker compose exec -T antispam
|
docker compose exec -T antispam
|
||||||
rspamadm dkim_keygen -s dkim -d {{ applications[application_id].domain }} -k {{ applications[application_id].domain }}.dkim.key
|
rspamadm dkim_keygen -s dkim -d {{ applications[application_id].domain }} -k {{ mailu_dkim_key_path }}
|
||||||
register: dkim_keygen_output
|
register: dkim_keygen_output
|
||||||
chdir: "{{ docker_compose.directories.instance }}"
|
when: dkim_key_file_stat.rc != 0
|
||||||
|
args:
|
||||||
|
chdir: "{{ docker_compose.directories.instance }}"
|
||||||
|
|
||||||
- name: Extract DKIM record from parentheses
|
- name: Fetch DKIM private key from antispam container
|
||||||
|
shell: >
|
||||||
|
docker compose exec -T antispam
|
||||||
|
cat {{ mailu_dkim_key_path }}
|
||||||
|
args:
|
||||||
|
chdir: "{{ docker_compose.directories.instance }}"
|
||||||
|
register: dkim_priv_content
|
||||||
|
failed_when: dkim_priv_content.rc != 0
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Generate DKIM public key on the host
|
||||||
|
command: openssl rsa -pubout
|
||||||
|
args:
|
||||||
|
stdin: "{{ dkim_priv_content.stdout }}"
|
||||||
|
register: dkim_pub_raw
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Normalize and build Mailu DKIM TXT record
|
||||||
set_fact:
|
set_fact:
|
||||||
mailu_dkim_public_key: >-
|
mailu_dkim_public_key: >-
|
||||||
{{ dkim_keygen_output.stdout
|
v=DKIM1; k=rsa; p={{
|
||||||
| regex_search('(?s)\((.*?)\)', '\\1')
|
dkim_pub_raw.stdout
|
||||||
| default('') }}
|
| regex_replace('-----BEGIN PUBLIC KEY-----', '')
|
||||||
|
| regex_replace('-----END PUBLIC KEY-----', '')
|
||||||
|
| regex_replace('\s+', '')
|
||||||
|
}}
|
||||||
|
|
||||||
|
- name: Debug Mailu DKIM public key
|
||||||
|
debug:
|
||||||
|
msg: "Mailu DKIM public key: {{ mailu_dkim_public_key }}"
|
@ -42,21 +42,6 @@
|
|||||||
loop_var: item
|
loop_var: item
|
||||||
when: run_once_docker_mailu is not defined
|
when: run_once_docker_mailu is not defined
|
||||||
|
|
||||||
- name: "Load Mailu DNS variables"
|
|
||||||
include_vars: vars/mailu-dns.yml
|
|
||||||
when: dns_provider == 'cloudflare'
|
|
||||||
|
|
||||||
- name: Generate DKIM public key
|
|
||||||
include_tasks: generate-and-read-dkim.yml
|
|
||||||
when:
|
|
||||||
- not applications[application_id].credentials.dkim_public_key is defined
|
|
||||||
|
|
||||||
- name: Set DKIM public key
|
|
||||||
set_fact:
|
|
||||||
mailu_dkim_public_key: >-
|
|
||||||
{{ applications[application_id].credentials.dkim_public_key }}
|
|
||||||
when: applications[application_id].credentials.dkim_public_key is defined
|
|
||||||
|
|
||||||
- name: Set Mailu DNS records
|
- name: Set Mailu DNS records
|
||||||
include_tasks: set-mailu-dns-records.yml
|
include_tasks: set-mailu-dns-records.yml
|
||||||
when: dns_provider == 'cloudflare'
|
when: dns_provider == 'cloudflare'
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
- name: "Load Mailu DNS variables"
|
||||||
|
include_vars: vars/mailu-dns.yml
|
||||||
|
|
||||||
|
- name: Generate DKIM public key
|
||||||
|
include_tasks: generate-and-read-dkim.yml
|
||||||
|
|
||||||
- name: "Set A record for mail server"
|
- name: "Set A record for mail server"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
api_token: "{{ cloudflare_record_api_token }}"
|
api_token: "{{ cloudflare_record_api_token }}"
|
||||||
@ -6,7 +12,7 @@
|
|||||||
name: "{{ domain }}"
|
name: "{{ domain }}"
|
||||||
content: "{{ mailu_dns_ip }}"
|
content: "{{ mailu_dns_ip }}"
|
||||||
proxied: false
|
proxied: false
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Set CNAME record for autoconfig"
|
- name: "Set CNAME record for autoconfig"
|
||||||
@ -17,7 +23,7 @@
|
|||||||
name: "autoconfig.{{ mailu_dns_zone }}"
|
name: "autoconfig.{{ mailu_dns_zone }}"
|
||||||
value: "{{ domain }}"
|
value: "{{ domain }}"
|
||||||
proxied: false
|
proxied: false
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Set MX record"
|
- name: "Set MX record"
|
||||||
@ -28,7 +34,7 @@
|
|||||||
name: "{{ mailu_dns_zone }}"
|
name: "{{ mailu_dns_zone }}"
|
||||||
value: "{{ domain }}"
|
value: "{{ domain }}"
|
||||||
priority: 10
|
priority: 10
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Set SRV records"
|
- name: "Set SRV records"
|
||||||
@ -36,18 +42,19 @@
|
|||||||
api_token: "{{ cloudflare_record_api_token }}"
|
api_token: "{{ cloudflare_record_api_token }}"
|
||||||
zone: "{{ mailu_dns_zone }}"
|
zone: "{{ mailu_dns_zone }}"
|
||||||
type: SRV
|
type: SRV
|
||||||
name: "_{{ item.key }}._tcp"
|
service: "_{{ item.key }}"
|
||||||
data:
|
proto: "_tcp"
|
||||||
service: "_{{ item.key }}"
|
priority: "{{ item.value.priority }}"
|
||||||
proto: "_tcp"
|
weight: "{{ item.value.weight }}"
|
||||||
name: "{{ mailu_dns_zone }}"
|
port: "{{ item.value.port }}"
|
||||||
priority: "{{ item.value.priority }}"
|
value: "{{ domain }}"
|
||||||
weight: "{{ item.value.weight }}"
|
ttl: 1
|
||||||
port: "{{ item.value.port }}"
|
|
||||||
target: "{{ domain }}"
|
|
||||||
ttl: 3600
|
|
||||||
state: present
|
state: present
|
||||||
loop: "{{ mailu_dns_srv_records | dict2items }}"
|
loop: "{{ mailu_dns_srv_records | dict2items }}"
|
||||||
|
ignore_errors: true
|
||||||
|
#register: srv_result
|
||||||
|
#failed_when: srv_result.rc != 0 and ("An identical record already exists" not in srv_result.stdout)
|
||||||
|
#changed_when: srv_result.rc == 0 and ("An identical record already exists" not in srv_result.stdout)
|
||||||
|
|
||||||
- name: "Set SPF TXT record"
|
- name: "Set SPF TXT record"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -56,7 +63,7 @@
|
|||||||
type: TXT
|
type: TXT
|
||||||
name: "{{ mailu_dns_zone }}"
|
name: "{{ mailu_dns_zone }}"
|
||||||
value: "v=spf1 mx a:{{ domain }} ~all"
|
value: "v=spf1 mx a:{{ domain }} ~all"
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Set DMARC TXT record"
|
- name: "Set DMARC TXT record"
|
||||||
@ -66,7 +73,7 @@
|
|||||||
type: TXT
|
type: TXT
|
||||||
name: "_dmarc.{{ mailu_dns_zone }}"
|
name: "_dmarc.{{ mailu_dns_zone }}"
|
||||||
value: "v=DMARC1; p=reject; ruf=mailto:{{ mailu_dmarc_ruf }}; adkim=s; aspf=s"
|
value: "v=DMARC1; p=reject; ruf=mailto:{{ mailu_dmarc_ruf }}; adkim=s; aspf=s"
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Set DKIM TXT record"
|
- name: "Set DKIM TXT record"
|
||||||
@ -76,5 +83,5 @@
|
|||||||
type: TXT
|
type: TXT
|
||||||
name: "dkim._domainkey.{{ mailu_dns_zone }}"
|
name: "dkim._domainkey.{{ mailu_dns_zone }}"
|
||||||
value: "{{ mailu_dkim_public_key }}"
|
value: "{{ mailu_dkim_public_key }}"
|
||||||
ttl: 3600
|
ttl: 1
|
||||||
state: present
|
state: present
|
@ -5,7 +5,10 @@ mailu_dns_ip: "{{ networks.internet.ip4 }}"
|
|||||||
|
|
||||||
cloudflare_record_api_token: "{{ certbot_dns_api_token }}"
|
cloudflare_record_api_token: "{{ certbot_dns_api_token }}"
|
||||||
|
|
||||||
mailu_dmarc_ruf: "{{ applications[application_id].users.administrator.email }}"
|
mailu_dmarc_ruf: "{{ applications[application_id].users.administrator.email }}"
|
||||||
|
|
||||||
|
mailu_dkim_key_file: "{{ applications[application_id].domain }}.dkim.key"
|
||||||
|
mailu_dkim_key_path: "/dkim/{{ mailu_dkim_key_file }}"
|
||||||
|
|
||||||
mailu_dns_srv_records:
|
mailu_dns_srv_records:
|
||||||
submission:
|
submission:
|
||||||
|
2
roles/letsencrypt/TODO.md
Normal file
2
roles/letsencrypt/TODO.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Todos
|
||||||
|
- Implement issuewild and iodef -> Not possible yet due to API issues
|
@ -1,17 +1,4 @@
|
|||||||
---
|
---
|
||||||
# tasks/main.yml
|
|
||||||
# Creates and sets CAA records (issue, issuewild, iodef) for all base domains
|
|
||||||
|
|
||||||
- name: "Define CAA entries"
|
|
||||||
set_fact:
|
|
||||||
caa_entries:
|
|
||||||
- tag: issue
|
|
||||||
value: "letsencrypt.org"
|
|
||||||
- tag: issuewild
|
|
||||||
value: "letsencrypt.org"
|
|
||||||
- tag: iodef
|
|
||||||
value: "mailto:{{ users.administrator.email }}"
|
|
||||||
|
|
||||||
- name: "Ensure all CAA records are present"
|
- name: "Ensure all CAA records are present"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
api_token: "{{ certbot_dns_api_token }}"
|
api_token: "{{ certbot_dns_api_token }}"
|
||||||
|
7
roles/letsencrypt/vars/main.yml
Normal file
7
roles/letsencrypt/vars/main.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
caa_entries:
|
||||||
|
- tag: issue
|
||||||
|
value: "letsencrypt.org"
|
||||||
|
# - tag: issuewild
|
||||||
|
# value: "letsencrypt.org"
|
||||||
|
# - tag: iodef
|
||||||
|
# value: "mailto:{{ users.administrator.email }}"
|
@ -320,7 +320,7 @@ defaults_applications:
|
|||||||
mailu:
|
mailu:
|
||||||
version: "2024.06" # Docker Image Version
|
version: "2024.06" # Docker Image Version
|
||||||
users:
|
users:
|
||||||
adminsitrator:
|
administrator:
|
||||||
email: "{{users.administrator.email}}" # Administrator Email for DNS Records
|
email: "{{users.administrator.email}}" # Administrator Email for DNS Records
|
||||||
oidc:
|
oidc:
|
||||||
email_by_username: true # If true, then the mail is set by the username. If wrong then the OIDC user email is used
|
email_by_username: true # If true, then the mail is set by the username. If wrong then the OIDC user email is used
|
||||||
|
Loading…
x
Reference in New Issue
Block a user