diff options
96 files changed, 3325 insertions, 2 deletions
diff --git a/ansible/README.md b/ansible/README.md index f26ed5a..7b2591b 100644 --- a/ansible/README.md +++ b/ansible/README.md | |||
@@ -1,3 +1,66 @@ | |||
1 | 1 | mailweb: Matt's Mail and Web Ansible Config | |
2 | =========================================== | ||
2 | 3 | ||
3 | Self hosted mail server | 4 | ## What Is It? |
5 | |||
6 | This is an Ansible playbook containing Ansible roles to configure | ||
7 | my personal mail infrastructure components including: | ||
8 | |||
9 | - postfix | ||
10 | - dovecot | ||
11 | - rspamd | ||
12 | - borg-backup | ||
13 | - fail2ban | ||
14 | |||
15 | Also includes web components for installing multi-site `nginx` servers. | ||
16 | |||
17 | `mailweb` was created to apply on modern Ubuntu servers with a current | ||
18 | release version of Bionic 18.04 LTS (meaning: packages are deployed using | ||
19 | the `apt` module only currently). | ||
20 | |||
21 | A full writeup about this architecutre is at [Building a Production Mail Server in 2018](https://matt.sh/email2018) | ||
22 | |||
23 | ## Organization | ||
24 | |||
25 | To avoid mistakes like accidentally publishing all your private keys or | ||
26 | backup passphrases, we take advantage of Ansible's directory search hierarchy | ||
27 | to isolate non-public content from role directories. | ||
28 | |||
29 | For example: to avoid committing our private keys to the public repository, | ||
30 | instead of putting keys in a subdirectory of the role itself (e.g. `./roles/certs/files/tls/site-key.pem`), | ||
31 | we place them at the top level `file` path Ansible also searches (e.g. `./files/certs/tls/site-key.pem`). | ||
32 | |||
33 | The same goes for `hosts_vars` and `group_vars` using this insight from the | ||
34 | [Ansible docs](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#splitting-out-host-and-group-specific-data): | ||
35 | |||
36 | > Tip: The `group_vars/` and `host_vars/` directories can exist in the playbook directory OR the inventory directory. If both paths exist, variables in the playbook directory will override variables set in the inventory directory. | ||
37 | |||
38 | So, we place our sample vars in `inventory/{group,host}_vars` for publishing in this | ||
39 | repository, then for actual usage we write production vars at the top level (which overrides the `inventory/*` vars). | ||
40 | |||
41 | Now all we have to do is _not_ commit top level `files`, `group_vars`, and `host_vars` directories | ||
42 | into the public repository (only commit on local internal branches). This is helped | ||
43 | by our `.gitignore` in the public branch. View comments in `.gitignore` for more details | ||
44 | about private usage. | ||
45 | |||
46 | |||
47 | ## Contributing | ||
48 | |||
49 | Contributions welcome! Any PRs about improving configs towards security, usability, performance, and cross platform growth is encouraged. | ||
50 | |||
51 | If you want to make changes for your own needs (but maybe not for _everybody's_ needs), feel free to submit the changes and just guard them with enable `when` blocks activated by config variables. | ||
52 | |||
53 | Hopefully we can keep this architecture alive as its package components and underlying distributions grow over time. | ||
54 | |||
55 | ### Potential Problems | ||
56 | |||
57 | - Not extensively tested outside my personal environment | ||
58 | - there's probably default vars missing in places; feel free to submit fixes | ||
59 | |||
60 | ### Acceptable Improvements | ||
61 | |||
62 | - Feel free to submit better cross-platform integration | ||
63 | - cross-OS package management (`if centos` vs. `if debian` etc) | ||
64 | - should include better version checking/version pinning so we don't try to load 2018 configs into older servers not supporting modern options | ||
65 | - cross-OS config file locations, handlers, etc | ||
66 | - Update config files when [newer standards or features](https://matt.sh/web2018) get implemented and released | ||
diff --git a/ansible/inventory/host_vars/mailmash/backup.yml b/ansible/inventory/host_vars/mailmash/backup.yml new file mode 100644 index 0000000..aa5fcc4 --- /dev/null +++ b/ansible/inventory/host_vars/mailmash/backup.yml | |||
@@ -0,0 +1,18 @@ | |||
1 | --- | ||
2 | backup: | ||
3 | # Define a host in your ~/.ssh/config with username, host, and private key. | ||
4 | # Maintaining your ~/.ssh/config is out of scope for our implementation here. | ||
5 | host: rsn-backup | ||
6 | |||
7 | # directories to backup can be amended at any time | ||
8 | dirs: | ||
9 | - /var/mail | ||
10 | - /var/lib/fail2ban | ||
11 | - /var/lib/redis | ||
12 | |||
13 | # phrase is from: borg init --remote-path=borg1 --encryption=repokey-blake2 rsn-backup:mailmash | ||
14 | phrase: your phrase goes here | ||
15 | |||
16 | # your runAs user should be able to ssh to the backup host without a password | ||
17 | # (remote login user is configured by Host->User in this user's ~/.ssh/config) | ||
18 | runAs: root | ||
diff --git a/ansible/inventory/host_vars/mailmash/certs.yml b/ansible/inventory/host_vars/mailmash/certs.yml new file mode 100644 index 0000000..fd6dde0 --- /dev/null +++ b/ansible/inventory/host_vars/mailmash/certs.yml | |||
@@ -0,0 +1,13 @@ | |||
1 | --- | ||
2 | certs: | ||
3 | # Copy only these private keys and certs from ansible into the system | ||
4 | requested: | ||
5 | - yourmail.server.com | ||
6 | |||
7 | # we receive our certs by scp from the main cert hosting service elsewhere | ||
8 | receiver: true | ||
9 | |||
10 | # These users have ansible-controlled ssh private keys | ||
11 | # (mainly for automated backups right now) | ||
12 | sshKeysForUsers: | ||
13 | - root | ||
diff --git a/ansible/inventory/host_vars/mailmash/network.yml b/ansible/inventory/host_vars/mailmash/network.yml new file mode 100644 index 0000000..e290f7b --- /dev/null +++ b/ansible/inventory/host_vars/mailmash/network.yml | |||
@@ -0,0 +1,37 @@ | |||
1 | --- | ||
2 | network: | ||
3 | # These interface names are used to pull IP addresses into templates. | ||
4 | # interface.public has the IP we use to open ports to the world (mail, web, etc) | ||
5 | # interface.private has the IP for private services (ssh login, reporting, etc) | ||
6 | # Right now we don't support multiple IPs per interface, we just grab the IPv4 | ||
7 | # address as presented by ansible fact e.g. 'ansible_{{interface.public}}.ipv4.address' | ||
8 | interface: | ||
9 | private: ens3 | ||
10 | public: ens4 | ||
11 | hostname: | ||
12 | # network.hostname.public is used populate templates with | ||
13 | # server's public hostname, including: | ||
14 | # - TLS certs to use with this pattern: | ||
15 | # /etc/ssl/[hostname]-cert-combined.pem | ||
16 | # /etc/ssl/[hostname]-key.pem | ||
17 | # - Postfix config parameter "myhostname" | ||
18 | public: yourmail.server.com | ||
19 | |||
20 | # Below is almost (almost!) the netplan schema with three changes: | ||
21 | # - only one "interface" per system because ansible can't seem to generate multiple | ||
22 | # templates from one yaml dict? | ||
23 | # - so, the 'interface' key is added, other wise it would just be ethernets: ens4: ... | ||
24 | # - also, 'addresses' needs per-address broadcast, so addresses are now lists | ||
25 | # of dicts, so 'ip' is a new name as is 'broadcast' | ||
26 | ethernets: | ||
27 | interface: ens4 | ||
28 | macaddress: 02:00:00:7d:ca:ab | ||
29 | networks: | ||
30 | - subnet: 4.4.4.0/30 | ||
31 | gateway: 5.5.5.5 | ||
32 | addresses: | ||
33 | - 4.4.4.4/32 | ||
34 | routes: | ||
35 | - to: 0.0.0.0/0 | ||
36 | via: 5.5.5.5 | ||
37 | on-link: true | ||
diff --git a/ansible/inventory/host_vars/mailmash/sieve.yml b/ansible/inventory/host_vars/mailmash/sieve.yml new file mode 100644 index 0000000..635fb4e --- /dev/null +++ b/ansible/inventory/host_vars/mailmash/sieve.yml | |||
@@ -0,0 +1,9 @@ | |||
1 | --- | ||
2 | sieve: | ||
3 | users: | ||
4 | # username field is the filename [username].sieve in files/ | ||
5 | # The sieve file gets stored in vmail user directory [domain]/[user]/sieve/ | ||
6 | # We could improve this because it's clearly redundant... | ||
7 | - username: [email protected] | ||
8 | domain: server.com | ||
9 | user: username | ||
diff --git a/ansible/inventory/host_vars/webby/certs.yml b/ansible/inventory/host_vars/webby/certs.yml new file mode 100644 index 0000000..c38b80d --- /dev/null +++ b/ansible/inventory/host_vars/webby/certs.yml | |||
@@ -0,0 +1,23 @@ | |||
1 | --- | ||
2 | certs: | ||
3 | # Copy only these private keys and certs from ansible into the system | ||
4 | keyTypes: | ||
5 | - rsa2048 | ||
6 | - prime256v1 | ||
7 | |||
8 | # requested can EITHER be: | ||
9 | # - just a list of hostnames (then we depoly all 'keyTypes' for each hostname) | ||
10 | # - or, a mapping of, e.g.: | ||
11 | # - host: example1.com | ||
12 | # type: rsa2048 | ||
13 | # - host: example1.com | ||
14 | # type: prime256v1 | ||
15 | required: | ||
16 | - example1.com | ||
17 | - example2.com | ||
18 | - example3.com | ||
19 | |||
20 | # These users have ansible-controlled ssh private keys | ||
21 | # (mainly for automated backups right now) | ||
22 | sshKeysForUsers: [] | ||
23 | # - root | ||
diff --git a/ansible/inventory/host_vars/webby/network.yml b/ansible/inventory/host_vars/webby/network.yml new file mode 100644 index 0000000..39eb141 --- /dev/null +++ b/ansible/inventory/host_vars/webby/network.yml | |||
@@ -0,0 +1,12 @@ | |||
1 | --- | ||
2 | network: | ||
3 | # These interface names are used to pull IP addresses into templates. | ||
4 | # interface.public has the IP we use to open ports to the world (mail, web, etc) | ||
5 | # interface.private has the IP for private services (ssh login, reporting, etc) | ||
6 | # Right now we don't support multiple IPs per interface, we just grab the IPv4 | ||
7 | # address as presented by ansible fact e.g. 'ansible_{{interface.public}}.ipv4.address' | ||
8 | interface: | ||
9 | private: ens3 | ||
10 | public: ens4 | ||
11 | hostname: | ||
12 | public: webby | ||
diff --git a/ansible/inventory/host_vars/webby/nginx.yml b/ansible/inventory/host_vars/webby/nginx.yml new file mode 100644 index 0000000..87976dc --- /dev/null +++ b/ansible/inventory/host_vars/webby/nginx.yml | |||
@@ -0,0 +1,77 @@ | |||
1 | --- | ||
2 | nginx: | ||
3 | # Google webmaster tools wants this same filename on all hosts | ||
4 | google: | ||
5 | siteKey: googleYOURKEYHERE | ||
6 | siteKeyServeDir: /srv/web/files/ | ||
7 | |||
8 | # ssl can be "modern" or "tls13" or anything else means default | ||
9 | ssl: default | ||
10 | |||
11 | # These configs are directly uploaded as saved config files from files/nginx/<sitename> | ||
12 | complex: | ||
13 | - example4.com | ||
14 | - example5.com | ||
15 | |||
16 | basic: [] | ||
17 | # These configs are generated by template description below. | ||
18 | # 'customConfig' is nginx directives placed for your http2 server block. | ||
19 | # basic: | ||
20 | # - domain: "example.com" | ||
21 | # uri: | ||
22 | # - path: / | ||
23 | # | ||
24 | # - domain: example2.com | ||
25 | # uri: | ||
26 | # - path: / | ||
27 | # appServer: "http://127.0.0.1:7780" | ||
28 | # customConfig: | | ||
29 | # keepalive_timeout 5 5; | ||
30 | # keepalive_requests 200; | ||
31 | # | ||
32 | # proxy_intercept_errors on; | ||
33 | # error_page 502 =503 @noserver; | ||
34 | # error_page 503 =503 @noserver; | ||
35 | # error_page 504 =503 @noserver; | ||
36 | # | ||
37 | # location @noserver { | ||
38 | # root /home/matt/repos/matt-prod/priv; | ||
39 | # charset utf-8; | ||
40 | # rewrite ^(.*)$ /noserver.txt break; | ||
41 | # } | ||
42 | # | ||
43 | # location /src/ { | ||
44 | # proxy_pass http://127.0.0.1:7780/$request_uri; | ||
45 | # add_header Cache-Control public; | ||
46 | # expires +5m; | ||
47 | # if ($args) { | ||
48 | # expires +1y; | ||
49 | # } | ||
50 | # } | ||
51 | # | ||
52 | # location /style { | ||
53 | # proxy_pass http://127.0.0.1:7780/$request_uri; | ||
54 | # add_header Cache-Control public; | ||
55 | # expires +5m; | ||
56 | # if ($args) { | ||
57 | # expires +1y; | ||
58 | # } | ||
59 | # } | ||
60 | # | ||
61 | # location /js { | ||
62 | # proxy_pass http://127.0.0.1:7780/$request_uri; | ||
63 | # add_header Cache-Control public; | ||
64 | # expires +5m; | ||
65 | # if ($args) { | ||
66 | # expires +1y; | ||
67 | # } | ||
68 | # } | ||
69 | # | ||
70 | # location /favicon.ico { | ||
71 | # empty_gif; | ||
72 | # } | ||
73 | # | ||
74 | # location /files { | ||
75 | # expires max; | ||
76 | # root /srv/web/matt.sh; | ||
77 | # } | ||
diff --git a/ansible/inventory/inventory b/ansible/inventory/inventory new file mode 100644 index 0000000..3999869 --- /dev/null +++ b/ansible/inventory/inventory | |||
@@ -0,0 +1,5 @@ | |||
1 | [mail] | ||
2 | mailmash ansible_python_interpreter=/usr/bin/python3 | ||
3 | |||
4 | [web] | ||
5 | webby ansible_python_interpreter=/usr/bin/python3 | ||
diff --git a/ansible/mailmash.yml b/ansible/mailmash.yml new file mode 100644 index 0000000..15603b4 --- /dev/null +++ b/ansible/mailmash.yml | |||
@@ -0,0 +1,15 @@ | |||
1 | --- | ||
2 | - hosts: mail | ||
3 | remote_user: clarkzjw | ||
4 | become: yes | ||
5 | roles: | ||
6 | - common | ||
7 | - certs | ||
8 | - network | ||
9 | - disableFirewall | ||
10 | - rspamd | ||
11 | - dovecot | ||
12 | - sieve | ||
13 | - postfix | ||
14 | - fail2ban | ||
15 | - backup | ||
diff --git a/ansible/roles/backup/meta/main.yml b/ansible/roles/backup/meta/main.yml new file mode 100644 index 0000000..023023d --- /dev/null +++ b/ansible/roles/backup/meta/main.yml | |||
@@ -0,0 +1,4 @@ | |||
1 | --- | ||
2 | dependencies: | ||
3 | # borgmatic is inside a pip3 package | ||
4 | - role: pip3 | ||
diff --git a/ansible/roles/backup/tasks/main.yml b/ansible/roles/backup/tasks/main.yml new file mode 100644 index 0000000..fedc68b --- /dev/null +++ b/ansible/roles/backup/tasks/main.yml | |||
@@ -0,0 +1,40 @@ | |||
1 | --- | ||
2 | - name: install borgbackup | ||
3 | apt: | ||
4 | pkg: borgbackup | ||
5 | state: latest | ||
6 | |||
7 | - name: install borgmatic | ||
8 | pip: | ||
9 | name: borgmatic | ||
10 | state: latest | ||
11 | |||
12 | - name: create backup config dir | ||
13 | file: | ||
14 | path: /etc/borgmatic.d | ||
15 | owner: "{{ backup.runAs }}" | ||
16 | mode: 0700 | ||
17 | state: directory | ||
18 | |||
19 | # Create backup config for entire server | ||
20 | # Ideally we only have one type of data to backup per server and the rest | ||
21 | # can be re-constructed as necessary through auto-deploy processes | ||
22 | - name: populate borgmatic config with details for hosts | ||
23 | template: | ||
24 | src: borgmatic.yml.j2 | ||
25 | dest: /etc/borgmatic.d/system.backup.yml | ||
26 | owner: "{{ backup.runAs }}" | ||
27 | mode: 0600 | ||
28 | |||
29 | # Note: right now we aren't populating an 'excludes' file | ||
30 | # If we need 'excludes' in the future, append '--excludes [excludesDirsFile]' | ||
31 | # ALSO NOTE: your backup.runAs user MUST MANUALLY ACCEPT THE BACKUP HOST SSH KEY | ||
32 | # Backup will stall if unattended ssh sees new host fingerprint needing approval | ||
33 | - name: install backup crontab | ||
34 | cron: | ||
35 | name: "Backup Offsite" | ||
36 | minute: 32 | ||
37 | hour: 3 | ||
38 | job: "borgmatic --verbosity 1 -c /etc/borgmatic.d/system.backup.yml" | ||
39 | user: "{{ backup.runAs }}" | ||
40 | cron_file: backup_offsite | ||
diff --git a/ansible/roles/backup/templates/borgmatic.yml.j2 b/ansible/roles/backup/templates/borgmatic.yml.j2 new file mode 100644 index 0000000..864c8a6 --- /dev/null +++ b/ansible/roles/backup/templates/borgmatic.yml.j2 | |||
@@ -0,0 +1,36 @@ | |||
1 | location: | ||
2 | # List of source directories to backup. Globs are expanded. | ||
3 | source_directories: | ||
4 | {% for dir in backup.dirs %} | ||
5 | - {{ dir }} | ||
6 | {% endfor %} | ||
7 | |||
8 | # Paths to local or remote repositories. | ||
9 | repositories: | ||
10 | - {{ backup.host }}:{{ inventory_hostname }} | ||
11 | |||
12 | one_file_system: True | ||
13 | remote_path: borg1 | ||
14 | |||
15 | # Any paths matching these patterns are excluded from backups. | ||
16 | exclude_patterns: | ||
17 | - /home/*/.cache | ||
18 | |||
19 | storage: | ||
20 | encryption_passphrase: {{ backup.phrase }} | ||
21 | compression: lz4 | ||
22 | |||
23 | retention: | ||
24 | # Retention policy for how many backups to keep in each category. | ||
25 | keep_within: 3H | ||
26 | keep_daily: 7 | ||
27 | keep_weekly: 2 | ||
28 | keep_monthly: 3 | ||
29 | |||
30 | consistency: | ||
31 | # List of consistency checks to run: "repository", "archives", or both. | ||
32 | checks: | ||
33 | - repository | ||
34 | - archives | ||
35 | |||
36 | check_last: 1 | ||
diff --git a/ansible/roles/certreload/tasks/main.yml b/ansible/roles/certreload/tasks/main.yml new file mode 100644 index 0000000..0e4fcc7 --- /dev/null +++ b/ansible/roles/certreload/tasks/main.yml | |||
@@ -0,0 +1,21 @@ | |||
1 | --- | ||
2 | # This is a hack because ansible can't trigger handlers if they don't | ||
3 | # exist, so we can't have our 'certs' role unconditionally fire things | ||
4 | # like "reload nginx" and "reload postfix" because those don't exist | ||
5 | # in every deployment. | ||
6 | # As a hack, just check if /etc/ssl was recently modified then reload | ||
7 | - name: check certificate update recency | ||
8 | stat: | ||
9 | path: /etc/ssl | ||
10 | register: statSSL | ||
11 | |||
12 | # Have to mock a command resulting in some "changed" status so ansible | ||
13 | # allows itself to trigger handlers. | ||
14 | # The actual restriction on this handler is the 'when' clause, not | ||
15 | # the command itself. | ||
16 | - name: reload because certs are newish | ||
17 | command: /bin/true | ||
18 | when: ((ansible_date_time.epoch |int) - (statSSL.stat.mtime |int)) < 300 | ||
19 | notify: | ||
20 | - "{{ item }}" | ||
21 | loop: "{{ certreload.notifiers }}" | ||
diff --git a/ansible/roles/certs/files/leforward.py b/ansible/roles/certs/files/leforward.py new file mode 100755 index 0000000..dccbac1 --- /dev/null +++ b/ansible/roles/certs/files/leforward.py | |||
@@ -0,0 +1,68 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | """ Run a single-purpose HTTP server. | ||
4 | |||
5 | Server takes all GET requests and redirects them to a new host | ||
6 | if the request URI starts with SUBPATH, otherwise returns 404. | ||
7 | |||
8 | Requests are redirected to the URL provided by --baseurl. """ | ||
9 | |||
10 | import socketserver | ||
11 | import http.server | ||
12 | import argparse | ||
13 | import sys | ||
14 | |||
15 | |||
16 | CHALLENGE_HOST = None | ||
17 | SUBPATH = "/.well-known/acme-challenge" | ||
18 | |||
19 | |||
20 | class RedirectChallenges(http.server.BaseHTTPRequestHandler): | ||
21 | def do_GET(self): | ||
22 | if self.path.startswith(SUBPATH): | ||
23 | self.send_response(301) | ||
24 | self.send_header('Location', f"{CHALLENGE_HOST}{self.path}") | ||
25 | else: | ||
26 | self.send_response(404) | ||
27 | |||
28 | self.end_headers() | ||
29 | |||
30 | |||
31 | class ReusableServer(socketserver.TCPServer): | ||
32 | """ Allow TCPServer to reuse host address. | ||
33 | |||
34 | Without setting 'allow_reuse_address', we can get stuck in | ||
35 | TIME_WAIT after being killed and the stale state stops a new | ||
36 | server from attaching to the port.""" | ||
37 | |||
38 | allow_reuse_address = True | ||
39 | |||
40 | |||
41 | if __name__ == "__main__": | ||
42 | parser = argparse.ArgumentParser( | ||
43 | description="Redirect all URIs with matching prefix to another host") | ||
44 | parser.add_argument( | ||
45 | '--baseurl', | ||
46 | dest='baseurl', | ||
47 | required=True, | ||
48 | help="Destination URL for all matching URIs on this server") | ||
49 | |||
50 | args = parser.parse_args() | ||
51 | CHALLENGE_HOST = args.baseurl | ||
52 | |||
53 | if not CHALLENGE_HOST.startswith("http"): | ||
54 | print("Redirect URL must be a full URL starting with http") | ||
55 | sys.exit(1) | ||
56 | |||
57 | # If user gave us a trailing slash URL, remove slash. | ||
58 | if CHALLENGE_HOST[-1] == "/": | ||
59 | CHALLENGE_HOST = CHALLENGE_HOST[:-1] | ||
60 | |||
61 | serverAddress = ('', 80) | ||
62 | |||
63 | # Note: if running remotely by an SSH command, you MUST launch with '-t': | ||
64 | # > ssh -t me@otherhost leforward.py --baseurl http://otherserver.com | ||
65 | # If you omit '-t' the listening server won't terminate when you kill the | ||
66 | # ssh session, which probably isn't what you want. | ||
67 | with ReusableServer(serverAddress, RedirectChallenges) as httpd: | ||
68 | httpd.serve_forever() | ||
diff --git a/ansible/roles/certs/files/lets-encrypt-x3-cross-signed.pem b/ansible/roles/certs/files/lets-encrypt-x3-cross-signed.pem new file mode 100644 index 0000000..0002462 --- /dev/null +++ b/ansible/roles/certs/files/lets-encrypt-x3-cross-signed.pem | |||
@@ -0,0 +1,27 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/ | ||
3 | MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT | ||
4 | DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow | ||
5 | SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT | ||
6 | GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC | ||
7 | AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF | ||
8 | q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8 | ||
9 | SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0 | ||
10 | Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA | ||
11 | a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj | ||
12 | /PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T | ||
13 | AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG | ||
14 | CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv | ||
15 | bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k | ||
16 | c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw | ||
17 | VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC | ||
18 | ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz | ||
19 | MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu | ||
20 | Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF | ||
21 | AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo | ||
22 | uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/ | ||
23 | wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu | ||
24 | X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG | ||
25 | PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 | ||
26 | KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== | ||
27 | -----END CERTIFICATE----- | ||
diff --git a/ansible/roles/certs/tasks/main.yml b/ansible/roles/certs/tasks/main.yml new file mode 100644 index 0000000..e83a640 --- /dev/null +++ b/ansible/roles/certs/tasks/main.yml | |||
@@ -0,0 +1,153 @@ | |||
1 | --- | ||
2 | - name: remove default ubuntu key | ||
3 | file: | ||
4 | path: /etc/ssl/private/ssl-cert-snakeoil.key | ||
5 | state: absent | ||
6 | |||
7 | - name: create cert maint group | ||
8 | group: | ||
9 | name: certmaint | ||
10 | gid: 1070 | ||
11 | state: present | ||
12 | |||
13 | - name: create cert maint user | ||
14 | user: | ||
15 | name: certmaint | ||
16 | uid: 1070 | ||
17 | group: ssl-cert | ||
18 | groups: | ||
19 | - certmaint | ||
20 | shell: /bin/sh | ||
21 | create_home: yes | ||
22 | state: present | ||
23 | |||
24 | #- name: allow certmaint to maint certs and keys (default) | ||
25 | # acl: | ||
26 | # path: /etc/ssl/ | ||
27 | # etype: user | ||
28 | # entity: certmaint | ||
29 | # permissions: rw | ||
30 | # default: yes | ||
31 | # recursive: yes | ||
32 | # state: present | ||
33 | # no_log: true | ||
34 | |||
35 | #- name: allow certmaint to maint certs and keys (actual certs) | ||
36 | # acl: | ||
37 | # path: /etc/ssl/ | ||
38 | # etype: user | ||
39 | # entity: certmaint | ||
40 | # permissions: rwx | ||
41 | # state: present | ||
42 | # no_log: true | ||
43 | |||
44 | #- name: allow certmaint to maint certs and keys (actual keys) | ||
45 | # acl: | ||
46 | # path: /etc/ssl/private/ | ||
47 | # etype: user | ||
48 | # entity: certmaint | ||
49 | # permissions: rwx | ||
50 | # state: present | ||
51 | # no_log: true | ||
52 | |||
53 | # Keys are private: only owner can read/write, and only group can read | ||
54 | - name: populate required keys (common types) | ||
55 | copy: | ||
56 | src: "tls/private/{{ item[0] }}-key.{{ item[1] }}.pem" | ||
57 | dest: /etc/ssl/private/ | ||
58 | mode: 0640 | ||
59 | owner: certmaint | ||
60 | group: ssl-cert | ||
61 | loop: "{{ certs.required |product(certs.keyTypes) |list }}" | ||
62 | when: certs.required[0] is string | ||
63 | |||
64 | |||
65 | # Certs are owned by 'certmaint' so user 'certmaint' can update them over scp | ||
66 | # Certs are public (obviously) | ||
67 | - name: populate required certs (common types) | ||
68 | copy: | ||
69 | src: "tls/{{ item[0] }}-cert-combined.{{ item[1] }}.pem" | ||
70 | dest: /etc/ssl/ | ||
71 | mode: 0644 | ||
72 | owner: certmaint | ||
73 | loop: "{{ certs.required |product(certs.keyTypes) |list }}" | ||
74 | when: certs.required[0] is string | ||
75 | |||
76 | |||
77 | |||
78 | # Keys are private: only owner can read/write, and only group can read | ||
79 | - name: populate required keys (specific types) | ||
80 | copy: | ||
81 | src: "tls/private/{{ item.host }}-key.{{ item.type }}.pem" | ||
82 | dest: /etc/ssl/private/ | ||
83 | mode: 0640 | ||
84 | owner: certmaint | ||
85 | group: ssl-cert | ||
86 | loop: "{{ certs.required }}" | ||
87 | when: certs.required[0] is mapping | ||
88 | |||
89 | # Certs are owned by 'certmaint' so user 'certmaint' can update them over scp | ||
90 | # Certs are public (obviously) | ||
91 | - name: populate required certs (specific types) | ||
92 | copy: | ||
93 | src: "tls/{{ item.host }}-cert-combined.{{ item.type }}.pem" | ||
94 | dest: /etc/ssl/ | ||
95 | mode: 0644 | ||
96 | owner: certmaint | ||
97 | loop: "{{ certs.required }}" | ||
98 | when: certs.required[0] is mapping | ||
99 | |||
100 | |||
101 | |||
102 | - name: plop LE cert chain | ||
103 | copy: | ||
104 | src: "tls/lets-encrypt-x3-cross-signed.pem" | ||
105 | dest: /etc/ssl/ | ||
106 | mode: 0644 | ||
107 | owner: certmaint | ||
108 | |||
109 | - name: plop remote LE challenge redirector | ||
110 | copy: | ||
111 | src: leforward.py | ||
112 | dest: /usr/local/bin/ | ||
113 | mode: 0755 | ||
114 | when: | ||
115 | - certs.receiver is defined and certs.receiver | ||
116 | |||
117 | |||
118 | # Retrieve all users on this host (creates variable 'passwd' containing results) | ||
119 | - name: get all user details so we can populate home directories | ||
120 | getent: | ||
121 | database: passwd | ||
122 | |||
123 | # Copy users/hostname/username contents into remote home directory | ||
124 | - name: verify explicit user keys exist as expected | ||
125 | copy: | ||
126 | src: "users/{{ inventory_hostname }}/{{ item }}/" | ||
127 | # [item][4] is [username][homedir] where /etc/passwd is tokenized on ':' | ||
128 | # and username becomes the key with remaining fields indexed by integers | ||
129 | dest: "{{ getent_passwd[item][4] }}" | ||
130 | mode: 0600 | ||
131 | owner: "{{ item }}" | ||
132 | directory_mode: 0700 | ||
133 | loop: "{{ certs.sshKeysForUsers }}" | ||
134 | |||
135 | # TODO: we could make one key per action then restrict actions by ssh key. | ||
136 | # (postfix key, dovecot key, nginx key, leforward key) | ||
137 | - name: verify certmaint receiver key exists | ||
138 | copy: | ||
139 | src: "users/certmaint/" | ||
140 | dest: "{{ getent_passwd[item][4] }}" | ||
141 | mode: 0600 | ||
142 | owner: "{{ item }}" | ||
143 | directory_mode: 0700 | ||
144 | loop: | ||
145 | - certmaint | ||
146 | |||
147 | - name: allow certmaint group to sudo reload relevant services | ||
148 | lineinfile: | ||
149 | path: /etc/sudoers.d/certmaint_reloads | ||
150 | regexp: "^%certmaint" | ||
151 | line: "%certmaint ALL = (root) NOPASSWD: /usr/sbin/service postfix reload, /usr/sbin/service dovecot reload, /usr/sbin/service nginx reload" | ||
152 | create: yes | ||
153 | mode: 0440 | ||
diff --git a/ansible/roles/common/defaults/main.yml b/ansible/roles/common/defaults/main.yml new file mode 100644 index 0000000..2410e85 --- /dev/null +++ b/ansible/roles/common/defaults/main.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | --- | ||
2 | grub: | ||
3 | extras: "" | ||
diff --git a/ansible/roles/common/files/ffdhe2048.pem b/ansible/roles/common/files/ffdhe2048.pem new file mode 100644 index 0000000..9b182b7 --- /dev/null +++ b/ansible/roles/common/files/ffdhe2048.pem | |||
@@ -0,0 +1,8 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz | ||
3 | +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a | ||
4 | 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 | ||
5 | YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi | ||
6 | 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD | ||
7 | ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== | ||
8 | -----END DH PARAMETERS----- | ||
diff --git a/ansible/roles/common/files/ffdhe3072.pem b/ansible/roles/common/files/ffdhe3072.pem new file mode 100644 index 0000000..fb31ccd --- /dev/null +++ b/ansible/roles/common/files/ffdhe3072.pem | |||
@@ -0,0 +1,11 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIIBiAKCAYEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz | ||
3 | +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a | ||
4 | 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 | ||
5 | YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi | ||
6 | 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD | ||
7 | ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3 | ||
8 | 7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32 | ||
9 | nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZsYu | ||
10 | N///////////AgEC | ||
11 | -----END DH PARAMETERS----- | ||
diff --git a/ansible/roles/common/files/ffdhe4096.pem b/ansible/roles/common/files/ffdhe4096.pem new file mode 100644 index 0000000..3cf0fcb --- /dev/null +++ b/ansible/roles/common/files/ffdhe4096.pem | |||
@@ -0,0 +1,13 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIICCAKCAgEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz | ||
3 | +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a | ||
4 | 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 | ||
5 | YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi | ||
6 | 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD | ||
7 | ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3 | ||
8 | 7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32 | ||
9 | nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZp4e | ||
10 | 8W5vUsMWTfT7eTDp5OWIV7asfV9C1p9tGHdjzx1VA0AEh/VbpX4xzHpxNciG77Qx | ||
11 | iu1qHgEtnmgyqQdgCpGBMMRtx3j5ca0AOAkpmaMzy4t6Gh25PXFAADwqTs6p+Y0K | ||
12 | zAqCkc3OyX3Pjsm1Wn+IpGtNtahR9EGC4caKAH5eZV9q//////////8CAQI= | ||
13 | -----END DH PARAMETERS----- | ||
diff --git a/ansible/roles/common/files/inputrc b/ansible/roles/common/files/inputrc new file mode 100644 index 0000000..47e7275 --- /dev/null +++ b/ansible/roles/common/files/inputrc | |||
@@ -0,0 +1,61 @@ | |||
1 | # do not bell on tab-completion | ||
2 | #set bell-style none | ||
3 | |||
4 | set meta-flag on | ||
5 | set input-meta on | ||
6 | set convert-meta off | ||
7 | set output-meta on | ||
8 | |||
9 | # Completed names which are symbolic links to | ||
10 | # directories have a slash appended. | ||
11 | set mark-symlinked-directories on | ||
12 | |||
13 | $if mode=emacs | ||
14 | |||
15 | # for linux console and RH/Debian xterm | ||
16 | "\e[1~": beginning-of-line | ||
17 | "\e[4~": end-of-line | ||
18 | # commented out keymappings for pgup/pgdown to reach begin/end of history | ||
19 | #"\e[5~": beginning-of-history | ||
20 | #"\e[6~": end-of-history | ||
21 | "\e[5~": history-search-backward | ||
22 | "\e[6~": history-search-forward | ||
23 | "\e[3~": delete-char | ||
24 | "\e[2~": quoted-insert | ||
25 | "\e[5C": forward-word | ||
26 | "\e[5D": backward-word | ||
27 | "\e[1;5C": forward-word | ||
28 | "\e[1;5D": backward-word | ||
29 | |||
30 | # for rxvt | ||
31 | "\e[8~": end-of-line | ||
32 | "\eOc": forward-word | ||
33 | "\eOd": backward-word | ||
34 | |||
35 | # for non RH/Debian xterm, can't hurt for RH/DEbian xterm | ||
36 | "\eOH": beginning-of-line | ||
37 | "\eOF": end-of-line | ||
38 | |||
39 | # for freebsd console | ||
40 | "\e[H": beginning-of-line | ||
41 | "\e[F": end-of-line | ||
42 | $endif | ||
43 | |||
44 | # cd d<TAB> will match documents or Documents | ||
45 | set completion-ignore-case on | ||
46 | |||
47 | # front-of-command up and down completion | ||
48 | "\e[A":history-search-backward | ||
49 | "\e[B":history-search-forward | ||
50 | |||
51 | # This is the magic command. | ||
52 | # Enables sane tcsh-like ctrl-d completion showing. | ||
53 | Control-d:delete-char-or-list | ||
54 | |||
55 | # oddly, menu-complete makes the menu *not* appear | ||
56 | # just cycle through each option | ||
57 | Tab:menu-complete | ||
58 | |||
59 | # stop asking if I "Really want to see 102 completions" | ||
60 | set completion-query-items 350 | ||
61 | set page-completions off | ||
diff --git a/ansible/roles/common/files/net-listeners.py b/ansible/roles/common/files/net-listeners.py new file mode 100755 index 0000000..f8b39cd --- /dev/null +++ b/ansible/roles/common/files/net-listeners.py | |||
@@ -0,0 +1,334 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | """ Output a colorized list of listening addresses with owners. | ||
4 | |||
5 | This tool parses files in /proc directly to obtain the list | ||
6 | of IPv4 and IPv6 addresses listening on tcp, tcp6, udp, and udp6 ports | ||
7 | also with pids of processes responsible for the listening. | ||
8 | |||
9 | Due to permission restrictions on Linux, script must be run as root | ||
10 | to determine which pids match which listening sockets. | ||
11 | |||
12 | This is also something like: | ||
13 | osqueryi "select po.pid, rtrim(p.cmdline), po.family, po.local_address, po.local_port from process_open_sockets as po JOIN processes as p ON po.pid=p.pid WHERE po.state='LISTEN';" | ||
14 | |||
15 | """ | ||
16 | |||
17 | import collections | ||
18 | import subprocess | ||
19 | import codecs | ||
20 | import socket | ||
21 | import struct | ||
22 | import glob | ||
23 | import sys | ||
24 | import re | ||
25 | import os | ||
26 | |||
27 | TERMINAL_WIDTH = "/usr/bin/tput cols" # could also be "stty size" | ||
28 | |||
29 | ONLY_LOWEST_PID = False | ||
30 | |||
31 | # oooh, look, a big dirty global dict collecting all our data without being | ||
32 | # passed around! call the programming police! | ||
33 | inodes = {} | ||
34 | |||
35 | |||
36 | class Color: | ||
37 | HEADER = '\033[95m' | ||
38 | OKBLUE = '\033[94m' | ||
39 | OKGREEN = '\033[92m' | ||
40 | WARNING = '\033[93m' | ||
41 | FAIL = '\033[91m' | ||
42 | BOLD = '\033[1m' | ||
43 | UNDERLINE = '\033[4m' | ||
44 | END = '\033[0m' | ||
45 | |||
46 | |||
47 | COLOR_HEADER = Color.HEADER | ||
48 | COLOR_OKAY = Color.OKBLUE | ||
49 | COLOR_WARNING = Color.FAIL | ||
50 | COLOR_END = Color.END | ||
51 | |||
52 | # This should capture: | ||
53 | # 127.0.0.0/8 | ||
54 | # 192.168.0.0/16 | ||
55 | # 10.0.0.0/8 | ||
56 | # 169.254.0.0/16 | ||
57 | # 172.16.0.0/12 | ||
58 | # ::1 | ||
59 | # fe80::/10 | ||
60 | # fc00::/7 | ||
61 | # fd00::/8 | ||
62 | NON_ROUTABLE_REGEX = r"""^((127\.) | | ||
63 | (192\.168\.) | | ||
64 | (10\.) | | ||
65 | (169\.254\.) | | ||
66 | (172\.1[6-9]\.) | | ||
67 | (172\.2[0-9]\.) | | ||
68 | (172\.3[0-1]\.) | | ||
69 | (::1) | | ||
70 | ([fF][eE]80) | ||
71 | ([fF][cCdD]))""" | ||
72 | likelyLocalOnly = re.compile(NON_ROUTABLE_REGEX, re.VERBOSE) | ||
73 | |||
74 | |||
75 | def run(thing): | ||
76 | """ Run any string as an async command invocation. """ | ||
77 | # We don't use subprocess.check_output because we want to run all | ||
78 | # processes async | ||
79 | return subprocess.Popen(thing.split(), stdout=subprocess.PIPE) | ||
80 | |||
81 | |||
82 | def readOutput(ranCommand): | ||
83 | """ Return array of rows split by newline from previous invocation. """ | ||
84 | stdout, stderr = ranCommand.communicate() | ||
85 | return stdout.decode('utf-8').strip().splitlines() | ||
86 | |||
87 | |||
88 | def procListeners(): | ||
89 | """ Wrapper to parse all IPv4 tcp udp, and, IPv6 tcp6 udp6 listeners. """ | ||
90 | |||
91 | def processProc(name): | ||
92 | """ Process IPv4 and IPv6 versions of listeners based on ``name``. | ||
93 | |||
94 | ``name`` is either 'udp' or 'tcp' so we parse, for each ``name``: | ||
95 | - /proc/net/[name] | ||
96 | - /proc/net/[name]6 | ||
97 | |||
98 | As in: | ||
99 | - /proc/net/tcp | ||
100 | - /proc/net/tcp6 | ||
101 | - /proc/net/udp | ||
102 | - /proc/net/udp6 | ||
103 | """ | ||
104 | |||
105 | def ipv6(addr): | ||
106 | """ Convert /proc IPv6 hex address into standard IPv6 notation. """ | ||
107 | # turn ASCII hex address into binary | ||
108 | addr = codecs.decode(addr, "hex") | ||
109 | |||
110 | # unpack into 4 32-bit integers in big endian / network byte order | ||
111 | addr = struct.unpack('!LLLL', addr) | ||
112 | |||
113 | # re-pack as 4 32-bit integers in system native byte order | ||
114 | addr = struct.pack('@IIII', *addr) | ||
115 | |||
116 | # now we can use standard network APIs to format the address | ||
117 | addr = socket.inet_ntop(socket.AF_INET6, addr) | ||
118 | return addr | ||
119 | |||
120 | def ipv4(addr): | ||
121 | """ Convert /proc IPv4 hex address into standard IPv4 notation. """ | ||
122 | # Instead of codecs.decode(), we can just convert a 4 byte hex | ||
123 | # string to an integer directly using python radix conversion. | ||
124 | # Basically, int(addr, 16) EQUALS: | ||
125 | # aOrig = addr | ||
126 | # addr = codecs.decode(addr, "hex") | ||
127 | # addr = struct.unpack(">L", addr) | ||
128 | # assert(addr == (int(aOrig, 16),)) | ||
129 | addr = int(addr, 16) | ||
130 | |||
131 | # system native byte order, 4-byte integer | ||
132 | addr = struct.pack("=L", addr) | ||
133 | addr = socket.inet_ntop(socket.AF_INET, addr) | ||
134 | return addr | ||
135 | |||
136 | isUDP = name == "udp" | ||
137 | |||
138 | # Iterate four files: /proc/net/{tcp,udp}{,6} | ||
139 | # ipv4 has no prefix, while ipv6 has 6 appended. | ||
140 | for ver in ["", "6"]: | ||
141 | with open(f"/proc/net/{name}{ver}", 'r') as proto: | ||
142 | proto = proto.read().splitlines() | ||
143 | proto = proto[1:] # drop header row | ||
144 | |||
145 | for cxn in proto: | ||
146 | cxn = cxn.split() | ||
147 | |||
148 | # /proc/net/udp{,6} uses different constants for LISTENING | ||
149 | if isUDP: | ||
150 | # These constants are based on enum offsets inside | ||
151 | # the Linux kernel itself. They aren't likely to ever | ||
152 | # change since they are hardcoded in utilities. | ||
153 | isListening = cxn[3] == "07" | ||
154 | else: | ||
155 | isListening = cxn[3] == "0A" | ||
156 | |||
157 | # Right now this is a single-purpose tool so if process is | ||
158 | # not listening, we avoid further processing of this row. | ||
159 | if not isListening: | ||
160 | continue | ||
161 | |||
162 | ip, port = cxn[1].split(':') | ||
163 | if ver: | ||
164 | ip = ipv6(ip) | ||
165 | else: | ||
166 | ip = ipv4(ip) | ||
167 | |||
168 | port = int(port, 16) | ||
169 | inode = cxn[9] | ||
170 | |||
171 | # We just use a list here because creating a new sub-dict | ||
172 | # for each entry was noticably slower than just indexing | ||
173 | # into lists. | ||
174 | inodes[int(inode)] = [ip, port, f"{name}{ver}"] | ||
175 | |||
176 | processProc("tcp") | ||
177 | processProc("udp") | ||
178 | |||
179 | |||
180 | def appendToInodePidMap(fd, inodePidMap): | ||
181 | """ Take a full path to /proc/[pid]/fd/[fd] for reading. | ||
182 | |||
183 | Populates both pid and full command line of pid owning an inode we | ||
184 | are interested in. | ||
185 | |||
186 | Basically finds if any inodes on this pid is a listener we previously | ||
187 | recorded into our ``inodes`` dict. """ | ||
188 | _, _, pid, _, _ = fd.split('/') | ||
189 | try: | ||
190 | target = os.readlink(fd) | ||
191 | except FileNotFoundError: | ||
192 | # file vanished, can't do anything else | ||
193 | return | ||
194 | |||
195 | if target.startswith("socket"): | ||
196 | ostype, inode = target.split(':') | ||
197 | # strip brackets from fd string (it looks like: [fd]) | ||
198 | inode = int(inode[1:-1]) | ||
199 | inodePidMap[inode].append(int(pid)) | ||
200 | |||
201 | |||
202 | def addProcessNamesToInodes(): | ||
203 | """ Loop over every fd in every process in /proc. | ||
204 | |||
205 | The only way to map an fd back to a process is by looking | ||
206 | at *every* processes fd and extracting backing inodes. | ||
207 | |||
208 | It's basically like a big awkward database join where you don't | ||
209 | have an index on the field you want. | ||
210 | |||
211 | Also, due to Linux permissions (and Linux security concerns), | ||
212 | only the root user can read fd listing of processes not owned | ||
213 | by the current user. """ | ||
214 | |||
215 | # glob glob glob it all | ||
216 | allFDs = glob.iglob("/proc/*/fd/*") | ||
217 | inodePidMap = collections.defaultdict(list) | ||
218 | |||
219 | for fd in allFDs: | ||
220 | appendToInodePidMap(fd, inodePidMap) | ||
221 | |||
222 | for inode in inodes: | ||
223 | if inode in inodePidMap: | ||
224 | for pid in inodePidMap[inode]: | ||
225 | try: | ||
226 | with open(f"/proc/{pid}/cmdline", 'r') as cmd: | ||
227 | # /proc command line arguments are delimited by | ||
228 | # null bytes, so undo that here... | ||
229 | cmdline = cmd.read().split('\0') | ||
230 | inodes[inode].append((pid, cmdline)) | ||
231 | except BaseException: | ||
232 | # files can vanish on us at any time (and that's okay!) | ||
233 | # But, since the file is gone, we want the entire fd | ||
234 | # entry gone too: | ||
235 | pass # del inodes[inode] | ||
236 | |||
237 | |||
238 | def checkListenersProc(): | ||
239 | terminalWidth = run(TERMINAL_WIDTH) | ||
240 | |||
241 | procListeners() | ||
242 | addProcessNamesToInodes() | ||
243 | tried = inodes | ||
244 | |||
245 | try: | ||
246 | cols = readOutput(terminalWidth)[0] | ||
247 | cols = int(cols) | ||
248 | except BaseException: | ||
249 | cols = 80 | ||
250 | |||
251 | # Print our own custom output header... | ||
252 | proto = "Proto" | ||
253 | addr = "Listening" | ||
254 | pid = "PID" | ||
255 | process = "Process" | ||
256 | print(f"{COLOR_HEADER}{proto:^5} {addr:^25} {pid:>5} {process:^30}") | ||
257 | |||
258 | # Could sort by anything: ip, port, proto, pid, command name | ||
259 | # (or even the fd integer if that provided any insight whatsoever) | ||
260 | def compareByPidOrPort(what): | ||
261 | k, v = what | ||
262 | # v = [ip, port, proto, pid, cmd] | ||
263 | # - OR - | ||
264 | # v = [ip, port, proto] | ||
265 | |||
266 | # If we're not running as root we can't pid and command mappings for | ||
267 | # the processes of other users, so sort the pids we did find at end | ||
268 | # of list and show UNKNOWN entries first | ||
269 | # (because the lines will be shorter most likely so the bigger visual | ||
270 | # weight should be lower in the display table) | ||
271 | try: | ||
272 | # Pid available! Sort by first pid, subsort by IP then port. | ||
273 | return (1, v[3], v[0], v[1]) | ||
274 | except BaseException: | ||
275 | # No pid available! Sort by port number then IP then... port again. | ||
276 | return (0, v[1], v[0], v[1]) | ||
277 | |||
278 | # Sort results by pid... | ||
279 | for name, vals in sorted(tried.items(), key=compareByPidOrPort): | ||
280 | attachedPids = vals[3:] | ||
281 | if attachedPids: | ||
282 | desc = [f"{pid:5} {' '.join(cmd)}" for pid, cmd in vals[3:]] | ||
283 | else: | ||
284 | # If not running as root, we won't have pid or process, so use | ||
285 | # defaults | ||
286 | desc = ["UNKNOWN (must be root for global pid mappings)"] | ||
287 | |||
288 | port = vals[1] | ||
289 | try: | ||
290 | # Convert port integer to service name if possible | ||
291 | port = socket.getservbyport(port) | ||
292 | except BaseException: | ||
293 | # If no match, just use port number directly. | ||
294 | pass | ||
295 | |||
296 | addr = f"{vals[0]}:{port}" | ||
297 | proto = vals[2] | ||
298 | |||
299 | # If IP address looks like it could be visible to the world, | ||
300 | # throw up a color. | ||
301 | # Note: due to port forwarding and NAT and other issues, | ||
302 | # this clearly isn't exhaustive. | ||
303 | if re.match(likelyLocalOnly, addr): | ||
304 | colorNotice = COLOR_OKAY | ||
305 | else: | ||
306 | colorNotice = COLOR_WARNING | ||
307 | |||
308 | isFirstLine = True | ||
309 | for line in desc: | ||
310 | if isFirstLine: | ||
311 | output = f"{colorNotice}{proto:5} {addr:25} {line}" | ||
312 | isFirstLine = False | ||
313 | else: | ||
314 | output = f"{' ':31} {line}" | ||
315 | |||
316 | # Be a polite terminal citizen by limiting our width to user's width | ||
317 | # (colors take up non-visible space, so add it to our col count) | ||
318 | print(output[:cols + (len(colorNotice) if isFirstLine else 0)]) | ||
319 | |||
320 | if ONLY_LOWEST_PID: | ||
321 | break | ||
322 | |||
323 | print(COLOR_END) | ||
324 | |||
325 | |||
326 | if __name__ == "__main__": | ||
327 | # cheap hack garbage way of setting one option | ||
328 | # if we need more options, obviously pull in argparse | ||
329 | if len(sys.argv) > 1: | ||
330 | ONLY_LOWEST_PID = True | ||
331 | else: | ||
332 | ONLY_LOWEST_PID = False | ||
333 | |||
334 | checkListenersProc() | ||
diff --git a/ansible/roles/common/files/ssh-transfer-only.sh b/ansible/roles/common/files/ssh-transfer-only.sh new file mode 100755 index 0000000..c1f0624 --- /dev/null +++ b/ansible/roles/common/files/ssh-transfer-only.sh | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # Only allow ssh commands starting with 'scp' or 'rsync' | ||
4 | case $SSH_ORIGINAL_COMMAND in | ||
5 | scp*) | ||
6 | $SSH_ORIGINAL_COMMAND ;; | ||
7 | rsync*) | ||
8 | $SSH_ORIGINAL_COMMAND ;; | ||
9 | *) | ||
10 | echo "Not allowed with this key: $SSH_ORIGINAL_COMMAND" ;; | ||
11 | esac | ||
diff --git a/ansible/roles/common/files/vimrc.local b/ansible/roles/common/files/vimrc.local new file mode 100644 index 0000000..378d91e --- /dev/null +++ b/ansible/roles/common/files/vimrc.local | |||
@@ -0,0 +1,25 @@ | |||
1 | set encoding=utf-8 | ||
2 | |||
3 | set ignorecase | ||
4 | set smartcase | ||
5 | |||
6 | set title | ||
7 | |||
8 | set backupdir=~/.vim-tmp,/tmp | ||
9 | set directory=~/.vim-tmp,/tmp | ||
10 | |||
11 | set ruler | ||
12 | |||
13 | filetype plugin indent on | ||
14 | |||
15 | set ai | ||
16 | set expandtab | ||
17 | set tabstop=4 | ||
18 | set shiftwidth=4 | ||
19 | |||
20 | autocmd BufEnter * :syntax sync fromstart | ||
21 | |||
22 | set hlsearch | ||
23 | colorscheme peachpuff | ||
24 | |||
25 | set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.o,*.dSYM,tags | ||
diff --git a/ansible/roles/common/handlers/main.yml b/ansible/roles/common/handlers/main.yml new file mode 100644 index 0000000..ade4fea --- /dev/null +++ b/ansible/roles/common/handlers/main.yml | |||
@@ -0,0 +1,20 @@ | |||
1 | --- | ||
2 | - name: reload sshd | ||
3 | service: | ||
4 | name: sshd | ||
5 | state: reloaded | ||
6 | |||
7 | - name: reload grub | ||
8 | command: update-grub | ||
9 | |||
10 | - name: double disable systemd ntp client | ||
11 | command: timedatectl set-ntp false | ||
12 | |||
13 | - name: clear motd cache | ||
14 | file: | ||
15 | path: "{{ item }}" | ||
16 | state: absent | ||
17 | loop: | ||
18 | - /var/cache/motd-news | ||
19 | - /run/motd.dynamic | ||
20 | - /run/motd.dynamic.new | ||
diff --git a/ansible/roles/common/tasks/main.yml b/ansible/roles/common/tasks/main.yml new file mode 100644 index 0000000..23de53c --- /dev/null +++ b/ansible/roles/common/tasks/main.yml | |||
@@ -0,0 +1,301 @@ | |||
1 | --- | ||
2 | # You can manually view how your OS-provided packages are supported with: | ||
3 | # ubuntu-support-status --show-all | ||
4 | - name: update packages | ||
5 | apt: | ||
6 | update_cache: yes | ||
7 | upgrade: safe | ||
8 | cache_valid_time: 3600 | ||
9 | |||
10 | |||
11 | - name: fix inputrc | ||
12 | copy: | ||
13 | src: inputrc | ||
14 | dest: /etc/inputrc | ||
15 | owner: root | ||
16 | group: root | ||
17 | mode: 0644 | ||
18 | |||
19 | - name: fix vimrc | ||
20 | copy: | ||
21 | src: vimrc.local | ||
22 | dest: /etc/vim/ | ||
23 | owner: root | ||
24 | group: root | ||
25 | mode: 0644 | ||
26 | |||
27 | |||
28 | - include_role: | ||
29 | name: ramdisk | ||
30 | |||
31 | |||
32 | - name: remove ubuntu call home reporting cron | ||
33 | cron: | ||
34 | cron_file: popularity-contest | ||
35 | state: absent | ||
36 | |||
37 | |||
38 | - name: remove low port restriction | ||
39 | sysctl: | ||
40 | name: net.ipv4.ip_unprivileged_port_start | ||
41 | value: 0 | ||
42 | state: present | ||
43 | sysctl_set: yes | ||
44 | |||
45 | |||
46 | # 3 means enable for outgoing and incoming connections | ||
47 | # 2 means enable for incoming connections | ||
48 | # 1 means enable for outgoing connections | ||
49 | # 0 means disabled | ||
50 | # Linux 3.13 (2014-01-19) and newer | ||
51 | - name: enable server and client TCP_FASTOPEN | ||
52 | sysctl: | ||
53 | name: net.ipv4.tcp_fastopen | ||
54 | value: 3 | ||
55 | state: present | ||
56 | sysctl_set: yes | ||
57 | |||
58 | |||
59 | # These were taken from: | ||
60 | # https://wiki.mozilla.org/Security/Server_Side_TLS#Pre-defined_DHE_groups | ||
61 | - name: populate known-good dhparams | ||
62 | copy: | ||
63 | src: "{{ item }}" | ||
64 | dest: "/etc/ssl/{{ item }}" | ||
65 | loop: | ||
66 | - ffdhe2048.pem | ||
67 | - ffdhe3072.pem | ||
68 | - ffdhe4096.pem | ||
69 | |||
70 | |||
71 | - name: configure /etc/hostname | ||
72 | hostname: | ||
73 | name: "{{ inventory_hostname }}" | ||
74 | |||
75 | #- name: Add IP address of all hosts to all hosts | ||
76 | # lineinfile: | ||
77 | # state: present | ||
78 | # dest: /etc/hosts | ||
79 | # regexp: '.*{{ item }}$' | ||
80 | # line: "{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" | ||
81 | # when: hostvars[item].ansible_default_ipv4.address is defined | ||
82 | # with_items: "{{ groups['all'] }}" | ||
83 | |||
84 | |||
85 | - name: configure sshd to only listen on IPv4 | ||
86 | lineinfile: | ||
87 | dest: /etc/ssh/sshd_config | ||
88 | regexp: '^#?AddressFamily' | ||
89 | line: "AddressFamily inet" # no ipv6 | ||
90 | state: present | ||
91 | notify: reload sshd | ||
92 | |||
93 | |||
94 | # Capture example: | ||
95 | #- replace: | ||
96 | # path: /etc/hosts | ||
97 | # regexp: '(\s+)old\.host\.name(\s+.*)?$' | ||
98 | # replace: '\1new.host.name\2' | ||
99 | # backup: yes | ||
100 | |||
101 | |||
102 | - name: fix motd | ||
103 | replace: | ||
104 | path: /etc/default/motd-news | ||
105 | regexp: 'https://motd.ubuntu.com' | ||
106 | replace: 'https://matt.sh/motd' | ||
107 | notify: | ||
108 | - clear motd cache | ||
109 | |||
110 | |||
111 | # Verify against: | ||
112 | # systemctl list-timers | ||
113 | - name: disable more automated call home reporting | ||
114 | systemd: | ||
115 | name: "{{ item }}" | ||
116 | state: stopped | ||
117 | enabled: False | ||
118 | loop: | ||
119 | - apt-daily-upgrade.timer | ||
120 | - apt-daily.timer | ||
121 | - motd-news.timer | ||
122 | |||
123 | |||
124 | - name: remove ubuntu self-advertising | ||
125 | file: | ||
126 | path: "/etc/update-motd.d/{{ item }}" | ||
127 | state: absent | ||
128 | loop: | ||
129 | - 91-release-upgrade | ||
130 | - 80-livepatch | ||
131 | - 10-help-text | ||
132 | notify: | ||
133 | - clear motd cache | ||
134 | |||
135 | |||
136 | # Ubuntu's pam_motd.so shows you /etc/legal | ||
137 | # on login if you don't have ~/.cache/motd.legal-displayed | ||
138 | # There is no way to disable the creation of that file in ~/.cache on login, | ||
139 | # but we can wipe out the message for new users. | ||
140 | - name: remove login disclaimer | ||
141 | file: | ||
142 | path: /etc/legal | ||
143 | state: absent | ||
144 | |||
145 | |||
146 | - name: place net-listeners.py | ||
147 | copy: | ||
148 | src: net-listeners.py | ||
149 | dest: /usr/local/bin/ | ||
150 | owner: root | ||
151 | group: root | ||
152 | mode: 0755 | ||
153 | |||
154 | - name: place scp/rsync-only ssh restriction capability | ||
155 | copy: | ||
156 | src: ssh-transfer-only.sh | ||
157 | dest: /usr/local/bin/ | ||
158 | owner: root | ||
159 | group: root | ||
160 | mode: 0755 | ||
161 | |||
162 | # can't setsid 04755 scripts, so enable script with global passwordless sudo | ||
163 | - name: enable all user running of net-listeners.py | ||
164 | lineinfile: | ||
165 | path: /etc/sudoers.d/net-listeners | ||
166 | regexp: "listeners.py" | ||
167 | line: "ALL ALL = (root) NOPASSWD: /usr/local/bin/net-listeners.py" | ||
168 | create: yes | ||
169 | mode: 0440 | ||
170 | |||
171 | - name: add uptime and uname to login motd | ||
172 | lineinfile: | ||
173 | dest: /etc/update-motd.d/00-header | ||
174 | line: "{{ item }}" | ||
175 | state: present | ||
176 | loop: | ||
177 | - printf "\n$(w -us)\n" | ||
178 | |||
179 | - name: add listening watcher to global login config | ||
180 | lineinfile: | ||
181 | dest: /etc/bash.bashrc | ||
182 | line: "{{ item }}" | ||
183 | state: present | ||
184 | loop: | ||
185 | # Only show output when running a login, not when starting a sudo shell | ||
186 | - "[[ -z $SUDO_UID ]] && sudo /usr/local/bin/net-listeners.py" | ||
187 | |||
188 | - name: ensure system grub template has serial access | ||
189 | lineinfile: | ||
190 | dest: /etc/default/grub | ||
191 | regexp: '^GRUB_CMDLINE_LINUX=' | ||
192 | line: 'GRUB_CMDLINE_LINUX="console=ttyS0 {{ grub.extras }}"' | ||
193 | state: present | ||
194 | notify: reload grub | ||
195 | |||
196 | |||
197 | # This is an ops opinion. For more advanced needs, modify here or just template | ||
198 | # the entire sshd_config directly. | ||
199 | - name: configure sshd to only listen on local IP | ||
200 | lineinfile: | ||
201 | dest: /etc/ssh/sshd_config | ||
202 | regexp: '^#?ListenAddress' | ||
203 | line: "ListenAddress {{ hostvars[inventory_hostname]['ansible_' + network.interface.private]['ipv4']['address'] }}" | ||
204 | state: present | ||
205 | notify: reload sshd | ||
206 | |||
207 | |||
208 | - name: install system tools | ||
209 | apt: | ||
210 | pkg: | ||
211 | # acl is required for ansible to "become_user" as someone non-root because | ||
212 | # of permissions on its temporary files. Ansible will setfacl on temp files | ||
213 | # so it doesn't have to 0666 everything just so a new user can modify things. | ||
214 | - acl | ||
215 | |||
216 | # you aren't a linux server without sending nightly summary emails | ||
217 | - logwatch | ||
218 | |||
219 | # apt helpers for repo installs not included by default for some reason | ||
220 | - software-properties-common | ||
221 | |||
222 | # production CA bundles so we don't get unknown CA errors | ||
223 | - ca-certificates | ||
224 | |||
225 | # Maintains high numbers in /proc/sys/kernel/random/entropy_avail | ||
226 | - rng-tools | ||
227 | |||
228 | # should we use a more modern thing than collect? distributed osquery? | ||
229 | - collectd | ||
230 | |||
231 | # make sure 'install_recommends: no' or this installs lots of other stuff | ||
232 | - vim-nox | ||
233 | |||
234 | # rrdtool only installed so we can be lazy and generate graphs on-demand | ||
235 | # with: /usr/share/doc/collectd-core/examples/collectd2html.pl | ||
236 | # TODO: enable centralized reporting system | ||
237 | - rrdtool | ||
238 | |||
239 | # netstat, mii-tool, etc | ||
240 | - net-tools | ||
241 | install_recommends: no | ||
242 | state: latest | ||
243 | |||
244 | # use a modern ntp client+server. | ||
245 | # | ||
246 | # systemd actually has a built-in ntp client called 'systemd-timesyncd' | ||
247 | # You can view its status with: | ||
248 | # journalctl -u systemd-timesyncd | ||
249 | # timedatectl | ||
250 | # | ||
251 | # Installing chrony will disable systemd-timesyncd | ||
252 | # (represented in apt with "Replaces: time-daemon") | ||
253 | # but it doesn't _actually_ disable it according to timedatectl (bug?) | ||
254 | # so we also manually run 'timedatectl set-ntp false' just to confirm. | ||
255 | # A good writeup about systemd-timesyncd lives at: | ||
256 | # https://wiki.archlinux.org/index.php/systemd-timesyncd | ||
257 | # | ||
258 | # You can view your live chrony status with: | ||
259 | # chronyc tracking | ||
260 | # chronyc sources | ||
261 | # chronyc sourcestats | ||
262 | # | ||
263 | # ...and that's a lot more detail than the built-in garabage systemd-timesyncd | ||
264 | # client will tell you about how your system time is being managed. | ||
265 | # | ||
266 | # chrony is both an ntp client with a remote administration interface | ||
267 | # and an ntp server, but by default chrony does not enable remote admin | ||
268 | # or ntp serving without additional explicit configuration (chrony.conf). | ||
269 | # | ||
270 | # For more details about becoming an ntp server and remote time administartion, | ||
271 | # see sections 2.2 and 2.5 of: | ||
272 | # https://chrony.tuxfamily.org/faq.html#_how_do_i_make_an_ntp_server_from_an_ntp_client | ||
273 | - name: install ntp client | ||
274 | apt: | ||
275 | pkg: chrony | ||
276 | state: latest | ||
277 | notify: | ||
278 | - double disable systemd ntp client | ||
279 | |||
280 | # If ansible facts aren't enough, we can get puppet and chef facts too: | ||
281 | #- name: install facter | ||
282 | # apt: | ||
283 | # pkg: facter | ||
284 | # state: latest | ||
285 | # | ||
286 | #- name: install ohai | ||
287 | # apt: | ||
288 | # pkg: facter | ||
289 | # state: latest | ||
290 | |||
291 | |||
292 | # cleanup | ||
293 | - name: cleanup packaging | ||
294 | apt: | ||
295 | autoclean: yes | ||
296 | autoremove: yes | ||
297 | |||
298 | # If needed, build and provide: | ||
299 | # | ||
300 | # Build for nsjail: | ||
301 | # apt install protobu* bison flex pkg-config libprotobuf-dev | ||
diff --git a/ansible/roles/disableFirewall/files/modprobe.d/blacklist-iptables.conf b/ansible/roles/disableFirewall/files/modprobe.d/blacklist-iptables.conf new file mode 100644 index 0000000..4655374 --- /dev/null +++ b/ansible/roles/disableFirewall/files/modprobe.d/blacklist-iptables.conf | |||
@@ -0,0 +1,13 @@ | |||
1 | # Don't load iptables on startup (or ever)! | ||
2 | |||
3 | # These look weird, but the 'blacklist' command still allows | ||
4 | # module insertion. | ||
5 | # | ||
6 | # This method defines a load-time alias so when you load the module, | ||
7 | # it runs a delegated command to load the module instead, but in | ||
8 | # the case of denying modules completely, just run nothing. | ||
9 | install ip6table_filter /bin/true | ||
10 | install iptable_filter /bin/true | ||
11 | install ip6_tables /bin/true | ||
12 | install ip_tables /bin/true | ||
13 | install x_tables /bin/true | ||
diff --git a/ansible/roles/disableFirewall/tasks/main.yml b/ansible/roles/disableFirewall/tasks/main.yml new file mode 100644 index 0000000..9454702 --- /dev/null +++ b/ansible/roles/disableFirewall/tasks/main.yml | |||
@@ -0,0 +1,22 @@ | |||
1 | --- | ||
2 | # Our mail systems only listen to SMTP(S) and IMAP(S) | ||
3 | # so we can disable all firewalls | ||
4 | # This stops ufw, then uninstalls ufw and iptables (and ip6tables) | ||
5 | - name: remove firewall | ||
6 | apt: | ||
7 | name: iptables | ||
8 | state: absent | ||
9 | register: firewallKaboom | ||
10 | |||
11 | # removing iptables doesn't actually stop iptables processing, | ||
12 | # so let's force remove all packet processing from the kernel itself here | ||
13 | # TODO: this conditional could be better. would be nice if we had a fact | ||
14 | # of loaded kernel modules to query the presence/absence of | ||
15 | - name: unload firewall | ||
16 | command: modprobe -r ip6table_filter iptable_filter ip6_tables ip_tables x_tables | ||
17 | when: firewallKaboom.changed | ||
18 | |||
19 | - name: disable iptables from reappearing in the future | ||
20 | copy: | ||
21 | src: modprobe.d/ | ||
22 | dest: /etc/modprobe.d/ | ||
diff --git a/ansible/roles/dovecot/files/dovecot/authdb.sqlite3.empty b/ansible/roles/dovecot/files/dovecot/authdb.sqlite3.empty new file mode 100644 index 0000000..f1e0330 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/authdb.sqlite3.empty | |||
Binary files differ | |||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/10-acl.conf b/ansible/roles/dovecot/files/dovecot/conf.d/10-acl.conf new file mode 100644 index 0000000..f9fa335 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/10-acl.conf | |||
@@ -0,0 +1,15 @@ | |||
1 | mail_plugins = $mail_plugins acl | ||
2 | |||
3 | protocol imap { | ||
4 | mail_plugins = $mail_plugins imap_acl | ||
5 | } | ||
6 | |||
7 | plugin { | ||
8 | acl_defaults_from_inbox = yes | ||
9 | } | ||
10 | |||
11 | # Should saving a mail to a nonexistent mailbox automatically create it? | ||
12 | lda_mailbox_autocreate = yes | ||
13 | |||
14 | # Should automatically created mailboxes be also automatically subscribed? | ||
15 | lda_mailbox_autosubscribe = yes | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/10-auth.conf b/ansible/roles/dovecot/files/dovecot/conf.d/10-auth.conf new file mode 100644 index 0000000..4e23fa8 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/10-auth.conf | |||
@@ -0,0 +1,46 @@ | |||
1 | # cache all authentication results for one hour | ||
2 | #auth_cache_size = 10M | ||
3 | #auth_cache_ttl = 1 hour | ||
4 | #auth_cache_negative_ttl = 1 hour | ||
5 | |||
6 | # Don't cache password details, otherwise password changes require a server HUP | ||
7 | # before the server will re-query the password data source. | ||
8 | auth_cache_size = 0 | ||
9 | |||
10 | # only use plain username/password auth - OK since everything is over TLS | ||
11 | auth_mechanisms = plain | ||
12 | |||
13 | # passdb specifies how users are authenticated - sql here, and | ||
14 | # our sql config specifies the sqlite filename with queries to use | ||
15 | passdb { | ||
16 | driver = sql | ||
17 | args = /etc/dovecot/dovecot-sql.conf.ext | ||
18 | } | ||
19 | |||
20 | # userdb specifies the location of users' "home" directories - where their | ||
21 | # mail is stored. e.g. /var/mail/vhosts/exmaple.com/user | ||
22 | # %d = domain, %n = user | ||
23 | # We can't use "prefetch" because postfix can't read users from "prefetch" db, | ||
24 | # and we can't use 'static' because the doveadm tool needs to iterate users | ||
25 | # for purging zero refcount deleted mails, so we give a userdb of sql here | ||
26 | # and specify a "get all users" SQL query in the configuration file. | ||
27 | userdb { | ||
28 | driver = sql | ||
29 | args = /etc/dovecot/dovecot-sql.conf.ext | ||
30 | } | ||
31 | |||
32 | # UNIX socket path to master authentication server to find users. | ||
33 | # This is used by imap (for shared users) and lda. | ||
34 | auth_socket_path = /var/run/dovecot/auth-userdb | ||
35 | |||
36 | # Respect /etc/hosts.deny (populated by fail2ban) | ||
37 | # You can use /etc/hosts.allow to countermand fail2ban decisions. | ||
38 | login_access_sockets = tcpwrap | ||
39 | |||
40 | service tcpwrap { | ||
41 | unix_listener login/tcpwrap { | ||
42 | group = $default_login_user | ||
43 | mode = 0600 | ||
44 | user = $default_login_user | ||
45 | } | ||
46 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/10-mail.conf b/ansible/roles/dovecot/files/dovecot/conf.d/10-mail.conf new file mode 100644 index 0000000..6c03965 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/10-mail.conf | |||
@@ -0,0 +1,28 @@ | |||
1 | # default home directory location for all users | ||
2 | mail_home = /var/mail/vhosts/%d/%n | ||
3 | |||
4 | # directory to store mail. The tilda makes it relative to the *dovecot* | ||
5 | # virtual home directory. | ||
6 | # | ||
7 | # I use mdbox - this is Dovecot's own high-performance mail store format. | ||
8 | # There are other slower, more "traditional" formats you can choose from. | ||
9 | # Read about them here: https://wiki2.dovecot.org/MailboxFormat | ||
10 | mail_location = mdbox:~/mdbox | ||
11 | |||
12 | # nothing fancy - just a standard default namespace with '/' as the | ||
13 | # hierarchy separator | ||
14 | namespace inbox { | ||
15 | separator = / | ||
16 | inbox = yes | ||
17 | } | ||
18 | |||
19 | # set this to the group that owns your vmail directory. | ||
20 | mail_privileged_group = vmail | ||
21 | |||
22 | # these lines enable attachment deduplication. Attachments must be somewhat | ||
23 | # large (64k) to store them separately from the mail store. | ||
24 | mail_attachment_dir = /var/mail/attachments | ||
25 | mail_attachment_min_size = 64k | ||
26 | |||
27 | # we'll uncomment this after we set up Solr in the following section: | ||
28 | # mail_plugins = $mail_plugins fts fts_solr | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/10-master.conf b/ansible/roles/dovecot/files/dovecot/conf.d/10-master.conf new file mode 100644 index 0000000..f99d0f4 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/10-master.conf | |||
@@ -0,0 +1,82 @@ | |||
1 | # to improve performance, disable fsync globally - we will enable it for | ||
2 | # some specific services later on | ||
3 | mail_fsync = never | ||
4 | |||
5 | service imap-login { | ||
6 | # plain-text IMAP should only be accessible from localhost | ||
7 | inet_listener imap { | ||
8 | address = 127.0.0.1, ::1 | ||
9 | } | ||
10 | |||
11 | # enable high-performance mode, described here: | ||
12 | # https://wiki.dovecot.org/LoginProcess | ||
13 | service_count = 0 | ||
14 | |||
15 | # set to the number of CPU cores on your server | ||
16 | process_min_avail = 3 | ||
17 | vsz_limit = 1G | ||
18 | } | ||
19 | |||
20 | # disable POP3 altogether | ||
21 | service pop3-login { | ||
22 | inet_listener pop3 { | ||
23 | port = 0 | ||
24 | } | ||
25 | |||
26 | inet_listener pop3s { | ||
27 | port = 0 | ||
28 | } | ||
29 | } | ||
30 | |||
31 | # enable semi-long-lived IMAP processes to improve performance | ||
32 | service imap { | ||
33 | service_count = 256 | ||
34 | # set to the number of CPU cores on your server | ||
35 | process_min_avail = 3 | ||
36 | } | ||
37 | |||
38 | # expose an LMTP socket for postfix to deliver mail | ||
39 | service lmtp { | ||
40 | unix_listener /var/spool/postfix/private/dovecot-lmtp { | ||
41 | group = postfix | ||
42 | mode = 0600 | ||
43 | user = postfix | ||
44 | } | ||
45 | } | ||
46 | |||
47 | service auth { | ||
48 | # auth_socket_path points to this userdb socket by default. It's typically | ||
49 | # used by dovecot-lda, doveadm, possibly imap process, etc. Users that have | ||
50 | # full permissions to this socket are able to get a list of all usernames and | ||
51 | # get the results of everyone's userdb lookups. | ||
52 | # | ||
53 | # The default 0666 mode allows anyone to connect to the socket, but the | ||
54 | # userdb lookups will succeed only if the userdb returns an "uid" field that | ||
55 | # matches the caller process's UID. Also if caller's uid or gid matches the | ||
56 | # socket's uid or gid the lookup succeeds. Anything else causes a failure. | ||
57 | # | ||
58 | # To give the caller full permissions to lookup all users, set the mode to | ||
59 | # something else than 0666 and Dovecot lets the kernel enforce the | ||
60 | # permissions (e.g. 0777 allows everyone full permissions). | ||
61 | |||
62 | # auth for postfix | ||
63 | unix_listener /var/spool/postfix/private/auth { | ||
64 | mode = 0666 | ||
65 | user = postfix | ||
66 | group = postfix | ||
67 | } | ||
68 | |||
69 | # auth for doveadm tools | ||
70 | unix_listener auth-userdb { | ||
71 | mode = 0666 | ||
72 | user = vmail | ||
73 | group = vmail | ||
74 | } | ||
75 | |||
76 | client_limit = 840 | ||
77 | } | ||
78 | |||
79 | # no need to run this as root | ||
80 | service auth-worker { | ||
81 | user = vmail | ||
82 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/15-lda.conf b/ansible/roles/dovecot/files/dovecot/conf.d/15-lda.conf new file mode 100644 index 0000000..32ca50d --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/15-lda.conf | |||
@@ -0,0 +1,7 @@ | |||
1 | # configuration for mail delivered by the `dovecot-lda` command. Shouldn't | ||
2 | # be needed since we are using LMTP, but kept for backwards compatibility. | ||
3 | protocol lda { | ||
4 | # use fsync for write-safety - this deals with delivering actual mail | ||
5 | mail_fsync = optimized | ||
6 | mail_plugins = $mail_plugins sieve | ||
7 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/15-mailboxes.conf b/ansible/roles/dovecot/files/dovecot/conf.d/15-mailboxes.conf new file mode 100644 index 0000000..8674b0b --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/15-mailboxes.conf | |||
@@ -0,0 +1,24 @@ | |||
1 | # define any special IMAP folders here. You can force them to be created or | ||
2 | # created+subscribed automatically used the `auto` option. | ||
3 | namespace inbox { | ||
4 | mailbox Drafts { | ||
5 | auto = subscribe | ||
6 | special_use = \Drafts | ||
7 | } | ||
8 | mailbox Junk { | ||
9 | auto = create | ||
10 | special_use = \Junk | ||
11 | } | ||
12 | mailbox Trash { | ||
13 | auto = create | ||
14 | special_use = \Trash | ||
15 | } | ||
16 | mailbox Archive { | ||
17 | auto = subscribe | ||
18 | special_use = \Archive | ||
19 | } | ||
20 | mailbox Sent { | ||
21 | auto = subscribe | ||
22 | special_use = \Sent | ||
23 | } | ||
24 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/20-imap.conf b/ansible/roles/dovecot/files/dovecot/conf.d/20-imap.conf new file mode 100644 index 0000000..7b32396 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/20-imap.conf | |||
@@ -0,0 +1,10 @@ | |||
1 | # Use a longer IDLE interval to reduce network chatter and save battery | ||
2 | # life. Max is 30 minutes. | ||
3 | imap_idle_notify_interval = 29 mins | ||
4 | |||
5 | protocol imap { | ||
6 | # max IMAP connections per IP address | ||
7 | mail_max_userip_connections = 50 | ||
8 | # imap_sieve will be used for spam training by rspamd | ||
9 | mail_plugins = $mail_plugins imap_sieve | ||
10 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/20-lmtp.conf b/ansible/roles/dovecot/files/dovecot/conf.d/20-lmtp.conf new file mode 100644 index 0000000..a51ee42 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/20-lmtp.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | protocol lmtp { | ||
2 | # use fsync for write-safety - this deals with delivering actual mail | ||
3 | mail_fsync = optimized | ||
4 | mail_plugins = $mail_plugins sieve | ||
5 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/90-imapsieve.conf b/ansible/roles/dovecot/files/dovecot/conf.d/90-imapsieve.conf new file mode 100644 index 0000000..26987b1 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/90-imapsieve.conf | |||
@@ -0,0 +1,18 @@ | |||
1 | plugin { | ||
2 | sieve_plugins = sieve_imapsieve sieve_extprograms | ||
3 | |||
4 | # From elsewhere to Junk folder | ||
5 | imapsieve_mailbox1_name = Junk | ||
6 | imapsieve_mailbox1_causes = COPY | ||
7 | imapsieve_mailbox1_before = file:/etc/dovecot/sieve/report-spam.sieve | ||
8 | |||
9 | # From Junk folder to elsewhere | ||
10 | imapsieve_mailbox2_name = * | ||
11 | imapsieve_mailbox2_from = Junk | ||
12 | imapsieve_mailbox2_causes = COPY | ||
13 | imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve | ||
14 | |||
15 | sieve_pipe_bin_dir = /etc/dovecot/sieve | ||
16 | |||
17 | sieve_global_extensions = +vnd.dovecot.pipe | ||
18 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/conf.d/90-sieve.conf b/ansible/roles/dovecot/files/dovecot/conf.d/90-sieve.conf new file mode 100644 index 0000000..9a753bf --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/conf.d/90-sieve.conf | |||
@@ -0,0 +1,34 @@ | |||
1 | plugin { | ||
2 | # 'active' is a symlink to one sieve source script inside directory at 'file' | ||
3 | sieve = file:~/sieve;active=~/.dovecot.sieve | ||
4 | |||
5 | # directory of global sieve scripts to run before and after processing ALL | ||
6 | # incoming mail | ||
7 | sieve_before = /etc/dovecot/sieve-before.d | ||
8 | sieve_after = /etc/dovecot/sieve-after.d | ||
9 | |||
10 | # make sieve aware of [email protected] aliases | ||
11 | recipient_delimiter = + | ||
12 | |||
13 | |||
14 | # no limits on script size or actions | ||
15 | sieve_quota_max_storage = 0 | ||
16 | sieve_max_script_size = 0 | ||
17 | sieve_max_actions = 0 | ||
18 | |||
19 | sieve_extensions = +spamtest +spamtestplus | ||
20 | |||
21 | sieve_spamtest_status_header = X-Spam-Score | ||
22 | sieve_spamtest_status_type = strlen | ||
23 | |||
24 | # X-Spamd-Bar: +++++++++ | ||
25 | sieve_spamtest_max_value = 9 | ||
26 | |||
27 | |||
28 | # X-Spamd-Result: default: False [9.19 / 15.00]; | ||
29 | # (regex not fixed to capture the above) | ||
30 | #sieve_spamtest_status_type = score | ||
31 | #sieve_spamtest_status_header = \ | ||
32 | # X-Spamd-Result: [[:alnum:]]+, score=(-?[[:digit:]]+\.[[:digit:]]) | ||
33 | #sieve_spamtest_max_value = 5.0 | ||
34 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/dovecot-sql.conf.ext b/ansible/roles/dovecot/files/dovecot/dovecot-sql.conf.ext new file mode 100644 index 0000000..f248243 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/dovecot-sql.conf.ext | |||
@@ -0,0 +1,150 @@ | |||
1 | # This file is commonly accessed via passdb {} or userdb {} section in | ||
2 | # conf.d/auth-sql.conf.ext | ||
3 | |||
4 | # This file is opened as root, so it should be owned by root and mode 0600. | ||
5 | # | ||
6 | # http://wiki2.dovecot.org/AuthDatabase/SQL | ||
7 | # | ||
8 | # For the sql passdb module, you'll need a database with a table that | ||
9 | # contains fields for at least the username and password. If you want to | ||
10 | # use the user@domain syntax, you might want to have a separate domain | ||
11 | # field as well. | ||
12 | # | ||
13 | # If your users all have the same uig/gid, and have predictable home | ||
14 | # directories, you can use the static userdb module to generate the home | ||
15 | # dir based on the username and domain. In this case, you won't need fields | ||
16 | # for home, uid, or gid in the database. | ||
17 | # | ||
18 | # If you prefer to use the sql userdb module, you'll want to add fields | ||
19 | # for home, uid, and gid. Here is an example table: | ||
20 | # | ||
21 | # CREATE TABLE users ( | ||
22 | # username VARCHAR(128) NOT NULL, | ||
23 | # domain VARCHAR(128) NOT NULL, | ||
24 | # password VARCHAR(64) NOT NULL, | ||
25 | # home VARCHAR(255) NOT NULL, | ||
26 | # uid INTEGER NOT NULL, | ||
27 | # gid INTEGER NOT NULL, | ||
28 | # active CHAR(1) DEFAULT 'Y' NOT NULL | ||
29 | # ); | ||
30 | |||
31 | # Database driver: mysql, pgsql, sqlite | ||
32 | driver = sqlite | ||
33 | |||
34 | # Database connection string. This is driver-specific setting. | ||
35 | # | ||
36 | # HA / round-robin load-balancing is supported by giving multiple host | ||
37 | # settings, like: host=sql1.host.org host=sql2.host.org | ||
38 | # | ||
39 | # pgsql: | ||
40 | # For available options, see the PostgreSQL documention for the | ||
41 | # PQconnectdb function of libpq. | ||
42 | # Use maxconns=n (default 5) to change how many connections Dovecot can | ||
43 | # create to pgsql. | ||
44 | # | ||
45 | # mysql: | ||
46 | # Basic options emulate PostgreSQL option names: | ||
47 | # host, port, user, password, dbname | ||
48 | # | ||
49 | # But also adds some new settings: | ||
50 | # client_flags - See MySQL manual | ||
51 | # connect_timeout - Connect timeout in seconds (default: 5) | ||
52 | # read_timeout - Read timeout in seconds (default: 30) | ||
53 | # write_timeout - Write timeout in seconds (default: 30) | ||
54 | # ssl_ca, ssl_ca_path - Set either one or both to enable SSL | ||
55 | # ssl_cert, ssl_key - For sending client-side certificates to server | ||
56 | # ssl_cipher - Set minimum allowed cipher security (default: HIGH) | ||
57 | # ssl_verify_server_cert - Verify that the name in the server SSL certificate | ||
58 | # matches the host (default: no) | ||
59 | # option_file - Read options from the given file instead of | ||
60 | # the default my.cnf location | ||
61 | # option_group - Read options from the given group (default: client) | ||
62 | # | ||
63 | # You can connect to UNIX sockets by using host: host=/var/run/mysql.sock | ||
64 | # Note that currently you can't use spaces in parameters. | ||
65 | # | ||
66 | # sqlite: | ||
67 | # The path to the database file. | ||
68 | # | ||
69 | # Examples: | ||
70 | # connect = host=192.168.1.1 dbname=users | ||
71 | # connect = host=sql.example.com dbname=virtual user=virtual password=blarg | ||
72 | # connect = /etc/dovecot/authdb.sqlite | ||
73 | # | ||
74 | connect = /etc/dovecot/authdb.sqlite | ||
75 | |||
76 | # Default password scheme. | ||
77 | # | ||
78 | # List of supported schemes is in | ||
79 | # http://wiki2.dovecot.org/Authentication/PasswordSchemes | ||
80 | # | ||
81 | #default_pass_scheme = SHA512-CRYPT | ||
82 | |||
83 | # passdb query to retrieve the password. It can return fields: | ||
84 | # password - The user's password. This field must be returned. | ||
85 | # user - user@domain from the database. Needed with case-insensitive lookups. | ||
86 | # username and domain - An alternative way to represent the "user" field. | ||
87 | # | ||
88 | # The "user" field is often necessary with case-insensitive lookups to avoid | ||
89 | # e.g. "name" and "nAme" logins creating two different mail directories. If | ||
90 | # your user and domain names are in separate fields, you can return "username" | ||
91 | # and "domain" fields instead of "user". | ||
92 | # | ||
93 | # The query can also return other fields which have a special meaning, see | ||
94 | # http://wiki2.dovecot.org/PasswordDatabase/ExtraFields | ||
95 | # | ||
96 | # Commonly used available substitutions (see http://wiki2.dovecot.org/Variables | ||
97 | # for full list): | ||
98 | # %u = entire user@domain | ||
99 | # %n = user part of user@domain | ||
100 | # %d = domain part of user@domain | ||
101 | # | ||
102 | # Note that these can be used only as input to SQL query. If the query outputs | ||
103 | # any of these substitutions, they're not touched. Otherwise it would be | ||
104 | # difficult to have eg. usernames containing '%' characters. | ||
105 | # | ||
106 | # Example: | ||
107 | # password_query = SELECT userid AS user, pw AS password \ | ||
108 | # FROM users WHERE userid = '%u' AND active = 'Y' | ||
109 | # | ||
110 | password_query = \ | ||
111 | SELECT '%u' AS username, domain, password \ | ||
112 | FROM users WHERE userid = '%n' AND domain = '%d' | ||
113 | |||
114 | # You can update (or modify this a bit to insert) user passwords in a shell with: | ||
115 | # sqlite3 authdb.sqlite "update users set password='$(doveadm pw -s SHA512-CRYPT -r 1856250)' where userid='USERNAME' and domain = 'DOMAIN';" | ||
116 | |||
117 | |||
118 | # userdb query to retrieve the user information. It can return fields: | ||
119 | # uid - System UID (overrides mail_uid setting) | ||
120 | # gid - System GID (overrides mail_gid setting) | ||
121 | # home - Home directory | ||
122 | # mail - Mail location (overrides mail_location setting) | ||
123 | # | ||
124 | # None of these are strictly required. If you use a single UID and GID, and | ||
125 | # home or mail directory fits to a template string, you could use userdb static | ||
126 | # instead. For a list of all fields that can be returned, see | ||
127 | # http://wiki2.dovecot.org/UserDatabase/ExtraFields | ||
128 | # | ||
129 | # Examples: | ||
130 | # user_query = SELECT home, uid, gid FROM users WHERE userid = '%u' | ||
131 | # user_query = SELECT dir AS home, user AS uid, group AS gid FROM users where userid = '%u' | ||
132 | # user_query = SELECT home, 501 AS uid, 501 AS gid FROM users WHERE userid = '%u' | ||
133 | # | ||
134 | user_query = \ | ||
135 | SELECT "/var/mail/vhosts/" || '%d' || '/' || '%n' AS home, 145 as uid, 145 as gid | ||
136 | |||
137 | # If you wish to avoid two SQL lookups (passdb + userdb), you can use | ||
138 | # userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll | ||
139 | # also have to return userdb fields in password_query prefixed with "userdb_" | ||
140 | # string. For example: | ||
141 | password_query = \ | ||
142 | SELECT '%u' AS user, password, \ | ||
143 | "/var/mail/vhosts/" || '%d' || '/' || '%n' AS userdb_home, 145 AS userdb_uid, 145 AS userdb_gid \ | ||
144 | FROM users WHERE userid = '%n' AND domain = '%d' | ||
145 | |||
146 | # Query to get a list of all usernames. | ||
147 | # This iteration is used for things like globally purging zero refcount emails | ||
148 | # for all users, but to get all users, we have to iterate the user storage, | ||
149 | # hence this iterator query is required. | ||
150 | iterate_query = SELECT userid AS user FROM users | ||
diff --git a/ansible/roles/dovecot/files/dovecot/dovecot.conf b/ansible/roles/dovecot/files/dovecot/dovecot.conf new file mode 100644 index 0000000..4304fa6 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/dovecot.conf | |||
@@ -0,0 +1,19 @@ | |||
1 | # IMAP for remote access, LMTP for local delivery | ||
2 | protocols = imap lmtp | ||
3 | |||
4 | # set these to the uid of your `vmail` user | ||
5 | first_valid_uid = 145 | ||
6 | last_valid_uid = 145 | ||
7 | |||
8 | #mail_debug = yes | ||
9 | ##auth_verbose = yes | ||
10 | ##auth_debug = yes | ||
11 | ##auth_debug_passwords = yes | ||
12 | ##auth_verbose_passwords = yes | ||
13 | |||
14 | |||
15 | mail_uid = vmail | ||
16 | mail_gid = vmail | ||
17 | |||
18 | !include conf.d/*.conf | ||
19 | !include_try local.conf | ||
diff --git a/ansible/roles/dovecot/files/dovecot/sieve-before.d/10-rspamd.sieve b/ansible/roles/dovecot/files/dovecot/sieve-before.d/10-rspamd.sieve new file mode 100644 index 0000000..7931a71 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/sieve-before.d/10-rspamd.sieve | |||
@@ -0,0 +1,5 @@ | |||
1 | require ["fileinto"]; | ||
2 | |||
3 | if header :is "X-Spam" "Yes" { | ||
4 | fileinto "Junk"; | ||
5 | } | ||
diff --git a/ansible/roles/dovecot/files/dovecot/sieve/report-ham.sieve b/ansible/roles/dovecot/files/dovecot/sieve/report-ham.sieve new file mode 100644 index 0000000..2ad40aa --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/sieve/report-ham.sieve | |||
@@ -0,0 +1,23 @@ | |||
1 | require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; | ||
2 | |||
3 | if environment :matches "imap.mailbox" "*" { | ||
4 | set "mailbox" "${1}"; | ||
5 | } | ||
6 | |||
7 | # This line is important because when we delete from Junk/Spam, | ||
8 | # messages get moved to Trash, which tirggers the "message moved out of | ||
9 | # spam" script (this script) which—usually!—trains the originally classified | ||
10 | # Spam as not-spam. | ||
11 | # BUT, this is just a delete! If we train our spam as not-spam on delete, that | ||
12 | # defeats our goals. | ||
13 | # In short, this always gets run on a message being moved out of Spam, but if | ||
14 | # the target mailbox is Trash, just don't run the trainer this time. | ||
15 | if string "${mailbox}" "Trash" { | ||
16 | stop; | ||
17 | } | ||
18 | |||
19 | if environment :matches "imap.email" "*" { | ||
20 | set "email" "${1}"; | ||
21 | } | ||
22 | |||
23 | pipe :copy "train-ham.sh" [ "${email}" ]; | ||
diff --git a/ansible/roles/dovecot/files/dovecot/sieve/report-spam.sieve b/ansible/roles/dovecot/files/dovecot/sieve/report-spam.sieve new file mode 100644 index 0000000..4ed95d7 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/sieve/report-spam.sieve | |||
@@ -0,0 +1,7 @@ | |||
1 | require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"]; | ||
2 | |||
3 | if environment :matches "imap.email" "*" { | ||
4 | set "email" "${1}"; | ||
5 | } | ||
6 | |||
7 | pipe :copy "train-spam.sh" [ "${email}" ]; | ||
diff --git a/ansible/roles/dovecot/files/dovecot/sieve/train-ham.sh b/ansible/roles/dovecot/files/dovecot/sieve/train-ham.sh new file mode 100755 index 0000000..b0f30fd --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/sieve/train-ham.sh | |||
@@ -0,0 +1 @@ | |||
exec /usr/bin/rspamc --connect localhost:11334 learn_ham | |||
diff --git a/ansible/roles/dovecot/files/dovecot/sieve/train-spam.sh b/ansible/roles/dovecot/files/dovecot/sieve/train-spam.sh new file mode 100755 index 0000000..bf1b920 --- /dev/null +++ b/ansible/roles/dovecot/files/dovecot/sieve/train-spam.sh | |||
@@ -0,0 +1 @@ | |||
exec /usr/bin/rspamc --connect localhost:11334 learn_spam | |||
diff --git a/ansible/roles/dovecot/handlers/main.yml b/ansible/roles/dovecot/handlers/main.yml new file mode 100644 index 0000000..dda7930 --- /dev/null +++ b/ansible/roles/dovecot/handlers/main.yml | |||
@@ -0,0 +1,31 @@ | |||
1 | --- | ||
2 | - name: restart dovecot | ||
3 | service: | ||
4 | name: dovecot | ||
5 | state: restarted | ||
6 | |||
7 | - name: reload dovecot | ||
8 | service: | ||
9 | name: dovecot | ||
10 | state: reloaded | ||
11 | |||
12 | # We intentionally don't have a "creates:" guard on the resieve handlers | ||
13 | # because if they get called we need to re-run them on any changes of | ||
14 | # the underlying script itself regardless whether the result .svbin | ||
15 | # already exists or not. | ||
16 | - name: resieve spam | ||
17 | command: sievec report-spam.sieve | ||
18 | args: | ||
19 | chdir: /etc/dovecot/sieve | ||
20 | |||
21 | - name: resieve ham | ||
22 | command: sievec report-ham.sieve | ||
23 | args: | ||
24 | chdir: /etc/dovecot/sieve | ||
25 | |||
26 | - name: resieve spam mover | ||
27 | command: sievec 10-rspamd.sieve | ||
28 | args: | ||
29 | chdir: /etc/dovecot/sieve-before.d | ||
30 | creates: 10-rspamd.svbin | ||
31 | |||
diff --git a/ansible/roles/dovecot/tasks/main.yml b/ansible/roles/dovecot/tasks/main.yml new file mode 100644 index 0000000..6e097c1 --- /dev/null +++ b/ansible/roles/dovecot/tasks/main.yml | |||
@@ -0,0 +1,110 @@ | |||
1 | --- | ||
2 | # dovecot install and configuration | ||
3 | - name: install dovecot | ||
4 | apt: | ||
5 | state: latest | ||
6 | pkg: | ||
7 | - dovecot-imapd | ||
8 | - dovecot-lmtpd | ||
9 | - dovecot-sieve | ||
10 | - dovecot-sqlite | ||
11 | |||
12 | # Convert existing maildir to mdbox (local on-fs dirs) with: | ||
13 | # dsync -o mail_location=mdbox:herebox mirror maildir:Maildir | ||
14 | # Or, you can pull from a remote site: | ||
15 | # Below, -R means REVERSE backup so PULL messages FROM vorash INTO mdbox, | ||
16 | # otherwise, it's a PUSH backup and mdbox PUSHES to vorash which isn't what we want | ||
17 | # doveadm -o mail_location=mdbox:herebox backup -R ssh -J [email protected] matt@vorash doveadm dsync-server | ||
18 | - name: create mail spool dirs | ||
19 | file: | ||
20 | path: /var/mail/local | ||
21 | owner: root | ||
22 | group: mail | ||
23 | mode: 0775 | ||
24 | state: directory | ||
25 | |||
26 | - name: create dovecot virtual mailbox group | ||
27 | group: | ||
28 | name: vmail | ||
29 | gid: 145 | ||
30 | state: present | ||
31 | |||
32 | - name: create dovecot virtual mailbox and virtual authentication account | ||
33 | user: | ||
34 | name: vmail | ||
35 | uid: 145 | ||
36 | group: vmail | ||
37 | shell: /sbin/nologin | ||
38 | create_home: yes | ||
39 | home: /var/mail/vhosts | ||
40 | state: present | ||
41 | |||
42 | - name: give dovecot user permission to read private keys | ||
43 | user: | ||
44 | name: dovecot | ||
45 | groups: ssl-cert | ||
46 | append: yes | ||
47 | |||
48 | # Create new passwords with: | ||
49 | # time doveadm pw -s SHA512-CRYPT -r 1856250 | ||
50 | - name: copy dovecot configs and userdb | ||
51 | copy: | ||
52 | src: dovecot/ | ||
53 | dest: /etc/dovecot/ | ||
54 | mode: preserve | ||
55 | notify: | ||
56 | - resieve spam | ||
57 | - resieve ham | ||
58 | - resieve spam mover | ||
59 | - restart dovecot | ||
60 | |||
61 | # This permission is important because dovecot has multiple users: | ||
62 | # - dovecot | ||
63 | # - dovenull | ||
64 | # - vmail | ||
65 | # but login processes are run by the 'vmail' user, so 'vmail' must have read | ||
66 | # access to the DB | ||
67 | - name: fix user permissions on authdb | ||
68 | file: | ||
69 | path: /etc/dovecot/authdb.sqlite | ||
70 | owner: vmail | ||
71 | group: vmail | ||
72 | mode: 0600 | ||
73 | |||
74 | - name: instantiate dovecot SSL template with host vars | ||
75 | template: | ||
76 | src: dovecot/conf.d/10-ssl.conf.j2 | ||
77 | dest: /etc/dovecot/conf.d/10-ssl.conf | ||
78 | notify: | ||
79 | - restart dovecot # NB this could be a reload instead | ||
80 | |||
81 | # Dovecot mdbox format requires a purge to remove storage space | ||
82 | # allocated to messages that have been fully deleted by users. | ||
83 | # (it's an append-only refcounting system, so when a refcount becomes | ||
84 | # zero on final delete, it needs some cleanup to rewrite the old | ||
85 | # pack files without the deleted emails present anymore.) | ||
86 | - cron: | ||
87 | name: setup cron so dovecot can GC mailboxes | ||
88 | minute: 0 | ||
89 | hour: 3 | ||
90 | user: vmail | ||
91 | job: "doveadm purge -A" | ||
92 | cron_file: dovecot_maint_purge | ||
93 | |||
94 | |||
95 | # verify everything is running | ||
96 | - name: verify services are running in dependency order | ||
97 | service: | ||
98 | name: "{{ item }}" | ||
99 | enabled: yes | ||
100 | state: started | ||
101 | loop: | ||
102 | - dovecot | ||
103 | |||
104 | - name: reload if certs newish | ||
105 | include_role: | ||
106 | name: certreload | ||
107 | vars: | ||
108 | certreload: | ||
109 | notifiers: | ||
110 | - reload dovecot | ||
diff --git a/ansible/roles/dovecot/templates/dovecot/conf.d/10-ssl.conf.j2 b/ansible/roles/dovecot/templates/dovecot/conf.d/10-ssl.conf.j2 new file mode 100644 index 0000000..c1654cd --- /dev/null +++ b/ansible/roles/dovecot/templates/dovecot/conf.d/10-ssl.conf.j2 | |||
@@ -0,0 +1,22 @@ | |||
1 | # require SSL for all non-localhost connections | ||
2 | ssl = required | ||
3 | |||
4 | # Config detials at https://wiki.dovecot.org/SSL/DovecotConfiguration | ||
5 | ssl_cert = </etc/ssl/{{ network.hostname.public }}-cert-combined.rsa2048.pem | ||
6 | ssl_key = </etc/ssl/private/{{ network.hostname.public }}-key.rsa2048.pem | ||
7 | |||
8 | # Since v2.2.31+ you can specify alternative ssl certificate | ||
9 | # if the algorithm differs from the primary certificate. | ||
10 | # This is useful when migrating to e.g. ECDSA certificate. | ||
11 | ssl_alt_cert = </etc/ssl/{{ network.hostname.public }}-cert-combined.prime256v1.pem | ||
12 | ssl_alt_key = </etc/ssl/private/{{ network.hostname.public }}-key.prime256v1.pem | ||
13 | |||
14 | # require modern crypto - taken from Mozilla's SSL recommendations page | ||
15 | ssl_dh_parameters_length = 4096 | ||
16 | ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1 TLSv1.2 | ||
17 | ssl_cipher_list = ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256 | ||
18 | ssl_prefer_server_ciphers = yes | ||
19 | |||
20 | # newer dovecot 2.3+ | ||
21 | #ssl_min_protocol = TLSv1.2 | ||
22 | #ssl_dh = /etc/ssl/ffdhe4096.pem | ||
diff --git a/ansible/roles/fail2ban/files/fail2ban/fail2ban.local b/ansible/roles/fail2ban/files/fail2ban/fail2ban.local new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ansible/roles/fail2ban/files/fail2ban/fail2ban.local | |||
diff --git a/ansible/roles/fail2ban/files/fail2ban/filter.d/postfix-rspamd.conf b/ansible/roles/fail2ban/files/fail2ban/filter.d/postfix-rspamd.conf new file mode 100644 index 0000000..311936b --- /dev/null +++ b/ansible/roles/fail2ban/files/fail2ban/filter.d/postfix-rspamd.conf | |||
@@ -0,0 +1,11 @@ | |||
1 | [INCLUDES] | ||
2 | before = common.conf | ||
3 | |||
4 | [Definition] | ||
5 | _daemon = postfix/cleanup | ||
6 | _port = (?::\d+)? | ||
7 | |||
8 | # Line looks like: | ||
9 | # Jul 4 16:40:22 mailmash postfix/cleanup[14378]: F3FECD008FA: milter-reject: END-OF-MESSAGE from fixed-187-188-96-153.totalplay.net[187.188.96.153]: 5.7.1 Spam message rejected; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<fixed-187-188-96-153.totalplay.net> | ||
10 | failregex = milter-reject: END-OF-MESSAGE from [a-z0-9.-]+\[<HOST>\]: 5.7.1 Spam message rejected | ||
11 | ignoreregex = | ||
diff --git a/ansible/roles/fail2ban/files/fail2ban/jail.local b/ansible/roles/fail2ban/files/fail2ban/jail.local new file mode 100644 index 0000000..5b77b5b --- /dev/null +++ b/ansible/roles/fail2ban/files/fail2ban/jail.local | |||
@@ -0,0 +1,59 @@ | |||
1 | [DEFAULT] | ||
2 | # For 'banaction' you can use any action defined in /etc/fail2ban/action.d/ | ||
3 | # including things like iptables, iptables-ipset, nftables-*, ... | ||
4 | banaction = hostsdeny | ||
5 | banaction_allports = hostsdeny | ||
6 | |||
7 | # Blocking decision making is fully logged in /var/log/fail2ban.log | ||
8 | # Current blocking can be viewed with: | ||
9 | # fail2ban-client status | ||
10 | # fail2ban-client status [service] | ||
11 | |||
12 | # You can unban IPs with | ||
13 | # fail2ban-client unban <ip>... | ||
14 | # | ||
15 | # Or unban just for one service/jail | ||
16 | # fail2ban-client set <jail> unban <ip> | ||
17 | |||
18 | # Go away for a long time | ||
19 | bantime = 34d | ||
20 | |||
21 | |||
22 | # DEBUGGING | ||
23 | # You can debug fail2ban behavior by running it in the foreground with | ||
24 | # client debug and server debug logging: | ||
25 | # fail2ban-client -vvvvvvvvvv --loglevel DEBUG -f -x start | ||
26 | # In another terminal: | ||
27 | # tail -F /var/log/fail2ban.log | ||
28 | # | ||
29 | # It helps to delete the persistent save db before fail2ban is started | ||
30 | # in debug mode too: | ||
31 | # rm /var/lib/fail2ban/fail2ban.sqlite3 | ||
32 | |||
33 | |||
34 | # And we're always watching | ||
35 | # If you're testing/debugging your auth and failing your own logins | ||
36 | # either by mistake or intentionally, you'll want to either decrease | ||
37 | # the findtime, decrease the bantime, increase the maxretry time, | ||
38 | # or just disable fail2ban for [findtime] after your testing. | ||
39 | findtime = 6h | ||
40 | |||
41 | # Quick and done | ||
42 | maxretry = 5 | ||
43 | |||
44 | [sshd] | ||
45 | # Disable sshd since we don't have public ssh access to these servers | ||
46 | enabled = false | ||
47 | |||
48 | [postfix] | ||
49 | enabled = true | ||
50 | mode = aggressive | ||
51 | findtime = 7d # watch out for bad long-term trickle tricksters | ||
52 | |||
53 | [postfix-rspamd] | ||
54 | enabled = true | ||
55 | findtime = 7d | ||
56 | maxretry = 3 | ||
57 | |||
58 | [dovecot] | ||
59 | enabled = true | ||
diff --git a/ansible/roles/fail2ban/handlers/main.yml b/ansible/roles/fail2ban/handlers/main.yml new file mode 100644 index 0000000..d83f78d --- /dev/null +++ b/ansible/roles/fail2ban/handlers/main.yml | |||
@@ -0,0 +1,5 @@ | |||
1 | --- | ||
2 | - name: restart fail2ban | ||
3 | service: | ||
4 | name: fail2ban | ||
5 | state: restarted | ||
diff --git a/ansible/roles/fail2ban/tasks/main.yml b/ansible/roles/fail2ban/tasks/main.yml new file mode 100644 index 0000000..6d8e237 --- /dev/null +++ b/ansible/roles/fail2ban/tasks/main.yml | |||
@@ -0,0 +1,28 @@ | |||
1 | --- | ||
2 | # dovecot is configured to respect the fail2ban deny decisions | ||
3 | # A failed login is recorded as: | ||
4 | # dovecot[<pid>]: imap-login: access(tcpwrap): Client refused (rip=<ip>) | ||
5 | - name: install fail2ban | ||
6 | apt: | ||
7 | name: fail2ban | ||
8 | state: latest | ||
9 | install_recommends: false | ||
10 | |||
11 | - name: copy fail2ban config | ||
12 | copy: | ||
13 | src: fail2ban/ | ||
14 | dest: /etc/fail2ban/ | ||
15 | mode: preserve | ||
16 | notify: | ||
17 | - restart fail2ban | ||
18 | |||
19 | |||
20 | # verify everything is running | ||
21 | - name: verify services are running in dependency order | ||
22 | service: | ||
23 | name: "{{ item }}" | ||
24 | enabled: yes | ||
25 | state: started | ||
26 | loop: | ||
27 | - fail2ban | ||
28 | |||
diff --git a/ansible/roles/gpg/tasks/main.yml b/ansible/roles/gpg/tasks/main.yml new file mode 100644 index 0000000..6bb9299 --- /dev/null +++ b/ansible/roles/gpg/tasks/main.yml | |||
@@ -0,0 +1,6 @@ | |||
1 | --- | ||
2 | # gpg is required to verify keys of external apt repos | ||
3 | - name: install gpg | ||
4 | apt: | ||
5 | pkg: gpg | ||
6 | state: latest | ||
diff --git a/ansible/roles/network/tasks/main.yml b/ansible/roles/network/tasks/main.yml new file mode 100644 index 0000000..5aaaeff --- /dev/null +++ b/ansible/roles/network/tasks/main.yml | |||
@@ -0,0 +1,40 @@ | |||
1 | --- | ||
2 | #- name: plop netplan | ||
3 | # copy: | ||
4 | # src: "{{ inventory_hostname }}.yaml" | ||
5 | # dest: "/etc/netplan/20-customNetworking.yaml" | ||
6 | # register: netplanCopy | ||
7 | # | ||
8 | #- name: generate netplan | ||
9 | # command: netplan generate | ||
10 | # register: netplanGenerated | ||
11 | # when: netplanCopy.changed | ||
12 | # | ||
13 | #- name: apply netplan | ||
14 | # command: netplan apply | ||
15 | # when: netplanGenerated.changed | ||
16 | |||
17 | - name: configure public network link through systemd directly | ||
18 | template: | ||
19 | src: network/custom.link | ||
20 | dest: "/etc/systemd/network/custom-{{ network.ethernets.interface }}.link" | ||
21 | register: networkUpdated | ||
22 | |||
23 | - name: configure public network address through systemd directly | ||
24 | template: | ||
25 | src: network/custom.network | ||
26 | dest: "/etc/systemd/network/custom-{{ network.ethernets.interface }}.network" | ||
27 | register: networkUpdated | ||
28 | |||
29 | - name: reload network since configuration changed | ||
30 | command: systemctl restart systemd-networkd | ||
31 | when: networkUpdated.changed | ||
32 | |||
33 | - name: re-query ansible facts since system changed | ||
34 | setup: | ||
35 | gather_subset: | ||
36 | - "!all" | ||
37 | - "!min" | ||
38 | - network | ||
39 | when: networkUpdated.changed | ||
40 | |||
diff --git a/ansible/roles/network/templates/network/custom.link b/ansible/roles/network/templates/network/custom.link new file mode 100644 index 0000000..e3bc5a8 --- /dev/null +++ b/ansible/roles/network/templates/network/custom.link | |||
@@ -0,0 +1,6 @@ | |||
1 | [Match] | ||
2 | OriginalName={{ network.ethernets.interface }} | ||
3 | |||
4 | [Link] | ||
5 | WakeOnLan=off | ||
6 | MACAddress={{ network.ethernets.macaddress }} | ||
diff --git a/ansible/roles/network/templates/network/custom.network b/ansible/roles/network/templates/network/custom.network new file mode 100644 index 0000000..5a8b74e --- /dev/null +++ b/ansible/roles/network/templates/network/custom.network | |||
@@ -0,0 +1,38 @@ | |||
1 | [Match] | ||
2 | Name={{ network.ethernets.interface }} | ||
3 | |||
4 | #{% for net in network.ethernets.networks %} | ||
5 | #[Network] | ||
6 | #Address={{ net.subnet }} | ||
7 | #{% if net.gateway is defined %} | ||
8 | #Gateway={{ net.gateway }} | ||
9 | #{% endif %} | ||
10 | # | ||
11 | #{% endfor %} | ||
12 | |||
13 | |||
14 | {% for addr in network.ethernets.addresses %} | ||
15 | [Address] | ||
16 | Address={{ addr }} | ||
17 | |||
18 | {% endfor %} | ||
19 | |||
20 | {% for net in network.ethernets.networks %} | ||
21 | [Network] | ||
22 | Address={{ net.subnet }} | ||
23 | {% if net.gateway is defined %} | ||
24 | Gateway={{ net.gateway }} | ||
25 | {% endif %} | ||
26 | |||
27 | {% endfor %} | ||
28 | |||
29 | |||
30 | {% for route in network.ethernets.routes %} | ||
31 | [Route] | ||
32 | Destination={{ route.to }} | ||
33 | Gateway={{ route.via }} | ||
34 | {% if route['on-link'] %} | ||
35 | GatewayOnlink=true | ||
36 | {% endif %} | ||
37 | |||
38 | {% endfor %} | ||
diff --git a/ansible/roles/nginx/defaults/main.yml b/ansible/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..34ac696 --- /dev/null +++ b/ansible/roles/nginx/defaults/main.yml | |||
@@ -0,0 +1,6 @@ | |||
1 | --- | ||
2 | nginx: | ||
3 | # Don't disable anything by default, but provide it here | ||
4 | # so you don't need to include empty 'disabled' in your own | ||
5 | # host configs. | ||
6 | disabled: [] | ||
diff --git a/ansible/roles/nginx/files/conf.d/http.custom.conf b/ansible/roles/nginx/files/conf.d/http.custom.conf new file mode 100644 index 0000000..5f70166 --- /dev/null +++ b/ansible/roles/nginx/files/conf.d/http.custom.conf | |||
@@ -0,0 +1,84 @@ | |||
1 | |||
2 | ## Proxy options | ||
3 | proxy_buffering on; | ||
4 | # proxy_cache_min_uses 3; | ||
5 | proxy_cache_path /var/nginx/proxy-cache/ levels=1:2 keys_zone=cache:10m inactive=10m max_size=1000M; | ||
6 | proxy_cache_valid any 10m; | ||
7 | proxy_ignore_client_abort off; | ||
8 | proxy_intercept_errors on; | ||
9 | proxy_next_upstream error timeout invalid_header; | ||
10 | proxy_redirect off; | ||
11 | proxy_set_header Host $host; | ||
12 | proxy_set_header X-Forwarded-For $remote_addr; | ||
13 | proxy_connect_timeout 60; | ||
14 | proxy_send_timeout 60; | ||
15 | proxy_read_timeout 60; | ||
16 | |||
17 | # We used to use this header when we ran dual http/https stacks to verify | ||
18 | # user login pages were being only requested over https, but now we forward | ||
19 | # every site to https, so we can assume our schemes are aligned to our interests | ||
20 | # (as long as all our backend code stopped checking for X-Forwarded-Proto too). | ||
21 | #proxy_set_header X-Forwarded-Proto $scheme; | ||
22 | |||
23 | ## Size Limits | ||
24 | # May need to override these (server or location blocks) if doing large uploads. | ||
25 | # Setting to zero disables any size checking. | ||
26 | client_body_buffer_size 16k; | ||
27 | client_max_body_size 15m; | ||
28 | |||
29 | # If clients send headers larger than 1k, | ||
30 | # they get upgraded to large_client_header_buffers. | ||
31 | client_header_buffer_size 1k; | ||
32 | large_client_header_buffers 32 64k; | ||
33 | |||
34 | ## Timeouts | ||
35 | client_body_timeout 5s; | ||
36 | client_header_timeout 5s; | ||
37 | keepalive_timeout 5s 5s; | ||
38 | #keepalive_timeout 0; | ||
39 | send_timeout 5s; | ||
40 | |||
41 | ## General Options | ||
42 | ignore_invalid_headers on; | ||
43 | recursive_error_pages on; | ||
44 | #sendfile on; # enabled by top level config | ||
45 | server_name_in_redirect off; | ||
46 | server_tokens off; | ||
47 | |||
48 | # For per-client rate limiting, see config options at: | ||
49 | # https://nginx.org/en/docs/http/ngx_http_limit_conn_module.html | ||
50 | |||
51 | ## Compression | ||
52 | #gzip on; # enabled by top level config | ||
53 | gzip_static on; | ||
54 | gzip_buffers 16 32k; | ||
55 | gzip_comp_level 6; | ||
56 | gzip_http_version 1.0; | ||
57 | gzip_min_length 500; | ||
58 | gzip_types text/plain application/x-javascript text/xml text/css image/x-icon application/xml application/xml+rss text/javascript application/javascript application/json image/svg+xml font/truetype font/opentype application/vnd.ms-fontobject; | ||
59 | gzip_vary on; | ||
60 | gzip_proxied any; # required for cloudfront to receive a gzip'd response | ||
61 | |||
62 | ## Filesystem Operation Cache (caches fds, sizes, times, errors, etc) | ||
63 | open_file_cache max=6000 inactive=5m; | ||
64 | open_file_cache_valid 2m; | ||
65 | open_file_cache_min_uses 1; | ||
66 | open_file_cache_errors on; | ||
67 | |||
68 | # For reading a response from disk | ||
69 | output_buffers 32 32k; | ||
70 | |||
71 | ## Optimize Large File Transfers (can be overriden in hosts and locations) | ||
72 | aio threads; # use default thread pool, create thread pools: threads=NAME; | ||
73 | aio_write on; # use threaded writes for temporary files and proxied data | ||
74 | |||
75 | # For files larger than 8 MB, use O_DIRECT instead of sendfile() | ||
76 | directio 8m; | ||
77 | directio_alignment 512; # if using XFS, set as 4096 | ||
78 | |||
79 | ## Access Log Caches | ||
80 | open_log_file_cache max=64 inactive=20s min_uses=1 valid=1m; | ||
81 | |||
82 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
83 | '$status $body_bytes_sent "$http_referer" ' | ||
84 | '"$http_user_agent" "$http_x_forwarded_for"'; | ||
diff --git a/ansible/roles/nginx/files/tls/ssl_ciphers_intermediate b/ansible/roles/nginx/files/tls/ssl_ciphers_intermediate new file mode 100644 index 0000000..bc79954 --- /dev/null +++ b/ansible/roles/nginx/files/tls/ssl_ciphers_intermediate | |||
@@ -0,0 +1,10 @@ | |||
1 | # From https://mozilla.github.io/server-side-tls/ssl-config-generator/ | ||
2 | # as of 2018-07-12 | ||
3 | |||
4 | # No TLSv1.3 support yet! | ||
5 | |||
6 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
7 | ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; | ||
8 | |||
9 | # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits | ||
10 | ssl_dhparam /etc/ssl/ffdhe2048.pem; | ||
diff --git a/ansible/roles/nginx/files/tls/ssl_ciphers_modern b/ansible/roles/nginx/files/tls/ssl_ciphers_modern new file mode 100644 index 0000000..ab93ffc --- /dev/null +++ b/ansible/roles/nginx/files/tls/ssl_ciphers_modern | |||
@@ -0,0 +1,7 @@ | |||
1 | # From https://mozilla.github.io/server-side-tls/ssl-config-generator/ | ||
2 | # as of 2018-07-12 | ||
3 | |||
4 | # No TLSv1.3 support yet! | ||
5 | |||
6 | ssl_protocols TLSv1.2; | ||
7 | ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; | ||
diff --git a/ansible/roles/nginx/files/tls/ssl_ciphers_tls13 b/ansible/roles/nginx/files/tls/ssl_ciphers_tls13 new file mode 100644 index 0000000..db04c36 --- /dev/null +++ b/ansible/roles/nginx/files/tls/ssl_ciphers_tls13 | |||
@@ -0,0 +1,7 @@ | |||
1 | # From https://github.com/cloudflare/sslconfig/blob/796bc5ac7224f1e540394d792323ccafa86aaeea/conf | ||
2 | |||
3 | # nginx >= 1.11.0 (2016-05-24) created the 'ssl_ecdh_curve' parameter | ||
4 | |||
5 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; | ||
6 | ssl_ecdh_curve X25519:P-256:P-384:P-224:P-521; | ||
7 | ssl_ciphers '[ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256|ECDHE-RSA-CHACHA20-POLY1305]:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256:ECDHE+3DES:RSA+3DES'; | ||
diff --git a/ansible/roles/nginx/files/tls/ssl_params b/ansible/roles/nginx/files/tls/ssl_params new file mode 100644 index 0000000..37798fc --- /dev/null +++ b/ansible/roles/nginx/files/tls/ssl_params | |||
@@ -0,0 +1,55 @@ | |||
1 | # Test OCSP with: | ||
2 | # openssl s_client -connect $site:443 -tls1 -tlsextdebug -status | ||
3 | # | ||
4 | # also test with: | ||
5 | # openssl s_client -connect $site:443 -CAfile /etc/ssl/certs/ca-certificates.crt -showcerts -status -tlsextdebug -cipher RSA </dev/null | ||
6 | # | ||
7 | # openssl s_client -connect $site:443 -CAfile /etc/ssl/certs/ca-certificates.crt -showcerts -status -tlsextdebug -cipher ECDSA </dev/null | ||
8 | |||
9 | |||
10 | # Duration client SSL session tickets are valid for: | ||
11 | ssl_session_timeout 1d; | ||
12 | # NOTE NOTE NOTE NOTE NOTE | ||
13 | # nginx only regenerates its ssl_session_ticket_key on reload or restart. | ||
14 | # the ticket key is basically a symmetric key that effectively breaks | ||
15 | # forward secrecy if leaked. | ||
16 | # With ssl_session_tickets enabled, you should reload nginx daily to reset | ||
17 | # the internal cached ticket key. | ||
18 | # If you are using external ticket keys, those should also be rotated daily. | ||
19 | # END NOTE END NOTE END NOTE | ||
20 | |||
21 | # Internal cache of SSL sessions | ||
22 | ssl_session_cache shared:SSL:500m; # 500MB = 2M cached sessions (4k sessions/MB) | ||
23 | |||
24 | # session tickets are reused for the life of the server. | ||
25 | # For multiple servers serving the same host, | ||
26 | # have them all share the same key and rotate as necessary: | ||
27 | # ssl_session_ticket_key [keyfile]; | ||
28 | # Without a ticket key file defined, a reload of nginx resets the key. | ||
29 | ssl_session_tickets on; | ||
30 | |||
31 | # Individual cipher files are included externally | ||
32 | # (one of ssl_ciphers_{intermediate,modern}) | ||
33 | ssl_prefer_server_ciphers on; | ||
34 | |||
35 | # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) | ||
36 | add_header Strict-Transport-Security "max-age=15768000; includeSubdomains"; | ||
37 | |||
38 | # OCSP Stapling --- | ||
39 | # fetch OCSP records from URL in ssl_certificate and cache them | ||
40 | ssl_stapling on; | ||
41 | ssl_stapling_verify on; | ||
42 | |||
43 | # See: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_trusted_certificate | ||
44 | ssl_trusted_certificate /etc/ssl/lets-encrypt-x3-cross-signed.pem; | ||
45 | |||
46 | # Instead of using resolver, take response from file: | ||
47 | # ssl_stapling_file <-- must be set PER domain, but nginx so far has refused | ||
48 | # to add the ability to have one stapling file per certificate now that nginx | ||
49 | # supports both RSA and EC per domain. So, this is useless if you have multiple | ||
50 | # certificates per domain. | ||
51 | |||
52 | # 'valid' ignores DNS TTL and caches lookups for specified duration | ||
53 | # This should be replaced with a local dnsmasq resolver at 127.0.0.1 | ||
54 | resolver 127.0.0.53 4.2.2.2 8.8.8.8 1.1.1.1 valid=600s ipv6=off; | ||
55 | resolver_timeout 4s; | ||
diff --git a/ansible/roles/nginx/handlers/main.yml b/ansible/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..31f8ade --- /dev/null +++ b/ansible/roles/nginx/handlers/main.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | --- | ||
2 | - name: reload nginx | ||
3 | command: nginx -s reload | ||
diff --git a/ansible/roles/nginx/tasks/main.yml b/ansible/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..73469a1 --- /dev/null +++ b/ansible/roles/nginx/tasks/main.yml | |||
@@ -0,0 +1,118 @@ | |||
1 | --- | ||
2 | - name: emerge, nginx with extra modules! | ||
3 | apt: | ||
4 | pkg: nginx-extras | ||
5 | state: latest | ||
6 | |||
7 | # Keep 32 logs | ||
8 | - name: adjust nginx logrotate keep files | ||
9 | lineinfile: | ||
10 | state: present | ||
11 | path: /etc/logrotate.d/nginx | ||
12 | regexp: "^(\\s+)rotate " | ||
13 | line: "\\1rotate 32" | ||
14 | backrefs: yes | ||
15 | |||
16 | # And only rotate when they grow larger than 1 GB | ||
17 | - name: adjust nginx logrotate trigger rolls | ||
18 | lineinfile: | ||
19 | state: present | ||
20 | path: /etc/logrotate.d/nginx | ||
21 | regexp: "minsize" | ||
22 | line: "minsize 1G" | ||
23 | insertafter: "rotate \\d+" | ||
24 | |||
25 | - name: verify nginx isn't serving default pages | ||
26 | file: | ||
27 | path: /etc/nginx/sites-enabled/default | ||
28 | state: absent | ||
29 | notify: | ||
30 | - reload nginx | ||
31 | |||
32 | - name: verify nginx proxy cache dir exists | ||
33 | file: | ||
34 | path: /var/nginx/proxy-cache | ||
35 | owner: www-data | ||
36 | state: directory | ||
37 | |||
38 | - name: verify nginx cpu affinity | ||
39 | lineinfile: | ||
40 | state: present | ||
41 | path: /etc/nginx/nginx.conf | ||
42 | regexp: "^worker_cpu_affinity " | ||
43 | line: "worker_cpu_affinity auto;" | ||
44 | insertafter: '^worker_processes ' | ||
45 | notify: | ||
46 | - reload nginx | ||
47 | |||
48 | - name: drop keepalive from nginx conf because we set it custom | ||
49 | lineinfile: | ||
50 | state: absent | ||
51 | path: /etc/nginx/nginx.conf | ||
52 | regexp: "^\\s+keepalive_timeout" | ||
53 | notify: | ||
54 | - reload nginx | ||
55 | |||
56 | - name: copy config extensions | ||
57 | copy: | ||
58 | src: conf.d | ||
59 | dest: /etc/nginx/ | ||
60 | notify: | ||
61 | - reload nginx | ||
62 | |||
63 | - name: copy shared tls settings | ||
64 | copy: | ||
65 | src: tls/ | ||
66 | dest: /etc/nginx/ | ||
67 | notify: | ||
68 | - reload nginx | ||
69 | |||
70 | - name: generate our templated basic sites | ||
71 | template: | ||
72 | src: basic-site.conf.j2 | ||
73 | dest: "/etc/nginx/sites-available/{{ item.domain }}" | ||
74 | loop: "{{ nginx.basic }}" | ||
75 | notify: | ||
76 | - reload nginx | ||
77 | |||
78 | - name: copy our more complex sites we don't want templated | ||
79 | copy: | ||
80 | src: "servers/{{ item }}" | ||
81 | dest: /etc/nginx/sites-available/ | ||
82 | loop: "{{ nginx.complex }}" | ||
83 | notify: | ||
84 | - reload nginx | ||
85 | |||
86 | - name: activate our nginx site configs | ||
87 | file: | ||
88 | src: "/etc/nginx/sites-available/{{ item }}" | ||
89 | dest: "/etc/nginx/sites-enabled/{{ item }}" | ||
90 | state: link | ||
91 | loop: "{{ nginx.complex }}" | ||
92 | notify: | ||
93 | - reload nginx | ||
94 | |||
95 | - name: activate our nginx site templates | ||
96 | file: | ||
97 | src: "/etc/nginx/sites-available/{{ item.domain }}" | ||
98 | dest: "/etc/nginx/sites-enabled/{{ item.domain }}" | ||
99 | state: link | ||
100 | loop: "{{ nginx.basic }}" | ||
101 | notify: | ||
102 | - reload nginx | ||
103 | |||
104 | - name: remove disabled sites | ||
105 | file: | ||
106 | src: "/etc/nginx/sites-enabled/{{ item }}" | ||
107 | state: absent | ||
108 | loop: "{{ nginx.disabled | default([]) }}" | ||
109 | notify: | ||
110 | - reload nginx | ||
111 | |||
112 | - name: reload if certs newish | ||
113 | include_role: | ||
114 | name: certreload | ||
115 | vars: | ||
116 | certreload: | ||
117 | notifiers: | ||
118 | - reload nginx | ||
diff --git a/ansible/roles/nginx/templates/basic-site.conf.j2 b/ansible/roles/nginx/templates/basic-site.conf.j2 new file mode 100644 index 0000000..454b2bd --- /dev/null +++ b/ansible/roles/nginx/templates/basic-site.conf.j2 | |||
@@ -0,0 +1,68 @@ | |||
1 | server { | ||
2 | listen {{ item.domain }}:443 ssl http2 fastopen=4096 reuseport; | ||
3 | server_name {{ item.domain }}; | ||
4 | |||
5 | access_log /var/log/nginx/{{ item.domain }}.access.log main buffer=32k; | ||
6 | error_log /var/log/nginx/{{ item.domain }}.error.log error; | ||
7 | |||
8 | ssl on; | ||
9 | |||
10 | include /etc/nginx/ssl_params; | ||
11 | |||
12 | {% if nginx.ssl == "modern" %} | ||
13 | include /etc/nginx/ssl_ciphers_modern; | ||
14 | {% elif nginx.ssl == "tls13" %} | ||
15 | include /etc/nginx/ssl_ciphers_tls13; | ||
16 | {% else %} | ||
17 | # Default, just use commonly accepted options: | ||
18 | include /etc/nginx/ssl_ciphers_intermediate; | ||
19 | {% endif %} | ||
20 | |||
21 | ssl_certificate /etc/ssl/{{ item.domain }}-cert-combined.rsa2048.pem; | ||
22 | ssl_certificate_key /etc/ssl/private/{{ item.domain }}-key.rsa2048.pem; | ||
23 | |||
24 | # nginx >= 1.11.0 (2016-05-24) allows loading redundant certs and keys so you | ||
25 | # can serve modern EC clients and less modern RSA clients at the same time. | ||
26 | ssl_certificate /etc/ssl/{{ item.domain }}-cert-combined.prime256v1.pem; | ||
27 | ssl_certificate_key /etc/ssl/private/{{ item.domain }}-key.prime256v1.pem; | ||
28 | |||
29 | root /srv/web/{{ item.domain }}; | ||
30 | |||
31 | {% if nginx.google is defined %} | ||
32 | location /{{ nginx.google.siteKey }}.html { | ||
33 | root {{ nginx.google.siteKeyServeDir }}}; | ||
34 | } | ||
35 | {% endif %} | ||
36 | |||
37 | {% if item.customConfig is defined %} | ||
38 | {{ item.customConfig }} | ||
39 | {% endif %} | ||
40 | |||
41 | {% for location in item.uri %} | ||
42 | location {{ location.path }} { | ||
43 | {% if location.appServer is defined %} | ||
44 | proxy_pass {{ location.appServer }}/$request_uri; | ||
45 | proxy_set_header Host $host; | ||
46 | {% else %} | ||
47 | root /srv/web/{{ item.domain }}; | ||
48 | {% endif %} | ||
49 | } | ||
50 | {% endfor %} | ||
51 | } | ||
52 | |||
53 | server { | ||
54 | listen {{ item.domain }} fastopen=4096 reuseport; | ||
55 | server_name www.{{ item.domain }} {{ item.domain }}; | ||
56 | |||
57 | access_log /var/log/nginx/{{ item.domain }}.access.log main buffer=32k; | ||
58 | error_log /var/log/nginx/{{ item.domain }}.error.log error; | ||
59 | |||
60 | location /.well-known/acme-challenge/ { | ||
61 | alias /srv/web/challenges/; | ||
62 | try_files $uri =404; | ||
63 | } | ||
64 | |||
65 | location / { | ||
66 | return 301 https://{{ item.domain }}$request_uri; | ||
67 | } | ||
68 | } | ||
diff --git a/ansible/roles/pip3/tasks/main.yml b/ansible/roles/pip3/tasks/main.yml new file mode 100644 index 0000000..26de65b --- /dev/null +++ b/ansible/roles/pip3/tasks/main.yml | |||
@@ -0,0 +1,6 @@ | |||
1 | --- | ||
2 | # pip3 because borgmatic is distributed through pip3, not apt/dpkg | ||
3 | - name: install pip3 | ||
4 | apt: | ||
5 | pkg: python3-pip | ||
6 | state: latest | ||
diff --git a/ansible/roles/postfix/files/postfix/master.cf b/ansible/roles/postfix/files/postfix/master.cf new file mode 100644 index 0000000..d428c18 --- /dev/null +++ b/ansible/roles/postfix/files/postfix/master.cf | |||
@@ -0,0 +1,113 @@ | |||
1 | # | ||
2 | # Postfix master process configuration file. For details on the format | ||
3 | # of the file, see the master(5) manual page (command: "man 5 master" or | ||
4 | # on-line: http://www.postfix.org/master.5.html). | ||
5 | # | ||
6 | # Do not forget to execute "postfix reload" after editing this file. | ||
7 | # | ||
8 | # ========================================================================== | ||
9 | # service type private unpriv chroot wakeup maxproc command + args | ||
10 | # (yes) (yes) (no) (never) (100) | ||
11 | # ========================================================================== | ||
12 | smtp inet n - y - - smtpd | ||
13 | -o smtpd_sasl_auth_enable=no | ||
14 | # for verbose connection debugging, append -v to the above args | ||
15 | #smtp inet n - y - 1 postscreen | ||
16 | #smtpd pass - - y - - smtpd | ||
17 | #dnsblog unix - - y - 0 dnsblog | ||
18 | #tlsproxy unix - - y - 0 tlsproxy | ||
19 | submission inet n - n - - smtpd | ||
20 | -o smtpd_tls_security_level=encrypt | ||
21 | -o tls_preempt_cipherlist=yes | ||
22 | #submission inet n - y - - smtpd | ||
23 | # -o syslog_name=postfix/submission | ||
24 | # -o smtpd_tls_security_level=encrypt | ||
25 | # -o smtpd_sasl_auth_enable=yes | ||
26 | # -o smtpd_tls_auth_only=yes | ||
27 | # -o smtpd_reject_unlisted_recipient=no | ||
28 | # -o smtpd_client_restrictions=$mua_client_restrictions | ||
29 | # -o smtpd_helo_restrictions=$mua_helo_restrictions | ||
30 | # -o smtpd_sender_restrictions=$mua_sender_restrictions | ||
31 | # -o smtpd_recipient_restrictions= | ||
32 | # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject | ||
33 | # -o milter_macro_daemon_name=ORIGINATING | ||
34 | #smtps inet n - y - - smtpd | ||
35 | # -o syslog_name=postfix/smtps | ||
36 | # -o smtpd_tls_wrappermode=yes | ||
37 | # -o smtpd_sasl_auth_enable=yes | ||
38 | # -o smtpd_reject_unlisted_recipient=no | ||
39 | # -o smtpd_client_restrictions=$mua_client_restrictions | ||
40 | # -o smtpd_helo_restrictions=$mua_helo_restrictions | ||
41 | # -o smtpd_sender_restrictions=$mua_sender_restrictions | ||
42 | # -o smtpd_recipient_restrictions= | ||
43 | # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject | ||
44 | # -o milter_macro_daemon_name=ORIGINATING | ||
45 | #628 inet n - y - - qmqpd | ||
46 | pickup unix n - y 60 1 pickup | ||
47 | cleanup unix n - y - 0 cleanup | ||
48 | qmgr unix n - n 300 1 qmgr | ||
49 | #qmgr unix n - n 300 1 oqmgr | ||
50 | tlsmgr unix - - y 1000? 1 tlsmgr | ||
51 | rewrite unix - - y - - trivial-rewrite | ||
52 | bounce unix - - y - 0 bounce | ||
53 | defer unix - - y - 0 bounce | ||
54 | trace unix - - y - 0 bounce | ||
55 | verify unix - - y - 1 verify | ||
56 | flush unix n - y 1000? 0 flush | ||
57 | proxymap unix - - n - - proxymap | ||
58 | proxywrite unix - - n - 1 proxymap | ||
59 | smtp unix - - y - - smtp | ||
60 | relay unix - - y - - smtp | ||
61 | -o syslog_name=postfix/$service_name | ||
62 | # -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 | ||
63 | showq unix n - y - - showq | ||
64 | error unix - - y - - error | ||
65 | retry unix - - y - - error | ||
66 | discard unix - - y - - discard | ||
67 | local unix - n n - - local | ||
68 | virtual unix - n n - - virtual | ||
69 | lmtp unix - - y - - lmtp | ||
70 | anvil unix - - y - 1 anvil | ||
71 | scache unix - - y - 1 scache | ||
72 | # | ||
73 | # ==================================================================== | ||
74 | # Interfaces to non-Postfix software. Be sure to examine the manual | ||
75 | # pages of the non-Postfix software to find out what options it wants. | ||
76 | # | ||
77 | # Many of the following services use the Postfix pipe(8) delivery | ||
78 | # agent. See the pipe(8) man page for information about ${recipient} | ||
79 | # and other message envelope options. | ||
80 | # ==================================================================== | ||
81 | # | ||
82 | # maildrop. See the Postfix MAILDROP_README file for details. | ||
83 | # Also specify in main.cf: maildrop_destination_recipient_limit=1 | ||
84 | # | ||
85 | maildrop unix - n n - - pipe | ||
86 | flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient} | ||
87 | # | ||
88 | # ==================================================================== | ||
89 | # | ||
90 | # Recent Cyrus versions can use the existing "lmtp" master.cf entry. | ||
91 | # | ||
92 | # Specify in cyrus.conf: | ||
93 | # lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4 | ||
94 | # | ||
95 | # Specify in main.cf one or more of the following: | ||
96 | # mailbox_transport = lmtp:inet:localhost | ||
97 | # virtual_transport = lmtp:inet:localhost | ||
98 | # | ||
99 | # ==================================================================== | ||
100 | # | ||
101 | # Cyrus 2.1.5 (Amos Gouaux) | ||
102 | # Also specify in main.cf: cyrus_destination_recipient_limit=1 | ||
103 | # | ||
104 | #cyrus unix - n n - - pipe | ||
105 | # user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user} | ||
106 | # | ||
107 | # ==================================================================== | ||
108 | # Old example of delivery via Cyrus. | ||
109 | # | ||
110 | #old-cyrus unix - n n - - pipe | ||
111 | # flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user} | ||
112 | # | ||
113 | # ==================================================================== | ||
diff --git a/ansible/roles/postfix/files/postfix/remap.sh b/ansible/roles/postfix/files/postfix/remap.sh new file mode 100755 index 0000000..86e8d73 --- /dev/null +++ b/ansible/roles/postfix/files/postfix/remap.sh | |||
@@ -0,0 +1,9 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | here=$(dirname $0) | ||
4 | |||
5 | MAPS="virtual" | ||
6 | |||
7 | for map in $MAPS; do | ||
8 | postmap $here/$map | ||
9 | done | ||
diff --git a/ansible/roles/postfix/handlers/main.yml b/ansible/roles/postfix/handlers/main.yml new file mode 100644 index 0000000..aa41be4 --- /dev/null +++ b/ansible/roles/postfix/handlers/main.yml | |||
@@ -0,0 +1,13 @@ | |||
1 | --- | ||
2 | - name: restart postfix | ||
3 | service: | ||
4 | name: postfix | ||
5 | state: restarted | ||
6 | |||
7 | - name: reload postfix | ||
8 | service: | ||
9 | name: postfix | ||
10 | state: reloaded | ||
11 | |||
12 | - name: rehash postfix aliases | ||
13 | command: /etc/postfix/remap.sh | ||
diff --git a/ansible/roles/postfix/tasks/main.yml b/ansible/roles/postfix/tasks/main.yml new file mode 100644 index 0000000..57b0601 --- /dev/null +++ b/ansible/roles/postfix/tasks/main.yml | |||
@@ -0,0 +1,50 @@ | |||
1 | --- | ||
2 | # postfix install and configuration | ||
3 | # note: this postfix config requires open ports: 25 and 587 | ||
4 | - name: install postfix | ||
5 | apt: | ||
6 | state: latest | ||
7 | pkg: | ||
8 | - postfix | ||
9 | - postfix-doc | ||
10 | - postfix-pcre | ||
11 | |||
12 | - name: give postfix user permission to read private keys | ||
13 | user: | ||
14 | name: postfix | ||
15 | groups: ssl-cert | ||
16 | append: yes | ||
17 | |||
18 | - name: copy postfix config | ||
19 | copy: | ||
20 | src: postfix/ | ||
21 | dest: /etc/postfix/ | ||
22 | mode: preserve | ||
23 | notify: | ||
24 | - restart postfix # NB this could be a reload instead | ||
25 | - rehash postfix aliases | ||
26 | |||
27 | - name: instantiate postfix main.cf template | ||
28 | template: | ||
29 | src: postfix/main.cf.j2 | ||
30 | dest: /etc/postfix/main.cf | ||
31 | notify: | ||
32 | - reload postfix | ||
33 | |||
34 | |||
35 | # verify everything is running | ||
36 | - name: verify services are running in dependency order | ||
37 | service: | ||
38 | name: "{{ item }}" | ||
39 | enabled: yes | ||
40 | state: started | ||
41 | loop: | ||
42 | - postfix | ||
43 | |||
44 | - name: reload if certs newish | ||
45 | include_role: | ||
46 | name: certreload | ||
47 | vars: | ||
48 | certreload: | ||
49 | notifiers: | ||
50 | - reload postfix | ||
diff --git a/ansible/roles/postfix/templates/postfix/main.cf.j2 b/ansible/roles/postfix/templates/postfix/main.cf.j2 new file mode 100644 index 0000000..b3e8cc2 --- /dev/null +++ b/ansible/roles/postfix/templates/postfix/main.cf.j2 | |||
@@ -0,0 +1,194 @@ | |||
1 | # Modified from https://www.c0ffee.net/blog/mail-server-guide | ||
2 | |||
3 | smtpd_banner = $myhostname ESMTP dx Independence | ||
4 | |||
5 | # "2" is current for postfix 3.2 configs | ||
6 | compatibility_level = 2 | ||
7 | |||
8 | # disable "new mail" notifications for local unix users | ||
9 | biff = no | ||
10 | |||
11 | # directory to store mail for local unix users | ||
12 | mail_spool_directory = /var/mail/local | ||
13 | |||
14 | # Name of this mail server, used in the SMTP HELO for outgoing mail. Make | ||
15 | # sure this resolves to the same IP as your reverse DNS hostname. | ||
16 | myhostname = {{ network.hostname.public }} | ||
17 | |||
18 | # Domains for which postfix will deliver local mail. Does not apply to | ||
19 | # virtual domains, which are configured below. Make sure to specify the FQDN | ||
20 | # of your sever, as well as localhost. | ||
21 | # Note: NEVER specify any virtual domains here!!! Those come later. | ||
22 | mydestination = localhost | ||
23 | |||
24 | # Domain appended to mail sent locally from this machine - such as mail sent | ||
25 | # via the `sendmail` command. | ||
26 | myorigin = $myhostname | ||
27 | |||
28 | # prevent spammers from searching for valid users | ||
29 | disable_vrfy_command = yes | ||
30 | |||
31 | # require properly formatted email addresses - prevents a lot of spam | ||
32 | strict_rfc821_envelopes = yes | ||
33 | |||
34 | # don't give any helpful info when a mailbox doesn't exist | ||
35 | show_user_unknown_table_name = no | ||
36 | |||
37 | # limit maximum e-mail size to 256 MB. mailbox size must be at least as big as | ||
38 | # the message size for the mail to be accepted, but has no meaning after | ||
39 | # that since we are using Dovecot for delivery. | ||
40 | message_size_limit = 268435456 | ||
41 | mailbox_size_limit = 0 | ||
42 | |||
43 | # require addresses of the form "[email protected]" | ||
44 | allow_percent_hack = no | ||
45 | swap_bangpath = no | ||
46 | |||
47 | # allow plus-aliasing: "[email protected]" delivers to "user" mailbox | ||
48 | recipient_delimiter = + | ||
49 | |||
50 | # path to the SSL certificate for the mail server | ||
51 | smtpd_tls_cert_file = /etc/ssl/{{ network.hostname.public }}-cert-combined.rsa2048.pem | ||
52 | smtpd_tls_key_file = /etc/ssl/private/{{ network.hostname.public }}-key.rsa2048.pem | ||
53 | |||
54 | # You can also specify an EC cert to try first if the clients support it. | ||
55 | smtpd_tls_eccert_file = /etc/ssl/{{ network.hostname.public }}-cert-combined.prime256v1.pem | ||
56 | smtpd_tls_eckey_file = /etc/ssl/private/{{ network.hostname.public }}-key.prime256v1.pem | ||
57 | |||
58 | # Path to your trusted certificates file. Usually provided by a | ||
59 | # ca-certificates package or similar. | ||
60 | smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt | ||
61 | |||
62 | # These two lines define how postfix will connect to other mail servers. | ||
63 | # "may" allows opportunistic TLS and "enabled" allows hostname lookups | ||
64 | # http://www.postfix.org/TLS_README.html | ||
65 | smtp_tls_security_level = may | ||
66 | smtp_dns_support_level = enabled | ||
67 | |||
68 | # IP address used by postfix to send outgoing mail. You only need this if | ||
69 | # your machine has multiple IP addresses - set it to your MX address to | ||
70 | # satisfy your SPF record. | ||
71 | smtp_bind_address = {{ hostvars[inventory_hostname]['ansible_' + network.interface.public]['ipv4']['address'] }} | ||
72 | smtp_bind_address6 = | ||
73 | inet_interfaces = 127.0.0.1,$smtp_bind_address | ||
74 | inet_protocols = ipv4 | ||
75 | |||
76 | # Here we define the options for "mandatory" TLS. In our setup, TLS is only | ||
77 | # "mandatory" for authenticating users. I got these settings from Mozilla's | ||
78 | # SSL reccomentations page. | ||
79 | # | ||
80 | # NOTE: do not attempt to make TLS mandatory for all incoming/outgoing | ||
81 | # connections. Do not attempt to change the default cipherlist for non- | ||
82 | # mandatory connections either. There are still a lot of mail servers out | ||
83 | # there that do not use TLS, and many that do only support old ciphers. | ||
84 | # Forcing TLS for everyone *will* cause you to lose mail. | ||
85 | smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1, TLSv1.2 | ||
86 | smtpd_tls_mandatory_ciphers = high | ||
87 | tls_high_cipherlist = ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256 | ||
88 | |||
89 | # allow other mail servers to connect using TLS, but don't require it | ||
90 | smtpd_tls_security_level = may | ||
91 | |||
92 | # tickets and compression have known vulnerabilities | ||
93 | tls_ssl_options = no_ticket, no_compression | ||
94 | |||
95 | # yes, using 2048 with "dh1024" is the right thing to do | ||
96 | smtpd_tls_dh1024_param_file = /etc/ssl/ffdhe2048.pem | ||
97 | |||
98 | # cache incoming and outgoing TLS sessions | ||
99 | smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_tlscache | ||
100 | smtp_tls_session_cache_database = btree:${data_directory}/smtp_tlscache | ||
101 | |||
102 | # enable SMTPD auth. Dovecot will place an `auth` socket in postfix's | ||
103 | # runtime directory that we will use for authentication. | ||
104 | # TODO: can also replace this with a network inet connection if dovecot opens it | ||
105 | smtpd_sasl_auth_enable = yes | ||
106 | smtpd_sasl_path = private/auth | ||
107 | smtpd_sasl_type = dovecot | ||
108 | |||
109 | # only allow authentication over TLS | ||
110 | smtpd_tls_auth_only = yes | ||
111 | |||
112 | # don't allow plaintext auth methods on unencrypted connections | ||
113 | smtpd_sasl_security_options = noanonymous, noplaintext | ||
114 | # but plaintext auth is fine when using TLS | ||
115 | smtpd_sasl_tls_security_options = noanonymous | ||
116 | |||
117 | # add a message header when email was recieved over TLS | ||
118 | smtpd_tls_received_header = yes | ||
119 | |||
120 | # require that connecting mail servers identify themselves - this greatly | ||
121 | # reduces spam | ||
122 | smtpd_helo_required = yes | ||
123 | |||
124 | # The following block specifies some security restrictions for incoming | ||
125 | # mail. The gist of it is, authenticated users and connections from | ||
126 | # localhost can do anything they want. Random people connecting over the | ||
127 | # internet are treated with more suspicion: they must have a reverse DNS | ||
128 | # entry and present a valid, FQDN HELO hostname. In addition, they can only | ||
129 | # send mail to valid mailboxes on the server, and the sender's domain must | ||
130 | # actually exist. | ||
131 | smtpd_client_restrictions = | ||
132 | permit_mynetworks, | ||
133 | permit_sasl_authenticated, | ||
134 | #reject_unknown_reverse_client_hostname, | ||
135 | # you might want to consider: | ||
136 | # reject_unknown_client_hostname, | ||
137 | # here. This will reject all incoming connections without a reverse DNS | ||
138 | # entry that resolves back to the client's IP address. This is a very | ||
139 | # restrictive check and may reject legitimate mail. | ||
140 | reject_unauth_pipelining | ||
141 | smtpd_helo_restrictions = | ||
142 | permit_mynetworks, | ||
143 | permit_sasl_authenticated, | ||
144 | reject_invalid_helo_hostname, | ||
145 | reject_non_fqdn_helo_hostname, | ||
146 | # you might want to consider: | ||
147 | # reject_unknown_helo_hostname, | ||
148 | # here. This will reject all incoming mail without a HELO hostname that | ||
149 | # properly resolves in DNS. This is a somewhat restrictive check and may | ||
150 | # reject legitimate mail. | ||
151 | reject_unauth_pipelining | ||
152 | smtpd_sender_restrictions = | ||
153 | permit_mynetworks, | ||
154 | permit_sasl_authenticated, | ||
155 | reject_non_fqdn_sender, | ||
156 | # reject_unknown_sender_domain, | ||
157 | reject_unauth_pipelining | ||
158 | smtpd_relay_restrictions = | ||
159 | permit_mynetworks, | ||
160 | permit_sasl_authenticated, | ||
161 | # !!! THIS SETTING PREVENTS YOU FROM BEING AN OPEN RELAY !!! | ||
162 | reject_unauth_destination | ||
163 | # !!! DO NOT REMOVE IT UNDER ANY CIRCUMSTANCES !!! | ||
164 | #smtpd_recipient_restrictions = | ||
165 | # permit_mynetworks, | ||
166 | # permit_sasl_authenticated, | ||
167 | # reject_non_fqdn_recipient, | ||
168 | # reject_unknown_recipient_domain, | ||
169 | # reject_unauth_pipelining, | ||
170 | smtpd_data_restrictions = | ||
171 | permit_mynetworks, | ||
172 | permit_sasl_authenticated, | ||
173 | reject_multi_recipient_bounce, | ||
174 | reject_unauth_pipelining | ||
175 | |||
176 | smtpd_recipient_restrictions = | ||
177 | permit_mynetworks, | ||
178 | permit_sasl_authenticated, | ||
179 | reject_unauth_destination | ||
180 | |||
181 | # deliver mail for virtual users to Dovecot's LMTP socket | ||
182 | # TODO: convert this to network with dovecot opening a local inet port | ||
183 | virtual_transport = lmtp:unix:private/dovecot-lmtp | ||
184 | virtual_mailbox_domains = /etc/postfix/domains | ||
185 | |||
186 | virtual_alias_maps = hash:/etc/postfix/virtual | ||
187 | #virtual_alias_domains = /etc/postfix/domains | ||
188 | |||
189 | # We'll uncomment these when we set up rspamd later: | ||
190 | milter_protocol = 6 | ||
191 | milter_default_action = accept | ||
192 | #smtpd_milters = unix:/var/run/rspamd/milter.sock | ||
193 | smtpd_milters = inet:localhost:11332 | ||
194 | milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen} | ||
diff --git a/ansible/roles/ramdisk/tasks/main.yml b/ansible/roles/ramdisk/tasks/main.yml new file mode 100644 index 0000000..2c05747 --- /dev/null +++ b/ansible/roles/ramdisk/tasks/main.yml | |||
@@ -0,0 +1,13 @@ | |||
1 | - name: create ramdisk directory | ||
2 | file: | ||
3 | dest: /srv/ramdisk | ||
4 | mode: 0755 # TODO: use acl module and bind this to system data user | ||
5 | state: directory | ||
6 | |||
7 | - name: mount ramdisk to /srv/ramdisk | ||
8 | mount: | ||
9 | path: /srv/ramdisk | ||
10 | src: tmpfs | ||
11 | fstype: tmpfs | ||
12 | opts: "lazytime,size={{ ansible_memtotal_mb }}M" | ||
13 | state: mounted | ||
diff --git a/ansible/roles/rspamd/files/redis/redis.conf b/ansible/roles/rspamd/files/redis/redis.conf new file mode 100644 index 0000000..ee237d9 --- /dev/null +++ b/ansible/roles/rspamd/files/redis/redis.conf | |||
@@ -0,0 +1,21 @@ | |||
1 | # listen only on localhost | ||
2 | # Even though we only tell rspamd to contact Redis over 127.0.0.1, it still | ||
3 | # connects via ::1 for some modules as well, so things inside rspamd break | ||
4 | # if redis isn't listening on both 127.0.0.1 and ::1 | ||
5 | bind 127.0.0.1 ::1 | ||
6 | |||
7 | # limit the max amount of memory used - appropriate value will depend on | ||
8 | # your email volume | ||
9 | maxmemory 512mb | ||
10 | maxmemory-policy volatile-lru | ||
11 | |||
12 | daemonize yes | ||
13 | |||
14 | logfile /var/log/redis/redis-server.log | ||
15 | dir /var/lib/redis | ||
16 | |||
17 | appendonly yes | ||
18 | appendfilename redisisgarbage.aof | ||
19 | dbfilename redisisgarbage.rdb | ||
20 | |||
21 | pidfile /var/run/redis/redis-server.pid | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/classifier-bayes.conf b/ansible/roles/rspamd/files/rspamd/local.d/classifier-bayes.conf new file mode 100644 index 0000000..db2f240 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/classifier-bayes.conf | |||
@@ -0,0 +1,4 @@ | |||
1 | autolearn = true; | ||
2 | backend = "redis"; | ||
3 | new_schema = true; | ||
4 | expire = 8640000; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/greylist.conf b/ansible/roles/rspamd/files/rspamd/local.d/greylist.conf new file mode 100644 index 0000000..a6ee831 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/greylist.conf | |||
@@ -0,0 +1 @@ | |||
enabled = false; | |||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/milter_headers.conf b/ansible/roles/rspamd/files/rspamd/local.d/milter_headers.conf new file mode 100644 index 0000000..4c924d7 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/milter_headers.conf | |||
@@ -0,0 +1,3 @@ | |||
1 | # Refer to https://rspamd.com/doc/modules/milter_headers.html for information on configuration | ||
2 | |||
3 | use = ["x-spamd-bar", "authentication-results", "x-spamd-result", "x-rspamd-server", "x-rspamd-queue-id"]; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/mx_check.conf b/ansible/roles/rspamd/files/rspamd/local.d/mx_check.conf new file mode 100644 index 0000000..de9fac1 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/mx_check.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # checks if sender's domain has at least one connectable MX record | ||
2 | enabled = true; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/neural.conf b/ansible/roles/rspamd/files/rspamd/local.d/neural.conf new file mode 100644 index 0000000..7fc7bd2 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/neural.conf | |||
@@ -0,0 +1,33 @@ | |||
1 | servers = "localhost"; | ||
2 | enabled = true; # Important after 1.7 | ||
3 | |||
4 | # use_settings = true; | ||
5 | |||
6 | rules { | ||
7 | "LONG" { | ||
8 | train { | ||
9 | max_trains = 5000; | ||
10 | max_usages = 200; | ||
11 | max_iterations = 25; | ||
12 | learning_rate = 0.01, | ||
13 | spam_score = 8; | ||
14 | ham_score = -2; | ||
15 | } | ||
16 | symbol_spam = "NEURAL_SPAM_LONG"; | ||
17 | symbol_ham = "NEURAL_HAM_LONG"; | ||
18 | ann_expire = 100d; | ||
19 | } | ||
20 | "SHORT" { | ||
21 | train { | ||
22 | max_trains = 100; | ||
23 | max_usages = 2; | ||
24 | max_iterations = 25; | ||
25 | learning_rate = 0.01, | ||
26 | spam_score = 8; | ||
27 | ham_score = -2; | ||
28 | } | ||
29 | symbol_spam = "NEURAL_SPAM_SHORT"; | ||
30 | symbol_ham = "NEURAL_HAM_SHORT"; | ||
31 | ann_expire = 1d; | ||
32 | } | ||
33 | } | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/neural_group.conf b/ansible/roles/rspamd/files/rspamd/local.d/neural_group.conf new file mode 100644 index 0000000..fff5058 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/neural_group.conf | |||
@@ -0,0 +1,29 @@ | |||
1 | symbols = { | ||
2 | "NEURAL_SPAM" { | ||
3 | weight = 3.0; # sample weight | ||
4 | description = "Neural network spam"; | ||
5 | } | ||
6 | "NEURAL_HAM" { | ||
7 | weight = -3.0; # sample weight | ||
8 | description = "Neural network ham"; | ||
9 | } | ||
10 | } | ||
11 | |||
12 | symbols = { | ||
13 | "NEURAL_SPAM_LONG" { | ||
14 | weight = 3.0; # sample weight | ||
15 | description = "Neural network spam (long)"; | ||
16 | } | ||
17 | "NEURAL_HAM_LONG" { | ||
18 | weight = -3.0; # sample weight | ||
19 | description = "Neural network ham (long)"; | ||
20 | } | ||
21 | "NEURAL_SPAM_SHORT" { | ||
22 | weight = 2.0; # sample weight | ||
23 | description = "Neural network spam (short)"; | ||
24 | } | ||
25 | "NEURAL_HAM_SHORT" { | ||
26 | weight = -1.0; # sample weight | ||
27 | description = "Neural network ham (short)"; | ||
28 | } | ||
29 | } | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/phishing.conf b/ansible/roles/rspamd/files/rspamd/local.d/phishing.conf new file mode 100644 index 0000000..dcb1caf --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/phishing.conf | |||
@@ -0,0 +1,3 @@ | |||
1 | # check messages against some anti-phishing databases | ||
2 | openphish_enabled = true; | ||
3 | phishtank_enabled = true; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/redis.conf b/ansible/roles/rspamd/files/rspamd/local.d/redis.conf new file mode 100644 index 0000000..4ae822d --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/redis.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # just specifying a server enables redis for all modules that can use it | ||
2 | servers = "127.0.0.1:6379"; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/replies.conf b/ansible/roles/rspamd/files/rspamd/local.d/replies.conf new file mode 100644 index 0000000..382764d --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/replies.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # whitelist messages from threads that have been replied to | ||
2 | action = "no action"; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/surbl.conf b/ansible/roles/rspamd/files/rspamd/local.d/surbl.conf new file mode 100644 index 0000000..9cbd70f --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/surbl.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # follow redirects when checking URLs in emails for spaminess | ||
2 | redirector_hosts_map = "/etc/rspamd/redirectors.inc"; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/url_reputation.conf b/ansible/roles/rspamd/files/rspamd/local.d/url_reputation.conf new file mode 100644 index 0000000..f5ca48a --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/url_reputation.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # check URLs within messages for spaminess | ||
2 | enabled = true; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/url_tags.conf b/ansible/roles/rspamd/files/rspamd/local.d/url_tags.conf new file mode 100644 index 0000000..61832fb --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/url_tags.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | # cache some URL tags in redis | ||
2 | enabled = true; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/worker-controller.inc b/ansible/roles/rspamd/files/rspamd/local.d/worker-controller.inc new file mode 100644 index 0000000..1e1a713 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/worker-controller.inc | |||
@@ -0,0 +1,39 @@ | |||
1 | # generate a password hash using the `rspamadm pw` command and define 'password' | ||
2 | # this one is the hash for 'hunter2' | ||
3 | # password = "$2$b9s94udsn7zzgk1hc9wuheqqcpydo64x$a1kksr9r9f1g1358shqdz789wmoqbnapndwqi6uscazhz3muz4gy"; | ||
4 | |||
5 | # this one is the hash for: | ||
6 | # Roberts had grown so rich, he wanted to retire. He took me to his cabin and he told me his secret. 'I am not the Dread Pirate Roberts' he said. 'My name is Ryan; I inherited the ship from the previous Dread Pirate Roberts, just as you will inherit it from me. The man I inherited it from is not the real Dread Pirate Roberts either. His name was Cummerbund. The real Roberts has been retired 15 years and living like a king in Patagonia.' | ||
7 | # password = "$2$bhjy5j4njn8r5mx3yo6ksmdt9hbm8fan$myysr1gnbcf9ggpf4dzjdky3by9nbb8w9wbm7wciu97sbb7zhomy"; | ||
8 | |||
9 | # this one is the hash for: | ||
10 | # The point is, ladies and gentleman, that greed, for lack of a better word, is good. Greed is right, greed works. Greed clarifies, cuts through, and captures the essence of the evolutionary spirit. Greed, in all of its forms; greed for life, for money, for love, knowledge has marked the upward surge of mankind. And greed, you mark my words, will not only save Teldar Paper, but that other malfunctioning corporation called the USA. Thank you very much. | ||
11 | # password = "$2$eqre5picpektnop85uashzyxpxeeo6cr$gugecdr35jhg8uhzxkwh4jnp19rtxc6ukaadaad5665sm1rapmfy"; | ||
12 | |||
13 | # this one is the hash for: | ||
14 | # whence the day goes on | ||
15 | # password = "$2$am4gzwgxbuksntkn7784g6mpoir4mp1o$83i86hfju6jfbp6g9w9sh44qacqmne85q9weah6xcj1d3c5ei1rb"; | ||
16 | |||
17 | |||
18 | # You can list multiple bind sockets on networks and file systems. | ||
19 | #bind_socket = "/var/run/rspamd/rspamd.sock mode=0666 owner=nobody"; | ||
20 | |||
21 | # The worker controller handles multiple functions: | ||
22 | # - trains spam | ||
23 | # - trains not-spam | ||
24 | # - hosts the built-in statistics web interface | ||
25 | # - web interface also allows config modification and data injection | ||
26 | |||
27 | # The config parameter 'secure_ip' defines which sources DO NOT need a | ||
28 | # password to connect to this worker controller. | ||
29 | # By default, 'secure_ip' is defined as: | ||
30 | # secure_ip = "127.0.0.1"; | ||
31 | # secure_ip = "::1"; | ||
32 | # | ||
33 | # If you need distributed rspamd access or want to view your spam stats console | ||
34 | # from another machine without SSH tunneling port 11334, you can add multiple | ||
35 | # non-localhost IP address config lines here, but also remember to | ||
36 | # define 'password' above as well. | ||
37 | |||
38 | bind_socket = "127.0.0.1:11334"; | ||
39 | #bind_socket = "192.168.122.8:11334"; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/worker-normal.inc b/ansible/roles/rspamd/files/rspamd/local.d/worker-normal.inc new file mode 100644 index 0000000..ffa77f5 --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/worker-normal.inc | |||
@@ -0,0 +1,3 @@ | |||
1 | # we're not running rspamd in a distributed setup, so this can be disabled | ||
2 | # the proxy worker will handle all the spam filtering | ||
3 | enabled = false; | ||
diff --git a/ansible/roles/rspamd/files/rspamd/local.d/worker-proxy.inc b/ansible/roles/rspamd/files/rspamd/local.d/worker-proxy.inc new file mode 100644 index 0000000..056d2bc --- /dev/null +++ b/ansible/roles/rspamd/files/rspamd/local.d/worker-proxy.inc | |||
@@ -0,0 +1,16 @@ | |||
1 | # this worker will be used as postfix milter | ||
2 | milter = yes; | ||
3 | |||
4 | # note to self - tighten up these permissions | ||
5 | #bind_socket = "/var/run/rspamd/milter.sock mode=0666 owner=nobody"; | ||
6 | |||
7 | # DEFAULT: listens on localhost:11332 | ||
8 | |||
9 | |||
10 | # the following specifies self-scan mode, for when rspamd is on the same | ||
11 | # machine as postfix | ||
12 | timeout = 120s; | ||
13 | upstream "local" { | ||
14 | default = yes; | ||
15 | self_scan = yes; | ||
16 | } | ||
diff --git a/ansible/roles/rspamd/handlers/main.yml b/ansible/roles/rspamd/handlers/main.yml new file mode 100644 index 0000000..de7cfc9 --- /dev/null +++ b/ansible/roles/rspamd/handlers/main.yml | |||
@@ -0,0 +1,11 @@ | |||
1 | --- | ||
2 | - name: restart rspamd | ||
3 | service: | ||
4 | name: rspamd | ||
5 | state: restarted | ||
6 | |||
7 | - name: restart redis | ||
8 | service: | ||
9 | name: redis | ||
10 | state: restarted | ||
11 | |||
diff --git a/ansible/roles/rspamd/meta/main.yml b/ansible/roles/rspamd/meta/main.yml new file mode 100644 index 0000000..8ab008e --- /dev/null +++ b/ansible/roles/rspamd/meta/main.yml | |||
@@ -0,0 +1,3 @@ | |||
1 | --- | ||
2 | dependencies: | ||
3 | - role: gpg | ||
diff --git a/ansible/roles/rspamd/tasks/main.yml b/ansible/roles/rspamd/tasks/main.yml new file mode 100644 index 0000000..a15c330 --- /dev/null +++ b/ansible/roles/rspamd/tasks/main.yml | |||
@@ -0,0 +1,54 @@ | |||
1 | --- | ||
2 | # Set Up rspam repo | ||
3 | - name: install rspam key | ||
4 | apt_key: | ||
5 | url: https://rspamd.com/apt-stable/gpg.key | ||
6 | state: present | ||
7 | |||
8 | - name: create rspam repo | ||
9 | apt_repository: | ||
10 | repo: deb http://rspamd.com/apt-stable/ bionic main | ||
11 | state: present | ||
12 | |||
13 | # rspamd install and configuration | ||
14 | - name: install shitdis | ||
15 | apt: | ||
16 | pkg: redis | ||
17 | state: latest | ||
18 | |||
19 | - name: set guanodis directory permissions | ||
20 | file: | ||
21 | path: /var/lib/redis | ||
22 | owner: redis | ||
23 | group: redis | ||
24 | mode: 0700 | ||
25 | state: directory | ||
26 | |||
27 | - name: copy poodis config | ||
28 | copy: | ||
29 | src: redis/ | ||
30 | dest: /etc/redis/ | ||
31 | notify: | ||
32 | - restart redis | ||
33 | |||
34 | - name: install rspamd | ||
35 | apt: | ||
36 | pkg: rspamd | ||
37 | state: latest | ||
38 | |||
39 | - name: copy rspamd config | ||
40 | copy: | ||
41 | src: rspamd/local.d/ | ||
42 | dest: /etc/rspamd/local.d/ | ||
43 | notify: | ||
44 | - restart rspamd | ||
45 | |||
46 | # verify everything is running | ||
47 | - name: verify services are running in dependency order | ||
48 | service: | ||
49 | name: "{{ item }}" | ||
50 | enabled: yes | ||
51 | state: started | ||
52 | loop: | ||
53 | - redis | ||
54 | - rspamd | ||
diff --git a/ansible/roles/sieve/tasks/main.yml b/ansible/roles/sieve/tasks/main.yml new file mode 100644 index 0000000..1be8729 --- /dev/null +++ b/ansible/roles/sieve/tasks/main.yml | |||
@@ -0,0 +1,20 @@ | |||
1 | --- | ||
2 | - name: copy user sieves to user vmail homedirs | ||
3 | copy: | ||
4 | src: "sieve/{{ item.username }}.sieve" | ||
5 | dest: "/var/mail/vhosts/{{item.domain}}/{{item.user}}/sieve/" | ||
6 | mode: 0600 | ||
7 | owner: vmail | ||
8 | group: vmail | ||
9 | loop: "{{ sieve.users }}" | ||
10 | |||
11 | # dovecot only reads .dovecot.sieve symlink in each users's virtual homedir | ||
12 | - name: create active sieve symlinks for dovecot users | ||
13 | file: | ||
14 | state: link | ||
15 | src: "/var/mail/vhosts/{{item.domain}}/{{item.user}}/sieve/{{ item.username }}.sieve" | ||
16 | dest: "/var/mail/vhosts/{{item.domain}}/{{item.user}}/.dovecot.sieve" | ||
17 | owner: vmail | ||
18 | group: vmail | ||
19 | force: yes | ||
20 | loop: "{{ sieve.users }}" | ||
diff --git a/ansible/runner.sh b/ansible/runner.sh new file mode 100755 index 0000000..c06b35a --- /dev/null +++ b/ansible/runner.sh | |||
@@ -0,0 +1,41 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | set -x | ||
4 | set -e | ||
5 | |||
6 | here=$(dirname $0) | ||
7 | |||
8 | GROUP_PLAYBOOK=$1 | ||
9 | INVENTORY="$here/inventory/inventory" | ||
10 | |||
11 | # More debug options from ansible docs about auto-provisioning... | ||
12 | # (mostly disables built-in checks and overrides some defaults) | ||
13 | # (broken across lines so all the options are easier to see): | ||
14 | # PYTHONUNBUFFERED=1 | ||
15 | # ANSIBLE_FORCE_COLOR=true | ||
16 | # ANSIBLE_HOST_KEY_CHECKING=false | ||
17 | # ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s' | ||
18 | # ansible-playbook | ||
19 | # --private-key=/home/someone/.vagrant.d/insecure_private_key | ||
20 | # --user=vagrant | ||
21 | # --connection=ssh | ||
22 | # --limit='machine1' | ||
23 | # --inventory-file=/inventory/vagrant_ansible_inventory | ||
24 | # playbook.yml | ||
25 | |||
26 | # "debug" below formats output as properly indented/pretty printed. | ||
27 | # You can also replace "debug" with "yaml" for a different view. | ||
28 | # For details of all stdout callbacks, see: | ||
29 | # https://docs.ansible.com/ansible/2.5/plugins/callback.html | ||
30 | # and/or | ||
31 | # ansible-doc -t callback -l | ||
32 | |||
33 | # The following assumes you are testing per-host playbooks and the | ||
34 | # host(s) you are testing are a prefix of the playbook name. | ||
35 | # e.g. if your host name is "webby" and you test playbook "web", | ||
36 | # that's a valid prefix match ("web" is a prefix of "webby") | ||
37 | # or, you can use direct names: deploy to mailmash using mailmash.yml | ||
38 | ANSIBLE_STDOUT_CALLBACK=debug PYTHONUNBUFFERED=1 ansible-playbook -v --inventory $INVENTORY \ | ||
39 | -l $GROUP_PLAYBOOK \ | ||
40 | "$here/$GROUP_PLAYBOOK.yml" \ | ||
41 | --ask-pass --ask-become-pass | ||