mirror of
https://github.com/trailofbits/algo.git
synced 2026-08-17 21:25:50 +02:00
* fix: add explicit bool filters for Ansible 12 jinja2_native compatibility Ansible 12 enables jinja2_native by default, which means string values like "true"/"false" are no longer automatically coerced to booleans in when: conditions and Jinja2 if statements. Add | bool filters to all boolean variable references in tasks, templates, and handlers. Also reformats long single-line Jinja2 conditionals into multi-line for readability, fixes GCE default() calls for native mode, adds help command to the algo script, and updates test fixtures to register the bool filter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: add j2lint for Jinja2 template linting Add j2lint (aristanetworks/j2lint) to catch syntax errors, spacing issues, and operator formatting in Jinja2 templates. Integrated into pre-commit hooks, lint.yml CI, and smart-tests.yml. Rules S3/S5/S6/S7/V1 are ignored — they enforce conventions incompatible with Ansible's config-file-embedded templates. Also fixes int+1 → int + 1 operator spacing in server.conf.j2. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: resolve all ansible-lint warnings and enforce zero-tolerance policy Fix 18 jinja[spacing] errors across 12 files by moving Jinja2 block delimiters to prevent YAML >- folding from introducing trailing spaces. Fix 27 key-order[task] warnings across 17 files by reordering task keys to canonical order (name → when → tags → environment → become → block). Promote key-order[task] and yaml[line-length] from warn_list to hard errors by removing warn_list entirely from .ansible-lint. Add zero-tolerance warning policy to CLAUDE.md explaining why warnings are unacceptable in a security tool and documenting resolution order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
151 lines
4.3 KiB
YAML
151 lines
4.3 KiB
YAML
---
|
|
- when: ansible_facts['distribution_version'] is version('20.04', '<')
|
|
block:
|
|
- name: Add the repository
|
|
apt_repository:
|
|
state: present
|
|
codename: "{{ ansible_distribution_release }}"
|
|
repo: ppa:shevchuk/dnscrypt-proxy
|
|
register: result
|
|
until: result is succeeded
|
|
retries: 10
|
|
delay: 3
|
|
|
|
- name: Configure unattended-upgrades
|
|
copy:
|
|
src: 50-dnscrypt-proxy-unattended-upgrades
|
|
dest: /etc/apt/apt.conf.d/50-dnscrypt-proxy-unattended-upgrades
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
|
|
- name: Install dnscrypt-proxy (individual)
|
|
apt:
|
|
name: dnscrypt-proxy
|
|
state: present
|
|
update_cache: true
|
|
when: not performance_parallel_packages | default(true)
|
|
|
|
- when: apparmor_enabled|default(false)|bool
|
|
tags: apparmor
|
|
block:
|
|
- name: Ubuntu | Configure AppArmor policy for dnscrypt-proxy
|
|
copy:
|
|
src: apparmor.profile.dnscrypt-proxy
|
|
dest: /etc/apparmor.d/usr.bin.dnscrypt-proxy
|
|
owner: root
|
|
group: root
|
|
mode: '0600'
|
|
notify: restart dnscrypt-proxy
|
|
|
|
- name: Ubuntu | Enforce the dnscrypt-proxy AppArmor policy
|
|
command: aa-enforce usr.bin.dnscrypt-proxy
|
|
changed_when: false
|
|
|
|
- name: Ubuntu | Ensure that the dnscrypt-proxy service directory exist
|
|
file:
|
|
path: /etc/systemd/system/dnscrypt-proxy.service.d/
|
|
state: directory
|
|
mode: '0755'
|
|
owner: root
|
|
group: root
|
|
|
|
- name: Ubuntu | Ensure socket override directory exists
|
|
file:
|
|
path: /etc/systemd/system/dnscrypt-proxy.socket.d/
|
|
state: directory
|
|
mode: '0755'
|
|
owner: root
|
|
group: root
|
|
|
|
- name: Ubuntu | Configure dnscrypt-proxy socket to listen on VPN IPs
|
|
copy:
|
|
dest: /etc/systemd/system/dnscrypt-proxy.socket.d/10-algo-override.conf
|
|
content: |
|
|
[Socket]
|
|
# Clear default listeners
|
|
ListenStream=
|
|
ListenDatagram=
|
|
# Add VPN service IPs
|
|
ListenStream={{ local_service_ip }}:53
|
|
ListenDatagram={{ local_service_ip }}:53
|
|
{% if ipv6_support %}
|
|
ListenStream=[{{ local_service_ipv6 }}]:53
|
|
ListenDatagram=[{{ local_service_ipv6 }}]:53
|
|
{% endif %}
|
|
NoDelay=true
|
|
DeferAcceptSec=1
|
|
mode: '0644'
|
|
register: socket_override
|
|
notify:
|
|
- daemon-reload
|
|
- restart dnscrypt-proxy.socket
|
|
- restart dnscrypt-proxy
|
|
|
|
- name: Ubuntu | Reload systemd daemon after socket configuration
|
|
systemd:
|
|
daemon_reload: true
|
|
when: socket_override.changed
|
|
|
|
- name: Ubuntu | Restart dnscrypt-proxy socket to apply configuration
|
|
systemd:
|
|
name: dnscrypt-proxy.socket
|
|
state: restarted
|
|
when: socket_override.changed
|
|
|
|
- name: Ubuntu | Add custom requirements to successfully start the unit
|
|
copy:
|
|
dest: /etc/systemd/system/dnscrypt-proxy.service.d/99-algo.conf
|
|
mode: '0644'
|
|
content: |
|
|
[Unit]
|
|
After=systemd-resolved.service
|
|
Requires=systemd-resolved.service
|
|
|
|
[Service]
|
|
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
|
register: dnscrypt_override
|
|
|
|
- name: Ubuntu | Reload systemd daemon if override changed
|
|
systemd:
|
|
daemon_reload: true
|
|
when: dnscrypt_override.changed
|
|
|
|
- name: Ubuntu | Apply systemd security hardening for dnscrypt-proxy
|
|
copy:
|
|
dest: /etc/systemd/system/dnscrypt-proxy.service.d/90-security-hardening.conf
|
|
content: |
|
|
# Algo VPN systemd security hardening for dnscrypt-proxy
|
|
# Additional hardening on top of comprehensive AppArmor
|
|
[Service]
|
|
# Privilege restrictions
|
|
NoNewPrivileges=yes
|
|
|
|
# Filesystem isolation (complements AppArmor)
|
|
ProtectSystem=strict
|
|
ProtectHome=yes
|
|
PrivateTmp=yes
|
|
PrivateDevices=yes
|
|
ProtectKernelTunables=yes
|
|
ProtectControlGroups=yes
|
|
|
|
# Network restrictions
|
|
RestrictAddressFamilies=AF_INET AF_INET6
|
|
|
|
# Allow access to dnscrypt-proxy cache (AppArmor also controls this)
|
|
ReadWritePaths=/var/cache/dnscrypt-proxy
|
|
|
|
# System call filtering (complements AppArmor restrictions)
|
|
SystemCallFilter=@system-service @network-io
|
|
SystemCallFilter=~@debug @mount @swap @reboot @raw-io
|
|
SystemCallErrorNumber=EPERM
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
register: dnscrypt_hardening
|
|
|
|
- name: Ubuntu | Reload systemd daemon if hardening changed
|
|
systemd:
|
|
daemon_reload: true
|
|
when: dnscrypt_hardening.changed
|