mirror of
https://github.com/trailofbits/algo.git
synced 2026-09-27 12:04:55 +02:00
* Fix DNS IP changing after running update-users The local_service_ip variable is generated using a deterministic random formula seeded by algo_server_name + ansible_fqdn. While algo_server_name is persisted in .config.yml, ansible_fqdn is a runtime fact gathered from the target host that can change if: - Server's hostname configuration changes - DNS resolution changes - User runs ansible from a different control machine When ansible_fqdn differs between initial deployment and users.yml, a different local_service_ip is generated, causing new client configs to point to a DNS IP that doesn't exist on the server. This fix persists local_service_ip and local_service_ipv6 in .config.yml during initial deployment, ensuring users.yml uses the correct DNS IP. Fixes #14614 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Skip apt upgrade and reboot during update-users Previously, running `./algo update-users` would trigger a full apt upgrade and potentially reboot the server because ubuntu.yml was tagged with `update-users`. This caused unexpected disconnections for all VPN clients (gaming, downloads, etc.) during what should be a simple user management operation. Now only facts.yml runs during update-users, which provides the necessary password facts for IPsec certificate generation without running apt upgrade or triggering reboots. Fixes #14518 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add keys_clean_all support to WireGuard (parity with IPsec) Previously, WireGuard had no option to force credential regeneration for existing users. The keys_clean_all option only affected IPsec certificates. Now WireGuard respects keys_clean_all the same way IPsec does: - keys_clean_all: false (default) - preserve existing keys, only generate for new users - keys_clean_all: true - delete all keys and regenerate for all users Also improved the config.cfg documentation to clarify this option affects both WireGuard and IPsec credentials. Fixes #14610 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add permission check for local deployment update-users For local deployments, file ownership must be consistent between initial deployment and subsequent update-users runs. When there's a mismatch (e.g., initial deployment without sudo, update with sudo), files get mixed ownership causing permission errors. This adds a pre-flight check that: - Detects local deployments (localhost or algo_provider: local) - Compares config directory owner with current user - Displays a warning with guidance if there's a mismatch - Provides the exact chown command to fix permissions Addresses #14551 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Address review feedback: explicit directory modes and clearer docs - Add explicit mode to WireGuard directory creation in main.yml: - PKI directories (preshared, private, public): 0700 - Config directories (apple/ios, apple/macos): 0755 - Enhance config.cfg keys_clean_all comment to clarify: - When false: new users added (not just preserved) - When true: ALL CLIENTS MUST RECONFIGURE (explicit impact warning) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Address review: fail on permission mismatch, clean up directory creation 1. Permission check now FAILS instead of warning - Prevents continuing with mismatched permissions - Provides clear fix command: sudo chown -R <user> configs/<server>/ - Simpler condition: just compare owner with current user 2. Clean separation of directory creation - main.yml: Only config directories (apple/ios, apple/macos) with 0755 - keys.yml: Only PKI directories (preshared, private, public) with 0700 - Eliminates duplication and clarifies responsibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Address review: add empty users validation and improve docs 1. Add empty users list validation - Fails early with clear message if no users defined in config.cfg - Prevents confusing downstream errors 2. Improve config.cfg keys_clean_all documentation - Add example use cases: key compromise, removing untrusted users, security audit 3. Rename block for clarity - "Check local deployment permissions" → "Local deployment permission validation" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix jinja2 spacing lint warning Remove extra spaces inside brackets in Jinja2 expression per ansible-lint jinja[spacing] rule. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
179 lines
6.2 KiB
YAML
179 lines
6.2 KiB
YAML
---
|
|
- name: Manage VPN Users
|
|
hosts: localhost
|
|
gather_facts: false
|
|
tags: always
|
|
vars_files:
|
|
- config.cfg
|
|
|
|
tasks:
|
|
- block:
|
|
- name: Get list of installed config files
|
|
find:
|
|
paths: configs/
|
|
depth: 2
|
|
recurse: true
|
|
hidden: true
|
|
patterns: .config.yml
|
|
register: _configs_list
|
|
|
|
- name: Verify servers
|
|
assert:
|
|
that: _configs_list.matched > 0
|
|
msg: No servers found, nothing to update.
|
|
|
|
- name: Build list of installed servers
|
|
set_fact:
|
|
server_list: "{{ server_list | default([]) + [{'server': config.server, 'IP_subject_alt_name': config.IP_subject_alt_name}] }}"
|
|
loop: "{{ _configs_list.files }}"
|
|
loop_control:
|
|
label: "{{ item.path }}"
|
|
vars:
|
|
config: "{{ lookup('file', item.path) | from_yaml }}"
|
|
|
|
- name: Server address prompt
|
|
pause:
|
|
prompt: |
|
|
Select the server to update user list below:
|
|
{% for r in server_list %}
|
|
{{ loop.index }}. {{ r.server }} ({{ r.IP_subject_alt_name }})
|
|
{% endfor %}
|
|
register: _server
|
|
when: server is undefined
|
|
|
|
- block:
|
|
- name: Set facts based on the input
|
|
set_fact:
|
|
algo_server: >-
|
|
{% if server is defined %}{{ server }}{%- elif _server.user_input %}{{ server_list[_server.user_input | int - 1].server }}{%- else %}omit{% endif %}
|
|
|
|
- name: Import host specific variables
|
|
include_vars:
|
|
file: configs/{{ algo_server }}/.config.yml
|
|
|
|
- name: Validate users list is not empty
|
|
fail:
|
|
msg: |
|
|
NO USERS DEFINED
|
|
|
|
The 'users' list in config.cfg is empty. At least one user is required.
|
|
Add users to config.cfg before running update-users.
|
|
when: users | default([]) | length == 0
|
|
|
|
- name: Local deployment permission validation
|
|
block:
|
|
- name: Get config directory owner
|
|
stat:
|
|
path: configs/{{ algo_server }}
|
|
register: config_dir_stat
|
|
|
|
- name: Fail on permission mismatch
|
|
fail:
|
|
msg: |
|
|
PERMISSION MISMATCH DETECTED
|
|
|
|
Config directory owner: {{ config_dir_stat.stat.pw_name }}
|
|
Current user: {{ ansible_user_id }}
|
|
|
|
Running update-users with mismatched permissions will create
|
|
files with inconsistent ownership, breaking future operations.
|
|
|
|
TO FIX: Run this command, then retry update-users:
|
|
sudo chown -R {{ ansible_user_id }} configs/{{ algo_server }}/
|
|
|
|
PREVENT: Always run update-users the same way as initial deployment
|
|
(both with sudo, or both without sudo).
|
|
when: config_dir_stat.stat.pw_name != ansible_user_id
|
|
when: algo_server == 'localhost' or algo_provider | default('') == 'local'
|
|
|
|
- name: Test SSH connectivity to server
|
|
wait_for:
|
|
host: "{{ algo_server }}"
|
|
port: "{{ ansible_ssh_port | default(ssh_port) | int }}"
|
|
timeout: 10
|
|
register: ssh_check
|
|
ignore_errors: true
|
|
when: algo_server != 'localhost'
|
|
|
|
- name: Fail with helpful message if server unreachable
|
|
fail:
|
|
msg: |
|
|
Cannot connect to {{ algo_server }} on port {{ ansible_ssh_port | default(ssh_port) }}.
|
|
|
|
Possible causes:
|
|
- Server is not running (check your cloud provider console)
|
|
- IP address changed (common after EC2 restart without Elastic IP)
|
|
- Firewall/security group blocking port {{ ansible_ssh_port | default(ssh_port) }}
|
|
|
|
To diagnose:
|
|
nc -zv {{ algo_server }} {{ ansible_ssh_port | default(ssh_port) }}
|
|
ssh -vvv -p {{ ansible_ssh_port | default(ssh_port) }} -i configs/algo.pem {{ server_user | default('algo') }}@{{ algo_server }}
|
|
when:
|
|
- algo_server != 'localhost'
|
|
- ssh_check is failed
|
|
|
|
- when: ipsec_enabled
|
|
block:
|
|
- name: CA password prompt
|
|
pause:
|
|
prompt: Enter the password for the private CA key
|
|
echo: false
|
|
register: _ca_password
|
|
when: ca_password is undefined
|
|
|
|
- name: Set facts based on the input
|
|
set_fact:
|
|
CA_password: >-
|
|
{%- if ca_password is defined -%}{{ ca_password }}{%- elif _ca_password.user_input -%}{{ _ca_password.user_input }}{%- else -%}omit{%- endif -%}
|
|
|
|
- name: Local pre-tasks
|
|
import_tasks: playbooks/cloud-pre.yml
|
|
become: false
|
|
|
|
- name: Add the server to the vpn-host group
|
|
add_host:
|
|
name: "{{ algo_server }}"
|
|
groups: vpn-host
|
|
ansible_ssh_user: "{{ server_user | default('root') }}"
|
|
ansible_connection: "{% if algo_server == 'localhost' %}local{% else %}ssh{% endif %}"
|
|
ansible_python_interpreter: /usr/bin/python3
|
|
CA_password: "{{ CA_password | default(omit) }}"
|
|
rescue:
|
|
- include_tasks: playbooks/rescue.yml
|
|
|
|
- name: User management
|
|
hosts: vpn-host
|
|
gather_facts: true
|
|
become: true
|
|
vars_files:
|
|
- config.cfg
|
|
- configs/{{ inventory_hostname }}/.config.yml
|
|
|
|
tasks:
|
|
- block:
|
|
- import_role:
|
|
name: common
|
|
|
|
- import_role:
|
|
name: wireguard
|
|
when: wireguard_enabled
|
|
|
|
- import_role:
|
|
name: strongswan
|
|
when: ipsec_enabled
|
|
tags: ipsec
|
|
|
|
- import_role:
|
|
name: ssh_tunneling
|
|
when: algo_ssh_tunneling
|
|
|
|
- debug:
|
|
msg:
|
|
- "{{ congrats.common.split('\n') }}"
|
|
- " {{ congrats.p12_pass if algo_ssh_tunneling or ipsec_enabled else '' }}"
|
|
- " {{ congrats.ca_key_pass if algo_store_pki and ipsec_enabled else '' }}"
|
|
- " {{ congrats.ssh_access if algo_provider != 'local' else '' }}"
|
|
tags: always
|
|
rescue:
|
|
- include_tasks: playbooks/rescue.yml
|