Repository: trailofbits/algo Branch: main Commit: 3750bac55b63 Files: 335 Total size: 946.0 KB Directory structure: gitextract_xk3afjz7/ ├── .ansible-lint ├── .dockerignore ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ ├── config.yml │ │ └── feature_request.md │ ├── actions/ │ │ ├── setup-algo/ │ │ │ └── action.yml │ │ └── setup-uv/ │ │ └── action.yml │ ├── dependabot.yml │ └── workflows/ │ ├── docker-image.yaml │ ├── integration-tests.yml │ ├── lint.yml │ ├── main.yml │ ├── security.yml │ ├── smart-tests.yml │ └── test-effectiveness.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .yamllint ├── CLAUDE.md ├── CODEOWNERS ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── SECURITY.md ├── algo ├── algo-docker.sh ├── algo-showenv.sh ├── algo.ps1 ├── ansible.cfg ├── cloud.yml ├── config.cfg ├── deploy_client.yml ├── destroy.yml ├── docs/ │ ├── aws-credentials.md │ ├── client-android.md │ ├── client-apple-ipsec.md │ ├── client-linux-ipsec.md │ ├── client-linux-wireguard.md │ ├── client-linux.md │ ├── client-macos-wireguard.md │ ├── client-openwrt-router-wireguard.md │ ├── client-windows.md │ ├── cloud-alternative-ingress-ip.md │ ├── cloud-amazon-ec2.md │ ├── cloud-azure.md │ ├── cloud-cloudstack.md │ ├── cloud-do.md │ ├── cloud-gce.md │ ├── cloud-hetzner.md │ ├── cloud-linode.md │ ├── cloud-scaleway.md │ ├── cloud-vultr.md │ ├── deploy-from-ansible.md │ ├── deploy-from-cloudshell.md │ ├── deploy-from-docker.md │ ├── deploy-from-macos.md │ ├── deploy-from-script-or-cloud-init-to-localhost.md │ ├── deploy-from-windows.md │ ├── deploy-to-ubuntu.md │ ├── deploy-to-unsupported-cloud.md │ ├── faq.md │ ├── firewalls.md │ ├── index.md │ └── troubleshooting.md ├── files/ │ └── cloud-init/ │ ├── README.md │ ├── base.sh │ ├── base.yml │ └── sshd_config ├── input.yml ├── install.sh ├── inventory ├── library/ │ ├── gcp_compute_location_info.py │ ├── lightsail_region_facts.py │ ├── scaleway_compute.py │ └── x25519_pubkey.py ├── main.yml ├── playbooks/ │ ├── cloud-post.yml │ ├── cloud-pre.yml │ ├── rescue.yml │ └── tmpfs/ │ ├── linux.yml │ ├── macos.yml │ ├── main.yml │ └── umount.yml ├── pyproject.toml ├── pytest.ini ├── requirements.yml ├── roles/ │ ├── client/ │ │ ├── files/ │ │ │ └── libstrongswan-relax-constraints.conf │ │ ├── handlers/ │ │ │ └── main.yml │ │ └── tasks/ │ │ ├── main.yml │ │ └── systems/ │ │ ├── CentOS.yml │ │ ├── Debian.yml │ │ ├── Fedora.yml │ │ ├── Ubuntu.yml │ │ └── main.yml │ ├── cloud-azure/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── files/ │ │ │ └── deployment.json │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-cloudstack/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-digitalocean/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-ec2/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── files/ │ │ │ └── stack.yaml │ │ └── tasks/ │ │ ├── cloudformation.yml │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-gce/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-hetzner/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-lightsail/ │ │ ├── files/ │ │ │ └── stack.yaml │ │ └── tasks/ │ │ ├── cloudformation.yml │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-linode/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-openstack/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ └── main.yml │ ├── cloud-scaleway/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── cloud-vultr/ │ │ └── tasks/ │ │ ├── destroy.yml │ │ ├── main.yml │ │ └── prompts.yml │ ├── common/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── handlers/ │ │ │ └── main.yml │ │ ├── tasks/ │ │ │ ├── aip/ │ │ │ │ ├── digitalocean.yml │ │ │ │ ├── main.yml │ │ │ │ └── placeholder.yml │ │ │ ├── facts.yml │ │ │ ├── iptables.yml │ │ │ ├── main.yml │ │ │ ├── packages.yml │ │ │ ├── ubuntu.yml │ │ │ └── unattended-upgrades.yml │ │ └── templates/ │ │ ├── 10-algo-lo100.network.j2 │ │ ├── 10periodic.j2 │ │ ├── 50unattended-upgrades.j2 │ │ ├── 99-algo-ipv6-egress.yaml.j2 │ │ ├── rules.v4.j2 │ │ └── rules.v6.j2 │ ├── dns/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── files/ │ │ │ ├── 50-dnscrypt-proxy-unattended-upgrades │ │ │ └── apparmor.profile.dnscrypt-proxy │ │ ├── handlers/ │ │ │ └── main.yml │ │ ├── tasks/ │ │ │ ├── dns_adblocking.yml │ │ │ ├── main.yml │ │ │ └── ubuntu.yml │ │ └── templates/ │ │ ├── adblock.sh.j2 │ │ ├── dnscrypt-proxy/ │ │ │ ├── cache.toml.j2 │ │ │ ├── filters.toml.j2 │ │ │ ├── global.toml.j2 │ │ │ └── sources.toml.j2 │ │ ├── dnscrypt-proxy.toml.j2 │ │ └── ip-blacklist.txt.j2 │ ├── local/ │ │ └── tasks/ │ │ ├── main.yml │ │ └── prompts.yml │ ├── privacy/ │ │ ├── README.md │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── handlers/ │ │ │ └── main.yml │ │ ├── tasks/ │ │ │ ├── advanced_privacy.yml │ │ │ ├── auto_cleanup.yml │ │ │ ├── clear_history.yml │ │ │ ├── log_filtering.yml │ │ │ ├── log_rotation.yml │ │ │ └── main.yml │ │ └── templates/ │ │ ├── 46-privacy-ssh-filter.conf.j2 │ │ ├── 47-privacy-auth-filter.conf.j2 │ │ ├── 48-privacy-kernel-filter.conf.j2 │ │ ├── 49-privacy-vpn-filter.conf.j2 │ │ ├── auth-logrotate.j2 │ │ ├── clear-history-on-logout.sh.j2 │ │ ├── kern-logrotate.j2 │ │ ├── privacy-auto-cleanup.sh.j2 │ │ ├── privacy-log-cleanup.sh.j2 │ │ ├── privacy-logrotate.j2 │ │ ├── privacy-monitor.sh.j2 │ │ ├── privacy-rsyslog.conf.j2 │ │ └── privacy-shutdown-cleanup.service.j2 │ ├── ssh_tunneling/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── handlers/ │ │ │ └── main.yml │ │ ├── tasks/ │ │ │ └── main.yml │ │ └── templates/ │ │ └── ssh_config.j2 │ ├── strongswan/ │ │ ├── defaults/ │ │ │ └── main.yml │ │ ├── handlers/ │ │ │ └── main.yml │ │ ├── meta/ │ │ │ └── main.yml │ │ ├── tasks/ │ │ │ ├── client_configs.yml │ │ │ ├── distribute_keys.yml │ │ │ ├── ipsec_configuration.yml │ │ │ ├── main.yml │ │ │ ├── openssl.yml │ │ │ └── ubuntu.yml │ │ └── templates/ │ │ ├── 100-CustomLimitations.conf.j2 │ │ ├── charon.conf.j2 │ │ ├── client_ipsec.conf.j2 │ │ ├── client_ipsec.secrets.j2 │ │ ├── ipsec.conf.j2 │ │ ├── ipsec.secrets.j2 │ │ ├── mobileconfig.j2 │ │ └── strongswan.conf.j2 │ └── wireguard/ │ ├── defaults/ │ │ └── main.yml │ ├── files/ │ │ └── wireguard.sh │ ├── handlers/ │ │ └── main.yml │ ├── tasks/ │ │ ├── keys.yml │ │ ├── main.yml │ │ ├── mobileconfig.yml │ │ └── ubuntu.yml │ └── templates/ │ ├── client.conf.j2 │ ├── mobileconfig.j2 │ ├── server.conf.j2 │ └── vpn-dict.j2 ├── scripts/ │ ├── annotate-test-failure.sh │ ├── lint.sh │ ├── list_servers.py │ ├── test-templates.sh │ └── track-test-effectiveness.py ├── server.yml ├── tests/ │ ├── README.md │ ├── conftest.py │ ├── e2e/ │ │ ├── README.md │ │ └── test-vpn-connectivity.sh │ ├── fixtures/ │ │ ├── __init__.py │ │ └── test_variables.yml │ ├── integration/ │ │ ├── ansible-service-wrapper.py │ │ ├── ansible.cfg │ │ ├── mock-apparmor_status.sh │ │ ├── mock_modules/ │ │ │ ├── apt.py │ │ │ ├── command.py │ │ │ └── shell.py │ │ ├── test-configs/ │ │ │ ├── .provisioned │ │ │ └── 10.99.0.10/ │ │ │ ├── .config.yml │ │ │ ├── ipsec/ │ │ │ │ ├── .pki/ │ │ │ │ │ ├── .rnd │ │ │ │ │ ├── 10.99.0.10_ca_generated │ │ │ │ │ ├── cacert.pem │ │ │ │ │ ├── certs/ │ │ │ │ │ │ ├── 01.pem │ │ │ │ │ │ ├── 02.pem │ │ │ │ │ │ ├── 03.pem │ │ │ │ │ │ ├── 10.99.0.10.crt │ │ │ │ │ │ ├── 10.99.0.10_crt_generated │ │ │ │ │ │ ├── testuser1.crt │ │ │ │ │ │ ├── testuser1_crt_generated │ │ │ │ │ │ ├── testuser2.crt │ │ │ │ │ │ └── testuser2_crt_generated │ │ │ │ │ ├── ecparams/ │ │ │ │ │ │ └── secp384r1.pem │ │ │ │ │ ├── index.txt │ │ │ │ │ ├── index.txt.attr │ │ │ │ │ ├── index.txt.attr.old │ │ │ │ │ ├── index.txt.old │ │ │ │ │ ├── openssl.cnf │ │ │ │ │ ├── private/ │ │ │ │ │ │ ├── .rnd │ │ │ │ │ │ ├── 10.99.0.10.key │ │ │ │ │ │ ├── cakey.pem │ │ │ │ │ │ ├── testuser1.key │ │ │ │ │ │ ├── testuser1.p12 │ │ │ │ │ │ ├── testuser1_ca.p12 │ │ │ │ │ │ ├── testuser2.key │ │ │ │ │ │ ├── testuser2.p12 │ │ │ │ │ │ └── testuser2_ca.p12 │ │ │ │ │ ├── public/ │ │ │ │ │ │ ├── testuser1.pub │ │ │ │ │ │ └── testuser2.pub │ │ │ │ │ ├── reqs/ │ │ │ │ │ │ ├── 10.99.0.10.req │ │ │ │ │ │ ├── testuser1.req │ │ │ │ │ │ └── testuser2.req │ │ │ │ │ ├── serial │ │ │ │ │ ├── serial.old │ │ │ │ │ └── serial_generated │ │ │ │ ├── apple/ │ │ │ │ │ ├── testuser1.mobileconfig │ │ │ │ │ └── testuser2.mobileconfig │ │ │ │ └── manual/ │ │ │ │ ├── cacert.pem │ │ │ │ ├── testuser1.conf │ │ │ │ ├── testuser1.p12 │ │ │ │ ├── testuser1.secrets │ │ │ │ ├── testuser2.conf │ │ │ │ ├── testuser2.p12 │ │ │ │ └── testuser2.secrets │ │ │ └── wireguard/ │ │ │ ├── .pki/ │ │ │ │ ├── index.txt │ │ │ │ ├── preshared/ │ │ │ │ │ ├── 10.99.0.10 │ │ │ │ │ ├── testuser1 │ │ │ │ │ └── testuser2 │ │ │ │ ├── private/ │ │ │ │ │ ├── 10.99.0.10 │ │ │ │ │ ├── testuser1 │ │ │ │ │ └── testuser2 │ │ │ │ └── public/ │ │ │ │ ├── 10.99.0.10 │ │ │ │ ├── testuser1 │ │ │ │ └── testuser2 │ │ │ ├── apple/ │ │ │ │ ├── ios/ │ │ │ │ │ ├── testuser1.mobileconfig │ │ │ │ │ └── testuser2.mobileconfig │ │ │ │ └── macos/ │ │ │ │ ├── testuser1.mobileconfig │ │ │ │ └── testuser2.mobileconfig │ │ │ ├── testuser1.conf │ │ │ └── testuser2.conf │ │ └── test-run.log │ ├── test-aws-credentials.yml │ ├── test-local-config.sh │ ├── test-wireguard-async.yml │ ├── test-wireguard-fix.yml │ ├── test-wireguard-real-async.yml │ ├── test_cloud_init_template.py │ ├── test_package_preinstall.py │ ├── unit/ │ │ ├── test_ansible_12_boolean_fix.py │ │ ├── test_basic_sanity.py │ │ ├── test_boolean_variables.py │ │ ├── test_cloud_provider_configs.py │ │ ├── test_comprehensive_boolean_scan.py │ │ ├── test_config_validation.py │ │ ├── test_destroy.py │ │ ├── test_docker_localhost_deployment.py │ │ ├── test_double_templating.py │ │ ├── test_generated_configs.py │ │ ├── test_iptables_rules.py │ │ ├── test_lightsail_boto3_fix.py │ │ ├── test_list_servers.py │ │ ├── test_openssl_compatibility.py │ │ ├── test_scaleway_fix.py │ │ ├── test_strongswan_templates.py │ │ ├── test_template_rendering.py │ │ ├── test_user_management.py │ │ ├── test_wireguard_key_generation.py │ │ └── test_yaml_jinja2_expressions.py │ └── validate_jinja2_templates.py └── users.yml ================================================ FILE CONTENTS ================================================ ================================================ FILE: .ansible-lint ================================================ # Ansible-lint configuration exclude_paths: - .cache/ - .github/ - tests/ - files/cloud-init/ # Cloud-init files have special format requirements - playbooks/ # These are task files included by other playbooks, not standalone playbooks - roles/cloud-ec2/files/ # AWS CloudFormation templates use YAML tags ansible-lint can't parse - roles/cloud-lightsail/files/ # AWS CloudFormation templates use YAML tags ansible-lint can't parse skip_list: - 'package-latest' # Package installs should not use latest - needed for updates - 'experimental' # Experimental rules - 'fqcn[action]' # Use FQCN for module actions - gradual migration - 'fqcn[action-core]' # Use FQCN for builtin actions - gradual migration - 'var-naming[no-role-prefix]' # Variable naming - 'var-naming[pattern]' # Variable naming patterns - 'no-free-form' # Avoid free-form syntax - some legacy usage - 'name[casing]' # Name casing - 'yaml[document-start]' # YAML document start - 'role-name' # Role naming convention - too many cloud-* roles - 'no-handler' # Handler usage - some legitimate non-handler use cases - 'name[missing]' # All tasks should be named - 113 issues to fix (temporary) # Enable additional rules enable_list: - no-log-password - no-same-owner - partial-become - name[play] # All plays should be named - yaml[new-line-at-end-of-file] # Files should end with newline - jinja[invalid] # Invalid Jinja2 syntax (catches template errors) - jinja[spacing] # Proper spacing in Jinja2 expressions - no-changed-when # Commands should declare changed_when - risky-file-permissions # File tasks must have explicit mode verbosity: 1 # Mock custom modules in library/ that ansible-lint can't auto-discover # These modules exist and work at runtime, but need to be declared for static analysis mock_modules: - gcp_compute_location_info - lightsail_region_facts - x25519_pubkey - scaleway_compute # vim: ft=yaml ================================================ FILE: .dockerignore ================================================ # Version control and CI .git/ .github/ .gitignore # Development environment .env .venv/ .ruff_cache/ __pycache__/ *.pyc *.pyo *.pyd # Documentation and metadata docs/ tests/ README.md CHANGELOG.md CONTRIBUTING.md PULL_REQUEST_TEMPLATE.md SECURITY.md logo.png .travis.yml # Build artifacts and configs configs/ Dockerfile .dockerignore Vagrantfile # User configuration (should be bind-mounted) config.cfg # IDE and editor files .vscode/ .idea/ *.swp *.swo *~ # OS generated files .DS_Store Thumbs.db ================================================ FILE: .github/FUNDING.yml ================================================ --- # These are supported funding model platforms github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: algovpn open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with a single custom sponsorship URL ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Report a problem with Algo --- **What happened?** **Environment** (cloud provider, OS, WireGuard or IPsec) **Output** ``` Paste any error messages or relevant output here ``` ================================================ FILE: .github/ISSUE_TEMPLATE/config.yml ================================================ --- blank_issues_enabled: true contact_links: - name: Troubleshooting Guide url: https://trailofbits.github.io/algo/troubleshooting.html about: Check common issues and solutions before filing ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea for this project --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/actions/setup-algo/action.yml ================================================ --- name: 'Setup Algo Environment' description: 'Setup Python, uv, and dependencies for Algo VPN CI' inputs: python-version: description: 'Python version to use' required: false default: '3.11' install-shellcheck: description: 'Install shellcheck for shell script linting' required: false default: 'false' install-ansible-collections: description: 'Install Ansible Galaxy collections' required: false default: 'false' runs: using: composite steps: - name: Setup Python uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 with: python-version: ${{ inputs.python-version }} - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Install shellcheck if: inputs.install-shellcheck == 'true' run: sudo apt-get update && sudo apt-get install -y shellcheck shell: bash - name: Install Ansible collections if: inputs.install-ansible-collections == 'true' run: uv run ansible-galaxy collection install -r requirements.yml shell: bash ================================================ FILE: .github/actions/setup-uv/action.yml ================================================ --- name: 'Setup uv Environment' description: 'Install uv and sync dependencies for Algo VPN project' outputs: uv-version: description: 'The version of uv that was installed' value: ${{ steps.setup.outputs.uv-version }} runs: using: composite steps: - name: Install uv id: setup uses: astral-sh/setup-uv@1ddb97e5078301c0bec13b38151f8664ed04edc8 # v6 with: enable-cache: true - name: Sync dependencies run: uv sync shell: bash ================================================ FILE: .github/dependabot.yml ================================================ --- version: 2 updates: # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" cooldown: default-days: 7 groups: github-actions: patterns: - "*" # Maintain dependencies for Python using uv # Using "uv" ecosystem ensures both pyproject.toml AND uv.lock are updated together # This prevents Docker build failures from lockfile mismatches - package-ecosystem: "uv" directory: "/" schedule: interval: "weekly" cooldown: default-days: 7 groups: python: patterns: - "*" # Maintain Docker base image (python:3.12-alpine) - package-ecosystem: "docker" directory: "/" schedule: interval: "weekly" cooldown: default-days: 7 ================================================ FILE: .github/workflows/docker-image.yaml ================================================ --- name: Create and publish a Docker image 'on': push: branches: ['master'] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-push-image: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Set up QEMU uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 - name: Log in to the Container registry uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | # set latest tag for master branch type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} - name: Build and push Docker image uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0 with: context: . push: true platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} ================================================ FILE: .github/workflows/integration-tests.yml ================================================ --- name: Integration Tests 'on': pull_request: types: [opened, synchronize, reopened] paths: - 'main.yml' - 'roles/**' - 'playbooks/**' - 'library/**' workflow_dispatch: schedule: - cron: '0 2 * * 1' # Weekly on Monday at 2 AM permissions: contents: read jobs: localhost-deployment: name: Localhost VPN Deployment Test runs-on: ubuntu-22.04 timeout-minutes: 30 strategy: fail-fast: false matrix: vpn_type: ['wireguard', 'ipsec', 'both'] steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' # Note: No pip cache - we use uv for dependency management - name: Install system dependencies run: | sudo apt-get update sudo apt-get install -y \ wireguard \ wireguard-tools \ strongswan \ libstrongswan-standard-plugins \ dnsmasq \ qrencode \ openssl \ "linux-headers-$(uname -r)" \ libxml2-utils \ dnsutils - name: Install uv run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Install Python dependencies run: uv sync - name: Install Ansible collections run: uv run ansible-galaxy collection install -r requirements.yml - name: Create test configuration run: | cat > integration-test.cfg << EOF users: - alice - bob cloud_providers: local: server: localhost endpoint: 127.0.0.1 wireguard_enabled: ${{ matrix.vpn_type == 'wireguard' || matrix.vpn_type == 'both' }} ipsec_enabled: ${{ matrix.vpn_type == 'ipsec' || matrix.vpn_type == 'both' }} dns_adblocking: true ssh_tunneling: false store_pki: true algo_provider: local algo_server_name: github-ci-test server: localhost algo_ssh_port: 22 CA_password: "test-ca-password-${{ github.run_id }}" p12_export_password: "test-p12-password-${{ github.run_id }}" tests: true no_log: false ansible_connection: local dns_encryption: true algo_dns_adblocking: true algo_ssh_tunneling: false BetweenClients_DROP: true block_smb: true block_netbios: true pki_in_tmpfs: true endpoint: 127.0.0.1 ssh_port: 4160 local_service_ip: 172.16.0.1 local_service_ipv6: "fd00::1" EOF - name: Run Algo deployment run: | # Run ansible-playbook via uv - become: true in playbook handles root # GitHub runners have passwordless sudo for become escalation uv run ansible-playbook main.yml \ -i "localhost," \ -c local \ -e @integration-test.cfg \ -e "provider=local" \ -vv - name: Verify services are running run: | # Check WireGuard if [[ "${{ matrix.vpn_type }}" == "wireguard" || "${{ matrix.vpn_type }}" == "both" ]]; then echo "Checking WireGuard..." sudo wg show if ! sudo systemctl is-active --quiet wg-quick@wg0; then echo "✗ WireGuard service not running" exit 1 fi echo "✓ WireGuard is running" fi # Check StrongSwan (service name is strongswan-starter on Ubuntu 20.04+) if [[ "${{ matrix.vpn_type }}" == "ipsec" || "${{ matrix.vpn_type }}" == "both" ]]; then echo "Checking StrongSwan..." sudo ipsec statusall if ! sudo systemctl is-active --quiet strongswan-starter; then echo "✗ StrongSwan service not running" exit 1 fi echo "✓ StrongSwan is running" fi # Check dnsmasq if ! sudo systemctl is-active --quiet dnsmasq; then echo "⚠️ dnsmasq not running (may be expected)" else echo "✓ dnsmasq is running" fi # Check dnscrypt-proxy if sudo systemctl is-active --quiet dnscrypt-proxy; then echo "✓ dnscrypt-proxy is running" else echo "⚠️ dnscrypt-proxy not running" fi # DNS health check - verify DNS resolution works echo "Testing DNS resolution via local_service_ip (172.16.0.1)..." if dig @172.16.0.1 google.com +short +timeout=5 | grep -q .; then echo "✓ DNS resolution working" else echo "⚠️ DNS resolution failed (service may still be starting)" fi - name: Verify generated configs run: | echo "Checking generated configuration files..." # WireGuard configs if [[ "${{ matrix.vpn_type }}" == "wireguard" || "${{ matrix.vpn_type }}" == "both" ]]; then for user in alice bob; do if [ ! -f "configs/localhost/wireguard/${user}.conf" ]; then echo "✗ Missing WireGuard config for ${user}" exit 1 fi if [ ! -f "configs/localhost/wireguard/${user}.png" ]; then echo "✗ Missing WireGuard QR code for ${user}" exit 1 fi done echo "✓ All WireGuard configs generated" fi # IPsec configs (p12 in manual/, mobileconfig in apple/) if [[ "${{ matrix.vpn_type }}" == "ipsec" || "${{ matrix.vpn_type }}" == "both" ]]; then for user in alice bob; do if [ ! -f "configs/localhost/ipsec/manual/${user}.p12" ]; then echo "✗ Missing IPsec certificate for ${user}" exit 1 fi if [ ! -f "configs/localhost/ipsec/apple/${user}.mobileconfig" ]; then echo "✗ Missing IPsec mobile config for ${user}" exit 1 fi done echo "✓ All IPsec configs generated" fi - name: Test VPN connectivity run: | echo "Testing basic VPN connectivity..." # Test WireGuard if [[ "${{ matrix.vpn_type }}" == "wireguard" || "${{ matrix.vpn_type }}" == "both" ]]; then # Get server's WireGuard public key SERVER_PUBKEY=$(sudo wg show wg0 public-key) echo "Server public key: $SERVER_PUBKEY" # Check if interface has peers PEER_COUNT=$(sudo wg show wg0 peers | wc -l) echo "✓ WireGuard has $PEER_COUNT peer(s) configured" fi # Test StrongSwan if [[ "${{ matrix.vpn_type }}" == "ipsec" || "${{ matrix.vpn_type }}" == "both" ]]; then # Check IPsec policies sudo ipsec statusall | grep -E "INSTALLED|ESTABLISHED" || echo "No active IPsec connections (expected)" fi - name: Run E2E VPN connectivity tests env: VPN_TYPE: ${{ matrix.vpn_type }} run: | chmod +x tests/e2e/test-vpn-connectivity.sh sudo tests/e2e/test-vpn-connectivity.sh "${VPN_TYPE}" - name: Collect E2E debug info on failure if: failure() run: | echo "=== E2E Test Debug Information ===" echo "=== Network Namespaces ===" ip netns list || true echo "=== WireGuard Config (alice) ===" cat configs/localhost/wireguard/alice.conf 2>/dev/null || echo "Not found" echo "=== IPsec Certificates ===" ls -la configs/localhost/ipsec/.pki/certs/ 2>/dev/null || echo "Not found" echo "=== iptables NAT ===" sudo iptables -t nat -L -n -v || true - name: Upload configs as artifacts if: always() uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: name: vpn-configs-${{ matrix.vpn_type }}-${{ github.run_id }} path: configs/ retention-days: 7 - name: Upload logs on failure if: failure() run: | echo "=== Network Interfaces ===" ip addr || true echo "=== Listening Ports ===" sudo ss -tulnp || true echo "=== WireGuard Status ===" sudo wg show || true echo "=== IPsec Status ===" sudo ipsec statusall || true echo "=== DNS Services ===" sudo systemctl status dnscrypt-proxy dnscrypt-proxy.socket dnsmasq --no-pager || true echo "=== WireGuard Log ===" sudo journalctl -u wg-quick@wg0 -n 50 --no-pager || true echo "=== StrongSwan Log ===" sudo journalctl -u strongswan -n 50 --no-pager || true echo "=== dnscrypt-proxy Log ===" sudo journalctl -u dnscrypt-proxy -n 50 --no-pager || true echo "=== System Log (last 100 lines) ===" sudo journalctl -n 100 --no-pager || true docker-build-test: name: Docker Image Build Test runs-on: ubuntu-22.04 timeout-minutes: 10 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Build Algo Docker image run: | docker build -t algo:ci-test . - name: Test Docker image run: | # Test that the image can run and show help docker run --rm --entrypoint /bin/sh algo:ci-test -c "cd /algo && ./algo --help" || true # Test that required binaries exist in the virtual environment docker run --rm --entrypoint /bin/sh algo:ci-test -c "cd /algo && uv run which ansible" docker run --rm --entrypoint /bin/sh algo:ci-test -c "which python3" docker run --rm --entrypoint /bin/sh algo:ci-test -c "which rsync" - name: Test Docker config validation run: | # Create a minimal valid config mkdir -p test-data cat > test-data/config.cfg << 'EOF' users: - test-user cloud_providers: ec2: size: t3.micro region: us-east-1 wireguard_enabled: true ipsec_enabled: false dns_encryption: true algo_provider: ec2 EOF # Test that config is readable docker run --rm --entrypoint cat -v "$(pwd)/test-data:/data" algo:ci-test /data/config.cfg echo "✓ Docker image built and basic tests passed" ================================================ FILE: .github/workflows/lint.yml ================================================ --- name: Lint 'on': push: branches: [main, master] pull_request: permissions: contents: read jobs: ansible-lint: name: Ansible linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup Algo environment uses: ./.github/actions/setup-algo with: install-ansible-collections: 'true' - name: Run ansible-lint run: | uv run --with ansible-lint ansible-lint . - name: Run playbook dry-run check (catch runtime issues) run: | # Test main playbook logic without making changes # This catches filter warnings, collection issues, and runtime errors uv run ansible-playbook main.yml --check --connection=local \ -e "server_ip=test" \ -e "server_name=ci-test" \ -e "IP_subject_alt_name=192.168.1.1" \ || echo "Dry-run check completed with issues - review output above" yaml-lint: name: YAML linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Run yamllint run: uv run --with yamllint yamllint -c .yamllint . jinja2-lint: name: Jinja2 template linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Run j2lint run: | # Lint Jinja2 templates for syntax and style issues # Ignored rules (incompatible with Ansible config-file templates): # S3: indentation (dictated by output format, not Jinja style) # S5: tabs (some config formats require them) # S6: whitespace-control delimiters ({%- -%} are standard Ansible) # S7: single-statement-per-line (inline Jinja in config output) # V1: lowercase variables (existing names like IP_subject_alt_name) uv run --with j2lint j2lint roles/ --ignore S3 S5 S6 S7 V1 python-lint: name: Python linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup Algo environment uses: ./.github/actions/setup-algo - name: Run ruff check run: | # Fast Python linter uv run --with ruff ruff check . - name: Run ruff format check run: | # Verify consistent Python formatting uv run --with ruff ruff format --check . python-types: name: Python type checking runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup Algo environment uses: ./.github/actions/setup-algo - name: Run ty check run: | # Type checking with ty uv run --with ty ty check shellcheck: name: Shell script linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup Algo environment uses: ./.github/actions/setup-algo with: install-shellcheck: 'true' - name: Run shellcheck run: | # Check all shell scripts, not just algo and install.sh find . -type f -name "*.sh" -not -path "./.git/*" -exec shellcheck {} \; powershell-lint: name: PowerShell script linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Install PowerShell run: | # Install PowerShell Core wget -q https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/powershell_7.4.0-1.deb_amd64.deb sudo dpkg -i powershell_7.4.0-1.deb_amd64.deb sudo apt-get install -f - name: Install PSScriptAnalyzer run: | pwsh -Command "Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser" - name: Run PowerShell syntax check run: | # Check syntax by parsing the script pwsh -NoProfile -NonInteractive -Command " try { \$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path './algo.ps1' -Raw), [ref]\$null) Write-Host '✓ PowerShell syntax check passed' } catch { Write-Error 'PowerShell syntax error: ' + \$_.Exception.Message exit 1 } " - name: Run PSScriptAnalyzer run: | pwsh -Command " \$results = Invoke-ScriptAnalyzer -Path './algo.ps1' -Severity Warning,Error if (\$results.Count -gt 0) { \$results | Format-Table -AutoSize exit 1 } else { Write-Host '✓ PSScriptAnalyzer check passed' } " actionlint: name: GitHub Actions linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Install actionlint run: | bash <(curl -sL https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) sudo mv actionlint /usr/local/bin/ - name: Run actionlint run: | actionlint .github/workflows/*.yml zizmor: name: GitHub Actions security audit runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Install zizmor run: | pip install zizmor - name: Run zizmor run: | zizmor .github/workflows/ ================================================ FILE: .github/workflows/main.yml ================================================ --- name: Main 'on': push: branches: - master - main workflow_dispatch: permissions: contents: read jobs: syntax-check: name: Ansible syntax check runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Check Ansible playbook syntax run: uv run ansible-playbook main.yml --syntax-check basic-tests: name: Basic sanity tests runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Install system dependencies run: sudo apt-get update && sudo apt-get install -y shellcheck - name: Run basic sanity tests run: uv run pytest tests/unit/ -v docker-build: name: Docker build test runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Build Docker image run: docker build -t local/algo:test . - name: Test Docker image starts run: | # Just verify the image can start and show help docker run --rm local/algo:test /algo/algo --help - name: Run Docker deployment tests run: uv run pytest tests/unit/test_docker_localhost_deployment.py -v config-generation: name: Configuration generation test runs-on: ubuntu-22.04 timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Test configuration generation (local mode) run: | # Run our simplified config test chmod +x tests/test-local-config.sh ./tests/test-local-config.sh ansible-dry-run: name: Ansible dry-run validation runs-on: ubuntu-22.04 timeout-minutes: 10 permissions: contents: read strategy: matrix: provider: [local, ec2, digitalocean, gce] steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Create test configuration for ${{ matrix.provider }} run: | # Create provider-specific test config cat > test-${{ matrix.provider }}.cfg << 'EOF' users: - testuser cloud_providers: ${{ matrix.provider }}: server: test-server size: t3.micro image: ubuntu-22.04 region: us-east-1 wireguard_enabled: true ipsec_enabled: false dns_adblocking: false ssh_tunneling: false store_pki: true algo_provider: ${{ matrix.provider }} algo_server_name: test-algo-vpn server: test-server endpoint: 10.0.0.1 ansible_ssh_user: ubuntu ansible_ssh_port: 22 algo_ssh_port: 4160 algo_ondemand_cellular: false algo_ondemand_wifi: false EOF - name: Run Ansible check mode for ${{ matrix.provider }} run: | # Run ansible in check mode to validate playbooks work uv run ansible-playbook main.yml \ -i "localhost," \ -c local \ -e @test-${{ matrix.provider }}.cfg \ -e "provider=${{ matrix.provider }}" \ --check \ --diff \ -vv \ --skip-tags "facts,tests,local,update-alternatives,cloud_api" || true # The || true is because check mode will fail on some tasks # but we're looking for syntax/undefined variable errors ================================================ FILE: .github/workflows/security.yml ================================================ --- name: Security 'on': push: branches: [main, master] pull_request: permissions: contents: read jobs: semgrep: name: Semgrep SAST runs-on: ubuntu-22.04 container: image: semgrep/semgrep@sha256:d3d1be3a3770514d16a6a57b9761575d7536d70f45a5220274f4ec7d55c442b9 # v1.151.0 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Run semgrep run: > semgrep --config auto --exclude-rule dockerfile.security.last-user-is-root.last-user-is-root --error --quiet . pip-audit: name: Python dependency audit runs-on: ubuntu-22.04 steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - name: Setup Algo environment uses: ./.github/actions/setup-algo - name: Run pip-audit run: uv run --with pip-audit pip-audit ================================================ FILE: .github/workflows/smart-tests.yml ================================================ --- name: Smart Test Selection 'on': pull_request: types: [opened, synchronize, reopened] permissions: contents: read pull-requests: read jobs: changed-files: name: Detect Changed Files runs-on: ubuntu-latest outputs: # Define what tests to run based on changes run_syntax_check: ${{ steps.filter.outputs.ansible }} run_basic_tests: ${{ steps.filter.outputs.python }} run_docker_tests: ${{ steps.filter.outputs.docker }} run_config_tests: ${{ steps.filter.outputs.configs }} run_template_tests: ${{ steps.filter.outputs.templates }} run_lint: ${{ steps.filter.outputs.lint }} run_integration: ${{ steps.filter.outputs.integration }} steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 id: filter with: filters: | ansible: - '**/*.yml' - '**/*.yaml' - 'main.yml' - 'playbooks/**' - 'roles/**' - 'library/**' python: - '**/*.py' - 'pyproject.toml' - 'uv.lock' - 'tests/**' docker: - 'Dockerfile*' - '.dockerignore' - 'docker-compose*.yml' configs: - 'config.cfg*' - 'roles/**/templates/**' - 'roles/**/defaults/**' templates: - '**/*.j2' - 'roles/**/templates/**' lint: - '**/*.py' - '**/*.yml' - '**/*.yaml' - '**/*.sh' - '**/*.j2' - '.ansible-lint' - '.yamllint' - 'pyproject.toml' integration: - 'main.yml' - 'roles/**' - 'library/**' - 'playbooks/**' syntax-check: name: Ansible Syntax Check needs: changed-files if: needs.changed-files.outputs.run_syntax_check == 'true' runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Check Ansible playbook syntax run: uv run ansible-playbook main.yml --syntax-check basic-tests: name: Basic Sanity Tests needs: changed-files if: needs.changed-files.outputs.run_basic_tests == 'true' || needs.changed-files.outputs.run_template_tests == 'true' runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Install system dependencies run: sudo apt-get update && sudo apt-get install -y shellcheck - name: Run relevant tests env: RUN_BASIC_TESTS: ${{ needs.changed-files.outputs.run_basic_tests }} RUN_TEMPLATE_TESTS: ${{ needs.changed-files.outputs.run_template_tests }} run: | # Always run basic sanity uv run pytest tests/unit/test_basic_sanity.py -v # Run other tests based on what changed if [[ "${RUN_BASIC_TESTS}" == "true" ]]; then uv run pytest \ tests/unit/test_config_validation.py \ tests/unit/test_user_management.py \ tests/unit/test_openssl_compatibility.py \ tests/unit/test_cloud_provider_configs.py \ tests/unit/test_generated_configs.py \ -v fi if [[ "${RUN_TEMPLATE_TESTS}" == "true" ]]; then uv run pytest tests/unit/test_template_rendering.py -v fi docker-tests: name: Docker Build Test needs: changed-files if: needs.changed-files.outputs.run_docker_tests == 'true' runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Build Docker image run: docker build -t local/algo:test . - name: Test Docker image starts run: | docker run --rm local/algo:test /algo/algo --help - name: Run Docker deployment tests run: uv run pytest tests/unit/test_docker_localhost_deployment.py -v config-tests: name: Configuration Tests needs: changed-files if: needs.changed-files.outputs.run_config_tests == 'true' runs-on: ubuntu-22.04 timeout-minutes: 10 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Test configuration generation run: | chmod +x tests/test-local-config.sh ./tests/test-local-config.sh - name: Run ansible dry-run tests run: | # Quick dry-run for local provider only cat > test-local.cfg << 'EOF' users: - testuser cloud_providers: local: server: test-server wireguard_enabled: true ipsec_enabled: false dns_adblocking: false ssh_tunneling: false algo_provider: local algo_server_name: test-algo-vpn server: test-server endpoint: 10.0.0.1 EOF uv run ansible-playbook main.yml \ -i "localhost," \ -c local \ -e @test-local.cfg \ -e "provider=local" \ --check \ --diff \ -vv \ --skip-tags "facts,tests,local,update-alternatives,cloud_api" || true lint: name: Linting needs: changed-files if: needs.changed-files.outputs.run_lint == 'true' runs-on: ubuntu-22.04 permissions: contents: read steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Setup uv environment uses: ./.github/actions/setup-uv - name: Install ansible dependencies run: uv run ansible-galaxy collection install community.crypto - name: Run relevant linters env: RUN_LINT: ${{ needs.changed-files.outputs.run_lint }} BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.sha }} run: | # Run linters if lint-related files changed if [[ "${RUN_LINT}" == "true" ]]; then echo "Running linters..." # Run Python linter uv run --with ruff ruff check . # Run YAML linter uv run --with yamllint yamllint -c .yamllint . # Run Ansible linter uv run --with ansible-lint ansible-lint # Check Jinja2 templates if git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" | grep -q '\.j2$'; then uv run --with j2lint j2lint roles/ --ignore S3 S5 S6 S7 V1 fi # Check shell scripts if any changed if git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" | grep -q '\.sh$'; then find . -name "*.sh" -type f -not -path "./.git/*" -exec shellcheck {} + fi fi all-tests-required: name: All Required Tests needs: [syntax-check, basic-tests, docker-tests, config-tests, lint] if: always() runs-on: ubuntu-latest steps: - name: Check test results env: SYNTAX_CHECK_RESULT: ${{ needs.syntax-check.result }} BASIC_TESTS_RESULT: ${{ needs.basic-tests.result }} DOCKER_TESTS_RESULT: ${{ needs.docker-tests.result }} CONFIG_TESTS_RESULT: ${{ needs.config-tests.result }} LINT_RESULT: ${{ needs.lint.result }} run: | # This job ensures all required tests pass # It will fail if any dependent job failed if [[ "${SYNTAX_CHECK_RESULT}" == "failure" ]] || \ [[ "${BASIC_TESTS_RESULT}" == "failure" ]] || \ [[ "${DOCKER_TESTS_RESULT}" == "failure" ]] || \ [[ "${CONFIG_TESTS_RESULT}" == "failure" ]] || \ [[ "${LINT_RESULT}" == "failure" ]]; then echo "One or more required tests failed" exit 1 fi echo "All required tests passed!" trigger-integration: name: Trigger Integration Tests needs: changed-files if: | needs.changed-files.outputs.run_integration == 'true' && github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - name: Trigger integration tests run: | echo "Integration tests should be triggered for this PR" echo "Changed files indicate potential breaking changes" echo "Run workflow manually: .github/workflows/integration-tests.yml" ================================================ FILE: .github/workflows/test-effectiveness.yml ================================================ --- name: Test Effectiveness Tracking 'on': schedule: - cron: '0 0 * * 0' # Weekly on Sunday workflow_dispatch: # Allow manual runs permissions: contents: write issues: write pull-requests: read actions: read jobs: track-effectiveness: name: Analyze Test Effectiveness runs-on: ubuntu-latest steps: - uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v5.0.1 with: persist-credentials: true - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3.11' - name: Analyze test effectiveness env: GH_TOKEN: ${{ github.token }} run: | python scripts/track-test-effectiveness.py - name: Upload metrics uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: name: test-effectiveness-metrics path: .metrics/ - name: Create issue if tests are ineffective env: GH_TOKEN: ${{ github.token }} run: | # Check if we need to create an issue if grep -q "⚠️" .metrics/test-effectiveness-report.md; then # Check if issue already exists existing=$(gh issue list --label "test-effectiveness" --state open --json number --jq '.[0].number') if [ -z "$existing" ]; then gh issue create \ --title "Test Effectiveness Review Needed" \ --body-file .metrics/test-effectiveness-report.md \ --label "test-effectiveness,maintenance" else # Update existing issue gh issue comment "$existing" --body-file .metrics/test-effectiveness-report.md fi fi - name: Commit metrics if changed run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" if [[ -n $(git status -s .metrics/) ]]; then git add .metrics/ git commit -m "chore: Update test effectiveness metrics [skip ci]" git push fi ================================================ FILE: .gitignore ================================================ *.retry .idea/ configs/* inventory_users *.kate-swp .env/ .venv/ .DS_Store .vagrant .ansible/ __pycache__/ *.pyc algo.egg-info/ ================================================ FILE: .pre-commit-config.yaml ================================================ # See https://prek.j178.dev for more information --- # Apply to all files without committing: # prek run --all-files # Update this file: # prek auto-update repos: # Use prek built-in hooks (faster, Rust-native) - repo: builtin hooks: - id: check-yaml args: [--allow-multiple-documents] exclude: '(files/cloud-init/base\.yml|roles/cloud-.*/files/stack\.yaml)' - id: end-of-file-fixer - id: trailing-whitespace - id: check-added-large-files args: ['--maxkb=500'] - id: check-merge-conflict - id: mixed-line-ending args: [--fix=lf] # Python linting with ruff (fast, replaces many tools) - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.14.14 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format # YAML linting - repo: https://github.com/adrienverge/yamllint rev: v1.38.0 hooks: - id: yamllint args: [-c=.yamllint] exclude: '.git/.*' # Shell script linting - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.11.0.1 hooks: - id: shellcheck exclude: '.git/.*' # Local hooks that use the project's installed tools - repo: local hooks: - id: ty-check name: Python type check entry: bash -c 'uv run --with ty ty check' language: system types: [python] pass_filenames: false - id: j2lint name: Jinja2 template lint entry: bash -c 'uv run j2lint roles/ --ignore S3 S5 S6 S7 V1' language: system files: '\.j2$' pass_filenames: false - id: ansible-lint name: Ansible-lint entry: bash -c 'uv run ansible-lint --force-color || echo "Ansible-lint had issues - check output"' language: system types: [yaml] files: \.(yml|yaml)$ exclude: '^(.git/|.github/|requirements\.yml)' pass_filenames: false - id: ansible-syntax name: Ansible syntax check entry: bash -c 'uv run ansible-playbook main.yml --syntax-check' language: system files: 'main\.yml|server\.yml|users\.yml' pass_filenames: false - id: semgrep name: Semgrep security scan entry: > bash -c ' command -v semgrep >/dev/null && semgrep --config auto --exclude-rule dockerfile.security.last-user-is-root.last-user-is-root --error --quiet --skip-unknown-extensions . || echo "semgrep not installed - skipping"' language: system pass_filenames: false - id: actionlint name: GitHub Actions lint entry: bash -c 'command -v actionlint >/dev/null && actionlint .github/workflows/ || echo "actionlint not installed - skipping"' language: system files: '^\.github/workflows/.*\.yml$' pass_filenames: false - id: zizmor name: GitHub Actions security audit entry: bash -c 'command -v zizmor >/dev/null && zizmor .github/workflows/ || echo "zizmor not installed - skipping"' language: system files: '^\.github/workflows/.*\.yml$' pass_filenames: false # Configuration for prek # Files to exclude globally exclude: | (?x)^( .env/.*| .venv/.*| .git/.*| __pycache__/.*| .*\.egg-info/.* )$ ================================================ FILE: .yamllint ================================================ --- extends: default # Cloud-init files must be excluded from normal YAML rules # The #cloud-config header cannot have a space and cannot have --- document start ignore: | files/cloud-init/ .env/ .venv/ .ansible/ configs/ tests/integration/test-configs/ rules: line-length: max: 160 level: warning comments: min-spaces-from-content: 1 comments-indentation: false octal-values: forbid-implicit-octal: true forbid-explicit-octal: true braces: max-spaces-inside: 1 truthy: allowed-values: ['true', 'false', 'yes', 'no'] ================================================ FILE: CLAUDE.md ================================================ # CLAUDE.md - LLM Guidance for Algo VPN This document provides essential context and guidance for LLMs working on the Algo VPN codebase. ## Project Overview Algo is an Ansible-based tool that sets up a personal VPN in the cloud. It's designed to be: - **Security-focused**: Creates hardened VPN servers with minimal attack surface - **Easy to use**: Automated deployment with sensible defaults - **Multi-platform**: Supports various cloud providers and operating systems - **Privacy-preserving**: No logging, minimal data retention ### Core Technologies - **VPN Protocols**: WireGuard (preferred) and IPsec/IKEv2 - **Configuration Management**: Ansible (v12+) - **Languages**: Python, YAML, Shell, Jinja2 templates - **Supported Providers**: AWS, Azure, DigitalOcean, GCP, Vultr, Hetzner, local deployment ### Philosophy - Stability over features - Security over convenience - Clarity over cleverness - Test everything - Stay in scope - solve exactly what the issue asks, nothing more - Test assumptions - run the code before committing - Resist new dependencies - each one is attack surface and maintenance ## Architecture and Structure ``` algo/ ├── main.yml # Primary playbook ├── users.yml # User management playbook ├── server.yml # Server-specific tasks ├── config.cfg # Main configuration file ├── pyproject.toml # Python project configuration and dependencies ├── uv.lock # Exact dependency versions lockfile ├── requirements.yml # Ansible collections ├── roles/ # Ansible roles │ ├── common/ # Base system configuration, firewall, hardening │ ├── wireguard/ # WireGuard VPN setup │ ├── strongswan/ # IPsec/IKEv2 setup │ ├── dns/ # DNS configuration (dnscrypt-proxy) │ └── cloud-*/ # Cloud provider specific roles ├── library/ # Custom Ansible modules └── tests/unit/ # Python unit tests ``` ## Development Workflow ### Quality Gates (MANDATORY) **All PRs must pass these checks locally before submission.** CI will reject failures: ```bash # Run the full lint suite (same as CI) ansible-lint . && yamllint . && ruff check . && shellcheck scripts/*.sh && semgrep --config auto --exclude-rule dockerfile.security.last-user-is-root.last-user-is-root --error --quiet . ansible-playbook main.yml --syntax-check ansible-playbook users.yml --syntax-check pytest tests/unit/ -q ``` Common lint issues to fix before submitting: - YAML files missing `---` document start markers - GitHub workflows with unquoted `on:` (must be `'on':`) - Using `ignore_errors: true` instead of `failed_when: false` - Jinja2 spacing errors (`{{foo}}` should be `{{ foo }}`) - Missing `mode:` on file/directory tasks ### Zero-Tolerance Warning Policy **No warnings are tolerated in CI.** Every linter finding must be either fixed or explicitly allowlisted in the tool's config file (`.ansible-lint`, `pyproject.toml`, etc.). Why this matters for Algo: - **Security tool** - VPN misconfigurations silently break privacy guarantees. A "cosmetic" warning today hides a real bug tomorrow. - **Ansible complexity** - YAML+Jinja2 linting catches real runtime failures (wrong key order breaks `when` evaluation, spacing errors cause template failures). Warnings in Ansible are not style nits. - **CI signal integrity** - If 30 warnings scroll by on every run, the 31st one (a real regression) goes unnoticed. Zero warnings means every new finding gets human attention. Resolution order of preference: 1. **Fix it** - Preferred. Most findings have straightforward fixes. 2. **Allowlist in config** - If the rule is wrong for this project, add to `skip_list` with a comment explaining why. 3. **Inline suppress** - Last resort. Use `# noqa: rule-name` with a comment justifying the exception. Never use `warn_list` in `.ansible-lint` — it exists as a migration tool, not a permanent home. Rules either pass or are explicitly skipped. ### Design Requirements When adding or modifying features, verify these before requesting review: 1. **Validate inputs early** - Check for empty lists, missing configs, permission mismatches before expensive operations 2. **Explicit file modes** - Always specify `mode:` on file/directory tasks (never rely on umask) 3. **Fail vs warn** - Permission/security issues should fail; optional features can warn 4. **Actionable errors** - Include fix commands in error messages: `"Run: sudo chown -R $USER configs/"` 5. **Follow existing patterns** - Search codebase first: `rg "when:.*localhost" --type yaml` ### Linting Tools | Tool | Target | Key Rules | |------|--------|-----------| | `ansible-lint` | YAML tasks | Use `failed_when` not `ignore_errors`, add `mode:` to files | | `yamllint` | All YAML | Document start `---`, quote `'on':` in workflows | | `ruff` | Python | Line length 120, target Python 3.11 | | `shellcheck` | Shell scripts | Quote variables, use `set -euo pipefail` | | `semgrep` | All code | SAST scanner, `--config auto`, suppress with `# nosemgrep: rule-id` | ### Git Workflow 1. Create feature branches from `master` 2. Run all linters before pushing 3. Make atomic commits with clear messages 4. Update PR description with test results ### Self-Review Checklist Before creating a PR, review your own diff: - [ ] Did I run all linters locally? - [ ] Did I search for similar patterns in the codebase? - [ ] Did I add explicit `mode:` to file/directory tasks? - [ ] Did I validate inputs before expensive operations? - [ ] Did I update tests if I changed file paths or behavior? - [ ] Would a reviewer ask "what happens if X is empty/missing?" ## Ansible Pitfalls ### with_items vs loop `with_items` auto-flattens lists; `loop` does not. **Never mechanically convert:** ```yaml # WRONG - treats list as single item, creates file named "['alice', 'bob']" loop: - "{{ users }}" # CORRECT - iterates over list contents loop: "{{ users }}" # CORRECT - combining lists (with_items did this automatically) loop: "{{ users + [server_name] }}" ``` **Always test loop conversions** - verify the task creates expected files. ### Path Variables Never include trailing slashes - causes double-slash bugs: ```yaml # WRONG - creates paths like /etc/ipsec.d//private ipsec_path: "configs/{{ server }}/ipsec/" # CORRECT ipsec_path: "configs/{{ server }}/ipsec" ``` ### ignore_errors vs failed_when ```yaml # WRONG - ansible-lint failure - name: Clear history command: some_command ignore_errors: true # CORRECT - explicit about expected failures - name: Clear history command: some_command failed_when: false ``` ### changed_when on Read-Only Tasks Handlers and check commands that don't modify state need `changed_when: false`: ```yaml - name: Check service status command: systemctl status foo changed_when: false ``` ### Jinja2 Native Mode (Ansible 12+) Ansible 12 enables `jinja2_native` by default, changing how values are evaluated: **Boolean conditionals require actual booleans:** ```yaml # WRONG - string "true" is not boolean ipv6_support: "{% if ipv6 %}true{% else %}false{% endif %}" # CORRECT - return actual boolean ipv6_support: "{{ ipv6 is defined }}" ``` **No nested templates in lookup():** ```yaml # WRONG - deprecated double-templating key: "{{ lookup('file', '{{ SSH_keys.public }}') }}" # CORRECT - pass variable directly key: "{{ lookup('file', SSH_keys.public) }}" ``` **JSON files need explicit parsing:** ```yaml # WRONG - returns string in native mode creds: "{{ lookup('file', 'credentials.json') }}" # CORRECT - parse JSON explicitly creds: "{{ lookup('file', 'credentials.json') | from_json }}" ``` **default() doesn't trigger on empty strings:** ```yaml # WRONG - empty string '' is not undefined key: "{{ lookup('env', 'AWS_KEY') | default('fallback') }}" # CORRECT - add true to handle falsy values key: "{{ lookup('env', 'AWS_KEY') | default('fallback', true) }}" ``` **Complex Jinja loops break in set_fact:** ```yaml # WRONG - list comprehension fails in native mode servers: "[{% for s in configs %}{{ s.name }},{% endfor %}]" # CORRECT - use Ansible loop servers: "{{ servers | default([]) + [item.name] }}" loop: "{{ configs }}" ``` **Use tests (not filters) for boolean checks:** ```yaml # WRONG - filters return transformed data, not booleans that: my_ip | ansible.utils.ipv4 # CORRECT - tests return native booleans that: my_ip is ansible.utils.ipv4_address ``` ## DNS Architecture Algo uses a randomly generated IP in 172.16.0.0/12 on the loopback interface (`local_service_ip`) for DNS. This provides consistency across WireGuard and IPsec but requires understanding systemd socket activation. ### Why This Design - Consistent DNS IP across both VPN protocols - Survives interface changes and restarts - Works identically across all cloud providers - Trade-off: Requires `route_localnet=1` sysctl ### systemd Socket Activation Ubuntu's dnscrypt-proxy uses socket activation which **completely ignores** the `listen_addresses` config setting. You must configure the socket, not the service: ```ini # /etc/systemd/system/dnscrypt-proxy.socket.d/10-algo-override.conf [Socket] ListenStream= # Clear defaults first ListenDatagram= ListenStream=172.x.x.x:53 # Then set VPN IP ListenDatagram=172.x.x.x:53 ``` Common mistakes: - Trying to disable/mask the socket (breaks service dependency) - Only setting ListenStream (need ListenDatagram for UDP) - Forgetting to restart socket after config changes ### Debugging DNS Many "routing" issues are actually DNS issues. Start here: ```bash ss -lnup | grep :53 # Should show local_service_ip:53 systemctl status dnscrypt-proxy.socket # Check for config warnings sysctl net.ipv4.conf.all.route_localnet # Must be 1 dig @172.x.x.x google.com # Test resolution ``` For comprehensive diagnostics, see [docs/troubleshooting.md](docs/troubleshooting.md#diagnostic-commands). ## Common Issues ### iptables Backend (nft vs legacy) Ubuntu 22.04+ defaults to iptables-nft which reorders rules unpredictably. Algo forces iptables-legacy for consistent behavior. Switching backends can break DNS routing that previously worked. ### Multi-homed Systems (DigitalOcean, etc.) Servers with both public and private IPs on the same interface need explicit output interface for NAT: ```yaml -o {{ ansible_default_ipv4['interface'] }} ``` Don't overengineer with SNAT - MASQUERADE with interface specification works fine. ### OpenSSL Version Compatibility OpenSSL 3.x dropped support for legacy algorithms. Add `-legacy` flag conditionally: ```yaml {{ (openssl_version is version('3', '>=')) | ternary('-legacy', '') }} ``` ### IPv6 Endpoint Formatting WireGuard configs must bracket IPv6 addresses: ```jinja2 {% if ':' in IP %}[{{ IP }}]:{{ port }}{% else %}{{ IP }}:{{ port }}{% endif %} ``` ### Jinja2 Templates Many templates use Ansible-specific filters. Test with `tests/unit/test_template_rendering.py` and mock Ansible filters when testing. ## Time Wasters to Avoid Lessons learned - don't spend time on these unless absolutely necessary: 1. **Converting MASQUERADE to SNAT** - MASQUERADE works fine for Algo's use case 2. **Fighting systemd socket activation** - Configure it properly instead of disabling 3. **Debugging NAT before checking DNS** - Most "routing" issues are DNS issues 4. **Complex IPsec policy matching** - Keep NAT rules simple 5. **Testing on existing servers** - Always test on fresh deployments 6. **Interface-specific route_localnet** - WireGuard interface doesn't exist until service starts 7. **DNAT for loopback addresses** - Packets to local IPs don't traverse PREROUTING ## What to Avoid - **Speculative features** - Don't add "might be useful" functionality. Open an issue instead. - **New dependencies without justification** - Vanilla Ansible/Python can do most things. - **Bundling unrelated fixes** - One PR, one purpose. Separate issues get separate PRs. - **Assuming behavior** - If converting `with_items` to `loop`, test that it still works. If adding a firewall rule, verify packets flow. - **Configuration options** - Don't add flags unless users actively need them. Each option doubles testing surface. - **Undocumented workarounds** - When working around broken upstream modules, file an issue and add a comment linking to it. Future maintainers need to know why workarounds exist. ## Writing Effective Tests When writing tests, **verify your test actually detects the failure case** (mutation testing approach): 1. Write the test for the bug you're preventing 2. Temporarily introduce the bug to verify the test fails 3. Fix the bug and verify the test passes 4. Document what specific issue the test prevents ```python def test_regression_openssl_inline_comments(): """Tests that we detect inline comments in Jinja2 expressions.""" # This pattern SHOULD fail (has inline comments) problematic = "{{ ['DNS:' + id, # comment ] }}" assert not validate(problematic), "Should detect inline comments" # This pattern SHOULD pass (no inline comments) fixed = "{{ ['DNS:' + id] }}" assert validate(fixed), "Should pass without comments" ``` ## Quick Reference ### Local Development Setup ```bash uv sync uv run ansible-galaxy install -r requirements.yml ansible-playbook main.yml -e "provider=local" ``` ### Common Commands ```bash # Add/update users ansible-playbook users.yml -e "server=SERVER_NAME" # Update dependencies uv lock && pytest tests/unit/ -q # Debug deployment ansible-playbook main.yml -vvv ``` ### Key Directories - `configs/` - Generated client configurations - `roles/*/tasks/` - Main task files - `roles/*/templates/` - Jinja2 templates - `library/` - Custom Ansible modules (add to `mock_modules` in `.ansible-lint`) ## Non-Interactive Deployment All `pause:` prompts in `input.yml` and provider roles skip when their variable is pre-defined via `-e` or environment variables. This enables fully headless deployment for CI, agents, and scripted workflows. See [docs/deploy-from-ansible.md](docs/deploy-from-ansible.md) for full human-facing documentation. ### Core variables These bypass the main prompts in `input.yml`: | Variable | Type | Default | Purpose | |----------|------|---------|---------| | `provider` | string | *(prompt)* | Provider alias (e.g., `digitalocean`, `ec2`, `local`) | | `server_name` | string | `algo` | VPN server name | | `ondemand_cellular` | bool | `false` | iOS/macOS Connect On Demand for cellular | | `ondemand_wifi` | bool | `false` | iOS/macOS Connect On Demand for Wi-Fi | | `ondemand_wifi_exclude` | string | *(none)* | Comma-separated trusted Wi-Fi networks | | `store_pki` | bool | `false` | Retain PKI keys (needed to add users later) | | `dns_adblocking` | bool | `false` | Enable DNS ad blocking | | `ssh_tunneling` | bool | `false` | Per-user SSH tunnel accounts | ### Provider credentials | Provider | `-e` variables | Env var fallbacks | |----------|---------------|-------------------| | `digitalocean` | `do_token`, `region` | `DO_API_TOKEN` | | `ec2` | `aws_access_key`, `aws_secret_key`, `region` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (also reads `~/.aws/credentials`) | | `lightsail` | `aws_access_key`, `aws_secret_key`, `region` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` | | `azure` | `azure_secret`, `azure_tenant`, `azure_client_id`, `azure_subscription_id`, `region` | `AZURE_SECRET`, `AZURE_TENANT`, `AZURE_CLIENT_ID`, `AZURE_SUBSCRIPTION_ID` | | `gce` | `gce_credentials_file`, `region` | `GCE_CREDENTIALS_FILE_PATH` | | `hetzner` | `hcloud_token`, `region` | `HCLOUD_TOKEN` | | `vultr` | `vultr_config`, `region` | `VULTR_API_CONFIG` | | `scaleway` | `scaleway_token`, `scaleway_org_id`, `region` | `SCW_TOKEN`, `SCW_DEFAULT_ORGANIZATION_ID` | | `linode` | `linode_token`, `region` | `LINODE_API_TOKEN` | | `cloudstack` | `cs_key`, `cs_secret`, `cs_url`, `region` | `CLOUDSTACK_KEY`, `CLOUDSTACK_SECRET`, `CLOUDSTACK_ENDPOINT` | | `openstack` | `region` | `OS_AUTH_URL` (source your `openrc.sh`) | | `local` | `server`, `endpoint`, `local_install_confirmed` | *(none)* | ### Minimal examples ```bash # DigitalOcean — fully headless ansible-playbook main.yml -e \ "provider=digitalocean server_name=algo region=nyc3 do_token=YOUR_TOKEN ondemand_cellular=false ondemand_wifi=false dns_adblocking=false ssh_tunneling=false store_pki=false" # Local — for CI/testing ansible-playbook main.yml -e \ "provider=local server=localhost endpoint=10.0.0.1 local_install_confirmed=true ondemand_cellular=false ondemand_wifi=false dns_adblocking=false ssh_tunneling=false" ``` ### Updating users non-interactively ```bash ansible-playbook users.yml -e "server=YOUR_SERVER ca_password=YOUR_CA_PASS" ``` The `server` variable bypasses the server selection prompt. `ca_password` is only required when IPsec is enabled. ## Security Considerations - **Never expose secrets** - No passwords/keys in commits - **CVE Response** - Update immediately when security issues found - **Least Privilege** - Minimal permissions, dropped capabilities - **Secure Defaults** - Strong crypto (secp384r1), no logging, strict firewall ## Platform Support - **Primary OS**: Ubuntu 22.04/24.04 LTS - **Secondary**: Debian 11/12 - **Architectures**: x86_64 and ARM64 - **Testing tip**: DigitalOcean droplets have both public and private IPs on eth0, making them good test cases for multi-IP NAT scenarios ================================================ FILE: CODEOWNERS ================================================ * @jackivanov ================================================ FILE: CONTRIBUTING.md ================================================ ### Filing New Issues * We welcome bug reports! Before filing, a quick check of the [FAQ](docs/faq.md) or [troubleshooting](docs/troubleshooting.md) docs might have your answer * Algo automatically installs dependencies with uv - no manual setup required * We support modern clients: macOS 12+, iOS 15+, Windows 11+, Ubuntu 22.04+, etc. * Supported cloud providers: DigitalOcean, AWS, Azure, GCP, Vultr, Hetzner, Linode, OpenStack, CloudStack * If you need to file a new issue, fill out any relevant fields in the Issue Template ### Pull Requests * Run the full linter suite: `./scripts/lint.sh` * Test your changes on multiple platforms when possible * Use conventional commit messages that clearly describe your changes * Pin dependency versions rather than using ranges (e.g., `==1.2.3` not `>=1.2.0`) ### Development Setup * Clone the repository: `git clone https://github.com/trailofbits/algo.git` * Run Algo: `./algo` (dependencies installed automatically via uv) * Install git hooks: `prek install` (optional, for contributors) * For local testing, consider using Docker or a cloud provider test instance Thanks! ================================================ FILE: Dockerfile ================================================ # syntax=docker/dockerfile:1 FROM python:3.12-alpine ARG VERSION="git" # Removed rust/cargo (not needed with uv), simplified package list ARG PACKAGES="bash openssh-client openssl rsync tini" LABEL name="algo" \ version="${VERSION}" \ description="Set up a personal IPsec VPN in the cloud" \ maintainer="Trail of Bits " \ org.opencontainers.image.source="https://github.com/trailofbits/algo" \ org.opencontainers.image.description="Algo VPN - Set up a personal IPsec VPN in the cloud" \ org.opencontainers.image.licenses="AGPL-3.0" # Install system packages in a single layer RUN apk --no-cache add ${PACKAGES} && \ adduser -D -H -u 19857 algo && \ mkdir -p /algo /algo/configs WORKDIR /algo # Copy uv binary from official image (using latest tag for automatic updates) COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv # Copy dependency files and install in single layer for better optimization COPY pyproject.toml uv.lock ./ RUN uv sync --locked --no-dev # Copy application code COPY . . # Install Ansible Galaxy collections for cloud provider modules RUN uv run ansible-galaxy collection install -r requirements.yml # Set executable permissions and prepare runtime # Note: /algo must remain root-owned for --cap-drop=all compatibility # (root without CAP_DAC_OVERRIDE cannot write to files owned by others) RUN chmod 0755 /algo/algo-docker.sh && \ mkdir -p /data && \ chown algo:algo /data # Multi-arch support metadata ARG TARGETPLATFORM ARG BUILDPLATFORM RUN printf "Built on: %s\nTarget: %s\n" "${BUILDPLATFORM}" "${TARGETPLATFORM}" > /algo/build-info # Note: Running as root for bind mount compatibility with algo-docker.sh # The script handles /data volume permissions and needs root access # This is a Docker limitation with bind-mounted volumes USER root # Health check to ensure container is functional HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD /bin/uv --version || exit 1 VOLUME ["/data"] CMD [ "/algo/algo-docker.sh" ] ENTRYPOINT [ "/sbin/tini", "--" ] ================================================ FILE: LICENSE ================================================ GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . ================================================ FILE: PULL_REQUEST_TEMPLATE.md ================================================ ## Description ## Motivation and Context ## How Has This Been Tested? ## Types of changes - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist: - [ ] I have read the **CONTRIBUTING** document. - [ ] My code passes all linters (`./scripts/lint.sh`) - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. - [ ] Dependencies use exact versions (e.g., `==1.2.3` not `>=1.2.0`). ================================================ FILE: README.md ================================================ # Algo VPN [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20%40AlgoVPN)](https://x.com/AlgoVPN) Algo VPN is a set of Ansible scripts that simplify the setup of a personal WireGuard and IPsec VPN. It uses the most secure defaults available and works with common cloud providers. See our [release announcement](https://blog.trailofbits.com/2016/12/12/meet-algo-the-vpn-that-works/) for more information. ## Features * Supports only IKEv2 with strong crypto (AES-GCM, SHA2, and P-256) for iOS, MacOS, and Linux * Supports [WireGuard](https://www.wireguard.com/) for all of the above, in addition to Android and Windows 11 * Generates .conf files and QR codes for iOS, macOS, Android, and Windows WireGuard clients * Generates Apple profiles to auto-configure iOS and macOS devices for IPsec - no client software required * Includes helper scripts to add, remove, and manage users * Blocks ads with a local DNS resolver (optional) * Sets up limited SSH users for tunneling traffic (optional) * Privacy-focused with minimal logging, automatic log rotation, and configurable privacy enhancements * Based on Ubuntu 22.04 LTS with automatic security updates * Installs to DigitalOcean, Amazon Lightsail, Amazon EC2, Vultr, Microsoft Azure, Google Compute Engine, Scaleway, OpenStack, CloudStack, Hetzner Cloud, Linode, or [your own Ubuntu server (for advanced users)](docs/deploy-to-ubuntu.md) ## Anti-features * Does not support legacy cipher suites or protocols like L2TP, IKEv1, or RSA * Does not install Tor, OpenVPN, or other risky servers * Does not depend on the security of [TLS](https://tools.ietf.org/html/rfc7457) * Does not claim to provide anonymity or censorship avoidance * Does not claim to protect you from the [FSB](https://en.wikipedia.org/wiki/Federal_Security_Service), [MSS](https://en.wikipedia.org/wiki/Ministry_of_State_Security_(China)), [DGSE](https://en.wikipedia.org/wiki/Directorate-General_for_External_Security), or [FSM](https://en.wikipedia.org/wiki/Flying_Spaghetti_Monster) ## Deploy the Algo Server The easiest way to get an Algo server running is to run it on your local system or from [Google Cloud Shell](docs/deploy-from-cloudshell.md) and let it set up a _new_ virtual machine in the cloud for you. 1. **Setup an account on a cloud hosting provider.** Algo supports [DigitalOcean](https://m.do.co/c/4d7f4ff9cfe4) (most user friendly), [Amazon Lightsail](https://aws.amazon.com/lightsail/), [Amazon EC2](https://aws.amazon.com/), [Vultr](https://www.vultr.com/), [Microsoft Azure](https://azure.microsoft.com/), [Google Compute Engine](https://cloud.google.com/compute/), [Scaleway](https://www.scaleway.com/), [DreamCompute](https://www.dreamhost.com/cloud/computing/), [Linode](https://www.linode.com), other OpenStack-based cloud hosting, CloudStack-based cloud hosting, or [Hetzner Cloud](https://www.hetzner.com/). 2. **Get a copy of Algo.** The Algo scripts will be run from your local system. There are two ways to get a copy: - Download the [ZIP file](https://github.com/trailofbits/algo/archive/master.zip). Unzip the file to create a directory named `algo-master` containing the Algo scripts. - Use `git clone` to create a directory named `algo` containing the Algo scripts: ```bash git clone https://github.com/trailofbits/algo.git ``` 3. **Set your configuration options.** Open `config.cfg` in your favorite text editor. Specify the users you want to create in the `users` list. Create a unique user for each device you plan to connect to your VPN. You should also review the other options before deployment, as changing your mind about them later [may require you to deploy a brand new server](https://github.com/trailofbits/algo/blob/master/docs/faq.md#i-deployed-an-algo-server-can-you-update-it-with-new-features). 4. **Start the deployment.** Return to your terminal. In the Algo directory, run the appropriate script for your platform: **macOS/Linux:** ```bash ./algo ``` **Windows:** ```powershell .\algo.ps1 ``` The first time you run the script, it will automatically install the required Python environment (Python 3.11+). On subsequent runs, it starts immediately and works on all platforms (macOS, Linux, Windows via WSL). The Windows PowerShell script automatically uses WSL when needed, since Ansible requires a Unix-like environment. There are several optional features available, none of which are required for a fully functional VPN server. These optional features are described in the [deployment documentation](docs/deploy-from-ansible.md). That's it! You can now set up clients to connect to your VPN. Proceed to [Configure the VPN Clients](#configure-the-vpn-clients) below. ``` "# Congratulations! #" "# Your Algo server is running. #" "# Config files and certificates are in the ./configs/ directory. #" "# Go to https://whoer.net/ after connecting #" "# and ensure that all your traffic passes through the VPN. #" "# Local DNS resolver 172.16.0.1 #" "# The p12 and SSH keys password for new users is XXXXXXXX #" "# The CA key password is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #" "# Shell access: ssh -F configs//ssh_config #" ``` ## Configure the VPN Clients Certificates and configuration files that users will need are placed in the `configs` directory. Make sure to secure these files since many contain private keys. All files are saved under a subdirectory named with the IP address of your new Algo VPN server. **Important for IPsec users**: If you want to add or delete users later, you must select `yes` at the `Do you want to retain the keys (PKI)?` prompt during the server deployment. This preserves the certificate authority needed for user management. ### Apple WireGuard is used to provide VPN services on Apple devices. Algo generates a WireGuard configuration file, `wireguard/.conf`, and a QR code, `wireguard/.png`, for each user defined in `config.cfg`. On iOS, install the [WireGuard](https://itunes.apple.com/us/app/wireguard/id1441195209?mt=8) app from the iOS App Store. Then, use the WireGuard app to scan the QR code or AirDrop the configuration file to the device. On macOS, install the [WireGuard](https://itunes.apple.com/us/app/wireguard/id1451685025?mt=12) app from the Mac App Store. WireGuard will appear in the menu bar once you run the app. Click on the WireGuard icon, choose **Import tunnel(s) from file...**, then select the appropriate WireGuard configuration file. On either iOS or macOS, you can enable "Connect on Demand" and/or exclude certain trusted Wi-Fi networks (such as your home or work) by editing the tunnel configuration in the WireGuard app. (Algo can't do this automatically for you.) If you prefer to use the built-in IPsec VPN on Apple devices, or need "Connect on Demand" or excluded Wi-Fi networks automatically configured, see the [Apple IPsec client setup guide](docs/client-apple-ipsec.md) for detailed configuration instructions. ### Android WireGuard is used to provide VPN services on Android. Install the [WireGuard VPN Client](https://play.google.com/store/apps/details?id=com.wireguard.android). Import the corresponding `wireguard/.conf` file to your device, then set up a new connection with it. See the [Android setup guide](docs/client-android.md) for detailed installation and configuration instructions. ### Windows WireGuard is used to provide VPN services on Windows. Algo generates a WireGuard configuration file, `wireguard/.conf`, for each user defined in `config.cfg`. Install the [WireGuard VPN Client](https://www.wireguard.com/install/#windows-7-8-81-10-2012-2016-2019). Import the generated `wireguard/.conf` file to your device, then set up a new connection with it. See the [Windows setup instructions](docs/client-windows.md) for more detailed walkthrough and troubleshooting. ### Linux Linux clients can use either WireGuard or IPsec: WireGuard: WireGuard works great with Linux clients. See the [Linux WireGuard setup guide](docs/client-linux-wireguard.md) for step-by-step instructions on configuring WireGuard on Ubuntu and other distributions. IPsec: For strongSwan IPsec clients (including OpenWrt, Ubuntu Server, and other distributions), see the [Linux IPsec setup guide](docs/client-linux-ipsec.md) for detailed configuration instructions. ### OpenWrt For OpenWrt routers using WireGuard, see the [OpenWrt WireGuard setup guide](docs/client-openwrt-router-wireguard.md) for router-specific configuration instructions. ### Other Devices For devices not covered above or manual configuration, you'll need specific certificate and configuration files. The files you need depend on your device platform and VPN protocol (WireGuard or IPsec). * ipsec/manual/cacert.pem: CA Certificate * ipsec/manual/.p12: User Certificate and Private Key (in PKCS#12 format) * ipsec/manual/.conf: strongSwan client configuration * ipsec/manual/.secrets: strongSwan client configuration * ipsec/apple/.mobileconfig: Apple Profile * wireguard/.conf: WireGuard configuration profile * wireguard/.png: WireGuard configuration QR code ## Setup an SSH Tunnel If you turned on the optional SSH tunneling role, local user accounts will be created for each user in `config.cfg`, and SSH authorized_key files for them will be in the `configs` directory (user.pem). SSH user accounts do not have shell access, cannot authenticate with a password, and only have limited tunneling options (e.g., `ssh -N` is required). This ensures that SSH users have the least access required to set up a tunnel and can perform no other actions on the Algo server. Use the example command below to start an SSH tunnel by replacing `` and `` with your own. Once the tunnel is set up, you can configure a browser or other application to use 127.0.0.1:1080 as a SOCKS proxy to route traffic through the Algo server: ```bash ssh -D 127.0.0.1:1080 -f -q -C -N @algo -i configs//ssh-tunnel/.pem -F configs//ssh_config ``` ## SSH into Algo Server Your Algo server is configured for key-only SSH access for administrative purposes. Open the Terminal app, `cd` into the `algo-master` directory where you originally downloaded Algo, and then use the command listed on the success message: ``` ssh -F configs//ssh_config ``` where `` is the IP address of your Algo server. If you find yourself regularly logging into the server, it will be useful to load your Algo SSH key automatically. Add the following snippet to the bottom of `~/.bash_profile` to add it to your shell environment permanently: ``` ssh-add ~/.ssh/algo > /dev/null 2>&1 ``` Alternatively, you can choose to include the generated configuration for any Algo servers created into your SSH config. Edit the file `~/.ssh/config` to include this directive at the top: ``` Include /configs/*/ssh_config ``` where `` is the directory where you cloned Algo. ## Adding or Removing Users Algo makes it easy to add or remove users from your VPN server after initial deployment. For IPsec users: You must have selected `yes` at the `Do you want to retain the keys (PKI)?` prompt during the initial server deployment. This preserves the certificate authority needed for user management. You should also save the p12 and CA key passwords shown during deployment, as they're only displayed once. To add or remove users, first edit the `users` list in your `config.cfg` file. Add new usernames or remove existing ones as needed. Then navigate to the algo directory in your terminal and run: **macOS/Linux:** ```bash ./algo update-users ``` **Windows:** ```powershell .\algo.ps1 update-users ``` After the process completes, new configuration files will be generated in the `configs` directory for any new users. The Algo VPN server will be updated to contain only the users listed in the `config.cfg` file. Removed users will no longer be able to connect, and new users will have fresh certificates and configuration files ready for use. ## Privacy and Logging Algo takes a pragmatic approach to privacy. By default, we minimize logging while maintaining enough information for security and troubleshooting. What IS logged by default: * System security events (failed SSH attempts, firewall blocks, system updates) * Kernel messages and boot diagnostics (with reduced verbosity) * WireGuard client state (visible via `sudo wg` - shows last endpoint and handshake time) * Basic service status (service starts/stops/errors) * All logs automatically rotate and delete after 7 days Privacy is controlled by two main settings in `config.cfg`: * `strongswan_log_level: -1` - Controls StrongSwan connection logging (-1 = disabled, 2 = debug) * `privacy_enhancements_enabled: true` - Master switch for log rotation, history clearing, log filtering, and cleanup To enable full debugging when troubleshooting, set both `strongswan_log_level: 2` and `privacy_enhancements_enabled: false`. This will capture detailed connection logs and disable all privacy features. Remember to revert these changes after debugging. After deployment, verify your privacy settings: ```bash ssh -F configs//ssh_config sudo /usr/local/bin/privacy-monitor.sh ``` Perfect privacy is impossible with any VPN solution. Your cloud provider sees and logs network traffic metadata regardless of your server configuration. And of course, your ISP knows you're connecting to a VPN server, even if they can't see what you're doing through it. For the highest level of privacy, treat your Algo servers as disposable. Spin up a new instance when you need it, use it for your specific purpose, then destroy it completely. The ephemeral nature of cloud infrastructure can be a privacy feature if you use it intentionally. ## Additional Documentation * [FAQ](docs/faq.md) * [Troubleshooting](docs/troubleshooting.md) * How Algo uses [Firewalls](docs/firewalls.md) ### Setup Instructions for Specific Cloud Providers * Configure [Amazon EC2](docs/cloud-amazon-ec2.md) * Configure [Azure](docs/cloud-azure.md) * Configure [DigitalOcean](docs/cloud-do.md) * Configure [Google Cloud Platform](docs/cloud-gce.md) * Configure [Vultr](docs/cloud-vultr.md) * Configure [CloudStack](docs/cloud-cloudstack.md) * Configure [Hetzner Cloud](docs/cloud-hetzner.md) ### Install and Deploy from Common Platforms * Deploy from [macOS](docs/deploy-from-macos.md) * Deploy from [Windows](docs/deploy-from-windows.md) * Deploy from [Google Cloud Shell](docs/deploy-from-cloudshell.md) * Deploy from a [Docker container](docs/deploy-from-docker.md) ### Setup VPN Clients to Connect to the Server * Setup [Windows](docs/client-windows.md) clients * Setup [Android](docs/client-android.md) clients * Setup [Linux](docs/client-linux.md) clients with Ansible * Setup Ubuntu clients to use [WireGuard](docs/client-linux-wireguard.md) * Setup Linux clients to use [IPsec](docs/client-linux-ipsec.md) * Setup Apple devices to use [IPsec](docs/client-apple-ipsec.md) * Setup Macs running macOS 10.13 or older to use [WireGuard](docs/client-macos-wireguard.md) ### Advanced Deployment * Deploy to your own [Ubuntu](docs/deploy-to-ubuntu.md) server, and road warrior setup * Deploy from [Ansible](docs/deploy-from-ansible.md) non-interactively * Deploy onto a [cloud server at time of creation with shell script or cloud-init](docs/deploy-from-script-or-cloud-init-to-localhost.md) * Deploy to an [unsupported cloud provider](docs/deploy-to-unsupported-cloud.md) If you've read all the documentation and have further questions, [create a new discussion](https://github.com/trailofbits/algo/discussions). ## Endorsements > I've been ranting about the sorry state of VPN svcs for so long, probably about > time to give a proper talk on the subject. TL;DR: use Algo. -- [Kenn White](https://twitter.com/kennwhite/status/814166603587788800) > Before picking a VPN provider/app, make sure you do some research > https://research.csiro.au/ng/wp-content/uploads/sites/106/2016/08/paper-1.pdf ... – or consider Algo -- [The Register](https://twitter.com/TheRegister/status/825076303657177088) > Algo is really easy and secure. -- [the grugq](https://twitter.com/thegrugq/status/786249040228786176) > I played around with Algo VPN, a set of scripts that let you set up a VPN in the cloud in very little time, even if you don’t know much about development. I’ve got to say that I was quite impressed with Trail of Bits’ approach. -- [Romain Dillet](https://twitter.com/romaindillet/status/851037243728965632) for [TechCrunch](https://techcrunch.com/2017/04/09/how-i-made-my-own-vpn-server-in-15-minutes/) > If you’re uncomfortable shelling out the cash to an anonymous, random VPN provider, this is the best solution. -- [Thorin Klosowski](https://twitter.com/kingthor) for [Lifehacker](http://lifehacker.com/how-to-set-up-your-own-completely-free-vpn-in-the-cloud-1794302432) ## Contributing See our [Development Guide](docs/DEVELOPMENT.md) for information on: * Setting up your development environment * Using prek hooks for code quality * Running tests and linters * Contributing code via pull requests ## Support Algo VPN [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E) [![Patreon](https://img.shields.io/badge/back_on-patreon-red.svg)](https://www.patreon.com/algovpn) All donations support continued development. Thanks! * We accept donations via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E) and [Patreon](https://www.patreon.com/algovpn). * Use our [referral code](https://m.do.co/c/4d7f4ff9cfe4) when you sign up to Digital Ocean for a $10 credit. * We also accept and appreciate contributions of new code and bugfixes via Github Pull Requests. Algo is licensed and distributed under the AGPLv3. If you want to distribute a closed-source modification or service based on Algo, then please consider purchasing an exception . As with the methods above, this will help support continued development. ================================================ FILE: SECURITY.md ================================================ # Reporting Security Issues The Algo team and community take security bugs in Algo seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/trailofbits/algo/security/) tab. The Algo team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. Report security bugs in third-party modules to the person or team maintaining the module. ================================================ FILE: algo ================================================ #!/usr/bin/env bash set -e # Track which installation method succeeded UV_INSTALL_METHOD="" # Function to install uv via package managers (most secure) install_uv_via_package_manager() { echo "Attempting to install uv via system package manager..." if command -v brew &> /dev/null; then echo "Using Homebrew..." brew install uv && UV_INSTALL_METHOD="Homebrew" && return 0 elif command -v apt &> /dev/null && apt list uv 2>/dev/null | grep -q uv; then echo "Using apt..." sudo apt update && sudo apt install -y uv && UV_INSTALL_METHOD="apt" && return 0 elif command -v dnf &> /dev/null; then echo "Using dnf..." sudo dnf install -y uv 2>/dev/null && UV_INSTALL_METHOD="dnf" && return 0 elif command -v pacman &> /dev/null; then echo "Using pacman..." sudo pacman -S --noconfirm uv 2>/dev/null && UV_INSTALL_METHOD="pacman" && return 0 elif command -v zypper &> /dev/null; then echo "Using zypper..." sudo zypper install -y uv 2>/dev/null && UV_INSTALL_METHOD="zypper" && return 0 elif command -v winget &> /dev/null; then echo "Using winget..." winget install --id=astral-sh.uv -e && UV_INSTALL_METHOD="winget" && return 0 elif command -v scoop &> /dev/null; then echo "Using scoop..." scoop install uv && UV_INSTALL_METHOD="scoop" && return 0 fi return 1 } # Function to handle Ubuntu-specific installation alternatives install_uv_ubuntu_alternatives() { # Check if we're on Ubuntu if ! command -v lsb_release &> /dev/null || [[ "$(lsb_release -si)" != "Ubuntu" ]]; then return 1 # Not Ubuntu, skip these options fi echo "" echo "Ubuntu detected. Additional trusted installation options available:" echo "" echo "1. pipx (official PyPI, installs ~9 packages)" echo " Command: sudo apt install pipx && pipx install uv" echo "" echo "2. snap (community-maintained by Canonical employee)" echo " Command: sudo snap install astral-uv --classic" echo " Source: https://github.com/lengau/uv-snap" echo "" echo "3. Continue to official installer script download" echo "" while true; do read -r -p "Choose installation method (1/2/3): " choice case $choice in 1) echo "Installing uv via pipx..." if sudo apt update && sudo apt install -y pipx; then if pipx install uv; then # Add pipx bin directory to PATH export PATH="$HOME/.local/bin:$PATH" UV_INSTALL_METHOD="pipx" return 0 fi fi echo "pipx installation failed, trying next option..." ;; 2) echo "Installing uv via snap..." if sudo snap install astral-uv --classic; then # Snap binaries should be automatically in PATH via /snap/bin UV_INSTALL_METHOD="snap" return 0 fi echo "snap installation failed, trying next option..." ;; 3) return 1 # Continue to official installer download ;; *) echo "Invalid option. Please choose 1, 2, or 3." ;; esac done } # Function to install uv via download (with user consent) install_uv_via_download() { echo "" echo "⚠️ SECURITY NOTICE ⚠️" echo "uv is not available via system package managers on this system." echo "To continue, we need to download and execute an installation script from:" echo " https://astral.sh/uv/install.sh (Linux/macOS)" echo " https://astral.sh/uv/install.ps1 (Windows)" echo "" echo "For maximum security, you can install uv manually instead:" echo " 1. Visit: https://docs.astral.sh/uv/getting-started/installation/" echo " 2. Download the binary for your platform from GitHub releases" echo " 3. Verify checksums and install manually" echo " 4. Then run: ./algo" echo "" read -p "Continue with script download? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Installation cancelled. Please install uv manually and retry." exit 1 fi echo "Downloading uv installation script..." if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "linux-gnu" && -n "${WSL_DISTRO_NAME:-}" ]] || uname -s | grep -q "MINGW\|MSYS"; then # Windows (Git Bash/WSL/MINGW) - use versioned installer powershell -ExecutionPolicy ByPass -c "irm https://github.com/astral-sh/uv/releases/download/0.8.5/uv-installer.ps1 | iex" UV_INSTALL_METHOD="official installer (Windows)" else # macOS/Linux - use the versioned script for consistency curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.8.5/uv-installer.sh | sh UV_INSTALL_METHOD="official installer" fi } # Check if uv is installed, if not, install it securely if ! command -v uv &> /dev/null; then echo "uv (Python package manager) not found. Installing..." # Try package managers first (most secure) if ! install_uv_via_package_manager; then # Try Ubuntu-specific alternatives if available if ! install_uv_ubuntu_alternatives; then # Fall back to download with user consent install_uv_via_download fi fi # Reload PATH to find uv (includes pipx, cargo, and snap paths) # Note: This PATH change only affects the current shell session. # Users may need to restart their terminal for subsequent runs. export PATH="$HOME/.local/bin:$HOME/.cargo/bin:/snap/bin:$PATH" # Verify installation worked if ! command -v uv &> /dev/null; then echo "Error: uv installation failed. Please restart your terminal and try again." echo "Or install manually from: https://docs.astral.sh/uv/getting-started/installation/" exit 1 fi echo "✓ uv installed successfully via ${UV_INSTALL_METHOD}!" fi # Install Ansible Galaxy collections if requirements.yml exists # This is needed for cloud providers that use collection modules (Linode, DigitalOcean, Azure, etc.) if [ -f "requirements.yml" ]; then uv run ansible-galaxy collection install -r requirements.yml > /dev/null 2>&1 || true fi # Run the appropriate playbook case "$1" in help|-h|--help) echo "Usage: ./algo [COMMAND] [ANSIBLE_OPTIONS]" echo "" echo "Set up a personal VPN in the cloud." echo "" echo "Commands:" echo " (default) Deploy a new VPN server" echo " update-users Add or remove users on an existing server" echo " destroy Destroy a deployed server and clean up configs" echo " list-servers List deployed servers (JSON output)" echo "" echo "Configuration:" echo " Edit config.cfg to set users, DNS, and VPN options before deploying." echo "" echo "Non-interactive deployment:" echo " ./algo -e 'provider=digitalocean server_name=algo region=nyc3 do_token=TOKEN'" echo "" echo "Common Ansible options (passed through):" echo " -e KEY=VALUE Set variable (bypass interactive prompts)" echo " -v, -vvv Increase output verbosity" echo " --skip-tags TAG Skip specific components" echo " -t, --tags TAG Run only specific components" echo "" echo "Docs: https://trailofbits.github.io/algo/" exit 0 ;; update-users) uv run ansible-playbook users.yml "${@:2}" -t update-users ;; destroy) if [ -z "${2:-}" ] || [[ "$2" == -* ]]; then echo "Usage: ./algo destroy [ANSIBLE_OPTIONS]" echo "" echo "Destroy a deployed Algo VPN server and remove local configs." echo "" echo "Arguments:" echo " server-ip IP address of the server to destroy" echo "" echo "Examples:" echo " ./algo destroy 188.166.66.185" echo " ./algo destroy 52.1.2.3 -e \"region=us-east-1\"" echo " ./algo destroy 188.166.66.185 -e \"confirm_destroy=true\"" exit 1 fi uv run ansible-playbook destroy.yml -e "server_ip=$2" "${@:3}" ;; list-servers) uv run python3 scripts/list_servers.py "${@:2}" ;; *) uv run ansible-playbook main.yml "${@}" ;; esac ================================================ FILE: algo-docker.sh ================================================ #!/usr/bin/env bash set -eEo pipefail ALGO_DIR="/algo" DATA_DIR="/data" umask 0077 usage() { retcode="${1:-0}" echo "To run algo from Docker:" echo "" echo "docker run --cap-drop=all -it -v :${DATA_DIR} ghcr.io/trailofbits/algo:latest" echo "" exit "${retcode}" } if [ ! -f "${DATA_DIR}"/config.cfg ] ; then echo "Looks like you're not bind-mounting your config.cfg into this container." echo "algo needs a configuration file to run." echo "" usage -1 fi if [ ! -e /dev/console ] ; then echo "Looks like you're trying to run this container without a TTY." echo "If you don't pass -t, you can't interact with the algo script." echo "" usage -1 fi # To work around problems with bind-mounting Windows volumes, we need to # copy files out of ${DATA_DIR}, ensure appropriate line endings and permissions, # then copy the algo-generated files into ${DATA_DIR}. tr -d '\r' < "${DATA_DIR}"/config.cfg > "${ALGO_DIR}"/config.cfg test -d "${DATA_DIR}"/configs && rsync -qLktr --delete "${DATA_DIR}"/configs "${ALGO_DIR}"/ "${ALGO_DIR}"/algo "${ALGO_ARGS[@]}" retcode=${?} rsync -qLktr --delete "${ALGO_DIR}"/configs "${DATA_DIR}"/ exit "${retcode}" ================================================ FILE: algo-showenv.sh ================================================ #!/usr/bin/env bash # # Print information about Algo's invocation environment to aid in debugging. # This is normally called from Ansible right before a deployment gets underway. # Skip printing this header if we're just testing with no arguments. if [[ $# -gt 0 ]]; then echo "" echo "--> Please include the following block of text when reporting issues:" echo "" fi if [[ ! -f ./algo ]]; then echo "This should be run from the top level Algo directory" fi # Determine the operating system. case "$(uname -s)" in Linux) OS="Linux ($(uname -r) $(uname -v))" if [[ -f /etc/os-release ]]; then # shellcheck disable=SC1091 # I hope this isn't dangerous. . /etc/os-release if [[ ${PRETTY_NAME} ]]; then OS="${PRETTY_NAME}" elif [[ ${NAME} ]]; then OS="${NAME} ${VERSION}" fi fi STAT="stat -c %y" ;; Darwin) OS="$(sw_vers -productName) $(sw_vers -productVersion)" STAT="stat -f %Sm" ;; *) OS="Unknown" ;; esac # Determine if virtualization is being used with Linux. VIRTUALIZED="" if [[ -x $(command -v systemd-detect-virt) ]]; then DETECT_VIRT="$(systemd-detect-virt)" if [[ ${DETECT_VIRT} != "none" ]]; then VIRTUALIZED=" (Virtualized: ${DETECT_VIRT})" fi elif [[ -f /.dockerenv ]]; then VIRTUALIZED=" (Virtualized: docker)" fi echo "Algo running on: ${OS}${VIRTUALIZED}" # Determine the currentness of the Algo software. if [[ -d .git && -x $(command -v git) ]]; then ORIGIN="$(git remote get-url origin)" COMMIT="$(git log --max-count=1 --oneline --no-decorate --no-color)" if [[ ${ORIGIN} == "https://github.com/trailofbits/algo.git" ]]; then SOURCE="clone" else SOURCE="fork" fi echo "Created from git ${SOURCE}. Last commit: ${COMMIT}" elif [[ -f LICENSE && ${STAT} ]]; then CREATED="$(${STAT} LICENSE)" echo "ZIP file created: ${CREATED}" fi # The Python version might be useful to know. if [[ -x $(command -v uv) ]]; then echo "uv Python environment:" uv run python --version 2>&1 uv --version 2>&1 elif [[ -f ./algo ]]; then echo "uv not found: try running './algo' to install dependencies" fi # Just print out all command line arguments, which are expected # to be Ansible variables. if [[ $# -gt 0 ]]; then echo "Runtime variables:" for VALUE in "$@"; do echo " ${VALUE}" done fi exit 0 ================================================ FILE: algo.ps1 ================================================ # PowerShell script for Windows users to run Algo VPN param( [Parameter(ValueFromRemainingArguments)] [string[]]$Arguments ) # Check if we're actually running inside WSL (not just if WSL is available) function Test-RunningInWSL { # These environment variables are only set when running inside WSL return $env:WSL_DISTRO_NAME -or $env:WSLENV } # Function to run Algo in WSL function Invoke-AlgoInWSL { param($Arguments) Write-Host "NOTICE: Ansible requires a Unix-like environment and cannot run natively on Windows." Write-Host "Attempting to run Algo via Windows Subsystem for Linux (WSL)..." Write-Host "" if (-not (Get-Command wsl -ErrorAction SilentlyContinue)) { Write-Host "ERROR: WSL (Windows Subsystem for Linux) is not installed." -ForegroundColor Red Write-Host "" Write-Host "Algo requires WSL to run Ansible on Windows. To install WSL:" -ForegroundColor Yellow Write-Host "" Write-Host " Step 1: Open PowerShell as Administrator and run:" Write-Host " wsl --install -d Ubuntu-22.04" -ForegroundColor Cyan Write-Host " (Note: 22.04 LTS recommended for WSL stability)" -ForegroundColor Gray Write-Host "" Write-Host " Step 2: Restart your computer when prompted" Write-Host "" Write-Host " Step 3: After restart, open Ubuntu from the Start menu" Write-Host " and complete the initial setup (create username/password)" Write-Host "" Write-Host " Step 4: Run this script again: .\algo.ps1" Write-Host "" Write-Host "For detailed instructions, see:" -ForegroundColor Yellow Write-Host "https://github.com/trailofbits/algo/blob/master/docs/deploy-from-windows.md" exit 1 } # Check if any WSL distributions are installed and running Write-Host "Checking for WSL Linux distributions..." $wslList = wsl -l -v 2>$null if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: WSL is installed but no Linux distributions are available." -ForegroundColor Red Write-Host "" Write-Host "You need to install Ubuntu. Run this command as Administrator:" -ForegroundColor Yellow Write-Host " wsl --install -d Ubuntu-22.04" -ForegroundColor Cyan Write-Host " (Note: 22.04 LTS recommended for WSL stability)" -ForegroundColor Gray Write-Host "" Write-Host "Then restart your computer and try again." exit 1 } Write-Host "Successfully found WSL. Launching Algo..." -ForegroundColor Green Write-Host "" # Get current directory name for WSL path mapping $currentDir = Split-Path -Leaf (Get-Location) try { if ($Arguments.Count -gt 0 -and $Arguments[0] -eq "update-users") { $remainingArgs = $Arguments[1..($Arguments.Count-1)] -join " " wsl bash -c "cd /mnt/c/$currentDir 2>/dev/null || (echo 'Error: Cannot access directory in WSL. Make sure you are running from a Windows drive (C:, D:, etc.)' && exit 1) && ./algo update-users $remainingArgs" } else { $allArgs = $Arguments -join " " wsl bash -c "cd /mnt/c/$currentDir 2>/dev/null || (echo 'Error: Cannot access directory in WSL. Make sure you are running from a Windows drive (C:, D:, etc.)' && exit 1) && ./algo $allArgs" } if ($LASTEXITCODE -ne 0) { Write-Host "" Write-Host "Algo finished with exit code: $LASTEXITCODE" -ForegroundColor Yellow if ($LASTEXITCODE -eq 1) { Write-Host "This may indicate a configuration issue or user cancellation." } } } catch { Write-Host "" Write-Host "ERROR: Failed to run Algo in WSL." -ForegroundColor Red Write-Host "Error details: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "Troubleshooting:" -ForegroundColor Yellow Write-Host "1. Make sure you're running from a Windows drive (C:, D:, etc.)" Write-Host "2. Try opening Ubuntu directly and running: cd /mnt/c/$currentDir && ./algo" Write-Host "3. See: https://github.com/trailofbits/algo/blob/master/docs/deploy-from-windows.md" exit 1 } } # Main execution try { # Check if we're actually running inside WSL if (Test-RunningInWSL) { Write-Host "Detected WSL environment. Running Algo using standard Unix approach..." # Verify bash is available (should be in WSL) if (-not (Get-Command bash -ErrorAction SilentlyContinue)) { Write-Host "ERROR: Running in WSL but bash is not available." -ForegroundColor Red Write-Host "Your WSL installation may be incomplete. Try running:" -ForegroundColor Yellow Write-Host " wsl --shutdown" -ForegroundColor Cyan Write-Host " wsl" -ForegroundColor Cyan exit 1 } # Run the standard Unix algo script & bash -c "./algo $($Arguments -join ' ')" exit $LASTEXITCODE } # We're on native Windows - need to use WSL Invoke-AlgoInWSL $Arguments } catch { Write-Host "" Write-Host "UNEXPECTED ERROR:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red Write-Host "" Write-Host "If you continue to have issues:" -ForegroundColor Yellow Write-Host "1. Ensure WSL is properly installed and Ubuntu is set up" Write-Host "2. See troubleshooting guide: https://github.com/trailofbits/algo/blob/master/docs/deploy-from-windows.md" Write-Host "3. Or use WSL directly: open Ubuntu and run './algo'" exit 1 } ================================================ FILE: ansible.cfg ================================================ [defaults] inventory = inventory pipelining = True retry_files_enabled = False host_key_checking = False timeout = 60 stdout_callback = default display_skipped_hosts = no force_valid_group_names = ignore remote_tmp = /tmp/.ansible/tmp [paramiko_connection] record_host_keys = False [ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o ConnectTimeout=6 -o ConnectionAttempts=30 -o IdentitiesOnly=yes scp_if_ssh = True retries = 30 ================================================ FILE: cloud.yml ================================================ --- - name: Provision the server hosts: localhost tags: always become: false vars_files: - config.cfg tasks: - block: - name: Local pre-tasks import_tasks: playbooks/cloud-pre.yml - name: Include a provisioning role include_role: name: "{{ 'local' if algo_provider == 'local' else 'cloud-' + algo_provider }}" - name: Local post-tasks import_tasks: playbooks/cloud-post.yml rescue: - include_tasks: playbooks/rescue.yml ================================================ FILE: config.cfg ================================================ --- # ============================================ # TROUBLESHOOTING DEPLOYMENT ISSUES # ============================================ # If your deployment fails with hidden/censored output, temporarily set # algo_no_log to 'false' below. This will show detailed error messages # including API responses. # IMPORTANT: Set back to 'true' before sharing logs or screenshots! # ============================================ algo_no_log: true # Set to 'false' for debugging (shows sensitive data in output) # This is the list of users to generate. # Every device must have a unique user. # You can add up to 65,534 new users over the lifetime of an AlgoVPN. # User names with leading 0's or containing only numbers should be escaped in double quotes, e.g. "000dan" or "123". # Email addresses are not allowed. users: - phone - laptop - desktop ### Review these options BEFORE you run Algo, as they are very difficult/impossible to change after the server is deployed. # SSH port for cloud deployments (doesn't apply to existing Ubuntu servers) ssh_port: 4160 # VPN protocols to deploy ipsec_enabled: true wireguard_enabled: true wireguard_port: 51820 # Change if blocked by your network (avoid 53/UDP) # Use different IP for outbound traffic (DigitalOcean only) alternative_ingress_ip: false # Reduce MTU if connections hang (0 = auto-detect) # See: docs/troubleshooting.md#various-websites-appear-to-be-offline-through-the-vpn reduce_mtu: 0 # Ad blocking lists (modify /usr/local/sbin/adblock.sh after deployment to add more) adblock_lists: - "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" # DNS encryption (required if using ad blocking) dns_encryption: true # Client isolation (set false for "road warrior" setup where clients can reach each other) BetweenClients_DROP: true block_smb: true # Block SMB/CIFS traffic block_netbios: true # Block NETBIOS traffic # Automatic reboot for security updates (time in server's timezone, default UTC) unattended_reboot: enabled: false time: 06:00 ### Privacy Settings ### # StrongSwan connection logging (-1 = disabled, 2 = debug) strongswan_log_level: -1 # Master switch for privacy enhancements (log rotation, history clearing, etc.) # Set to false for debugging. For advanced privacy options, see roles/privacy/defaults/main.yml privacy_enhancements_enabled: true ### Advanced users only below this line ### # DNSCrypt providers (see https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v2/public-resolvers.md) dnscrypt_servers: ipv4: - cloudflare # - google # - YourCustomServer # For NextDNS etc., add stamp below ipv6: - cloudflare-ipv6 custom_server_stamps: # YourCustomServer: 'sdns://...' # DNS servers when encryption is disabled dns_servers: ipv4: - 1.1.1.1 - 1.0.0.1 ipv6: - 2606:4700:4700::1111 - 2606:4700:4700::1001 # Store PKI in RAM disk when not retaining (MacOS/Linux only) pki_in_tmpfs: true # Regenerate ALL user credentials on update-users (not just new users) # When false: existing WireGuard keys and IPsec certs are preserved, new users added # When true: all credentials deleted and regenerated - ALL CLIENTS MUST RECONFIGURE # Use true after: suspected key compromise, removing untrusted users, or security audit keys_clean_all: false ### VPN Network Configuration ### strongswan_network: 10.48.0.0/16 strongswan_network_ipv6: '2001:db8:4160::/48' wireguard_network_ipv4: 10.49.0.0/16 wireguard_network_ipv6: 2001:db8:a160::/48 # Keep NAT connections alive (0 = disabled) wireguard_PersistentKeepalive: 0 ### Experimental Performance Options ### # These are experimental and may cause issues. Enable at your own risk. # performance_skip_optional_reboots: false # Skip non-kernel reboots # performance_parallel_crypto: false # Parallel key generation # performance_parallel_packages: false # Batch package installation # performance_preinstall_packages: false # Pre-install via cloud-init # performance_parallel_services: false # Configure VPN services in parallel # Randomly generated IP address for the local dns resolver local_service_ip: "{{ '172.16.0.1' | ansible.utils.ipmath(1048573 | random(seed=algo_server_name + ansible_fqdn)) }}" local_service_ipv6: "{{ 'fd00::1' | ansible.utils.ipmath(1048573 | random(seed=algo_server_name + ansible_fqdn)) }}" congrats: common: | "# Congratulations! #" "# Your Algo server is running. #" "# Config files and certificates are in the ./configs/ directory. #" "# Go to https://whoer.net/ after connecting #" "# and ensure that all your traffic passes through the VPN. #" "# Local DNS resolver {{ local_service_ip }}{{ ', ' + local_service_ipv6 if ipv6_support else '' }} #" p12_pass: | "# The p12 and SSH keys password for new users is {{ p12_export_password }} #" ca_key_pass: | "# The CA key password is {{ CA_password|default(omit) }} #" ssh_access: | "# Shell access: ssh -F configs/{{ ansible_ssh_host|default(omit) }}/ssh_config {{ algo_server_name }} #" SSH_keys: comment: algo@ssh private: configs/algo.pem private_tmp: /tmp/algo-ssh.pem public: configs/algo.pem.pub cloud_providers: azure: size: Standard_B1S osDisk: # The storage account type to use for the OS disk. Possible values: # 'Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS', # 'Premium_ZRS', 'StandardSSD_ZRS', 'PremiumV2_LRS'. type: Standard_LRS image: publisher: Canonical offer: 0001-com-ubuntu-minimal-jammy-daily sku: minimal-22_04-daily-lts version: latest digitalocean: # See docs for extended droplet options, pricing, and availability. # Possible values: 's-1vcpu-512mb-10gb', 's-1vcpu-1gb', ... size: s-1vcpu-1gb image: "ubuntu-22-04-x64" ec2: # Change the encrypted flag to "false" to disable AWS volume encryption. encrypted: true # Set use_existing_eip to "true" if you want to use a pre-allocated Elastic IP # Additional prompt will be raised to determine which IP to use use_existing_eip: false size: t3.micro image: name: "ubuntu-jammy-22.04" arch: x86_64 owner: "099720109477" # Change instance_market_type from "on-demand" to "spot" to launch a spot # instance. See deploy-from-ansible.md for spot's additional IAM permission instance_market_type: on-demand gce: size: e2-micro image: ubuntu-2204-lts external_static_ip: false lightsail: size: nano_2_0 image: ubuntu_22_04 scaleway: size: DEV1-S image: Ubuntu 22.04 Jammy Jellyfish arch: x86_64 hetzner: server_type: cpx22 image: ubuntu-22.04 openstack: flavor_ram: ">=512" image: Ubuntu-22.04 cloudstack: size: Micro image: Linux Ubuntu 22.04 LTS 64-bit disk: 10 vultr: os: Ubuntu 22.04 LTS x64 size: vc2-1c-1gb linode: type: g6-nanode-1 image: linode/ubuntu22.04 local: fail_hint: - Sorry, but something went wrong! - Check troubleshooting for common fixes, or file an issue if you found a bug. - https://trailofbits.github.io/algo/troubleshooting.html - https://github.com/trailofbits/algo/issues/new booleans_map: Y: true y: true ================================================ FILE: deploy_client.yml ================================================ --- - name: Configure the client hosts: localhost become: false vars_files: - config.cfg tasks: - name: Add the droplet to an inventory group add_host: name: "{{ client_ip }}" groups: client-host ansible_ssh_user: "{{ 'root' if client_ip == 'localhost' else ssh_user }}" vpn_user: "{{ vpn_user }}" IP_subject_alt_name: "{{ server_ip }}" ansible_python_interpreter: "{% if client_ip == 'localhost' %}{{ ansible_playbook_python }}{% else %}/usr/bin/python3{% endif %}" - name: Configure the client and install required software hosts: client-host gather_facts: false become: true vars_files: - config.cfg - roles/strongswan/defaults/main.yml roles: - role: client ================================================ FILE: destroy.yml ================================================ --- - name: Destroy an Algo VPN server hosts: localhost gather_facts: false become: false vars_files: - config.cfg tasks: - block: - name: Validate server_ip is provided assert: that: server_ip is defined and server_ip | length > 0 fail_msg: | server_ip is required. Usage: ./algo destroy ansible-playbook destroy.yml -e "server_ip=YOUR_SERVER_IP" - name: Check that server config exists stat: path: "configs/{{ server_ip }}/.config.yml" register: _server_config - name: Fail if server config not found fail: msg: | No config found at configs/{{ server_ip }}/.config.yml This server may not have been deployed by Algo, or its configs were already removed. Known servers: ls configs/*/ when: not _server_config.stat.exists - name: Load server configuration include_vars: file: "configs/{{ server_ip }}/.config.yml" name: _server_cfg - name: Set provider and server name from config set_fact: algo_provider: "{{ _server_cfg.algo_provider }}" algo_server_name: "{{ _server_cfg.algo_server_name }}" - name: Validate required config values assert: that: - algo_provider is defined and algo_provider | length > 0 - algo_server_name is defined and algo_server_name | length > 0 fail_msg: | Server config is missing algo_provider or algo_server_name. Check configs/{{ server_ip }}/.config.yml - name: Install cloud provider dependencies shell: "uv pip install '.[{{ _provider_extras[algo_provider] | default(algo_provider) }}]'" vars: _provider_extras: ec2: aws lightsail: aws azure: azure gce: gcp hetzner: hetzner linode: linode openstack: openstack cloudstack: cloudstack when: algo_provider != "local" changed_when: false - name: Set region from stored config set_fact: region: "{{ _server_cfg.algo_region }}" when: - region is not defined - _server_cfg.algo_region is defined - _server_cfg.algo_region | length > 0 - name: Validate region for providers that require it fail: msg: | Region is required to destroy {{ algo_provider }} servers. Pass it with: -e "region=YOUR_REGION" Example: ./algo destroy {{ server_ip }} -e "region=us-east-1" when: - algo_provider in ['ec2', 'lightsail', 'gce', 'scaleway', 'vultr'] - region is not defined - name: Set dummy region for providers that do not need it set_fact: region: "unused" when: - region is not defined - algo_provider not in ['ec2', 'lightsail', 'gce', 'scaleway', 'vultr'] - name: Gather provider credentials include_tasks: "roles/cloud-{{ algo_provider }}/tasks/prompts.yml" when: algo_provider != "local" - name: Display destroy plan debug: msg: - "Server IP: {{ server_ip }}" - "Server name: {{ algo_server_name }}" - "Provider: {{ algo_provider }}" - name: Confirm destruction pause: prompt: | This will permanently destroy the server and remove local configs. Type 'yes' to confirm register: _confirm_destroy when: confirm_destroy is not defined or not confirm_destroy | bool - name: Abort if not confirmed fail: msg: "Destroy aborted by user." when: - confirm_destroy is not defined or not confirm_destroy | bool - _confirm_destroy.user_input | default('') | lower != 'yes' - name: Destroy cloud resources include_tasks: "roles/cloud-{{ algo_provider }}/tasks/destroy.yml" when: algo_provider != "local" - name: Remove local config directory file: path: "configs/{{ server_ip }}" state: absent - name: Remove localhost symlink file: path: configs/localhost state: absent when: server_ip == "localhost" - name: Destroy complete debug: msg: - "Server {{ algo_server_name }} ({{ server_ip }}) destroyed." - "Local configs removed from configs/{{ server_ip }}/" rescue: - include_tasks: playbooks/rescue.yml ================================================ FILE: docs/aws-credentials.md ================================================ # AWS Credential Configuration Algo supports multiple methods for providing AWS credentials, following standard AWS practices: ## Methods (in order of precedence) 1. **Command-line variables** (highest priority) ```bash ./algo -e "aws_access_key=YOUR_KEY aws_secret_key=YOUR_SECRET" ``` 2. **Environment variables** ```bash export AWS_ACCESS_KEY_ID=YOUR_KEY export AWS_SECRET_ACCESS_KEY=YOUR_SECRET export AWS_SESSION_TOKEN=YOUR_TOKEN # Optional, for temporary credentials ./algo ``` 3. **AWS credentials file** (lowest priority) - Default location: `~/.aws/credentials` - Custom location: Set `AWS_SHARED_CREDENTIALS_FILE` environment variable - Profile selection: Set `AWS_PROFILE` environment variable (defaults to "default") ## Using AWS Credentials File After running `aws configure` or manually creating `~/.aws/credentials`: ```ini [default] aws_access_key_id = YOUR_KEY_ID aws_secret_access_key = YOUR_SECRET_KEY [work] aws_access_key_id = WORK_KEY_ID aws_secret_access_key = WORK_SECRET_KEY aws_session_token = TEMPORARY_TOKEN # Optional ``` To use a specific profile: ```bash AWS_PROFILE=work ./algo ``` ## Security Considerations - Credentials files should have restricted permissions (600) - Consider using AWS IAM roles or temporary credentials when possible - Tools like [aws-vault](https://github.com/99designs/aws-vault) can provide additional security by storing credentials encrypted ## Troubleshooting If Algo isn't finding your credentials: 1. Check file permissions: `ls -la ~/.aws/credentials` 2. Verify the profile name matches: `AWS_PROFILE=your-profile` 3. Test with AWS CLI: `aws sts get-caller-identity` If credentials are found but authentication fails: - Ensure your IAM user has the required permissions (see [EC2 deployment guide](deploy-from-ansible.md)) - Check if you need session tokens for temporary credentials ================================================ FILE: docs/client-android.md ================================================ # Android client setup ## Installation via profiles 1. [Install the WireGuard VPN Client](https://play.google.com/store/apps/details?id=com.wireguard.android). 2. Open QR code `configs//wireguard/.png` and scan it in the WireGuard app ================================================ FILE: docs/client-apple-ipsec.md ================================================ # Using the built-in IPSEC VPN on Apple Devices ## Configure IPsec Find the corresponding `mobileconfig` (Apple Profile) for each user and send it to them over AirDrop or other secure means. Apple Configuration Profiles are all-in-one configuration files for iOS and macOS devices. On macOS, double-clicking a profile to install it will fully configure the VPN. On iOS, users are prompted to install the profile as soon as the AirDrop is accepted. ## Enable the VPN On iOS, connect to the VPN by opening **Settings** and clicking the toggle next to "VPN" near the top of the list. If using WireGuard, you can also enable the VPN from the WireGuard app. On macOS, connect to the VPN by opening **System Settings** -> **Network** (or **VPN** on macOS Sequoia 15.0+), finding the Algo VPN in the left column, and clicking "Connect." Check "Show VPN status in menu bar" to easily connect and disconnect from the menu bar. ## Managing "Connect On Demand" If you enable "Connect On Demand", the VPN will connect automatically whenever it is able. Most Apple users will want to enable "Connect On Demand", but if you do then simply disabling the VPN will not cause it to stay disabled; it will just "Connect On Demand" again. To disable the VPN you'll need to disable "Connect On Demand". On iOS, you can turn off "Connect On Demand" in **Settings** by clicking the (i) next to the entry for your Algo VPN and toggling off "Connect On Demand." On macOS, you can turn off "Connect On Demand" by opening **System Settings** -> **Network** (or **VPN** on macOS Sequoia 15.0+), finding the Algo VPN in the left column, unchecking the box for "Connect on demand", and clicking Apply. ================================================ FILE: docs/client-linux-ipsec.md ================================================ # Linux strongSwan IPsec Clients (e.g., OpenWRT, Ubuntu Server, etc.) Install strongSwan, then copy the included ipsec_user.conf, ipsec_user.secrets, user.crt (user certificate), and user.key (private key) files to your client device. These will require customization based on your exact use case. These files were originally generated with a point-to-point OpenWRT-based VPN in mind. ## Ubuntu Server example 1. `sudo apt install strongswan libstrongswan-standard-plugins`: install strongSwan 2. `/etc/ipsec.d/certs`: copy `.crt` from `algo-master/configs//ipsec/.pki/certs/.crt` 3. `/etc/ipsec.d/private`: copy `.key` from `algo-master/configs//ipsec/.pki/private/.key` 4. `/etc/ipsec.d/cacerts`: copy `cacert.pem` from `algo-master/configs//ipsec/manual/cacert.pem` 5. `/etc/ipsec.secrets`: add your `user.key` to the list, e.g. ` : ECDSA .key` 6. `/etc/ipsec.conf`: add the connection from `ipsec_user.conf` and ensure `leftcert` matches the `.crt` filename 7. `sudo ipsec restart`: pick up config changes 8. `sudo ipsec up `: start the ipsec tunnel 9. `sudo ipsec down `: shutdown the ipsec tunnel One common use case is to let your server access your local LAN without going through the VPN. Set up a passthrough connection by adding the following to `/etc/ipsec.conf`: conn lan-passthrough leftsubnet=192.168.1.1/24 # Replace with your LAN subnet rightsubnet=192.168.1.1/24 # Replace with your LAN subnet authby=never # No authentication necessary type=pass # passthrough auto=route # no need to ipsec up lan-passthrough To configure the connection to come up at boot time replace `auto=add` with `auto=start`. ## Notes on SELinux If you use a system with SELinux enabled, you might need to set appropriate file contexts: ```` semanage fcontext -a -t ipsec_key_file_t "$(pwd)(/.*)?" restorecon -R -v $(pwd) ```` See [this comment](https://github.com/trailofbits/algo/issues/263#issuecomment-328053950). ================================================ FILE: docs/client-linux-wireguard.md ================================================ # Using Ubuntu as a Client with WireGuard ## Install WireGuard To connect to your AlgoVPN using [WireGuard](https://www.wireguard.com) from Ubuntu, make sure your system is up-to-date then install WireGuard: ```shell # Update your system: sudo apt update && sudo apt upgrade # If the file /var/run/reboot-required exists then reboot: [ -e /var/run/reboot-required ] && sudo reboot # Install WireGuard: sudo apt install wireguard # Note: openresolv is no longer needed on Ubuntu 22.04 LTS+ ``` For installation on other Linux distributions, see the [Installation](https://www.wireguard.com/install/) page on the WireGuard site. ## Locate the Config File The Algo-generated config files for WireGuard are named `configs//wireguard/.conf` on the system where you ran `./algo`. One file was generated for each of the users you added to `config.cfg`. Each WireGuard client you connect to your AlgoVPN must use a different config file. Choose one of these files and copy it to your Linux client. ## Configure WireGuard Finally, install the config file on your client as `/etc/wireguard/wg0.conf` and start WireGuard: ```shell # Install the config file to the WireGuard configuration directory on your # Linux client: sudo install -o root -g root -m 600 .conf /etc/wireguard/wg0.conf # Start the WireGuard VPN: sudo systemctl start wg-quick@wg0 # Check that it started properly: sudo systemctl status wg-quick@wg0 # Verify the connection to the AlgoVPN: sudo wg # See that your client is using the IP address of your AlgoVPN: curl ipv4.icanhazip.com # Optionally configure the connection to come up at boot time: sudo systemctl enable wg-quick@wg0 ``` If your Linux distribution does not use `systemd` you can bring up WireGuard with `sudo wg-quick up wg0`. ## Using a DNS Search Domain As of the `v1.0.20200510` release of `wireguard-tools` WireGuard supports setting a DNS search domain. In your `wg0.conf` file a non-numeric entry on the `DNS` line will be used as a search domain. For example, this: ``` DNS = 172.27.153.31, fd00::b:991f, mydomain.com ``` will cause your `/etc/resolv.conf` to contain: ``` search mydomain.com nameserver 172.27.153.31 nameserver fd00::b:991f ``` ================================================ FILE: docs/client-linux.md ================================================ # Linux client setup ## Provision client config After you deploy a server, you can use an included Ansible script to provision Linux clients too! Debian, Ubuntu, CentOS, and Fedora are supported. The playbook is `deploy_client.yml`. ### Required variables * `client_ip` - The IP address of your client machine (You can use `localhost` in order to deploy locally) * `vpn_user` - The username. (Ensure that you have valid certificates and keys in the `configs/SERVER_ip/pki/` directory) * `ssh_user` - The username that we need to use in order to connect to the client machine via SSH (ignore if you are deploying locally) * `server_ip` - The vpn server ip address ### Example ```shell ansible-playbook deploy_client.yml -e 'client_ip=client.com vpn_user=jack server_ip=vpn-server.com ssh_user=root' ``` ### Additional options If the user requires sudo password use the following argument: `--ask-become-pass`. ## OS Specific instructions Some Linux clients may require more specific and details instructions to configure a connection to the deployed Algo VPN, these are documented here. ### Fedora Workstation #### (Gnome) Network Manager install First, install the required plugins. ```` dnf install NetworkManager-strongswan NetworkManager-strongswan-gnome ```` #### (Gnome) Network Manager configuration In this example we'll assume the IP of our Algo VPN server is `1.2.3.4` and the user we created is `user-name`. * Go to *Settings* > *Network* * Add a new Network (`+` bottom left of the window) * Select *IPsec/IKEv2 (strongswan)* * Fill out the options: * Name: your choice, e.g.: *ikev2-1.2.3.4* * Gateway: * Address: IP of the Algo VPN server, e.g: `1.2.3.4` * Certificate: `cacert.pem` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/cacert.pem` * Client: * Authentication: *Certificate/Private key* * Certificate: `user-name.crt` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/certs/user-name.crt` * Private key: `user-name.key` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/private/user-name.key` * Options: * Check *Request an inner IP address*, connection will fail without this option * Optionally check *Enforce UDP encapsulation* * Optionally check *Use IP compression* * For the later 2 options, hover to option in the settings to see a description * Cipher proposal: * Check *Enable custom proposals* * IKE: `aes256gcm16-prfsha512-ecp384` * ESP: `aes256gcm16-ecp384` * Apply and turn the connection on, you should now be connected ================================================ FILE: docs/client-macos-wireguard.md ================================================ # MacOS WireGuard Client Setup The WireGuard macOS app is unavailable for older operating systems. Please update your operating system if you can. If you are on a macOS High Sierra (10.13) or earlier, then you can still use WireGuard via their userspace drivers via the process detailed below. ## Install WireGuard Install the wireguard-go userspace driver: ``` brew install wireguard-tools ``` ## Locate the Config File Algo generates a WireGuard configuration file, `wireguard/.conf`, and a QR code, `wireguard/.png`, for each user defined in `config.cfg`. Find the configuration file and copy it to your device if you don't already have it. Note that each client you use to connect to Algo VPN must have a unique WireGuard config. ## Configure WireGuard You'll need to copy the appropriate WireGuard configuration file into a location where the userspace driver can find it. After it is in the right place, start the VPN, and verify connectivity. ``` # Copy the config file to the WireGuard configuration directory on your macOS device mkdir /usr/local/etc/wireguard/ cp .conf /usr/local/etc/wireguard/wg0.conf # Start the WireGuard VPN sudo wg-quick up wg0 # Verify the connection to the Algo VPN wg # See that your client is using the IP address of your Algo VPN: curl ipv4.icanhazip.com ``` ================================================ FILE: docs/client-openwrt-router-wireguard.md ================================================ # OpenWrt Router as WireGuard Client This guide explains how to configure an OpenWrt router as a WireGuard VPN client, allowing all devices connected to your network to route traffic through your Algo VPN automatically. This setup is ideal for devices that don't support VPN natively (smart TVs, IoT devices, game consoles) or when you want seamless VPN access for all network clients. ## Use Cases - Connect devices without native VPN support (smart TVs, gaming consoles, IoT devices) - Automatically route all connected devices through the VPN - Create a secure connection when traveling with multiple devices - Configure VPN once at the router level instead of per-device ## Prerequisites You'll need an OpenWrt-compatible router with sufficient RAM (minimum 64MB recommended) and OpenWrt 23.05 or later installed. Your Algo VPN server must be deployed and running, and you'll need the WireGuard configuration file from your Algo deployment. Ensure your router's LAN subnet doesn't conflict with upstream networks. The default OpenWrt IP is `192.168.1.1` - change to `192.168.2.1` if conflicts exist. This configuration has been verified on TP-Link TL-WR1043ND and TP-Link Archer C20i AC750 with OpenWrt 23.05+. For compatibility with other devices, check the [OpenWrt Table of Hardware](https://openwrt.org/toh/start). ## Install Required Packages ### Web Interface Method 1. Access your router's web interface (typically `http://192.168.1.1`) 2. Login with your credentials (default: username `root`, no password) 3. Navigate to System → Software 4. Click "Update lists" to refresh the package database 5. Search for and install these packages: - `wireguard-tools` - `kmod-wireguard` - `luci-app-wireguard` - `wireguard` - `kmod-crypto-sha256` - `kmod-crypto-sha1` - `kmod-crypto-md5` 6. Restart the router after installation completes ### SSH Method 1. SSH into your router: `ssh root@192.168.1.1` 2. Update the package list: ```bash opkg update ``` 3. Install required packages: ```bash opkg install wireguard-tools kmod-wireguard luci-app-wireguard wireguard kmod-crypto-sha256 kmod-crypto-sha1 kmod-crypto-md5 ``` 4. Reboot the router: ```bash reboot ``` ## Locate Your WireGuard Configuration Before proceeding, locate your WireGuard configuration file from your Algo deployment. This file is typically located at: ``` configs//wireguard/.conf ``` Your configuration file should look similar to: ```ini [Interface] PrivateKey = Address = 10.49.0.2/16 DNS = 172.16.0.1 [Peer] PublicKey = PresharedKey = AllowedIPs = 0.0.0.0/0, ::/0 Endpoint = :51820 PersistentKeepalive = 25 ``` ## Configure WireGuard Interface 1. In the OpenWrt web interface, navigate to Network → Interfaces 2. Click "Add new interface..." 3. Set the name to `AlgoVPN` (or your preferred name) and select "WireGuard VPN" as the protocol 4. Click "Create interface" In the General Settings tab: - Check "Bring up on boot" - Enter your private key from the Algo config file - Add your IP address from the Algo config file (e.g., `10.49.0.2/16`) Switch to the Peers tab and click "Add peer": - Description: `Algo Server` - Public Key: Copy from the `[Peer]` section of your config - Preshared Key: Copy from the `[Peer]` section of your config - Allowed IPs: `0.0.0.0/0, ::/0` (routes all traffic through VPN) - Route Allowed IPs: Check this box - Endpoint Host: Extract the IP address from the `Endpoint` line - Endpoint Port: Extract the port from the `Endpoint` line (typically `51820`) - Persistent Keep Alive: `25` Click "Save & Apply". ## Configure Firewall Rules 1. Navigate to Network → Firewall 2. Click "Add" to create a new zone 3. Configure the firewall zone: - Name: `vpn` - Input: `Reject` - Output: `Accept` - Forward: `Reject` - Masquerading: Check this box - MSS clamping: Check this box - Covered networks: Select your WireGuard interface (`AlgoVPN`) 4. In the Inter-Zone Forwarding section: - Allow forward from source zones: Select `lan` - Allow forward to destination zones: Leave unspecified 5. Click "Save & Apply" 6. Reboot your router to ensure all changes take effect ## Verification and Testing Navigate to Network → Interfaces and verify your WireGuard interface shows as "Connected" with a green status. Check that it has received the correct IP address. From a device connected to your router, visit https://whatismyipaddress.com/. Your public IP should match your Algo VPN server's IP address. Test DNS resolution to ensure it's working through the VPN. For command line verification, SSH into your router and check: ```bash # Check interface status wg show # Check routing table ip route # Test connectivity ping 8.8.8.8 ``` ## Configuration File Reference Your OpenWrt network configuration (`/etc/config/network`) should include sections similar to: ```uci config interface 'AlgoVPN' option proto 'wireguard' list addresses '10.49.0.2/16' option private_key '' config wireguard_AlgoVPN option public_key '' option preshared_key '' option route_allowed_ips '1' list allowed_ips '0.0.0.0/0' list allowed_ips '::/0' option endpoint_host '' option endpoint_port '51820' option persistent_keepalive '25' ``` ## Troubleshooting If the interface won't connect, verify all keys are correctly copied with no extra spaces or line breaks. Check that your Algo server is running and accessible, and confirm the endpoint IP and port are correct. If you have no internet access after connecting, verify firewall rules allow forwarding from LAN to VPN zone. Check that masquerading is enabled on the VPN zone and ensure MSS clamping is enabled. If some websites don't work, try disabling MSS clamping temporarily to test. Verify DNS is working by testing `nslookup google.com` and check that IPv6 is properly configured if used. For DNS resolution issues, configure custom DNS servers in Network → DHCP and DNS. Consider using your Algo server's DNS (typically `172.16.0.1`). Check system logs for WireGuard-related errors: ```bash # View system logs logread | grep -i wireguard # Check kernel messages dmesg | grep -i wireguard ``` ## Advanced Configuration For split tunneling (routing only specific traffic through the VPN), change "Allowed IPs" in the peer configuration to specific subnets and add custom routing rules for desired traffic. If your Algo server supports IPv6, add the IPv6 address to your interface configuration and include `::/0` in "Allowed IPs" for the peer. For optimal privacy, configure your router to use your Algo server's DNS by navigating to Network → DHCP and DNS and adding your Algo DNS server IP (typically `172.16.0.1`) to the DNS forwardings. ## Security Notes Store your private keys securely and never share them. Keep OpenWrt and packages updated for security patches. Regularly check VPN connectivity to ensure ongoing protection, and save your configuration before making changes. This configuration routes ALL traffic from your router through the VPN. If you need selective routing or have specific requirements, consider consulting the [OpenWrt WireGuard documentation](https://openwrt.org/docs/guide-user/services/vpn/wireguard/start) for advanced configurations. ================================================ FILE: docs/client-windows.md ================================================ # Windows Client Setup This guide will help you set up your Windows device to connect to your Algo VPN server. ## Supported Versions - Windows 10 (all editions) - Windows 11 (all editions) - Windows Server 2016 and later ## WireGuard Setup (Recommended) WireGuard is the recommended VPN protocol for Windows clients due to its simplicity and performance. ### Installation 1. Download and install the official [WireGuard client for Windows](https://www.wireguard.com/install/) 2. Locate your configuration file: `configs//wireguard/.conf` 3. In the WireGuard application, click "Import tunnel(s) from file" 4. Select your `.conf` file and import it 5. Click "Activate" to connect to your VPN ### Alternative Import Methods - **QR Code**: If you have access to the QR code (`wireguard/.png`), you can scan it using a mobile device first, then export the configuration - **Manual Entry**: You can create a new empty tunnel and paste the contents of your `.conf` file ## IPsec/IKEv2 Setup (Legacy) While Algo supports IPsec/IKEv2, it requires PowerShell scripts for Windows setup. WireGuard is strongly recommended instead. If you must use IPsec: 1. Locate the PowerShell setup script in your configs directory 2. Run PowerShell as Administrator 3. Execute the setup script 4. The VPN connection will appear in Settings → Network & Internet → VPN ## Troubleshooting ### "The parameter is incorrect" Error This is a common error that occurs when trying to connect. See the [troubleshooting guide](troubleshooting.md#windows-the-parameter-is-incorrect-error-when-connecting) for the solution. ### Connection Issues 1. **Check Windows Firewall**: Ensure Windows Firewall isn't blocking the VPN connection 2. **Verify Server Address**: Make sure the server IP/domain in your configuration is correct 3. **Check Date/Time**: Ensure your system date and time are correct 4. **Disable Other VPNs**: Disconnect from any other VPN services before connecting ### WireGuard Specific Issues - **DNS Not Working**: Check if "Block untunneled traffic (kill-switch)" is enabled in tunnel settings - **Slow Performance**: Try reducing the MTU in the tunnel configuration (default is 1420) - **Can't Import Config**: Ensure the configuration file has a `.conf` extension ### Performance Optimization 1. **Use WireGuard**: It's significantly faster than IPsec on Windows 2. **Close Unnecessary Apps**: Some antivirus or firewall software can slow down VPN connections 3. **Check Network Adapter**: Update your network adapter drivers to the latest version ## Advanced Configuration ### Split Tunneling To exclude certain traffic from the VPN: 1. Edit your WireGuard configuration file 2. Modify the `AllowedIPs` line to exclude specific networks 3. For example, to exclude local network: Remove `0.0.0.0/0` and add specific routes ### Automatic Connection To connect automatically: 1. Open WireGuard 2. Select your tunnel 3. Edit → Uncheck "On-demand activation" 4. Windows will maintain the connection automatically ### Multiple Servers You can import multiple `.conf` files for different Algo servers. Give each a descriptive name to distinguish them. ## Security Notes - Keep your configuration files secure - they contain your private keys - Don't share your configuration with others - Each user should have their own unique configuration - Regularly update your WireGuard client for security patches ## Need More Help? - Check the main [troubleshooting guide](troubleshooting.md) - Review [WireGuard documentation](https://www.wireguard.com/quickstart/) - [Create a discussion](https://github.com/trailofbits/algo/discussions) for help ================================================ FILE: docs/cloud-alternative-ingress-ip.md ================================================ # Alternative Ingress IP This feature allows you to configure the Algo server to send outbound traffic through a different external IP address than the one you are establishing the VPN connection with. ![cloud-alternative-ingress-ip](/docs/images/cloud-alternative-ingress-ip.png) Additional info might be found in [this issue](https://github.com/trailofbits/algo/issues/1047) #### Caveats ##### Extra charges - DigitalOcean: Floating IPs are free when assigned to a Droplet, but after manually deleting a Droplet, you need to also delete the Floating IP or you'll get charged for it. ##### IPv6 Some cloud providers provision a VM with an `/128` address block size. This is the only IPv6 address provided and for outbound and incoming traffic. If the provided address block size is bigger, e.g., `/64`, Algo takes a separate address than the one is assigned to the server to send outbound IPv6 traffic. ================================================ FILE: docs/cloud-amazon-ec2.md ================================================ # Amazon EC2 Cloud Setup This guide walks you through setting up Algo VPN on Amazon EC2, including account creation, permissions configuration, and deployment process. ## AWS Account Creation Creating an Amazon AWS account requires providing a phone number that can receive automated calls with PIN verification. The phone verification system occasionally fails, but you can request a new PIN and try again until it succeeds. ## Choose Your EC2 Plan ### AWS Free Tier The most cost-effective option for new AWS customers is the [AWS Free Tier](https://aws.amazon.com/free/), which provides: - 750 hours of Amazon EC2 Linux t2.micro or t3.micro instance usage per month - 100 GB of outbound data transfer per month - 30 GB of cloud storage The Free Tier is available for 12 months from account creation. Some regions like Middle East (Bahrain), EU (Stockholm), and Israel (il-central-1) don't offer t2.micro instances, but t3.micro is available as an alternative. Note that your Algo instance will continue working if you exceed bandwidth limits - you'll just start accruing standard charges on your AWS account. ### Cost-Effective Alternatives If you're not eligible for the Free Tier or prefer more predictable costs, consider AWS Graviton instances. To use Graviton instances, modify your `config.cfg` file: ```yaml ec2: size: t4g.nano arch: arm64 ``` The t4g.nano instance is currently the least expensive option without promotional requirements. AWS is also running a promotion offering free t4g.small instances until December 31, 2025 - see the [AWS documentation](https://aws.amazon.com/ec2/faqs/#t4g-instances) for details. For additional EC2 configuration options, see the [deploy from ansible guide](https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md#amazon-ec2). ## Set Up IAM Permissions ### Create IAM Policy 1. In the AWS console, navigate to Services → IAM → Policies 2. Click "Create Policy" 3. Switch to the JSON tab 4. Replace the default content with the [minimum required AWS policy for Algo deployment](https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md#minimum-required-iam-permissions-for-deployment) 5. Name the policy `AlgoVPN_Provisioning` ![Creating a new permissions policy in the AWS console.](/docs/images/aws-ec2-new-policy.png) ### Create IAM User 1. Navigate to Services → IAM → Users 2. Enable multi-factor authentication (MFA) on your root account using Google Authenticator or a hardware token 3. Click "Add User" and create a username (e.g., `algovpn`) 4. Select "Programmatic access" 5. Click "Next: Permissions" ![The new user screen in the AWS console.](/docs/images/aws-ec2-new-user.png) 6. Choose "Attach existing policies directly" 7. Search for "Algo" and select the `AlgoVPN_Provisioning` policy you created 8. Click "Next: Tags" (optional), then "Next: Review" ![Attaching a policy to an IAM user in the AWS console.](/docs/images/aws-ec2-attach-policy.png) 9. Review your settings and click "Create user" 10. Download the CSV file containing your access credentials - you'll need these for Algo deployment ![Downloading the credentials for an AWS IAM user.](/docs/images/aws-ec2-new-user-csv.png) Keep the CSV file secure as it contains sensitive credentials that grant access to your AWS account. ## Deploy with Algo Once you've installed Algo and its dependencies, you can deploy your VPN server to EC2. ### Provider Selection Run `./algo` and select Amazon EC2 when prompted: ``` $ ./algo What provider would you like to use? 1. DigitalOcean 2. Amazon Lightsail 3. Amazon EC2 4. Microsoft Azure 5. Google Compute Engine 6. Hetzner Cloud 7. Vultr 8. Scaleway 9. OpenStack (DreamCompute optimised) 10. CloudStack 11. Linode 12. Install to existing Ubuntu server (for more advanced users) Enter the number of your desired provider : 3 ``` ### AWS Credentials Algo will automatically detect AWS credentials in this order: 1. Command-line variables 2. Environment variables (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`) 3. AWS credentials file (`~/.aws/credentials`) If no credentials are found, you'll be prompted to enter them manually: ``` Enter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) Note: Make sure to use an IAM user with an acceptable policy attached (see https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md). [pasted values will not be displayed] [AKIA...]: Enter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) [pasted values will not be displayed] [ABCD...]: ``` For detailed credential configuration options, see the [AWS Credentials guide](aws-credentials.md). ### Server Configuration You'll be prompted to name your server (default is "algo"): ``` Name the vpn server: [algo]: algovpn ``` Next, select your preferred AWS region: ``` What region should the server be located in? (https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region) 1. ap-northeast-1 2. ap-northeast-2 3. ap-south-1 4. ap-southeast-1 5. ap-southeast-2 6. ca-central-1 7. eu-central-1 8. eu-north-1 9. eu-west-1 10. eu-west-2 11. eu-west-3 12. sa-east-1 13. us-east-1 14. us-east-2 15. us-west-1 16. us-west-2 Enter the number of your desired region [13] : ``` Choose a region close to your location for optimal performance, keeping in mind that some regions may have different pricing or instance availability. After region selection, Algo will continue with the standard setup questions for user configuration and VPN options. ## Resource Cleanup If you deploy Algo to EC2 multiple times, unused resources (instances, VPCs, subnets) may accumulate and potentially cause future deployment issues. The cleanest way to remove an Algo deployment is through CloudFormation: 1. Go to the AWS console and navigate to CloudFormation 2. Find the stack associated with your Algo server 3. Delete the entire stack Warning: Deleting a CloudFormation stack will permanently delete your EC2 instance and all associated resources unless you've enabled termination protection. Make sure you're deleting the correct stack and have backed up any important data. This approach ensures all related AWS resources are properly cleaned up, preventing resource conflicts in future deployments. ================================================ FILE: docs/cloud-azure.md ================================================ # Azure cloud setup The easiest way to get started with the Azure CLI is by running it in an Azure Cloud Shell environment through your browser. Here you can find some information from [the official doc](https://docs.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest). We put the essential commands together for simplest usage. ## Install azure-cli - macOS ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-macos?view=azure-cli-latest)): ```bash $ brew update && brew install azure-cli ``` - Linux (deb-based) ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest)): ```bash $ sudo apt-get update && sudo apt-get install \ apt-transport-https \ lsb-release \ software-properties-common \ dirmngr -y $ AZ_REPO=$(lsb_release -cs) $ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \ sudo tee /etc/apt/sources.list.d/azure-cli.list $ sudo apt-key --keyring /etc/apt/trusted.gpg.d/Microsoft.gpg adv \ --keyserver packages.microsoft.com \ --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF $ sudo apt-get update $ sudo apt-get install azure-cli ``` - Linux (rpm-based) ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-yum?view=azure-cli-latest)): ```bash $ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc $ sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo' $ sudo yum install azure-cli ``` - Windows ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)): For Windows the Azure CLI is installed via an MSI, which gives you access to the CLI through the Windows Command Prompt (CMD) or PowerShell. When installing for Windows Subsystem for Linux (WSL), packages are available for your Linux distribution. [Download the MSI installer](https://aka.ms/installazurecliwindows) If your OS is missing or to get more information, see [the official doc](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) ## Sign in 1. Run the `login` command: ```bash az login ``` If the CLI can open your default browser, it will do so and load a sign-in page. Otherwise, you need to open a browser page and follow the instructions on the command line to enter an authorization code after navigating to https://aka.ms/devicelogin in your browser. 2. Sign in with your account credentials in the browser. There are ways to sign in non-interactively, which are covered in detail in [Sign in with Azure CLI](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest). **Now you are able to deploy an AlgoVPN instance without hassle** ================================================ FILE: docs/cloud-cloudstack.md ================================================ ### Configuration file > **⚠️ Important Note:** Exoscale is no longer supported as they deprecated their CloudStack API on May 1, 2024. Please use alternative providers like Hetzner, DigitalOcean, Vultr, or Scaleway. Algo scripts will ask you for the API details. You need to fetch the API credentials and the endpoint from your CloudStack provider's control panel. For CloudStack providers, you'll need to set: ```bash export CLOUDSTACK_KEY="" export CLOUDSTACK_SECRET="" export CLOUDSTACK_ENDPOINT="" ``` Make sure your provider supports the CloudStack API. Contact your provider for the correct API endpoint URL. ================================================ FILE: docs/cloud-do.md ================================================ # DigitalOcean cloud setup ## API Token creation First, login into your DigitalOcean account. Select **API** from the titlebar. This will take you to the "Applications & API" page. ![The Applications & API page](/docs/images/do-api.png) On the **Tokens/Keys** tab, select **Generate New Token**. A dialog will pop up. In that dialog, give your new token a name, and make sure **Write** is checked off. Click the **Generate Token** button when you are ready. ![The new token dialog, showing a form requesting a name and confirmation on the scope for the new token.](/docs/images/do-new-token.png) You will be returned to the **Tokens/Keys** tab, and your new key will be shown under the **Personal Access Tokens** header. ![The new token in the listing.](/docs/images/do-view-token.png) Copy or note down the hash that shows below the name you entered, as this will be necessary for the steps below. This value will disappear if you leave this page, and you'll need to regenerate it if you forget it. ## Select a Droplet (optional) The default option is the `s-1vcpu-1gb` because it is available in all regions. However, you may want to switch to a cheaper droplet such as `s-1vcpu-512mb-10gb` even though it is not available in all regions. This can be edited in the [Configuration File](config.cfg) under `cloud_providers > digitalocean > size`. See this brief comparison between the two droplets below: | Droplet Type | Monthly Cost | Bandwidth | Availability | |:--|:-:|:-:|:--| | `s-1vcpu-512mb-10gb` | $4/month | 0.5 TB | Limited | | `s-1vcpu-1gb` | $6/month | 1.0 TB | All regions | | ... | ... | ... | ... | *Note: Exceeding bandwidth limits costs $0.01/GiB at time of writing ([docs](https://docs.digitalocean.com/products/billing/bandwidth/#droplets)). See the live list of droplets [here](https://slugs.do-api.dev/).* ## Using DigitalOcean with Algo (interactive) These steps are for those who run Algo using Docker or using the `./algo` command. Choose DigitalOcean as your provider: ``` What provider would you like to use? 1. DigitalOcean 2. Amazon Lightsail 3. Amazon EC2 4. Vultr 5. Microsoft Azure 6. Google Compute Engine 7. Scaleway 8. OpenStack (DreamCompute optimised) 9. Install to existing Ubuntu server (Advanced) Enter the number of your desired provider : 1 ``` Enter a name for your server. Leave this as the default if you are not certain how this will affect your setup: ``` Name the vpn server: [algo]: ``` After several prompts related to Algo features you will be asked for the API Token value. Paste the API Token value you copied when following the steps in [API Token creation](#api-token-creation) (you won't see any output as the key is not echoed by Algo): ``` Enter your API token. The token must have read and write permissions (https://cloud.digitalocean.com/settings/api/tokens): (output is hidden): ``` Finally, you will be asked the region in which you wish to setup your new Algo server. This list is dynamic and can change based on availability of resources. Enter the number next to name of the region: ``` What region should the server be located in? 1. ams3 Amsterdam 3 2. blr1 Bangalore 1 3. fra1 Frankfurt 1 4. lon1 London 1 5. nyc1 New York 1 6. nyc3 New York 3 7. sfo2 San Francisco 2 8. sgp1 Singapore 1 9. tor1 Toronto 1 Enter the number of your desired region [6] : 9 ``` ## Using DigitalOcean with Algo (scripted) If you are using Ansible directly to run Algo you will need to pass the API Token as `do_token`. For example: ```shell ansible-playbook main.yml -e "provider=digitalocean server_name=algo ondemand_cellular=true ondemand_wifi=true dns_adblocking=false ssh_tunneling=false store_pki=true region=nyc3 do_token=token" ``` For more, see [Scripted Deployment](deploy-from-ansible.md). ## Using the DigitalOcean firewall with Algo Many cloud providers include the option to configure an external firewall between the Internet and your cloud server. For some providers this is mandatory and Algo will configure it for you, but for DigitalOcean the external firewall is optional. See [AlgoVPN and Firewalls](/docs/firewalls.md) for more information. To configure the DigitalOcean firewall, go to **Networking**, **Firewalls**, and choose **Create Firewall**. Configure your **Inbound Rules** as follows: ![Inbound Rules](/docs/images/do-firewall.png) Leave the **Outbound Rules** at their defaults. Under **Apply to Droplets** enter the tag `Environment:Algo` to apply this firewall to all current and future Algo VPNs you create. ================================================ FILE: docs/cloud-gce.md ================================================ # Google Cloud Platform setup * Follow the [`gcloud` installation instructions](https://cloud.google.com/sdk/) * Log into your account using `gcloud init` ### Creating a project The recommendation on GCP is to group resources into **Projects**, so we will create a new project for our VPN server and use a service account restricted to it. ```bash ## Create the project to group the resources ### You might need to change it to have a global unique project id PROJECT_ID=${USER}-algo-vpn BILLING_ID="$(gcloud beta billing accounts list --format="value(ACCOUNT_ID)")" gcloud projects create ${PROJECT_ID} --name algo-vpn --set-as-default gcloud beta billing projects link ${PROJECT_ID} --billing-account ${BILLING_ID} ## Create an account that have access to the VPN gcloud iam service-accounts create algo-vpn --display-name "Algo VPN" gcloud iam service-accounts keys create configs/gce.json \ --iam-account algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com gcloud projects add-iam-policy-binding ${PROJECT_ID} \ --member serviceAccount:algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com \ --role roles/compute.admin gcloud projects add-iam-policy-binding ${PROJECT_ID} \ --member serviceAccount:algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com \ --role roles/iam.serviceAccountUser ## Enable the services gcloud services enable compute.googleapis.com ./algo -e "provider=gce" -e "gce_credentials_file=$(pwd)/configs/gce.json" ``` **Attention:** take care of the `configs/gce.json` file, which contains the credentials to manage your Google Cloud account, including create and delete servers on this project. There are more advanced arguments available for deployment [using ansible](deploy-from-ansible.md). ================================================ FILE: docs/cloud-hetzner.md ================================================ ## API Token Sign in into the [Hetzner Cloud Console](https://console.hetzner.cloud/) choose a project, go to `Security` → `API Tokens`, and `Generate API Token` with `Read & Write` access. Make sure to copy the token because it won’t be shown to you again. A token is bound to a project. To interact with the API of another project you have to create a new token inside the project. ================================================ FILE: docs/cloud-linode.md ================================================ ## API Token Sign in to the Linode Manager and go to the [tokens management page](https://cloud.linode.com/profile/tokens). Click `Add a Personal Access Token`. Label your new token and select *at least* the `Linodes` read/write permission and `StackScripts` read/write permission. Press `Submit` and make sure to copy the displayed token as it won't be shown again. ================================================ FILE: docs/cloud-scaleway.md ================================================ ### Configuration file Algo requires an API key from your Scaleway account to create a server. The API key is generated by going to your Scaleway credentials at [https://console.scaleway.com/project/credentials](https://console.scaleway.com/project/credentials), and then selecting "Generate new API key" on the right side of the box labeled "API Keys". You'll be ask for to specify a purpose for your API key before it is created. You will then be presented and "Access key" and a "Secret key". Enter the "Secret key" when Algo prompts you for the `auth token`. You won't need the "Access key". This information will be pass as the `algo_scaleway_token` variable when asked for in the Algo prompt. Your organization ID is also on this page: https://console.scaleway.com/account/credentials ================================================ FILE: docs/cloud-vultr.md ================================================ ### Configuration file Algo requires an API key from your Vultr account in order to create a server. The API key is generated by going to your Vultr settings at https://my.vultr.com/settings/#settingsapi, and then selecting "generate new API key" on the right side of the box labeled "API Key". Algo can read the API key in several different ways. Algo will first look for the file containing the API key in the environment variable $VULTR_API_CONFIG if present. You can set this with the command: `export VULTR_API_CONFIG=/path/to/vultr.ini`. Probably the simplest way to give Algo the API key is to create a file titled `.vultr.ini` in your home directory by typing `nano ~/.vultr.ini`, then entering the following text: ``` [default] key = ``` where you've cut-and-pasted the API key from above into the `` field (no brackets). When Algo asks `Enter the local path to your configuration INI file (https://trailofbits.github.io/algo/cloud-vultr.html):` if you hit enter without typing anything, Algo will look for the file in `~/.vultr.ini` by default. ================================================ FILE: docs/deploy-from-ansible.md ================================================ # Deployment from Ansible Before you begin, make sure you have installed all the dependencies necessary for your operating system as described in the [README](../README.md). You can deploy Algo non-interactively by running the Ansible playbooks directly with `ansible-playbook`. `ansible-playbook` accepts variables via the `-e` or `--extra-vars` option. You can pass variables as space separated key=value pairs. Algo requires certain variables that are listed below. You can also use the `--skip-tags` option to skip certain parts of the install, such as `iptables` (overwrite iptables rules), `ipsec` (install strongSwan), `wireguard` (install Wireguard). We don't recommend using the `-t` option as it will only include the tagged portions of the deployment, and skip certain necessary roles (such as `common`). Here is a full example for DigitalOcean: ```shell ansible-playbook main.yml -e "provider=digitalocean server_name=algo ondemand_cellular=false ondemand_wifi=false dns_adblocking=true ssh_tunneling=true store_pki=true region=ams3 do_token=token" ``` See below for more information about variables and roles. ### Variables - `provider` - (Required) The provider to use. See possible values below - `server_name` - (Required) Server name. Default: algo - `ondemand_cellular` (Optional) Enables VPN On Demand when connected to cellular networks for iOS/macOS clients using IPsec. Default: false - `ondemand_wifi` - (Optional. See `ondemand_wifi_exclude`) Enables VPN On Demand when connected to WiFi networks for iOS/macOS clients using IPsec. Default: false - `ondemand_wifi_exclude` (Required if `ondemand_wifi` set) - WiFi networks to exclude from using the VPN. Comma-separated values - `dns_adblocking` - (Optional) Enables dnscrypt-proxy adblocking. Default: false - `ssh_tunneling` - (Optional) Enable SSH tunneling for each user. Default: false - `store_pki` - (Optional) Whether or not keep the CA key (required to add users in the future, but less secure). Default: false If any of the above variables are unspecified, ansible will ask the user to input them. ### Ansible roles Cloud roles can be activated by specifying an extra variable `provider`. Cloud roles: - role: cloud-digitalocean, [provider: digitalocean](#digital-ocean) - role: cloud-ec2, [provider: ec2](#amazon-ec2) - role: cloud-gce, [provider: gce](#google-compute-engine) - role: cloud-vultr, [provider: vultr](#vultr) - role: cloud-azure, [provider: azure](#azure) - role: cloud-lightsail, [provider: lightsail](#lightsail) - role: cloud-scaleway, [provider: scaleway](#scaleway) - role: cloud-openstack, [provider: openstack](#openstack) - role: cloud-cloudstack, [provider: cloudstack](#cloudstack) - role: cloud-hetzner, [provider: hetzner](#hetzner) - role: cloud-linode, [provider: linode](#linode) Server roles: - role: strongswan - Installs [strongSwan](https://www.strongswan.org/) - Enables AppArmor, limits CPU and memory access, and drops user privileges - Builds a Certificate Authority (CA) with [easy-rsa-ipsec](https://github.com/ValdikSS/easy-rsa-ipsec) and creates one client certificate per user - Bundles the appropriate certificates into Apple mobileconfig profiles for each user - role: dns_adblocking - Installs DNS encryption through [dnscrypt-proxy](https://github.com/jedisct1/dnscrypt-proxy) with blacklists to be updated daily from `adblock_lists` in `config.cfg` - note this will occur even if `dns_encryption` in `config.cfg` is set to `false` - Constrains dnscrypt-proxy with AppArmor and cgroups CPU and memory limitations - role: ssh_tunneling - Adds a restricted `algo` group with no shell access and limited SSH forwarding options - Creates one limited, local account and an SSH public key for each user - role: wireguard - Install a [Wireguard](https://www.wireguard.com/) server, with a startup script, and automatic checks for upgrades - Creates wireguard.conf files for Linux clients as well as QR codes for Apple/Android clients Note: The `strongswan` role generates Apple profiles with On-Demand Wifi and Cellular if you pass the following variables: - ondemand_wifi: true - ondemand_wifi_exclude: HomeNet,OfficeWifi - ondemand_cellular: true ### Local Installation - role: local, provider: local This role is intended to be run for local installation onto an Ubuntu server, or onto an unsupported cloud provider's Ubuntu instance. Required variables: - server - IP address of your server (or "localhost" if deploying to the local machine) - endpoint - public IP address of the server you're installing on - ssh_user - name of the SSH user you will use to install on the machine (passwordless login required). If `server=localhost`, this isn't required. - ca_password - Password for the private CA key Note that by default, the iptables rules on your existing server will be overwritten. If you don't want to overwrite the iptables rules, you can use the `--skip-tags iptables` flag. ### Digital Ocean Required variables: - do_token - region Possible options can be gathered calling to ### Amazon EC2 Required variables: - aws_access_key: `AKIA...` - aws_secret_key - region: e.g. `us-east-1` Possible options can be gathered via cli `aws ec2 describe-regions` Additional variables: - [encrypted](https://aws.amazon.com/blogs/aws/new-encrypted-ebs-boot-volumes/) - Encrypted EBS boot volume. Boolean (Default: true) - [size](https://aws.amazon.com/ec2/instance-types/) - EC2 instance type. String (Default: t3.micro) - [image](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/describe-images.html) - AMI `describe-images` search parameters to find the OS for the hosted image. Each OS and architecture has a unique AMI-ID. The OS owner, for example, [Ubuntu](https://cloud-images.ubuntu.com/locator/ec2/), updates these images often. If parameters below result in multiple results, the most recent AMI-ID is chosen ``` # Example of equivalent cli command aws ec2 describe-images --owners "099720109477" --filters "Name=architecture,Values=arm64" "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04*" ``` - [owners] - The operating system owner id. Default is [Canonical](https://help.ubuntu.com/community/EC2StartersGuide#Official_Ubuntu_Cloud_Guest_Amazon_Machine_Images_.28AMIs.29) (Default: 099720109477) - [arch] - The architecture (Default: x86_64, Optional: arm64) - [name] - The wildcard string to filter available ami names. Algo appends this name with the string "-\*64-server-\*", and prepends with "ubuntu/images/hvm-ssd/" (Default: Ubuntu latest LTS) - [instance_market_type](https://aws.amazon.com/ec2/pricing/) - Two pricing models are supported: on-demand and spot. String (Default: on-demand) - If using spot instance types, one additional IAM permission along with the below minimum is required for deployment: ``` "ec2:CreateLaunchTemplate" ``` #### Minimum required IAM permissions for deployment ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "PreDeployment", "Effect": "Allow", "Action": [ "ec2:DescribeImages", "ec2:DescribeKeyPairs", "ec2:DescribeRegions", "ec2:ImportKeyPair", "ec2:CopyImage" ], "Resource": [ "*" ] }, { "Sid": "DeployCloudFormationStack", "Effect": "Allow", "Action": [ "cloudformation:CreateStack", "cloudformation:UpdateStack", "cloudformation:DescribeStacks", "cloudformation:DescribeStackEvents", "cloudformation:ListStackResources" ], "Resource": [ "*" ] }, { "Sid": "CloudFormationEC2Access", "Effect": "Allow", "Action": [ "ec2:DescribeRegions", "ec2:CreateInternetGateway", "ec2:DescribeVpcs", "ec2:CreateVpc", "ec2:DescribeInternetGateways", "ec2:ModifyVpcAttribute", "ec2:CreateTags", "ec2:CreateSubnet", "ec2:AssociateVpcCidrBlock", "ec2:AssociateSubnetCidrBlock", "ec2:AssociateRouteTable", "ec2:AssociateAddress", "ec2:CreateRouteTable", "ec2:AttachInternetGateway", "ec2:DescribeRouteTables", "ec2:DescribeSubnets", "ec2:ModifySubnetAttribute", "ec2:CreateRoute", "ec2:CreateSecurityGroup", "ec2:DescribeSecurityGroups", "ec2:AuthorizeSecurityGroupIngress", "ec2:RunInstances", "ec2:DescribeInstances", "ec2:AllocateAddress", "ec2:DescribeAddresses" ], "Resource": [ "*" ] } ] } ``` ### Google Compute Engine Required variables: - gce_credentials_file: e.g. /configs/gce.json if you use the [GCE docs](https://trailofbits.github.io/algo/cloud-gce.html) - can also be defined in environment as GCE_CREDENTIALS_FILE_PATH - [region](https://cloud.google.com/compute/docs/regions-zones/): e.g. `useast-1` ### Vultr Required variables: - [vultr_config](https://trailofbits.github.io/algo/cloud-vultr.html): /path/to/.vultr.ini - [region](https://api.vultr.com/v1/regions/list): e.g. `Chicago`, `'New Jersey'` ### Azure Required variables: - azure_secret - azure_tenant - azure_client_id - azure_subscription_id - [region](https://azure.microsoft.com/en-us/global-infrastructure/regions/) ### Lightsail Required variables: - aws_access_key: `AKIA...` - aws_secret_key - region: e.g. `us-east-1` Possible options can be gathered via cli `aws lightsail get-regions` #### Minimum required IAM permissions for deployment ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "LightsailDeployment", "Effect": "Allow", "Action": [ "lightsail:GetRegions", "lightsail:GetInstance", "lightsail:CreateInstances", "lightsail:DisableAddOn", "lightsail:PutInstancePublicPorts", "lightsail:StartInstance", "lightsail:TagResource", "lightsail:GetStaticIp", "lightsail:AllocateStaticIp", "lightsail:AttachStaticIp" ], "Resource": [ "*" ] }, { "Sid": "DeployCloudFormationStack", "Effect": "Allow", "Action": [ "cloudformation:CreateStack", "cloudformation:UpdateStack", "cloudformation:DescribeStacks", "cloudformation:DescribeStackEvents", "cloudformation:ListStackResources" ], "Resource": [ "*" ] } ] } ``` ### Scaleway Required variables: - [scaleway_token](https://www.scaleway.com/docs/generate-an-api-token/) - region: e.g. `ams1`, `par1` ### OpenStack You need to source the rc file prior to run Algo. Download it from the OpenStack dashboard->Compute->API Access and source it in the shell (eg: source /tmp/dhc-openrc.sh) ### CloudStack > **Note:** Exoscale is no longer supported as they deprecated their CloudStack API on May 1, 2024. Required variables: - [cs_config](https://trailofbits.github.io/algo/cloud-cloudstack.html): /path/to/.cloudstack.ini - cs_region: your CloudStack region - cs_zones: your CloudStack zone The first two can also be defined in your environment, using the variables `CLOUDSTACK_CONFIG` and `CLOUDSTACK_REGION`. ### Hetzner Required variables: - hcloud_token: Your [API token](https://trailofbits.github.io/algo/cloud-hetzner.html#api-token) - can also be defined in the environment as HCLOUD_TOKEN - region: e.g. `nbg1` ### Linode Required variables: - linode_token: Your [API token](https://trailofbits.github.io/algo/cloud-linode.html#api-token) - can also be defined in the environment as LINODE_TOKEN - region: e.g. `us-east` ### Update users Playbook: ``` users.yml ``` Required variables: - server - IP or hostname to access the server via SSH - ca_password - Password to access the CA key Tags required: - update-users ================================================ FILE: docs/deploy-from-cloudshell.md ================================================ # Deploy from Google Cloud Shell If you want to try Algo but don't wish to install anything on your own system, you can use the **free** [Google Cloud Shell](https://cloud.google.com/shell/) to deploy a VPN to any supported cloud provider. Note that you cannot choose `Install to existing Ubuntu server` to turn Google Cloud Shell into your VPN server. 1. See the [Cloud Shell documentation](https://cloud.google.com/shell/docs/) to start an instance of Cloud Shell in your browser. 2. Get Algo and run it: ```bash git clone https://github.com/trailofbits/algo.git cd algo ./algo ``` The first time you run `./algo`, it will automatically install all required dependencies. Google Cloud Shell already has most tools available, making this even faster than on your local system. 3. Once Algo has completed, retrieve a copy of the configuration files that were created to your local system. While still in the Algo directory, run: ``` zip -r configs configs dl configs.zip ``` 4. Unzip `configs.zip` on your local system and use the files to configure your VPN clients. ================================================ FILE: docs/deploy-from-docker.md ================================================ # Docker Support While it is not possible to run your Algo server from within a Docker container, it is possible to use Docker to provision your Algo server. ## Limitations 1. This has not yet been tested with user namespacing enabled. 2. If you're running this on Windows, take care when editing files under `configs/` to ensure that line endings are set appropriately for Unix systems. ## Deploying an Algo Server with Docker 1. Install [Docker](https://www.docker.com/community-edition#/download) -- setup and configuration is not covered here 2. Create a local directory to hold your VPN configs (e.g. `C:\Users\trailofbits\Documents\VPNs\`) 3. Create a local copy of [config.cfg](https://github.com/trailofbits/algo/blob/master/config.cfg), with required modifications (e.g. `C:\Users\trailofbits\Documents\VPNs\config.cfg`) 4. Run the Docker container, mounting your configurations appropriately (assuming the container is named `trailofbits/algo` with a tag `latest`): - From Windows: ```powershell C:\Users\trailofbits> docker run --cap-drop=all -it \ -v C:\Users\trailofbits\Documents\VPNs:/data \ ghcr.io/trailofbits/algo:latest ``` - From Linux: ```bash $ docker run --cap-drop=all -it \ -v /home/trailofbits/Documents/VPNs:/data \ ghcr.io/trailofbits/algo:latest ``` 5. When it exits, you'll be left with a fully populated `configs` directory, containing all appropriate configuration data for your clients, and for future server management ### Providing Additional Files If you need to provide additional files -- like authorization files for Google Cloud Project -- you can simply specify an additional `-v` parameter, and provide the appropriate path when prompted by `algo`. For example, you can specify `-v C:\Users\trailofbits\Documents\VPNs\gce_auth.json:/algo/gce_auth.json`, making the local path to your credentials JSON file `/algo/gce_auth.json`. ### Scripted deployment Ansible variables (see [Deployment from Ansible](deploy-from-ansible.md)) can be passed via `ALGO_ARGS` environment variable. _The leading `-e` (or `--extra-vars`) is required_, e.g. ```bash $ ALGO_ARGS="-e provider=digitalocean server_name=algo ondemand_cellular=false ondemand_wifi=false dns_adblocking=true ssh_tunneling=true store_pki=true region=ams3 do_token=token" $ docker run --cap-drop=all -it \ -e "ALGO_ARGS=$ALGO_ARGS" \ -v /home/trailofbits/Documents/VPNs:/data \ ghcr.io/trailofbits/algo:latest ``` ## Managing an Algo Server with Docker Even though the container itself is transient, because you've persisted the configuration data, you can use the same Docker image to manage your Algo server. This is done by setting the environment variable `ALGO_ARGS`. If you want to use Algo to update the users on an existing server, specify `-e "ALGO_ARGS=update-users"` in your `docker run` command: ```powershell $ docker run --cap-drop=all -it \ -e "ALGO_ARGS=update-users" \ -v C:\Users\trailofbits\Documents\VPNs:/data \ ghcr.io/trailofbits/algo:latest ``` ## GNU Makefile for Docker You can also build and deploy with a Makefile. This simplifies some of the command strings and opens the door for further user configuration. The `Makefile` consists of three targets: `docker-build`, `docker-deploy`, and `docker-prune`. `docker-all` will run thru all of them. ## Building Your Own Docker Image You can use the Dockerfile provided in this repository as-is, or modify it to suit your needs. Further instructions on building an image can be found in the [Docker engine](https://docs.docker.com/engine/) documents. ## Security Considerations Using Docker is largely no different from running Algo yourself, with a couple of notable exceptions: we run as root within the container, and you're retrieving your content from Docker Hub. To work around the limitations of bind mounts in docker, we have to run as root within the container. To mitigate concerns around doing this, we pass the `--cap-drop=all` parameter to `docker run`, which effectively removes all privileges from the root account, reducing it to a generic user account that happens to have a userid of 0. Further steps can be taken by applying `seccomp` profiles to the container; this is being considered as a future improvement. Docker themselves provide a concept of [Content Trust](https://docs.docker.com/engine/security/trust/content_trust/) for image management, which helps to ensure that the image you download is, in fact, the image that was uploaded. Content trust is still under development, and while we may be using it, its implementation, limitations, and constraints are documented with Docker. ## Future Improvements 1. Even though we're taking care to drop all capabilities to minimize the impact of running as root, we can probably include not only a `seccomp` profile, but also AppArmor and/or SELinux profiles as well. 2. The Docker image doesn't natively support [advanced](deploy-from-ansible.md) Algo deployments, which is useful for scripting. This can be done by launching an interactive shell and running the commands yourself. 3. The way configuration is passed into and out of the container is a bit kludgy. Hopefully, future improvements in Docker volumes will make this a bit easier to handle. ## Advanced Usage If you want to poke around the Docker container yourself, you can do so by changing your `entrypoint`. Pass `--entrypoint=/bin/ash` as a parameter to `docker run`, and you'll be dropped into a full Linux shell in the container. ================================================ FILE: docs/deploy-from-macos.md ================================================ # Deploy from macOS You can install the Algo scripts on a macOS system and use them to deploy your AlgoVPN to a cloud provider. ## Installation Algo handles all Python setup automatically. Simply: 1. Get Algo: `git clone https://github.com/trailofbits/algo.git && cd algo` 2. Run Algo: `./algo` The first time you run `./algo`, it will automatically install the required Python environment (Python 3.11+) using [uv](https://docs.astral.sh/uv/), a fast Python package manager. This works on all macOS versions without any manual Python installation. ## What happens automatically When you run `./algo` for the first time: - uv is installed automatically using curl - Python 3.11+ is installed and managed by uv - All required dependencies (Ansible, etc.) are installed - Your VPN deployment begins No manual Python installation, virtual environments, or dependency management required! ================================================ FILE: docs/deploy-from-script-or-cloud-init-to-localhost.md ================================================ # Deploy from script or cloud-init You can use `install.sh` to prepare the environment and deploy AlgoVPN on the local Ubuntu server in one shot using cloud-init, or run the script directly on the server after it's been created. The script doesn't configure any parameters in your cloud, so you're on your own to configure related [firewall rules](/docs/firewalls.md), a floating IP address and other resources you may need. The output of the install script (including the p12 and CA passwords) can be found at `/var/log/algo.log`, and user config files will be installed into the `/opt/algo/configs/localhost` directory. If you need to update users later, `cd /opt/algo`, change the user list in `config.cfg`, install additional dependencies as in step 4 of the [main README](https://github.com/trailofbits/algo/blob/master/README.md), and run `./algo update-users` from that directory. ## Cloud init deployment You can copy-paste the snippet below to the user data (cloud-init or startup script) field when creating a new server. For now this has only been successfully tested on [DigitalOcean](https://www.digitalocean.com/docs/droplets/resources/metadata/), Amazon [EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) and [Lightsail](https://lightsail.aws.amazon.com/ls/docs/en/articles/lightsail-how-to-configure-server-additional-data-shell-script), [Google Cloud](https://cloud.google.com/compute/docs/startupscript), [Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init) and [Vultr](https://my.vultr.com/startup/), although Vultr doesn't [officially support cloud-init](https://www.vultr.com/docs/getting-started-with-cloud-init). ``` #!/bin/bash curl -s https://raw.githubusercontent.com/trailofbits/algo/master/install.sh | sudo -E bash -x ``` The command will prepare the environment and install AlgoVPN with the default parameters below. If you want to modify the behavior, you may define additional variables. ## Variables - `METHOD`: which method of the deployment to use. Possible values are local and cloud. Default: cloud. The cloud method is intended to use in cloud-init deployments only. If you are not using cloud-init to deploy the server, you have to use the local method. - `ONDEMAND_CELLULAR`: "Connect On Demand" when connected to cellular networks. Boolean. Default: false. - `ONDEMAND_WIFI`: "Connect On Demand" when connected to Wi-Fi. Default: false. - `ONDEMAND_WIFI_EXCLUDE`: List the names of any trusted Wi-Fi networks where macOS/iOS IPsec clients should not use "Connect On Demand". Comma-separated list. - `STORE_PKI`: To retain the PKI. (required to add users in the future, but less secure). Default: false. - `DNS_ADBLOCKING`: To install an ad blocking DNS resolver. Default: false. - `SSH_TUNNELING`: Enable SSH tunneling for each user. Default: false. - `ENDPOINT`: The public IP address or domain name of your server: (IMPORTANT! This is used to verify the certificate). It will be gathered automatically for DigitalOcean, AWS, GCE, Azure or Vultr if the `METHOD` is cloud. Otherwise, you need to define this variable according to your public IP address. - `USERS`: list of VPN users. Comma-separated list. Default: user1. - `REPO_SLUG`: Owner and repository that used to get the installation scripts from. Default: trailofbits/algo. - `REPO_BRANCH`: Branch for `REPO_SLUG`. Default: master. - `EXTRA_VARS`: Additional extra variables. - `ANSIBLE_EXTRA_ARGS`: Any available ansible parameters. ie: `--skip-tags apparmor`. ## Examples ##### How to customise a cloud-init deployment by variables ``` #!/bin/bash export ONDEMAND_CELLULAR=true export SSH_TUNNELING=true curl -s https://raw.githubusercontent.com/trailofbits/algo/master/install.sh | sudo -E bash -x ``` ##### How to deploy locally without using cloud-init ``` export METHOD=local export ONDEMAND_CELLULAR=true export ENDPOINT=[your server's IP here] curl -s https://raw.githubusercontent.com/trailofbits/algo/master/install.sh | sudo -E bash -x ``` ##### How to deploy a server using arguments The arguments order as per [variables](#variables) above ``` curl -s https://raw.githubusercontent.com/trailofbits/algo/master/install.sh | sudo -E bash -x -s local true false _null true true true true myvpnserver.com phone,laptop,desktop ``` ================================================ FILE: docs/deploy-from-windows.md ================================================ # Deploy from Windows You have three options to run Algo on Windows: 1. **PowerShell Script** (Recommended) - Automated WSL wrapper for easy use 2. **Windows Subsystem for Linux (WSL)** - Direct Linux environment access 3. **Git Bash/MSYS2** - Unix-like shell environment (limited compatibility) ## Option 1: PowerShell Script (Recommended) The PowerShell script provides the easiest Windows experience by automatically using WSL when needed: ```powershell git clone https://github.com/trailofbits/algo cd algo .\algo.ps1 ``` **How it works:** - Detects if you're already in WSL and uses the standard Unix approach - On native Windows, automatically runs Algo via WSL (since Ansible requires Unix) - Provides clear guidance if WSL isn't installed **Requirements:** - Windows Subsystem for Linux (WSL) with Ubuntu 22.04 - If WSL isn't installed, the script will guide you through installation ## Option 2: Windows Subsystem for Linux (WSL) For users who prefer a full Linux environment or need advanced features: ### Prerequisites * 64-bit Windows 10/11 (Anniversary update or later) ### Setup WSL 1. Install WSL from PowerShell (as Administrator): ```powershell wsl --install -d Ubuntu-22.04 ``` 2. After restart, open Ubuntu and create your user account ### Install Algo in WSL ```bash cd ~ git clone https://github.com/trailofbits/algo cd algo ./algo ``` **Important**: Don't install Algo in `/mnt/c` directory due to file permission issues. ### WSL Configuration (if needed) You may encounter permission issues if you clone Algo to a Windows drive (like `/mnt/c/`). Symptoms include: - **Git errors**: "fatal: could not set 'core.filemode' to 'false'" - **Ansible errors**: "ERROR! Skipping, '/mnt/c/.../ansible.cfg' as it is not safe to use as a configuration file" - **SSH key errors**: "WARNING: UNPROTECTED PRIVATE KEY FILE!" or "Permissions 0777 for key are too open" If you see these errors, configure WSL: 1. Edit `/etc/wsl.conf` to allow metadata: ```ini [automount] options = "metadata" ``` 2. Restart WSL completely: ```powershell wsl --shutdown ``` 3. Fix directory permissions for Ansible: ```bash chmod 744 . ``` **Why this happens**: Windows filesystems mounted in WSL (`/mnt/c/`) don't support Unix file permissions by default. Git can't set executable bits, and Ansible refuses to load configs from "world-writable" directories for security. After deployment, copy configs to Windows: ```bash cp -r configs /mnt/c/Users/$USER/ ``` ## Option 3: Git Bash/MSYS2 If you have Git for Windows installed, you can use the included Git Bash terminal: ```bash git clone https://github.com/trailofbits/algo cd algo ./algo ``` **Pros**: - Uses the standard Unix `./algo` script - No WSL setup required - Familiar Unix-like environment **Cons**: - **Limited compatibility**: Ansible may not work properly due to Windows/Unix differences - **Not officially supported**: May encounter unpredictable issues - Less robust than WSL or PowerShell options - Requires Git for Windows installation **Note**: This approach is not recommended due to Ansible's Unix requirements. Use WSL-based options instead. ================================================ FILE: docs/deploy-to-ubuntu.md ================================================ # Local Installation **IMPORTANT**: Algo is designed to create a dedicated VPN server. There is no uninstallation option. Installing Algo on an existing server may break existing services, especially since firewall rules will be overwritten. See [AlgoVPN and Firewalls](/docs/firewalls.md) for details. ## Requirements Algo currently supports **Ubuntu 22.04 LTS only**. Your target server must be running an unmodified installation of Ubuntu 22.04. ## Installation You can install Algo on an existing Ubuntu server instead of creating a new cloud instance. This is called a **local** installation. If you're new to Algo or Linux, cloud deployment is easier. 1. Follow the normal Algo installation instructions 2. When prompted, choose: `Install to existing Ubuntu latest LTS server (for advanced users)` 3. The target can be: - The same system where you installed Algo (requires `sudo ./algo`) - A remote Ubuntu server accessible via SSH without password prompts (use `ssh-agent`) For local installation on the same machine, you must run: ```bash sudo ./algo ``` ## Confirmation Prompt Local installation displays a warning and requires you to type `yes` to proceed. This ensures you understand that Algo will modify firewall rules and system settings, and that there is no uninstall option. For automated deployments or CI/CD pipelines, skip the confirmation with: ```bash ansible-playbook main.yml -e "provider=local local_install_confirmed=true server=localhost endpoint=YOUR_IP" ``` Only use `local_install_confirmed=true` when you have already taken a backup and understand the risks. ## Road Warrior Setup A "road warrior" setup lets you securely access your home network and its resources when traveling. This involves installing Algo on a server within your home LAN. **Network Configuration:** - Forward the necessary ports from your router to the Algo server (see [firewall documentation](/docs/firewalls.md#external-firewall)) **Algo Configuration** (edit `config.cfg` before deployment): - Set `BetweenClients_DROP` to `false` (allows VPN clients to reach your LAN) - Consider setting `block_smb` and `block_netbios` to `false` (enables SMB/NetBIOS traffic) - For local DNS resolution (e.g., Pi-hole), set `dns_encryption` to `false` and update `dns_servers` to your local DNS server IP ================================================ FILE: docs/deploy-to-unsupported-cloud.md ================================================ # Deploying to Unsupported Cloud Providers Algo officially supports the [cloud providers listed in the README](https://github.com/trailofbits/algo/blob/master/README.md#deploy-the-algo-server). If you want to deploy Algo on another cloud provider, that provider must meet specific technical requirements for compatibility. ## Technical Requirements Your cloud provider must support: 1. **Ubuntu 22.04 LTS** - Algo exclusively supports Ubuntu 22.04 LTS as the base operating system 2. **Required kernel modules** - Specific modules needed for strongSwan IPsec and WireGuard VPN functionality 3. **Network capabilities** - Full networking stack access, not containerized environments ## Compatibility Testing Before attempting to deploy Algo on an unsupported provider, test compatibility using strongSwan's kernel module checker: 1. Deploy a basic Ubuntu 22.04 LTS instance on your target provider 2. Run the [kernel module compatibility script](https://wiki.strongswan.org/projects/strongswan/wiki/KernelModules) from strongSwan 3. Verify all required modules are available and loadable The script will identify any missing kernel modules that would prevent Algo from functioning properly. ## Adding Official Support For Algo to officially support a new cloud provider, the provider must have: - An available Ansible [cloud module](https://docs.ansible.com/ansible/list_of_cloud_modules.html) - Reliable API for programmatic instance management - Consistent Ubuntu 22.04 LTS image availability If no Ansible module exists for your provider: 1. Check Ansible's [open issues](https://github.com/ansible/ansible/issues) and [pull requests](https://github.com/ansible/ansible/pulls) for existing development efforts 2. Consider developing the module yourself using the [Ansible module developer documentation](https://docs.ansible.com/ansible/dev_guide/developing_modules.html) 3. Reference your provider's API documentation for implementation details ## Unsupported Environments ### Container-Based Hosting Providers using **OpenVZ**, **Docker containers**, or other **containerized environments** cannot run Algo because: - Container environments don't provide access to kernel modules - VPN functionality requires low-level network interface access - IPsec and WireGuard need direct kernel interaction For more details, see strongSwan's [Cloud Platforms documentation](https://wiki.strongswan.org/projects/strongswan/wiki/Cloudplatforms). ### Userland IPsec (libipsec) Some providers attempt to work around kernel limitations using strongSwan's [kernel-libipsec](https://wiki.strongswan.org/projects/strongswan/wiki/Kernel-libipsec) plugin, which implements IPsec entirely in userspace. **Algo does not support libipsec** for these reasons: - **Performance issues** - Buffers each packet in memory, causing performance degradation - **Resource consumption** - Can cause out-of-memory conditions on resource-constrained systems - **Stability concerns** - May crash the charon daemon or lock up the host system - **Security implications** - Less thoroughly audited than kernel implementations - **Added complexity** - Introduces additional code paths that increase attack surface We strongly recommend choosing a provider that supports native kernel modules rather than attempting workarounds. ## Alternative Deployment Options If your preferred provider doesn't support Algo's requirements: 1. **Use a supported provider** - Deploy on AWS, DigitalOcean, Azure, GCP, or another [officially supported provider](https://github.com/trailofbits/algo/blob/master/README.md#deploy-the-algo-server) 2. **Deploy locally** - Use the [Ubuntu server deployment option](deploy-to-ubuntu.md) on your own hardware 3. **Hybrid approach** - Deploy the VPN server on a supported provider while using your preferred provider for other services ## Contributing Support If you successfully deploy Algo on an unsupported provider and want to contribute official support: 1. Ensure the provider meets all technical requirements 2. Verify consistent deployment success across multiple regions 3. Create an Ansible module or verify existing module compatibility 4. Document the deployment process and any provider-specific considerations 5. Submit a pull request with your implementation Community contributions to expand provider support are welcome, provided they meet Algo's security and reliability standards. ================================================ FILE: docs/faq.md ================================================ # FAQ * [Has Algo been audited?](#has-algo-been-audited) * [What's the current status of WireGuard?](#whats-the-current-status-of-wireguard) * [Why aren't you using Tor?](#why-arent-you-using-tor) * [Why aren't you using Racoon, LibreSwan, or OpenSwan?](#why-arent-you-using-racoon-libreswan-or-openswan) * [Why aren't you using a memory-safe or verified IKE daemon?](#why-arent-you-using-a-memory-safe-or-verified-ike-daemon) * [Why aren't you using OpenVPN?](#why-arent-you-using-openvpn) * [Why aren't you using Alpine Linux or OpenBSD?](#why-arent-you-using-alpine-linux-or-openbsd) * [Why does Algo support only a single cipher suite?](#why-does-algo-support-only-a-single-cipher-suite) * [Why doesn't Algo support censorship circumvention?](#why-doesnt-algo-support-censorship-circumvention) * [I deployed an Algo server. Can you update it with new features?](#i-deployed-an-algo-server-can-you-update-it-with-new-features) * [Can I migrate my existing clients to a new Algo server?](#can-i-migrate-my-existing-clients-to-a-new-algo-server) * [Where did the name "Algo" come from?](#where-did-the-name-algo-come-from) * [Can DNS filtering be disabled?](#can-dns-filtering-be-disabled) * [Does Algo support zero logging?](#does-algo-support-zero-logging) * [Wasn't IPSEC backdoored by the US government?](#wasnt-ipsec-backdoored-by-the-us-government) * [What inbound ports are used?](#what-inbound-ports-are-used) * [How do I monitor user activity?](#how-do-i-monitor-user-activity) * [How do I reach another connected client?](#how-do-i-reach-another-connected-client) ## Has Algo been audited? No. This project is under active development. We're happy to [accept and fix issues](https://github.com/trailofbits/algo/issues) as they are identified. Use Algo at your own risk. If you find a security issue of any severity, please [contact us on Slack](https://slack.empirehacking.nyc). ## What's the current status of WireGuard? [WireGuard reached "stable" 1.0.0 release](https://lists.zx2c4.com/pipermail/wireguard/2020-March/005206.html) in Spring 2020. It has undergone [substantial](https://www.wireguard.com/formal-verification/) security review. ## Why aren't you using Tor? The goal of this project is not to provide anonymity, but to ensure confidentiality of network traffic. Tor introduces new risks that are unsuitable for Algo's intended users. Namely, with Algo, users are in control over the gateway routing their traffic. With Tor, users are at the mercy of [actively](https://www.securityweek2016.tu-darmstadt.de/fileadmin/user_upload/Group_securityweek2016/pets2016/10_honions-sanatinia.pdf) [malicious](https://web.archive.org/web/20150705184539/https://chloe.re/2015/06/20/a-month-with-badonions/) [exit](https://community.fireeye.com/people/archit.mehta/blog/2014/11/18/onionduke-apt-malware-distributed-via-malicious-tor-exit-node) [nodes](https://www.wired.com/2010/06/wikileaks-documents/). ## Why aren't you using Racoon, LibreSwan, or OpenSwan? Racoon does not support IKEv2. Racoon2 supports IKEv2 but is not actively maintained. When we looked, the documentation for strongSwan was better than the corresponding documentation for LibreSwan or OpenSwan. strongSwan also has the benefit of a from-scratch rewrite to support IKEv2. I consider such rewrites a positive step when supporting a major new protocol version. ## Why aren't you using a memory-safe or verified IKE daemon? I would, but I don't know of any [suitable ones](https://github.com/trailofbits/algo/issues/68). If you're in the position to fund the development of such a project, [contact us](mailto:info@trailofbits.com). We would be interested in leading such an effort. At the very least, I plan to make modifications to strongSwan and the environment it's deployed in that prevent or significantly complicate exploitation of any latent issues. ## Why aren't you using OpenVPN? OpenVPN does not have out-of-the-box client support on any major desktop or mobile operating system. This introduces user experience issues and requires the user to [update](https://www.exploit-db.com/exploits/34037/) and [maintain](https://www.exploit-db.com/exploits/20485/) the software themselves. OpenVPN depends on the security of [TLS](https://tools.ietf.org/html/rfc7457), both the [protocol](https://arstechnica.com/security/2016/08/new-attack-can-pluck-secrets-from-1-of-https-traffic-affects-top-sites/) and its [implementations](https://arstechnica.com/security/2014/04/confirmed-nasty-heartbleed-bug-exposes-openvpn-private-keys-too/), and we simply trust the server less due to [past](https://sweet32.info/) [security](https://github.com/ValdikSS/openvpn-fix-dns-leak-plugin/blob/master/README.md) [incidents](https://www.exploit-db.com/exploits/34879/). ## Why aren't you using Alpine Linux or OpenBSD? Alpine Linux is not supported out-of-the-box by any major cloud provider. While we considered BSD variants in the past, Algo now focuses exclusively on Ubuntu LTS for consistency, security, and maintainability. ## Why does Algo support only a single cipher suite? Algo deliberately supports only one modern cipher suite (AES256-GCM with SHA2 and P-256) rather than offering a menu of cryptographic options. This design decision enhances security by: 1. **Eliminating downgrade attacks** - With no weaker ciphers available, attackers cannot force connections to use vulnerable algorithms 2. **Reducing complexity** - A single, well-tested configuration minimizes the chance of implementation errors 3. **Ensuring modern clients only** - This approach naturally filters out outdated systems that might have unpatched vulnerabilities 4. **Simplifying audits** - Security researchers can focus on validating one strong configuration rather than multiple combinations The chosen cipher suite (AES256-GCM-SHA512 with ECP384) represents current cryptographic best practices and is supported by all modern operating systems (macOS 10.11+, iOS 10+, Windows 10+, and current Linux distributions). If your device doesn't support this cipher suite, it's likely outdated and shouldn't be trusted for secure communications anyway. ## Why doesn't Algo support censorship circumvention? Algo is designed for privacy and security, not censorship avoidance. This distinction is important for several reasons: 1. **Different threat models** - Censorship circumvention requires techniques like traffic obfuscation and protocol mimicry that add complexity and potential vulnerabilities. Algo focuses on protecting your data from eavesdroppers and ensuring confidential communications. 2. **Legal considerations** - Operating VPNs to bypass censorship is illegal in several countries. We don't want to encourage users to break local laws or put themselves at legal risk. 3. **Security focus** - Adding censorship circumvention tools would expand our codebase significantly, making it harder to audit and maintain the high security standards Algo promises. Each additional component is a potential attack vector. 4. **Separation of concerns** - Tools like Tor, Shadowsocks, and V2Ray are specifically designed for censorship circumvention with teams dedicated to that cat-and-mouse game. Algo maintains its effectiveness by staying focused on its core mission: providing a secure, private VPN that "just works." If you need to bypass censorship, consider purpose-built tools designed for that specific threat model. Algo will give you privacy from your ISP and security on untrusted networks, but it won't hide the fact that you're using a VPN or help you access blocked content in restrictive countries. ## I deployed an Algo server. Can you update it with new features? No. By design, the Algo development team has no access to any Algo server that our users have deployed. We cannot modify the configuration, update the software, or sniff the traffic that goes through your personal Algo VPN server. This prevents scenarios where we are legally compelled or hacked to push down backdoored updates that surveil our users. As a result, once your Algo server has been deployed, it is yours to maintain. It will use unattended-upgrades by default to apply security and feature updates to Ubuntu, as well as to the core VPN software of strongSwan, dnscrypt-proxy and WireGuard. However, if you want to take advantage of new features available in the current release of Algo, then you have two options. You can use the [SSH administrative interface](/README.md#ssh-into-algo-server) to make the changes you want on your own or you can shut down the server and deploy a new one (recommended). As an extension of this rationale, most configuration options (other than users) available in `config.cfg` can only be set at the time of initial deployment. ## Can I migrate my existing clients to a new Algo server? Technically yes, but it's rarely worth the effort. WireGuard clients would need their server endpoint and public key updated. IPsec clients additionally require securely copying the CA certificate and potentially regenerating client certificates. Since your existing server auto-updates its VPN software via unattended-upgrades, there's usually no benefit to migrating—you already have the latest security patches for strongSwan, WireGuard, and dnscrypt-proxy. If you need features from a newer Algo release, deploy a fresh server and redistribute new client configs. This is simpler and more secure than attempting key migration. ## Where did the name "Algo" come from? Algo is short for "Al Gore", the **V**ice **P**resident of **N**etworks everywhere for [inventing the Internet](https://www.youtube.com/watch?v=BnFJ8cHAlco). ## Can DNS filtering be disabled? You can temporarily disable DNS filtering for all IPsec clients at once with the following workaround: SSH to your Algo server (using the 'shell access' command printed upon a successful deployment), edit `/etc/ipsec.conf`, and change `rightdns=` to `rightdns=8.8.8.8`. Then run `sudo systemctl restart strongswan`. DNS filtering for WireGuard clients has to be disabled on each client device separately by modifying the settings in the app, or by directly modifying the `DNS` setting on the `clientname.conf` file. If all else fails, we recommend deploying a new Algo server without the adblocking feature enabled. ## Does Algo support zero logging? Yes, Algo includes privacy enhancements that minimize logging by default. StrongSwan connection logging is disabled, DNSCrypt syslog is turned off, and logs are automatically rotated after 7 days. However, some system-level logging remains for security and troubleshooting purposes. For detailed privacy configuration and limitations, see the [Privacy and Logging](#privacy-and-logging) section in the README. ## Wasn't IPSEC backdoored by the US government? No. [Per security researcher Thomas Ptacek](https://news.ycombinator.com/item?id=2014197): > In 2001, Angelos Keromytis --- then a grad student at Penn, now a Columbia professor --- added support for hardware-accelerated IPSEC NICs. When you have an IPSEC NIC, the channel between the NIC and the IPSEC stack keeps state to tell the stack not to bother doing the things the NIC already did, among them validating the IPSEC ESP authenticator. Angelos' code had a bug; it appears to have done the software check only when the hardware had already done it, and skipped it otherwise. > > The bug happened during a change that simultaneously refactored and added a feature to OpenBSD's ESP code; a comparison that should have been == was instead !=; the "if" statement with the bug was originally and correctly !=, but should have been flipped based on how the code was refactored. > > HD Moore may as we speak be going through the pain of reconstituting a nearly decade-old version of OpenBSD to verify the bug, but stipulate that it was there, and here's what you get: IPSEC ESP packet authentication was disabled if you didn't have hardware IPSEC. There is probably an elaborate man-in-the-middle scenario in which this could get you traffic inspection, but it's nowhere nearly as straightforward as leaking key bits. > > To entertain the conspiracy theory, you're still suggesting that the FBI not only introduced this bug, but also developed the technology required to MITM ESP sessions, bouncing them through some secret FBI-developed middlebox. > > One year later, Jason Wright from NETSEC (the company at the heart of the [I think silly] allegations about OpenBSD IPSEC backdoors) fixed the bug. > > It's interesting that the bug was fixed without an advisory (oh to be a fly on the wall on ICB that day; Theo had a, um, a, "way" with his dev team). On the other hand, we don't know what releases of OpenBSD actually had the bug right now. > > It seems vanishingly unlikely that there could have been anything deliberate about this series of changes. You are unlikely to find anyone who will impugn Angelos. Meanwhile, the diffs tell exactly the opposite of the story that Greg Perry told. ## What inbound ports are used? You should only need 4160/TCP, 500/UDP, 4500/UDP, and 51820/UDP opened on any firewall that sits between your clients and your Algo server. See [AlgoVPN and Firewalls](/docs/firewalls.md) for more information. ## How do I monitor user activity? Your Algo server will track IPsec client logins by default in `/var/log/syslog`. This will give you client names, date/time of connection and reconnection, and what IP addresses they're connecting from. This can be disabled entirely by setting `strongswan_log_level` to `-1` in `config.cfg`. WireGuard doesn't save any logs, but entering `sudo wg` on the server will give you the last endpoint and contact time of each client. Disabling this is [paradoxically difficult](https://git.zx2c4.com/blind-operator-mode/about/). There isn't any out-of-the-box way to monitor actual user _activity_ (e.g. websites browsed, etc.) ## How do I reach another connected client? By default, your Algo server doesn't allow connections between connected clients. This can be changed at the time of deployment by enabling the `BetweenClients_DROP` flag in `config.cfg`. See the ["Road Warrior" instructions](/docs/deploy-to-ubuntu.md#road-warrior-setup) for more details. ================================================ FILE: docs/firewalls.md ================================================ # AlgoVPN and Firewalls Your AlgoVPN requires properly configured firewalls. The key points to know are: * If you deploy to a **cloud** provider all firewall configuration will done automatically. * If you perform a **local** installation on an existing server you are responsible for configuring any external firewalls. You must also take care not to interfere with the server firewall configuration of the AlgoVPN. ## The Two Types of Firewall ![Firewall Illustration](/docs/images/firewalls.png) ### Server Firewall During installation Algo configures the Linux [Netfilter](https://en.wikipedia.org/wiki/Netfilter) firewall on the server. The rules added are required for AlgoVPN to work properly. The package `netfilter-persistent` is used to load the IPv4 and IPv6 rules files that Algo generates and stores in `/etc/iptables`. The rules for IPv6 are only generated if the server appears to be properly configured for IPv6. The use of conflicting firewall packages on the server such as `ufw` will likely break AlgoVPN. ### External Firewall Most cloud service providers offer a firewall that sits between the Internet and your AlgoVPN. With some providers (such as EC2, Lightsail, and GCE) this firewall is required and is configured by Algo during a **cloud** deployment. If the firewall is not required by the provider then Algo does not configure it. External firewalls are not configured when performing a **local** installation, even when using a server from a cloud service provider. Any external firewall must be configured to pass the following incoming ports over IPv4 : Port | Protocol | Description | Related variables in `config.cfg` ---- | -------- | ----------- | --------------------------------- 4160 | TCP | Secure Shell (SSH) | `ssh_port` (**cloud** only; for **local** port remains 22) 500 | UDP | IPsec IKEv2 | `ipsec_enabled` 4500 | UDP | IPsec NAT-T | `ipsec_enabled` 51820 | UDP | WireGuard | `wireguard_enabled`, `wireguard_port` If you have chosen to disable either IPsec or WireGuard in `config.cfg` before running `./algo` then the corresponding ports don't need to pass through the firewall. SSH is used when performing a **cloud** deployment and when subsequently modifying the list of VPN users by running `./algo update-users`. Even when not required by the cloud service provider, you still might wish to use an external firewall to limit SSH access to your AlgoVPN to connections from certain IP addresses, or perhaps to block SSH access altogether if you don't need it. Every service provider firewall is different so refer to the provider's documentation for more information. ================================================ FILE: docs/index.md ================================================ # Algo VPN documentation * Deployment instructions - Deploy from [RedHat/CentOS 6.x](deploy-from-redhat-centos6.md) - Deploy from [Windows](deploy-from-windows.md) - Deploy from a [Docker container](deploy-from-docker.md) - Deploy from [Ansible](deploy-from-ansible.md) non-interactively - Deploy onto a [cloud server at time of creation with shell script or cloud-init](deploy-from-script-or-cloud-init-to-localhost.md) - Deploy from [macOS](deploy-from-macos.md) - Deploy from [Google Cloud Shell](deploy-from-cloudshell.md) * Client setup - Setup [Android](client-android.md) clients - Setup [Generic/Linux](client-linux.md) clients with Ansible - Setup Ubuntu clients to use [WireGuard](client-linux-wireguard.md) - Setup Linux clients to use [IPsec](client-linux-ipsec.md) - Setup Apple devices to use [IPsec](client-apple-ipsec.md) - Setup Macs running macOS 10.13 or older to use [WireGuard](client-macos-wireguard.md) * Cloud provider setup - Configure [Amazon EC2](cloud-amazon-ec2.md) - Configure [Azure](cloud-azure.md) - Configure [DigitalOcean](cloud-do.md) - Configure [Google Cloud Platform](cloud-gce.md) - Configure [Vultr](cloud-vultr.md) - Configure [CloudStack](cloud-cloudstack.md) - Configure [Hetzner Cloud](cloud-hetzner.md) * Advanced Deployment - Deploy to your own [Ubuntu](deploy-to-ubuntu.md) server, and road warrior setup - Deploy to an [unsupported cloud provider](deploy-to-unsupported-cloud.md) * [FAQ](faq.md) * [Firewalls](firewalls.md) * [Troubleshooting](troubleshooting.md) ================================================ FILE: docs/troubleshooting.md ================================================ # Troubleshooting First of all, check [this](https://github.com/trailofbits/algo#features) and ensure that you are deploying to Ubuntu 22.04 LTS, the only supported server platform. * [Installation Problems](#installation-problems) * General Setup * [Python version is not supported](#python-version-is-not-supported) * [Error: "ansible-playbook: command not found"](#error-ansible-playbook-command-not-found) * [Fatal: "Failed to validate the SSL certificate for ..."](#fatal-failed-to-validate-the-SSL-certificate) * [Bad owner or permissions on .ssh](#bad-owner-or-permissions-on-ssh) * Cloud Providers * [The region you want is not available](#the-region-you-want-is-not-available) * [AWS: SSH permission denied with an ECDSA key](#aws-ssh-permission-denied-with-an-ecdsa-key) * [AWS: "Deploy the template" fails with CREATE_FAILED](#aws-deploy-the-template-fails-with-create_failed) * [AWS: not authorized to perform: cloudformation:UpdateStack](#aws-not-authorized-to-perform-cloudformationupdatestack) * [Azure: No such file or directory .azure/azureProfile.json](#azure-no-such-file-or-directory-homeusernameazureazureprofilejson) * [Azure: Deployment Permissions Error](#azure-deployment-permissions-error) * [Linode: Stackscript error](#linode-error-unable-to-query-the-linode-api-saw-400-the-requested-distribution-is-not-supported-by-this-stackscript-) * Windows * [Windows: The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid](#windows-the-value-of-parameter-linuxconfigurationsshpublickeyskeydata-is-invalid) * [Windows: "The parameter is incorrect" error when connecting](#windows-the-parameter-is-incorrect-error-when-connecting) * Local Deployment * [Error: Failed to create symlinks for deploying to localhost](#error-failed-to-create-symlinks-for-deploying-to-localhost) * [Wireguard: Unable to find 'configs/...' in expected paths](#wireguard-unable-to-find-configs-in-expected-paths) * Network * [Timeout when waiting for search string OpenSSH](#old-networking-firewall-in-place) * [Connection Problems](#connection-problems) * [I'm blocked or get CAPTCHAs when I access certain websites](#im-blocked-or-get-captchas-when-i-access-certain-websites) * [I want to change the list of trusted Wifi networks on my Apple device](#i-want-to-change-the-list-of-trusted-wifi-networks-on-my-apple-device) * [Error: "The VPN Service payload could not be installed."](#error-the-vpn-service-payload-could-not-be-installed) * [Little Snitch is broken when connected to the VPN](#little-snitch-is-broken-when-connected-to-the-vpn) * [I can't get my router to connect to the Algo server](#i-cant-get-my-router-to-connect-to-the-algo-server) * [Various websites appear to be offline through the VPN](#various-websites-appear-to-be-offline-through-the-vpn) * [Clients appear stuck in a reconnection loop](#clients-appear-stuck-in-a-reconnection-loop) * [Wireguard: clients can connect on Wifi but not LTE](#wireguard-clients-can-connect-on-wifi-but-not-lte) * [IPsec: Difficulty connecting through router](#ipsec-difficulty-connecting-through-router) * [Diagnostic Commands](#diagnostic-commands) * [Enable Verbose Logging](#enable-verbose-logging) * [Server-Side Diagnostics](#server-side-diagnostics) * [Client-Side Diagnostics](#client-side-diagnostics) * [I have a problem not covered here](#i-have-a-problem-not-covered-here) ## Installation Problems Look here if you have a problem running the installer to set up a new Algo server. ### Python version is not supported The minimum Python version required to run Algo is 3.11. Most modern operation systems should have it by default, but if the OS you are using doesn't meet the requirements, you have to upgrade. See the official documentation for your OS, or manual download it from https://www.python.org/downloads/. Otherwise, you may [deploy from docker](deploy-from-docker.md) ### Error: "ansible-playbook: command not found" You tried to install Algo and you see an error that reads "ansible-playbook: command not found." This indicates that Ansible is not installed or not available in your PATH. Algo automatically installs all dependencies (including Ansible) using uv when you run `./algo` for the first time. If you're seeing this error, try running `./algo` again - it should automatically install the required Python environment and dependencies. If the issue persists, ensure you're running `./algo` from the Algo project directory. ### Fatal: "Failed to validate the SSL certificate" You received a message like this: ``` fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to validate the SSL certificate for api.digitalocean.com:443. Make sure your managed systems have a valid CA certificate installed. You can use validate_certs=False if you do not need to confirm the servers identity but this is unsafe and not recommended. Paths checked for this platform: /etc/ssl/certs, /etc/ansible, /usr/local/etc/openssl. The exception msg was: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076).", "status": -1, "url": "https://api.digitalocean.com/v2/regions"} ``` Your local system does not have a CA certificate that can validate the cloud provider's API. This typically occurs with custom Python installations. Try reinstalling Python using Homebrew (`brew install python3`) or ensure your system has proper CA certificates installed. ### Bad owner or permissions on .ssh You tried to run Algo and it quickly exits with an error about a bad owner or permissions: ``` fatal: [104.236.2.94]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Bad owner or permissions on /home/user/.ssh/config\r\n", "unreachable": true} ``` You need to reset the permissions on your `.ssh` directory. Run `chmod 700 /home/user/.ssh` and then `chmod 600 /home/user/.ssh/config`. You may need to repeat this for other files mentioned in the error message. ### The region you want is not available Algo downloads the regions from the supported cloud providers (other than Microsoft Azure) listed in the first menu using APIs. If the region you want isn't available, the cloud provider has probably taken it offline for some reason. You should investigate further with your cloud provider. If there's a specific region you want to install to in Microsoft Azure that isn't available, you should [file an issue](https://github.com/trailofbits/algo/issues/new), give us information about what region is missing, and we'll add it. ### AWS: SSH permission denied with an ECDSA key You tried to deploy Algo to AWS and you received an error like this one: ``` TASK [Copy the algo ssh key to the local ssh directory] ************************ ok: [localhost -> localhost] PLAY [Configure the server and install required software] ********************** TASK [Check the system] ******************************************************** fatal: [X.X.X.X]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added 'X.X.X.X' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey).\r\n", "unreachable": true} ``` You previously deployed Algo to a hosting provider other than AWS, and Algo created an ECDSA keypair at that time. You are now deploying to AWS which [does not support ECDSA keys](https://aws.amazon.com/certificate-manager/faqs/) via their API. As a result, the deploy has failed. In order to fix this issue, delete the `algo.pem` and `algo.pem.pub` keys from your `configs` directory and run the deploy again. If AWS is selected, Algo will now generate new RSA ssh keys which are compatible with the AWS API. ### AWS: "Deploy the template fails" with CREATE_FAILED You tried to deploy Algo to AWS and you received an error like this one: ``` TASK [cloud-ec2 : Make a cloudformation template] ****************************** changed: [localhost] TASK [cloud-ec2 : Deploy the template] ***************************************** fatal: [localhost]: FAILED! => {"changed": true, "events": ["StackEvent AWS::CloudFormation::Stack algopvpn1 ROLLBACK_COMPLETE", "StackEvent AWS::EC2::VPC VPC DELETE_COMPLETE", "StackEvent AWS::EC2::InternetGateway InternetGateway DELETE_COMPLETE", "StackEvent AWS::CloudFormation::Stack algopvpn1 ROLLBACK_IN_PROGRESS", "StackEvent AWS::EC2::VPC VPC CREATE_FAILED", "StackEvent AWS::EC2::VPC VPC CREATE_IN_PROGRESS", "StackEvent AWS::EC2::InternetGateway InternetGateway CREATE_FAILED", "StackEvent AWS::EC2::InternetGateway InternetGateway CREATE_IN_PROGRESS", "StackEvent AWS::CloudFormation::Stack algopvpn1 CREATE_IN_PROGRESS"], "failed": true, "output": "Problem with CREATE. Rollback complete", "stack_outputs": {}, "stack_resources": [{"last_updated_time": null, "logical_resource_id": "InternetGateway", "physical_resource_id": null, "resource_type": "AWS::EC2::InternetGateway", "status": "DELETE_COMPLETE", "status_reason": null}, {"last_updated_time": null, "logical_resource_id": "VPC", "physical_resource_id": null, "resource_type": "AWS::EC2::VPC", "status": "DELETE_COMPLETE", "status_reason": null}]} ``` Algo builds a [Cloudformation](https://aws.amazon.com/cloudformation/) template to deploy to AWS. You can find the entire contents of the Cloudformation template in `configs/algo.yml`. In order to troubleshoot this issue, login to the AWS console, go to the Cloudformation service, find the failed deployment, click the events tab, and find the corresponding "CREATE_FAILED" events. Note that all AWS resources created by Algo are tagged with `Environment => Algo` for easy identification. In many cases, failed deployments are the result of [service limits](http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html) being reached, such as "CREATE_FAILED AWS::EC2::VPC VPC The maximum number of VPCs has been reached." In these cases, you must either [delete the VPCs from previous deployments](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/working-with-vpcs.html#VPC_Deleting), or [contact AWS support](https://console.aws.amazon.com/support/home?region=us-east-1#/case/create?issueType=service-limit-increase&limitType=service-code-direct-connect) to increase the limits on your account. ### AWS: not authorized to perform: cloudformation:UpdateStack You tried to deploy Algo to AWS and you received an error like this one: ``` TASK [cloud-ec2 : Deploy the template] ***************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "User: arn:aws:iam::082851645362:user/algo is not authorized to perform: cloudformation:UpdateStack on resource: arn:aws:cloudformation:us-east-1:082851645362:stack/algo/*"} ``` This error indicates you already have Algo deployed to Cloudformation. Need to [delete it](cloud-amazon-ec2.md#cleanup) first, then re-deploy. ### Azure: No such file or directory: '/home/username/.azure/azureProfile.json' ``` TASK [cloud-azure : Create AlgoVPN Server] ***************************************************************************************************************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/.azure/azureProfile.json' fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last): File \"/usr/local/lib/python3.11/dist-packages/azure/cli/core/_session.py\", line 39, in load with codecs_open(self.filename, 'r', encoding=self._encoding) as f: File \"/usr/lib/python3.11/codecs.py\", line 897, in open\n file = builtins.open(filename, mode, buffering) FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/.azure/azureProfile.json' ", "module_stdout": "", "msg": "MODULE FAILURE See stdout/stderr for the exact error", "rc": 1} ``` It happens when your machine is not authenticated in the azure cloud, follow this [guide](https://trailofbits.github.io/algo/cloud-azure.html) to configure your environment ### Azure: Deployment Permissions Error The AAD Application Registration (aka, the 'Service Principal', where you got the ClientId) needs permission to create the resources for the subscription. Otherwise, you will get the following error when you run the Ansible deploy script: ``` fatal: [localhost]: FAILED! => {"changed": false, "msg": "Resource group create_or_update failed with status code: 403 and message: The client 'xxxxx' with object id 'THE_OBJECT_ID' does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/write' over scope '/subscriptions/THE_SUBSCRIPTION_ID/resourcegroups/algo' or the scope is invalid. If access was recently granted, please refresh your credentials."} ``` The solution for this is to open the Azure CLI and run the following command to grant contributor role to the Service Principal: ``` az role assignment create --assignee-object-id THE_OBJECT_ID --scope subscriptions/THE_SUBSCRIPTION_ID --role contributor ``` After this is applied, the Service Principal has permissions to create the resources and you can re-run `ansible-playbook main.yml` to complete the deployment. ### Linode Error: "Unable to query the Linode API. Saw: 400: The requested distribution is not supported by this stackscript.; " StackScript is a custom deployment script that defines a set of configurations for a Linode instance (e.g. which distribution, specs, etc.). if you used algo with default values in the past deployments, a stackscript that would've been created is 're-used' in the deployment process (in fact, go see 'create Linodes' and under 'StackScripts' tab). Thus, there's a little chance that your deployment process will generate this 'unsupported stackscript' error due to a pre-existing StackScript that doesn't support a particular configuration setting or value due to an 'old' stackscript. The quickest solution is just to change the name of your deployment from the default value of 'algo' (or any other name that you've used before, again see the dashboard) and re-run the deployment. ### Windows: The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid You tried to deploy Algo from Windows and you received an error like this one: ``` TASK [cloud-azure : Create an instance]. fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error creating or updating virtual machine AlgoVPN - Azure Error: InvalidParameter\n Message: The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid.\n Target: linuxConfiguration.ssh.publicKeys.keyData"} ``` This is related to [the chmod issue](https://github.com/Microsoft/WSL/issues/81) inside /mnt directory which is NTFS. The fix is to place Algo outside of /mnt directory. ### Windows: "The parameter is incorrect" error when connecting When trying to connect to your Algo VPN on Windows 10/11, you may receive an error stating "The parameter is incorrect". This is a common issue that can usually be resolved by resetting your Windows networking stack. #### Solution 1. **Clear the networking caches** Open Command Prompt as Administrator (right-click on Command Prompt and select "Run as Administrator") and run these commands: ```cmd netsh int ip reset netsh int ipv6 reset netsh winsock reset ``` Then restart your computer. 2. **Reset Device Manager network adapters** (if step 1 doesn't work) - Open Device Manager - Find "Network Adapters" - Uninstall all WAN Miniport drivers (IKEv2, IP, IPv6, etc.) - Click Action → Scan for hardware changes - The adapters you just uninstalled should reinstall automatically Try connecting to the VPN again. #### What causes this issue? This error typically occurs when: - Windows networking stack becomes corrupted - After Windows updates that affect network drivers - When switching between different VPN configurations - After network-related software installations/uninstallations Note: This issue has been reported by many users and the above solution has proven effective in most cases. ### Error: Failed to create symlinks for deploying to localhost You tried to run Algo and you received an error like this one: ``` TASK [Create a symlink if deploying to localhost] ******************************************************************** fatal: [localhost]: FAILED! => {"changed": false, "gid": 1000, "group": "ubuntu", "mode": "0775", "msg": "the directory configs/localhost is not empty, refusing to convert it", "owner": "ubuntu", "path": "configs/localhost", "size": 4096, "state": "directory", "uid": 1000} included: /home/ubuntu/algo-master/playbooks/rescue.yml for localhost TASK [debug] ********************************************************************************************************* ok: [localhost] => { "fail_hint": [ "Sorry, but something went wrong!", "Please check the troubleshooting guide.", "https://trailofbits.github.io/algo/troubleshooting.html" ] } TASK [Fail the installation] ***************************************************************************************** ``` This error is usually encountered when using the local install option and `localhost` is provided in answer to this question, which is expecting an IP address or domain name of your server: ``` Enter the public IP address or domain name of your server: (IMPORTANT! This is used to verify the certificate) [localhost] : ``` You should remove the files in /etc/wireguard/ and configs/ as follows: ```ssh sudo rm -rf /etc/wireguard/* rm -rf configs/* ``` And then immediately re-run `./algo` and provide a domain name or IP address in response to the question referenced above. ### Wireguard: Unable to find 'configs/...' in expected paths You tried to run Algo and you received an error like this one: ``` TASK [wireguard : Generate public keys] ******************************************************************************** [WARNING]: Unable to find 'configs/xxx.xxx.xxx.xxx/wireguard//private/dan' in expected paths. fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'file'. Error was a , original message: could not locate file in lookup: configs/xxx.xxx.xxx.xxx/wireguard//private/dan"} ``` This error is usually hit when using the local install option on an unsupported server. Algo requires Ubuntu 22.04 LTS. You should upgrade your server to Ubuntu 22.04 LTS. If this doesn't work, try removing files in /etc/wireguard/ and the configs directories as follows: ```ssh sudo rm -rf /etc/wireguard/* rm -rf configs/* ``` Then immediately re-run `./algo`. ### Old Networking Firewall In Place You may see the following output when attemptint to run ./algo from your localhost: ``` TASK [Wait until SSH becomes ready...] ********************************************************************************************************************** fatal: [localhost]: FAILED! => {"changed": false, "elapsed": 321, "msg": "Timeout when waiting for search string OpenSSH in xxx.xxx.xxx.xxx:4160"} included: /home//algo/algo/playbooks/rescue.yml for localhost TASK [debug] ************************************************************************************************************************************************ ok: [localhost] => { "fail_hint": [ "Sorry, but something went wrong!", "Please check the troubleshooting guide.", "https://trailofbits.github.io/algo/troubleshooting.html" ] } ``` If you see this error then one possible explanation is that you have a previous firewall configured in your cloud hosting provider which needs to be either updated or ideally removed. Removing this can often fix this issue. ## Connection Problems Look here if you deployed an Algo server but now have a problem connecting to it with a client. ### I'm blocked or get CAPTCHAs when I access certain websites This is normal. When you deploy a Algo to a new cloud server, the address you are given may have been used before. In some cases, a malicious individual may have attacked others with that address and had it added to "IP reputation" feeds or simply a blacklist. In order to regain the trust for that address, you may be asked to enter CAPTCHAs to prove that you are a human, and not a Denial of Service (DoS) bot trying to attack others. This happens most frequently with Google. You can try entering the CAPTCHAs or you can try redeploying your Algo server to a new IP to resolve this issue. In some cases, a website will block any visitors accessing their site through a cloud hosting provider due to previous, frequent DoS attacks originating from them. In these cases, there is not much you can do except deploy Algo to your own server or another IP that the website has not outright blocked. ### I want to change the list of trusted Wifi networks on my Apple device This setting is enforced on your client device via the Apple profile you put on it. You can edit the profile with new settings, then load it on your device to change the settings. You can use the [Apple Configurator](https://itunes.apple.com/us/app/apple-configurator-2/id1037126344?mt=12) to edit and resave the profile. Advanced users can edit the file directly in a text editor. Use the [Configuration Profile Reference](https://developer.apple.com/library/content/featuredarticles/iPhoneConfigurationProfileRef/Introduction/Introduction.html) for information about the file format and other available options. If you're not comfortable editing the profile, you can also simply redeploy a new Algo server with different settings to receive a new auto-generated profile. ### Error: "The VPN Service payload could not be installed." You tried to install the Apple profile on one of your devices and you received an error stating `The "VPN Service" payload could not be installed. The VPN service could not be created.` Client support for Algo VPN is limited to modern operating systems, e.g. macOS 10.11+, iOS 9+. Please upgrade your operating system and try again. ### Little Snitch is broken when connected to the VPN Little Snitch is not compatible with IPSEC VPNs due to a known bug in macOS and there is no solution. The Little Snitch "filter" does not get incoming packets from IPSEC VPNs and, therefore, cannot evaluate any rules over them. Their developers have filed a bug report with Apple but there has been no response. There is nothing they or Algo can do to resolve this problem on their own. You can read more about this problem in [issue #134](https://github.com/trailofbits/algo/issues/134). ### I can't get my router to connect to the Algo server In order to connect to the Algo VPN server, your router must support IKEv2, ECC certificate-based authentication, and the cipher suite we use. See the ipsec.conf files we generate in the `config` folder for more information. Note that we do not officially support routers as clients for Algo VPN at this time, though patches and documentation for them are welcome (for example, see open issues for [Ubiquiti](https://github.com/trailofbits/algo/issues/307) and [pfSense](https://github.com/trailofbits/algo/issues/292)). ### Various websites appear to be offline through the VPN This issue appears occasionally due to issues with [MTU](https://en.wikipedia.org/wiki/Maximum_transmission_unit) size. Different networks may require the MTU to be within a specific range to correctly pass traffic. We made an effort to set the MTU to the most conservative, most compatible size by default but problems may still occur. If either your Internet service provider or your chosen cloud service provider use an MTU smaller than the normal value of 1500 you can use the `reduce_mtu` option in the file `config.cfg` to correspondingly reduce the size of the VPN tunnels created by Algo. Algo will attempt to automatically set `reduce_mtu` based on the MTU found on the server at the time of deployment, but it cannot detect if the MTU is smaller on the client side of the connection. If you change `reduce_mtu` you'll need to deploy a new Algo VPN. To determine the value for `reduce_mtu` you should examine the MTU on your Algo VPN server's primary network interface (see below). You might algo want to run tests using `ping`, both on a local client *when not connected to the VPN* and also on your Algo VPN server (see below). Then take the smallest MTU you find (local or server side), subtract it from 1500, and use that for `reduce_mtu`. An exception to this is if you find the smallest MTU is your local MTU at 1492, typical for PPPoE connections, then no MTU reduction should be necessary. #### Check the MTU on the Algo VPN server To check the MTU on your server, SSH in to it, run the command `ifconfig`, and look for the MTU of the main network interface. For example: ``` ens4: flags=4163 mtu 1460 ``` The MTU shown here is 1460 instead of 1500. Therefore set `reduce_mtu: 40` in `config.cfg`. Algo should do this automatically. #### Determine the MTU using `ping` When using `ping` you increase the payload size with the "Don't Fragment" option set until it fails. The largest payload size that works, plus the `ping` overhead of 28, is the MTU of the connection. ##### Example: Test on your Algo VPN server (Ubuntu) ``` $ ping -4 -s 1432 -c 1 -M do github.com PING github.com (192.30.253.112) 1432(1460) bytes of data. 1440 bytes from lb-192-30-253-112-iad.github.com (192.30.253.112): icmp_seq=1 ttl=53 time=13.1 ms --- github.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 13.135/13.135/13.135/0.000 ms $ ping -4 -s 1433 -c 1 -M do github.com PING github.com (192.30.253.113) 1433(1461) bytes of data. ping: local error: Message too long, mtu=1460 --- github.com ping statistics --- 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms ``` In this example the largest payload size that works is 1432. The `ping` overhead is 28 so the MTU is 1432 + 28 = 1460, which is 40 lower than the normal MTU of 1500. Therefore set `reduce_mtu: 40` in `config.cfg`. ##### Example: Test on a macOS client *not connected to your Algo VPN* ``` $ ping -c 1 -D -s 1464 github.com PING github.com (192.30.253.113): 1464 data bytes 1472 bytes from 192.30.253.113: icmp_seq=0 ttl=50 time=169.606 ms --- github.com ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 169.606/169.606/169.606/0.000 ms $ ping -c 1 -D -s 1465 github.com PING github.com (192.30.253.113): 1465 data bytes --- github.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss ``` In this example the largest payload size that works is 1464. The `ping` overhead is 28 so the MTU is 1464 + 28 = 1492, which is typical for a PPPoE Internet connection and does not require an MTU adjustment. Therefore use the default of `reduce_mtu: 0` in `config.cfg`. #### Change the client MTU without redeploying the Algo VPN If you don't wish to deploy a new Algo VPN (which is required to incorporate a change to `reduce_mtu`) you can change the client side MTU of WireGuard clients and Linux IPsec clients without needing to make changes to your Algo VPN. For WireGuard on Linux, or macOS (when installed with `brew`), you can specify the MTU yourself in the client configuration file (typically `wg0.conf`). Refer to the documentation (see `man wg-quick`). For WireGuard on iOS and Android you can change the MTU in the app. For IPsec on Linux you can change the MTU of your network interface to match the required MTU. For example: ``` sudo ifconfig eth0 mtu 1440 ``` To make the change take effect after a reboot, on Ubuntu 22.04 LTS edit the relevant file in the `/etc/netplan` directory (see `man netplan`). #### Note for WireGuard iOS users As of WireGuard for iOS 0.0.20190107 the default MTU is 1280, a conservative value intended to allow mobile devices to continue to work as they switch between different networks which might have smaller than normal MTUs. In order to use this default MTU review the configuration in the WireGuard app and remove any value for MTU that might have been added automatically by Algo. ### Clients appear stuck in a reconnection loop If you're using 'Connect on Demand' on iOS and your client device appears stuck in a reconnection loop after switching from WiFi to LTE or vice versa, you may want to try disabling DoS protection in strongSwan. The configuration value can be found in `/etc/strongswan.d/charon.conf`. After making the change you must reload or restart ipsec. Example command: ``` sed -i -e 's/#*.dos_protection = yes/dos_protection = no/' /etc/strongswan.d/charon.conf && ipsec restart ``` ### WireGuard: Clients can connect on Wifi but not LTE Certain cloud providers (like AWS Lightsail) don't assign an IPv6 address to your server, but certain cellular carriers (e.g. T-Mobile in the United States, [EE](https://community.ee.co.uk/t5/4G-and-mobile-data/IPv4-VPN-Connectivity/td-p/757881) in the United Kingdom) operate an IPv6-only network. This somehow leads to the Wireguard app not being able to make a connection when transitioning to cell service. Go to the Wireguard app on the device when you're having problems with cell connectivity and select "Export log file" or similar option. If you see a long string of error messages like "`Failed to send data packet write udp6 [::]:49727->[2607:7700:0:2a:0:1:354:40ae]:51820: sendto: no route to host` then you might be having this problem. Manually disconnecting and then reconnecting should restore your connection. To solve this, you need to either "force IPv4 connection" if available on your phone, or install an IPv4 APN, which might be available from your carrier tech support. T-mobile's is available [for iOS here under "iOS IPv4/IPv6 fix"](https://www.reddit.com/r/tmobile/wiki/index), and [here is a walkthrough for Android phones](https://www.myopenrouter.com/article/vpn-connections-not-working-t-mobile-heres-how-fix). ### IPsec: Difficulty connecting through router Some routers treat IPsec connections specially because older versions of IPsec did not work properly through [NAT](https://en.wikipedia.org/wiki/Network_address_translation). If you're having problems connecting to your AlgoVPN through a specific router using IPsec you might need to change some settings on the router. #### Change the "VPN Passthrough" settings If your router has a setting called something like "VPN Passthrough" or "IPsec Passthrough" try changing the setting to a different value. #### Change the default pfSense NAT rules If your router runs [pfSense](https://www.pfsense.org) and a single IPsec client can connect but you have issues when using multiple clients, you'll need to change the **Outbound NAT** mode to **Manual Outbound NAT** and disable the rule that specifies **Static Port** for IKE (UDP port 500). See [Outbound NAT](https://docs.netgate.com/pfsense/en/latest/book/nat/outbound-nat.html#outbound-nat) in the [pfSense Book](https://docs.netgate.com/pfsense/en/latest/book). ## Diagnostic Commands If you want to investigate issues yourself, here are useful commands to run on your Algo server. ### Enable Verbose Logging By default, Algo minimizes logging for privacy. To enable detailed logging for debugging: **During deployment** - Edit `config.cfg` before running `./algo`: ```yaml algo_no_log: false # Show detailed Ansible output (includes sensitive data!) strongswan_log_level: 2 # IPsec debug logging (default: -1 disabled) privacy_enhancements_enabled: false # Disable log rotation/clearing ``` **Important:** Reset these to defaults before sharing logs or screenshots, as they may contain sensitive information. ### Server-Side Diagnostics **Check service status:** ```bash # WireGuard systemctl status wg-quick@wg0 wg show # Show WireGuard interface and peers # IPsec/StrongSwan systemctl status strongswan ipsec statusall # Show all IKE_SA and CHILD_SA ipsec leases # Show assigned virtual IPs # DNS systemctl status dnscrypt-proxy.socket dnscrypt-proxy.service ss -lnup | grep :53 # Check what's listening on DNS port ``` **View logs:** ```bash # WireGuard (kernel module, limited logging) dmesg | grep wireguard # IPsec/StrongSwan journalctl -u strongswan -f # Follow strongswan logs journalctl -t charon -f # Follow IKE daemon logs # DNS journalctl -u dnscrypt-proxy -f # General system journalctl -f # Follow all system logs ``` **Check network and firewall:** ```bash # Verify VPN interfaces exist ip addr show wg0 # WireGuard interface ip addr show # All interfaces # Check firewall rules iptables -L -v -n # IPv4 filter rules with counters iptables -t nat -L -v -n # IPv4 NAT rules ip6tables -L -v -n # IPv6 filter rules # Test DNS resolution dig @172.x.x.x google.com # Replace with your local_service_ip ``` **Find your local DNS IP:** ```bash grep local_service_ip /etc/dnsmasq.d/algo.conf 2>/dev/null || \ grep listen_addresses /etc/dnscrypt-proxy/dnscrypt-proxy.toml ``` ### Client-Side Diagnostics **macOS:** ```bash # View VPN-related logs (last hour) log show --predicate 'subsystem == "com.apple.networkextension"' --info --last 1h # Or use Console.app and search for: nesessionmanager ``` **Linux (WireGuard):** ```bash sudo wg show journalctl -t NetworkManager -f # If using NetworkManager ``` **Windows:** ```powershell # View VPN event logs Get-WinEvent -LogName "Microsoft-Windows-VPN-Client/Operational" -MaxEvents 50 ``` ## I have a problem not covered here If you have an issue that you cannot solve with the guidance here, please [file an issue](https://github.com/trailofbits/algo/issues/new). We welcome bug reports and want to hear about problems you encounter. ================================================ FILE: files/cloud-init/README.md ================================================ # Cloud-Init Files - Critical Format Requirements ## ⚠️ CRITICAL WARNING ⚠️ The files in this directory have **STRICT FORMAT REQUIREMENTS** that must not be changed by linters or automated formatting tools. ## Cloud-Config Header Format The first line of `base.yml` **MUST** be exactly: ``` #cloud-config ``` ### ❌ DO NOT CHANGE TO: - `# cloud-config` (space after #) - **BREAKS CLOUD-INIT PARSING** - Add YAML document start `---` - **NOT ALLOWED IN CLOUD-INIT** ### Why This Matters Cloud-init's YAML parser expects the exact string `#cloud-config` as the first line. Any deviation causes: 1. **Complete parsing failure** - All directives are skipped 2. **SSH configuration not applied** - Servers remain on port 22 instead of 4160 3. **Deployment timeouts** - Ansible cannot connect to configure the VPN 4. **DigitalOcean specific impact** - Other providers may be more tolerant ## Historical Context - **Working**: All versions before PR #14775 (August 2025) - **Broken**: PR #14775 "Apply ansible-lint improvements" added space by mistake - **Fixed**: PR #14801 restored correct format + added protections See GitHub issue #14800 for full technical details. ## Linter Configuration These files are **excluded** from: - `yamllint` (`.yamllint` config) - `ansible-lint` (`.ansible-lint` config) This prevents automated tools from "fixing" the format and breaking deployments. ## Template Variables The cloud-init files use Jinja2 templating: - `{{ ssh_port }}` - Configured SSH port (typically 4160) - `{{ lookup('file', '{{ SSH_keys.public }}') }}` - SSH public key ## Editing Guidelines 1. **Never** run automated formatters on these files 2. **Test immediately** after any changes with real deployments 3. **Check yamllint warnings** are expected (missing space in comment, missing ---) 4. **Verify first line** remains exactly `#cloud-config` ## References - [Cloud-init documentation](https://cloudinit.readthedocs.io/) - [Cloud-config examples](https://cloudinit.readthedocs.io/en/latest/reference/examples.html) - [GitHub Issue #14800](https://github.com/trailofbits/algo/issues/14800) ================================================ FILE: files/cloud-init/base.sh ================================================ #!/bin/sh set -eux # shellcheck disable=SC2230 which sudo || until \ apt-get update -y && \ apt-get install sudo -yf --install-suggests; do sleep 3 done getent passwd algo || useradd -m -d /home/algo -s /bin/bash -G adm -p '!' algo (umask 337 && echo "algo ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/10-algo-user) cat </etc/ssh/sshd_config {{ lookup('template', 'files/cloud-init/sshd_config') }} EOF test -d /home/algo/.ssh || sudo -u algo mkdir -m 0700 /home/algo/.ssh echo "{{ lookup('file', SSH_keys.public) }}" | (sudo -u algo tee /home/algo/.ssh/authorized_keys && chmod 0600 /home/algo/.ssh/authorized_keys) ufw --force reset # shellcheck disable=SC2015 dpkg -l sshguard && until apt-get remove -y --purge sshguard; do sleep 3 done || true systemctl restart sshd.service ================================================ FILE: files/cloud-init/base.yml ================================================ #cloud-config # CRITICAL: The above line MUST be exactly "#cloud-config" (no space after #) # This is required by cloud-init's YAML parser. Adding a space breaks parsing # and causes all cloud-init directives to be skipped, resulting in SSH timeouts. # See: https://github.com/trailofbits/algo/issues/14800 output: {all: '| tee -a /var/log/cloud-init-output.log'} package_update: true package_upgrade: true packages: - sudo {% if performance_preinstall_packages | default(false) %} # Universal tools always needed by Algo (performance optimization) - git - screen - apparmor-utils - uuid-runtime - coreutils - iptables-persistent - cgroup-tools {% endif %} users: - default - name: algo homedir: /home/algo sudo: ALL=(ALL) NOPASSWD:ALL groups: adm,netdev shell: /bin/bash lock_passwd: true ssh_authorized_keys: - "{{ lookup('file', SSH_keys.public) | string }}" write_files: - path: /etc/ssh/sshd_config content: | {{ lookup('template', 'files/cloud-init/sshd_config') | string | indent(width=6, first=True) }} runcmd: - set -x - ufw --force reset - sudo apt-get remove -y --purge sshguard || true - systemctl restart sshd.service ================================================ FILE: files/cloud-init/sshd_config ================================================ Port {{ ssh_port }} AllowGroups algo PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication no UsePAM yes X11Forwarding yes PrintMotd no AcceptEnv LANG LC_* Subsystem sftp /usr/lib/openssh/sftp-server ================================================ FILE: input.yml ================================================ --- - name: Ask user for the input hosts: localhost tags: always vars: defaults: server_name: algo ondemand_cellular: false ondemand_wifi: false dns_adblocking: false ssh_tunneling: false store_pki: false providers_map: - { name: DigitalOcean, alias: digitalocean } - { name: Amazon Lightsail, alias: lightsail } - { name: Amazon EC2, alias: ec2 } - { name: Microsoft Azure, alias: azure } - { name: Google Compute Engine, alias: gce } - { name: Hetzner Cloud, alias: hetzner } - { name: Vultr, alias: vultr } - { name: Scaleway, alias: scaleway } - { name: OpenStack (DreamCompute optimised), alias: openstack } - { name: CloudStack, alias: cloudstack } - { name: Linode, alias: linode } - { name: Install to existing Ubuntu latest LTS server (for more advanced users), alias: local } vars_files: - config.cfg tasks: - block: - name: Cloud prompt pause: prompt: | What provider would you like to use? {% for p in providers_map %} {{ loop.index }}. {{ p['name'] }} {% endfor %} Enter the number of your desired provider register: _algo_provider when: provider is undefined - name: Set facts based on the input set_fact: algo_provider: "{{ provider | default(providers_map[_algo_provider.user_input | default(omit) | int - 1]['alias']) }}" - name: VPN server name prompt pause: prompt: | Name the vpn server [algo] register: _algo_server_name when: - server_name is undefined - algo_provider != "local" - name: Cellular On Demand prompt pause: prompt: | Do you want macOS/iOS clients to enable "Connect On Demand" when connected to cellular networks? [y/N] register: _ondemand_cellular when: ondemand_cellular is undefined - name: Wi-Fi On Demand prompt pause: prompt: | Do you want macOS/iOS clients to enable "Connect On Demand" when connected to Wi-Fi? [y/N] register: _ondemand_wifi when: ondemand_wifi is undefined - name: Trusted Wi-Fi networks prompt pause: prompt: | List the names of any trusted Wi-Fi networks where macOS/iOS clients should not use "Connect On Demand" (e.g., your home network. Comma-separated value, e.g., HomeNet,OfficeWifi,AlgoWiFi) register: _ondemand_wifi_exclude when: - ondemand_wifi_exclude is undefined - (ondemand_wifi|default(false)|bool) or (booleans_map[_ondemand_wifi.user_input|default(omit)]|default(false)) - name: Retain the PKI prompt pause: prompt: | Do you want to retain the keys (PKI)? (required to add users in the future, but less secure) [y/N] register: _store_pki when: - store_pki is undefined - ipsec_enabled - name: DNS adblocking prompt pause: prompt: | Do you want to enable DNS ad blocking on this VPN server? [y/N] register: _dns_adblocking when: dns_adblocking is undefined - name: SSH tunneling prompt pause: prompt: | Do you want each user to have their own account for SSH tunneling? [y/N] register: _ssh_tunneling when: ssh_tunneling is undefined - name: Set facts based on the input set_fact: algo_server_name: >- {%- if server_name is defined -%}{% set _server = server_name %}{%- elif _algo_server_name.user_input is defined and _algo_server_name.user_input | length > 0 -%}{%- set _server = _algo_server_name.user_input -%}{%- else -%}{% set _server = defaults['server_name'] %}{%- endif -%} {{ _server | regex_replace('(?!\.)(\W|_)', '-') }} algo_ondemand_cellular: >- {%- if ondemand_cellular is defined -%}{{ ondemand_cellular | bool }}{%- elif _ondemand_cellular.user_input is defined -%}{{ booleans_map[_ondemand_cellular.user_input] | default(defaults['ondemand_cellular']) }}{%- else -%}{{ false }}{%- endif -%} algo_ondemand_wifi: >- {%- if ondemand_wifi is defined -%}{{ ondemand_wifi | bool }}{%- elif _ondemand_wifi.user_input is defined -%}{{ booleans_map[_ondemand_wifi.user_input] | default(defaults['ondemand_wifi']) }}{%- else -%}{{ false }}{%- endif -%} algo_ondemand_wifi_exclude: >- {%- if ondemand_wifi_exclude is defined -%}{{ ondemand_wifi_exclude | b64encode }}{%- elif _ondemand_wifi_exclude.user_input is defined and _ondemand_wifi_exclude.user_input | length > 0 -%} {{ _ondemand_wifi_exclude.user_input | b64encode }}{%- else -%}{{ '_null' | b64encode }}{%- endif -%} algo_dns_adblocking: >- {%- if dns_adblocking is defined -%}{{ dns_adblocking | bool }}{%- elif _dns_adblocking.user_input is defined -%}{{ booleans_map[_dns_adblocking.user_input] | default(defaults['dns_adblocking']) }}{%- else -%}{{ false }}{%- endif -%} algo_ssh_tunneling: >- {%- if ssh_tunneling is defined -%}{{ ssh_tunneling | bool }}{%- elif _ssh_tunneling.user_input is defined -%}{{ booleans_map[_ssh_tunneling.user_input] | default(defaults['ssh_tunneling']) }}{%- else -%}{{ false }}{%- endif -%} algo_store_pki: >- {%- if ipsec_enabled -%} {%- if store_pki is defined -%}{{ store_pki | bool }}{%- elif _store_pki.user_input is defined -%}{{ booleans_map[_store_pki.user_input] | default(defaults['store_pki']) }}{%- else -%}{{ false }}{%- endif -%} {%- endif -%} rescue: - include_tasks: playbooks/rescue.yml ================================================ FILE: install.sh ================================================ #!/usr/bin/env sh set -ex METHOD="${1:-${METHOD:-cloud}}" ONDEMAND_CELLULAR="${2:-${ONDEMAND_CELLULAR:-false}}" ONDEMAND_WIFI="${3:-${ONDEMAND_WIFI:-false}}" ONDEMAND_WIFI_EXCLUDE="${4:-${ONDEMAND_WIFI_EXCLUDE:-_null}}" STORE_PKI="${5:-${STORE_PKI:-false}}" DNS_ADBLOCKING="${6:-${DNS_ADBLOCKING:-false}}" SSH_TUNNELING="${7:-${SSH_TUNNELING:-false}}" ENDPOINT="${8:-${ENDPOINT:-localhost}}" USERS="${9:-${USERS:-user1}}" REPO_SLUG="${10:-${REPO_SLUG:-trailofbits/algo}}" REPO_BRANCH="${11:-${REPO_BRANCH:-master}}" EXTRA_VARS="${12:-${EXTRA_VARS:-placeholder=null}}" ANSIBLE_EXTRA_ARGS="${13:-${ANSIBLE_EXTRA_ARGS}}" cd /opt/ installRequirements() { export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install \ curl \ jq -y # Install uv curl -LsSf https://astral.sh/uv/install.sh | sh export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" } getAlgo() { [ ! -d "algo" ] && git clone "https://github.com/${REPO_SLUG}" -b "${REPO_BRANCH}" algo cd algo # uv handles all dependency installation automatically uv sync } publicIpFromInterface() { echo "Couldn't find a valid ipv4 address, using the first IP found on the interfaces as the endpoint." DEFAULT_INTERFACE="$(ip -4 route list match default | grep -Eo "dev .*" | awk '{print $2}')" ENDPOINT=$(ip -4 addr sh dev "$DEFAULT_INTERFACE" | grep -w inet | head -n1 | awk '{print $2}' | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b') export ENDPOINT="${ENDPOINT}" echo "Using ${ENDPOINT} as the endpoint" } tryGetMetadata() { # Helper function to fetch metadata with retry url="$1" headers="$2" response="" # Try up to 2 times for attempt in 1 2; do if [ -n "$headers" ]; then response="$(curl -s --connect-timeout 5 --max-time "${METADATA_TIMEOUT}" -H "$headers" "$url" || true)" else response="$(curl -s --connect-timeout 5 --max-time "${METADATA_TIMEOUT}" "$url" || true)" fi # If we got a response, return it if [ -n "$response" ]; then echo "$response" return 0 fi # Wait before retry (only on first attempt) [ $attempt -eq 1 ] && sleep 2 done # Return empty string if all attempts failed echo "" return 1 } publicIpFromMetadata() { # Set default timeout from environment or use 20 seconds METADATA_TIMEOUT="${METADATA_TIMEOUT:-20}" if tryGetMetadata "http://169.254.169.254/metadata/v1/vendor-data" "" | grep DigitalOcean >/dev/null; then ENDPOINT="$(tryGetMetadata "http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address" "")" elif test "$(tryGetMetadata "http://169.254.169.254/latest/meta-data/services/domain" "")" = "amazonaws.com"; then ENDPOINT="$(tryGetMetadata "http://169.254.169.254/latest/meta-data/public-ipv4" "")" elif host -t A -W 10 metadata.google.internal 127.0.0.53 >/dev/null; then ENDPOINT="$(tryGetMetadata "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" "Metadata-Flavor: Google")" elif test "$(tryGetMetadata "http://169.254.169.254/metadata/instance/compute/publisher/?api-version=2017-04-02&format=text" "Metadata:true")" = "Canonical"; then ENDPOINT="$(tryGetMetadata "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-04-02&format=text" "Metadata:true")" fi if echo "${ENDPOINT}" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"; then export ENDPOINT="${ENDPOINT}" echo "Using ${ENDPOINT} as the endpoint" else publicIpFromInterface fi } deployAlgo() { getAlgo cd /opt/algo export HOME=/root export ANSIBLE_LOCAL_TEMP=/root/.ansible/tmp export ANSIBLE_REMOTE_TEMP=/root/.ansible/tmp # shellcheck disable=SC2086 uv run ansible-playbook main.yml \ -e provider=local \ -e "ondemand_cellular=${ONDEMAND_CELLULAR}" \ -e "ondemand_wifi=${ONDEMAND_WIFI}" \ -e "ondemand_wifi_exclude=${ONDEMAND_WIFI_EXCLUDE}" \ -e "store_pki=${STORE_PKI}" \ -e "dns_adblocking=${DNS_ADBLOCKING}" \ -e "ssh_tunneling=${SSH_TUNNELING}" \ -e "endpoint=$ENDPOINT" \ -e "users=$(echo "$USERS" | jq -Rc 'split(",")')" \ -e server=localhost \ -e ssh_user=root \ -e "${EXTRA_VARS}" \ --skip-tags debug ${ANSIBLE_EXTRA_ARGS} | tee /var/log/algo.log } if test "$METHOD" = "cloud"; then publicIpFromMetadata fi installRequirements deployAlgo ================================================ FILE: inventory ================================================ [local] localhost ansible_connection=local ansible_python_interpreter=python3 ================================================ FILE: library/gcp_compute_location_info.py ================================================ #!/usr/bin/python import json from ansible.module_utils.gcp_utils import GcpModule, GcpSession, navigate_hash ################################################################################ # Documentation ################################################################################ ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} ################################################################################ # Main ################################################################################ def main(): module = GcpModule( argument_spec={"filters": {"type": "list", "elements": "str"}, "scope": {"required": True, "type": "str"}} ) if module._name == "gcp_compute_image_facts": module.deprecate( "The 'gcp_compute_image_facts' module has been renamed to 'gcp_compute_regions_info'", version="2.13" ) if not module.params["scopes"]: module.params["scopes"] = ["https://www.googleapis.com/auth/compute"] items = fetch_list(module, collection(module), query_options(module.params["filters"])) if items.get("items"): items = items.get("items") else: items = [] return_value = {"resources": items} module.exit_json(**return_value) def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/{scope}".format(**module.params) def fetch_list(module, link, query): auth = GcpSession(module, "compute") response = auth.get(link, params={"filter": query}) return return_if_object(module, response) def query_options(filters): if not filters: return "" if len(filters) == 1: return filters[0] else: queries = [] for f in filters: # For multiple queries, all queries should have () if f[0] != "(" and f[-1] != ")": queries.append("({})".format("".join(f))) else: queries.append(f) return " ".join(queries) def return_if_object(module, response): # If not found, return nothing. if response.status_code == 404: return None # If no content, return nothing. if response.status_code == 204: return None try: module.raise_for_status(response) result = response.json() except getattr(json.decoder, "JSONDecodeError", ValueError) as inst: module.fail_json(msg=f"Invalid JSON response with error: {inst}") if navigate_hash(result, ["error", "errors"]): module.fail_json(msg=navigate_hash(result, ["error", "errors"])) return result if __name__ == "__main__": main() ================================================ FILE: library/lightsail_region_facts.py ================================================ #!/usr/bin/python # Copyright: Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} DOCUMENTATION = """ --- module: lightsail_region_facts short_description: Gather facts about AWS Lightsail regions. description: - Gather facts about AWS Lightsail regions. version_added: "2.5.3" author: "Jack Ivanov (@jackivanov)" options: requirements: - "python >= 2.6" - boto3 extends_documentation_fragment: - aws - ec2 """ EXAMPLES = """ # Gather facts about all regions - lightsail_region_facts: """ RETURN = """ regions: returned: on success description: > Each element consists of a dict with all the information related to that region. type: list sample: "[{ "availabilityZones": [], "continentCode": "NA", "description": "This region is recommended to serve users in the eastern United States", "displayName": "Virginia", "name": "us-east-1" }]" """ import traceback try: import botocore HAS_BOTOCORE = True except ImportError: HAS_BOTOCORE = False try: import boto3 except ImportError: # will be caught by imported HAS_BOTO3 pass from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.ec2 import ( HAS_BOTO3, boto3_conn, ec2_argument_spec, get_aws_connection_info, ) def main(): argument_spec = ec2_argument_spec() module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO3: module.fail_json(msg='Python module "boto3" is missing, please install it') if not HAS_BOTOCORE: module.fail_json(msg='Python module "botocore" is missing, please install it') try: region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) client = None try: client = boto3_conn( module, conn_type="client", resource="lightsail", region=region, endpoint=ec2_url, **aws_connect_kwargs ) except (botocore.exceptions.ClientError, botocore.exceptions.ValidationError) as e: module.fail_json( msg="Failed while connecting to the lightsail service: %s" % e, exception=traceback.format_exc() ) response = client.get_regions(includeAvailabilityZones=False) module.exit_json(changed=False, data=response) except (botocore.exceptions.ClientError, Exception) as e: module.fail_json(msg=str(e), exception=traceback.format_exc()) if __name__ == "__main__": main() ================================================ FILE: library/scaleway_compute.py ================================================ #!/usr/bin/python # # Scaleway Compute management module # # Copyright (C) 2018 Online SAS. # https://www.scaleway.com # # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} DOCUMENTATION = """ --- module: scaleway_compute short_description: Scaleway compute management module version_added: "2.6" author: Remy Leone (@sieben) description: - "This module manages compute instances on Scaleway." extends_documentation_fragment: scaleway options: public_ip: description: - Manage public IP on a Scaleway server - Could be Scaleway IP address UUID - C(dynamic) Means that IP is destroyed at the same time the host is destroyed - C(absent) Means no public IP at all version_added: '2.8' default: absent enable_ipv6: description: - Enable public IPv6 connectivity on the instance default: false type: bool boot_type: description: - Boot method default: bootscript choices: - bootscript - local image: description: - Image identifier used to start the instance with required: true name: description: - Name of the instance organization: description: - Organization identifier required: true state: description: - Indicate desired state of the instance. default: present choices: - present - absent - running - restarted - stopped tags: description: - List of tags to apply to the instance (5 max) required: false default: [] region: description: - Scaleway compute zone required: true choices: - ams1 - EMEA-NL-EVS - par1 - EMEA-FR-PAR1 commercial_type: description: - Commercial name of the compute node required: true wait: description: - Wait for the instance to reach its desired state before returning. type: bool default: 'no' wait_timeout: description: - Time to wait for the server to reach the expected state required: false default: 300 wait_sleep_time: description: - Time to wait before every attempt to check the state of the server required: false default: 3 security_group: description: - Security group unique identifier - If no value provided, the default security group or current security group will be used required: false version_added: "2.8" """ EXAMPLES = """ - name: Create a server scaleway_compute: name: foobar state: present image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe organization: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S tags: - test - www - name: Create a server attached to a security group scaleway_compute: name: foobar state: present image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe organization: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S security_group: 4a31b633-118e-4900-bd52-facf1085fc8d tags: - test - www - name: Destroy it right after scaleway_compute: name: foobar state: absent image: 89ee4018-f8c3-4dc4-a6b5-bca14f985ebe organization: 951df375-e094-4d26-97c1-ba548eeb9c42 region: ams1 commercial_type: VC1S """ RETURN = """ """ import datetime import time from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.scaleway import SCALEWAY_LOCATION, Scaleway, scaleway_argument_spec SCALEWAY_SERVER_STATES = ("stopped", "stopping", "starting", "running", "locked") SCALEWAY_TRANSITIONS_STATES = ("stopping", "starting", "pending") def check_image_id(compute_api, image_id): response = compute_api.get(path="images") if response.ok and response.json: image_ids = [image["id"] for image in response.json["images"]] if image_id not in image_ids: compute_api.module.fail_json( msg="Error in getting image %s on %s" % (image_id, compute_api.module.params.get("api_url")) ) else: compute_api.module.fail_json(msg="Error in getting images from: %s" % compute_api.module.params.get("api_url")) def fetch_state(compute_api, server): compute_api.module.debug("fetch_state of server: %s" % server["id"]) response = compute_api.get(path="servers/%s" % server["id"]) if response.status_code == 404: return "absent" if not response.ok: msg = "Error during state fetching: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) try: compute_api.module.debug("Server %s in state: %s" % (server["id"], response.json["server"]["state"])) return response.json["server"]["state"] except KeyError: compute_api.module.fail_json(msg="Could not fetch state in %s" % response.json) def wait_to_complete_state_transition(compute_api, server): wait = compute_api.module.params["wait"] if not wait: return wait_timeout = compute_api.module.params["wait_timeout"] wait_sleep_time = compute_api.module.params["wait_sleep_time"] start = datetime.datetime.utcnow() end = start + datetime.timedelta(seconds=wait_timeout) while datetime.datetime.utcnow() < end: compute_api.module.debug("We are going to wait for the server to finish its transition") if fetch_state(compute_api, server) not in SCALEWAY_TRANSITIONS_STATES: compute_api.module.debug("It seems that the server is not in transition anymore.") compute_api.module.debug("Server in state: %s" % fetch_state(compute_api, server)) break time.sleep(wait_sleep_time) else: compute_api.module.fail_json(msg="Server takes too long to finish its transition") def public_ip_payload(compute_api, public_ip): # We don't want a public ip if public_ip in ("absent",): return {"dynamic_ip_required": False} # IP is only attached to the instance and is released as soon as the instance terminates if public_ip in ("dynamic", "allocated"): return {"dynamic_ip_required": True} # We check that the IP we want to attach exists, if so its ID is returned response = compute_api.get("ips") if not response.ok: msg = "Error during public IP validation: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) ip_list = [] try: ip_list = response.json["ips"] except KeyError: compute_api.module.fail_json(msg="Error in getting the IP information from: %s" % response.json) lookup = [ip["id"] for ip in ip_list] if public_ip in lookup: return {"public_ip": public_ip} def create_server(compute_api, server): compute_api.module.debug("Starting a create_server") target_server = None data = { "enable_ipv6": server["enable_ipv6"], "tags": server["tags"], "commercial_type": server["commercial_type"], "image": server["image"], "dynamic_ip_required": server["dynamic_ip_required"], "name": server["name"], "organization": server["organization"], } if server["boot_type"]: data["boot_type"] = server["boot_type"] if server["security_group"]: data["security_group"] = server["security_group"] response = compute_api.post(path="servers", data=data) if not response.ok: msg = "Error during server creation: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) try: target_server = response.json["server"] except KeyError: compute_api.module.fail_json(msg="Error in getting the server information from: %s" % response.json) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) return target_server def restart_server(compute_api, server): return perform_action(compute_api=compute_api, server=server, action="reboot") def stop_server(compute_api, server): return perform_action(compute_api=compute_api, server=server, action="poweroff") def start_server(compute_api, server): return perform_action(compute_api=compute_api, server=server, action="poweron") def perform_action(compute_api, server, action): response = compute_api.post(path="servers/%s/action" % server["id"], data={"action": action}) if not response.ok: msg = "Error during server %s: (%s) %s" % (action, response.status_code, response.json) compute_api.module.fail_json(msg=msg) wait_to_complete_state_transition(compute_api=compute_api, server=server) return response def remove_server(compute_api, server): compute_api.module.debug("Starting remove server strategy") response = compute_api.delete(path="servers/%s" % server["id"]) if not response.ok: msg = "Error during server deletion: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) wait_to_complete_state_transition(compute_api=compute_api, server=server) return response def present_strategy(compute_api, wished_server): compute_api.module.debug("Starting present strategy") changed = False query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1) if not query_results: changed = True if compute_api.module.check_mode: return changed, {"status": "A server would be created."} target_server = create_server(compute_api=compute_api, server=wished_server) else: target_server = query_results[0] if server_attributes_should_be_changed( compute_api=compute_api, target_server=target_server, wished_server=wished_server ): changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s attributes would be changed." % target_server["id"]} target_server = server_change_attributes( compute_api=compute_api, target_server=target_server, wished_server=wished_server ) return changed, target_server def absent_strategy(compute_api, wished_server): compute_api.module.debug("Starting absent strategy") changed = False target_server = None query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1) if not query_results: return changed, {"status": "Server already absent."} else: target_server = query_results[0] changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s would be made absent." % target_server["id"]} # A server MUST be stopped to be deleted. while fetch_state(compute_api=compute_api, server=target_server) != "stopped": wait_to_complete_state_transition(compute_api=compute_api, server=target_server) response = stop_server(compute_api=compute_api, server=target_server) if not response.ok: err_msg = f"Error while stopping a server before removing it [{response.status_code}: {response.json}]" compute_api.module.fail_json(msg=err_msg) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) response = remove_server(compute_api=compute_api, server=target_server) if not response.ok: err_msg = f"Error while removing server [{response.status_code}: {response.json}]" compute_api.module.fail_json(msg=err_msg) return changed, {"status": "Server %s deleted" % target_server["id"]} def running_strategy(compute_api, wished_server): compute_api.module.debug("Starting running strategy") changed = False query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1) if not query_results: changed = True if compute_api.module.check_mode: return changed, {"status": "A server would be created before being run."} target_server = create_server(compute_api=compute_api, server=wished_server) else: target_server = query_results[0] if server_attributes_should_be_changed( compute_api=compute_api, target_server=target_server, wished_server=wished_server ): changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s attributes would be changed before running it." % target_server["id"]} target_server = server_change_attributes( compute_api=compute_api, target_server=target_server, wished_server=wished_server ) current_state = fetch_state(compute_api=compute_api, server=target_server) if current_state not in ("running", "starting"): compute_api.module.debug("running_strategy: Server in state: %s" % current_state) changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s attributes would be changed." % target_server["id"]} response = start_server(compute_api=compute_api, server=target_server) if not response.ok: msg = f"Error while running server [{response.status_code}: {response.json}]" compute_api.module.fail_json(msg=msg) return changed, target_server def stop_strategy(compute_api, wished_server): compute_api.module.debug("Starting stop strategy") query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1) changed = False if not query_results: if compute_api.module.check_mode: return changed, {"status": "A server would be created before being stopped."} target_server = create_server(compute_api=compute_api, server=wished_server) changed = True else: target_server = query_results[0] compute_api.module.debug("stop_strategy: Servers are found.") if server_attributes_should_be_changed( compute_api=compute_api, target_server=target_server, wished_server=wished_server ): changed = True if compute_api.module.check_mode: return changed, { "status": "Server %s attributes would be changed before stopping it." % target_server["id"] } target_server = server_change_attributes( compute_api=compute_api, target_server=target_server, wished_server=wished_server ) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) current_state = fetch_state(compute_api=compute_api, server=target_server) if current_state not in ("stopped",): compute_api.module.debug("stop_strategy: Server in state: %s" % current_state) changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s would be stopped." % target_server["id"]} response = stop_server(compute_api=compute_api, server=target_server) compute_api.module.debug(response.json) compute_api.module.debug(response.ok) if not response.ok: msg = f"Error while stopping server [{response.status_code}: {response.json}]" compute_api.module.fail_json(msg=msg) return changed, target_server def restart_strategy(compute_api, wished_server): compute_api.module.debug("Starting restart strategy") changed = False query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1) if not query_results: changed = True if compute_api.module.check_mode: return changed, {"status": "A server would be created before being rebooted."} target_server = create_server(compute_api=compute_api, server=wished_server) else: target_server = query_results[0] if server_attributes_should_be_changed( compute_api=compute_api, target_server=target_server, wished_server=wished_server ): changed = True if compute_api.module.check_mode: return changed, { "status": "Server %s attributes would be changed before rebooting it." % target_server["id"] } target_server = server_change_attributes( compute_api=compute_api, target_server=target_server, wished_server=wished_server ) changed = True if compute_api.module.check_mode: return changed, {"status": "Server %s would be rebooted." % target_server["id"]} wait_to_complete_state_transition(compute_api=compute_api, server=target_server) if fetch_state(compute_api=compute_api, server=target_server) in ("running",): response = restart_server(compute_api=compute_api, server=target_server) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) if not response.ok: msg = f"Error while restarting server that was running [{response.status_code}: {response.json}]." compute_api.module.fail_json(msg=msg) if fetch_state(compute_api=compute_api, server=target_server) in ("stopped",): response = restart_server(compute_api=compute_api, server=target_server) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) if not response.ok: msg = f"Error while restarting server that was stopped [{response.status_code}: {response.json}]." compute_api.module.fail_json(msg=msg) return changed, target_server state_strategy = { "present": present_strategy, "restarted": restart_strategy, "stopped": stop_strategy, "running": running_strategy, "absent": absent_strategy, } def find(compute_api, wished_server, per_page=1): compute_api.module.debug("Getting inside find") # Only the name attribute is accepted in the Compute query API response = compute_api.get("servers", params={"name": wished_server["name"], "per_page": per_page}) if not response.ok: msg = "Error during server search: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) search_results = response.json["servers"] return search_results PATCH_MUTABLE_SERVER_ATTRIBUTES = ( "ipv6", "tags", "name", "dynamic_ip_required", "security_group", ) def server_attributes_should_be_changed(compute_api, target_server, wished_server): compute_api.module.debug("Checking if server attributes should be changed") compute_api.module.debug("Current Server: %s" % target_server) compute_api.module.debug("Wished Server: %s" % wished_server) debug_dict = dict( (x, (target_server[x], wished_server[x])) for x in PATCH_MUTABLE_SERVER_ATTRIBUTES if x in target_server and x in wished_server ) compute_api.module.debug("Debug dict %s" % debug_dict) try: for key in PATCH_MUTABLE_SERVER_ATTRIBUTES: if key in target_server and key in wished_server: # When you are working with dict, only ID matter as we ask user to put only the resource ID in the playbook if ( isinstance(target_server[key], dict) and wished_server[key] and "id" in target_server[key].keys() and target_server[key]["id"] != wished_server[key] ): return True # Handling other structure compare simply the two objects content elif not isinstance(target_server[key], dict) and target_server[key] != wished_server[key]: return True return False except AttributeError: compute_api.module.fail_json(msg="Error while checking if attributes should be changed") def server_change_attributes(compute_api, target_server, wished_server): compute_api.module.debug("Starting patching server attributes") patch_payload = dict() for key in PATCH_MUTABLE_SERVER_ATTRIBUTES: if key in target_server and key in wished_server: # When you are working with dict, only ID matter as we ask user to put only the resource ID in the playbook if isinstance(target_server[key], dict) and "id" in target_server[key] and wished_server[key]: # Setting all key to current value except ID key_dict = dict((x, target_server[key][x]) for x in target_server[key].keys() if x != "id") # Setting ID to the user specified ID key_dict["id"] = wished_server[key] patch_payload[key] = key_dict elif not isinstance(target_server[key], dict): patch_payload[key] = wished_server[key] response = compute_api.patch(path="servers/%s" % target_server["id"], data=patch_payload) if not response.ok: msg = "Error during server attributes patching: (%s) %s" % (response.status_code, response.json) compute_api.module.fail_json(msg=msg) try: target_server = response.json["server"] except KeyError: compute_api.module.fail_json(msg="Error in getting the server information from: %s" % response.json) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) return target_server def core(module): region = module.params["region"] wished_server = { "state": module.params["state"], "image": module.params["image"], "name": module.params["name"], "commercial_type": module.params["commercial_type"], "enable_ipv6": module.params["enable_ipv6"], "boot_type": module.params["boot_type"], "tags": module.params["tags"], "organization": module.params["organization"], "security_group": module.params["security_group"], } module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"] compute_api = Scaleway(module=module) if wished_server["state"] != "absent": check_image_id(compute_api, wished_server["image"]) # IP parameters of the wished server depends on the configuration ip_payload = public_ip_payload(compute_api=compute_api, public_ip=module.params["public_ip"]) wished_server.update(ip_payload) changed, summary = state_strategy[wished_server["state"]](compute_api=compute_api, wished_server=wished_server) module.exit_json(changed=changed, msg=summary) def main(): argument_spec = scaleway_argument_spec() argument_spec.update( dict( image=dict(), name=dict(), region=dict(required=True, choices=SCALEWAY_LOCATION.keys()), commercial_type=dict(), enable_ipv6=dict(default=False, type="bool"), boot_type=dict(choices=["bootscript", "local"]), public_ip=dict(default="absent"), state=dict(choices=state_strategy.keys(), default="present"), tags=dict(type="list", default=[]), organization=dict(), wait=dict(type="bool", default=False), wait_timeout=dict(type="int", default=300), wait_sleep_time=dict(type="int", default=3), security_group=dict(), ) ) module = AnsibleModule( argument_spec=argument_spec, required_if=[ ("state", "present", ["image", "commercial_type", "organization"]), ("state", "running", ["image", "commercial_type", "organization"]), ("state", "stopped", ["image", "commercial_type", "organization"]), ("state", "restarted", ["image", "commercial_type", "organization"]), ], supports_check_mode=True, ) core(module) if __name__ == "__main__": main() ================================================ FILE: library/x25519_pubkey.py ================================================ #!/usr/bin/python # x25519_pubkey.py - Ansible module to derive a base64-encoded WireGuard-compatible public key # from a base64-encoded 32-byte X25519 private key. # # Why: community.crypto does not provide raw public key derivation for X25519 keys. import base64 from ansible.module_utils.basic import AnsibleModule from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import x25519 """ Ansible module to derive base64-encoded X25519 public keys from private keys. Supports both base64-encoded strings and raw 32-byte key files. Used for WireGuard key generation where community.crypto lacks raw public key derivation. Parameters: - private_key_b64: Base64-encoded X25519 private key string - private_key_path: Path to file containing X25519 private key (base64 or raw 32 bytes) - public_key_path: Path where the derived public key should be written Returns: - public_key: Base64-encoded X25519 public key - changed: Whether the public key file was modified - public_key_path: Path where public key was written (if specified) """ def run_module(): """ Main execution function for the x25519_pubkey Ansible module. Handles parameter validation, private key processing, public key derivation, and optional file output with idempotent behavior. """ module_args = { "private_key_b64": {"type": "str", "required": False}, "private_key_path": {"type": "path", "required": False}, "public_key_path": {"type": "path", "required": False}, } result = { "changed": False, "public_key": "", } module = AnsibleModule( argument_spec=module_args, required_one_of=[["private_key_b64", "private_key_path"]], supports_check_mode=True ) priv_b64 = None if module.params["private_key_path"]: try: with open(module.params["private_key_path"], "rb") as f: data = f.read() try: # First attempt: assume file contains base64 text data # Strip whitespace from edges for text files (safe for base64 strings) stripped_data = data.strip() base64.b64decode(stripped_data, validate=True) priv_b64 = stripped_data.decode() except (base64.binascii.Error, ValueError): # Second attempt: assume file contains raw binary data # CRITICAL: Do NOT strip raw binary data - X25519 keys can contain # whitespace-like bytes (0x09, 0x0A, etc.) that must be preserved # Stripping would corrupt the key and cause "got 31 bytes" errors if len(data) != 32: module.fail_json( msg=f"Private key file must be either base64 or exactly 32 raw bytes, got {len(data)} bytes" ) priv_b64 = base64.b64encode(data).decode() except OSError as e: module.fail_json(msg=f"Failed to read private key file: {e}") else: priv_b64 = module.params["private_key_b64"] # Validate input parameters if not priv_b64: module.fail_json(msg="No private key provided") try: priv_raw = base64.b64decode(priv_b64, validate=True) except Exception as e: module.fail_json(msg=f"Invalid base64 private key format: {e}") if len(priv_raw) != 32: module.fail_json(msg=f"Private key must decode to exactly 32 bytes, got {len(priv_raw)}") try: priv_key = x25519.X25519PrivateKey.from_private_bytes(priv_raw) pub_key = priv_key.public_key() pub_raw = pub_key.public_bytes(encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw) pub_b64 = base64.b64encode(pub_raw).decode() result["public_key"] = pub_b64 if module.params["public_key_path"]: pub_path = module.params["public_key_path"] existing = None try: with open(pub_path) as f: existing = f.read().strip() except OSError: existing = None if existing != pub_b64: try: with open(pub_path, "w") as f: f.write(pub_b64) result["changed"] = True except OSError as e: module.fail_json(msg=f"Failed to write public key file: {e}") result["public_key_path"] = pub_path except Exception as e: module.fail_json(msg=f"Failed to derive public key: {e}") module.exit_json(**result) def main(): """Entry point when module is executed directly.""" run_module() if __name__ == "__main__": main() ================================================ FILE: main.yml ================================================ --- - name: Algo VPN Setup hosts: localhost become: false tasks: - name: Playbook dir stat stat: path: "{{ playbook_dir }}" register: _playbook_dir - name: Ensure Ansible is not being run in a world writable directory assert: that: _playbook_dir.stat.mode|int <= 775 msg: > Ansible is being run in a world writable directory ({{ playbook_dir }}), ignoring it as an ansible.cfg source. For more information see https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir - name: Ensure the requirements installed debug: msg: "{{ '192.168.1.1' | ansible.utils.ipaddr }}" failed_when: false no_log: true register: ipaddr - name: Extract ansible version from pyproject.toml set_fact: ansible_requirement: "{{ lookup('file', 'pyproject.toml') | regex_search('ansible==[0-9]+\\.[0-9]+\\.[0-9]+') }}" - name: Parse ansible version requirement set_fact: required_ansible_version: op: "{{ ansible_requirement | regex_replace('^ansible\\s*([~>=<]+)\\s*.*$', '\\1') }}" ver: "{{ ansible_requirement | regex_replace('^ansible\\s*[~>=<]+\\s*(\\d+\\.\\d+(?:\\.\\d+)?).*$', '\\1') }}" when: ansible_requirement is defined - name: Get current ansible package version command: uv pip list register: uv_package_list changed_when: false - name: Extract ansible version from uv package list set_fact: current_ansible_version: "{{ uv_package_list.stdout | regex_search('ansible\\s+([0-9]+\\.[0-9]+\\.[0-9]+)', '\\1') | first }}" - name: Verify Python meets Algo VPN requirements assert: that: (ansible_python.version.major|string + '.' + ansible_python.version.minor|string) is version('3.11', '>=') msg: > Python version is not supported. You must upgrade to at least Python 3.11 to use this version of Algo. See for more details - https://trailofbits.github.io/algo/troubleshooting.html#python-version-is-not-supported - name: Verify Ansible meets Algo VPN requirements assert: that: - current_ansible_version is version(required_ansible_version.ver, required_ansible_version.op) - not ipaddr.failed msg: > Ansible version is {{ current_ansible_version }}. You must update the requirements to use this version of Algo. Try to run: uv sync - name: Check cryptography library SECP384R1 support command: > {{ ansible_playbook_python }} -c "from cryptography.hazmat.primitives.asymmetric.ec import SECP384R1" changed_when: false failed_when: false register: _crypto_check when: ipsec_enabled | default(true) | bool - name: Verify cryptography library supports IPsec requirements assert: that: _crypto_check.rc == 0 msg: > The Python cryptography library is missing or does not support SECP384R1. IPsec/IKEv2 requires the cryptography package with elliptic curve support. Fix: Run ./algo (manages dependencies automatically) or: uv sync && uv run ansible-playbook main.yml when: ipsec_enabled | default(true) | bool - name: Include prompts playbook import_playbook: input.yml - name: Include cloud provisioning playbook import_playbook: cloud.yml - name: Include server configuration playbook import_playbook: server.yml ================================================ FILE: playbooks/cloud-post.yml ================================================ --- - name: Set subjectAltName as a fact set_fact: IP_subject_alt_name: "{{ (IP_subject_alt_name if algo_provider == 'local' else cloud_instance_ip) | lower }}" - name: Add the server to an inventory group add_host: name: "{% if cloud_instance_ip == 'localhost' %}localhost{% else %}{{ cloud_instance_ip }}{% endif %}" groups: vpn-host ansible_connection: "{% if cloud_instance_ip == 'localhost' %}local{% else %}ssh{% endif %}" ansible_ssh_user: "{{ ansible_ssh_user | default('root') }}" ansible_ssh_port: "{{ ansible_ssh_port | default(22) }}" ansible_python_interpreter: "{% if cloud_instance_ip == 'localhost' %}{{ ansible_playbook_python }}{% else %}/usr/bin/python3{% endif %}" algo_provider: "{{ algo_provider }}" algo_server_name: "{{ algo_server_name }}" algo_ondemand_cellular: "{{ algo_ondemand_cellular }}" algo_ondemand_wifi: "{{ algo_ondemand_wifi }}" algo_ondemand_wifi_exclude: "{{ algo_ondemand_wifi_exclude }}" algo_dns_adblocking: "{{ algo_dns_adblocking }}" algo_ssh_tunneling: "{{ algo_ssh_tunneling }}" algo_store_pki: "{{ algo_store_pki }}" IP_subject_alt_name: "{{ IP_subject_alt_name }}" alternative_ingress_ip: "{{ alternative_ingress_ip | default(omit) }}" cloudinit: "{{ cloudinit | default(false) }}" - name: Additional variables for the server add_host: name: "{% if cloud_instance_ip == 'localhost' %}localhost{% else %}{{ cloud_instance_ip }}{% endif %}" ansible_ssh_private_key_file: "{{ SSH_keys.private_tmp }}" when: algo_provider != 'local' - name: Wait until SSH becomes ready... wait_for: port: "{{ ansible_ssh_port | default(22) }}" host: "{{ cloud_instance_ip }}" search_regex: OpenSSH delay: 10 timeout: 320 state: present when: cloud_instance_ip != "localhost" - name: Mount tmpfs import_tasks: tmpfs/main.yml when: - pki_in_tmpfs - not algo_store_pki - ansible_system == "Darwin" or ansible_system == "Linux" - debug: var: IP_subject_alt_name - name: Wait for target connection to become reachable/usable wait_for_connection: delay: 10 # Wait 10 seconds before first attempt (conservative) timeout: 480 # Reduce from 600 to 480 seconds (8 minutes - safer) sleep: 10 # Check every 10 seconds (less aggressive polling) delegate_to: "{{ item }}" loop: "{{ groups['vpn-host'] }}" when: cloud_instance_ip != "localhost" ================================================ FILE: playbooks/cloud-pre.yml ================================================ --- - block: - name: Display the invocation environment shell: > ./algo-showenv.sh \ 'algo_provider "{{ algo_provider }}"' \ {% if ipsec_enabled %} 'algo_ondemand_cellular "{{ algo_ondemand_cellular }}"' \ 'algo_ondemand_wifi "{{ algo_ondemand_wifi }}"' \ 'algo_ondemand_wifi_exclude "{{ algo_ondemand_wifi_exclude }}"' \ {% endif %} 'algo_dns_adblocking "{{ algo_dns_adblocking }}"' \ 'algo_ssh_tunneling "{{ algo_ssh_tunneling }}"' \ 'wireguard_enabled "{{ wireguard_enabled }}"' \ 'dns_encryption "{{ dns_encryption }}"' \ > /dev/tty || true tags: debug # Install cloud provider specific dependencies - name: Install cloud provider dependencies shell: uv pip install '.[{{ cloud_provider_extra }}]' vars: cloud_provider_extra: >- {%- if algo_provider in ['ec2', 'lightsail'] -%}aws {%- elif algo_provider == 'azure' -%}azure {%- elif algo_provider == 'gce' -%}gcp {%- elif algo_provider == 'hetzner' -%}hetzner {%- elif algo_provider == 'linode' -%}linode {%- elif algo_provider == 'openstack' -%}openstack {%- elif algo_provider == 'cloudstack' -%}cloudstack {%- else -%}{{ algo_provider }} {%- endif -%} when: algo_provider != "local" changed_when: false # Note: pyOpenSSL and segno are now included in pyproject.toml dependencies # and installed automatically by uv sync delegate_to: localhost become: false - block: - name: Generate the SSH private key community.crypto.openssl_privatekey: path: "{{ SSH_keys.private }}" size: 4096 mode: "0600" type: RSA - name: Generate the SSH public key community.crypto.openssl_publickey: path: "{{ SSH_keys.public }}" privatekey_path: "{{ SSH_keys.private }}" format: OpenSSH - name: Copy the private SSH key to /tmp copy: src: "{{ SSH_keys.private }}" dest: "{{ SSH_keys.private_tmp }}" force: true mode: "0600" delegate_to: localhost become: false when: algo_provider != "local" ================================================ FILE: playbooks/rescue.yml ================================================ --- - debug: var: fail_hint - name: Fail the installation fail: ================================================ FILE: playbooks/tmpfs/linux.yml ================================================ --- - name: Linux | set OS specific facts set_fact: tmpfs_volume_name: AlgoVPN-{{ IP_subject_alt_name }} tmpfs_volume_path: /dev/shm ================================================ FILE: playbooks/tmpfs/macos.yml ================================================ --- - name: MacOS | set OS specific facts set_fact: tmpfs_volume_name: AlgoVPN-{{ IP_subject_alt_name }} tmpfs_volume_path: /Volumes - name: MacOS | mount a ram disk shell: > /usr/sbin/diskutil info "/{{ tmpfs_volume_path }}/{{ tmpfs_volume_name }}/" || /usr/sbin/diskutil erasevolume HFS+ "{{ tmpfs_volume_name }}" $(hdiutil attach -nomount ram://64000) args: creates: /{{ tmpfs_volume_path }}/{{ tmpfs_volume_name }} ================================================ FILE: playbooks/tmpfs/main.yml ================================================ --- - name: Include tasks for MacOS import_tasks: macos.yml when: ansible_system == "Darwin" - name: Include tasks for Linux import_tasks: linux.yml when: ansible_system == "Linux" - name: Set config paths as facts set_fact: ipsec_pki_path: /{{ tmpfs_volume_path }}/{{ tmpfs_volume_name }}/IPsec/ - name: Update config paths add_host: name: "{{ 'localhost' if cloud_instance_ip == 'localhost' else cloud_instance_ip }}" ipsec_pki_path: "{{ ipsec_pki_path }}" ================================================ FILE: playbooks/tmpfs/umount.yml ================================================ --- - name: Linux | Delete the PKI directory file: path: /{{ facts.tmpfs_volume_path }}/{{ facts.tmpfs_volume_name }}/ state: absent when: facts.ansible_system == "Linux" - block: - name: MacOS | check fs the ramdisk exists command: /usr/sbin/diskutil info "{{ facts.tmpfs_volume_name }}" failed_when: false changed_when: false register: diskutil_info - name: MacOS | unmount and eject the ram disk shell: > /usr/sbin/diskutil umount force "/{{ facts.tmpfs_volume_path }}/{{ facts.tmpfs_volume_name }}/" && /usr/sbin/diskutil eject "{{ facts.tmpfs_volume_name }}" changed_when: false when: diskutil_info.rc == 0 register: result until: result.rc == 0 retries: 5 delay: 3 when: - facts.ansible_system == "Darwin" ================================================ FILE: pyproject.toml ================================================ [build-system] requires = ["setuptools>=68.0.0"] build-backend = "setuptools.build_meta" [project] name = "algo" description = "Set up a personal IPSEC VPN in the cloud" version = "2.0.0-beta" requires-python = ">=3.11" dependencies = [ "ansible==12.3.0", "cryptography>=42.0.0", "jinja2>=3.1.6", "netaddr==1.3.0", "pyyaml>=6.0.2", "segno>=1.6.0", ] [tool.setuptools] # Explicitly disable package discovery since Algo is not a Python package py-modules = [] [project.optional-dependencies] # Cloud provider dependencies (installed automatically based on provider selection) aws = [ "boto3>=1.34.0", ] azure = [ "azure-identity>=1.15.0", "azure-mgmt-compute>=30.0.0", "azure-mgmt-network>=25.0.0", "azure-mgmt-resource>=23.0.0", "msrestazure>=0.6.4", ] gcp = [ "google-auth>=2.28.0", "requests>=2.31.0", ] hetzner = [ "hcloud>=1.33.0", ] linode = [ "linode-api4>=5.15.0", ] openstack = [ "openstacksdk>=2.1.0", ] cloudstack = [ "cs>=3.0.0", ] [tool.ruff] # Ruff configuration target-version = "py311" line-length = 120 [tool.ruff.lint] select = [ "E", # pycodestyle errors "W", # pycodestyle warnings "F", # pyflakes "I", # isort "B", # flake8-bugbear "C4", # flake8-comprehensions "UP", # pyupgrade "S", # flake8-bandit (security) "SIM", # flake8-simplify "RUF", # Ruff-specific rules "ERA", # commented-out code detection "PTH", # pathlib recommendations ] ignore = [ "E501", # line too long (handled by formatter) "B011", # assert False is acceptable in test code "S101", # assert is acceptable in test code "S110", # try-except-pass - used intentionally for optional checks "S112", # try-except-continue - used intentionally for skipping files "S603", # subprocess calls - needed for Ansible modules "S607", # partial path - needed for Ansible modules "S701", # jinja2 autoescape - templates are for config files, not HTML "S602", # shell=True in subprocess - needed for test mocks "SIM102", # nested if - sometimes clearer than combined conditions "SIM108", # ternary - sometimes if/else is more readable "ERA001", # commented code - some comments explain regex patterns "RUF005", # iterable unpacking - concatenation is clearer in some cases "PTH100", # pathlib - existing code uses os.path "PTH108", # pathlib - existing code uses os.unlink "PTH110", # pathlib - existing code uses os.path.exists "PTH118", # pathlib - existing code uses os.path.join "PTH119", # pathlib - existing code uses os.path.basename "PTH120", # pathlib - existing code uses os.path.dirname "PTH123", # pathlib - existing code uses open() "PTH201", # pathlib - existing code uses Path(".") "PTH207", # pathlib - existing code uses glob ] [tool.ruff.lint.per-file-ignores] "library/*" = ["ALL"] # Exclude Ansible library modules (external code) "tests/*" = ["S101"] # Allow assert in tests [tool.ty.environment] # Type checking configuration python-version = "3.11" [tool.ty.src] # Exclude Ansible library modules and tests (test code has looser typing) exclude = ["library/**", "tests/**"] [tool.ty.rules] # Ignore import warnings - ty doesn't see the venv when run via uv --with # These are checked by Python's import system at runtime unresolved-import = "ignore" unknown-argument = "warn" [tool.uv] # Centralized uv version management dev-dependencies = [ "pytest>=8.0.0", "pytest-xdist>=3.0.0", # Parallel test execution "ruff>=0.8.0", # Python linter and formatter "yamllint>=1.35.0", # YAML linter "ansible-lint>=24.0.0", # Ansible linter "j2lint>=1.2.0", # Jinja2 template linter ] [tool.pytest.ini_options] testpaths = ["tests"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] addopts = [ "-v", # Verbose output "--strict-markers", # Strict marker validation "--strict-config", # Strict config validation "--tb=short", # Short traceback format ] markers = [ "slow: marks tests as slow (deselect with '-m \"not slow\"')", "integration: marks tests as integration tests", ] ================================================ FILE: pytest.ini ================================================ [pytest] testpaths = tests/unit python_files = test_*.py python_classes = Test* python_functions = test_* addopts = -v --tb=short filterwarnings = ignore::DeprecationWarning ignore::PendingDeprecationWarning ================================================ FILE: requirements.yml ================================================ --- collections: - name: ansible.posix version: "==2.1.0" - name: ansible.utils version: ">=4.0.0" - name: community.general version: "==11.1.0" - name: community.crypto version: ">=3.1.1" - name: openstack.cloud version: "==2.4.1" - name: linode.cloud version: ">=0.41.0" - name: community.digitalocean version: ">=1.26.0" - name: azure.azcollection version: ">=3.0.0" ================================================ FILE: roles/client/files/libstrongswan-relax-constraints.conf ================================================ libstrongswan { x509 { enforce_critical = no } } ================================================ FILE: roles/client/handlers/main.yml ================================================ --- - name: restart strongswan service: name={{ strongswan_service }} state=restarted ================================================ FILE: roles/client/tasks/main.yml ================================================ --- - name: Gather Facts setup: - name: Include system based facts and tasks import_tasks: systems/main.yml - name: Install prerequisites package: name="{{ item }}" state=present loop: "{{ prerequisites }}" register: result until: result is succeeded retries: 10 delay: 3 - name: Install strongSwan package: name=strongswan state=present register: result until: result is succeeded retries: 10 delay: 3 - name: Setup the ipsec config template: src: roles/strongswan/templates/client_ipsec.conf.j2 dest: "{{ configs_prefix }}/ipsec.{{ IP_subject_alt_name }}.conf" mode: "0644" notify: - restart strongswan - name: Setup the ipsec secrets template: src: roles/strongswan/templates/client_ipsec.secrets.j2 dest: "{{ configs_prefix }}/ipsec.{{ IP_subject_alt_name }}.secrets" mode: "0600" notify: - restart strongswan - name: Include additional ipsec config lineinfile: dest: "{{ item.dest }}" line: "{{ item.line }}" create: true mode: "{{ item.mode }}" loop: - dest: "{{ configs_prefix }}/ipsec.conf" line: include ipsec.{{ IP_subject_alt_name }}.conf mode: '0644' - dest: "{{ configs_prefix }}/ipsec.secrets" line: include ipsec.{{ IP_subject_alt_name }}.secrets mode: '0600' notify: - restart strongswan - name: Configure libstrongswan to relax CA constraints copy: src: libstrongswan-relax-constraints.conf dest: "{{ configs_prefix }}/strongswan.d/relax-ca-constraints.conf" owner: root group: root mode: '0644' - name: Setup the certificates and keys template: src: "{{ item.src }}" dest: "{{ item.dest }}" mode: "{{ item.mode }}" loop: - src: configs/{{ IP_subject_alt_name }}/ipsec/.pki/certs/{{ vpn_user }}.crt dest: "{{ configs_prefix }}/ipsec.d/certs/{{ vpn_user }}.crt" mode: '0644' - src: configs/{{ IP_subject_alt_name }}/ipsec/.pki/cacert.pem dest: "{{ configs_prefix }}/ipsec.d/cacerts/{{ IP_subject_alt_name }}.pem" mode: '0644' - src: configs/{{ IP_subject_alt_name }}/ipsec/.pki/private/{{ vpn_user }}.key dest: "{{ configs_prefix }}/ipsec.d/private/{{ vpn_user }}.key" mode: '0600' notify: - restart strongswan ================================================ FILE: roles/client/tasks/systems/CentOS.yml ================================================ --- - name: Set OS specific facts set_fact: prerequisites: - epel-release configs_prefix: /etc/strongswan ================================================ FILE: roles/client/tasks/systems/Debian.yml ================================================ --- - name: Set OS specific facts set_fact: prerequisites: - libstrongswan-standard-plugins configs_prefix: /etc ================================================ FILE: roles/client/tasks/systems/Fedora.yml ================================================ --- - name: Set OS specific facts set_fact: prerequisites: - libselinux-python configs_prefix: /etc/strongswan ================================================ FILE: roles/client/tasks/systems/Ubuntu.yml ================================================ --- - name: Set OS specific facts set_fact: prerequisites: - libstrongswan-standard-plugins configs_prefix: /etc ================================================ FILE: roles/client/tasks/systems/main.yml ================================================ --- - include_tasks: Debian.yml when: ansible_distribution == 'Debian' - include_tasks: Ubuntu.yml when: ansible_distribution == 'Ubuntu' - include_tasks: CentOS.yml when: ansible_distribution == 'CentOS' - include_tasks: Fedora.yml when: ansible_distribution == 'Fedora' ================================================ FILE: roles/cloud-azure/defaults/main.yml ================================================ --- # az account list-locations --query 'sort_by([].{name:name,displayName:displayName,regionalDisplayName:regionalDisplayName}, &name)' -o yaml azure_regions: - displayName: Asia name: asia regionalDisplayName: Asia - displayName: Asia Pacific name: asiapacific regionalDisplayName: Asia Pacific - displayName: Australia name: australia regionalDisplayName: Australia - displayName: Australia Central name: australiacentral regionalDisplayName: (Asia Pacific) Australia Central - displayName: Australia Central 2 name: australiacentral2 regionalDisplayName: (Asia Pacific) Australia Central 2 - displayName: Australia East name: australiaeast regionalDisplayName: (Asia Pacific) Australia East - displayName: Australia Southeast name: australiasoutheast regionalDisplayName: (Asia Pacific) Australia Southeast - displayName: Brazil name: brazil regionalDisplayName: Brazil - displayName: Brazil South name: brazilsouth regionalDisplayName: (South America) Brazil South - displayName: Brazil Southeast name: brazilsoutheast regionalDisplayName: (South America) Brazil Southeast - displayName: Brazil US name: brazilus regionalDisplayName: (South America) Brazil US - displayName: Canada name: canada regionalDisplayName: Canada - displayName: Canada Central name: canadacentral regionalDisplayName: (Canada) Canada Central - displayName: Canada East name: canadaeast regionalDisplayName: (Canada) Canada East - displayName: Central India name: centralindia regionalDisplayName: (Asia Pacific) Central India - displayName: Central US name: centralus regionalDisplayName: (US) Central US - displayName: Central US EUAP name: centraluseuap regionalDisplayName: (US) Central US EUAP - displayName: Central US (Stage) name: centralusstage regionalDisplayName: (US) Central US (Stage) - displayName: East Asia name: eastasia regionalDisplayName: (Asia Pacific) East Asia - displayName: East Asia (Stage) name: eastasiastage regionalDisplayName: (Asia Pacific) East Asia (Stage) - displayName: East US name: eastus regionalDisplayName: (US) East US - displayName: East US 2 name: eastus2 regionalDisplayName: (US) East US 2 - displayName: East US 2 EUAP name: eastus2euap regionalDisplayName: (US) East US 2 EUAP - displayName: East US 2 (Stage) name: eastus2stage regionalDisplayName: (US) East US 2 (Stage) - displayName: East US (Stage) name: eastusstage regionalDisplayName: (US) East US (Stage) - displayName: East US STG name: eastusstg regionalDisplayName: (US) East US STG - displayName: Europe name: europe regionalDisplayName: Europe - displayName: France name: france regionalDisplayName: France - displayName: France Central name: francecentral regionalDisplayName: (Europe) France Central - displayName: France South name: francesouth regionalDisplayName: (Europe) France South - displayName: Germany name: germany regionalDisplayName: Germany - displayName: Germany North name: germanynorth regionalDisplayName: (Europe) Germany North - displayName: Germany West Central name: germanywestcentral regionalDisplayName: (Europe) Germany West Central - displayName: Global name: global regionalDisplayName: Global - displayName: India name: india regionalDisplayName: India - displayName: Israel name: israel regionalDisplayName: Israel - displayName: Israel Central name: israelcentral regionalDisplayName: (Middle East) Israel Central - displayName: Italy name: italy regionalDisplayName: Italy - displayName: Italy North name: italynorth regionalDisplayName: (Europe) Italy North - displayName: Japan name: japan regionalDisplayName: Japan - displayName: Japan East name: japaneast regionalDisplayName: (Asia Pacific) Japan East - displayName: Japan West name: japanwest regionalDisplayName: (Asia Pacific) Japan West - displayName: Jio India Central name: jioindiacentral regionalDisplayName: (Asia Pacific) Jio India Central - displayName: Jio India West name: jioindiawest regionalDisplayName: (Asia Pacific) Jio India West - displayName: Korea name: korea regionalDisplayName: Korea - displayName: Korea Central name: koreacentral regionalDisplayName: (Asia Pacific) Korea Central - displayName: Korea South name: koreasouth regionalDisplayName: (Asia Pacific) Korea South - displayName: New Zealand name: newzealand regionalDisplayName: New Zealand - displayName: North Central US name: northcentralus regionalDisplayName: (US) North Central US - displayName: North Central US (Stage) name: northcentralusstage regionalDisplayName: (US) North Central US (Stage) - displayName: North Europe name: northeurope regionalDisplayName: (Europe) North Europe - displayName: Norway name: norway regionalDisplayName: Norway - displayName: Norway East name: norwayeast regionalDisplayName: (Europe) Norway East - displayName: Norway West name: norwaywest regionalDisplayName: (Europe) Norway West - displayName: Poland name: poland regionalDisplayName: Poland - displayName: Poland Central name: polandcentral regionalDisplayName: (Europe) Poland Central - displayName: Qatar name: qatar regionalDisplayName: Qatar - displayName: Qatar Central name: qatarcentral regionalDisplayName: (Middle East) Qatar Central - displayName: Singapore name: singapore regionalDisplayName: Singapore - displayName: South Africa name: southafrica regionalDisplayName: South Africa - displayName: South Africa North name: southafricanorth regionalDisplayName: (Africa) South Africa North - displayName: South Africa West name: southafricawest regionalDisplayName: (Africa) South Africa West - displayName: South Central US name: southcentralus regionalDisplayName: (US) South Central US - displayName: South Central US (Stage) name: southcentralusstage regionalDisplayName: (US) South Central US (Stage) - displayName: Southeast Asia name: southeastasia regionalDisplayName: (Asia Pacific) Southeast Asia - displayName: Southeast Asia (Stage) name: southeastasiastage regionalDisplayName: (Asia Pacific) Southeast Asia (Stage) - displayName: South India name: southindia regionalDisplayName: (Asia Pacific) South India - displayName: Sweden name: sweden regionalDisplayName: Sweden - displayName: Sweden Central name: swedencentral regionalDisplayName: (Europe) Sweden Central - displayName: Switzerland name: switzerland regionalDisplayName: Switzerland - displayName: Switzerland North name: switzerlandnorth regionalDisplayName: (Europe) Switzerland North - displayName: Switzerland West name: switzerlandwest regionalDisplayName: (Europe) Switzerland West - displayName: United Arab Emirates name: uae regionalDisplayName: United Arab Emirates - displayName: UAE Central name: uaecentral regionalDisplayName: (Middle East) UAE Central - displayName: UAE North name: uaenorth regionalDisplayName: (Middle East) UAE North - displayName: United Kingdom name: uk regionalDisplayName: United Kingdom - displayName: UK South name: uksouth regionalDisplayName: (Europe) UK South - displayName: UK West name: ukwest regionalDisplayName: (Europe) UK West - displayName: United States name: unitedstates regionalDisplayName: United States - displayName: United States EUAP name: unitedstateseuap regionalDisplayName: United States EUAP - displayName: West Central US name: westcentralus regionalDisplayName: (US) West Central US - displayName: West Europe name: westeurope regionalDisplayName: (Europe) West Europe - displayName: West India name: westindia regionalDisplayName: (Asia Pacific) West India - displayName: West US name: westus regionalDisplayName: (US) West US - displayName: West US 2 name: westus2 regionalDisplayName: (US) West US 2 - displayName: West US 2 (Stage) name: westus2stage regionalDisplayName: (US) West US 2 (Stage) - displayName: West US 3 name: westus3 regionalDisplayName: (US) West US 3 - displayName: West US (Stage) name: westusstage regionalDisplayName: (US) West US (Stage) ================================================ FILE: roles/cloud-azure/files/deployment.json ================================================ { "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", "contentVersion": "1.0.0.0", "parameters": { "sshKeyData": { "type": "string" }, "WireGuardPort": { "type": "int" }, "vmSize": { "type": "string" }, "imageReferencePublisher": { "type": "string" }, "imageReferenceOffer": { "type": "string" }, "imageReferenceSku": { "type": "string" }, "imageReferenceVersion": { "type": "string" }, "osDiskType": { "type": "string" }, "SshPort": { "type": "int" }, "UserData": { "type": "string" } }, "variables": { "vnetID": "[resourceId('Microsoft.Network/virtualNetworks', resourceGroup().name)]", "subnet1Ref": "[concat(variables('vnetID'),'/subnets/', resourceGroup().name)]" }, "resources": [ { "apiVersion": "2015-06-15", "type": "Microsoft.Network/networkSecurityGroups", "name": "[resourceGroup().name]", "location": "[resourceGroup().location]", "properties": { "securityRules": [ { "name": "AllowSSH", "properties": { "description": "Allow SSH", "protocol": "Tcp", "sourcePortRange": "*", "destinationPortRange": "[parameters('SshPort')]", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 100, "direction": "Inbound" } }, { "name": "AllowIPSEC500", "properties": { "description": "Allow UDP to port 500", "protocol": "Udp", "sourcePortRange": "*", "destinationPortRange": "500", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 110, "direction": "Inbound" } }, { "name": "AllowIPSEC4500", "properties": { "description": "Allow UDP to port 4500", "protocol": "Udp", "sourcePortRange": "*", "destinationPortRange": "4500", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 120, "direction": "Inbound" } }, { "name": "AllowWireGuard", "properties": { "description": "Locks inbound down to ssh default port 22.", "protocol": "Udp", "sourcePortRange": "*", "destinationPortRange": "[parameters('WireGuardPort')]", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 130, "direction": "Inbound" } } ] } }, { "apiVersion": "2015-06-15", "type": "Microsoft.Network/publicIPAddresses", "name": "[resourceGroup().name]", "location": "[resourceGroup().location]", "properties": { "publicIPAllocationMethod": "Static" } }, { "apiVersion": "2015-06-15", "type": "Microsoft.Network/virtualNetworks", "name": "[resourceGroup().name]", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ "10.10.0.0/16" ] }, "subnets": [ { "name": "[resourceGroup().name]", "properties": { "addressPrefix": "10.10.0.0/24" } } ] } }, { "apiVersion": "2015-06-15", "type": "Microsoft.Network/networkInterfaces", "name": "[resourceGroup().name]", "location": "[resourceGroup().location]", "dependsOn": [ "[concat('Microsoft.Network/networkSecurityGroups/', resourceGroup().name)]", "[concat('Microsoft.Network/publicIPAddresses/', resourceGroup().name)]", "[concat('Microsoft.Network/virtualNetworks/', resourceGroup().name)]" ], "properties": { "networkSecurityGroup": { "id": "[resourceId('Microsoft.Network/networkSecurityGroups', resourceGroup().name)]" }, "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "[resourceId('Microsoft.Network/publicIPAddresses', resourceGroup().name)]" }, "subnet": { "id": "[variables('subnet1Ref')]" } } } ] } }, { "apiVersion": "2016-04-30-preview", "type": "Microsoft.Compute/virtualMachines", "name": "[resourceGroup().name]", "location": "[resourceGroup().location]", "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', resourceGroup().name)]" ], "properties": { "hardwareProfile": { "vmSize": "[parameters('vmSize')]" }, "osProfile": { "computerName": "[resourceGroup().name]", "customData": "[parameters('UserData')]", "adminUsername": "algo", "linuxConfiguration": { "disablePasswordAuthentication": true, "ssh": { "publicKeys": [ { "path": "/home/algo/.ssh/authorized_keys", "keyData": "[parameters('sshKeyData')]" } ] } } }, "storageProfile": { "imageReference": { "publisher": "[parameters('imageReferencePublisher')]", "offer": "[parameters('imageReferenceOffer')]", "sku": "[parameters('imageReferenceSku')]", "version": "[parameters('imageReferenceVersion')]" }, "osDisk": { "createOption": "FromImage", "managedDisk": { "storageAccountType": "[parameters('osDiskType')]" } } }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', resourceGroup().name)]" } ] } } } ], "outputs": { "publicIPAddresses": { "type": "string", "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',resourceGroup().name),providers('Microsoft.Network', 'publicIPAddresses').apiVersions[0]).ipAddress]" } } } ================================================ FILE: roles/cloud-azure/tasks/destroy.yml ================================================ --- - name: Destroy Azure resource group azure.azcollection.azure_rm_resourcegroup: name: "{{ algo_server_name }}" state: absent force_delete_nonempty: true secret: "{{ secret }}" tenant: "{{ tenant }}" client_id: "{{ client_id }}" subscription_id: "{{ subscription_id }}" ================================================ FILE: roles/cloud-azure/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - set_fact: algo_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ azure_regions[_algo_region.user_input | int - 1]['name'] }}{%- else -%}{{ azure_regions[default_region | int - 1]['name'] }}{%- endif -%} - name: Create AlgoVPN Server azure.azcollection.azure_rm_deployment: state: present deployment_name: "{{ algo_server_name }}" template: "{{ lookup('file', role_path + '/files/deployment.json') }}" secret: "{{ secret }}" tenant: "{{ tenant }}" client_id: "{{ client_id }}" subscription_id: "{{ subscription_id }}" resource_group_name: "{{ algo_server_name }}" location: "{{ algo_region }}" parameters: sshKeyData: value: "{{ lookup('file', SSH_keys.public) }}" WireGuardPort: value: "{{ wireguard_port }}" vmSize: value: "{{ cloud_providers.azure.size }}" imageReferencePublisher: value: "{{ cloud_providers.azure.image.publisher }}" imageReferenceOffer: value: "{{ cloud_providers.azure.image.offer }}" imageReferenceSku: value: "{{ cloud_providers.azure.image.sku }}" imageReferenceVersion: value: "{{ cloud_providers.azure.image.version }}" osDiskType: value: "{{ cloud_providers.azure.osDisk.type }}" SshPort: value: "{{ ssh_port }}" UserData: value: "{{ lookup('template', 'files/cloud-init/base.yml') | b64encode }}" register: azure_rm_deployment - set_fact: cloud_instance_ip: "{{ azure_rm_deployment.deployment.outputs.publicIPAddresses.value }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-azure/tasks/prompts.yml ================================================ --- - set_fact: secret: "{{ azure_secret | default(lookup('env', 'AZURE_SECRET'), true) }}" tenant: "{{ azure_tenant | default(lookup('env', 'AZURE_TENANT'), true) }}" client_id: "{{ azure_client_id | default(lookup('env', 'AZURE_CLIENT_ID'), true) }}" subscription_id: "{{ azure_subscription_id | default(lookup('env', 'AZURE_SUBSCRIPTION_ID'), true) }}" no_log: true - when: region is undefined block: - name: Set the default region set_fact: default_region: >- {% for r in azure_regions %}{%- if r['name'] == "eastus" %}{{ loop.index }}{% endif %}{%- endfor %} - pause: prompt: | What region should the server be located in? {% for r in azure_regions %} {{ loop.index }}. {{ r['regionalDisplayName'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region ================================================ FILE: roles/cloud-cloudstack/tasks/destroy.yml ================================================ --- - environment: CLOUDSTACK_KEY: "{{ algo_cs_key }}" CLOUDSTACK_SECRET: "{{ algo_cs_token }}" CLOUDSTACK_ENDPOINT: "{{ algo_cs_url }}" no_log: true block: - name: Destroy CloudStack instance cs_instance: name: "{{ algo_server_name }}" state: expunged - name: Remove security group cs_securitygroup: name: "{{ algo_server_name }}-security_group" state: absent failed_when: false ================================================ FILE: roles/cloud-cloudstack/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - environment: CLOUDSTACK_KEY: "{{ algo_cs_key }}" CLOUDSTACK_SECRET: "{{ algo_cs_token }}" CLOUDSTACK_ENDPOINT: "{{ algo_cs_url }}" no_log: true block: - set_fact: algo_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input is defined and _algo_region.user_input | length > 0 -%}{{ cs_zones[_algo_region.user_input | int - 1]['name'] }}{%- else -%}{{ cs_zones[default_zone | int - 1]['name'] }}{%- endif -%} - name: Security group created cs_securitygroup: name: "{{ algo_server_name }}-security_group" description: AlgoVPN security group register: cs_security_group - name: Security rules created cs_securitygroup_rule: security_group: "{{ cs_security_group.name }}" protocol: "{{ item.proto }}" start_port: "{{ item.start_port }}" end_port: "{{ item.end_port }}" cidr: "{{ item.range }}" loop: - { proto: tcp, start_port: "{{ ssh_port }}", end_port: "{{ ssh_port }}", range: 0.0.0.0/0 } - { proto: udp, start_port: 4500, end_port: 4500, range: 0.0.0.0/0 } - { proto: udp, start_port: 500, end_port: 500, range: 0.0.0.0/0 } - { proto: udp, start_port: "{{ wireguard_port }}", end_port: "{{ wireguard_port }}", range: 0.0.0.0/0 } - name: Set facts set_fact: image_id: "{{ cloud_providers.cloudstack.image }}" size: "{{ cloud_providers.cloudstack.size }}" disk: "{{ cloud_providers.cloudstack.disk }}" - name: Server created cs_instance: name: "{{ algo_server_name }}" root_disk_size: "{{ disk }}" template: "{{ image_id }}" security_groups: "{{ cs_security_group.name }}" zone: "{{ algo_region }}" service_offering: "{{ size }}" user_data: "{{ lookup('template', 'files/cloud-init/base.yml') }}" register: cs_server - set_fact: cloud_instance_ip: "{{ cs_server.default_ip }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-cloudstack/tasks/prompts.yml ================================================ --- - block: - pause: prompt: | Enter the API key (https://trailofbits.github.io/algo/cloud-cloudstack.html): echo: false register: _cs_key when: - cs_key is undefined - lookup('env', 'CLOUDSTACK_KEY')|length <= 0 no_log: true - pause: prompt: | Enter the API secret (https://trailofbits.github.io/algo/cloud-cloudstack.html): echo: false register: _cs_secret when: - cs_secret is undefined - lookup('env', 'CLOUDSTACK_SECRET')|length <= 0 no_log: true - pause: prompt: | Enter the API endpoint (https://trailofbits.github.io/algo/cloud-cloudstack.html) register: _cs_url when: - cs_url is undefined - lookup('env', 'CLOUDSTACK_ENDPOINT') | length <= 0 - set_fact: algo_cs_key: "{{ cs_key | default(_cs_key.user_input | default(None)) | default(lookup('env', 'CLOUDSTACK_KEY'), true) }}" algo_cs_token: "{{ cs_secret | default(_cs_secret.user_input | default(None)) | default(lookup('env', 'CLOUDSTACK_SECRET'), true) }}" algo_cs_url: >- {{ cs_url | default(_cs_url.user_input|default(None)) | default(lookup('env', 'CLOUDSTACK_ENDPOINT'), true) }} no_log: true - name: Check for Exoscale API endpoint fail: msg: | ERROR: Exoscale CloudStack API has been deprecated as of May 1, 2024. Exoscale has migrated from CloudStack to their proprietary API v2, which is not compatible with CloudStack-based tools. Algo no longer supports Exoscale deployments. Please consider these alternative providers: - Hetzner (provider: hetzner) - German provider with European coverage - DigitalOcean (provider: digitalocean) - Has Amsterdam and Frankfurt regions - Vultr (provider: vultr) - Multiple European locations - Scaleway (provider: scaleway) - French provider If you're using a different CloudStack provider, please provide the correct API endpoint. when: "'exoscale.com' in algo_cs_url or 'exoscale.ch' in algo_cs_url" - name: Get zones on cloud cs_zone_info: register: _cs_zones environment: CLOUDSTACK_KEY: "{{ algo_cs_key }}" CLOUDSTACK_SECRET: "{{ algo_cs_token }}" CLOUDSTACK_ENDPOINT: "{{ algo_cs_url }}" no_log: true - name: Extract zones from output set_fact: cs_zones: "{{ _cs_zones['zones'] | sort(attribute='name') }}" - name: Set the default zone set_fact: default_zone: "1" # Default to first zone in the list - pause: prompt: | What zone should the server be located in? {% for z in cs_zones %} {{ loop.index }}. {{ z['name'] }} {% endfor %} Enter the number of your desired zone [{{ default_zone }}] register: _algo_region when: region is undefined ================================================ FILE: roles/cloud-digitalocean/tasks/destroy.yml ================================================ --- - name: Destroy DigitalOcean droplet digital_ocean_droplet: state: absent name: "{{ algo_server_name }}" oauth_token: "{{ algo_do_token }}" unique_name: true ================================================ FILE: roles/cloud-digitalocean/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Upload the SSH key digital_ocean_sshkey: oauth_token: "{{ algo_do_token }}" name: "{{ SSH_keys.comment }}" ssh_pub_key: "{{ lookup('file', SSH_keys.public) }}" register: do_ssh_key - name: Creating a droplet... digital_ocean_droplet: state: present name: "{{ algo_server_name }}" oauth_token: "{{ algo_do_token }}" size: "{{ cloud_providers.digitalocean.size }}" region: "{{ algo_do_region }}" image: "{{ cloud_providers.digitalocean.image }}" wait_timeout: 300 unique_name: true ipv6: true ssh_keys: "{{ do_ssh_key.data.ssh_key.id }}" user_data: "{{ lookup('template', 'files/cloud-init/base.yml') | string }}" tags: - Environment:Algo register: digital_ocean_droplet # Return data is not idempotent - set_fact: droplet: "{{ digital_ocean_droplet.data.droplet | default(digital_ocean_droplet.data) }}" - when: alternative_ingress_ip | bool block: - name: Create a Floating IP community.digitalocean.digital_ocean_floating_ip: state: present oauth_token: "{{ algo_do_token }}" droplet_id: "{{ droplet.id }}" register: digital_ocean_floating_ip - name: Set the static ip as a fact set_fact: cloud_alternative_ingress_ip: "{{ digital_ocean_floating_ip.data.floating_ip.ip }}" - set_fact: cloud_instance_ip: "{{ (droplet.networks.v4 | selectattr('type', '==', 'public')).0.ip_address }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-digitalocean/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter your API token. The token must have read and write permissions (https://cloud.digitalocean.com/settings/api/tokens): echo: false register: _do_token when: - do_token is undefined - lookup('env', 'DO_API_TOKEN')|length <= 0 no_log: true - name: Set the token as a fact set_fact: algo_do_token: "{{ do_token | default(_do_token.user_input | default(None)) | default(lookup('env', 'DO_API_TOKEN'), true) }}" no_log: true - name: Get regions uri: url: https://api.digitalocean.com/v2/regions method: GET status_code: 200 headers: Content-Type: application/json Authorization: Bearer {{ algo_do_token }} register: _do_regions no_log: "{{ algo_no_log | default(true) }}" failed_when: false - name: Check DigitalOcean API response fail: msg: | {% if _do_regions.status == 401 %} DigitalOcean API authentication failed (401 Unauthorized) Your API token is invalid or expired. Please: 1. Go to https://cloud.digitalocean.com/settings/api/tokens 2. Create a new token with 'Read' and 'Write' scopes 3. Run the deployment again with the new token {% elif _do_regions.status == 403 %} DigitalOcean API access denied (403 Forbidden) Your API token lacks required permissions. Please: 1. Go to https://cloud.digitalocean.com/settings/api/tokens 2. Ensure your token has both 'Read' and 'Write' scopes 3. Consider creating a new token with full access {% elif _do_regions.status == 429 %} DigitalOcean API rate limit exceeded (429 Too Many Requests) You've hit the API rate limit. Please: 1. Wait 5-10 minutes before retrying 2. Check if other applications are using your token {% elif _do_regions.status == 500 or _do_regions.status == 502 or _do_regions.status == 503 %} DigitalOcean API server error ({{ _do_regions.status }}) DigitalOcean is experiencing issues. Please: 1. Check https://status.digitalocean.com for outages 2. Wait a few minutes and try again {% elif _do_regions.status is undefined %} Failed to connect to DigitalOcean API Could not reach api.digitalocean.com. Please check: 1. Your internet connection 2. Firewall rules (port 443 must be open) 3. DNS resolution for api.digitalocean.com {% else %} DigitalOcean API error (HTTP {{ _do_regions.status }}) An unexpected error occurred. Please: 1. Verify your API token at https://cloud.digitalocean.com/settings/api/tokens 2. Check https://status.digitalocean.com for service issues {% endif %} For detailed error messages: Set 'algo_no_log: false' in config.cfg and run again when: _do_regions.status != 200 - name: Set facts about the regions set_fact: do_regions: "{{ _do_regions.json.regions | selectattr('available', 'true') | sort(attribute='slug') }}" - name: Set default region set_fact: default_region: >- {% for r in do_regions %}{%- if r['slug'] == "nyc3" %}{{ loop.index }}{% endif %}{%- endfor %} - pause: prompt: | What region should the server be located in? {% for r in do_regions %} {{ loop.index }}. {{ r['slug'] }} {{ r['name'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region when: region is undefined - name: Set additional facts set_fact: algo_do_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ do_regions[_algo_region.user_input | int - 1]['slug'] }}{%- else -%}{{ do_regions[default_region | int - 1]['slug'] }}{%- endif -%} ================================================ FILE: roles/cloud-ec2/defaults/main.yml ================================================ --- encrypted: "{{ cloud_providers.ec2.encrypted }}" ec2_vpc_nets: cidr_block: 172.16.0.0/16 subnet_cidr: 172.16.254.0/23 existing_eip: "" ================================================ FILE: roles/cloud-ec2/files/stack.yaml ================================================ --- AWSTemplateFormatVersion: '2010-09-09' Description: 'Algo VPN stack' Parameters: InstanceTypeParameter: Type: String Default: t3.micro ImageIdParameter: Type: AWS::EC2::Image::Id WireGuardPort: Type: String UseThisElasticIP: Type: String Default: '' EbsEncrypted: Type: String UserData: Type: String SshPort: Type: String InstanceMarketTypeParameter: Description: Launch a Spot instance or standard on-demand instance Type: String Default: on-demand AllowedValues: - spot - on-demand Conditions: AllocateNewEIP: !Equals [!Ref UseThisElasticIP, ''] AssociateExistingEIP: !Not [!Equals [!Ref UseThisElasticIP, '']] InstanceIsSpot: !Equals [spot, !Ref InstanceMarketTypeParameter] Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 172.16.0.0/16 EnableDnsSupport: true EnableDnsHostnames: true InstanceTenancy: default Tags: - Key: Name Value: !Ref AWS::StackName VPCIPv6: Type: AWS::EC2::VPCCidrBlock Properties: AmazonProvidedIpv6CidrBlock: true VpcId: !Ref VPC InternetGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: !Ref AWS::StackName Subnet: Type: AWS::EC2::Subnet Properties: CidrBlock: 172.16.254.0/23 MapPublicIpOnLaunch: false VpcId: !Ref VPC Tags: - Key: Name Value: !Ref AWS::StackName VPCGatewayAttachment: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref VPC InternetGatewayId: !Ref InternetGateway RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: !Ref AWS::StackName Route: Type: AWS::EC2::Route DependsOn: - VPCGatewayAttachment Properties: RouteTableId: !Ref RouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway RouteIPv6: Type: AWS::EC2::Route DependsOn: - VPCGatewayAttachment Properties: RouteTableId: !Ref RouteTable DestinationIpv6CidrBlock: "::/0" GatewayId: !Ref InternetGateway SubnetIPv6: Type: AWS::EC2::SubnetCidrBlock DependsOn: - VPCIPv6 Properties: Ipv6CidrBlock: "Fn::Join": - "" - - !Select [0, !Split ["::", !Select [0, !GetAtt VPC.Ipv6CidrBlocks]]] - "::dead:beef/64" SubnetId: !Ref Subnet RouteSubnet: Type: "AWS::EC2::SubnetRouteTableAssociation" Properties: RouteTableId: !Ref RouteTable SubnetId: !Ref Subnet InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup DependsOn: - Subnet Properties: VpcId: !Ref VPC GroupDescription: Enable SSH and IPsec SecurityGroupIngress: - IpProtocol: tcp FromPort: !Ref SshPort ToPort: !Ref SshPort CidrIp: 0.0.0.0/0 - IpProtocol: udp FromPort: '500' ToPort: '500' CidrIp: 0.0.0.0/0 - IpProtocol: udp FromPort: '4500' ToPort: '4500' CidrIp: 0.0.0.0/0 - IpProtocol: udp FromPort: !Ref WireGuardPort ToPort: !Ref WireGuardPort CidrIp: 0.0.0.0/0 Tags: - Key: Name Value: !Ref AWS::StackName EC2LaunchTemplate: Type: AWS::EC2::LaunchTemplate Condition: InstanceIsSpot # Only create this template if requested Properties: # a spot instance_market_type in config.cfg LaunchTemplateName: !Ref AWS::StackName LaunchTemplateData: InstanceMarketOptions: MarketType: spot EC2Instance: Type: AWS::EC2::Instance DependsOn: - SubnetIPv6 Properties: InstanceType: Ref: InstanceTypeParameter BlockDeviceMappings: - DeviceName: /dev/sda1 Ebs: DeleteOnTermination: true VolumeSize: 8 Encrypted: !Ref EbsEncrypted InstanceInitiatedShutdownBehavior: terminate SecurityGroupIds: - Ref: InstanceSecurityGroup ImageId: Ref: ImageIdParameter SubnetId: !Ref Subnet Ipv6AddressCount: 1 UserData: !Ref UserData LaunchTemplate: !If # Only if Conditions created "EC2LaunchTemplate" - InstanceIsSpot - LaunchTemplateId: !Ref EC2LaunchTemplate Version: 1 - !Ref AWS::NoValue # Else this LaunchTemplate not set Tags: - Key: Name Value: !Ref AWS::StackName ElasticIP: Type: AWS::EC2::EIP Condition: AllocateNewEIP Properties: Domain: vpc InstanceId: !Ref EC2Instance DependsOn: - VPCGatewayAttachment ElasticIPAssociation: Type: AWS::EC2::EIPAssociation Condition: AssociateExistingEIP Properties: AllocationId: !Ref UseThisElasticIP InstanceId: !Ref EC2Instance Outputs: ElasticIP: Value: !GetAtt [EC2Instance, PublicIp] ================================================ FILE: roles/cloud-ec2/tasks/cloudformation.yml ================================================ --- # Note: Using template_body instead of deprecated 'template' parameter. # The 'template' parameter is deprecated and will be removed after 2026-05-01. - name: Deploy the template cloudformation: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" aws_session_token: "{{ session_token if session_token else omit }}" stack_name: "{{ stack_name }}" state: present region: "{{ algo_region }}" template_body: "{{ lookup('file', 'roles/cloud-ec2/files/stack.yaml') }}" template_parameters: InstanceTypeParameter: "{{ cloud_providers.ec2.size }}" ImageIdParameter: "{{ ami_image }}" WireGuardPort: "{{ wireguard_port }}" UseThisElasticIP: "{{ existing_eip }}" EbsEncrypted: "{{ encrypted }}" UserData: "{{ lookup('template', 'files/cloud-init/base.yml') | b64encode }}" SshPort: "{{ ssh_port }}" InstanceMarketTypeParameter: "{{ cloud_providers.ec2.instance_market_type }}" tags: Environment: Algo register: stack no_log: true ================================================ FILE: roles/cloud-ec2/tasks/destroy.yml ================================================ --- - name: Set stack name set_fact: stack_name: "{{ algo_server_name | replace('.', '-') }}" - name: Destroy CloudFormation stack cloudformation: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" aws_session_token: "{{ session_token if session_token else omit }}" stack_name: "{{ stack_name }}" state: absent region: "{{ algo_region }}" no_log: true ================================================ FILE: roles/cloud-ec2/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Locate official AMI for region ec2_ami_info: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" owners: "{{ cloud_providers.ec2.image.owner }}" region: "{{ algo_region }}" filters: architecture: "{{ cloud_providers.ec2.image.arch }}" name: ubuntu/images/hvm-ssd/{{ cloud_providers.ec2.image.name }}-*64-server-* register: ami_search no_log: true - name: Set the ami id as a fact set_fact: ami_image: "{{ (ami_search.images | sort(attribute='creation_date') | last)['image_id'] }}" - name: Deploy the stack import_tasks: cloudformation.yml - set_fact: cloud_instance_ip: "{{ stack.stack_outputs.ElasticIP }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-ec2/tasks/prompts.yml ================================================ --- # Discover AWS credentials from standard locations - name: Set AWS credentials file path set_fact: aws_credentials_path: "{{ lookup('env', 'AWS_SHARED_CREDENTIALS_FILE') | default(lookup('env', 'HOME') + '/.aws/credentials', true) }}" aws_profile: "{{ lookup('env', 'AWS_PROFILE') | default('default', true) }}" # Try to read credentials from file if not already provided - when: - aws_access_key is undefined - lookup('env', 'AWS_ACCESS_KEY_ID')|length <= 0 block: - name: Check if AWS credentials file exists stat: path: "{{ aws_credentials_path }}" register: aws_creds_file delegate_to: localhost - name: Read AWS credentials from file set_fact: _file_access_key: "{{ lookup('ini', 'aws_access_key_id', section=aws_profile, file=aws_credentials_path, errors='ignore') | default('', true) }}" _file_secret_key: "{{ lookup('ini', 'aws_secret_access_key', section=aws_profile, file=aws_credentials_path, errors='ignore') | default('', true) }}" _file_session_token: "{{ lookup('ini', 'aws_session_token', section=aws_profile, file=aws_credentials_path, errors='ignore') | default('', true) }}" when: aws_creds_file.stat.exists no_log: true # Prompt for credentials if still not available - pause: prompt: | Enter your AWS Access Key ID (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) Note: Make sure to use an IAM user with an acceptable policy attached (see https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md) echo: false register: _aws_access_key when: - aws_access_key is undefined - lookup('env', 'AWS_ACCESS_KEY_ID')|length <= 0 - _file_access_key is undefined or _file_access_key|length <= 0 - pause: prompt: | Enter your AWS Secret Access Key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) echo: false register: _aws_secret_key when: - aws_secret_key is undefined - lookup('env', 'AWS_SECRET_ACCESS_KEY')|length <= 0 - _file_secret_key is undefined or _file_secret_key|length <= 0 # Set final credentials with proper precedence # Note: The 'true' parameter in default() is required for Ansible 12+ compatibility. # Without it, empty strings from env lookups stop the default chain since they're # "defined" values, not "undefined". The 'true' makes default() also trigger on # falsy values (empty strings, None). - set_fact: access_key: >- {{ aws_access_key | default(lookup('env', 'AWS_ACCESS_KEY_ID'), true) | default(_file_access_key, true) | default(_aws_access_key.user_input | default(None), true) }} secret_key: >- {{ aws_secret_key | default(lookup('env', 'AWS_SECRET_ACCESS_KEY'), true) | default(_file_secret_key, true) | default(_aws_secret_key.user_input | default(None), true) }} session_token: >- {{ aws_session_token | default(lookup('env', 'AWS_SESSION_TOKEN'), true) | default(_file_session_token, true) | default('') }} no_log: true - when: region is undefined block: - name: Get regions aws_region_info: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" aws_session_token: "{{ session_token if session_token else omit }}" region: us-east-1 register: _aws_regions no_log: true - name: Set facts about the regions set_fact: aws_regions: "{{ _aws_regions.regions | sort(attribute='region_name') }}" - name: Set the default region set_fact: default_region: >- {%- for r in aws_regions -%} {%- if r['region_name'] == "us-east-1" %}{{ loop.index }}{% endif -%} {%- endfor %} - pause: prompt: | What region should the server be located in? (https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region) {% for r in aws_regions %} {{ loop.index }}. {{ r['region_name'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region - name: Set algo_region and stack_name facts set_fact: algo_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ aws_regions[_algo_region.user_input | int - 1]['region_name'] }}{%- else -%}{{ aws_regions[default_region | int - 1]['region_name'] }}{%- endif -%} stack_name: "{{ algo_server_name | replace('.', '-') }}" - when: cloud_providers.ec2.use_existing_eip block: - name: Get existing available Elastic IPs ec2_eip_info: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" aws_session_token: "{{ session_token if session_token else omit }}" region: "{{ algo_region }}" register: raw_eip_addresses no_log: true - set_fact: available_eip_addresses: "{{ raw_eip_addresses.addresses | selectattr('association_id', 'undefined') | list }}" - pause: prompt: >- What Elastic IP would you like to use? {% for eip in available_eip_addresses %} {{ loop.index }}. {{ eip['public_ip'] }} {% endfor %} Enter the number of your desired Elastic IP register: _use_existing_eip - set_fact: existing_eip: "{{ available_eip_addresses[_use_existing_eip.user_input | int - 1]['allocation_id'] }}" ================================================ FILE: roles/cloud-gce/tasks/destroy.yml ================================================ --- - name: Get zones gcp_compute_location_info: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" scope: zones filters: - name={{ algo_region }}-* - status=UP register: gcp_compute_zone_info - name: Set zone set_fact: algo_zone: >- {{ (gcp_compute_zone_info.resources | random(seed=algo_server_name + algo_region + project_id) ).name }} - name: Destroy GCE instance gcp_compute_instance: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: "{{ algo_server_name }}" zone: "{{ algo_zone }}" state: absent - name: Remove static IP gcp_compute_address: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: "{{ algo_server_name }}" region: "{{ algo_region }}" state: absent failed_when: false - name: Remove firewall rule gcp_compute_firewall: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: algovpn state: absent failed_when: false - name: Remove network gcp_compute_network: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: algovpn state: absent failed_when: false ================================================ FILE: roles/cloud-gce/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Network configured gcp_compute_network: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: algovpn auto_create_subnetworks: true routing_config: routing_mode: REGIONAL register: gcp_compute_network - name: Firewall configured gcp_compute_firewall: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: algovpn network: "{{ gcp_compute_network }}" direction: INGRESS allowed: - ip_protocol: udp ports: - "500" - "4500" - "{{ wireguard_port | string }}" - ip_protocol: tcp ports: - "{{ ssh_port }}" - ip_protocol: icmp - when: cloud_providers.gce.external_static_ip block: - name: External IP allocated gcp_compute_address: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: "{{ algo_server_name }}" region: "{{ algo_region }}" register: gcp_compute_address - name: Set External IP as a fact set_fact: external_ip: "{{ gcp_compute_address.address }}" - name: Instance created gcp_compute_instance: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" name: "{{ algo_server_name }}" zone: "{{ algo_zone }}" machine_type: "{{ cloud_providers.gce.size }}" disks: - auto_delete: true boot: true initialize_params: source_image: projects/ubuntu-os-cloud/global/images/family/{{ cloud_providers.gce.image }} metadata: ssh-keys: algo:{{ ssh_public_key_lookup }} user-data: "{{ lookup('template', 'files/cloud-init/base.yml') }}" network_interfaces: - network: "{{ gcp_compute_network }}" access_configs: - name: "{{ algo_server_name }}" nat_ip: "{{ gcp_compute_address | default(None) }}" type: ONE_TO_ONE_NAT tags: items: - environment-algo register: gcp_compute_instance - set_fact: cloud_instance_ip: "{{ gcp_compute_instance.networkInterfaces[0].accessConfigs[0].natIP }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-gce/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter the local path to your credentials JSON file (https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts) register: _gce_credentials_file when: - gce_credentials_file is undefined - lookup('env', 'GCE_CREDENTIALS_FILE_PATH')|length <= 0 no_log: true - set_fact: credentials_file_path: >- {{ gce_credentials_file | default(_gce_credentials_file.user_input|default(None)) | default(lookup('env', 'GCE_CREDENTIALS_FILE_PATH'), true) }} ssh_public_key_lookup: "{{ lookup('file', SSH_keys.public) }}" no_log: true - set_fact: credentials_file_lookup: "{{ lookup('file', credentials_file_path) | from_json }}" no_log: true - set_fact: service_account_email: "{{ credentials_file_lookup.client_email | default(lookup('env', 'GCE_EMAIL'), true) }}" project_id: "{{ credentials_file_lookup.project_id | default(lookup('env', 'GCE_PROJECT'), true) }}" no_log: true - when: region is undefined block: - name: Get regions gcp_compute_location_info: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" scope: regions filters: status=UP register: gcp_compute_regions_info - name: Set facts about the regions set_fact: gce_regions: "{{ gcp_compute_regions_info.resources | sort(attribute='name') }}" - name: Set facts about the default region set_fact: default_region: >- {% for r in gce_regions -%} {% if r.name == "us-east1" %}{{ loop.index }}{% endif %} {%- endfor %} - pause: prompt: | What region should the server be located in? (https://cloud.google.com/compute/docs/regions-zones/#locations) {% for r in gce_regions %} {{ loop.index }}. {{ r.name }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _gce_region - name: Set region as a fact set_fact: algo_region: >- {% if region is defined %}{{ region -}} {% elif _gce_region.user_input %}{{ gce_regions[_gce_region.user_input | int - 1].name -}} {% else %}{{ gce_regions[default_region | int - 1].name }}{% endif %} - name: Get zones gcp_compute_location_info: auth_kind: serviceaccount service_account_file: "{{ credentials_file_path }}" project: "{{ project_id }}" scope: zones filters: - name={{ algo_region }}-* - status=UP register: gcp_compute_zone_info - name: Set random available zone as a fact set_fact: algo_zone: "{{ (gcp_compute_zone_info.resources | random(seed=algo_server_name + algo_region + project_id)).name }}" ================================================ FILE: roles/cloud-hetzner/tasks/destroy.yml ================================================ --- - name: Destroy Hetzner server hetzner.hcloud.server: name: "{{ algo_server_name }}" state: absent api_token: "{{ algo_hcloud_token }}" ================================================ FILE: roles/cloud-hetzner/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Create an ssh key hetzner.hcloud.ssh_key: name: algo-{{ 999999 | random(seed=lookup('file', SSH_keys.public)) }} public_key: "{{ lookup('file', SSH_keys.public) }}" state: present api_token: "{{ algo_hcloud_token }}" register: hcloud_ssh_key - name: Create a server... hetzner.hcloud.server: name: "{{ algo_server_name }}" location: "{{ algo_hcloud_region }}" server_type: "{{ cloud_providers.hetzner.server_type }}" image: "{{ cloud_providers.hetzner.image }}" state: present api_token: "{{ algo_hcloud_token }}" ssh_keys: "{{ hcloud_ssh_key.hcloud_ssh_key.name }}" user_data: "{{ lookup('template', 'files/cloud-init/base.yml') }}" labels: Environment: algo register: hcloud_server - set_fact: cloud_instance_ip: "{{ hcloud_server.hcloud_server.ipv4_address }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-hetzner/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter your API token (https://trailofbits.github.io/algo/cloud-hetzner.html#api-token): echo: false register: _hcloud_token when: - hcloud_token is undefined - lookup('env', 'HCLOUD_TOKEN')|length <= 0 no_log: true - name: Set the token as a fact set_fact: algo_hcloud_token: "{{ hcloud_token | default(_hcloud_token.user_input | default(None)) | default(lookup('env', 'HCLOUD_TOKEN'), true) }}" no_log: true - name: Get regions hetzner.hcloud.datacenter_info: api_token: "{{ algo_hcloud_token }}" register: _hcloud_regions - name: Set facts about the regions set_fact: hcloud_regions: "{{ _hcloud_regions.hcloud_datacenter_info | sort(attribute='location') }}" - name: Set default region set_fact: default_region: >- {%- for r in hcloud_regions -%} {%- if r['location'] == "nbg1" %}{{ loop.index }}{% endif -%} {%- endfor %} - pause: prompt: | What region should the server be located in? {% for r in hcloud_regions %} {{ loop.index }}. {{ r['location'] }} {{ r['description'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region when: region is undefined - name: Set additional facts set_fact: algo_hcloud_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ hcloud_regions[_algo_region.user_input | int - 1]['location'] }}{%- else -%}{{ hcloud_regions[default_region | int - 1]['location'] }}{%- endif -%} ================================================ FILE: roles/cloud-lightsail/files/stack.yaml ================================================ --- AWSTemplateFormatVersion: '2010-09-09' Description: 'Algo VPN stack (LightSail)' Parameters: InstanceTypeParameter: Type: String Default: 'nano_2_0' ImageIdParameter: Type: String Default: 'ubuntu_20_04' WireGuardPort: Type: String Default: '51820' SshPort: Type: String Default: '4160' UserData: Type: String Default: 'true' Resources: Instance: Type: AWS::Lightsail::Instance Properties: BlueprintId: Ref: ImageIdParameter BundleId: Ref: InstanceTypeParameter InstanceName: !Ref AWS::StackName Networking: Ports: - AccessDirection: inbound Cidrs: ['0.0.0.0/0'] Ipv6Cidrs: ['::/0'] CommonName: SSH FromPort: !Ref SshPort ToPort: !Ref SshPort Protocol: tcp - AccessDirection: inbound Cidrs: ['0.0.0.0/0'] Ipv6Cidrs: ['::/0'] CommonName: WireGuard FromPort: !Ref WireGuardPort ToPort: !Ref WireGuardPort Protocol: udp - AccessDirection: inbound Cidrs: ['0.0.0.0/0'] Ipv6Cidrs: ['::/0'] CommonName: IPSec-4500 FromPort: 4500 ToPort: 4500 Protocol: udp - AccessDirection: inbound Cidrs: ['0.0.0.0/0'] Ipv6Cidrs: ['::/0'] CommonName: IPSec-500 FromPort: 500 ToPort: 500 Protocol: udp Tags: - Key: Name Value: !Ref AWS::StackName UserData: !Ref UserData StaticIP: Type: AWS::Lightsail::StaticIp Properties: AttachedTo: !Ref Instance StaticIpName: !Join ["-", [!Ref AWS::StackName, "ip"]] DependsOn: - Instance Outputs: IpAddress: Value: !GetAtt [StaticIP, IpAddress] ================================================ FILE: roles/cloud-lightsail/tasks/cloudformation.yml ================================================ --- # Note: Using template_body instead of deprecated 'template' parameter. # The 'template' parameter is deprecated and will be removed after 2026-05-01. - name: Deploy the template cloudformation: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" stack_name: "{{ stack_name }}" state: present region: "{{ algo_region }}" template_body: "{{ lookup('file', 'roles/cloud-lightsail/files/stack.yaml') }}" template_parameters: InstanceTypeParameter: "{{ cloud_providers.lightsail.size }}" ImageIdParameter: "{{ cloud_providers.lightsail.image }}" WireGuardPort: "{{ wireguard_port }}" SshPort: "{{ ssh_port }}" UserData: "{{ lookup('template', 'files/cloud-init/base.sh') }}" tags: Environment: Algo Lightsail: true register: stack no_log: true ================================================ FILE: roles/cloud-lightsail/tasks/destroy.yml ================================================ --- - name: Set stack name set_fact: stack_name: "{{ algo_server_name | replace('.', '-') }}" - name: Destroy CloudFormation stack cloudformation: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" stack_name: "{{ stack_name }}" state: absent region: "{{ algo_region }}" no_log: true ================================================ FILE: roles/cloud-lightsail/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Deploy the stack import_tasks: cloudformation.yml - set_fact: cloud_instance_ip: "{{ stack.stack_outputs.IpAddress }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-lightsail/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) Note: Make sure to use an IAM user with an acceptable policy attached (see https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md) echo: false register: _aws_access_key when: - aws_access_key is undefined - lookup('env', 'AWS_ACCESS_KEY_ID')|length <= 0 no_log: true - pause: prompt: | Enter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) echo: false register: _aws_secret_key when: - aws_secret_key is undefined - lookup('env', 'AWS_SECRET_ACCESS_KEY')|length <= 0 no_log: true - set_fact: access_key: "{{ aws_access_key | default(_aws_access_key.user_input | default(None)) | default(lookup('env', 'AWS_ACCESS_KEY_ID'), true) }}" secret_key: "{{ aws_secret_key | default(_aws_secret_key.user_input | default(None)) | default(lookup('env', 'AWS_SECRET_ACCESS_KEY'), true) }}" no_log: true - when: region is undefined block: - name: Get regions lightsail_region_facts: aws_access_key: "{{ access_key }}" aws_secret_key: "{{ secret_key }}" region: us-east-1 register: _lightsail_regions no_log: true - name: Set facts about the regions set_fact: lightsail_regions: "{{ _lightsail_regions.data.regions | sort(attribute='name') }}" - name: Set the default region set_fact: default_region: >- {% for r in lightsail_regions -%} {% if r['name'] == "us-east-1" %}{{ loop.index }}{% endif %} {%- endfor %} - pause: prompt: | What region should the server be located in? (https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) {% for r in lightsail_regions %} {{ (loop.index | string + '.').ljust(3) }} {{ r['name'].ljust(20) }} {{ r['displayName'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region - set_fact: stack_name: "{{ algo_server_name | replace('.', '-') }}" algo_region: >- {% if region is defined %}{{ region -}} {% elif _algo_region.user_input %}{{ lightsail_regions[_algo_region.user_input | int - 1]['name'] -}} {% else %}{{ lightsail_regions[default_region | int - 1]['name'] }}{% endif %} ================================================ FILE: roles/cloud-linode/defaults/main.yml ================================================ --- linode_venv: "{{ playbook_dir }}/configs/.venvs/linode" ================================================ FILE: roles/cloud-linode/tasks/destroy.yml ================================================ --- - name: Destroy Linode instance linode.cloud.instance: api_token: "{{ algo_linode_token }}" label: "{{ algo_server_name }}" state: absent ================================================ FILE: roles/cloud-linode/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - name: Set facts set_fact: stackscript: | {{ lookup('template', 'files/cloud-init/base.sh') }} mkdir -p /var/lib/cloud/data/ || true touch /var/lib/cloud/data/result.json - name: Create a stackscript linode.cloud.stackscript: api_token: "{{ algo_linode_token }}" label: "{{ algo_server_name }}" state: present description: Environment:Algo images: - "{{ cloud_providers.linode.image }}" script: | {{ stackscript }} register: _linode_stackscript no_log: true - name: Update the stackscript uri: url: https://api.linode.com/v4/linode/stackscripts/{{ _linode_stackscript.stackscript.id }} method: PUT body_format: json body: script: | {{ stackscript }} headers: Content-Type: application/json Authorization: Bearer {{ algo_linode_token }} when: (_linode_stackscript.stackscript.script | hash('md5')) != (stackscript | hash('md5')) no_log: true - name: Creating an instance... linode.cloud.instance: api_token: "{{ algo_linode_token }}" label: "{{ algo_server_name }}" state: present region: "{{ algo_linode_region }}" image: "{{ cloud_providers.linode.image }}" type: "{{ cloud_providers.linode.type }}" authorized_keys: "{{ public_key }}" stackscript_id: "{{ _linode_stackscript.stackscript.id }}" register: _linode no_log: true - set_fact: cloud_instance_ip: "{{ _linode.instance.ipv4[0] }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-linode/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter your ACCESS token. (https://developers.linode.com/api/v4/#access-and-authentication): echo: false register: _linode_token when: - linode_token is undefined - lookup('env', 'LINODE_API_TOKEN')|length <= 0 no_log: true - name: Set the token as a fact set_fact: algo_linode_token: "{{ linode_token | default(_linode_token.user_input | default(None)) | default(lookup('env', 'LINODE_API_TOKEN'), true) }}" no_log: true - name: Get regions uri: url: https://api.linode.com/v4/regions method: GET status_code: 200 register: _linode_regions - name: Set facts about the regions set_fact: linode_regions: "{{ _linode_regions.json.data | sort(attribute='id') }}" - name: Set default region set_fact: default_region: >- {%- for r in linode_regions -%} {%- if r['id'] == "us-east" %}{{ loop.index }}{% endif -%} {%- endfor %} - pause: prompt: | What region should the server be located in? {% for r in linode_regions %} {{ loop.index }}. {{ r['id'] }} {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region when: region is undefined - name: Set additional facts set_fact: algo_linode_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ linode_regions[_algo_region.user_input | int - 1]['id'] }}{%- else -%}{{ linode_regions[default_region | int - 1]['id'] }}{%- endif -%} public_key: "{{ lookup('file', SSH_keys.public) }}" ================================================ FILE: roles/cloud-openstack/tasks/destroy.yml ================================================ --- - name: Destroy OpenStack server openstack.cloud.server: state: absent name: "{{ algo_server_name }}" - name: Remove security group openstack.cloud.security_group: state: absent name: "{{ algo_server_name }}-security_group" failed_when: false ================================================ FILE: roles/cloud-openstack/tasks/main.yml ================================================ --- - fail: msg: >- OpenStack credentials are not set. Download it from the OpenStack dashboard->Compute->API Access and source it in the shell (eg: source /tmp/dhc-openrc.sh) when: lookup('env', 'OS_AUTH_URL')|length <= 0 - name: Security group created openstack.cloud.security_group: state: "{{ state | default('present') }}" name: "{{ algo_server_name }}-security_group" description: AlgoVPN security group register: os_security_group - name: Security rules created openstack.cloud.security_group_rule: state: "{{ state | default('present') }}" security_group: "{{ os_security_group.id }}" protocol: "{{ item.proto }}" port_range_min: "{{ item.port_min }}" port_range_max: "{{ item.port_max }}" remote_ip_prefix: "{{ item.range }}" loop: - { proto: tcp, port_min: "{{ ssh_port }}", port_max: "{{ ssh_port }}", range: 0.0.0.0/0 } - { proto: icmp, port_min: -1, port_max: -1, range: 0.0.0.0/0 } - { proto: udp, port_min: 4500, port_max: 4500, range: 0.0.0.0/0 } - { proto: udp, port_min: 500, port_max: 500, range: 0.0.0.0/0 } - { proto: udp, port_min: "{{ wireguard_port }}", port_max: "{{ wireguard_port }}", range: 0.0.0.0/0 } - name: Gather facts about flavors openstack.cloud.compute_flavor_info: ram: "{{ cloud_providers.openstack.flavor_ram }}" register: os_flavor - name: Gather facts about images openstack.cloud.image_info: register: os_image - name: Set image as a fact set_fact: image_id: "{{ item.id }}" loop: "{{ os_image.openstack_image }}" when: - item.name == cloud_providers.openstack.image - item.status == "active" - name: Gather facts about public networks openstack.cloud.networks_info: register: os_network - name: Set the network as a fact set_fact: public_network_id: "{{ item.id }}" when: - item['router:external']|default(omit) - item['admin_state_up']|default(omit) - item['status'] == 'ACTIVE' loop: "{{ os_network.openstack_networks }}" - name: Set facts set_fact: flavor_id: "{{ (os_flavor.openstack_flavors | sort(attribute='ram'))[0]['id'] }}" security_group_name: "{{ os_security_group['secgroup']['name'] }}" - name: Server created openstack.cloud.server: state: "{{ state | default('present') }}" name: "{{ algo_server_name }}" image: "{{ image_id }}" flavor: "{{ flavor_id }}" security_groups: "{{ security_group_name }}" userdata: "{{ lookup('template', 'files/cloud-init/base.yml') }}" nics: - net-id: "{{ public_network_id }}" register: os_server - set_fact: cloud_instance_ip: "{{ os_server['openstack']['public_v4'] }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-scaleway/defaults/main.yml ================================================ --- scaleway_regions: - alias: par1 - alias: ams1 ================================================ FILE: roles/cloud-scaleway/tasks/destroy.yml ================================================ --- - environment: SCW_TOKEN: "{{ algo_scaleway_token }}" block: - name: Destroy Scaleway server scaleway_compute: name: "{{ algo_server_name }}" state: absent region: "{{ algo_region }}" ================================================ FILE: roles/cloud-scaleway/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - environment: SCW_TOKEN: "{{ algo_scaleway_token }}" block: - name: Get Ubuntu 22.04 image ID from Scaleway Marketplace API uri: url: "https://api-marketplace.scaleway.com/images?arch={{ cloud_providers.scaleway.arch }}&include_eol=false" method: GET return_content: true register: marketplace_images - name: Find Ubuntu 22.04 Jammy image set_fact: scaleway_image_id: >- {{ (marketplace_images.json.images | selectattr('name', 'match', '.*Ubuntu.*22\\.04.*Jammy.*') | first).versions[0].local_images | selectattr('zone', 'equalto', algo_region) | map(attribute='id') | first }} - name: Create a server scaleway_compute: name: "{{ algo_server_name }}" enable_ipv6: true public_ip: dynamic boot_type: local state: present image: "{{ scaleway_image_id }}" project: "{{ algo_scaleway_org_id }}" region: "{{ algo_region }}" commercial_type: "{{ cloud_providers.scaleway.size }}" wait: true tags: - Environment:Algo - AUTHORIZED_KEY={{ lookup('file', SSH_keys.public) | regex_replace(' ', '_') }} register: scaleway_compute - name: Patch the cloud-init uri: url: https://cp-{{ algo_region }}.scaleway.com/servers/{{ scaleway_compute.msg.id }}/user_data/cloud-init method: PATCH body: "{{ lookup('template', 'files/cloud-init/base.yml') }}" status_code: 204 headers: Content-Type: text/plain X-Auth-Token: "{{ algo_scaleway_token }}" - name: Start the server scaleway_compute: name: "{{ algo_server_name }}" enable_ipv6: true public_ip: dynamic boot_type: local state: running image: "{{ scaleway_image_id }}" project: "{{ algo_scaleway_org_id }}" region: "{{ algo_region }}" commercial_type: "{{ cloud_providers.scaleway.size }}" wait: true tags: - Environment:Algo - AUTHORIZED_KEY={{ lookup('file', SSH_keys.public) | regex_replace(' ', '_') }} register: algo_instance until: algo_instance.msg.public_ip retries: 3 delay: 3 - set_fact: cloud_instance_ip: "{{ algo_instance.msg.public_ip.address }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-scaleway/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter your auth token (https://trailofbits.github.io/algo/cloud-scaleway.html) echo: false register: _scaleway_token when: - scaleway_token is undefined - lookup('env', 'SCW_TOKEN')|length <= 0 no_log: true - pause: prompt: | What region should the server be located in? {% for r in scaleway_regions %} {{ loop.index }}. {{ r['alias'] }} {% endfor %} Enter the number of your desired region [{{ scaleway_regions.0.alias }}] register: _algo_region when: region is undefined - pause: prompt: | Enter your Scaleway Organization ID (also serves as your default Project ID) You can find this in your Scaleway console: 1. Go to https://console.scaleway.com/organization/settings 2. Copy the Organization ID from the Organization Settings page Note: For the default project, the Project ID is the same as the Organization ID. (https://trailofbits.github.io/algo/cloud-scaleway.html) register: _scaleway_org_id when: - scaleway_org_id is undefined - lookup('env', 'SCW_DEFAULT_ORGANIZATION_ID')|length <= 0 - name: Set scaleway facts set_fact: algo_scaleway_token: "{{ scaleway_token | default(_scaleway_token.user_input) | default(lookup('env', 'SCW_TOKEN'), true) }}" algo_region: >- {% if region is defined %}{{ region }} {%- elif _algo_region.user_input %}{{ scaleway_regions[_algo_region.user_input | int - 1]['alias'] }} {%- else %}{{ scaleway_regions.0.alias }}{% endif %} algo_scaleway_org_id: "{{ scaleway_org_id | default(_scaleway_org_id.user_input) | default(lookup('env', 'SCW_DEFAULT_ORGANIZATION_ID'), true) }}" no_log: true ================================================ FILE: roles/cloud-vultr/tasks/destroy.yml ================================================ --- - environment: VULTR_API_KEY: "{{ lookup('ini', 'key', section='default', file=algo_vultr_config) }}" block: - name: Destroy Vultr instance vultr.cloud.instance: name: "{{ algo_server_name }}" region: "{{ algo_vultr_region }}" state: absent - name: Remove firewall group vultr.cloud.firewall_group: name: "{{ algo_server_name }}" state: absent failed_when: false ================================================ FILE: roles/cloud-vultr/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml - environment: VULTR_API_KEY: "{{ lookup('ini', 'key', section='default', file=algo_vultr_config) }}" block: - name: Set cloud-init script as fact set_fact: algo_cloud_init_script: "{{ lookup('template', 'files/cloud-init/base.yml') }}" - name: Creating a firewall group vultr.cloud.firewall_group: name: "{{ algo_server_name }}" - name: Creating firewall rules vultr.cloud.firewall_rule: group: "{{ algo_server_name }}" protocol: "{{ item.protocol }}" port: "{{ item.port }}" ip_type: "{{ item.ip }}" subnet: "{{ item.cidr.split('/')[0] }}" subnet_size: "{{ item.cidr.split('/')[1] }}" loop: - { protocol: tcp, port: "{{ ssh_port }}", ip: v4, cidr: 0.0.0.0/0 } - { protocol: tcp, port: "{{ ssh_port }}", ip: v6, cidr: "::/0" } - { protocol: udp, port: 500, ip: v4, cidr: 0.0.0.0/0 } - { protocol: udp, port: 500, ip: v6, cidr: "::/0" } - { protocol: udp, port: 4500, ip: v4, cidr: 0.0.0.0/0 } - { protocol: udp, port: 4500, ip: v6, cidr: "::/0" } - { protocol: udp, port: "{{ wireguard_port }}", ip: v4, cidr: 0.0.0.0/0 } - { protocol: udp, port: "{{ wireguard_port }}", ip: v6, cidr: "::/0" } - name: Upload the startup script vultr.cloud.startup_script: name: algo-startup script: "{{ algo_cloud_init_script }}" - name: Creating a server vultr.cloud.instance: name: "{{ algo_server_name }}" startup_script: algo-startup hostname: "{{ algo_server_name }}" os: "{{ cloud_providers.vultr.os }}" plan: "{{ cloud_providers.vultr.size }}" region: "{{ algo_vultr_region }}" firewall_group: "{{ algo_server_name }}" state: started tags: - Environment:Algo enable_ipv6: true backups: false activation_email: false register: vultr_server - set_fact: cloud_instance_ip: "{{ vultr_server.vultr_instance.main_ip }}" ansible_ssh_user: algo ansible_ssh_port: "{{ ssh_port }}" cloudinit: true ================================================ FILE: roles/cloud-vultr/tasks/prompts.yml ================================================ --- - pause: prompt: | Enter the local path to your configuration INI file (https://trailofbits.github.io/algo/cloud-vultr.html): register: _vultr_config when: - vultr_config is undefined - lookup('env', 'VULTR_API_CONFIG')|length <= 0 no_log: true - name: Set the token as a fact set_fact: algo_vultr_config: "{{ vultr_config | default(_vultr_config.user_input) | default(lookup('env', 'VULTR_API_CONFIG'), true) }}" no_log: true - name: Set the Vultr API Key as a fact set_fact: vultr_api_key: "{{ lookup('ansible.builtin.ini', 'key', section='default', file=algo_vultr_config) }}" - name: Get regions uri: url: https://api.vultr.com/v2/regions method: GET status_code: 200 headers: Authorization: "Bearer {{ vultr_api_key }}" register: _vultr_regions - name: Format regions set_fact: regions: "{{ _vultr_regions.json['regions'] }}" - name: Set regions as a fact set_fact: vultr_regions: "{{ regions | sort(attribute='country') }}" - name: Set default region set_fact: default_region: 1 - pause: prompt: | What region should the server be located in? (https://www.vultr.com/locations/): {% for r in vultr_regions %} {{ loop.index }}. {{ r['city'] }} ({{ r['id'] }}) {% endfor %} Enter the number of your desired region [{{ default_region }}] register: _algo_region when: region is undefined - name: Set the desired region as a fact set_fact: algo_vultr_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ vultr_regions[_algo_region.user_input | int - 1]['id'] }}{%- else -%}{{ vultr_regions[default_region | int - 1]['id'] }}{%- endif -%} algo_region: >- {%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ vultr_regions[_algo_region.user_input | int - 1]['id'] }}{%- else -%}{{ vultr_regions[default_region | int - 1]['id'] }}{%- endif -%} ================================================ FILE: roles/common/defaults/main.yml ================================================ --- install_headers: false aip_supported_providers: - digitalocean snat_aipv4: false ipv6_default: "{{ ansible_default_ipv6.address + '/' + ansible_default_ipv6.prefix }}" ipv6_subnet_size: "{{ ipv6_default | ansible.utils.ipaddr('size') }}" ipv6_egress_ip: >- {{ (ipv6_default | ansible.utils.next_nth_usable(15 | random(seed=algo_server_name + ansible_fqdn))) + '/124' if ipv6_subnet_size | int > 1 else ipv6_default }} ================================================ FILE: roles/common/handlers/main.yml ================================================ --- - name: restart rsyslog service: name=rsyslog state=restarted - name: flush routing cache shell: echo 1 > /proc/sys/net/ipv4/route/flush changed_when: false - name: restart systemd-networkd systemd: name: systemd-networkd state: restarted daemon_reload: true - name: restart systemd-resolved systemd: name: systemd-resolved state: restarted - name: restart iptables service: name=netfilter-persistent state=restarted - name: netplan apply command: netplan apply changed_when: false ================================================ FILE: roles/common/tasks/aip/digitalocean.yml ================================================ --- - name: Get the anchor IP uri: url: http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address return_content: true register: anchor_ipv4 until: anchor_ipv4 is succeeded retries: 30 delay: 10 - name: Set SNAT IP as a fact set_fact: snat_aipv4: "{{ anchor_ipv4.content }}" - name: IPv6 egress alias configured template: src: 99-algo-ipv6-egress.yaml.j2 dest: /etc/netplan/99-algo-ipv6-egress.yaml mode: '0644' when: - ipv6_support - ipv6_subnet_size|int > 1 notify: - netplan apply ================================================ FILE: roles/common/tasks/aip/main.yml ================================================ --- - name: Verify the provider assert: that: algo_provider in aip_supported_providers msg: Algo does not support Alternative Ingress IP for {{ algo_provider }} - name: Include alternative ingress ip configuration include_tasks: file: "{{ algo_provider if algo_provider in aip_supported_providers else 'placeholder' }}.yml" when: algo_provider in aip_supported_providers - name: Verify SNAT IPv4 found assert: that: snat_aipv4 | trim is ansible.utils.ipv4_address msg: The SNAT IPv4 address not found. Cannot proceed with the alternative ingress ip. ================================================ FILE: roles/common/tasks/aip/placeholder.yml ================================================ ================================================ FILE: roles/common/tasks/facts.yml ================================================ --- - name: Set OS platform facts set_fact: is_debian_based: "{{ ansible_distribution in ['Debian', 'Ubuntu'] }}" uses_systemd_socket: "{{ ansible_distribution in ['Debian', 'Ubuntu'] }}" is_ubuntu_22_plus: "{{ ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('22.04', '>=') }}" tags: always - name: Define facts set_fact: p12_export_password: "{{ p12_password | default(lookup('password', '/dev/null length=9 chars=ascii_letters,digits,_,@')) }}" tags: update-users no_log: true - name: Set facts set_fact: CA_password: "{{ ca_password | default(lookup('password', '/dev/null length=16 chars=ascii_letters,digits,_,@')) }}" IP_subject_alt_name: "{{ IP_subject_alt_name }}" no_log: true - name: Set IPv6 support as a fact set_fact: ipv6_support: "{{ ansible_default_ipv6['gateway'] is defined }}" tags: always - name: Check size of MTU set_fact: reduce_mtu: "{{ 1500 - ansible_default_ipv4['mtu'] | int if reduce_mtu | int == 0 and ansible_default_ipv4['mtu'] | int < 1500 else reduce_mtu | int }}" tags: always ================================================ FILE: roles/common/tasks/iptables.yml ================================================ --- - name: Iptables configured template: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: root group: root mode: '0640' loop: - { src: rules.v4.j2, dest: /etc/iptables/rules.v4 } notify: - restart iptables - name: Iptables configured template: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: root group: root mode: '0640' when: ipv6_support | bool loop: - { src: rules.v6.j2, dest: /etc/iptables/rules.v6 } notify: - restart iptables ================================================ FILE: roles/common/tasks/main.yml ================================================ --- - name: Check the system raw: uname -a register: OS changed_when: false tags: - update-users - fail: when: cloud_test|default(false)|bool - include_tasks: ubuntu.yml when: '"Ubuntu" in OS.stdout or "Linux" in OS.stdout' # Include facts separately - always runs to ensure OS detection facts are available - include_tasks: facts.yml tags: - always - update-users - name: Sysctl tuning sysctl: name="{{ item.item }}" value="{{ item.value }}" when: item.item is defined and item.item != none loop: "{{ sysctl | default([]) }}" tags: - always - meta: flush_handlers ================================================ FILE: roles/common/tasks/packages.yml ================================================ --- - name: Initialize package lists set_fact: algo_packages: "{{ tools | default([]) if not performance_preinstall_packages | default(false) else [] }}" algo_packages_optional: [] when: performance_parallel_packages | default(true) - name: Add StrongSwan packages set_fact: algo_packages: "{{ algo_packages + ['strongswan'] }}" when: - performance_parallel_packages | default(true) - ipsec_enabled | default(false) - name: Add WireGuard packages set_fact: algo_packages: "{{ algo_packages + ['wireguard'] }}" when: - performance_parallel_packages | default(true) - wireguard_enabled | default(true) - name: Add DNS packages set_fact: algo_packages: "{{ algo_packages + ['dnscrypt-proxy'] }}" when: - performance_parallel_packages | default(true) # dnscrypt-proxy handles both DNS ad-blocking and DNS-over-HTTPS/TLS encryption # Install if user wants either ad-blocking OR encrypted DNS (or both) - algo_dns_adblocking | default(false) or dns_encryption | default(false) - name: Add kernel headers to optional packages set_fact: algo_packages_optional: "{{ algo_packages_optional + ['linux-headers-generic', 'linux-headers-' + ansible_kernel] }}" when: - performance_parallel_packages | default(true) - install_headers | default(false) - name: Install all packages in batch (performance optimization) apt: name: "{{ algo_packages | unique }}" state: present update_cache: true install_recommends: true when: - performance_parallel_packages | default(true) - algo_packages | length > 0 - name: Install optional packages in batch apt: name: "{{ algo_packages_optional | unique }}" state: present when: - performance_parallel_packages | default(true) - algo_packages_optional | length > 0 - name: Debug - Show batched packages debug: msg: - "Batch installed {{ algo_packages | length }} main packages: {{ algo_packages | unique | join(', ') }}" - "Batch installed {{ algo_packages_optional | length }} optional packages: {{ algo_packages_optional | unique | join(', ') }}" when: - performance_parallel_packages | default(true) - (algo_packages | length > 0 or algo_packages_optional | length > 0) ================================================ FILE: roles/common/tasks/ubuntu.yml ================================================ --- - name: Gather facts setup: - name: Cloud only tasks when: algo_provider != "local" block: - name: Install software updates apt: update_cache: true install_recommends: true upgrade: dist register: result until: result is succeeded retries: 30 delay: 10 - name: Check if reboot is required shell: | set -o pipefail if [[ -e /var/run/reboot-required ]]; then # Check if kernel was updated (most critical reboot reason) if grep -q "linux-image\|linux-generic\|linux-headers" /var/log/dpkg.log.1 /var/log/dpkg.log 2>/dev/null; then echo "kernel-updated" else echo "optional" fi else echo "no" fi args: executable: /bin/bash register: reboot_required changed_when: false - name: Reboot (kernel updated or performance optimization disabled) shell: sleep 2 && shutdown -r now "Ansible updates triggered" async: 1 poll: 0 when: > reboot_required is defined and ( reboot_required.stdout == 'kernel-updated' or (reboot_required.stdout == 'optional' and not performance_skip_optional_reboots|default(false)) ) changed_when: true failed_when: false - name: Skip reboot (performance optimization enabled) debug: msg: "Skipping reboot - performance optimization enabled. No kernel updates detected." when: > reboot_required is defined and reboot_required.stdout == 'optional' and performance_skip_optional_reboots|default(false) - name: Wait until the server becomes ready... wait_for_connection: delay: 20 timeout: 320 when: > reboot_required is defined and ( reboot_required.stdout == 'kernel-updated' or (reboot_required.stdout == 'optional' and not performance_skip_optional_reboots|default(false)) ) become: false - name: Include unattended upgrades configuration import_tasks: unattended-upgrades.yml - name: Disable MOTD on login and SSHD replace: dest="{{ item.file }}" regexp="{{ item.regexp }}" replace="{{ item.line }}" become: true loop: - { regexp: ^session.*optional.*pam_motd.so.*, line: "# MOTD DISABLED", file: /etc/pam.d/login } - { regexp: ^session.*optional.*pam_motd.so.*, line: "# MOTD DISABLED", file: /etc/pam.d/sshd } - name: Ensure fallback resolvers are set ini_file: path: /etc/systemd/resolved.conf section: Resolve option: FallbackDNS value: "{{ dns_servers.ipv4 | join(' ') }}" mode: '0644' notify: - restart systemd-resolved - name: Loopback for services configured template: src: 10-algo-lo100.network.j2 dest: /etc/systemd/network/10-algo-lo100.network mode: '0644' notify: - restart systemd-networkd - name: systemd services enabled and started systemd: name: "{{ item }}" state: started enabled: true daemon_reload: true loop: - systemd-networkd - systemd-resolved - meta: flush_handlers - name: Check apparmor support command: apparmor_status failed_when: false changed_when: false register: apparmor_status - name: Set fact if apparmor enabled set_fact: apparmor_enabled: true when: '"profiles are in enforce mode" in apparmor_status.stdout' - name: Gather additional facts import_tasks: facts.yml - name: Set OS specific facts set_fact: tools: - git - screen - apparmor-utils - uuid-runtime - coreutils - iptables - iptables-persistent - cgroup-tools - openssl - gnupg2 - cron # yamllint disable-line rule:line-length sysctl: "{{ [{'item': 'net.ipv4.ip_forward', 'value': 1}, {'item': 'net.ipv4.conf.all.forwarding', 'value': 1}, {'item': 'net.ipv4.conf.all.route_localnet', 'value': 1}] + ([{'item': 'net.ipv6.conf.all.forwarding', 'value': 1}] if ipv6_support | bool else []) }}" - name: Install packages (batch optimization) include_tasks: packages.yml when: performance_parallel_packages | default(true) - name: Install tools (legacy method) apt: name: "{{ tools | default([]) }}" state: present update_cache: true when: - not performance_parallel_packages | default(true) - not performance_preinstall_packages | default(false) - name: Install headers (legacy method) apt: name: - linux-headers-generic - linux-headers-{{ ansible_kernel }} state: present when: - not performance_parallel_packages | default(true) - install_headers | bool - name: Configure the alternative ingress ip include_tasks: aip/main.yml when: alternative_ingress_ip | bool - name: Ubuntu 22.04+ | Use iptables-legacy for compatibility when: is_ubuntu_22_plus tags: iptables block: - name: Install iptables packages apt: name: - iptables - iptables-persistent state: present update_cache: true - name: Configure iptables-legacy as default alternatives: name: "{{ item }}" path: "/usr/sbin/{{ item }}-legacy" loop: - iptables - ip6tables - include_tasks: iptables.yml tags: iptables ================================================ FILE: roles/common/tasks/unattended-upgrades.yml ================================================ --- - name: Install unattended-upgrades apt: name: unattended-upgrades state: present - name: Configure unattended-upgrades template: src: 50unattended-upgrades.j2 dest: /etc/apt/apt.conf.d/50unattended-upgrades owner: root group: root mode: '0644' - name: Periodic upgrades configured template: src: 10periodic.j2 dest: /etc/apt/apt.conf.d/10periodic owner: root group: root mode: '0644' ================================================ FILE: roles/common/templates/10-algo-lo100.network.j2 ================================================ [Match] Name=lo [Network] Description=lo:100 Address={{ local_service_ip }}/32 Address={{ local_service_ipv6 }}/128 ================================================ FILE: roles/common/templates/10periodic.j2 ================================================ APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Download-Upgradeable-Packages "1"; APT::Periodic::AutocleanInterval "7"; APT::Periodic::Unattended-Upgrade "1"; ================================================ FILE: roles/common/templates/50unattended-upgrades.j2 ================================================ // Automatically upgrade packages from these (origin:archive) pairs // // Note that in Ubuntu security updates may pull in new dependencies // from non-security sources (e.g. chromium). By allowing the release // pocket these get automatically pulled in. Unattended-Upgrade::Allowed-Origins { "${distro_id}:${distro_codename}-security"; // Extended Security Maintenance; doesn't necessarily exist for // every release and this system may not have it installed, but if // available, the policy for updates is such that unattended-upgrades // should also install from here by default. "${distro_id}ESM:${distro_codename}"; "${distro_id}:${distro_codename}-updates"; // "${distro_id}:${distro_codename}-proposed"; // "${distro_id}:${distro_codename}-backports"; }; // List of packages to not update (regexp are supported) Unattended-Upgrade::Package-Blacklist { // "vim"; // "libc6"; // "libc6-dev"; // "libc6-i686"; }; // This option will controls whether the development release of Ubuntu will be // upgraded automatically. Unattended-Upgrade::DevRelease "false"; // This option allows you to control if on a unclean dpkg exit // unattended-upgrades will automatically run // dpkg --force-confold --configure -a // The default is true, to ensure updates keep getting installed Unattended-Upgrade::AutoFixInterruptedDpkg "true"; // Split the upgrade into the smallest possible chunks so that // they can be interrupted with SIGTERM. This makes the upgrade // a bit slower but it has the benefit that shutdown while a upgrade // is running is possible (with a small delay) Unattended-Upgrade::MinimalSteps "true"; // Install all unattended-upgrades when the machine is shutting down // instead of doing it in the background while the machine is running // This will (obviously) make shutdown slower //Unattended-Upgrade::InstallOnShutdown "true"; // Send email to this address for problems or packages upgrades // If empty or unset then no email is sent, make sure that you // have a working mail setup on your system. A package that provides // 'mailx' must be installed. E.g. "user@example.com" //Unattended-Upgrade::Mail "root"; // Set this value to "true" to get emails only on errors. Default // is to always send a mail if Unattended-Upgrade::Mail is set //Unattended-Upgrade::MailOnlyOnError "true"; // Remove unused automatically installed kernel-related packages // (kernel images, kernel headers and kernel version locked tools). Unattended-Upgrade::Remove-Unused-Kernel-Packages "true"; // Do automatic removal of new unused dependencies after the upgrade // (equivalent to apt-get autoremove) Unattended-Upgrade::Remove-Unused-Dependencies "true"; // Automatically reboot *WITHOUT CONFIRMATION* // if the file /var/run/reboot-required is found after the upgrade Unattended-Upgrade::Automatic-Reboot "{{ unattended_reboot.enabled | lower }}"; // If automatic reboot is enabled and needed, reboot at the specific // time instead of immediately // Default: "now" Unattended-Upgrade::Automatic-Reboot-Time "{{ unattended_reboot.time }}"; // Use apt bandwidth limit feature, this example limits the download // speed to 70kb/sec //Acquire::http::Dl-Limit "70"; // Enable logging to syslog. Default is False Unattended-Upgrade::SyslogEnable "true"; // Specify syslog facility. Default is daemon // Unattended-Upgrade::SyslogFacility "daemon"; // Download and install upgrades only on AC power // (i.e. skip or gracefully stop updates on battery) // Unattended-Upgrade::OnlyOnACPower "true"; // Download and install upgrades only on non-metered connection // (i.e. skip or gracefully stop updates on a metered connection) // Unattended-Upgrade::Skip-Updates-On-Metered-Connections "true"; // Keep the custom conffile when upgrading Dpkg::Options { "--force-confdef"; "--force-confold"; }; ================================================ FILE: roles/common/templates/99-algo-ipv6-egress.yaml.j2 ================================================ network: version: 2 ethernets: {{ ansible_default_ipv6.interface }}: addresses: - {{ ipv6_egress_ip }} ================================================ FILE: roles/common/templates/rules.v4.j2 ================================================ {% set subnets = ([strongswan_network] if ipsec_enabled | bool else []) + ([wireguard_network_ipv4] if wireguard_enabled | bool else []) %} {% set ports = (['500', '4500'] if ipsec_enabled | bool else []) + ([wireguard_port] if wireguard_enabled | bool else []) + ([wireguard_port_actual] if wireguard_enabled | bool and wireguard_port | int == wireguard_port_avoid | int else []) %} #### The mangle table # This table allows us to modify packet headers # Packets enter this table first # *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% if reduce_mtu | int > 0 and ipsec_enabled | bool %} -A FORWARD -s {{ strongswan_network }} -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss {{ 1360 - reduce_mtu | int }} {% endif %} COMMIT #### The nat table # This table enables Network Address Translation # (This is technically a type of packet mangling) # *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% if wireguard_enabled | bool and wireguard_port | int == wireguard_port_avoid | int %} # Handle the special case of allowing access to WireGuard over an already used # port like 53 -A PREROUTING -s {{ subnets | join(',') }} -p udp --dport {{ wireguard_port_avoid }} -j RETURN -A PREROUTING --in-interface {{ ansible_default_ipv4['interface'] }} -p udp --dport {{ wireguard_port_avoid }} -j REDIRECT --to-port {{ wireguard_port_actual }} {% endif %} # Allow traffic from the VPN network to the outside world, and replies {% if ipsec_enabled | bool %} # For IPsec traffic - NAT the decrypted packets from the VPN subnet -A POSTROUTING -s {{ strongswan_network }} -o {{ ansible_default_ipv4['interface'] }} {{ '-j SNAT --to ' + snat_aipv4 if snat_aipv4 | bool else '-j MASQUERADE' }} {% endif %} {% if wireguard_enabled | bool %} # For WireGuard traffic - NAT packets from the VPN subnet -A POSTROUTING -s {{ wireguard_network_ipv4 }} -o {{ ansible_default_ipv4['interface'] }} {{ '-j SNAT --to ' + snat_aipv4 if snat_aipv4 | bool else '-j MASQUERADE' }} {% endif %} COMMIT #### The filter table # The default ipfilter table # *filter # By default, drop packets that are destined for this server :INPUT DROP [0:0] # By default, drop packets that request to be forwarded by this server :FORWARD DROP [0:0] # By default, accept any packets originating from this server :OUTPUT ACCEPT [0:0] # Accept packets destined for localhost -A INPUT -i lo -j ACCEPT # Accept any packet from an open TCP connection -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Accept packets using the encapsulation protocol -A INPUT -p esp -j ACCEPT -A INPUT -p ah -j ACCEPT # rate limit ICMP traffic per source -A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit-upto 5/s --hashlimit-mode srcip --hashlimit-srcmask 32 --hashlimit-name icmp-echo-drop -j ACCEPT # Accept IPSEC/WireGuard traffic to ports {{ subnets | join(',') }} -A INPUT -p udp -m multiport --dports {{ ports | join(',') }} -j ACCEPT # Allow new traffic to port {{ ansible_ssh_port }} (SSH) -A INPUT -p tcp --dport {{ ansible_ssh_port }} -m conntrack --ctstate NEW -j ACCEPT {% if ipsec_enabled | bool %} # Allow any traffic from the IPsec VPN -A INPUT -p ipencap -m policy --dir in --pol ipsec --proto esp -j ACCEPT {% endif %} # TODO: # The IP of the resolver should be bound to a DUMMY interface. # DUMMY interfaces are the proper way to install IPs without assigning them any # particular virtual (tun,tap,...) or physical (ethernet) interface. # Accept DNS traffic to the local DNS resolver from VPN clients only -A INPUT -s {{ subnets | join(',') }} -d {{ local_service_ip }} -p udp --dport 53 -j ACCEPT # Drop traffic between VPN clients -A FORWARD -s {{ subnets | join(',') }} -d {{ subnets | join(',') }} -j {{ "DROP" if BetweenClients_DROP else "ACCEPT" }} # Drop traffic to VPN clients from SSH tunnels -A OUTPUT -d {{ subnets | join(',') }} -m owner --gid-owner 15000 -j {{ "DROP" if BetweenClients_DROP else "ACCEPT" }} # Drop traffic to the link-local network -A FORWARD -s {{ subnets | join(',') }} -d 169.254.0.0/16 -j DROP # Drop traffic to the link-local network from SSH tunnels -A OUTPUT -d 169.254.0.0/16 -m owner --gid-owner 15000 -j DROP # Forward any packet that's part of an established connection -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Drop SMB/CIFS traffic that requests to be forwarded -A FORWARD -p tcp --dport 445 -j {{ "DROP" if block_smb else "ACCEPT" }} # Drop NETBIOS traffic that requests to be forwarded -A FORWARD -p udp -m multiport --ports 137,138 -j {{ "DROP" if block_netbios else "ACCEPT" }} -A FORWARD -p tcp -m multiport --ports 137,139 -j {{ "DROP" if block_netbios else "ACCEPT" }} {% if ipsec_enabled | bool %} # Forward any IPSEC traffic from the VPN network -A FORWARD -m conntrack --ctstate NEW -s {{ strongswan_network }} -m policy --pol ipsec --dir in -j ACCEPT {% endif %} {% if wireguard_enabled | bool %} # Forward any traffic from the WireGuard VPN network -A FORWARD -m conntrack --ctstate NEW -s {{ wireguard_network_ipv4 }} -j ACCEPT {% endif %} COMMIT ================================================ FILE: roles/common/templates/rules.v6.j2 ================================================ {% set subnets = ([strongswan_network_ipv6] if ipsec_enabled | bool else []) + ([wireguard_network_ipv6] if wireguard_enabled | bool else []) %} {% set ports = (['500', '4500'] if ipsec_enabled | bool else []) + ([wireguard_port] if wireguard_enabled | bool else []) + ([wireguard_port_actual] if wireguard_enabled | bool and wireguard_port | int == wireguard_port_avoid | int else []) %} #### The mangle table # This table allows us to modify packet headers # Packets enter this table first # *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% if reduce_mtu | int > 0 and ipsec_enabled | bool %} -A FORWARD -s {{ strongswan_network_ipv6 }} -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss {{ 1340 - reduce_mtu | int }} {% endif %} COMMIT #### The nat table # This table enables Network Address Translation # (This is technically a type of packet mangling) # *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] {% if wireguard_enabled | bool and wireguard_port | int == wireguard_port_avoid | int %} # Handle the special case of allowing access to WireGuard over an already used # port like 53 -A PREROUTING -s {{ subnets | join(',') }} -p udp --dport {{ wireguard_port_avoid }} -j RETURN -A PREROUTING --in-interface {{ ansible_default_ipv6['interface'] }} -p udp --dport {{ wireguard_port_avoid }} -j REDIRECT --to-port {{ wireguard_port_actual }} {% endif %} # Allow traffic from the VPN network to the outside world, and replies {% if ipsec_enabled | bool %} # For IPsec traffic - NAT the decrypted packets from the VPN subnet -A POSTROUTING -s {{ strongswan_network_ipv6 }} -o {{ ansible_default_ipv6['interface'] }} {{ '-j SNAT --to ' + ipv6_egress_ip | ansible.utils.ipaddr('address') if alternative_ingress_ip | bool else '-j MASQUERADE' }} {% endif %} {% if wireguard_enabled | bool %} # For WireGuard traffic - NAT packets from the VPN subnet -A POSTROUTING -s {{ wireguard_network_ipv6 }} -o {{ ansible_default_ipv6['interface'] }} {{ '-j SNAT --to ' + ipv6_egress_ip | ansible.utils.ipaddr('address') if alternative_ingress_ip | bool else '-j MASQUERADE' }} {% endif %} COMMIT #### The filter table # The default ipfilter table # *filter # By default, drop packets that are destined for this server :INPUT DROP [0:0] # By default, drop packets that request to be forwarded by this server :FORWARD DROP [0:0] # By default, accept any packets originating from this server :OUTPUT ACCEPT [0:0] # Create the ICMPV6-CHECK chain and its log chain # These chains are used later to prevent a type of bug that would # allow malicious traffic to reach over the server into the private network # An instance of such a bug on Cisco software is described here: # https://www.insinuator.net/2016/05/cve-2016-1409-ipv6-ndp-dos-vulnerability-in-cisco-software/ # other software implementations might be at least as broken as the one in CISCO gear. :ICMPV6-CHECK - [0:0] :ICMPV6-CHECK-LOG - [0:0] # Accept packets destined for localhost -A INPUT -i lo -j ACCEPT # Accept any packet from an open TCP connection -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Accept packets using the encapsulation protocol -A INPUT -p esp -j ACCEPT -A INPUT -m ah -j ACCEPT # rate limit ICMP traffic per source -A INPUT -p icmpv6 --icmpv6-type echo-request -m hashlimit --hashlimit-upto 5/s --hashlimit-mode srcip --hashlimit-srcmask 32 --hashlimit-name icmp-echo-drop -j ACCEPT # Accept IPSEC/WireGuard traffic to ports {{ subnets | join(',') }} -A INPUT -p udp -m multiport --dports {{ ports | join(',') }} -j ACCEPT # Allow new traffic to port {{ ansible_ssh_port }} (SSH) -A INPUT -p tcp --dport {{ ansible_ssh_port }} -m conntrack --ctstate NEW -j ACCEPT # Accept properly formatted Neighbor Discovery Protocol packets -A INPUT -p icmpv6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT -A INPUT -p icmpv6 --icmpv6-type neighbor-solicitation -m hl --hl-eq 255 -j ACCEPT -A INPUT -p icmpv6 --icmpv6-type neighbor-advertisement -m hl --hl-eq 255 -j ACCEPT -A INPUT -p icmpv6 --icmpv6-type redirect -m hl --hl-eq 255 -j ACCEPT # DHCP in AWS -A INPUT -m conntrack --ctstate NEW -m udp -p udp --dport 546 -d fe80::/64 -j ACCEPT # TODO: # The IP of the resolver should be bound to a DUMMY interface. # DUMMY interfaces are the proper way to install IPs without assigning them any # particular virtual (tun,tap,...) or physical (ethernet) interface. # Accept DNS traffic to the local DNS resolver from VPN clients only -A INPUT -s {{ subnets | join(',') }} -d {{ local_service_ipv6 }}/128 -p udp --dport 53 -j ACCEPT # Drop traffic between VPN clients -A FORWARD -s {{ subnets | join(',') }} -d {{ subnets | join(',') }} -j {{ "DROP" if BetweenClients_DROP else "ACCEPT" }} # Drop traffic to VPN clients from SSH tunnels -A OUTPUT -d {{ subnets | join(',') }} -m owner --gid-owner 15000 -j {{ "DROP" if BetweenClients_DROP else "ACCEPT" }} -A FORWARD -j ICMPV6-CHECK -A FORWARD -p tcp --dport 445 -j {{ "DROP" if block_smb else "ACCEPT" }} -A FORWARD -p udp -m multiport --ports 137,138 -j {{ "DROP" if block_netbios else "ACCEPT" }} -A FORWARD -p tcp -m multiport --ports 137,139 -j {{ "DROP" if block_netbios else "ACCEPT" }} -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT {% if ipsec_enabled | bool %} -A FORWARD -m conntrack --ctstate NEW -s {{ strongswan_network_ipv6 }} -m policy --pol ipsec --dir in -j ACCEPT {% endif %} {% if wireguard_enabled | bool %} -A FORWARD -m conntrack --ctstate NEW -s {{ wireguard_network_ipv6 }} -j ACCEPT {% endif %} # Use the ICMPV6-CHECK chain, described above -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type router-solicitation -j ICMPV6-CHECK-LOG -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type router-advertisement -j ICMPV6-CHECK-LOG -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type neighbor-solicitation -j ICMPV6-CHECK-LOG -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type neighbor-advertisement -j ICMPV6-CHECK-LOG -A ICMPV6-CHECK-LOG -j LOG --log-prefix "ICMPV6-CHECK-LOG DROP " -A ICMPV6-CHECK-LOG -j DROP COMMIT ================================================ FILE: roles/dns/defaults/main.yml ================================================ --- algo_dns_adblocking: false apparmor_enabled: true dns_encryption: true ipv6_support: false dnscrypt_servers: ipv4: - cloudflare ipv6: - cloudflare-ipv6 ================================================ FILE: roles/dns/files/50-dnscrypt-proxy-unattended-upgrades ================================================ // Automatically upgrade packages from these (origin:archive) pairs Unattended-Upgrade::Allowed-Origins { "LP-PPA-shevchuk-dnscrypt-proxy:${distro_codename}"; }; ================================================ FILE: roles/dns/files/apparmor.profile.dnscrypt-proxy ================================================ #include /usr/{s,}bin/dnscrypt-proxy flags=(attach_disconnected) { #include #include #include capability chown, capability dac_override, capability net_bind_service, capability setgid, capability setuid, capability sys_resource, /etc/dnscrypt-proxy/** r, /usr/bin/dnscrypt-proxy mr, /var/cache/{private/,}dnscrypt-proxy/** rw, /tmp/*.tmp w, owner /tmp/*.tmp r, /run/systemd/notify rw, /lib/x86_64-linux-gnu/ld-*.so mr, @{PROC}/sys/kernel/hostname r, @{PROC}/sys/net/core/somaxconn r, /etc/ld.so.cache r, /usr/local/lib/{@{multiarch}/,}libldns.so* mr, /usr/local/lib/{@{multiarch}/,}libsodium.so* mr, } ================================================ FILE: roles/dns/handlers/main.yml ================================================ --- - name: daemon-reload systemd: daemon_reload: true - name: restart dnscrypt-proxy.socket systemd: name: dnscrypt-proxy.socket state: restarted daemon_reload: true when: uses_systemd_socket | bool - name: restart dnscrypt-proxy systemd: name: dnscrypt-proxy state: restarted daemon_reload: true when: uses_systemd_socket | bool ================================================ FILE: roles/dns/tasks/dns_adblocking.yml ================================================ --- - name: Adblock script created template: src: adblock.sh.j2 dest: /usr/local/sbin/adblock.sh owner: root group: "{{ root_group | default('root') }}" mode: '0755' - name: Adblock script added to cron cron: name: Adblock hosts update minute: "{{ range(0, 60) | random }}" hour: "{{ range(0, 24) | random }}" job: /usr/local/sbin/adblock.sh user: root - name: Update adblock hosts command: /usr/local/sbin/adblock.sh changed_when: false ================================================ FILE: roles/dns/tasks/main.yml ================================================ --- - name: Include tasks for Debian/Ubuntu include_tasks: ubuntu.yml when: is_debian_based | bool - name: dnscrypt-proxy ip-blacklist configured template: src: ip-blacklist.txt.j2 dest: "{{ config_prefix | default('/') }}etc/dnscrypt-proxy/ip-blacklist.txt" mode: '0644' notify: - restart dnscrypt-proxy - name: dnscrypt-proxy configured template: src: dnscrypt-proxy.toml.j2 dest: "{{ config_prefix | default('/') }}etc/dnscrypt-proxy/dnscrypt-proxy.toml" mode: '0644' notify: - restart dnscrypt-proxy - name: Include DNS adblocking tasks import_tasks: dns_adblocking.yml when: algo_dns_adblocking | bool - meta: flush_handlers - name: Ensure dnscrypt-proxy socket is enabled and started systemd: name: dnscrypt-proxy.socket enabled: true state: started daemon_reload: true when: uses_systemd_socket | bool - name: dnscrypt-proxy enabled and started service: name: dnscrypt-proxy state: started enabled: true ================================================ FILE: roles/dns/tasks/ubuntu.yml ================================================ --- - 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 ================================================ FILE: roles/dns/templates/adblock.sh.j2 ================================================ #!/bin/sh # Block ads, malware, etc.. TEMP="$(mktemp)" TEMP_SORTED="$(mktemp)" WHITELIST="/etc/dnscrypt-proxy/white.list" BLACKLIST="/etc/dnscrypt-proxy/black.list" BLOCKHOSTS="{{ config_prefix | default('/') }}etc/dnscrypt-proxy/blacklist.txt" BLOCKLIST_URLS="{% for url in adblock_lists %}{{ url }} {% endfor %}" #Delete the old block.hosts to make room for the updates rm -f $BLOCKHOSTS echo 'Downloading hosts lists...' #Download and process the files needed to make the lists (enable/add more, if you want) for url in $BLOCKLIST_URLS; do wget --timeout=2 --tries=3 -qO- "$url" | grep -Ev "(localhost)" | grep -Ev "#" | sed -E "s/(0.0.0.0 |127.0.0.1 |255.255.255.255 )//" >> "$TEMP" done #Add black list, if non-empty if [ -s "$BLACKLIST" ] then echo 'Adding blacklist...' cat $BLACKLIST >> "$TEMP" fi #Sort the download/black lists awk '/^[^#]/ { print $1 }' "$TEMP" | sort -u > "$TEMP_SORTED" #Filter (if applicable) if [ -s "$WHITELIST" ] then #Filter the blacklist, suppressing whitelist matches # This is relatively slow =-( echo 'Filtering white list...' grep -v -E "^[[:space:]]*$" $WHITELIST | awk '/^[^#]/ {sub(/\r$/,"");print $1}' | grep -vf - "$TEMP_SORTED" > $BLOCKHOSTS else cat "$TEMP_SORTED" > $BLOCKHOSTS fi echo 'Restarting dns service...' #Restart the dns service systemctl restart dnscrypt-proxy.service exit 0 ================================================ FILE: roles/dns/templates/dnscrypt-proxy/cache.toml.j2 ================================================ ########################### # DNS cache # ########################### ## Enable a DNS cache to reduce latency and outgoing traffic cache = true ## Cache size cache_size = 4096 ## Minimum TTL for cached entries cache_min_ttl = 2400 ## Maximum TTL for cached entries cache_max_ttl = 86400 ## Minimum TTL for negatively cached entries cache_neg_min_ttl = 60 ## Maximum TTL for negatively cached entries cache_neg_max_ttl = 600 ================================================ FILE: roles/dns/templates/dnscrypt-proxy/filters.toml.j2 ================================================ ######################### # Filters # ######################### ## Immediately respond to IPv6-related queries with an empty response block_ipv6 = false ############################### # Query logging # ############################### ## Log client queries to a file ## Privacy warning: Only enable for debugging purposes [query_log] format = 'tsv' ############################################ # Suspicious queries logging # ############################################ ## Log queries for nonexistent zones [nx_log] format = 'tsv' ###################################################### # Pattern-based blocking (blacklists) # ###################################################### [blacklist] {{ "blacklist_file = 'blacklist.txt'" if algo_dns_adblocking | bool else "" }} ########################################################### # Pattern-based IP blocking (IP blacklists) # ########################################################### [ip_blacklist] blacklist_file = 'ip-blacklist.txt' ###################################################### # Pattern-based whitelisting (blacklists bypass) # ###################################################### [whitelist] # whitelist_file = 'whitelist.txt' ########################################## # Time access restrictions # ########################################## [schedules] # Time-based access rules can be defined here ================================================ FILE: roles/dns/templates/dnscrypt-proxy/global.toml.j2 ================================================ ################################## # Global settings # ################################## ## List of servers to use {# Allow either list to be empty. Output nothing if both are empty. #} {% set servers = [] %} {% if dnscrypt_servers.ipv4 %}{% set servers = dnscrypt_servers.ipv4 %}{% endif %} {% if ipv6_support | bool and dnscrypt_servers.ipv6 %}{% set servers = servers + dnscrypt_servers.ipv6 %}{% endif %} {% if servers %}server_names = ['{{ servers | join("', '") }}']{% endif %} ## List of local addresses and ports to listen to. Can be IPv4 and/or IPv6. ## Note: When using systemd socket activation, choose an empty set (i.e. [] ). {% if uses_systemd_socket | bool %} # Using systemd socket activation on Debian/Ubuntu listen_addresses = [] {% else %} # Direct binding on non-systemd systems listen_addresses = [ '{{ local_service_ip }}:53'{% if ipv6_support | bool %}, '[{{ local_service_ipv6 }}]:53'{% endif %} ] {% endif %} ## Maximum number of simultaneous client connections to accept max_clients = 250 ## Require servers (from static + remote sources) to satisfy specific properties ipv4_servers = true ipv6_servers = {{ ipv6_support | bool | lower }} dnscrypt_servers = true doh_servers = true ## Require servers defined by remote sources to satisfy specific properties require_dnssec = true require_nolog = true require_nofilter = true disabled_server_names = [] ## Always use TCP to connect to upstream servers force_tcp = false ## How long a DNS query will wait for a response, in milliseconds timeout = 2500 ## Keepalive for HTTP (HTTPS, HTTP/2) queries, in seconds keepalive = 30 ## Load-balancing strategy: 'p2' (default), 'ph', 'first' or 'random' lb_strategy = 'p2' ## Log level (0-6, default: 2 - 0 is very verbose, 6 only contains fatal errors) ## Level 4 provides essential error information while minimizing privacy-sensitive logging log_level = 4 ## Use the system logger (disabled for privacy) use_syslog = false ## Delay, in minutes, after which certificates are reloaded cert_refresh_delay = 240 ## DNSCrypt: Create a new, unique key for every single DNS query dnscrypt_ephemeral_keys = true ## DoH: Disable TLS session tickets - increases privacy but also latency tls_disable_session_tickets = true ## Fallback resolver (used only for initial resolver list retrieval) fallback_resolver = '127.0.0.53:53' ## Never let dnscrypt-proxy try to use the system DNS settings ignore_system_dns = true ## Maximum time (in seconds) to wait for network connectivity netprobe_timeout = 60 netprobe_address = "1.1.1.1:53" ## Automatic log files rotation log_files_max_size = 10 log_files_max_age = 7 log_files_max_backups = 1 ================================================ FILE: roles/dns/templates/dnscrypt-proxy/sources.toml.j2 ================================================ ######################### # Servers # ######################### ## Remote lists of available servers [sources] ## Public resolvers from https://github.com/DNSCrypt/dnscrypt-resolvers [sources.'public-resolvers'] urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/public-resolvers.md', 'https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md'] cache_file = '/var/cache/dnscrypt-proxy/public-resolvers.md' minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3' prefix = '' ## Optional, local, static list of additional servers [static] {% if custom_server_stamps %}{% for name, stamp in custom_server_stamps.items() %} [static.'{{ name }}'] stamp = '{{ stamp }}' {%- endfor %}{% endif %} ================================================ FILE: roles/dns/templates/dnscrypt-proxy.toml.j2 ================================================ ############################################## # # # dnscrypt-proxy configuration # # # ############################################## ## Online documentation: https://dnscrypt.info/doc {% include 'dnscrypt-proxy/global.toml.j2' %} {% include 'dnscrypt-proxy/cache.toml.j2' %} {% include 'dnscrypt-proxy/filters.toml.j2' %} {% include 'dnscrypt-proxy/sources.toml.j2' %} ================================================ FILE: roles/dns/templates/ip-blacklist.txt.j2 ================================================ 0.0.0.0 10.* 127.* 169.254.* 172.16.* 172.17.* 172.18.* 172.19.* 172.20.* 172.21.* 172.22.* 172.23.* 172.24.* 172.25.* 172.26.* 172.27.* 172.28.* 172.29.* 172.30.* 172.31.* 192.168.* ::ffff:0.0.0.0 ::ffff:10.* ::ffff:127.* ::ffff:169.254.* ::ffff:172.16.* ::ffff:172.17.* ::ffff:172.18.* ::ffff:172.19.* ::ffff:172.20.* ::ffff:172.21.* ::ffff:172.22.* ::ffff:172.23.* ::ffff:172.24.* ::ffff:172.25.* ::ffff:172.26.* ::ffff:172.27.* ::ffff:172.28.* ::ffff:172.29.* ::ffff:172.30.* ::ffff:172.31.* ::ffff:192.168.* fd00::* fe80::* ================================================ FILE: roles/local/tasks/main.yml ================================================ --- - name: Include prompts import_tasks: prompts.yml ================================================ FILE: roles/local/tasks/prompts.yml ================================================ --- - name: Display local installation warning pause: prompt: | ====================================================================== *** DESTRUCTIVE OPERATION *** ====================================================================== Algo is designed for DEDICATED VPN servers only. This installation will: - Replace all firewall rules (blocks most incoming traffic) - Modify system network and DNS settings - Install and configure VPN services THERE IS NO UNINSTALL OPTION. If this server runs other services (web, database, mail, etc.), they will likely become inaccessible. Recommended: Take a snapshot/backup before proceeding. Documentation: https://trailofbits.github.io/algo/deploy-to-ubuntu.html ====================================================================== Type 'yes' to confirm you understand the risks and want to proceed: register: _local_warning_confirm when: - not tests | default(false) | bool - not local_install_confirmed | default(false) | bool - name: Abort if not confirmed fail: msg: "Installation aborted by user. Your server was not modified." when: - not tests | default(false) | bool - not local_install_confirmed | default(false) | bool - _local_warning_confirm.user_input | default('') | lower != 'yes' - pause: prompt: | Enter the IP address of your server: (or use localhost for local installation): [localhost] register: _algo_server when: server is undefined - name: Set the facts set_fact: cloud_instance_ip: >- {%- if server is defined -%}{{ server }}{%- elif _algo_server.user_input -%}{{ _algo_server.user_input }}{%- else -%}localhost{%- endif -%} - when: cloud_instance_ip != "localhost" block: - pause: prompt: | What user should we use to login on the server? (note: passwordless login required, or ignore if you're deploying to localhost) [root] register: _algo_ssh_user when: ssh_user is undefined - name: Set the facts set_fact: ansible_ssh_user: >- {%- if ssh_user is defined -%}{{ ssh_user }}{%- elif _algo_ssh_user.user_input -%}{{ _algo_ssh_user.user_input }}{%- else -%}root{%- endif -%} - pause: prompt: | Enter the public IP address or domain name of your server: (IMPORTANT! This is used to verify the certificate) [{{ cloud_instance_ip }}] register: _endpoint when: endpoint is undefined - name: Set the facts set_fact: IP_subject_alt_name: >- {%- if endpoint is defined -%}{{ endpoint }}{%- elif _endpoint.user_input -%}{{ _endpoint.user_input }}{%- else -%}{{ cloud_instance_ip }}{%- endif -%} ================================================ FILE: roles/privacy/README.md ================================================ # Privacy Enhancements Role This Ansible role implements additional privacy enhancements for Algo VPN to minimize server-side traces of VPN usage and reduce log retention. These measures help protect user privacy while maintaining system security. ## Features ### 1. Aggressive Log Rotation - Configures shorter log retention periods (default: 7 days) - Implements more frequent log rotation - Compresses rotated logs to save space - Automatically cleans up old log files ### 2. History Clearing - Clears bash/shell history after deployment - Disables persistent command history for system users - Clears temporary files and caches - Sets up automatic history clearing on user logout ### 3. VPN Log Filtering - Filters out VPN connection logs from rsyslog - Excludes WireGuard and StrongSwan messages from persistent storage - Filters kernel messages related to VPN traffic - Optional filtering of authentication logs (use with caution) ### 4. Automatic Cleanup - Daily/weekly/monthly cleanup of old logs and temporary files - Package cache cleaning - Configurable retention policies - Optional shutdown cleanup for extreme privacy ### 5. Advanced Privacy Settings - Reduced kernel log verbosity - Disabled successful SSH connection logging (optional) - Volatile systemd journal storage - Privacy monitoring script ## Configuration All privacy settings are configured in `config.cfg` under the "Privacy Enhancements" section: ```yaml # Enable/disable all privacy enhancements privacy_enhancements_enabled: true # Log rotation settings privacy_log_rotation: max_age: 7 # Days to keep logs max_size: 10 # Max size per log file (MB) rotate_count: 3 # Number of rotated files to keep compress: true # Compress rotated logs daily_rotation: true # Force daily rotation # History clearing privacy_history_clearing: clear_bash_history: true clear_system_history: true disable_service_history: true # Log filtering privacy_log_filtering: exclude_vpn_logs: true exclude_auth_logs: false # Use with caution filter_kernel_vpn_logs: true # Automatic cleanup privacy_auto_cleanup: enabled: true frequency: "daily" # daily, weekly, monthly temp_files_max_age: 1 clean_package_cache: true # Advanced settings privacy_advanced: disable_ssh_success_logs: false reduce_kernel_verbosity: true clear_logs_on_shutdown: false # Extreme measure ``` ## Security Considerations ### Safe Settings (Default) - `exclude_vpn_logs: true` - Safe, only filters VPN-specific messages - `clear_bash_history: true` - Safe, improves privacy without affecting security - `reduce_kernel_verbosity: true` - Safe, reduces noise in logs ### Use With Caution - `exclude_auth_logs: true` - Reduces security logging, makes incident investigation harder - `disable_ssh_success_logs: true` - Removes audit trail for successful connections - `clear_logs_on_shutdown: true` - Extreme measure, makes debugging very difficult ## Files Created ### Configuration Files - `/etc/logrotate.d/99-privacy-enhanced` - Main log rotation config - `/etc/logrotate.d/99-auth-privacy` - Auth log rotation - `/etc/logrotate.d/99-kern-privacy` - Kernel log rotation - `/etc/rsyslog.d/49-privacy-vpn-filter.conf` - VPN log filtering - `/etc/rsyslog.d/48-privacy-kernel-filter.conf` - Kernel log filtering - `/etc/rsyslog.d/47-privacy-auth-filter.conf` - Auth log filtering (optional) - `/etc/rsyslog.d/46-privacy-ssh-filter.conf` - SSH log filtering (optional) - `/etc/rsyslog.d/45-privacy-minimal.conf` - Minimal logging config ### Scripts - `/usr/local/bin/privacy-auto-cleanup.sh` - Automatic cleanup script - `/usr/local/bin/privacy-log-cleanup.sh` - Initial log cleanup - `/usr/local/bin/privacy-monitor.sh` - Privacy status monitoring - `/etc/bash.bash_logout` - History clearing on logout ### Systemd Services - `/etc/systemd/system/privacy-shutdown-cleanup.service` - Shutdown cleanup (optional) ## Usage ### Enable Privacy Enhancements Privacy enhancements are enabled by default. To disable them: ```yaml privacy_enhancements_enabled: false ``` ### Run Specific Privacy Tasks You can run specific privacy components using tags: ```bash # Run only log rotation setup ansible-playbook server.yml --tags privacy-logs # Run only history clearing ansible-playbook server.yml --tags privacy-history # Run only log filtering ansible-playbook server.yml --tags privacy-filtering # Run only cleanup tasks ansible-playbook server.yml --tags privacy-cleanup # Run all privacy enhancements ansible-playbook server.yml --tags privacy ``` ### Monitor Privacy Status Check the status of privacy enhancements: ```bash sudo /usr/local/bin/privacy-monitor.sh ``` ### Manual Cleanup Run manual cleanup: ```bash sudo /usr/local/bin/privacy-auto-cleanup.sh ``` ## Debugging If you need to debug VPN issues, temporarily disable privacy enhancements: 1. Set `privacy_enhancements_enabled: false` in `config.cfg` 2. Re-run the deployment: `./algo` 3. Debug your issues with full logging 4. Re-enable privacy enhancements when done Alternatively, disable specific features: - Set `exclude_vpn_logs: false` to see VPN connection logs - Set `reduce_kernel_verbosity: false` for full kernel logging - Check `/var/log/privacy-cleanup.log` for cleanup operation logs ## Impact on System ### Positive Effects - Improved user privacy - Reduced disk usage from logs - Faster log searches - Reduced attack surface ### Potential Drawbacks - Limited debugging information - Shorter audit trail - May complicate troubleshooting - Could hide security incidents ## Compatibility - **Ubuntu 22.04**: Fully supported - **Other distributions**: May require adaptation ## Best Practices 1. **Start Conservative**: Use default settings initially 2. **Test Thoroughly**: Verify VPN functionality after enabling privacy features 3. **Monitor Logs**: Check that essential security logs are still being captured 4. **Document Changes**: Keep track of privacy settings for troubleshooting 5. **Regular Reviews**: Periodically review privacy settings and their effectiveness ## Privacy vs. Security Balance This role aims to balance privacy with security by: - Keeping security-critical logs (authentication failures, system errors) - Filtering only VPN-specific operational logs - Providing granular control over what gets filtered - Maintaining essential audit trails while reducing VPN usage traces For maximum privacy, consider running your own log analysis before enabling aggressive filtering options. ================================================ FILE: roles/privacy/defaults/main.yml ================================================ --- # Privacy enhancement configuration defaults # These settings can be overridden in config.cfg # Enable privacy enhancements (disabled for debugging when false) privacy_enhancements_enabled: true # Log rotation settings privacy_log_rotation: # Maximum age for system logs in days max_age: 7 # Maximum size for individual log files in MB max_size: 10 # Number of rotated files to keep rotate_count: 3 # Compress rotated logs compress: true # Force daily rotation regardless of size daily_rotation: true # History clearing settings privacy_history_clearing: # Clear bash history after deployment clear_bash_history: true # Clear system command history clear_system_history: true # Disable bash history persistence for service users disable_service_history: true # Log filtering settings privacy_log_filtering: # Exclude VPN connection logs from persistent storage exclude_vpn_logs: true # Exclude authentication logs (be careful with this) exclude_auth_logs: false # Filter kernel logs related to VPN traffic filter_kernel_vpn_logs: true # Automatic cleanup settings privacy_auto_cleanup: # Enable automatic log cleanup enabled: true # Cleanup frequency (daily, weekly, monthly) frequency: "daily" # Clean up temporary files older than N days temp_files_max_age: 1 # Clean up old package cache clean_package_cache: true # Advanced privacy settings privacy_advanced: # Disable logging of successful SSH connections disable_ssh_success_logs: false # Reduce kernel log verbosity reduce_kernel_verbosity: true # Clear logs on shutdown (use with caution) clear_logs_on_shutdown: false ================================================ FILE: roles/privacy/handlers/main.yml ================================================ --- # Privacy role handlers # These handlers are triggered by privacy configuration changes - name: restart rsyslog systemd: name: rsyslog state: restarted daemon_reload: yes become: yes - name: restart systemd-journald systemd: name: systemd-journald state: restarted daemon_reload: yes become: yes - name: reload systemd systemd: daemon_reload: yes become: yes - name: enable privacy shutdown cleanup systemd: name: privacy-shutdown-cleanup.service enabled: yes daemon_reload: yes become: yes ================================================ FILE: roles/privacy/tasks/advanced_privacy.yml ================================================ --- # Advanced privacy settings for enhanced anonymity - name: Reduce kernel log verbosity for privacy sysctl: name: "{{ item.name }}" value: "{{ item.value }}" state: present reload: yes loop: - { name: 'kernel.printk', value: '3 4 1 3' } - { name: 'kernel.dmesg_restrict', value: '1' } when: privacy_advanced.reduce_kernel_verbosity | bool - name: Configure kernel parameters for privacy lineinfile: path: /etc/sysctl.d/99-privacy.conf line: "{{ item }}" create: yes mode: '0644' loop: - "# Privacy enhancements - reduce kernel logging" - "kernel.printk = 3 4 1 3" - "kernel.dmesg_restrict = 1" when: privacy_advanced.reduce_kernel_verbosity | bool - name: Configure journal settings for privacy lineinfile: path: /etc/systemd/journald.conf regexp: "^#?{{ item.key }}=" line: "{{ item.key }}={{ item.value }}" backup: yes loop: - { key: 'MaxRetentionSec', value: '{{ privacy_log_rotation.max_age * 24 * 3600 }}' } - { key: 'MaxFileSec', value: '1day' } - { key: 'SystemMaxUse', value: '100M' } - { key: 'SystemMaxFileSize', value: '{{ privacy_log_rotation.max_size }}M' } - { key: 'ForwardToSyslog', value: 'no' } notify: restart systemd-journald - name: Disable persistent systemd journal file: path: /var/log/journal state: absent when: privacy_advanced.reduce_kernel_verbosity | bool - name: Create journal configuration for volatile storage only lineinfile: path: /etc/systemd/journald.conf regexp: "^#?Storage=" line: "Storage=volatile" backup: yes notify: restart systemd-journald - name: Configure rsyslog for minimal logging template: src: privacy-rsyslog.conf.j2 dest: /etc/rsyslog.d/45-privacy-minimal.conf mode: '0644' owner: root group: root notify: restart rsyslog - name: Set up privacy monitoring script template: src: privacy-monitor.sh.j2 dest: /usr/local/bin/privacy-monitor.sh mode: '0755' owner: root group: root - name: Display privacy configuration summary debug: msg: - "Privacy enhancements applied:" - " - Log retention: {{ privacy_log_rotation.max_age }} days" - " - VPN log filtering: {{ privacy_log_filtering.exclude_vpn_logs | bool }}" - " - History clearing: {{ privacy_history_clearing.clear_bash_history | bool }}" - " - Auto cleanup: {{ privacy_auto_cleanup.enabled | bool }}" - " - Kernel verbosity reduction: {{ privacy_advanced.reduce_kernel_verbosity | bool }}" ================================================ FILE: roles/privacy/tasks/auto_cleanup.yml ================================================ --- # Automatic cleanup tasks for enhanced privacy - name: Create privacy cleanup script template: src: privacy-auto-cleanup.sh.j2 dest: /usr/local/bin/privacy-auto-cleanup.sh mode: '0755' owner: root group: root - name: Set up automatic privacy cleanup cron job cron: name: "Privacy auto cleanup" job: "/usr/local/bin/privacy-auto-cleanup.sh" minute: "30" hour: "2" user: root state: "{{ 'present' if privacy_auto_cleanup.enabled else 'absent' }}" when: privacy_auto_cleanup.frequency == 'daily' - name: Set up weekly privacy cleanup cron job cron: name: "Privacy auto cleanup weekly" job: "/usr/local/bin/privacy-auto-cleanup.sh" minute: "30" hour: "2" weekday: "0" user: root state: "{{ 'present' if privacy_auto_cleanup.enabled else 'absent' }}" when: privacy_auto_cleanup.frequency == 'weekly' - name: Set up monthly privacy cleanup cron job cron: name: "Privacy auto cleanup monthly" job: "/usr/local/bin/privacy-auto-cleanup.sh" minute: "30" hour: "2" day: "1" user: root state: "{{ 'present' if privacy_auto_cleanup.enabled else 'absent' }}" when: privacy_auto_cleanup.frequency == 'monthly' - name: Create systemd service for privacy cleanup on shutdown template: src: privacy-shutdown-cleanup.service.j2 dest: /etc/systemd/system/privacy-shutdown-cleanup.service mode: '0644' owner: root group: root when: privacy_advanced.clear_logs_on_shutdown | bool notify: - reload systemd - enable privacy shutdown cleanup - name: Clean up temporary files immediately shell: | find /tmp -type f -mtime +{{ privacy_auto_cleanup.temp_files_max_age }} -delete find /var/tmp -type f -mtime +{{ privacy_auto_cleanup.temp_files_max_age }} -delete changed_when: false when: privacy_auto_cleanup.enabled | bool - name: Clean package cache immediately apt: autoclean: true changed_when: false when: - privacy_auto_cleanup.enabled | bool - privacy_auto_cleanup.clean_package_cache | bool ================================================ FILE: roles/privacy/tasks/clear_history.yml ================================================ --- # Clear command history and disable persistent history for privacy - name: Clear bash history for all users shell: | for user_home in /home/* /root; do if [ -d "$user_home" ]; then rm -f "$user_home/.bash_history" rm -f "$user_home/.zsh_history" rm -f "$user_home/.sh_history" fi done when: privacy_history_clearing.clear_bash_history | bool changed_when: false - name: Clear system command history logs file: path: "{{ item }}" state: absent loop: - /var/log/lastlog - /var/log/wtmp.1 - /var/log/btmp.1 - /tmp/.X* - /tmp/.font-unix - /tmp/.ICE-unix when: privacy_history_clearing.clear_system_history | bool failed_when: false - name: Configure bash to not save history for service users lineinfile: path: "{{ item }}/.bashrc" line: "{{ history_disable_line }}" create: true mode: '0644' loop: - /root - /home/ubuntu vars: history_disable_line: | # Privacy enhancement: disable bash history export HISTFILE=/dev/null export HISTSIZE=0 export HISTFILESIZE=0 unset HISTFILE when: privacy_history_clearing.disable_service_history | bool failed_when: false - name: Create history clearing script for logout template: src: clear-history-on-logout.sh.j2 dest: /etc/bash.bash_logout mode: '0644' owner: root group: root when: privacy_history_clearing.clear_bash_history | bool # Note: We don't clear current session history as each Ansible task # runs in its own shell session, making this operation ineffective ================================================ FILE: roles/privacy/tasks/log_filtering.yml ================================================ --- # Configure rsyslog to filter out VPN-related logs for privacy - name: Create rsyslog privacy configuration directory file: path: /etc/rsyslog.d state: directory mode: '0755' owner: root group: root - name: Configure rsyslog to exclude VPN-related logs template: src: 49-privacy-vpn-filter.conf.j2 dest: /etc/rsyslog.d/49-privacy-vpn-filter.conf mode: '0644' owner: root group: root notify: restart rsyslog when: privacy_log_filtering.exclude_vpn_logs | bool - name: Configure rsyslog to filter kernel VPN logs template: src: 48-privacy-kernel-filter.conf.j2 dest: /etc/rsyslog.d/48-privacy-kernel-filter.conf mode: '0644' owner: root group: root notify: restart rsyslog when: privacy_log_filtering.filter_kernel_vpn_logs | bool - name: Configure rsyslog to exclude detailed auth logs (optional) template: src: 47-privacy-auth-filter.conf.j2 dest: /etc/rsyslog.d/47-privacy-auth-filter.conf mode: '0644' owner: root group: root notify: restart rsyslog when: privacy_log_filtering.exclude_auth_logs | bool - name: Create rsyslog privacy filter for SSH success logs template: src: 46-privacy-ssh-filter.conf.j2 dest: /etc/rsyslog.d/46-privacy-ssh-filter.conf mode: '0644' owner: root group: root notify: restart rsyslog when: privacy_advanced.disable_ssh_success_logs | bool - name: Test rsyslog configuration command: rsyslogd -N1 register: rsyslog_test changed_when: false failed_when: rsyslog_test.rc != 0 - name: Display rsyslog test results debug: msg: "Rsyslog configuration test passed" when: rsyslog_test.rc == 0 ================================================ FILE: roles/privacy/tasks/log_rotation.yml ================================================ --- # Aggressive log rotation configuration for privacy # Reduces log retention time and implements more frequent rotation - name: Check if default rsyslog logrotate config exists stat: path: /etc/logrotate.d/rsyslog register: rsyslog_logrotate - name: Disable default rsyslog logrotate to prevent conflicts command: mv /etc/logrotate.d/rsyslog /etc/logrotate.d/rsyslog.disabled when: rsyslog_logrotate.stat.exists changed_when: rsyslog_logrotate.stat.exists - name: Configure aggressive logrotate for system logs template: src: privacy-logrotate.j2 dest: /etc/logrotate.d/99-privacy-enhanced mode: '0644' owner: root group: root notify: restart rsyslog - name: Configure logrotate for auth logs with shorter retention template: src: auth-logrotate.j2 dest: /etc/logrotate.d/99-auth-privacy mode: '0644' owner: root group: root notify: restart rsyslog - name: Configure logrotate for kern logs with VPN filtering template: src: kern-logrotate.j2 dest: /etc/logrotate.d/99-kern-privacy mode: '0644' owner: root group: root notify: restart rsyslog - name: Set more frequent logrotate execution cron: name: "Enhanced privacy log rotation" job: "/usr/sbin/logrotate /etc/logrotate.conf" minute: "0" hour: "*/6" user: root state: present - name: Create privacy log cleanup script template: src: privacy-log-cleanup.sh.j2 dest: /usr/local/bin/privacy-log-cleanup.sh mode: '0755' owner: root group: root # Note: We don't force immediate rotation as it can cause conflicts # The new settings will apply on the next scheduled rotation ================================================ FILE: roles/privacy/tasks/main.yml ================================================ --- # Privacy enhancements for Algo VPN # This role implements additional privacy measures to reduce log retention # and minimize traces of VPN usage on the server - name: Display privacy enhancements status debug: msg: "Privacy enhancements are {{ 'enabled' if privacy_enhancements_enabled else 'disabled' }}" - name: Privacy enhancements block when: privacy_enhancements_enabled | bool block: - name: Include log rotation tasks include_tasks: log_rotation.yml tags: privacy-logs - name: Include history clearing tasks include_tasks: clear_history.yml tags: privacy-history - name: Include log filtering tasks include_tasks: log_filtering.yml tags: privacy-filtering - name: Include automatic cleanup tasks include_tasks: auto_cleanup.yml tags: privacy-cleanup - name: Include advanced privacy tasks include_tasks: advanced_privacy.yml tags: privacy-advanced - name: Display privacy enhancements completion debug: msg: "Privacy enhancements have been successfully applied" ================================================ FILE: roles/privacy/templates/46-privacy-ssh-filter.conf.j2 ================================================ # Privacy-enhanced SSH log filtering # Filters successful SSH connections while keeping failures for security # Generated by Algo VPN privacy role {% if privacy_advanced.disable_ssh_success_logs %} # Filter successful SSH connections (keep failures for security monitoring) :msg, contains, "sshd.*Accepted" stop :msg, contains, "sshd.*session opened" stop :msg, contains, "sshd.*session closed" stop # Filter SSH key-based authentication success :msg, contains, "sshd.*publickey" stop {% endif %} # Continue processing SSH failure messages and other logs ================================================ FILE: roles/privacy/templates/47-privacy-auth-filter.conf.j2 ================================================ # Privacy-enhanced authentication log filtering # WARNING: Use with caution - this reduces security logging # Only enable if you understand the security implications # Generated by Algo VPN privacy role {% if privacy_log_filtering.exclude_auth_logs %} # Filter successful authentication messages (reduces audit trail) :msg, contains, "authentication success" stop :msg, contains, "session opened" stop :msg, contains, "session closed" stop # Filter sudo success messages (keep failures for security) :msg, regex, "sudo.*COMMAND" stop # Filter cron messages :msg, contains, "CRON" stop {% endif %} # Continue processing other auth messages ================================================ FILE: roles/privacy/templates/48-privacy-kernel-filter.conf.j2 ================================================ # Privacy-enhanced kernel log filtering # Filters kernel messages that may reveal VPN usage patterns # Generated by Algo VPN privacy role {% if privacy_log_filtering.filter_kernel_vpn_logs %} # Filter iptables/netfilter messages related to VPN :msg, contains, "iptables" stop :msg, contains, "netfilter" stop # Filter connection tracking messages :msg, contains, "nf_conntrack" stop # Filter network interface up/down messages for VPN interfaces :msg, regex, "wg[0-9]+.*link" stop :msg, regex, "ipsec[0-9]+.*link" stop # Filter routing table changes :msg, contains, "rtnetlink" stop {% endif %} # Continue processing non-filtered messages ================================================ FILE: roles/privacy/templates/49-privacy-vpn-filter.conf.j2 ================================================ # Privacy-enhanced rsyslog configuration # Filters VPN-related log entries for enhanced privacy # Generated by Algo VPN privacy role # Stop processing VPN-related messages to prevent them from being logged # This helps maintain user privacy by not storing VPN connection details {% if privacy_log_filtering.exclude_vpn_logs %} # Filter WireGuard messages :msg, contains, "wireguard" stop # Filter StrongSwan/IPsec messages :msg, contains, "strongswan" stop :msg, contains, "ipsec" stop :msg, contains, "charon" stop :msg, contains, "xl2tpd" stop # Filter VPN interface messages :msg, contains, "wg0" stop :msg, contains, "ipsec0" stop # Filter VPN-related kernel messages :msg, regex, "IN=wg[0-9]+" stop :msg, regex, "OUT=wg[0-9]+" stop {% endif %} {% if privacy_log_filtering.filter_kernel_vpn_logs %} # Filter kernel messages related to VPN traffic :msg, contains, "netfilter" stop :msg, regex, "FORWARD.*DPT:(51820|500|4500)" stop {% endif %} # Continue processing other messages & stop ================================================ FILE: roles/privacy/templates/auth-logrotate.j2 ================================================ # Privacy-enhanced auth log rotation # Reduces retention time for authentication logs # Generated by Algo VPN privacy role /var/log/auth.log { # Shorter retention for auth logs (privacy) rotate 2 maxage {{ privacy_log_rotation.max_age | int // 2 }} size {{ privacy_log_rotation.max_size // 2 }}M daily missingok notifempty compress delaycompress create 0640 syslog adm copytruncate postrotate if [ -f /var/run/rsyslogd.pid ]; then kill -HUP `cat /var/run/rsyslogd.pid` fi endscript } ================================================ FILE: roles/privacy/templates/clear-history-on-logout.sh.j2 ================================================ #!/bin/bash # Privacy-enhanced history clearing on logout # This script clears command history when users log out # Generated by Algo VPN privacy role {% if privacy_history_clearing.clear_bash_history %} # Clear bash history if [ -f ~/.bash_history ]; then > ~/.bash_history fi # Clear zsh history if [ -f ~/.zsh_history ]; then > ~/.zsh_history fi # Clear current session history history -c history -w # Clear less history if [ -f ~/.lesshst ]; then rm -f ~/.lesshst fi # Clear vim history if [ -f ~/.viminfo ]; then rm -f ~/.viminfo fi {% endif %} {% if privacy_history_clearing.clear_system_history %} # Clear temporary files in user directory find ~/tmp -type f -delete 2>/dev/null || true find ~/.cache -type f -delete 2>/dev/null || true {% endif %} ================================================ FILE: roles/privacy/templates/kern-logrotate.j2 ================================================ # Privacy-enhanced kernel log rotation # Reduces retention time for kernel logs that may contain VPN traces # Generated by Algo VPN privacy role /var/log/kern.log { # Aggressive rotation for kernel logs rotate {{ privacy_log_rotation.rotate_count }} maxage {{ privacy_log_rotation.max_age }} size {{ privacy_log_rotation.max_size }}M daily missingok notifempty compress delaycompress create 0640 syslog adm copytruncate # Pre-rotation script to filter VPN-related entries prerotate # Create filtered version excluding VPN traces if [ -f /var/log/kern.log ]; then grep -v -E "(wireguard|ipsec|strongswan|xl2tpd)" /var/log/kern.log > /tmp/kern.log.filtered || true if [ -s /tmp/kern.log.filtered ]; then mv /tmp/kern.log.filtered /var/log/kern.log fi fi endscript postrotate if [ -f /var/run/rsyslogd.pid ]; then kill -HUP `cat /var/run/rsyslogd.pid` fi endscript } ================================================ FILE: roles/privacy/templates/privacy-auto-cleanup.sh.j2 ================================================ #!/bin/bash # Privacy auto-cleanup script # Automatically cleans up logs and temporary files for enhanced privacy # Generated by Algo VPN privacy role set -euo pipefail # Configuration LOG_MAX_AGE={{ privacy_auto_cleanup.temp_files_max_age }} SCRIPT_LOG="/var/log/privacy-cleanup.log" # Logging function log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$SCRIPT_LOG" } log_message "Starting privacy cleanup" {% if privacy_auto_cleanup.enabled %} # Rotate log files to prevent the cleanup log from growing if [ -f "$SCRIPT_LOG" ] && [ $(wc -l < "$SCRIPT_LOG") -gt 1000 ]; then tail -n 500 "$SCRIPT_LOG" > "$SCRIPT_LOG.tmp" mv "$SCRIPT_LOG.tmp" "$SCRIPT_LOG" fi # Clean temporary files log_message "Cleaning temporary files older than ${LOG_MAX_AGE} days" find /tmp -type f -mtime +${LOG_MAX_AGE} -delete 2>/dev/null || true find /var/tmp -type f -mtime +${LOG_MAX_AGE} -delete 2>/dev/null || true # Clean old log files that may have escaped rotation log_message "Cleaning old rotated logs" find /var/log -name "*.log.*" -type f -mtime +{{ privacy_log_rotation.max_age }} -delete 2>/dev/null || true find /var/log -name "*.gz" -type f -mtime +{{ privacy_log_rotation.max_age }} -delete 2>/dev/null || true # Clean systemd journal if it exists if [ -d /var/log/journal ]; then log_message "Cleaning systemd journal files" journalctl --vacuum-time={{ privacy_log_rotation.max_age }}d 2>/dev/null || true journalctl --vacuum-size=50M 2>/dev/null || true fi {% if privacy_auto_cleanup.clean_package_cache %} # Clean package cache log_message "Cleaning package cache" apt-get clean 2>/dev/null || true apt-get autoclean 2>/dev/null || true {% endif %} # Clean bash history files log_message "Cleaning bash history files" for user_home in /home/* /root; do if [ -d "$user_home" ]; then rm -f "$user_home/.bash_history" 2>/dev/null || true rm -f "$user_home/.zsh_history" 2>/dev/null || true rm -f "$user_home/.lesshst" 2>/dev/null || true rm -f "$user_home/.viminfo" 2>/dev/null || true fi done # Clean core dumps log_message "Cleaning core dumps" find /var/crash -type f -name "*.crash" -mtime +1 -delete 2>/dev/null || true # Force log rotation log_message "Forcing log rotation" /usr/sbin/logrotate -f /etc/logrotate.conf 2>/dev/null || true log_message "Privacy cleanup completed successfully" {% else %} log_message "Privacy cleanup is disabled" {% endif %} # Clean up old privacy cleanup logs find /var/log -name "privacy-cleanup.log.*" -type f -mtime +7 -delete 2>/dev/null || true ================================================ FILE: roles/privacy/templates/privacy-log-cleanup.sh.j2 ================================================ #!/bin/bash # Privacy log cleanup script # Immediately cleans up existing logs and applies privacy settings # Generated by Algo VPN privacy role set -euo pipefail echo "Starting privacy log cleanup..." # Truncate existing log files to apply new rotation settings immediately find /var/log -type f -name "*.log" -size +{{ privacy_log_rotation.max_size }}M -exec truncate -s {{ privacy_log_rotation.max_size }}M {} \; 2>/dev/null || true # Remove old rotated logs that exceed our retention policy find /var/log -type f \( -name "*.log.*" -o -name "*.gz" \) -mtime +{{ privacy_log_rotation.max_age }} -delete 2>/dev/null || true # Clean up systemd journal to respect new settings if [ -d /var/log/journal ]; then journalctl --vacuum-time={{ privacy_log_rotation.max_age }}d 2>/dev/null || true journalctl --vacuum-size={{ privacy_log_rotation.max_size * 10 }}M 2>/dev/null || true fi echo "Privacy log cleanup completed" ================================================ FILE: roles/privacy/templates/privacy-logrotate.j2 ================================================ # Privacy-enhanced logrotate configuration # This configuration enforces aggressive log rotation for privacy # Generated by Algo VPN privacy role # Replaces the default rsyslog logrotate configuration # Main system logs (may not all exist on every system) /var/log/syslog /var/log/messages /var/log/daemon.log /var/log/debug /var/log/user.log /var/log/mail.log /var/log/mail.err /var/log/mail.warn { # Rotate {{ privacy_log_rotation.rotate_count }} times before deletion rotate {{ privacy_log_rotation.rotate_count }} # Maximum age in days maxage {{ privacy_log_rotation.max_age }} # Maximum size per file size {{ privacy_log_rotation.max_size }}M {% if privacy_log_rotation.daily_rotation %} # Force daily rotation daily {% endif %} {% if privacy_log_rotation.compress %} # Compress rotated files compress delaycompress {% endif %} # Missing files are ok (not all systems have all logs) missingok # Don't rotate if empty notifempty # Create new files with specific permissions create 0640 syslog adm # Truncate original file after rotation copytruncate # Execute after rotation postrotate # Send SIGHUP to rsyslog /usr/bin/killall -HUP rsyslogd 2>/dev/null || true endscript } ================================================ FILE: roles/privacy/templates/privacy-monitor.sh.j2 ================================================ #!/bin/bash # Privacy monitoring script # Monitors and reports on privacy settings status # Generated by Algo VPN privacy role set -euo pipefail # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}Algo VPN Privacy Status Monitor${NC}" echo "========================================" # Check log rotation settings echo -e "\n${YELLOW}Log Rotation Status:${NC}" if [ -f /etc/logrotate.d/99-privacy-enhanced ]; then echo -e " ${GREEN}✓${NC} Privacy log rotation configured" else echo -e " ${RED}✗${NC} Privacy log rotation not found" fi # Check rsyslog filtering echo -e "\n${YELLOW}Log Filtering Status:${NC}" if [ -f /etc/rsyslog.d/49-privacy-vpn-filter.conf ]; then echo -e " ${GREEN}✓${NC} VPN log filtering enabled" else echo -e " ${RED}✗${NC} VPN log filtering not configured" fi # Check history clearing echo -e "\n${YELLOW}History Clearing Status:${NC}" if [ -f /etc/bash.bash_logout ]; then echo -e " ${GREEN}✓${NC} Logout history clearing configured" else echo -e " ${RED}✗${NC} Logout history clearing not configured" fi # Check auto cleanup echo -e "\n${YELLOW}Auto Cleanup Status:${NC}" if [ -f /usr/local/bin/privacy-auto-cleanup.sh ]; then echo -e " ${GREEN}✓${NC} Auto cleanup script installed" if crontab -l | grep -q "privacy-auto-cleanup"; then echo -e " ${GREEN}✓${NC} Auto cleanup scheduled" else echo -e " ${YELLOW}!${NC} Auto cleanup script exists but not scheduled" fi else echo -e " ${RED}✗${NC} Auto cleanup not configured" fi # Check current log sizes echo -e "\n${YELLOW}Current Log Status:${NC}" total_log_size=$(du -sh /var/log 2>/dev/null | cut -f1 || echo "Unknown") echo " Total log directory size: $total_log_size" if [ -f /var/log/auth.log ]; then auth_size=$(du -h /var/log/auth.log | cut -f1) echo " Auth log size: $auth_size" fi if [ -f /var/log/syslog ]; then syslog_size=$(du -h /var/log/syslog | cut -f1) echo " Syslog size: $syslog_size" fi # Check systemd journal status echo -e "\n${YELLOW}Journal Status:${NC}" if [ -d /var/log/journal ]; then journal_size=$(du -sh /var/log/journal 2>/dev/null | cut -f1 || echo "Unknown") echo " Journal size: $journal_size" else echo -e " ${GREEN}✓${NC} Persistent journal disabled (using volatile storage)" fi # Privacy configuration summary echo -e "\n${YELLOW}Privacy Configuration Summary:${NC}" echo " Log retention: {{ privacy_log_rotation.max_age }} days" echo " Max log size: {{ privacy_log_rotation.max_size }}MB" echo " VPN log filtering: {{ privacy_log_filtering.exclude_vpn_logs }}" echo -e " History clearing: {{ privacy_history_clearing.clear_bash_history }}" echo -e "\n${GREEN}Privacy monitoring complete${NC}" ================================================ FILE: roles/privacy/templates/privacy-rsyslog.conf.j2 ================================================ # Privacy-enhanced rsyslog configuration # Minimal logging configuration for enhanced privacy # Generated by Algo VPN privacy role # Global settings for privacy $ModLoad imuxsock # provides support for local system logging $ModLoad imklog # provides kernel logging support # Reduce logging verbosity $KLogPermitNonKernelFacility on $SystemLogSocketName /run/systemd/journal/syslog # Privacy-enhanced rules {% if privacy_advanced.reduce_kernel_verbosity %} # Reduce kernel message verbosity kern.info;kern.!debug /var/log/kern.log {% else %} kern.* /var/log/kern.log {% endif %} # Essential system messages only *.emerg :omusrmsg:* *.alert /var/log/alert.log *.crit /var/log/critical.log *.err /var/log/error.log # Compress and limit emergency logs $template PrivacyTemplate,"%timegenerated% %hostname% %syslogtag%%msg%\n" $ActionFileDefaultTemplate PrivacyTemplate # Stop processing after essential logs to prevent detailed logging & stop ================================================ FILE: roles/privacy/templates/privacy-shutdown-cleanup.service.j2 ================================================ # Privacy shutdown cleanup systemd service # Clears logs and sensitive data on system shutdown # Generated by Algo VPN privacy role [Unit] Description=Privacy Cleanup on Shutdown DefaultDependencies=false Before=shutdown.target reboot.target halt.target Requires=-.mount [Service] Type=oneshot RemainAfterExit=true ExecStart=/bin/true ExecStop=/bin/bash -c ' # Clear all logs find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; 2>/dev/null || true; # Clear rotated logs find /var/log -type f \( -name "*.log.*" -o -name "*.gz" \) -delete 2>/dev/null || true; # Clear systemd journal if [ -d /var/log/journal ]; then rm -rf /var/log/journal/* 2>/dev/null || true; fi; # Clear bash history for user_home in /home/* /root; do if [ -d "$user_home" ]; then rm -f "$user_home"/.bash_history 2>/dev/null || true; rm -f "$user_home"/.zsh_history 2>/dev/null || true; fi; done; # Clear temporary files rm -rf /tmp/* /var/tmp/* 2>/dev/null || true; # Sync to ensure changes are written sync; ' TimeoutStopSec=30 [Install] WantedBy=shutdown.target ================================================ FILE: roles/ssh_tunneling/defaults/main.yml ================================================ --- ssh_tunnels_config_path: configs/{{ IP_subject_alt_name }}/ssh-tunnel/ ================================================ FILE: roles/ssh_tunneling/handlers/main.yml ================================================ --- - name: restart ssh service: name="{{ ssh_service_name | default('ssh') }}" state=restarted ================================================ FILE: roles/ssh_tunneling/tasks/main.yml ================================================ --- - name: Ensure that the sshd_config file has desired options blockinfile: dest: /etc/ssh/sshd_config marker: "# {mark} ANSIBLE MANAGED BLOCK ssh_tunneling_role" block: | Match Group algo AllowTcpForwarding local AllowAgentForwarding no AllowStreamLocalForwarding no PermitTunnel no X11Forwarding no notify: - restart ssh - name: Ensure that the algo group exist group: name: algo state: present gid: 15000 - name: Ensure that the jail directory exist file: path: /var/jail/ state: directory mode: '0755' owner: root group: "{{ root_group | default('root') }}" - tags: update-users block: - name: Ensure that the SSH users exist user: name: "{{ item }}" group: algo groups: algo home: /var/jail/{{ item }} createhome: true generate_ssh_key: false shell: /bin/false state: present append: true loop: "{{ users }}" - become: false delegate_to: localhost block: - name: Clean up the ssh-tunnel directory file: dest: "{{ ssh_tunnels_config_path }}" state: absent when: keys_clean_all|bool - name: Ensure the config directories exist file: dest: "{{ ssh_tunnels_config_path }}" state: directory recurse: true mode: "0700" - name: Check if the private keys exist stat: path: "{{ ssh_tunnels_config_path }}/{{ item }}.pem" register: privatekey loop: "{{ users }}" - name: Build ssh private keys openssl_privatekey: path: "{{ ssh_tunnels_config_path }}/{{ item.item }}.pem" passphrase: "{{ p12_export_password }}" cipher: auto force: false no_log: "{{ algo_no_log | bool }}" when: not item.stat.exists loop: "{{ privatekey.results }}" register: openssl_privatekey - name: Build ssh public keys openssl_publickey: path: "{{ ssh_tunnels_config_path }}/{{ item.item.item }}.pub" privatekey_path: "{{ ssh_tunnels_config_path }}/{{ item.item.item }}.pem" privatekey_passphrase: "{{ p12_export_password }}" format: OpenSSH force: true no_log: "{{ algo_no_log | bool }}" when: item.changed loop: "{{ openssl_privatekey.results }}" - name: Build the client ssh config template: src: ssh_config.j2 dest: "{{ ssh_tunnels_config_path }}/{{ item }}.ssh_config" mode: '0700' loop: "{{ users }}" - name: The authorized keys file created authorized_key: user: "{{ item }}" key: "{{ lookup('file', ssh_tunnels_config_path + '/' + item + '.pub') }}" state: present manage_dir: true exclusive: true loop: "{{ users }}" - name: Get active users getent: database: group key: algo split: ":" - name: Delete non-existing users user: name: "{{ item }}" state: absent remove: true force: true when: item not in users loop: "{{ getent_group['algo'][2].split(',') }}" ================================================ FILE: roles/ssh_tunneling/templates/ssh_config.j2 ================================================ Host algo DynamicForward 127.0.0.1:1080 LogLevel quiet Compression yes IdentitiesOnly yes IdentityFile {{ item }}.ssh.pem User {{ item }} Hostname {{ IP_subject_alt_name }} ================================================ FILE: roles/strongswan/defaults/main.yml ================================================ --- ipsec_config_path: configs/{{ IP_subject_alt_name }}/ipsec ipsec_pki_path: "{{ ipsec_config_path }}/.pki" strongswan_shell: /usr/sbin/nologin strongswan_home: /var/lib/strongswan strongswan_service: "{{ 'strongswan-starter' if ansible_facts['distribution_version'] is version('20.04', '>=') else 'strongswan' }}" BetweenClients_DROP: true algo_ondemand_cellular: false algo_ondemand_wifi: false algo_ondemand_wifi_exclude: _null algo_dns_adblocking: false ipv6_support: false dns_encryption: true # Random UUID for CA name constraints - prevents certificate reuse across different Algo deployments # This unique identifier ensures each CA can only issue certificates for its specific server instance openssl_constraint_random_id: "{{ IP_subject_alt_name | to_uuid }}.algo" # Subject Alternative Name (SAN) configuration - CRITICAL for client compatibility # Modern clients (especially macOS/iOS) REQUIRE SAN extension in server certificates # Without SAN, IKEv2 connections will fail with certificate validation errors subjectAltName_type: "{{ 'DNS' if IP_subject_alt_name | regex_search('[a-z]') else 'IP' }}" subjectAltName: >- {{ subjectAltName_type }}:{{ IP_subject_alt_name }}{%- if ipv6_support | bool -%},IP:{{ ansible_default_ipv6['address'] }}{%- endif -%} subjectAltName_USER: email:{{ item }}@{{ openssl_constraint_random_id }} # yamllint disable rule:line-length nameConstraints: >- critical,permitted;{{ subjectAltName_type }}:{{ IP_subject_alt_name }}{{- '/255.255.255.255' if subjectAltName_type == 'IP' else '' -}}{%- if subjectAltName_type == 'IP' -%},permitted;DNS:{{ openssl_constraint_random_id }},excluded;DNS:.com,excluded;DNS:.org,excluded;DNS:.net,excluded;DNS:.gov,excluded;DNS:.edu,excluded;DNS:.mil,excluded;DNS:.int,excluded;IP:10.0.0.0/255.0.0.0,excluded;IP:172.16.0.0/255.240.0.0,excluded;IP:192.168.0.0/255.255.0.0{%- else -%},excluded;IP:0.0.0.0/0.0.0.0{%- endif -%},permitted;email:{{ openssl_constraint_random_id }},excluded;email:.com,excluded;email:.org,excluded;email:.net,excluded;email:.gov,excluded;email:.edu,excluded;email:.mil,excluded;email:.int{%- if ipv6_support | bool -%},permitted;IP:{{ ansible_default_ipv6['address'] }}/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff,excluded;IP:fc00:0:0:0:0:0:0:0/fe00:0:0:0:0:0:0:0,excluded;IP:fe80:0:0:0:0:0:0:0/ffc0:0:0:0:0:0:0:0,excluded;IP:2001:db8:0:0:0:0:0:0/ffff:fff8:0:0:0:0:0:0{%- else -%},excluded;IP:::/0{%- endif -%} # yamllint enable rule:line-length openssl_bin: openssl strongswan_enabled_plugins: - aes - gcm - hmac - kernel-netlink - nonce - openssl - pem - pgp - pkcs12 - pkcs7 - pkcs8 - pubkey - random - revocation - sha2 - socket-default - stroke - x509 ciphers: defaults: ike: aes256gcm16-prfsha512-ecp384! esp: aes256gcm16-ecp384! pkcs12_PayloadCertificateUUID: "{{ 900000 | random | to_uuid | upper }}" VPN_PayloadIdentifier: "{{ 800000 | random | to_uuid | upper }}" CA_PayloadIdentifier: "{{ 700000 | random | to_uuid | upper }}" ================================================ FILE: roles/strongswan/handlers/main.yml ================================================ --- - name: restart strongswan service: name={{ strongswan_service }} state=restarted - name: daemon-reload systemd: daemon_reload=true - name: restart apparmor service: name=apparmor state=restarted - name: rereadcrls shell: | # Check if StrongSwan is actually running if ! systemctl is-active --quiet strongswan-starter 2>/dev/null && \ ! systemctl is-active --quiet strongswan 2>/dev/null && \ ! service strongswan status >/dev/null 2>&1; then echo "StrongSwan is not running, skipping CRL reload" exit 0 fi # StrongSwan is running, wait a moment for it to stabilize sleep 2 # Try to reload CRLs with retries for attempt in 1 2 3; do if ipsec rereadcrls 2>/dev/null && ipsec purgecrls 2>/dev/null; then echo "Successfully reloaded CRLs" exit 0 fi echo "Attempt $attempt failed, retrying..." sleep 2 done # If StrongSwan is running but we can't reload CRLs, that's a real problem echo "Failed to reload CRLs after 3 attempts" exit 1 changed_when: false ================================================ FILE: roles/strongswan/meta/main.yml ================================================ --- ================================================ FILE: roles/strongswan/tasks/client_configs.yml ================================================ --- - name: Register p12 PayloadContent shell: | set -o pipefail cat private/{{ item }}.p12 | base64 register: PayloadContent changed_when: false args: executable: bash chdir: "{{ ipsec_pki_path }}" loop: "{{ users }}" - name: Set facts for mobileconfigs set_fact: PayloadContentCA: "{{ lookup('file', ipsec_pki_path + '/cacert.pem') | b64encode }}" - name: Build the mobileconfigs template: src: mobileconfig.j2 dest: "{{ ipsec_config_path }}/apple/{{ item.0 }}.mobileconfig" mode: '0600' with_together: - "{{ users }}" - "{{ PayloadContent.results }}" no_log: "{{ algo_no_log | bool }}" - name: Build the client ipsec config file template: src: client_ipsec.conf.j2 dest: "{{ ipsec_config_path }}/manual/{{ item }}.conf" mode: '0600' loop: "{{ users }}" - name: Build the client ipsec secret file template: src: client_ipsec.secrets.j2 dest: "{{ ipsec_config_path }}/manual/{{ item }}.secrets" mode: '0600' loop: "{{ users }}" - name: Restrict permissions for the local private directories file: path: "{{ ipsec_config_path }}" state: directory mode: '0700' ================================================ FILE: roles/strongswan/tasks/distribute_keys.yml ================================================ --- - name: Copy the keys to the strongswan directory copy: src: "{{ ipsec_pki_path }}/{{ item.src }}" dest: "{{ config_prefix | default('/') }}etc/ipsec.d/{{ item.dest }}" owner: "{{ item.owner }}" group: "{{ item.group }}" mode: "{{ item.mode }}" loop: - src: cacert.pem dest: cacerts/ca.crt owner: strongswan group: "{{ root_group | default('root') }}" mode: "0600" - src: certs/{{ IP_subject_alt_name }}.crt dest: certs/{{ IP_subject_alt_name }}.crt owner: strongswan group: "{{ root_group | default('root') }}" mode: "0600" - src: private/{{ IP_subject_alt_name }}.key dest: private/{{ IP_subject_alt_name }}.key owner: strongswan group: "{{ root_group | default('root') }}" mode: "0600" notify: - restart strongswan ================================================ FILE: roles/strongswan/tasks/ipsec_configuration.yml ================================================ --- - name: Setup the config files from our templates template: src: "{{ item.src }}" dest: "{{ config_prefix | default('/') }}etc/{{ item.dest }}" owner: "{{ item.owner }}" group: "{{ item.group }}" mode: "{{ item.mode }}" loop: - src: strongswan.conf.j2 dest: strongswan.conf owner: root group: "{{ root_group | default('root') }}" mode: "0644" - src: ipsec.conf.j2 dest: ipsec.conf owner: root group: "{{ root_group | default('root') }}" mode: "0644" - src: ipsec.secrets.j2 dest: ipsec.secrets owner: strongswan group: "{{ root_group | default('root') }}" mode: "0600" - src: charon.conf.j2 dest: strongswan.d/charon.conf owner: root group: "{{ root_group | default('root') }}" mode: "0644" notify: - restart strongswan - name: Get loaded plugins shell: | set -o pipefail find {{ config_prefix | default('/') }}etc/strongswan.d/charon/ -type f -name '*.conf' -exec basename {} \; | cut -f1 -d. changed_when: false args: executable: bash register: strongswan_plugins - name: Disable unneeded plugins lineinfile: dest: "{{ config_prefix | default('/') }}etc/strongswan.d/charon/{{ item }}.conf" regexp: .*load.* line: load = no state: present notify: - restart strongswan when: item not in strongswan_enabled_plugins and item not in strongswan_additional_plugins loop: "{{ strongswan_plugins.stdout_lines }}" - name: Ensure that required plugins are enabled lineinfile: dest="{{ config_prefix | default('/') }}etc/strongswan.d/charon/{{ item }}.conf" regexp='.*load.*' line='load = yes' state=present notify: - restart strongswan when: item in strongswan_enabled_plugins or item in strongswan_additional_plugins loop: "{{ strongswan_plugins.stdout_lines }}" ================================================ FILE: roles/strongswan/tasks/main.yml ================================================ --- - name: Include tasks for Debian/Ubuntu include_tasks: ubuntu.yml when: is_debian_based | bool - name: Ensure that the strongswan user exists user: name: strongswan group: nogroup shell: "{{ strongswan_shell }}" home: "{{ strongswan_home }}" state: present - name: Install strongSwan package: name=strongswan state=present - import_tasks: ipsec_configuration.yml - import_tasks: openssl.yml tags: update-users - import_tasks: distribute_keys.yml - import_tasks: client_configs.yml delegate_to: localhost become: false tags: update-users - name: strongSwan started service: name: "{{ strongswan_service }}" state: started enabled: true - meta: flush_handlers - name: Delete the PKI directory file: path: "{{ ipsec_pki_path }}" state: absent become: false delegate_to: localhost when: - not algo_store_pki - not pki_in_tmpfs ================================================ FILE: roles/strongswan/tasks/openssl.yml ================================================ --- - become: false delegate_to: localhost vars: ansible_python_interpreter: "{{ ansible_playbook_python }}" certificate_validity_days: 3650 # 10 years - configurable certificate lifespan block: - debug: var=subjectAltName - name: Ensure the pki directory does not exist file: dest: "{{ ipsec_pki_path }}" state: absent when: keys_clean_all|bool - name: Ensure the pki directories exist file: dest: "{{ ipsec_pki_path }}/{{ item }}" state: directory recurse: true mode: "0700" loop: - certs - private - public - name: Ensure the config directories exist file: dest: "{{ ipsec_config_path }}/{{ item }}" state: directory recurse: true mode: "0700" loop: - apple - manual - name: Create private key with password protection community.crypto.openssl_privatekey: path: "{{ ipsec_pki_path }}/private/cakey.pem" passphrase: "{{ CA_password }}" type: ECC curve: secp384r1 mode: "0600" no_log: true # CA certificate with name constraints to prevent certificate misuse (Issue #75) - name: Create certificate signing request (CSR) for CA certificate with security constraints community.crypto.openssl_csr_pipe: privatekey_path: "{{ ipsec_pki_path }}/private/cakey.pem" privatekey_passphrase: "{{ CA_password }}" common_name: "{{ IP_subject_alt_name }}" use_common_name_for_san: true # Generate Subject Key Identifier for proper Authority Key Identifier creation create_subject_key_identifier: true basic_constraints: - 'CA:TRUE' - 'pathlen:0' # Prevents sub-CA creation - limits certificate chain depth if CA key compromised basic_constraints_critical: true key_usage: - keyCertSign - cRLSign key_usage_critical: true # CA restricted to VPN certificate issuance only extended_key_usage: - '1.3.6.1.5.5.7.3.17' # IPsec End Entity OID - VPN-specific usage extended_key_usage_critical: true # Name Constraints: Defense-in-depth security restricting certificate scope to prevent misuse # Limits CA to only issue certificates for this specific VPN deployment's resources # Per-deployment UUID prevents cross-deployment reuse, unique email domain isolates certificate scope name_constraints_permitted: >- {{ [ subjectAltName_type + ':' + IP_subject_alt_name + ('/255.255.255.255' if subjectAltName_type == 'IP' else ''), 'DNS:' + openssl_constraint_random_id, 'email:' + openssl_constraint_random_id ] + ( ['IP:' + ansible_default_ipv6['address'] + '/128'] if ipv6_support | bool else [] ) }} # Block public domains/networks to prevent certificate abuse for impersonation attacks # Public TLD exclusion, Email domain exclusion, RFC 1918: prevents lateral movement # IPv6: ULA/link-local/doc ranges or all name_constraints_excluded: >- {{ [ 'DNS:.com', 'DNS:.org', 'DNS:.net', 'DNS:.gov', 'DNS:.edu', 'DNS:.mil', 'DNS:.int', 'email:.com', 'email:.org', 'email:.net', 'email:.gov', 'email:.edu', 'email:.mil', 'email:.int', 'IP:10.0.0.0/255.0.0.0', 'IP:172.16.0.0/255.240.0.0', 'IP:192.168.0.0/255.255.0.0' ] + ( ['IP:fc00::/7', 'IP:fe80::/10', 'IP:2001:db8::/32'] if ipv6_support | bool else ['IP:::/0'] ) }} name_constraints_critical: true register: ca_csr - name: Create self-signed CA certificate from CSR community.crypto.x509_certificate: path: "{{ ipsec_pki_path }}/cacert.pem" csr_content: "{{ ca_csr.csr }}" privatekey_path: "{{ ipsec_pki_path }}/private/cakey.pem" privatekey_passphrase: "{{ CA_password }}" provider: selfsigned mode: "0644" no_log: true - name: Copy the CA certificate copy: src: "{{ ipsec_pki_path }}/cacert.pem" dest: "{{ ipsec_config_path }}/manual/cacert.pem" mode: '0644' - name: Create private keys for users and server community.crypto.openssl_privatekey: path: "{{ ipsec_pki_path }}/private/{{ item }}.key" type: ECC curve: secp384r1 mode: "0600" loop: "{{ users + [IP_subject_alt_name] }}" register: client_key_jobs # Server certificate with SAN extension - required for modern Apple devices - name: Create CSRs for server certificate with SAN community.crypto.openssl_csr_pipe: privatekey_path: "{{ ipsec_pki_path }}/private/{{ IP_subject_alt_name }}.key" subject_alt_name: "{{ subjectAltName.split(',') }}" common_name: "{{ IP_subject_alt_name }}" # Add Basic Constraints to prevent certificate chain validation errors basic_constraints: - 'CA:FALSE' basic_constraints_critical: false key_usage: - digitalSignature - keyEncipherment key_usage_critical: false # Server auth EKU required for IKEv2 server certificates (Issue #75) # NOTE: clientAuth deliberately excluded to prevent role confusion attacks extended_key_usage: - serverAuth # Server Authentication (RFC 5280) - '1.3.6.1.5.5.7.3.17' # IPsec End Entity (RFC 4945) extended_key_usage_critical: false register: server_csr - name: Create CSRs for client certificates community.crypto.openssl_csr_pipe: privatekey_path: "{{ ipsec_pki_path }}/private/{{ item }}.key" subject_alt_name: - "email:{{ item }}@{{ openssl_constraint_random_id }}" # UUID domain prevents certificate reuse across deployments common_name: "{{ item }}" # Add Basic Constraints to client certificates for proper PKI validation basic_constraints: - 'CA:FALSE' basic_constraints_critical: false key_usage: - digitalSignature - keyEncipherment key_usage_critical: false # Client certs restricted to clientAuth only - prevents clients from impersonating the VPN server # NOTE: serverAuth deliberately excluded to prevent server impersonation attacks extended_key_usage: - clientAuth # Client Authentication (RFC 5280) - '1.3.6.1.5.5.7.3.17' # IPsec End Entity (RFC 4945) extended_key_usage_critical: false loop: "{{ users }}" register: client_csr_jobs - name: Sign server certificate with CA community.crypto.x509_certificate: csr_content: "{{ server_csr.csr }}" path: "{{ ipsec_pki_path }}/certs/{{ IP_subject_alt_name }}.crt" provider: ownca ownca_path: "{{ ipsec_pki_path }}/cacert.pem" ownca_privatekey_path: "{{ ipsec_pki_path }}/private/cakey.pem" ownca_privatekey_passphrase: "{{ CA_password }}" ownca_not_after: "+{{ certificate_validity_days }}d" ownca_not_before: "-1d" mode: "0644" no_log: true - name: Sign client certificates with CA community.crypto.x509_certificate: csr_content: "{{ item.csr }}" path: "{{ ipsec_pki_path }}/certs/{{ item.item }}.crt" provider: ownca ownca_path: "{{ ipsec_pki_path }}/cacert.pem" ownca_privatekey_path: "{{ ipsec_pki_path }}/private/cakey.pem" ownca_privatekey_passphrase: "{{ CA_password }}" ownca_not_after: "+{{ certificate_validity_days }}d" ownca_not_before: "-1d" mode: "0644" loop: "{{ client_csr_jobs.results }}" register: client_sign_results no_log: true - name: Generate p12 files community.crypto.openssl_pkcs12: path: "{{ ipsec_pki_path }}/private/{{ item }}.p12" friendly_name: "{{ item }}" privatekey_path: "{{ ipsec_pki_path }}/private/{{ item }}.key" certificate_path: "{{ ipsec_pki_path }}/certs/{{ item }}.crt" passphrase: "{{ p12_export_password }}" mode: "0600" encryption_level: "compatibility2022" # Apple device compatibility loop: "{{ users }}" no_log: true - name: Generate p12 files with CA certificate included community.crypto.openssl_pkcs12: path: "{{ ipsec_pki_path }}/private/{{ item }}_ca.p12" friendly_name: "{{ item }}" privatekey_path: "{{ ipsec_pki_path }}/private/{{ item }}.key" certificate_path: "{{ ipsec_pki_path }}/certs/{{ item }}.crt" other_certificates: - "{{ ipsec_pki_path }}/cacert.pem" passphrase: "{{ p12_export_password }}" mode: "0600" encryption_level: "compatibility2022" # Apple device compatibility loop: "{{ users }}" no_log: true - name: Copy the p12 certificates copy: src: "{{ ipsec_pki_path }}/private/{{ item }}.p12" dest: "{{ ipsec_config_path }}/manual/{{ item }}.p12" mode: '0600' loop: "{{ users }}" - name: Build openssh public keys community.crypto.openssl_publickey: path: "{{ ipsec_pki_path }}/public/{{ item }}.pub" privatekey_path: "{{ ipsec_pki_path }}/private/{{ item }}.key" format: OpenSSH loop: "{{ users }}" - name: Add all users to the file ansible.builtin.lineinfile: path: "{{ ipsec_pki_path }}/all-users" line: "{{ item }}" mode: '0644' create: true loop: "{{ users }}" register: users_file - name: Set all users as a fact set_fact: all_users: "{{ lookup('file', ipsec_pki_path + '/all-users').splitlines() }}" # Certificate Revocation List (CRL) for removed users - name: Calculate current timestamp for CRL set_fact: crl_timestamp: "{{ '%Y%m%d%H%M%SZ' | strftime(ansible_date_time.epoch | int) }}" - name: Identify users whose certificates need revocation set_fact: users_to_revoke: "{{ all_users | difference(users) }}" - name: Build revoked certificates list set_fact: revoked_certificates: >- {{ users_to_revoke | map('regex_replace', '^(.*)$', '{"path": "' + ipsec_pki_path + '/certs/\1.crt", "revocation_date": "' + crl_timestamp + '"}') | list }} - name: Generate a CRL community.crypto.x509_crl: path: "{{ ipsec_pki_path }}/crl.pem" privatekey_path: "{{ ipsec_pki_path }}/private/cakey.pem" privatekey_passphrase: "{{ CA_password }}" last_update: "{{ '%Y%m%d%H%M%SZ' | strftime(ansible_date_time.epoch | int) }}" next_update: "{{ '%Y%m%d%H%M%SZ' | strftime((ansible_date_time.epoch | int) + (10 * 365 * 24 * 60 * 60)) }}" crl_mode: generate issuer: CN: "{{ IP_subject_alt_name }}" revoked_certificates: "{{ revoked_certificates }}" no_log: true - name: Set CRL file permissions file: path: "{{ ipsec_pki_path }}/crl.pem" mode: "0644" - name: Copy the CRL to the vpn server copy: src: "{{ ipsec_pki_path }}/crl.pem" dest: "{{ config_prefix | default('/') }}etc/ipsec.d/crls/algo.root.pem" mode: '0644' notify: - rereadcrls ================================================ FILE: roles/strongswan/tasks/ubuntu.yml ================================================ --- - name: Set OS specific facts set_fact: strongswan_additional_plugins: [] - name: Ubuntu | Ensure af_key kernel module is loaded modprobe: name: af_key state: present persistent: present - name: Ubuntu | Install strongSwan (individual) apt: name: strongswan state: present update_cache: true install_recommends: true when: not performance_parallel_packages | default(true) - when: apparmor_enabled|default(false)|bool tags: apparmor block: # https://bugs.launchpad.net/ubuntu/+source/strongswan/+bug/1826238 - name: Ubuntu | Charon profile for apparmor configured copy: dest: /etc/apparmor.d/local/usr.lib.ipsec.charon content: " capability setpcap," owner: root group: root mode: '0644' notify: restart strongswan - name: Ubuntu | Enforcing ipsec with apparmor command: aa-enforce "{{ item }}" changed_when: false loop: - /usr/lib/ipsec/charon - /usr/lib/ipsec/lookip - /usr/lib/ipsec/stroke - name: Ubuntu | Enable services service: name={{ item }} enabled=yes loop: - apparmor - "{{ strongswan_service }}" - netfilter-persistent - name: Ubuntu | Ensure that the strongswan service directory exists file: path: /etc/systemd/system/{{ strongswan_service }}.service.d/ state: directory mode: '0755' owner: root group: root - name: Ubuntu | Setup the cgroup limitations for the ipsec daemon template: src: 100-CustomLimitations.conf.j2 dest: /etc/systemd/system/{{ strongswan_service }}.service.d/100-CustomLimitations.conf mode: '0644' notify: - daemon-reload - restart strongswan ================================================ FILE: roles/strongswan/templates/100-CustomLimitations.conf.j2 ================================================ # Algo VPN systemd security hardening for StrongSwan # Enhanced hardening on top of existing AppArmor [Service] # Privilege restrictions NoNewPrivileges=yes # Filesystem isolation (complements AppArmor) ProtectHome=yes PrivateTmp=yes ProtectKernelTunables=yes ProtectControlGroups=yes # Network restrictions - include IPsec kernel communication requirements # AF_UNIX required for VICI socket communication (swanctl/modern StrongSwan interface) RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_PACKET AF_UNIX # Allow access to IPsec configuration, state, and kernel interfaces ReadWritePaths=/etc/ipsec.d /var/lib/strongswan ReadOnlyPaths=/proc/net/pfkey # System call filtering (complements AppArmor restrictions) # Allow crypto operations, remove cpu-emulation restriction for crypto algorithms SystemCallFilter=@system-service @network-io SystemCallFilter=~@debug @mount @swap @reboot SystemCallErrorNumber=EPERM ================================================ FILE: roles/strongswan/templates/charon.conf.j2 ================================================ # Options for the charon IKE daemon. charon { # Accept unencrypted ID and HASH payloads in IKEv1 Main Mode. # accept_unencrypted_mainmode_messages = no # Maximum number of half-open IKE_SAs for a single peer IP. # block_threshold = 5 # Whether Certificate Revocation Lists (CRLs) fetched via HTTP or LDAP # should be saved under a unique file name derived from the public key of # the Certification Authority (CA) to /etc/ipsec.d/crls (stroke) or # /etc/swanctl/x509crl (vici), respectively. # cache_crls = no # Whether relations in validated certificate chains should be cached in # memory. # cert_cache = yes # Send Cisco Unity vendor ID payload (IKEv1 only). # cisco_unity = no # Close the IKE_SA if setup of the CHILD_SA along with IKE_AUTH failed. close_ike_on_child_failure = yes # Number of half-open IKE_SAs that activate the cookie mechanism. # cookie_threshold = 10 # Delete CHILD_SAs right after they got successfully rekeyed (IKEv1 only). # delete_rekeyed = no # Delay in seconds until inbound IPsec SAs are deleted after rekeyings # (IKEv2 only). # delete_rekeyed_delay = 5 # Use ANSI X9.42 DH exponent size or optimum size matched to cryptographic # strength. # dh_exponent_ansi_x9_42 = yes # Use RTLD_NOW with dlopen when loading plugins and IMV/IMCs to reveal # missing symbols immediately. # dlopen_use_rtld_now = no # DNS server assigned to peer via configuration payload (CP). # dns1 = # DNS server assigned to peer via configuration payload (CP). # dns2 = # Enable Denial of Service protection using cookies and aggressiveness # checks. # dos_protection = yes # Compliance with the errata for RFC 4753. # ecp_x_coordinate_only = yes # Free objects during authentication (might conflict with plugins). # flush_auth_cfg = no # Whether to follow IKEv2 redirects (RFC 5685). # follow_redirects = yes # Maximum size (complete IP datagram size in bytes) of a sent IKE fragment # when using proprietary IKEv1 or standardized IKEv2 fragmentation, defaults # to 1280 (use 0 for address family specific default values, which uses a # lower value for IPv4). If specified this limit is used for both IPv4 and # IPv6. # fragment_size = 1280 # Name of the group the daemon changes to after startup. # group = # Timeout in seconds for connecting IKE_SAs (also see IKE_SA_INIT DROPPING). half_open_timeout = 5 # Enable hash and URL support. # hash_and_url = no # Allow IKEv1 Aggressive Mode with pre-shared keys as responder. # i_dont_care_about_security_and_use_aggressive_mode_psk = no # Whether to ignore the traffic selectors from the kernel's acquire events # for IKEv2 connections (they are not used for IKEv1). # ignore_acquire_ts = no # A space-separated list of routing tables to be excluded from route # lookups. # ignore_routing_tables = # Maximum number of IKE_SAs that can be established at the same time before # new connection attempts are blocked. # ikesa_limit = 0 # Number of exclusively locked segments in the hash table. # ikesa_table_segments = 1 # Size of the IKE_SA hash table. # ikesa_table_size = 1 # Whether to close IKE_SA if the only CHILD_SA closed due to inactivity. inactivity_close_ike = yes # Limit new connections based on the current number of half open IKE_SAs, # see IKE_SA_INIT DROPPING in strongswan.conf(5). # init_limit_half_open = 0 # Limit new connections based on the number of queued jobs. # init_limit_job_load = 0 # Causes charon daemon to ignore IKE initiation requests. # initiator_only = no # Install routes into a separate routing table for established IPsec # tunnels. # install_routes = yes # Install virtual IP addresses. # install_virtual_ip = yes # The name of the interface on which virtual IP addresses should be # installed. # install_virtual_ip_on = # Check daemon, libstrongswan and plugin integrity at startup. # integrity_test = no # A comma-separated list of network interfaces that should be ignored, if # interfaces_use is specified this option has no effect. # interfaces_ignore = # A comma-separated list of network interfaces that should be used by # charon. All other interfaces are ignored. # interfaces_use = # NAT keep alive interval. keep_alive = 25s # Plugins to load in the IKE daemon charon. # load = # Determine plugins to load via each plugin's load option. # load_modular = no # Initiate IKEv2 reauthentication with a make-before-break scheme. # make_before_break = no # Maximum number of IKEv1 phase 2 exchanges per IKE_SA to keep state about # and track concurrently. # max_ikev1_exchanges = 3 # Maximum packet size accepted by charon. # max_packet = 10000 # Enable multiple authentication exchanges (RFC 4739). # multiple_authentication = yes # WINS servers assigned to peer via configuration payload (CP). # nbns1 = # WINS servers assigned to peer via configuration payload (CP). # nbns2 = # UDP port used locally. If set to 0 a random port will be allocated. # port = 500 # UDP port used locally in case of NAT-T. If set to 0 a random port will be # allocated. Has to be different from charon.port, otherwise a random port # will be allocated. # port_nat_t = 4500 # Whether to prefer updating SAs to the path with the best route. # prefer_best_path = no # Prefer locally configured proposals for IKE/IPsec over supplied ones as # responder (disabling this can avoid keying retries due to # INVALID_KE_PAYLOAD notifies). # prefer_configured_proposals = yes # By default public IPv6 addresses are preferred over temporary ones (RFC # 4941), to make connections more stable. Enable this option to reverse # this. # prefer_temporary_addrs = no # Process RTM_NEWROUTE and RTM_DELROUTE events. # process_route = yes # Delay in ms for receiving packets, to simulate larger RTT. # receive_delay = 0 # Delay request messages. # receive_delay_request = yes # Delay response messages. # receive_delay_response = yes # Specific IKEv2 message type to delay, 0 for any. # receive_delay_type = 0 # Size of the AH/ESP replay window, in packets. # replay_window = 32 # Base to use for calculating exponential back off, see IKEv2 RETRANSMISSION # in strongswan.conf(5). # retransmit_base = 1.8 # Maximum jitter in percent to apply randomly to calculated retransmission # timeout (0 to disable). # retransmit_jitter = 0 # Upper limit in seconds for calculated retransmission timeout (0 to # disable). # retransmit_limit = 0 # Timeout in seconds before sending first retransmit. # retransmit_timeout = 4.0 # Number of times to retransmit a packet before giving up. # retransmit_tries = 5 # Interval in seconds to use when retrying to initiate an IKE_SA (e.g. if # DNS resolution failed), 0 to disable retries. # retry_initiate_interval = 0 # Initiate CHILD_SA within existing IKE_SAs (always enabled for IKEv1). reuse_ikesa = yes # Numerical routing table to install routes to. # routing_table = # Priority of the routing table. # routing_table_prio = # Whether to use RSA with PSS padding instead of PKCS#1 padding by default. # rsa_pss = no # Delay in ms for sending packets, to simulate larger RTT. # send_delay = 0 # Delay request messages. # send_delay_request = yes # Delay response messages. # send_delay_response = yes # Specific IKEv2 message type to delay, 0 for any. # send_delay_type = 0 # Send strongSwan vendor ID payload # send_vendor_id = no # Whether to enable Signature Authentication as per RFC 7427. # signature_authentication = yes # Whether to enable constraints against IKEv2 signature schemes. # signature_authentication_constraints = yes # The upper limit for SPIs requested from the kernel for IPsec SAs. # spi_max = 0xcfffffff # The lower limit for SPIs requested from the kernel for IPsec SAs. # spi_min = 0xc0000000 # Number of worker threads in charon. # threads = 16 # Name of the user the daemon changes to after startup. # user = crypto_test { # Benchmark crypto algorithms and order them by efficiency. # bench = no # Buffer size used for crypto benchmark. # bench_size = 1024 # Number of iterations to test each algorithm. # bench_time = 50 # Test crypto algorithms during registration (requires test vectors # provided by the test-vectors plugin). # on_add = no # Test crypto algorithms on each crypto primitive instantiation. # on_create = no # Strictly require at least one test vector to enable an algorithm. # required = no # Whether to test RNG with TRUE quality; requires a lot of entropy. # rng_true = no } host_resolver { # Maximum number of concurrent resolver threads (they are terminated if # unused). # max_threads = 3 # Minimum number of resolver threads to keep around. # min_threads = 0 } leak_detective { # Includes source file names and line numbers in leak detective output. # detailed = yes # Threshold in bytes for leaks to be reported (0 to report all). # usage_threshold = 10240 # Threshold in number of allocations for leaks to be reported (0 to # report all). # usage_threshold_count = 0 } processor { # Section to configure the number of reserved threads per priority class # see JOB PRIORITY MANAGEMENT in strongswan.conf(5). priority_threads { } } # Section containing a list of scripts (name = path) that are executed when # the daemon is started. start-scripts { } # Section containing a list of scripts (name = path) that are executed when # the daemon is terminated. stop-scripts { } tls { # List of TLS encryption ciphers. # cipher = # List of TLS key exchange methods. # key_exchange = # List of TLS MAC algorithms. # mac = # List of TLS cipher suites. # suites = } x509 { # Discard certificates with unsupported or unknown critical extensions. enforce_critical = no } } ================================================ FILE: roles/strongswan/templates/client_ipsec.conf.j2 ================================================ conn algovpn-{{ IP_subject_alt_name }} fragmentation=yes rekey=no dpdaction=clear keyexchange=ikev2 compress=no dpddelay=35s ike={{ ciphers.defaults.ike }} esp={{ ciphers.defaults.esp }} right={{ IP_subject_alt_name }} rightid={{ IP_subject_alt_name }} rightsubnet={{ rightsubnet | default('0.0.0.0/0') }} rightauth=pubkey leftsourceip=%config leftauth=pubkey leftcert={{ item }}.crt leftfirewall=yes left=%defaultroute auto=add ================================================ FILE: roles/strongswan/templates/client_ipsec.secrets.j2 ================================================ {{ IP_subject_alt_name }} : ECDSA {{ item }}.key ================================================ FILE: roles/strongswan/templates/ipsec.conf.j2 ================================================ config setup uniqueids=never # allow multiple connections per user charondebug="ike {{ strongswan_log_level }}, knl {{ strongswan_log_level }}, cfg {{ strongswan_log_level }}, net {{ strongswan_log_level }}, esp {{ strongswan_log_level }}, dmn {{ strongswan_log_level }}, mgr {{ strongswan_log_level }}" conn %default fragmentation=yes rekey=no dpdaction=clear keyexchange=ikev2 compress=yes dpddelay=35s lifetime=3h ikelifetime=12h ike={{ ciphers.defaults.ike }} esp={{ ciphers.defaults.esp }} left=%any leftauth=pubkey leftid={{ IP_subject_alt_name }} leftcert={{ IP_subject_alt_name }}.crt leftsendcert=always leftsubnet=0.0.0.0/0,::/0 right=%any rightauth=pubkey rightsourceip={{ strongswan_network }},{{ strongswan_network_ipv6 }} {% if algo_dns_adblocking | bool or dns_encryption | bool %} rightdns={{ local_service_ip }}{{ ',' + local_service_ipv6 if ipv6_support | bool else '' }} {% else %} rightdns={% for host in dns_servers.ipv4 %}{{ host }}{% if not loop.last %},{% endif %}{% endfor %}{% if ipv6_support | bool %},{% for host in dns_servers.ipv6 %}{{ host }}{% if not loop.last %},{% endif %}{% endfor %}{% endif %} {% endif %} conn ikev2-pubkey auto=add ================================================ FILE: roles/strongswan/templates/ipsec.secrets.j2 ================================================ : ECDSA {{ IP_subject_alt_name }}.key ================================================ FILE: roles/strongswan/templates/mobileconfig.j2 ================================================ #jinja2:lstrip_blocks: True PayloadContent IKEv2 OnDemandEnabled {{ 1 if algo_ondemand_wifi or algo_ondemand_cellular else 0 }} OnDemandRules {% if algo_ondemand_wifi or algo_ondemand_cellular %} {% if algo_ondemand_wifi_exclude | b64decode != '_null' %} {% set WIFI_EXCLUDE_LIST = (algo_ondemand_wifi_exclude | b64decode | string).split(',') %} Action Disconnect InterfaceTypeMatch WiFi SSIDMatch {% for network_name in WIFI_EXCLUDE_LIST %} {{ network_name | e }} {% endfor %} {% endif %} Action {% if algo_ondemand_wifi %} Connect {% else %} Disconnect {% endif %} InterfaceTypeMatch WiFi URLStringProbe http://captive.apple.com/hotspot-detect.html Action {% if algo_ondemand_cellular %} Connect {% else %} Disconnect {% endif %} InterfaceTypeMatch Cellular URLStringProbe http://captive.apple.com/hotspot-detect.html {% endif %} Action {{ 'Disconnect' if algo_ondemand_wifi or algo_ondemand_cellular else 'Connect' }} AuthenticationMethod Certificate ChildSecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 DeadPeerDetectionRate Medium DisableMOBIKE 0 DisableRedirect 1 EnableCertificateRevocationCheck 0 EnablePFS IKESecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 LocalIdentifier {{ item.0 }}@{{ openssl_constraint_random_id }} PayloadCertificateUUID {{ pkcs12_PayloadCertificateUUID }} CertificateType ECDSA384 ServerCertificateIssuerCommonName {{ IP_subject_alt_name }} ServerCertificateCommonName {{ IP_subject_alt_name }} RemoteAddress {{ IP_subject_alt_name }} RemoteIdentifier {{ IP_subject_alt_name }} UseConfigurationAttributeInternalIPSubnet 0 IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName {{ algo_server_name }} PayloadIdentifier com.apple.vpn.managed.{{ VPN_PayloadIdentifier }} PayloadType com.apple.vpn.managed PayloadUUID {{ VPN_PayloadIdentifier }} PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN {{ algo_server_name }} IKEv2 VPNType IKEv2 Password {{ p12_export_password }} PayloadCertificateFileName {{ item.0 }}.p12 PayloadContent {{ item.1.stdout }} PayloadDescription Adds a PKCS#12-formatted certificate PayloadDisplayName {{ algo_server_name }} PayloadIdentifier com.apple.security.pkcs12.{{ pkcs12_PayloadCertificateUUID }} PayloadType com.apple.security.pkcs12 PayloadUUID {{ pkcs12_PayloadCertificateUUID }} PayloadVersion 1 PayloadCertificateFileName ca.crt PayloadContent {{ PayloadContentCA }} PayloadDescription Adds a CA root certificate PayloadDisplayName {{ algo_server_name }} PayloadIdentifier com.apple.security.root.{{ CA_PayloadIdentifier }} PayloadType com.apple.security.root PayloadUUID {{ CA_PayloadIdentifier }} PayloadVersion 1 PayloadDisplayName AlgoVPN {{ algo_server_name }} IKEv2 PayloadIdentifier donut.local.{{ 500000 | random | to_uuid | upper }} PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID {{ 400000 | random | to_uuid | upper }} PayloadVersion 1 ================================================ FILE: roles/strongswan/templates/strongswan.conf.j2 ================================================ # strongswan.conf - strongSwan configuration file # # Refer to the strongswan.conf(5) manpage for details # # Configuration changes should be made in the included files charon { load_modular = yes plugins { include strongswan.d/charon/*.conf } user = strongswan group = nogroup } include strongswan.d/*.conf ================================================ FILE: roles/wireguard/defaults/main.yml ================================================ --- wireguard_PersistentKeepalive: 0 wireguard_config_path: configs/{{ IP_subject_alt_name }}/wireguard wireguard_pki_path: "{{ wireguard_config_path }}/.pki" wireguard_interface: wg0 wireguard_port_avoid: 53 wireguard_port_actual: 51820 keys_clean_all: false wireguard_dns_servers: >- {%- if algo_dns_adblocking | default(false) | bool or dns_encryption | default(false) | bool -%} {{ local_service_ip }}{{ ', ' + local_service_ipv6 if ipv6_support | bool else '' }}{%- else -%} {%- for host in dns_servers.ipv4 -%}{{ host }}{% if not loop.last %},{% endif %}{%- endfor -%} {%- if ipv6_support | bool -%},{%- for host in dns_servers.ipv6 -%}{{ host }}{% if not loop.last %},{% endif %}{%- endfor -%} {%- endif -%} {%- endif -%} wireguard_client_ip: >- {{ wireguard_network_ipv4 | ansible.utils.ipmath(index | int + 2) }} {{ ',' + wireguard_network_ipv6 | ansible.utils.ipmath(index | int + 2) if ipv6_support | bool else '' }} wireguard_server_ip: >- {{ wireguard_network_ipv4 | ansible.utils.ipaddr('1') }} {{ ',' + wireguard_network_ipv6 | ansible.utils.ipaddr('1') if ipv6_support | bool else '' }} ================================================ FILE: roles/wireguard/files/wireguard.sh ================================================ #!/bin/sh # PROVIDE: wireguard # REQUIRE: LOGIN # BEFORE: securelevel # KEYWORD: shutdown # shellcheck source=/dev/null . /etc/rc.subr name="wg" # shellcheck disable=SC2034 rcvar=wg_enable command="/usr/local/bin/wg-quick" # shellcheck disable=SC2034 start_cmd=wg_up # shellcheck disable=SC2034 stop_cmd=wg_down # shellcheck disable=SC2034 status_cmd=wg_status pidfile="/var/run/$name.pid" load_rc_config "$name" : "${wg_enable=NO}" : "${wg_interface=wg0}" wg_up() { echo "Starting WireGuard..." /usr/sbin/daemon -cS -p "${pidfile}" "${command}" up "${wg_interface}" } wg_down() { echo "Stopping WireGuard..." "${command}" down "${wg_interface}" } wg_status () { not_running () { echo "WireGuard is not running on $wg_interface" && exit 1 } if /usr/local/bin/wg show wg0; then echo "WireGuard is running on $wg_interface" else not_running fi } run_rc_command "$1" ================================================ FILE: roles/wireguard/handlers/main.yml ================================================ --- - name: daemon-reload systemd: daemon_reload: true - name: restart wireguard service: name: "{{ service_name }}" state: restarted ================================================ FILE: roles/wireguard/tasks/keys.yml ================================================ --- - name: Ensure the WireGuard pki directory does not exist file: dest: "{{ wireguard_pki_path }}" state: absent when: keys_clean_all | bool - name: Ensure the WireGuard pki directories exist file: dest: "{{ wireguard_pki_path }}/{{ item }}" state: directory recurse: true mode: "0700" loop: - preshared - private - public - name: Generate raw private keys community.crypto.openssl_privatekey: type: X25519 path: "{{ wireguard_pki_path }}/private/{{ item }}.raw" format: raw mode: "0600" loop: "{{ users + [IP_subject_alt_name] }}" - name: Save base64 encoded private key copy: dest: "{{ wireguard_pki_path }}/private/{{ item }}" content: "{{ lookup('file', wireguard_pki_path + '/private/' + item + '.raw') | b64encode }}" mode: "0600" loop: "{{ users + [IP_subject_alt_name] }}" no_log: true - name: Generate raw preshared keys community.crypto.openssl_privatekey: type: X25519 path: "{{ wireguard_pki_path }}/preshared/{{ item }}.raw" format: raw mode: "0600" loop: "{{ users + [IP_subject_alt_name] }}" - name: Save base64 encoded preshared keys copy: dest: "{{ wireguard_pki_path }}/preshared/{{ item }}" content: "{{ lookup('file', wireguard_pki_path + '/preshared/' + item + '.raw') | b64encode }}" mode: "0600" loop: "{{ users + [IP_subject_alt_name] }}" no_log: true - name: Generate public keys x25519_pubkey: private_key_path: "{{ wireguard_pki_path }}/private/{{ item }}.raw" public_key_path: "{{ wireguard_pki_path }}/public/{{ item }}" loop: "{{ users + [IP_subject_alt_name] }}" no_log: true - name: Set permissions for public keys file: path: "{{ wireguard_pki_path }}/public/{{ item }}" mode: '0644' loop: "{{ users + [IP_subject_alt_name] }}" no_log: true ================================================ FILE: roles/wireguard/tasks/main.yml ================================================ --- - name: Ensure the required config directories exist file: dest: "{{ item }}" state: directory recurse: true mode: "0755" loop: - "{{ wireguard_config_path }}/apple/ios" - "{{ wireguard_config_path }}/apple/macos" delegate_to: localhost become: false - name: Include tasks for Debian/Ubuntu include_tasks: ubuntu.yml when: is_debian_based | bool tags: always - name: Generate keys import_tasks: keys.yml delegate_to: localhost become: false tags: update-users - tags: update-users block: - become: false delegate_to: localhost block: - name: WireGuard user list updated lineinfile: dest: "{{ wireguard_pki_path }}/index.txt" create: true mode: "0600" insertafter: EOF line: "{{ item }}" register: lineinfile loop: "{{ users }}" - set_fact: wireguard_users: "{{ (lookup('file', wireguard_pki_path + '/index.txt')).split('\n') }}" - name: WireGuard users config generated template: src: client.conf.j2 dest: "{{ wireguard_config_path }}/{{ item }}.conf" mode: "0600" loop: "{{ wireguard_users }}" loop_control: index_var: index when: item in users - include_tasks: mobileconfig.yml loop: - ios - macos loop_control: loop_var: system - name: Generate QR codes shell: > umask 077; which segno && segno --scale=5 --output={{ item }}.png \ "{{ lookup('template', 'client.conf.j2') }}" || true changed_when: false loop: "{{ wireguard_users }}" loop_control: index_var: index when: item in users vars: ansible_python_interpreter: "{{ ansible_playbook_python }}" args: chdir: "{{ wireguard_config_path }}" executable: bash no_log: true - name: WireGuard configured template: src: server.conf.j2 dest: "{{ config_prefix | default('/') }}etc/wireguard/{{ wireguard_interface }}.conf" mode: "0600" notify: restart wireguard - name: WireGuard enabled and started service: name: "{{ service_name }}" state: started enabled: true - name: Delete the PKI directory file: path: "{{ wireguard_pki_path }}" state: absent become: false delegate_to: localhost when: - not algo_store_pki - not pki_in_tmpfs - meta: flush_handlers ================================================ FILE: roles/wireguard/tasks/mobileconfig.yml ================================================ --- - name: WireGuard apple mobileconfig generated template: src: mobileconfig.j2 dest: "{{ wireguard_config_path }}/apple/{{ system }}/{{ item }}.mobileconfig" mode: "0600" loop: "{{ wireguard_users }}" loop_control: index_var: index when: item in users ================================================ FILE: roles/wireguard/tasks/ubuntu.yml ================================================ --- - name: WireGuard installed (individual) apt: name: wireguard state: present update_cache: true when: not performance_parallel_packages | default(true) - name: Set OS specific facts set_fact: service_name: wg-quick@{{ wireguard_interface }} tags: always - name: Ubuntu | Ensure that the WireGuard service directory exists file: path: /etc/systemd/system/wg-quick@{{ wireguard_interface }}.service.d/ state: directory mode: '0755' owner: root group: root - name: Ubuntu | Apply systemd security hardening for WireGuard copy: dest: /etc/systemd/system/wg-quick@{{ wireguard_interface }}.service.d/90-security-hardening.conf content: | # Algo VPN systemd security hardening for WireGuard [Service] # Privilege restrictions NoNewPrivileges=yes # Filesystem isolation ProtectSystem=strict ProtectHome=yes PrivateTmp=yes ProtectKernelTunables=yes ProtectControlGroups=yes # Network restrictions - WireGuard needs NETLINK for interface management RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK # Allow access to WireGuard configuration ReadWritePaths=/etc/wireguard ReadOnlyPaths=/etc/resolv.conf # System call filtering - allow network and system service calls SystemCallFilter=@system-service @network-io SystemCallFilter=~@debug @mount @swap @reboot @raw-io SystemCallErrorNumber=EPERM owner: root group: root mode: '0644' notify: - daemon-reload - restart wireguard ================================================ FILE: roles/wireguard/templates/client.conf.j2 ================================================ [Interface] PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + item) }} Address = {{ wireguard_client_ip }} DNS = {{ wireguard_dns_servers }} {% if reduce_mtu | int > 0 %}MTU = {{ 1420 - reduce_mtu | int }} {% endif %} [Peer] PublicKey = {{ lookup('file', wireguard_pki_path + '/public/' + IP_subject_alt_name) }} PresharedKey = {{ lookup('file', wireguard_pki_path + '/preshared/' + item) }} AllowedIPs = 0.0.0.0/0,::/0 Endpoint = {% if ':' in IP_subject_alt_name %}[{{ IP_subject_alt_name }}]:{{ wireguard_port }}{% else %}{{ IP_subject_alt_name }}:{{ wireguard_port }}{% endif %} {{ 'PersistentKeepalive = ' + wireguard_PersistentKeepalive | string if wireguard_PersistentKeepalive > 0 else '' }} ================================================ FILE: roles/wireguard/templates/mobileconfig.j2 ================================================ #jinja2:lstrip_blocks: True PayloadContent {% include 'vpn-dict.j2' %} PayloadDisplayName AlgoVPN {{ algo_server_name }} WireGuard PayloadIdentifier donut.local.{{ 500000 | random | to_uuid | upper }} PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID {{ 400000 | random | to_uuid | upper }} PayloadVersion 1 ================================================ FILE: roles/wireguard/templates/server.conf.j2 ================================================ [Interface] Address = {{ wireguard_server_ip }} ListenPort = {{ wireguard_port_actual if wireguard_port | int == wireguard_port_avoid | int else wireguard_port }} PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + IP_subject_alt_name) }} SaveConfig = false {% for u in wireguard_users %} {% if u in users %} {% set index = loop.index %} [Peer] # {{ u }} PublicKey = {{ lookup('file', wireguard_pki_path + '/public/' + u) }} PresharedKey = {{ lookup('file', wireguard_pki_path + '/preshared/' + u) }} AllowedIPs = {{ wireguard_network_ipv4 | ansible.utils.ipmath(index | int + 1) | ansible.utils.ipv4('address') }}/32{{ ',' + wireguard_network_ipv6 | ansible.utils.ipmath(index | int + 1) | ansible.utils.ipv6('address') + '/128' if ipv6_support | bool else '' }} {% endif %} {% endfor %} ================================================ FILE: roles/wireguard/templates/vpn-dict.j2 ================================================ IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName {{ algo_server_name }} PayloadIdentifier com.apple.vpn.managed.{{ algo_server_name + system | to_uuid | upper }} PayloadType com.apple.vpn.managed PayloadUUID {{ algo_server_name + system | to_uuid | upper }} PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN {{ algo_server_name }} VPN OnDemandEnabled {{ 1 if algo_ondemand_wifi or algo_ondemand_cellular else 0 }} OnDemandRules {% if algo_ondemand_wifi or algo_ondemand_cellular %} {% if algo_ondemand_wifi_exclude | b64decode != '_null' %} {% set WIFI_EXCLUDE_LIST = (algo_ondemand_wifi_exclude | b64decode | string).split(',') %} Action Disconnect InterfaceTypeMatch WiFi SSIDMatch {% for network_name in WIFI_EXCLUDE_LIST %} {{ network_name | e }} {% endfor %} {% endif %} Action {% if algo_ondemand_wifi %} Connect {% else %} Disconnect {% endif %} InterfaceTypeMatch WiFi URLStringProbe http://captive.apple.com/hotspot-detect.html Action {% if algo_ondemand_cellular %} Connect {% else %} Disconnect {% endif %} InterfaceTypeMatch Cellular URLStringProbe http://captive.apple.com/hotspot-detect.html {% endif %} Action {{ 'Disconnect' if algo_ondemand_wifi or algo_ondemand_cellular else 'Connect' }} AuthenticationMethod Password RemoteAddress {{ IP_subject_alt_name }}:{{ wireguard_port }} VPNSubType com.wireguard.{{ system }} VPNType VPN VendorConfig WgQuickConfig {{- lookup('template', 'client.conf.j2') | indent(8) }} ================================================ FILE: scripts/annotate-test-failure.sh ================================================ #!/bin/bash # Annotate test failures with metadata for tracking # This script should be called when a test fails in CI # Usage: ./annotate-test-failure.sh TEST_NAME="$1" CONTEXT="$2" TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # Create failures log if it doesn't exist mkdir -p .metrics FAILURE_LOG=".metrics/test-failures.jsonl" # Add failure record cat >> "$FAILURE_LOG" << EOF {"test": "$TEST_NAME", "context": "$CONTEXT", "timestamp": "$TIMESTAMP", "commit": "$GITHUB_SHA", "pr": "$GITHUB_PR_NUMBER", "branch": "$GITHUB_REF_NAME"} EOF # Also add as GitHub annotation if in CI if [ -n "$GITHUB_ACTIONS" ]; then echo "::warning title=Test Failure::$TEST_NAME failed in $CONTEXT" fi ================================================ FILE: scripts/lint.sh ================================================ #!/bin/bash set -euo pipefail # Run the same linting as CI echo "Running ansible-lint..." ansible-lint . echo "Running playbook dry-run check..." # Test main playbook logic without making changes - catches runtime issues ansible-playbook main.yml --check --connection=local \ -e "server_ip=test" \ -e "server_name=ci-test" \ -e "IP_subject_alt_name=192.168.1.1" \ || echo "Dry-run completed with issues - check output above" echo "Running yamllint..." yamllint -c .yamllint . echo "Running ruff..." ruff check . || true # Start with warnings only echo "Running shellcheck..." find . -type f -name "*.sh" -not -path "./.git/*" -exec shellcheck {} \; echo "All linting completed!" ================================================ FILE: scripts/list_servers.py ================================================ #!/usr/bin/env python3 """List deployed Algo VPN servers as JSON.""" import json import sys from pathlib import Path import yaml def list_servers(configs_dir: Path) -> list[dict]: """Scan configs directory for deployed server metadata.""" servers = [] for config_file in sorted(configs_dir.glob("*/.config.yml")): with open(config_file) as f: config = yaml.safe_load(f) if config: servers.append(config) return servers def main() -> None: configs_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("configs") if not configs_dir.is_dir(): json.dump([], sys.stdout) print() sys.exit(0) servers = list_servers(configs_dir) json.dump(servers, sys.stdout, indent=2, default=str) print() if __name__ == "__main__": main() ================================================ FILE: scripts/test-templates.sh ================================================ #!/bin/bash # Test all Jinja2 templates in the Algo codebase # This script is called by CI and can be run locally set -e echo "======================================" echo "Running Jinja2 Template Tests" echo "======================================" echo "" # Color codes for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color FAILED=0 # 1. Run the template syntax validator echo "1. Validating Jinja2 template syntax..." echo "----------------------------------------" if python tests/validate_jinja2_templates.py; then echo -e "${GREEN}✓ Template syntax validation passed${NC}" else echo -e "${RED}✗ Template syntax validation failed${NC}" FAILED=$((FAILED + 1)) fi echo "" # 2. Run the template rendering tests echo "2. Testing template rendering..." echo "--------------------------------" if python tests/unit/test_template_rendering.py; then echo -e "${GREEN}✓ Template rendering tests passed${NC}" else echo -e "${RED}✗ Template rendering tests failed${NC}" FAILED=$((FAILED + 1)) fi echo "" # 3. Run the StrongSwan template tests echo "3. Testing StrongSwan templates..." echo "----------------------------------" if python tests/unit/test_strongswan_templates.py; then echo -e "${GREEN}✓ StrongSwan template tests passed${NC}" else echo -e "${RED}✗ StrongSwan template tests failed${NC}" FAILED=$((FAILED + 1)) fi echo "" # 4. Run ansible-lint with Jinja2 checks enabled echo "4. Running ansible-lint Jinja2 checks..." echo "----------------------------------------" # Check only for jinja[invalid] errors, not spacing warnings if ansible-lint --nocolor 2>&1 | grep -E "jinja\[invalid\]"; then echo -e "${RED}✗ ansible-lint found Jinja2 syntax errors${NC}" ansible-lint --nocolor 2>&1 | grep -E "jinja\[invalid\]" | head -10 FAILED=$((FAILED + 1)) else echo -e "${GREEN}✓ No Jinja2 syntax errors found${NC}" # Show spacing warnings as info only if ansible-lint --nocolor 2>&1 | grep -E "jinja\[spacing\]" | head -1 > /dev/null; then echo -e "${YELLOW}ℹ Note: Some spacing style issues exist (not failures)${NC}" fi fi echo "" # Summary echo "======================================" if [ $FAILED -eq 0 ]; then echo -e "${GREEN}All template tests passed!${NC}" exit 0 else echo -e "${RED}$FAILED test suite(s) failed${NC}" echo "" echo "To debug failures, run individually:" echo " python tests/validate_jinja2_templates.py" echo " python tests/unit/test_template_rendering.py" echo " python tests/unit/test_strongswan_templates.py" echo " ansible-lint" exit 1 fi ================================================ FILE: scripts/track-test-effectiveness.py ================================================ #!/usr/bin/env python3 """ Track test effectiveness by analyzing CI failures and correlating with issues/PRs This helps identify which tests actually catch bugs vs just failing randomly """ import json import subprocess from collections import defaultdict from datetime import datetime, timedelta from pathlib import Path def get_github_api_data(endpoint): """Fetch data from GitHub API""" cmd = ["gh", "api", endpoint] result = subprocess.run(cmd, capture_output=True, text=True) if result.returncode != 0: print(f"Error fetching {endpoint}: {result.stderr}") return None return json.loads(result.stdout) def analyze_workflow_runs(repo_owner, repo_name, days_back=30): """Analyze workflow runs to find test failures""" since = (datetime.now() - timedelta(days=days_back)).isoformat() # Get workflow runs runs = get_github_api_data(f"/repos/{repo_owner}/{repo_name}/actions/runs?created=>{since}&status=failure") if not runs: return {} test_failures = defaultdict(list) for run in runs.get("workflow_runs", []): # Get jobs for this run jobs = get_github_api_data(f"/repos/{repo_owner}/{repo_name}/actions/runs/{run['id']}/jobs") if not jobs: continue for job in jobs.get("jobs", []): if job["conclusion"] == "failure": # Try to extract which test failed from logs logs_url = job.get("logs_url") if logs_url: # Parse logs to find test failures test_name = extract_failed_test(job["name"], run["id"]) if test_name: test_failures[test_name].append( { "run_id": run["id"], "run_number": run["run_number"], "date": run["created_at"], "branch": run["head_branch"], "commit": run["head_sha"][:7], "pr": extract_pr_number(run), } ) return test_failures def extract_failed_test(job_name, run_id): """Extract test name from job - this is simplified""" # Map job names to test categories job_to_tests = { "Basic sanity tests": "test_basic_sanity", "Ansible syntax check": "ansible_syntax", "Docker build test": "docker_tests", "Configuration generation test": "config_generation", "Ansible dry-run validation": "ansible_dry_run", } return job_to_tests.get(job_name, job_name) def extract_pr_number(run): """Extract PR number from workflow run""" for pr in run.get("pull_requests", []): return pr["number"] return None def correlate_with_issues(repo_owner, repo_name, test_failures): """Correlate test failures with issues/PRs that fixed them""" correlations = defaultdict(lambda: {"caught_bugs": 0, "false_positives": 0}) for test_name, failures in test_failures.items(): for failure in failures: if failure["pr"]: # Check if PR was merged (indicating it fixed a real issue) pr = get_github_api_data(f"/repos/{repo_owner}/{repo_name}/pulls/{failure['pr']}") if pr and pr.get("merged"): # Check PR title/body for bug indicators title = pr.get("title", "").lower() body = pr.get("body", "").lower() bug_keywords = ["fix", "bug", "error", "issue", "broken", "fail"] is_bug_fix = any(keyword in title or keyword in body for keyword in bug_keywords) if is_bug_fix: correlations[test_name]["caught_bugs"] += 1 else: correlations[test_name]["false_positives"] += 1 return correlations def generate_effectiveness_report(test_failures, correlations): """Generate test effectiveness report""" report = [] report.append("# Test Effectiveness Report") report.append(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") # Summary report.append("## Summary") total_failures = sum(len(f) for f in test_failures.values()) report.append(f"- Total test failures: {total_failures}") report.append(f"- Unique tests that failed: {len(test_failures)}") report.append("") # Effectiveness scores report.append("## Test Effectiveness Scores") report.append("| Test | Failures | Caught Bugs | False Positives | Effectiveness |") report.append("|------|----------|-------------|-----------------|---------------|") scores = [] for test_name, failures in test_failures.items(): failure_count = len(failures) caught = correlations[test_name]["caught_bugs"] false_pos = correlations[test_name]["false_positives"] # Calculate effectiveness (bugs caught / total failures) if failure_count > 0: effectiveness = caught / failure_count else: effectiveness = 0 scores.append((test_name, failure_count, caught, false_pos, effectiveness)) # Sort by effectiveness scores.sort(key=lambda x: x[4], reverse=True) for test_name, failures, caught, false_pos, effectiveness in scores: report.append(f"| {test_name} | {failures} | {caught} | {false_pos} | {effectiveness:.1%} |") # Recommendations report.append("\n## Recommendations") for test_name, failures, _caught, _false_pos, effectiveness in scores: if effectiveness < 0.2 and failures > 5: report.append(f"- ⚠️ Consider improving or removing `{test_name}` (only {effectiveness:.0%} effective)") elif effectiveness > 0.8: report.append(f"- ✅ `{test_name}` is highly effective ({effectiveness:.0%})") return "\n".join(report) def save_metrics(test_failures, correlations): """Save metrics to JSON for historical tracking""" metrics_file = Path(".metrics/test-effectiveness.json") metrics_file.parent.mkdir(exist_ok=True) # Load existing metrics if metrics_file.exists(): with open(metrics_file) as f: historical = json.load(f) else: historical = [] # Add current metrics current = { "date": datetime.now().isoformat(), "test_failures": {test: len(failures) for test, failures in test_failures.items()}, "effectiveness": { test: { "caught_bugs": data["caught_bugs"], "false_positives": data["false_positives"], "score": data["caught_bugs"] / (data["caught_bugs"] + data["false_positives"]) if (data["caught_bugs"] + data["false_positives"]) > 0 else 0, } for test, data in correlations.items() }, } historical.append(current) # Keep last 12 months of data cutoff = datetime.now() - timedelta(days=365) historical = [h for h in historical if datetime.fromisoformat(h["date"]) > cutoff] with open(metrics_file, "w") as f: json.dump(historical, f, indent=2) if __name__ == "__main__": # Configure these for your repo REPO_OWNER = "trailofbits" REPO_NAME = "algo" print("Analyzing test effectiveness...") # Analyze last 30 days of CI runs test_failures = analyze_workflow_runs(REPO_OWNER, REPO_NAME, days_back=30) # Correlate with issues/PRs correlations = correlate_with_issues(REPO_OWNER, REPO_NAME, test_failures) # Generate report report = generate_effectiveness_report(test_failures, correlations) print("\n" + report) # Save report report_file = Path(".metrics/test-effectiveness-report.md") report_file.parent.mkdir(exist_ok=True) with open(report_file, "w") as f: f.write(report) print(f"\nReport saved to: {report_file}") # Save metrics for tracking save_metrics(test_failures, correlations) print("Metrics saved to: .metrics/test-effectiveness.json") ================================================ FILE: server.yml ================================================ --- - name: Configure the server and install required software hosts: vpn-host gather_facts: false become: true vars_files: - config.cfg tasks: - block: - name: Wait until the cloud-init completed wait_for: path: /var/lib/cloud/data/result.json delay: 10 # Conservative 10 second initial delay timeout: 480 # Reduce from 600 to 480 seconds (8 minutes) sleep: 10 # Check every 10 seconds (less aggressive) state: present become: false when: cloudinit | bool - when: inventory_hostname != 'localhost' become: false delegate_to: localhost block: - name: Ensure the config directory exists file: dest: configs/{{ IP_subject_alt_name }} state: directory mode: "0700" - name: Dump the ssh config copy: dest: configs/{{ IP_subject_alt_name }}/ssh_config mode: "0600" content: | Host {{ IP_subject_alt_name }} {{ algo_server_name }} HostName {{ IP_subject_alt_name }} User {{ ansible_ssh_user }} Port {{ ansible_ssh_port }} IdentitiesOnly yes IdentityFile {{ SSH_keys.private | realpath }} KeepAlive yes ServerAliveInterval 30 - import_role: name: common tags: common # ============================================================ # VPN Service Configuration # Parallel mode (default): Services run concurrently for speed # Sequential mode: Services run one at a time (fallback) # ============================================================ - name: Configure VPN services (parallel mode) when: performance_parallel_services | default(true) tags: [dns, wireguard, ipsec, ssh_tunneling] block: # --- Launch all services asynchronously --- - import_role: {name: dns} async: 300 poll: 0 register: dns_job when: algo_dns_adblocking | bool or dns_encryption | bool tags: dns - import_role: {name: wireguard} async: 300 poll: 0 register: wireguard_job when: wireguard_enabled | bool tags: wireguard - import_role: {name: strongswan} async: 300 poll: 0 register: strongswan_job when: ipsec_enabled | bool tags: ipsec - import_role: {name: ssh_tunneling} async: 300 poll: 0 register: ssh_tunneling_job when: algo_ssh_tunneling | bool tags: ssh_tunneling # --- Build job list and wait for completion --- - name: Build async job list set_fact: _vpn_jobs: - {name: dns, job: "{{ dns_job | default({}) }}"} - {name: wireguard, job: "{{ wireguard_job | default({}) }}"} - {name: strongswan, job: "{{ strongswan_job | default({}) }}"} - {name: ssh_tunneling, job: "{{ ssh_tunneling_job | default({}) }}"} - name: Wait for VPN services to complete async_status: jid: "{{ item.job.ansible_job_id }}" register: _vpn_results until: _vpn_results.finished retries: 60 delay: 5 loop: "{{ _vpn_jobs | selectattr('job.ansible_job_id', 'defined') | list }}" loop_control: label: "{{ item.name }}" # --- Verify all services completed successfully --- - name: Check for service failures fail: msg: "{{ item.item.name }} service failed. Check logs above." when: item.rc | default(0) != 0 loop: "{{ _vpn_results.results | default([]) }}" loop_control: label: "{{ item.item.name | default('service') }}" # --- Sequential mode (fallback when parallel disabled) --- - name: Configure VPN services (sequential mode) when: not (performance_parallel_services | default(true)) tags: [dns, wireguard, ipsec, ssh_tunneling] block: - import_role: {name: dns} when: algo_dns_adblocking | bool or dns_encryption | bool tags: dns - import_role: {name: wireguard} when: wireguard_enabled | bool tags: wireguard - import_role: {name: strongswan} when: ipsec_enabled | bool tags: ipsec - import_role: {name: ssh_tunneling} when: algo_ssh_tunneling | bool tags: ssh_tunneling - import_role: name: privacy when: privacy_enhancements_enabled | default(true) tags: privacy - tags: always block: - name: Dump the configuration copy: dest: configs/{{ IP_subject_alt_name }}/.config.yml mode: '0644' content: | server: {{ 'localhost' if inventory_hostname == 'localhost' else inventory_hostname }} server_user: {{ ansible_ssh_user }} ansible_ssh_port: "{{ ansible_ssh_port | default(22) }}" {% if algo_provider != "local" %} ansible_ssh_private_key_file: {{ SSH_keys.private }} {% endif %} algo_provider: {{ algo_provider }} algo_server_name: {{ algo_server_name }} algo_region: {{ algo_region | default('') }} algo_ondemand_cellular: {{ algo_ondemand_cellular }} algo_ondemand_wifi: {{ algo_ondemand_wifi }} algo_ondemand_wifi_exclude: {{ algo_ondemand_wifi_exclude }} algo_dns_adblocking: {{ algo_dns_adblocking }} algo_ssh_tunneling: {{ algo_ssh_tunneling }} algo_store_pki: {{ algo_store_pki }} IP_subject_alt_name: {{ IP_subject_alt_name }} ipsec_enabled: {{ ipsec_enabled }} wireguard_enabled: {{ wireguard_enabled }} local_service_ip: {{ local_service_ip }} local_service_ipv6: {{ local_service_ipv6 }} {% if tests | default(false) | bool %} ca_password: '{{ CA_password }}' p12_password: '{{ p12_export_password }}' {% endif %} become: false delegate_to: localhost - name: Create a symlink if deploying to localhost file: src: "{{ IP_subject_alt_name }}" dest: configs/localhost state: link force: true when: inventory_hostname == 'localhost' - name: Import tmpfs tasks import_tasks: playbooks/tmpfs/umount.yml become: false delegate_to: localhost vars: facts: "{{ hostvars['localhost'] }}" when: - pki_in_tmpfs - not algo_store_pki - 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 '' }}" rescue: - include_tasks: playbooks/rescue.yml ================================================ FILE: tests/README.md ================================================ # Tests ## Running Tests ```bash # Run all linters (same as CI) ansible-lint . && yamllint . && ruff check . && shellcheck scripts/*.sh # Run Python unit tests pytest tests/unit/ -q # Run E2E connectivity tests (requires deployed Algo on localhost) sudo tests/e2e/test-vpn-connectivity.sh both ``` ## Directory Structure ``` tests/ ├── unit/ # Python unit tests (pytest) │ ├── test_basic_sanity.py │ ├── test_config_validation.py │ ├── test_template_rendering.py │ └── ... ├── e2e/ # End-to-end connectivity tests │ └── test-vpn-connectivity.sh ├── integration/ # Integration test helpers │ └── mock_modules/ ├── fixtures/ # Shared test data │ └── test_variables.yml └── conftest.py # Pytest configuration ``` ## Test Coverage | Category | Tests | What's Verified | |----------|-------|-----------------| | Sanity | `test_basic_sanity.py` | Python version, config syntax, playbook validity | | Config | `test_config_validation.py` | WireGuard/IPsec config formats, key validation | | Templates | `test_template_rendering.py` | Jinja2 template syntax, filter compatibility | | Certificates | `test_certificate_validation.py` | OpenSSL compatibility, PKCS#12 export | | Cloud Providers | `test_cloud_provider_configs.py` | Region formats, instance types, OS images | | E2E | `test-vpn-connectivity.sh` | WireGuard handshake, IPsec connection, DNS through VPN | ## CI Workflows | Workflow | Trigger | What It Does | |----------|---------|--------------| | `lint.yml` | All PRs | ansible-lint, yamllint, ruff, shellcheck | | `main.yml` | Push to master | Syntax check, unit tests, Docker build | | `integration-tests.yml` | PRs to roles/ | Full localhost deployment + E2E tests | | `smart-tests.yml` | All PRs | Runs subset based on changed files | ## Writing Tests ### Python Unit Tests Place in `tests/unit/`. Use fixtures from `conftest.py`: ```python def test_something(mock_ansible_module, jinja_env): # mock_ansible_module - mocked AnsibleModule # jinja_env - Jinja2 environment with Ansible filters pass ``` ### Shell Scripts Use bash strict mode and pass shellcheck: ```bash #!/bin/bash set -euo pipefail ``` ## Troubleshooting **E2E tests fail with "namespace already exists"** ```bash sudo ip netns del algo-client ``` **Template tests fail with "filter not found"** Add the filter to the mock in `conftest.py`. **CI fails but local passes** Check Python/Ansible versions match CI (Python 3.11, Ansible 12+). ================================================ FILE: tests/conftest.py ================================================ """Shared pytest fixtures for Algo VPN tests.""" import base64 import secrets import sys import tempfile from pathlib import Path import pytest import yaml # Add library directory to path for custom module imports sys.path.insert(0, str(Path(__file__).parent.parent / "library")) @pytest.fixture def test_variables(): """Load test variables from YAML fixture.""" fixture_path = Path(__file__).parent / "fixtures" / "test_variables.yml" with open(fixture_path) as f: return yaml.safe_load(f) @pytest.fixture def test_config(test_variables): """Get test configuration with common defaults.""" return test_variables.copy() @pytest.fixture def temp_directory(): """Create a temporary directory for test files.""" with tempfile.TemporaryDirectory() as tmpdir: yield Path(tmpdir) @pytest.fixture def wireguard_private_key(): """Generate a random WireGuard-compatible private key.""" raw_key = secrets.token_bytes(32) return base64.b64encode(raw_key).decode() @pytest.fixture def wireguard_key_pair(temp_directory): """Generate a WireGuard key pair and return paths and values.""" raw_key = secrets.token_bytes(32) b64_key = base64.b64encode(raw_key).decode() private_key_path = temp_directory / "private.key" private_key_path.write_bytes(raw_key) return { "private_key_raw": raw_key, "private_key_b64": b64_key, "private_key_path": str(private_key_path), } class MockAnsibleModule: """Mock AnsibleModule for testing custom Ansible modules.""" def __init__(self, params): """Initialize with module parameters.""" self.params = params self.result = {} self.failed = False self.fail_msg = None def fail_json(self, **kwargs): """Record failure and raise exception.""" self.failed = True self.fail_msg = kwargs.get("msg", "Unknown error") raise Exception(f"Module failed: {self.fail_msg}") def exit_json(self, **kwargs): """Record successful result.""" self.result = kwargs @pytest.fixture def mock_ansible_module(): """Fixture providing MockAnsibleModule class.""" return MockAnsibleModule # Jinja2 mock filters for template testing def mock_to_uuid(value): """Mock the to_uuid filter.""" return "12345678-1234-5678-1234-567812345678" def mock_bool(value): """Mock the bool filter.""" return str(value).lower() in ("true", "1", "yes", "on") def mock_lookup(lookup_type, path): """Mock the lookup function.""" if lookup_type == "file": if "private" in path: return "MOCK_PRIVATE_KEY_BASE64==" elif "public" in path: return "MOCK_PUBLIC_KEY_BASE64==" elif "preshared" in path: return "MOCK_PRESHARED_KEY_BASE64==" return "MOCK_LOOKUP_DATA" @pytest.fixture def jinja2_env(): """Create a Jinja2 environment with mock Ansible filters.""" from jinja2 import Environment, FileSystemLoader, StrictUndefined def create_env(template_dir): env = Environment(loader=FileSystemLoader(template_dir), undefined=StrictUndefined) env.globals["lookup"] = mock_lookup env.filters["to_uuid"] = mock_to_uuid env.filters["bool"] = mock_bool return env return create_env @pytest.fixture def project_root(): """Return the project root directory.""" return Path(__file__).parent.parent @pytest.fixture def roles_dir(project_root): """Return the roles directory.""" return project_root / "roles" # Skip markers for conditional tests def pytest_configure(config): """Register custom markers.""" config.addinivalue_line("markers", "requires_wireguard: mark test as requiring WireGuard tools") config.addinivalue_line("markers", "slow: mark test as slow running") @pytest.fixture(autouse=True) def skip_wireguard_tests(request): """Skip tests marked with requires_wireguard if WireGuard tools aren't available.""" if request.node.get_closest_marker("requires_wireguard"): import shutil if not shutil.which("wg"): pytest.skip("WireGuard tools not available") ================================================ FILE: tests/e2e/README.md ================================================ # End-to-End VPN Connectivity Tests This directory contains end-to-end tests that verify actual VPN connectivity using Linux network namespaces. ## Architecture ``` +---------------------------+ veth pair +---------------------------+ | Main Namespace | | Client Namespace | | (VPN Server) | | (algo-client) | | | | | | wg0: 10.49.0.1 | veth-algo-srv | veth-algo-cli | | strongswan listening |<----------------->| 10.99.0.2/24 | | dns: 172.16.0.1 | 10.99.0.1/24 | | | | | wg0 (after connection) | +---------------------------+ +---------------------------+ ``` The test creates a network namespace that simulates a VPN client. Traffic from the namespace routes through a veth pair to the host, which NATs it to allow the client to connect to the VPN server running on localhost. ## Running Locally (Linux) These tests require Linux (network namespaces are a Linux kernel feature). ```bash # Deploy Algo first ansible-playbook main.yml -e "provider=local" # Run all connectivity tests sudo tests/e2e/test-vpn-connectivity.sh both # Run only WireGuard tests sudo tests/e2e/test-vpn-connectivity.sh wireguard # Run only IPsec tests sudo tests/e2e/test-vpn-connectivity.sh ipsec ``` ## Running on macOS (via Multipass) Use [Multipass](https://multipass.run/) to run an Ubuntu VM: ```bash # Launch and mount algo directory multipass launch 22.04 --name algo-test --cpus 2 --memory 4G --disk 20G multipass mount ~/path/to/algo algo-test:/home/ubuntu/algo multipass shell algo-test # Inside VM: install dependencies and deploy sudo apt-get update sudo apt-get install -y python3-pip wireguard-tools strongswan libxml2-utils dnsutils curl -LsSf https://astral.sh/uv/install.sh | sh && source ~/.bashrc cd ~/algo && uv sync uv run ansible-playbook main.yml -e "provider=local" # Run tests sudo tests/e2e/test-vpn-connectivity.sh both # Cleanup (from macOS) multipass delete algo-test && multipass purge ``` ## Requirements - Root access (for network namespace operations) - Linux (network namespaces are a kernel feature) - Deployed Algo VPN on localhost (configs in `configs/localhost/`) - Required tools: - `iproute2` (ip netns) - `wireguard-tools` (wg, wg-quick) - `strongswan` (ipsec, swanctl) - `libxml2-utils` (xmllint) - `openssl` - `dnsutils` (host) ## Configuration Assumptions The tests assume Algo's default network configuration: | Setting | Default Value | Environment Variable | |---------|---------------|---------------------| | Test user | `alice` | `TEST_USER=username` | | WireGuard server IP | `10.49.0.1` | (hardcoded) | | DNS service IP | `172.16.0.1` | (hardcoded) | If you've customized `wireguard_network_ipv4` or `local_service_ip` in your deployment, the tests will fail. The CI workflow creates users `alice` and `bob` specifically for testing. ## What Gets Tested ### Validation Tests (No Namespace Required) - mobileconfig XML syntax validation (`xmllint`) - CA certificate chain verification (`openssl verify`) ### WireGuard Tests 1. Client config file exists and is parseable 2. WireGuard interface comes up in namespace 3. Cryptographic handshake completes (checks `latest handshake`) 4. Ping to server VPN IP (10.49.0.1) succeeds 5. DNS resolution through VPN (172.16.0.1) works ### IPsec Tests 1. Certificate and key files exist 2. Certificate chain validates 3. IPsec service is running and listening 4. IPsec ports (500, 4500) are reachable 5. DNS service is responding ## Test Flow 1. **Setup**: Create `algo-client` network namespace with veth pair 2. **Validate**: Check mobileconfig XML and certificates 3. **WireGuard**: Start wg-quick in namespace, verify handshake and connectivity 4. **IPsec**: Verify certificates and service status 5. **Cleanup**: Remove namespace, NAT rules, and temp files ## Troubleshooting ### Common Issues **Namespace already exists** ```bash sudo ip netns del algo-client ``` **WireGuard handshake timeout** - Check firewall allows UDP 51820 - Verify wg0 interface exists on host: `sudo wg show` - Check server public key matches config **IPsec connection failed** - Verify strongswan service: `sudo systemctl status strongswan-starter` - Check certificates: `openssl verify -CAfile cacert.pem user.crt` - Review logs: `sudo journalctl -u strongswan -n 50` **DNS resolution failed** - Check dnscrypt-proxy: `sudo systemctl status dnscrypt-proxy` - Verify DNS IP is routed: `ip route get 172.16.0.1` - Test from host: `host google.com 172.16.0.1` ### Debug Mode If tests fail, debug information is automatically collected including: - Network interfaces and routes - WireGuard and IPsec status - iptables NAT rules - DNS service status - Recent system logs ## CI Integration These tests run automatically in GitHub Actions after Algo deployment: ```yaml - name: Run E2E VPN connectivity tests run: sudo tests/e2e/test-vpn-connectivity.sh "${{ matrix.vpn_type }}" ``` The tests are matrix-aware and run for `wireguard`, `ipsec`, or `both` configurations. ================================================ FILE: tests/e2e/test-vpn-connectivity.sh ================================================ #!/bin/bash set -euo pipefail IFS=$'\n\t' # ============================================================================= # Algo VPN End-to-End Connectivity Tests # # Uses Linux network namespaces to simulate a VPN client connecting to the # server deployed on localhost. Tests both WireGuard and IPsec connectivity. # # Usage: sudo ./test-vpn-connectivity.sh [wireguard|ipsec|both] # ============================================================================= SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ALGO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" # Configuration NAMESPACE="algo-client" VETH_SERVER="veth-algo-srv" VETH_CLIENT="veth-algo-cli" SERVER_BRIDGE_IP="10.99.0.1" CLIENT_BRIDGE_IP="10.99.0.2" CONFIG_DIR="${ALGO_ROOT}/configs/localhost" TEST_USER="${TEST_USER:-alice}" VPN_TYPE="${1:-both}" # WireGuard network from config.cfg defaults WG_SERVER_IP="10.49.0.1" DNS_SERVICE_IP="172.16.0.1" # Colors for output (disabled if not a terminal) if [[ -t 1 ]]; then RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' else RED='' GREEN='' YELLOW='' NC='' fi log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } log_error() { echo -e "${RED}[ERROR]${NC} $*"; } log_step() { echo -e "\n${GREEN}==>${NC} $*"; } # ============================================================================= # Cleanup Functions # ============================================================================= # shellcheck disable=SC2317,SC2329 # Function is invoked indirectly via trap cleanup() { local exit_code=$? log_step "Cleaning up test environment..." # Tear down WireGuard in namespace (if running) ip netns exec "${NAMESPACE}" wg-quick down /tmp/algo-test-wg.conf 2>/dev/null || true # Tear down IPsec in namespace (if running) ip netns exec "${NAMESPACE}" ipsec stroke down-nb "algovpn" 2>/dev/null || true ip netns exec "${NAMESPACE}" ipsec stop 2>/dev/null || true # Remove firewall rules we added iptables -t nat -D POSTROUTING -s "${CLIENT_BRIDGE_IP}/32" ! -d 10.99.0.0/24 -j MASQUERADE 2>/dev/null || true iptables -D INPUT -i "${VETH_SERVER}" -p udp --dport 51820 -j ACCEPT 2>/dev/null || true iptables -D INPUT -i "${VETH_SERVER}" -p udp --dport 500 -j ACCEPT 2>/dev/null || true iptables -D INPUT -i "${VETH_SERVER}" -p udp --dport 4500 -j ACCEPT 2>/dev/null || true # Delete namespace (also removes veth pair) ip netns del "${NAMESPACE}" 2>/dev/null || true # Clean up server-side veth if orphaned ip link del "${VETH_SERVER}" 2>/dev/null || true # Clean up temp files rm -f /tmp/algo-test-wg.conf /tmp/algo-ipsec-test-* /tmp/algo-tcpdump.log 2>/dev/null || true rm -rf /tmp/algo-ipsec-test 2>/dev/null || true pkill -f "tcpdump.*port 51820" 2>/dev/null || true log_info "Cleanup complete" exit "${exit_code}" } trap cleanup EXIT INT TERM # ============================================================================= # Namespace Setup # ============================================================================= setup_namespace() { log_step "Setting up network namespace..." # Clean up any existing namespace first if ip netns list | grep -q "^${NAMESPACE}"; then log_warn "Namespace ${NAMESPACE} already exists, cleaning up first..." ip netns del "${NAMESPACE}" 2>/dev/null || true ip link del "${VETH_SERVER}" 2>/dev/null || true fi # Create namespace ip netns add "${NAMESPACE}" # Create veth pair ip link add "${VETH_SERVER}" type veth peer name "${VETH_CLIENT}" # Move client end to namespace ip link set "${VETH_CLIENT}" netns "${NAMESPACE}" # Configure server side ip addr add "${SERVER_BRIDGE_IP}/24" dev "${VETH_SERVER}" ip link set "${VETH_SERVER}" up # Configure client side (in namespace) ip netns exec "${NAMESPACE}" ip addr add "${CLIENT_BRIDGE_IP}/24" dev "${VETH_CLIENT}" ip netns exec "${NAMESPACE}" ip link set "${VETH_CLIENT}" up ip netns exec "${NAMESPACE}" ip link set lo up # Set default route in namespace to go through the veth to server ip netns exec "${NAMESPACE}" ip route add default via "${SERVER_BRIDGE_IP}" # Enable forwarding on the server for NAT sysctl -w net.ipv4.ip_forward=1 > /dev/null # Add MASQUERADE for the client namespace traffic going to external networks iptables -t nat -A POSTROUTING -s "${CLIENT_BRIDGE_IP}/32" ! -d 10.99.0.0/24 -j MASQUERADE # Allow WireGuard and IPsec traffic on the veth interface # Use -I to insert at beginning of chain (before any DROP rules) iptables -I INPUT -i "${VETH_SERVER}" -p udp --dport 51820 -j ACCEPT iptables -I INPUT -i "${VETH_SERVER}" -p udp --dport 500 -j ACCEPT iptables -I INPUT -i "${VETH_SERVER}" -p udp --dport 4500 -j ACCEPT log_info "Namespace ${NAMESPACE} created with IP ${CLIENT_BRIDGE_IP}" # Verify connectivity to server if ip netns exec "${NAMESPACE}" ping -c 1 -W 2 "${SERVER_BRIDGE_IP}" > /dev/null 2>&1; then log_info "Namespace can reach server bridge at ${SERVER_BRIDGE_IP}" else log_error "Namespace cannot reach server bridge. Network setup failed." log_error "Fix: Check veth configuration and firewall rules" exit 1 fi # Verify client can reach WireGuard port on localhost (through NAT) if ip netns exec "${NAMESPACE}" timeout 2 bash -c "echo >/dev/udp/127.0.0.1/51820" 2>/dev/null; then log_info "Client can reach WireGuard port (UDP 51820)" else log_warn "Cannot verify WireGuard port reachability (may be expected)" fi } # ============================================================================= # Mobileconfig Validation # ============================================================================= test_mobileconfig_validation() { log_step "Validating mobileconfig files..." local failed=0 # WireGuard mobileconfig (if exists) if [[ -d "${CONFIG_DIR}/wireguard/apple" ]]; then while IFS= read -r -d '' f; do if xmllint --noout "${f}" 2>/dev/null; then log_info "Valid XML: $(basename "${f}")" else log_error "Invalid XML: ${f}" ((failed++)) fi done < <(find "${CONFIG_DIR}/wireguard/apple" -name "*.mobileconfig" -print0 2>/dev/null) fi # IPsec mobileconfig if [[ -d "${CONFIG_DIR}/ipsec/apple" ]]; then while IFS= read -r -d '' f; do if xmllint --noout "${f}" 2>/dev/null; then log_info "Valid XML: $(basename "${f}")" else log_error "Invalid XML: ${f}" ((failed++)) fi done < <(find "${CONFIG_DIR}/ipsec/apple" -name "*.mobileconfig" -print0 2>/dev/null) fi if [[ ${failed} -eq 0 ]]; then log_info "All mobileconfig files valid" return 0 else log_error "${failed} mobileconfig file(s) invalid" return 1 fi } # ============================================================================= # CA Name Constraints Test # ============================================================================= test_ca_name_constraints() { log_step "Testing CA name constraints..." local cacert="${CONFIG_DIR}/ipsec/.pki/cacert.pem" local server_cert server_cert=$(find "${CONFIG_DIR}/ipsec/.pki/certs" -name "*.crt" ! -name "${TEST_USER}.crt" | head -1) if [[ ! -f "${cacert}" ]]; then log_warn "Skipping CA name constraints test (CA cert not found)" return 0 fi if [[ -z "${server_cert}" ]] || [[ ! -f "${server_cert}" ]]; then log_warn "Skipping CA name constraints test (server cert not found)" return 0 fi # The CA should verify the server certificate local verify_output verify_output=$(openssl verify -verbose -CAfile "${cacert}" "${server_cert}" 2>&1) || true if echo "${verify_output}" | grep -q "OK"; then log_info "Server certificate verification passed" else log_warn "Server certificate verification: ${verify_output}" fi log_info "CA name constraints test completed" return 0 } # ============================================================================= # WireGuard Tests # ============================================================================= test_wireguard() { log_step "Testing WireGuard connectivity..." local wg_config="${CONFIG_DIR}/wireguard/${TEST_USER}.conf" if [[ ! -f "${wg_config}" ]]; then log_error "WireGuard config not found: ${wg_config}" log_error "Fix: Ensure Algo deployed with wireguard_enabled: true" return 1 fi # Copy and modify config for namespace use local ns_config="/tmp/algo-test-wg.conf" cp "${wg_config}" "${ns_config}" # Modify config: # - Change Endpoint to use bridge IP (client namespace routes through veth) # - Set Table=off to prevent routing table changes conflicting with namespace # - Remove DNS line to avoid resolvconf dependency (we test DNS separately) sed -i "s/Endpoint = 127.0.0.1:/Endpoint = ${SERVER_BRIDGE_IP}:/" "${ns_config}" sed -i "s/Endpoint = localhost:/Endpoint = ${SERVER_BRIDGE_IP}:/" "${ns_config}" sed -i '/^DNS = /d' "${ns_config}" # Add Table=off if not present (prevent routing table changes in namespace) if ! grep -q "^Table" "${ns_config}"; then sed -i '/^\[Interface\]/a Table = off' "${ns_config}" fi # Add PersistentKeepalive to trigger handshake initiation # Without this, WireGuard waits for outgoing traffic before initiating if ! grep -q "^PersistentKeepalive" "${ns_config}"; then sed -i '/^\[Peer\]/a PersistentKeepalive = 1' "${ns_config}" fi log_info "Modified WireGuard config for namespace testing" log_info "Endpoint changed to ${SERVER_BRIDGE_IP}" # Debug: Show server WireGuard state before client connects log_info "Server WireGuard peers:" local server_peers server_peers=$(wg show wg0 peers 2>/dev/null || echo "") if [[ -z "${server_peers}" ]]; then # Workaround: Deployment bug causes handlers not to fire with async roles # Restart WireGuard to load the peer configuration log_warn "No peers found - restarting WireGuard to load config (deployment handler bug workaround)" systemctl restart wg-quick@wg0 || log_error "Failed to restart WireGuard" sleep 2 server_peers=$(wg show wg0 peers 2>/dev/null || echo "") fi if [[ -n "${server_peers}" ]]; then log_info "Found peers: ${server_peers}" else log_error "Server WireGuard has no peers configured!" log_error "Check that deployment created /etc/wireguard/wg0.conf with [Peer] sections" return 1 fi log_info "Server WireGuard listening:" ss -ulnp | grep 51820 || log_warn "WireGuard port not found in ss output" # Disable reverse path filtering on veth (can cause packet drops in some environments) sysctl -w net.ipv4.conf.all.rp_filter=0 > /dev/null 2>&1 || true sysctl -w net.ipv4.conf."${VETH_SERVER}".rp_filter=0 > /dev/null 2>&1 || true # Start packet capture in background for failure diagnosis local tcpdump_log="/tmp/algo-tcpdump.log" timeout 20 tcpdump -i any -n port 51820 -c 20 > "${tcpdump_log}" 2>&1 & local tcpdump_pid=$! # Start WireGuard in the namespace log_info "Starting WireGuard in namespace..." if ! ip netns exec "${NAMESPACE}" wg-quick up "${ns_config}" 2>&1; then log_error "Failed to start WireGuard in namespace" kill "${tcpdump_pid}" 2>/dev/null || true return 1 fi # Get the WireGuard interface name local wg_interface wg_interface=$(ip netns exec "${NAMESPACE}" wg show interfaces 2>/dev/null || echo "") if [[ -z "${wg_interface}" ]]; then log_error "WireGuard interface not created in namespace" return 1 fi log_info "WireGuard interface '${wg_interface}' is up" # Add routes for VPN traffic through wg interface ip netns exec "${NAMESPACE}" ip route add "${WG_SERVER_IP}/32" dev "${wg_interface}" 2>/dev/null || true ip netns exec "${NAMESPACE}" ip route add "${DNS_SERVICE_IP}/32" dev "${wg_interface}" 2>/dev/null || true # Wait for handshake (with timeout) log_info "Waiting for WireGuard handshake..." local attempts=0 local max_attempts=15 while [[ ${attempts} -lt ${max_attempts} ]]; do if ip netns exec "${NAMESPACE}" wg show 2>/dev/null | grep -q "latest handshake"; then log_info "WireGuard handshake completed!" break fi sleep 1 ((attempts++)) done if [[ ${attempts} -ge ${max_attempts} ]]; then log_error "WireGuard handshake timeout after ${max_attempts} seconds" log_error "Debug - client wg show:" ip netns exec "${NAMESPACE}" wg show 2>&1 || true log_error "Debug - server wg0 state:" wg show wg0 2>&1 || true log_error "Debug - iptables INPUT chain (first 15 rules):" iptables -L INPUT -n -v --line-numbers 2>&1 | head -20 || true log_error "Debug - packet capture (tcpdump):" kill "${tcpdump_pid}" 2>/dev/null || true sleep 1 cat "${tcpdump_log}" 2>/dev/null || echo "No capture available" log_error "Debug - host route to 10.99.0.0/24:" ip route get 10.99.0.2 2>&1 || true log_error "Debug - namespace route to server:" ip netns exec "${NAMESPACE}" ip route get 10.99.0.1 2>&1 || true return 1 fi # Stop packet capture kill "${tcpdump_pid}" 2>/dev/null || true # Show WireGuard status ip netns exec "${NAMESPACE}" wg show # Test connectivity to VPN server IP log_info "Testing ping to WireGuard server (${WG_SERVER_IP})..." if ip netns exec "${NAMESPACE}" ping -c 3 -W 3 "${WG_SERVER_IP}" 2>&1; then log_info "Ping to WireGuard server successful" else log_error "Cannot ping WireGuard server IP ${WG_SERVER_IP}" return 1 fi # Test DNS through VPN (hard fail as per user decision) log_info "Testing DNS resolution through VPN (${DNS_SERVICE_IP})..." if ip netns exec "${NAMESPACE}" host -W 5 google.com "${DNS_SERVICE_IP}" 2>&1; then log_info "DNS resolution through VPN successful" else log_error "DNS resolution through VPN failed" log_error "Fix: Check dnscrypt-proxy service and routing to ${DNS_SERVICE_IP}" return 1 fi # Cleanup WireGuard ip netns exec "${NAMESPACE}" wg-quick down "${ns_config}" 2>/dev/null || true rm -f "${ns_config}" log_info "WireGuard E2E tests PASSED" return 0 } # ============================================================================= # IPsec Tests # ============================================================================= test_ipsec() { log_step "Testing IPsec/StrongSwan connectivity..." local cacert="${CONFIG_DIR}/ipsec/.pki/cacert.pem" local user_cert="${CONFIG_DIR}/ipsec/.pki/certs/${TEST_USER}.crt" local user_key="${CONFIG_DIR}/ipsec/.pki/private/${TEST_USER}.key" # Verify required files exist for f in "${cacert}" "${user_cert}" "${user_key}"; do if [[ ! -f "${f}" ]]; then log_error "IPsec file not found: ${f}" log_error "Fix: Ensure Algo deployed with ipsec_enabled: true" return 1 fi done log_info "All IPsec certificates found" # Create temporary directory for namespace StrongSwan config local ns_ipsec_dir="/tmp/algo-ipsec-test" rm -rf "${ns_ipsec_dir}" mkdir -p "${ns_ipsec_dir}"/{ipsec.d/certs,ipsec.d/private,ipsec.d/cacerts} # Copy certificates cp "${cacert}" "${ns_ipsec_dir}/ipsec.d/cacerts/" cp "${user_cert}" "${ns_ipsec_dir}/ipsec.d/certs/" cp "${user_key}" "${ns_ipsec_dir}/ipsec.d/private/" chmod 600 "${ns_ipsec_dir}/ipsec.d/private/${TEST_USER}.key" # Create swanctl.conf for the client cat > "${ns_ipsec_dir}/swanctl.conf" << EOF connections { algovpn { version = 2 proposals = aes256gcm16-prfsha512-ecp384 rekey_time = 0 dpd_delay = 35s remote_addrs = ${SERVER_BRIDGE_IP} vips = 0.0.0.0 local { auth = pubkey certs = ${TEST_USER}.crt } remote { auth = pubkey id = ${SERVER_BRIDGE_IP} } children { algovpn { esp_proposals = aes256gcm16-ecp384 remote_ts = ${DNS_SERVICE_IP}/32 rekey_time = 0 dpd_action = clear } } } } secrets { ecdsa-${TEST_USER} { file = ${TEST_USER}.key } } EOF log_info "StrongSwan configuration created" # Start a minimal charon in the namespace log_info "Starting StrongSwan in namespace..." # Create a minimal strongswan.conf cat > "${ns_ipsec_dir}/strongswan.conf" << EOF charon { load_modular = yes plugins { include /etc/strongswan.d/charon/*.conf } filelog { /tmp/algo-ipsec-test/charon.log { default = 2 ike = 2 net = 1 } } } swanctl { load = pem pkcs1 x509 revocation constraints pubkey openssl kernel-netlink socket-default updown vici } EOF # Try to initiate IPsec connection using swanctl # First, we need charon running in the namespace log_info "Initiating IPsec connection..." # Use the host's charon but connect to server via bridge # This is simpler than running charon in a namespace # Instead, test that the certificates are valid and connection can be established # Test certificate chain validity log_info "Verifying certificate chain..." if openssl verify -CAfile "${cacert}" "${user_cert}" 2>&1 | grep -q "OK"; then log_info "Client certificate verification passed" else log_error "Client certificate verification failed" openssl verify -CAfile "${cacert}" "${user_cert}" 2>&1 return 1 fi # Check if IPsec service is running on host if ! ipsec status >/dev/null 2>&1; then log_error "IPsec service not running on host" return 1 fi log_info "IPsec service is running on host" # Show current IPsec status log_info "Current IPsec status:" ipsec statusall | head -20 || true # For a true E2E test, we would connect from the namespace # But IPsec in namespaces requires running charon which is complex # Instead, verify the server is accepting connections by checking logs # Test connectivity to IPsec ports log_info "Testing IPsec port reachability..." if ip netns exec "${NAMESPACE}" timeout 2 bash -c \ "echo >/dev/udp/${SERVER_BRIDGE_IP}/500" 2>/dev/null; then log_info "IKE port (UDP 500) reachable" else log_warn "IKE port (UDP 500) not reachable through namespace" fi if ip netns exec "${NAMESPACE}" timeout 2 bash -c \ "echo >/dev/udp/${SERVER_BRIDGE_IP}/4500" 2>/dev/null; then log_info "NAT-T port (UDP 4500) reachable" else log_warn "NAT-T port (UDP 4500) not reachable through namespace" fi # Verify strongswan is configured correctly on server log_info "Checking StrongSwan server configuration..." if ipsec statusall | grep -q "Listening"; then log_info "StrongSwan is listening for connections" fi # Test DNS service is accessible (for when IPsec tunnel would be up) log_info "Testing DNS service accessibility..." if host -W 5 google.com "${DNS_SERVICE_IP}" 2>&1 | grep -q "has address"; then log_info "DNS service at ${DNS_SERVICE_IP} is responding" else log_error "DNS service at ${DNS_SERVICE_IP} is not responding" log_error "Fix: Check dnscrypt-proxy service status" return 1 fi # Cleanup rm -rf "${ns_ipsec_dir}" log_info "IPsec E2E tests PASSED" log_info "Note: Full tunnel test requires running charon in namespace (complex)" return 0 } # ============================================================================= # Debug Information Collection # ============================================================================= collect_debug_info() { log_step "Collecting debug information..." echo "=== Network Interfaces (Host) ===" ip addr || true echo "=== Routing Table (Host) ===" ip route || true echo "=== Network Namespaces ===" ip netns list || true echo "=== Network Interfaces (Namespace) ===" ip netns exec "${NAMESPACE}" ip addr 2>/dev/null || echo "Namespace not available" echo "=== Routing Table (Namespace) ===" ip netns exec "${NAMESPACE}" ip route 2>/dev/null || echo "Namespace not available" echo "=== WireGuard Status (Host) ===" wg show || true echo "=== WireGuard Status (Namespace) ===" ip netns exec "${NAMESPACE}" wg show 2>/dev/null || echo "Not running" echo "=== IPsec Status (Host) ===" ipsec statusall || true echo "=== Listening Ports ===" ss -tulnp | grep -E ':(51820|500|4500|53)\s' || true echo "=== iptables NAT rules ===" iptables -t nat -L POSTROUTING -n -v || true echo "=== DNS Service Status ===" systemctl status dnscrypt-proxy --no-pager 2>/dev/null || true echo "=== Recent System Logs ===" journalctl -n 50 --no-pager 2>/dev/null || true } # ============================================================================= # Main # ============================================================================= main() { log_step "Algo VPN End-to-End Connectivity Tests" log_info "VPN type: ${VPN_TYPE}" log_info "Config directory: ${CONFIG_DIR}" log_info "Test user: ${TEST_USER}" # Check root if [[ ${EUID} -ne 0 ]]; then log_error "This script must be run as root (for namespace operations)" log_error "Fix: sudo $0 ${VPN_TYPE}" exit 1 fi # Check required commands local missing_cmds=() for cmd in ip wg wg-quick ipsec xmllint openssl host; do if ! command -v "${cmd}" &> /dev/null; then missing_cmds+=("${cmd}") fi done if [[ ${#missing_cmds[@]} -gt 0 ]]; then log_error "Required command(s) not found: ${missing_cmds[*]}" log_error "Fix: apt-get install iproute2 wireguard-tools strongswan libxml2-utils openssl dnsutils" exit 1 fi # Check config directory exists if [[ ! -d "${CONFIG_DIR}" ]]; then log_error "Config directory not found: ${CONFIG_DIR}" log_error "Fix: Deploy Algo first: ansible-playbook main.yml -e provider=local" exit 1 fi local exit_code=0 # Run validation tests first (no namespace needed) test_mobileconfig_validation || ((exit_code++)) test_ca_name_constraints || ((exit_code++)) # Setup namespace for connectivity tests setup_namespace # Run protocol-specific tests case "${VPN_TYPE}" in wireguard) test_wireguard || ((exit_code++)) ;; ipsec) test_ipsec || ((exit_code++)) ;; both) test_wireguard || ((exit_code++)) test_ipsec || ((exit_code++)) ;; *) log_error "Unknown VPN type: ${VPN_TYPE}" log_error "Usage: $0 [wireguard|ipsec|both]" exit 1 ;; esac # Summary log_step "Test Summary" if [[ ${exit_code} -eq 0 ]]; then log_info "All E2E tests PASSED" else log_error "${exit_code} test(s) FAILED" collect_debug_info fi exit ${exit_code} } main "$@" ================================================ FILE: tests/fixtures/__init__.py ================================================ """Test fixtures for Algo unit tests""" from pathlib import Path import yaml def load_test_variables(): """Load test variables from YAML fixture""" fixture_path = Path(__file__).parent / "test_variables.yml" with open(fixture_path) as f: return yaml.safe_load(f) def get_test_config(overrides=None): """Get test configuration with optional overrides""" config = load_test_variables() if overrides: config.update(overrides) return config ================================================ FILE: tests/fixtures/test_variables.yml ================================================ --- # Shared test variables for unit tests # This ensures consistency across all tests and easier maintenance # Server/Network basics server_name: test-algo-vpn IP_subject_alt_name: 10.0.0.1 ipv4_network_prefix: 10.19.49 ipv4_network: 10.19.49.0 ipv4_range: 10.19.49.2/24 ipv6_network: fd9d:bc11:4020::/48 ipv6_range: fd9d:bc11:4020::/64 wireguard_enabled: true wireguard_port: 51820 wireguard_PersistentKeepalive: 0 wireguard_network: 10.19.49.0/24 wireguard_network_ipv6: fd9d:bc11:4020::/48 # Additional WireGuard variables wireguard_pki_path: /etc/wireguard/pki wireguard_port_avoid: 53 wireguard_port_actual: 51820 wireguard_network_ipv4: 10.19.49.0/24 wireguard_client_ip: 10.19.49.2/32,fd9d:bc11:4020::2/128 wireguard_dns_servers: 1.1.1.1,1.0.0.1 # IPsec variables ipsec_enabled: true strongswan_enabled: true strongswan_af: ipv4 strongswan_log_level: '2' strongswan_network: 10.19.48.0/24 strongswan_network_ipv6: fd9d:bc11:4021::/64 algo_ondemand_cellular: 'false' algo_ondemand_wifi: 'false' algo_ondemand_wifi_exclude: X251bGw= # DNS dns_adblocking: true algo_dns_adblocking: true adblock_lists: - https://someblacklist.com dns_encryption: true dns_servers: - 1.1.1.1 - 1.0.0.1 local_dns: true alternative_ingress_ip: false local_service_ip: 10.19.49.1 local_service_ipv6: fd9d:bc11:4020::1 ipv6_support: true # Security/Firewall algo_ssh_tunneling: false ssh_tunneling: false snat_aipv4: false snat_aipv6: false block_smb: true block_netbios: true # Users and auth users: - alice - bob - charlie existing_users: - alice easyrsa_CA_password: test-ca-pass p12_export_password: test-export-pass CA_password: test-ca-pass # System ansible_ssh_port: 4160 ansible_python_interpreter: /usr/bin/python3 ansible_default_ipv4: interface: eth0 address: 10.0.0.1 ansible_default_ipv6: interface: eth0 address: 'fd9d:bc11:4020::1' BetweenClients_DROP: 'Y' ssh_tunnels_config_path: /etc/ssh/ssh_tunnels config_prefix: /etc/algo server_user: algo IP: 10.0.0.1 reduce_mtu: 0 algo_ssh_port: 4160 algo_store_pki: true # Ciphers ciphers: defaults: ike: aes128gcm16-prfsha512-ecp256,aes128-sha2_256-modp2048 esp: aes128gcm16-ecp256,aes128-sha2_256-modp2048 ike: aes128gcm16-prfsha512-ecp256,aes128-sha2_256-modp2048 esp: aes128gcm16-ecp256,aes128-sha2_256-modp2048 # Cloud provider specific algo_provider: local cloud_providers: - ec2 - gce - azure - do - lightsail - scaleway - openstack - cloudstack - hetzner - linode - vultr provider_dns_servers: - 1.1.1.1 - 1.0.0.1 ansible_ssh_private_key_file: ~/.ssh/id_rsa # Defaults inventory_hostname: localhost hostvars: localhost: {} groups: vpn-host: - localhost omit: OMIT_PLACEHOLDER ================================================ FILE: tests/integration/ansible-service-wrapper.py ================================================ #!/usr/bin/env python3 """ Wrapper for Ansible's service module that always succeeds for known services """ import json import sys # Parse module arguments args = json.loads(sys.stdin.read()) module_args = args.get("ANSIBLE_MODULE_ARGS", {}) service_name = module_args.get("name", "") state = module_args.get("state", "started") # Known services that should always succeed known_services = [ "netfilter-persistent", "iptables", "wg-quick@wg0", "strongswan-starter", "ipsec", "apparmor", "unattended-upgrades", "systemd-networkd", "systemd-resolved", "rsyslog", "ipfw", "cron", ] # Check if it's a known service service_found = False for svc in known_services: if service_name == svc or service_name.startswith(svc + "."): service_found = True break if service_found: # Return success result = { "changed": state in ["started", "stopped", "restarted", "reloaded"], "name": service_name, "state": state, "status": { "LoadState": "loaded", "ActiveState": "active" if state != "stopped" else "inactive", "SubState": "running" if state != "stopped" else "dead", }, } print(json.dumps(result)) sys.exit(0) else: # Service not found error = {"failed": True, "msg": f"Could not find the requested service {service_name}: "} print(json.dumps(error)) sys.exit(1) ================================================ FILE: tests/integration/ansible.cfg ================================================ [defaults] library = /algo/tests/integration/mock_modules roles_path = /algo/roles host_key_checking = False stdout_callback = debug ================================================ FILE: tests/integration/mock-apparmor_status.sh ================================================ #!/bin/bash # Mock apparmor_status for Docker testing # Return error code to indicate AppArmor is not available exit 1 ================================================ FILE: tests/integration/mock_modules/apt.py ================================================ #!/usr/bin/python # Mock apt module for Docker testing import subprocess from ansible.module_utils.basic import AnsibleModule def main(): module = AnsibleModule( argument_spec={ "name": {"type": "list", "aliases": ["pkg", "package"]}, "state": { "type": "str", "default": "present", "choices": ["present", "absent", "latest", "build-dep", "fixed"], }, "update_cache": {"type": "bool", "default": False}, "cache_valid_time": {"type": "int", "default": 0}, "install_recommends": {"type": "bool"}, "force": {"type": "bool", "default": False}, "allow_unauthenticated": {"type": "bool", "default": False}, "allow_downgrade": {"type": "bool", "default": False}, "allow_change_held_packages": {"type": "bool", "default": False}, "dpkg_options": {"type": "str", "default": "force-confdef,force-confold"}, "autoremove": {"type": "bool", "default": False}, "purge": {"type": "bool", "default": False}, "force_apt_get": {"type": "bool", "default": False}, }, supports_check_mode=True, ) name = module.params["name"] state = module.params["state"] update_cache = module.params["update_cache"] result = {"changed": False, "cache_updated": False, "cache_update_time": 0} # Log the operation with open("/var/log/mock-apt-module.log", "a") as f: f.write(f"apt module called: name={name}, state={state}, update_cache={update_cache}\n") # Handle cache update if update_cache: # In Docker, apt-get update was already run in entrypoint # Just pretend it succeeded result["cache_updated"] = True result["cache_update_time"] = 1754231778 # Fixed timestamp result["changed"] = True # Handle package installation/removal if name: packages = name if isinstance(name, list) else [name] # Check which packages are already installed installed_packages = [] for pkg in packages: # Use dpkg to check if package is installed check_cmd = ["dpkg", "-s", pkg] rc = subprocess.run(check_cmd, capture_output=True) if rc.returncode == 0: installed_packages.append(pkg) if state in ["present", "latest"]: # Check if we need to install anything missing_packages = [p for p in packages if p not in installed_packages] if missing_packages: # Log what we would install with open("/var/log/mock-apt-module.log", "a") as f: f.write(f"Would install packages: {missing_packages}\n") # For our test purposes, these packages are pre-installed in Docker # Just report success result["changed"] = True result["stdout"] = f"Mock: Packages {missing_packages} are already available" result["stderr"] = "" else: result["stdout"] = "All packages are already installed" elif state == "absent": # Check if we need to remove anything present_packages = [p for p in packages if p in installed_packages] if present_packages: result["changed"] = True result["stdout"] = f"Mock: Would remove packages {present_packages}" else: result["stdout"] = "No packages to remove" # Always report success for our testing module.exit_json(**result) if __name__ == "__main__": main() ================================================ FILE: tests/integration/mock_modules/command.py ================================================ #!/usr/bin/python # Mock command module for Docker testing import subprocess from ansible.module_utils.basic import AnsibleModule def main(): module = AnsibleModule( argument_spec={ "_raw_params": {"type": "str"}, "cmd": {"type": "str"}, "creates": {"type": "path"}, "removes": {"type": "path"}, "chdir": {"type": "path"}, "executable": {"type": "path"}, "warn": {"type": "bool", "default": False}, "stdin": {"type": "str"}, "stdin_add_newline": {"type": "bool", "default": True}, "strip_empty_ends": {"type": "bool", "default": True}, "_uses_shell": {"type": "bool", "default": False}, }, supports_check_mode=True, ) # Get the command raw_params = module.params.get("_raw_params") cmd = module.params.get("cmd") or raw_params if not cmd: module.fail_json(msg="no command given") result = {"changed": False, "cmd": cmd, "rc": 0, "stdout": "", "stderr": "", "stdout_lines": [], "stderr_lines": []} # Log the operation with open("/var/log/mock-command-module.log", "a") as f: f.write(f"command module called: cmd={cmd}\n") # Handle specific commands if "apparmor_status" in cmd: # Pretend apparmor is not installed/active result["rc"] = 127 result["stderr"] = "apparmor_status: command not found" result["msg"] = "[Errno 2] No such file or directory: b'apparmor_status'" module.fail_json(msg=result["msg"], **result) elif "netplan apply" in cmd: # Pretend netplan succeeded result["stdout"] = "Mock: netplan configuration applied" result["changed"] = True elif "echo 1 > /proc/sys/net/ipv4/route/flush" in cmd: # Routing cache flush result["stdout"] = "1" result["changed"] = True else: # For other commands, try to run them try: proc = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=module.params.get("chdir")) result["rc"] = proc.returncode result["stdout"] = proc.stdout result["stderr"] = proc.stderr result["stdout_lines"] = proc.stdout.splitlines() result["stderr_lines"] = proc.stderr.splitlines() result["changed"] = True except Exception as e: result["rc"] = 1 result["stderr"] = str(e) result["msg"] = str(e) module.fail_json(msg=result["msg"], **result) if result["rc"] == 0: module.exit_json(**result) else: if "msg" not in result: result["msg"] = f"Command failed with return code {result['rc']}" module.fail_json(msg=result["msg"], **result) if __name__ == "__main__": main() ================================================ FILE: tests/integration/mock_modules/shell.py ================================================ #!/usr/bin/python # Mock shell module for Docker testing import subprocess from ansible.module_utils.basic import AnsibleModule def main(): module = AnsibleModule( argument_spec={ "_raw_params": {"type": "str"}, "cmd": {"type": "str"}, "creates": {"type": "path"}, "removes": {"type": "path"}, "chdir": {"type": "path"}, "executable": {"type": "path", "default": "/bin/sh"}, "warn": {"type": "bool", "default": False}, "stdin": {"type": "str"}, "stdin_add_newline": {"type": "bool", "default": True}, }, supports_check_mode=True, ) # Get the command raw_params = module.params.get("_raw_params") cmd = module.params.get("cmd") or raw_params if not cmd: module.fail_json(msg="no command given") result = {"changed": False, "cmd": cmd, "rc": 0, "stdout": "", "stderr": "", "stdout_lines": [], "stderr_lines": []} # Log the operation with open("/var/log/mock-shell-module.log", "a") as f: f.write(f"shell module called: cmd={cmd}\n") # Handle specific commands if "echo 1 > /proc/sys/net/ipv4/route/flush" in cmd: # Routing cache flush - just pretend it worked result["stdout"] = "" result["changed"] = True else: # For other commands, try to run them try: proc = subprocess.run( cmd, shell=True, capture_output=True, text=True, executable=module.params.get("executable"), cwd=module.params.get("chdir"), ) result["rc"] = proc.returncode result["stdout"] = proc.stdout result["stderr"] = proc.stderr result["stdout_lines"] = proc.stdout.splitlines() result["stderr_lines"] = proc.stderr.splitlines() result["changed"] = True except Exception as e: result["rc"] = 1 result["stderr"] = str(e) result["msg"] = str(e) module.fail_json(msg=result["msg"], **result) if result["rc"] == 0: module.exit_json(**result) else: if "msg" not in result: result["msg"] = f"Command failed with return code {result['rc']}" module.fail_json(msg=result["msg"], **result) if __name__ == "__main__": main() ================================================ FILE: tests/integration/test-configs/.provisioned ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/.config.yml ================================================ server: localhost server_user: root ansible_ssh_port: "22" algo_provider: local algo_server_name: algo-test-server algo_ondemand_cellular: False algo_ondemand_wifi: False algo_ondemand_wifi_exclude: X251bGw= algo_dns_adblocking: False algo_ssh_tunneling: False algo_store_pki: True IP_subject_alt_name: 10.99.0.10 ipsec_enabled: True wireguard_enabled: True ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/10.99.0.10_ca_generated ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/cacert.pem ================================================ -----BEGIN CERTIFICATE----- MIICoTCCAiagAwIBAgIUYQ99YGsE7jDrDq93WTTWMkaM7IUwCgYIKoZIzj0EAwIw FTETMBEGA1UEAwwKMTAuOTkuMC4xMDAeFw0yNTA4MDMxMjU5MjdaFw0zNTA4MDEx MjU5MjdaMBUxEzARBgNVBAMMCjEwLjk5LjAuMTAwdjAQBgcqhkjOPQIBBgUrgQQA IgNiAASA2JYIRHTHqMnrGCoIFg8RVz3v2QdjGJnkF3f2Ia4s/V5LaP+WP0PhDEF3 pVHRzHKd2ntk0DBRNOih+/BiQ+lQhfET8tWH+mfAk0HemsgRzRIGadxPVxi1piqJ sL8uWU6jggE1MIIBMTAdBgNVHQ4EFgQUv/5pOGOAGenWXTgdI+dhjK9K6K0wUAYD VR0jBEkwR4AUv/5pOGOAGenWXTgdI+dhjK9K6K2hGaQXMBUxEzARBgNVBAMMCjEw Ljk5LjAuMTCCFGEPfWBrBO4w6w6vd1k01jJGjOyFMBIGA1UdEwEB/wQIMAYBAf8C AQAwgZwGA1UdHgEB/wSBkTCBjqBmMAqHCApjAAr/////MCuCKTk1NDZkNTc0LTNm ZDYtNThmNC05YWM2LTJjNjljYjc1NWRiNy5hbGdvMCuBKTk1NDZkNTc0LTNmZDYt NThmNC05YWM2LTJjNjljYjc1NWRiNy5hbGdvoSQwIocgAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAwCwYDVR0PBAQDAgEGMAoGCCqGSM49BAMCA2kAMGYC MQCsWQOinhhs4yZSOvupPIQKw7hMpKkEiKS6RtRfrvZohGQK92OKXsETLd7YPh3N RBACMQC8WAe35PXcg+JY8padri4d/u2ITreCXARuhUjypm+Ucy1qQ5A18wjj6/KV JJYlbfk= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/01.pem ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=10.99.0.10 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:61:19:b3:d6:a3:52:5a:ff:33:7d:a6:7b:ee:bc: 67:c0:d1:b1:80:bb:c0:72:06:fb:43:86:2d:2b:76: 6a:b9:de:02:f8:2d:30:21:d1:1b:b6:d7:d7:e3:69: 92:e3:d9:91:65:47:82:24:69:e1:4a:cc:d1:2b:c5: 49:30:5d:35:7f:1f:63:bf:52:ae:85:52:da:5f:e9: 5e:27:45:b9:dc:cd:e3:99:1b:d1:f6:24:72:35:28: bf:e4:51:0d:71:64:2e ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 8A:CC:04:6D:D6:3F:3A:3B:BF:06:01:92:27:48:76:08:26:D2:CB:22 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: IP Address:10.99.0.10 Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:65:02:31:00:dd:ed:97:1f:0c:f7:24:38:e8:2d:52:0a:26: 70:45:23:4e:28:43:0f:d2:18:c8:50:c4:82:77:8f:72:44:cb: 6f:60:ce:84:a1:30:e6:df:f0:90:8f:e0:a5:07:49:a0:51:02: 30:2c:2b:02:f7:b2:6e:4a:7a:9f:f9:cc:39:b7:a2:8c:b7:04: d0:b6:ad:1d:c6:a5:58:e3:74:d7:b0:76:99:7f:06:d3:7a:59: 7e:22:63:6b:19:db:f9:ac:5f:be:00:f8:60 -----BEGIN CERTIFICATE----- MIICHTCCAaOgAwIBAgIBATAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFTETMBEGA1UEAwwK MTAuOTkuMC4xMDB2MBAGByqGSM49AgEGBSuBBAAiA2IABGEZs9ajUlr/M32me+68 Z8DRsYC7wHIG+0OGLSt2arneAvgtMCHRG7bX1+NpkuPZkWVHgiRp4UrM0SvFSTBd NX8fY79SroVS2l/pXidFudzN45kb0fYkcjUov+RRDXFkLqOBxjCBwzAJBgNVHRME AjAAMB0GA1UdDgQWBBSKzARt1j86O78GAZInSHYIJtLLIjBQBgNVHSMESTBHgBS/ /mk4Y4AZ6dZdOB0j52GMr0roraEZpBcwFTETMBEGA1UEAwwKMTAuOTkuMC4xMIIU YQ99YGsE7jDrDq93WTTWMkaM7IUwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUF BwMCBggrBgEFBQcDETALBgNVHQ8EBAMCBaAwDwYDVR0RBAgwBocECmMACjAKBggq hkjOPQQDAgNoADBlAjEA3e2XHwz3JDjoLVIKJnBFI04oQw/SGMhQxIJ3j3JEy29g zoShMObf8JCP4KUHSaBRAjAsKwL3sm5Kep/5zDm3ooy3BNC2rR3GpVjjdNewdpl/ BtN6WX4iY2sZ2/msX74A+GA= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/02.pem ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=testuser1 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:81:4d:22:72:2d:c5:f8:cf:52:e3:e0:ef:d8:86: a9:c6:cb:7c:c9:64:04:18:9d:ce:31:c3:99:98:4e: 1a:8e:19:5c:25:56:78:9f:b4:87:9b:c2:51:ec:81: 11:1e:80:6d:fb:47:d6:b1:49:25:72:98:da:c7:2e: 48:23:d6:60:cc:d8:a9:a5:a9:3f:13:33:81:02:11: ad:70:17:f6:ee:41:ed:0b:be:d5:39:25:1f:0c:81: a2:a0:25:a7:4a:e5:e7 ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 51:8F:14:BA:87:16:14:B2:23:33:69:2A:2A:A6:C4:26:80:E3:A0:61 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: email:testuser1@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:66:02:31:00:a5:f7:05:17:78:b5:ce:dc:24:44:ba:57:ad: 65:d8:ce:37:f3:60:7c:55:37:9f:c0:58:7c:6b:09:67:cd:01: 3c:8f:56:32:c8:60:e5:52:2f:47:63:ae:2f:5f:2a:0e:f6:02: 31:00:ff:54:6f:3a:56:df:04:b0:ec:08:b8:c2:d7:20:2c:78: c7:80:b2:40:fe:54:eb:e5:a5:29:d6:53:9d:db:78:17:30:2d: db:09:ea:37:a8:ea:2e:11:23:e0:eb:b5:f5:86 -----BEGIN CERTIFICATE----- MIICTDCCAdGgAwIBAgIBAjAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFDESMBAGA1UEAwwJ dGVzdHVzZXIxMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEgU0ici3F+M9S4+Dv2Iap xst8yWQEGJ3OMcOZmE4ajhlcJVZ4n7SHm8JR7IERHoBt+0fWsUklcpjaxy5II9Zg zNippak/EzOBAhGtcBf27kHtC77VOSUfDIGioCWnSuXno4H1MIHyMAkGA1UdEwQC MAAwHQYDVR0OBBYEFFGPFLqHFhSyIzNpKiqmxCaA46BhMFAGA1UdIwRJMEeAFL/+ aThjgBnp1l04HSPnYYyvSuitoRmkFzAVMRMwEQYDVQQDDAoxMC45OS4wLjEwghRh D31gawTuMOsOr3dZNNYyRozshTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUH AwIGCCsGAQUFBwMRMAsGA1UdDwQEAwIFoDA+BgNVHREENzA1gTN0ZXN0dXNlcjFA OTU0NmQ1NzQtM2ZkNi01OGY0LTlhYzYtMmM2OWNiNzU1ZGI3LmFsZ28wCgYIKoZI zj0EAwIDaQAwZgIxAKX3BRd4tc7cJES6V61l2M4382B8VTefwFh8awlnzQE8j1Yy yGDlUi9HY64vXyoO9gIxAP9UbzpW3wSw7Ai4wtcgLHjHgLJA/lTr5aUp1lOd23gX MC3bCeo3qOouESPg67X1hg== -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/03.pem ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 3 (0x3) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=testuser2 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:88:ed:fc:6d:44:0e:5f:f4:73:13:51:6c:58:cf: 3f:97:c6:b3:3f:c5:12:fe:40:0a:cf:ff:46:da:73: 9a:34:bd:c1:b8:e6:7f:21:d5:ad:39:37:7b:0f:c0: cc:00:17:5c:2a:3e:3a:cf:42:7d:72:7e:2b:82:82: 9d:19:a2:25:e7:0e:3c:b7:67:66:84:15:89:8e:66: 4d:c7:d5:be:00:e9:75:f3:43:c6:94:c9:c8:3a:b1: d1:e7:c0:19:d4:a7:e1 ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 08:4E:A2:3F:07:36:D6:DD:91:11:4B:43:CF:0E:75:68:BF:49:AC:A2 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: email:testuser2@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:64:02:30:60:16:23:85:91:fc:40:f6:10:bc:5a:08:91:77: 30:5d:11:30:ac:8f:c7:6d:87:fd:b2:a0:c1:21:d6:2b:31:7e: 68:0e:b1:a1:86:91:0c:5b:b7:f5:a1:67:e8:11:2f:14:02:30: 62:f9:35:64:44:2b:c9:28:67:35:61:20:1e:2c:b2:25:cb:88: 1e:8c:d7:b6:6d:0f:aa:3d:62:3f:20:87:d6:86:36:25:5e:2a: 27:3a:2a:5e:97:0c:f8:8a:95:f6:b5:72 -----BEGIN CERTIFICATE----- MIICSjCCAdGgAwIBAgIBAzAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFDESMBAGA1UEAwwJ dGVzdHVzZXIyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEiO38bUQOX/RzE1FsWM8/ l8azP8US/kAKz/9G2nOaNL3BuOZ/IdWtOTd7D8DMABdcKj46z0J9cn4rgoKdGaIl 5w48t2dmhBWJjmZNx9W+AOl180PGlMnIOrHR58AZ1Kfho4H1MIHyMAkGA1UdEwQC MAAwHQYDVR0OBBYEFAhOoj8HNtbdkRFLQ88OdWi/SayiMFAGA1UdIwRJMEeAFL/+ aThjgBnp1l04HSPnYYyvSuitoRmkFzAVMRMwEQYDVQQDDAoxMC45OS4wLjEwghRh D31gawTuMOsOr3dZNNYyRozshTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUH AwIGCCsGAQUFBwMRMAsGA1UdDwQEAwIFoDA+BgNVHREENzA1gTN0ZXN0dXNlcjJA OTU0NmQ1NzQtM2ZkNi01OGY0LTlhYzYtMmM2OWNiNzU1ZGI3LmFsZ28wCgYIKoZI zj0EAwIDZwAwZAIwYBYjhZH8QPYQvFoIkXcwXREwrI/HbYf9sqDBIdYrMX5oDrGh hpEMW7f1oWfoES8UAjBi+TVkRCvJKGc1YSAeLLIly4gejNe2bQ+qPWI/IIfWhjYl XionOipelwz4ipX2tXI= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/10.99.0.10.crt ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 1 (0x1) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=10.99.0.10 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:61:19:b3:d6:a3:52:5a:ff:33:7d:a6:7b:ee:bc: 67:c0:d1:b1:80:bb:c0:72:06:fb:43:86:2d:2b:76: 6a:b9:de:02:f8:2d:30:21:d1:1b:b6:d7:d7:e3:69: 92:e3:d9:91:65:47:82:24:69:e1:4a:cc:d1:2b:c5: 49:30:5d:35:7f:1f:63:bf:52:ae:85:52:da:5f:e9: 5e:27:45:b9:dc:cd:e3:99:1b:d1:f6:24:72:35:28: bf:e4:51:0d:71:64:2e ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 8A:CC:04:6D:D6:3F:3A:3B:BF:06:01:92:27:48:76:08:26:D2:CB:22 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: IP Address:10.99.0.10 Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:65:02:31:00:dd:ed:97:1f:0c:f7:24:38:e8:2d:52:0a:26: 70:45:23:4e:28:43:0f:d2:18:c8:50:c4:82:77:8f:72:44:cb: 6f:60:ce:84:a1:30:e6:df:f0:90:8f:e0:a5:07:49:a0:51:02: 30:2c:2b:02:f7:b2:6e:4a:7a:9f:f9:cc:39:b7:a2:8c:b7:04: d0:b6:ad:1d:c6:a5:58:e3:74:d7:b0:76:99:7f:06:d3:7a:59: 7e:22:63:6b:19:db:f9:ac:5f:be:00:f8:60 -----BEGIN CERTIFICATE----- MIICHTCCAaOgAwIBAgIBATAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFTETMBEGA1UEAwwK MTAuOTkuMC4xMDB2MBAGByqGSM49AgEGBSuBBAAiA2IABGEZs9ajUlr/M32me+68 Z8DRsYC7wHIG+0OGLSt2arneAvgtMCHRG7bX1+NpkuPZkWVHgiRp4UrM0SvFSTBd NX8fY79SroVS2l/pXidFudzN45kb0fYkcjUov+RRDXFkLqOBxjCBwzAJBgNVHRME AjAAMB0GA1UdDgQWBBSKzARt1j86O78GAZInSHYIJtLLIjBQBgNVHSMESTBHgBS/ /mk4Y4AZ6dZdOB0j52GMr0roraEZpBcwFTETMBEGA1UEAwwKMTAuOTkuMC4xMIIU YQ99YGsE7jDrDq93WTTWMkaM7IUwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUF BwMCBggrBgEFBQcDETALBgNVHQ8EBAMCBaAwDwYDVR0RBAgwBocECmMACjAKBggq hkjOPQQDAgNoADBlAjEA3e2XHwz3JDjoLVIKJnBFI04oQw/SGMhQxIJ3j3JEy29g zoShMObf8JCP4KUHSaBRAjAsKwL3sm5Kep/5zDm3ooy3BNC2rR3GpVjjdNewdpl/ BtN6WX4iY2sZ2/msX74A+GA= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/10.99.0.10_crt_generated ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/testuser1.crt ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 2 (0x2) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=testuser1 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:81:4d:22:72:2d:c5:f8:cf:52:e3:e0:ef:d8:86: a9:c6:cb:7c:c9:64:04:18:9d:ce:31:c3:99:98:4e: 1a:8e:19:5c:25:56:78:9f:b4:87:9b:c2:51:ec:81: 11:1e:80:6d:fb:47:d6:b1:49:25:72:98:da:c7:2e: 48:23:d6:60:cc:d8:a9:a5:a9:3f:13:33:81:02:11: ad:70:17:f6:ee:41:ed:0b:be:d5:39:25:1f:0c:81: a2:a0:25:a7:4a:e5:e7 ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 51:8F:14:BA:87:16:14:B2:23:33:69:2A:2A:A6:C4:26:80:E3:A0:61 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: email:testuser1@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:66:02:31:00:a5:f7:05:17:78:b5:ce:dc:24:44:ba:57:ad: 65:d8:ce:37:f3:60:7c:55:37:9f:c0:58:7c:6b:09:67:cd:01: 3c:8f:56:32:c8:60:e5:52:2f:47:63:ae:2f:5f:2a:0e:f6:02: 31:00:ff:54:6f:3a:56:df:04:b0:ec:08:b8:c2:d7:20:2c:78: c7:80:b2:40:fe:54:eb:e5:a5:29:d6:53:9d:db:78:17:30:2d: db:09:ea:37:a8:ea:2e:11:23:e0:eb:b5:f5:86 -----BEGIN CERTIFICATE----- MIICTDCCAdGgAwIBAgIBAjAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFDESMBAGA1UEAwwJ dGVzdHVzZXIxMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEgU0ici3F+M9S4+Dv2Iap xst8yWQEGJ3OMcOZmE4ajhlcJVZ4n7SHm8JR7IERHoBt+0fWsUklcpjaxy5II9Zg zNippak/EzOBAhGtcBf27kHtC77VOSUfDIGioCWnSuXno4H1MIHyMAkGA1UdEwQC MAAwHQYDVR0OBBYEFFGPFLqHFhSyIzNpKiqmxCaA46BhMFAGA1UdIwRJMEeAFL/+ aThjgBnp1l04HSPnYYyvSuitoRmkFzAVMRMwEQYDVQQDDAoxMC45OS4wLjEwghRh D31gawTuMOsOr3dZNNYyRozshTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUH AwIGCCsGAQUFBwMRMAsGA1UdDwQEAwIFoDA+BgNVHREENzA1gTN0ZXN0dXNlcjFA OTU0NmQ1NzQtM2ZkNi01OGY0LTlhYzYtMmM2OWNiNzU1ZGI3LmFsZ28wCgYIKoZI zj0EAwIDaQAwZgIxAKX3BRd4tc7cJES6V61l2M4382B8VTefwFh8awlnzQE8j1Yy yGDlUi9HY64vXyoO9gIxAP9UbzpW3wSw7Ai4wtcgLHjHgLJA/lTr5aUp1lOd23gX MC3bCeo3qOouESPg67X1hg== -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/testuser1_crt_generated ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/testuser2.crt ================================================ Certificate: Data: Version: 3 (0x2) Serial Number: 3 (0x3) Signature Algorithm: ecdsa-with-SHA256 Issuer: CN=10.99.0.10 Validity Not Before: Aug 3 12:59:27 2025 GMT Not After : Aug 1 12:59:27 2035 GMT Subject: CN=testuser2 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (384 bit) pub: 04:88:ed:fc:6d:44:0e:5f:f4:73:13:51:6c:58:cf: 3f:97:c6:b3:3f:c5:12:fe:40:0a:cf:ff:46:da:73: 9a:34:bd:c1:b8:e6:7f:21:d5:ad:39:37:7b:0f:c0: cc:00:17:5c:2a:3e:3a:cf:42:7d:72:7e:2b:82:82: 9d:19:a2:25:e7:0e:3c:b7:67:66:84:15:89:8e:66: 4d:c7:d5:be:00:e9:75:f3:43:c6:94:c9:c8:3a:b1: d1:e7:c0:19:d4:a7:e1 ASN1 OID: secp384r1 NIST CURVE: P-384 X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Subject Key Identifier: 08:4E:A2:3F:07:36:D6:DD:91:11:4B:43:CF:0E:75:68:BF:49:AC:A2 X509v3 Authority Key Identifier: keyid:BF:FE:69:38:63:80:19:E9:D6:5D:38:1D:23:E7:61:8C:AF:4A:E8:AD DirName:/CN=10.99.0.10 serial:61:0F:7D:60:6B:04:EE:30:EB:0E:AF:77:59:34:D6:32:46:8C:EC:85 X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication, ipsec Internet Key Exchange X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: email:testuser2@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:64:02:30:60:16:23:85:91:fc:40:f6:10:bc:5a:08:91:77: 30:5d:11:30:ac:8f:c7:6d:87:fd:b2:a0:c1:21:d6:2b:31:7e: 68:0e:b1:a1:86:91:0c:5b:b7:f5:a1:67:e8:11:2f:14:02:30: 62:f9:35:64:44:2b:c9:28:67:35:61:20:1e:2c:b2:25:cb:88: 1e:8c:d7:b6:6d:0f:aa:3d:62:3f:20:87:d6:86:36:25:5e:2a: 27:3a:2a:5e:97:0c:f8:8a:95:f6:b5:72 -----BEGIN CERTIFICATE----- MIICSjCCAdGgAwIBAgIBAzAKBggqhkjOPQQDAjAVMRMwEQYDVQQDDAoxMC45OS4w LjEwMB4XDTI1MDgwMzEyNTkyN1oXDTM1MDgwMTEyNTkyN1owFDESMBAGA1UEAwwJ dGVzdHVzZXIyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEiO38bUQOX/RzE1FsWM8/ l8azP8US/kAKz/9G2nOaNL3BuOZ/IdWtOTd7D8DMABdcKj46z0J9cn4rgoKdGaIl 5w48t2dmhBWJjmZNx9W+AOl180PGlMnIOrHR58AZ1Kfho4H1MIHyMAkGA1UdEwQC MAAwHQYDVR0OBBYEFAhOoj8HNtbdkRFLQ88OdWi/SayiMFAGA1UdIwRJMEeAFL/+ aThjgBnp1l04HSPnYYyvSuitoRmkFzAVMRMwEQYDVQQDDAoxMC45OS4wLjEwghRh D31gawTuMOsOr3dZNNYyRozshTAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUH AwIGCCsGAQUFBwMRMAsGA1UdDwQEAwIFoDA+BgNVHREENzA1gTN0ZXN0dXNlcjJA OTU0NmQ1NzQtM2ZkNi01OGY0LTlhYzYtMmM2OWNiNzU1ZGI3LmFsZ28wCgYIKoZI zj0EAwIDZwAwZAIwYBYjhZH8QPYQvFoIkXcwXREwrI/HbYf9sqDBIdYrMX5oDrGh hpEMW7f1oWfoES8UAjBi+TVkRCvJKGc1YSAeLLIly4gejNe2bQ+qPWI/IIfWhjYl XionOipelwz4ipX2tXI= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/certs/testuser2_crt_generated ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/ecparams/secp384r1.pem ================================================ -----BEGIN EC PARAMETERS----- BgUrgQQAIg== -----END EC PARAMETERS----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/index.txt ================================================ V 350801125927Z 01 unknown /CN=10.99.0.10 V 350801125927Z 02 unknown /CN=testuser1 V 350801125927Z 03 unknown /CN=testuser2 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/index.txt.attr ================================================ unique_subject = yes ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/index.txt.attr.old ================================================ unique_subject = yes ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/index.txt.old ================================================ V 350801125927Z 01 unknown /CN=10.99.0.10 V 350801125927Z 02 unknown /CN=testuser1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/openssl.cnf ================================================ # For use with Easy-RSA 3.0 and OpenSSL 1.0.* RANDFILE = .rnd #################################################################### [ ca ] default_ca = CA_default # The default ca section #################################################################### [ CA_default ] dir = . # Where everything is kept certs = $dir # Where the issued certs are kept crl_dir = $dir # Where the issued crl are kept database = $dir/index.txt # database index file. new_certs_dir = $dir/certs # default place for new certs. certificate = $dir/cacert.pem # The CA certificate serial = $dir/serial # The current serial number crl = $dir/crl.pem # The current CRL private_key = $dir/private/cakey.pem # The private key RANDFILE = $dir/private/.rand # private random number file x509_extensions = basic_exts # The extensions to add to the cert # This allows a V2 CRL. Ancient browsers don't like it, but anything Easy-RSA # is designed for will. In return, we get the Issuer attached to CRLs. crl_extensions = crl_ext default_days = 3650 # how long to certify for default_crl_days= 3650 # how long before next CRL default_md = sha256 # use public key default MD preserve = no # keep passed DN ordering # A few difference way of specifying how similar the request should look # For type CA, the listed attributes must be the same, and the optional # and supplied fields are just that :-) policy = policy_anything # For the 'anything' policy, which defines allowed DN fields [ policy_anything ] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = optional organizationalUnitName = optional commonName = supplied name = optional emailAddress = optional #################################################################### # Easy-RSA request handling # We key off $DN_MODE to determine how to format the DN [ req ] default_bits = 2048 default_keyfile = privkey.pem default_md = sha256 distinguished_name = cn_only x509_extensions = easyrsa_ca # The extensions to add to the self signed cert # A placeholder to handle the $EXTRA_EXTS feature: #%EXTRA_EXTS% # Do NOT remove or change this line as $EXTRA_EXTS support requires it #################################################################### # Easy-RSA DN (Subject) handling # Easy-RSA DN for cn_only support: [ cn_only ] commonName = Common Name (eg: your user, host, or server name) commonName_max = 64 commonName_default = 10.99.0.10 # Easy-RSA DN for org support: [ org ] countryName = Country Name (2 letter code) countryName_default = US countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = California localityName = Locality Name (eg, city) localityName_default = San Francisco 0.organizationName = Organization Name (eg, company) 0.organizationName_default = Copyleft Certificate Co organizationalUnitName = Organizational Unit Name (eg, section) organizationalUnitName_default = My Organizational Unit commonName = Common Name (eg: your user, host, or server name) commonName_max = 64 commonName_default = 10.99.0.10 emailAddress = Email Address emailAddress_default = me@example.net emailAddress_max = 64 #################################################################### # Easy-RSA cert extension handling # This section is effectively unused as the main script sets extensions # dynamically. This core section is left to support the odd usecase where # a user calls openssl directly. [ basic_exts ] basicConstraints = CA:FALSE subjectKeyIdentifier = hash authorityKeyIdentifier = keyid,issuer:always extendedKeyUsage = serverAuth,clientAuth,1.3.6.1.5.5.7.3.17 keyUsage = digitalSignature, keyEncipherment # The Easy-RSA CA extensions [ easyrsa_ca ] # PKIX recommendations: subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer:always basicConstraints = critical,CA:true,pathlen:0 nameConstraints = critical,permitted;IP:10.99.0.10/255.255.255.255,permitted;DNS:9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo,permitted;email:9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo,excluded;IP:0:0:0:0:0:0:0:0/0:0:0:0:0:0:0:0 # Limit key usage to CA tasks. If you really want to use the generated pair as # a self-signed cert, comment this out. keyUsage = cRLSign, keyCertSign # nsCertType omitted by default. Let's try to let the deprecated stuff die. # nsCertType = sslCA # CRL extensions. [ crl_ext ] # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. # issuerAltName=issuer:copy authorityKeyIdentifier=keyid:always,issuer:always ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/private/.rnd ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/private/10.99.0.10.key ================================================ -----BEGIN PRIVATE KEY----- MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDCzl0q5oCboLdR2z2+f 8vva98ZlmXOoJUoQ2PolcmYzsXLsrN9IJ5FA0dxwGSPSkGShZANiAARhGbPWo1Ja /zN9pnvuvGfA0bGAu8ByBvtDhi0rdmq53gL4LTAh0Ru219fjaZLj2ZFlR4IkaeFK zNErxUkwXTV/H2O/Uq6FUtpf6V4nRbnczeOZG9H2JHI1KL/kUQ1xZC4= -----END PRIVATE KEY----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/private/cakey.pem ================================================ -----BEGIN ENCRYPTED PRIVATE KEY----- MIIBEzBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIfcz2CPzqvHQCAggA MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECGnSWGAxVxG5BIHAug0MQFAsaf6G usnpuTDOgIq5RGgeHhakkknU/RQ2zsPlxOpM3y3c7fURahWqC6Po21M3Az37pRHs bf35e8/8Gxp7eRSyVoPF88MmxGVxFIDeP/YuzoGILLjIWDZ2E89SSP7GnzO1a4UV poHWMV4hZvpT/Ey+1LK2cu7zLbQ5chBZ4aeButXxDHLl5ylPe+yBCoforpLAr3iA zI0DNoOe25EoIBWPycT+c3tExVLGE0MN9RusBlaB6f0go2kSWhQU -----END ENCRYPTED PRIVATE KEY----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/private/testuser1.key ================================================ -----BEGIN PRIVATE KEY----- MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDqYZekavWtJL939gPZ UGvuag2088jWmu3Iic5hp1QfgdFqSiuk69Xmgc3nzin8ulGhZANiAASBTSJyLcX4 z1Lj4O/YhqnGy3zJZAQYnc4xw5mYThqOGVwlVniftIebwlHsgREegG37R9axSSVy mNrHLkgj1mDM2KmlqT8TM4ECEa1wF/buQe0LvtU5JR8MgaKgJadK5ec= -----END PRIVATE KEY----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/private/testuser2.key ================================================ -----BEGIN PRIVATE KEY----- MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDCNgvEKQSidzP9DtA5q bj3qD3sWPeNTZhJ319E9NTgGvU6GPSxssiPZglgDziO0ALqhZANiAASI7fxtRA5f 9HMTUWxYzz+XxrM/xRL+QArP/0bac5o0vcG45n8h1a05N3sPwMwAF1wqPjrPQn1y fiuCgp0ZoiXnDjy3Z2aEFYmOZk3H1b4A6XXzQ8aUycg6sdHnwBnUp+E= -----END PRIVATE KEY----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/public/testuser1.pub ================================================ ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBIFNInItxfjPUuPg79iGqcbLfMlkBBidzjHDmZhOGo4ZXCVWeJ+0h5vCUeyBER6AbftH1rFJJXKY2scuSCPWYMzYqaWpPxMzgQIRrXAX9u5B7Qu+1TklHwyBoqAlp0rl5w== ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/public/testuser2.pub ================================================ ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBIjt/G1EDl/0cxNRbFjPP5fGsz/FEv5ACs//RtpzmjS9wbjmfyHVrTk3ew/AzAAXXCo+Os9CfXJ+K4KCnRmiJecOPLdnZoQViY5mTcfVvgDpdfNDxpTJyDqx0efAGdSn4Q== ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/reqs/10.99.0.10.req ================================================ -----BEGIN CERTIFICATE REQUEST----- MIIBDTCBlAIBADAVMRMwEQYDVQQDDAoxMC45OS4wLjEwMHYwEAYHKoZIzj0CAQYF K4EEACIDYgAEYRmz1qNSWv8zfaZ77rxnwNGxgLvAcgb7Q4YtK3Zqud4C+C0wIdEb ttfX42mS49mRZUeCJGnhSszRK8VJMF01fx9jv1KuhVLaX+leJ0W53M3jmRvR9iRy NSi/5FENcWQuoAAwCgYIKoZIzj0EAwIDaAAwZQIxANzofzNNOzBP5IxqtGOs9l53 aNpmDf638Ho6lXdXRtGynUyZ9ORoeIANVN4Kb/HbTQIwQndvZ4PIPvCp1QW1LmP5 kPd+OFyoyiJavLa9zRJsuAsYaj5NQucZJHKxLqWdGB94 -----END CERTIFICATE REQUEST----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/reqs/testuser1.req ================================================ -----BEGIN CERTIFICATE REQUEST----- MIIBDDCBkwIBADAUMRIwEAYDVQQDDAl0ZXN0dXNlcjEwdjAQBgcqhkjOPQIBBgUr gQQAIgNiAASBTSJyLcX4z1Lj4O/YhqnGy3zJZAQYnc4xw5mYThqOGVwlVniftIeb wlHsgREegG37R9axSSVymNrHLkgj1mDM2KmlqT8TM4ECEa1wF/buQe0LvtU5JR8M gaKgJadK5eegADAKBggqhkjOPQQDAgNoADBlAjEA6fukMpfRV9EguhFUu2ArTEUi y3wjuRlz0oOX1Al4bDdl0fI8fdGPhfWMkCFV99h1AjASgmIyTUBBShipXCq1zXYG yneN1AXvkW4sbdFZ55GC++fGyZo9uOiTj/NEpn52a1E= -----END CERTIFICATE REQUEST----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/reqs/testuser2.req ================================================ -----BEGIN CERTIFICATE REQUEST----- MIIBDTCBkwIBADAUMRIwEAYDVQQDDAl0ZXN0dXNlcjIwdjAQBgcqhkjOPQIBBgUr gQQAIgNiAASI7fxtRA5f9HMTUWxYzz+XxrM/xRL+QArP/0bac5o0vcG45n8h1a05 N3sPwMwAF1wqPjrPQn1yfiuCgp0ZoiXnDjy3Z2aEFYmOZk3H1b4A6XXzQ8aUycg6 sdHnwBnUp+GgADAKBggqhkjOPQQDAgNpADBmAjEA/pC5b5Ei8Hmfgsl5WHfOhV/r iReLin1RESK29Lcsxi6z2pvEGNkOFCq8tPJHr1L6AjEAuq9eBom5P0D8d+9MJcKt 3Zjtfb6Liyyupd2euSytyFKuY6NnbjMvAR4kZ3jhdw30 -----END CERTIFICATE REQUEST----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/serial ================================================ 04 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/serial.old ================================================ 03 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/.pki/serial_generated ================================================ ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/apple/testuser1.mobileconfig ================================================ PayloadContent IKEv2 OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Certificate ChildSecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 DeadPeerDetectionRate Medium DisableMOBIKE 0 DisableRedirect 1 EnableCertificateRevocationCheck 0 EnablePFS IKESecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 LocalIdentifier testuser1@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo PayloadCertificateUUID 4D4440E7-BA3F-57CE-AC2A-8599F30E0D0F CertificateType ECDSA384 ServerCertificateIssuerCommonName 10.99.0.10 RemoteAddress 10.99.0.10 RemoteIdentifier 10.99.0.10 UseConfigurationAttributeInternalIPSubnet 0 IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.839A7948-0024-5CE8-B26D-051C798F53F2 PayloadType com.apple.vpn.managed PayloadUUID 839A7948-0024-5CE8-B26D-051C798F53F2 PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server IKEv2 VPNType IKEv2 Password test_p12_password_123 PayloadCertificateFileName testuser1.p12 PayloadContent MIIEyQIBAzCCBI8GCSqGSIb3DQEHAaCCBIAEggR8MIIEeDCCAxcGCSqGSIb3DQEHBqCCAwgwggME AgEAMIIC/QYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI28pyp8KzMlACAggAgIIC0M5dcNtX /i2WQqXbb0momxCL+Vhyv4wUg/a5sjcV2n/P36NtG073yfPMek2lr+1yJNpTvmp/ur577DBPT7gN r7+FSHeq56TWIyakAKDipt0NTg+FuUJk4FYvlCmeZwtD1hZIzit293s6/+ZFDvkFnGDIv3eRzblh KE9zcK6UT+euDRnhOPPER8H9qJ9/yepcRIOS8jy7jF2NfLyMlyme/9q7062zhi4gejmlX5p/qoco cJgvbEEH8EpwakNmfaVx+LZS5zMIRSjomcTS2R70HoFJkaI051iZs/nTUhdWSULxr6VpeyVA/rJZ Ar6WEYrV+Pp6DWIA+hos6R5T8qb57zA989xjKckly7Ac5PXPScvIaxg9nxNcunsRDAgajsFkJ5EN ItzmEUt5eb0IcAIGwA2Y6PGn6UB6+65EnTp6yaB2UYA6E0U+sYO87ztnXfR3Qq8bHNDul26Gy4Va FkZ1wGuvUiFb7Kp96fGtWP1RHQ+W/Nh62dmTy1F2KleQ+F8APbSlZ0NkGsnkvWqVHh0igIL8YQCu SlAK6OM7OLWC0ep8q4+KoRZlpzZV4ubW1H7RVNPO/aaib++2h1aLWdhqxkeT9+X8Ux1s9pROLXKE j4DLWkjRoNd/ahN5wFdjS2qe59i3/EbNtp+hJJtlhsEVKwTjfFV8pKMJ0iRBQMtMkeUcQbtHhXid IqoHDFRJ7UL5r7odu1/3cqQLDSBApoJQp5I1gqsdzr3N7a+mJM98wVVPutL7DdfWTbEkDeYX0ItX gr5eus+0ZJoSB2d8zXlxyDQMvgNKiAxS2nnlyL8W45lhT6Gab1EkNnNLJs4aM9F2xcueo/DX9PpD bTI72l5u8km0ZB457tpF3HcK4uTcwqbYohUHK5gnKhQHtkQGxjOAk1mYrAJic/pl21R47R44WcJg SPlfPyCBu181R4ttQzI+wWaUWw0doOYMDXBQIoodZzCCAVkGCSqGSIb3DQEHAaCCAUoEggFGMIIB QjCCAT4GCyqGSIb3DQEMCgECoIHkMIHhMBwGCiqGSIb3DQEMAQMwDgQI147nWZq98I0CAggABIHA K3r5QS9SZIqobu0QbwvRzKGevyi7Xdau6ytuvKxb5HzEl1h9OjeoErgDAf4QCxGr2zq+KHjE78BP 2LOJrHd34bYhuZl1R19tZWDL40wlwspjfhsFvKiG6lg4o2KaCv5QNzApDaUvj0vg52R0IRF1qEol zpUS6+7/JA6IQ0dZMX/VWItPbNxxj5eHtFryz362QlMoqOiej5xWGoAaJcAHU44gtouL5SUEpA+m lt/L8Sqm3f8R9PoU803udHPMH7twMUgwIQYJKoZIhvcNAQkUMRQeEgB0AGUAcwB0AHUAcwBlAHIA MTAjBgkqhkiG9w0BCRUxFgQUQCD/6T8AKsHvofJ4aXb4gw6a/SwwMTAhMAkGBSsOAwIaBQAEFOj7 6u6lFCM5E2gXomAOVFPWqjwxBAgfPysUA1IgqgICCAA= PayloadDescription Adds a PKCS#12-formatted certificate PayloadDisplayName algo-test-server PayloadIdentifier com.apple.security.pkcs12.4D4440E7-BA3F-57CE-AC2A-8599F30E0D0F PayloadType com.apple.security.pkcs12 PayloadUUID 4D4440E7-BA3F-57CE-AC2A-8599F30E0D0F PayloadVersion 1 PayloadCertificateFileName ca.crt PayloadContent LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNvVENDQWlhZ0F3SUJBZ0lVWVE5OVlHc0U3akRyRHE5M1dUVFdNa2FNN0lVd0NnWUlLb1pJemowRUF3SXcKRlRFVE1CRUdBMVVFQXd3S01UQXVPVGt1TUM0eE1EQWVGdzB5TlRBNE1ETXhNalU1TWpkYUZ3MHpOVEE0TURFeApNalU1TWpkYU1CVXhFekFSQmdOVkJBTU1DakV3TGprNUxqQXVNVEF3ZGpBUUJnY3Foa2pPUFFJQkJnVXJnUVFBCklnTmlBQVNBMkpZSVJIVEhxTW5yR0NvSUZnOFJWejN2MlFkakdKbmtGM2YySWE0cy9WNUxhUCtXUDBQaERFRjMKcFZIUnpIS2QybnRrMERCUk5PaWgrL0JpUStsUWhmRVQ4dFdIK21mQWswSGVtc2dSelJJR2FkeFBWeGkxcGlxSgpzTDh1V1U2amdnRTFNSUlCTVRBZEJnTlZIUTRFRmdRVXYvNXBPR09BR2VuV1hUZ2RJK2Roaks5SzZLMHdVQVlEClZSMGpCRWt3UjRBVXYvNXBPR09BR2VuV1hUZ2RJK2Roaks5SzZLMmhHYVFYTUJVeEV6QVJCZ05WQkFNTUNqRXcKTGprNUxqQXVNVENDRkdFUGZXQnJCTzR3Nnc2dmQxazAxakpHak95Rk1CSUdBMVVkRXdFQi93UUlNQVlCQWY4QwpBUUF3Z1p3R0ExVWRIZ0VCL3dTQmtUQ0JqcUJtTUFxSENBcGpBQXIvLy8vL01DdUNLVGsxTkRaa05UYzBMVE5tClpEWXROVGhtTkMwNVlXTTJMVEpqTmpsallqYzFOV1JpTnk1aGJHZHZNQ3VCS1RrMU5EWmtOVGMwTFRObVpEWXQKTlRobU5DMDVZV00yTFRKak5qbGpZamMxTldSaU55NWhiR2R2b1NRd0lvY2dBQUFBQUFBQUFBQUFBQUFBQUFBQQpBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQXdDd1lEVlIwUEJBUURBZ0VHTUFvR0NDcUdTTTQ5QkFNQ0Eya0FNR1lDCk1RQ3NXUU9pbmhoczR5WlNPdnVwUElRS3c3aE1wS2tFaUtTNlJ0UmZydlpvaEdRSzkyT0tYc0VUTGQ3WVBoM04KUkJBQ01RQzhXQWUzNVBYY2crSlk4cGFkcmk0ZC91MklUcmVDWEFSdWhVanlwbStVY3kxcVE1QTE4d2pqNi9LVgpKSllsYmZrPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t PayloadDescription Adds a CA root certificate PayloadDisplayName algo-test-server PayloadIdentifier com.apple.security.root.E7564B4A-5330-5501-B969-5D4E0B05D3D4 PayloadType com.apple.security.root PayloadUUID E7564B4A-5330-5501-B969-5D4E0B05D3D4 PayloadVersion 1 PayloadDisplayName AlgoVPN algo-test-server IKEv2 PayloadIdentifier donut.local.E3BD8AD2-344A-5707-9514-8898A03E555C PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID ACE477A4-56E1-59E8-9D4E-C695588E71BB PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/apple/testuser2.mobileconfig ================================================ PayloadContent IKEv2 OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Certificate ChildSecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 DeadPeerDetectionRate Medium DisableMOBIKE 0 DisableRedirect 1 EnableCertificateRevocationCheck 0 EnablePFS IKESecurityAssociationParameters DiffieHellmanGroup 20 EncryptionAlgorithm AES-256-GCM IntegrityAlgorithm SHA2-512 LifeTimeInMinutes 1440 LocalIdentifier testuser2@9546d574-3fd6-58f4-9ac6-2c69cb755db7.algo PayloadCertificateUUID 9866F575-85ED-5B44-80DE-BB927BD9613D CertificateType ECDSA384 ServerCertificateIssuerCommonName 10.99.0.10 RemoteAddress 10.99.0.10 RemoteIdentifier 10.99.0.10 UseConfigurationAttributeInternalIPSubnet 0 IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.A50D0C60-F894-5E6A-85F3-404CB79BF2E6 PayloadType com.apple.vpn.managed PayloadUUID A50D0C60-F894-5E6A-85F3-404CB79BF2E6 PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server IKEv2 VPNType IKEv2 Password test_p12_password_123 PayloadCertificateFileName testuser2.p12 PayloadContent MIIEyQIBAzCCBI8GCSqGSIb3DQEHAaCCBIAEggR8MIIEeDCCAxcGCSqGSIb3DQEHBqCCAwgwggME AgEAMIIC/QYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI7AzVUTPoH5gCAggAgIIC0Eh7jsVz wJ4vttaZ17WC5tLqxMUCZJs35Vs/hidCKrTnSRw9/Sc4kIiNRrP5tPZIKpldKeDmPdCUFM+n0mP6 2rg7pI3nJm2kZ/9BusAwrokbekpHEJJRPJ4B2T5g+935Rc8xdNAasX1n6a+oyIwhVnAJ+4UAUF4u ISdQqxtPvl9oxfALSQD7CatKmvYqtNNsFbL0+5tGaRXhhB7IcHUy1Vyg7XWSgOXUtZEpYKcI60MB BKVCW0RA9pPniSu8WqDa+lADRrohK0+w2M40IiZtMpXAYQ+1MDIRj7ELVDdeUd+55dR4Y3qSz2lW Jn9rOk89bSQL4mO/Mfc7lZpWgp9R2HvTqL/MjDgzax3JsUNlotSM2dWDXvcoe/cLTnFD6GTi46O2 VCpPcVDF27urhKH9pR6ny3xdHNkMmKPzzxzQK+5uepZOK5MkkBqGql/hmO1nqrNAc4k9kwd2zwNb PzNiavtd1IpBjRUZkbZhqj2QzStTdtw+y5AdGhwBdDRn+vYmbjZQPMQ7VNKtiZrw8L+SSM6X5LE6 UvSZYJCNDCsH73UZl8UuCxajBOz3eEvkjyCTjjJt6L93ImXCUN5ilOyUReks8oaf8xp6X3mjI2JA QUhozvpItwMdwHJov6l8VhduXz4E0v2JxsN5hVhXRD4+5+DYGwn73j1BOIMeCdSF8WtYZa9IfBoZ KO1YRg72zHJrsPgrbU0BaOG6AtPTlmqN7VmWIY3vWr2HC5wiWVokfXPBSra+ZIQWU/gnQmXncaHu Dm6kqLjKrvhfS02mIT8znS1ugaJTW7MwfK66grMV/x38c8RMVwZMQxERuB4It8fh0zzlLv3AQVSZ FEzopwiDnfLgv6vrBuggs1tv82n8stFMen8DXavdPNSfQKyzBlnYm5z5FNlrhAxUYL4MdRNkKnhW 0Jf8mGzYt8pBFvcfKcsoQlM1EQn9/sWGXPJdZ8UXWzCCAVkGCSqGSIb3DQEHAaCCAUoEggFGMIIB QjCCAT4GCyqGSIb3DQEMCgECoIHkMIHhMBwGCiqGSIb3DQEMAQMwDgQIvFLqFNDnPxACAggABIHA Ri++0U1QcA0tnOkTPmCpWiw9qsm7AOJHzuzawhfmaB86H4/ACo4Aav1bM09Bqg+MZEgfNuieM4aO JT+SNAbRnVwkM/RAljnbW8tSpUlvBcFFoj4v740LfDjG/iPyJenvfsbRJ+7VnxqlsDIrtIiZ7F0t t4GH42OrjSRUmhqKYCcl+fOb6/ySkvCT9SCLaLDbsUlI4cpX1/xz0rx2CgB7P/BeqUMgOvUS0c9g AmrBS4MBX8XQHr3LeHU/gThLOzwuMUgwIQYJKoZIhvcNAQkUMRQeEgB0AGUAcwB0AHUAcwBlAHIA MjAjBgkqhkiG9w0BCRUxFgQUAiLn79PjWAqhawRgUdGc+ONhzlgwMTAhMAkGBSsOAwIaBQAEFMxN NnIveviZbPfIBVfQwieHIxmuBAj+zP2SHawgAAICCAA= PayloadDescription Adds a PKCS#12-formatted certificate PayloadDisplayName algo-test-server PayloadIdentifier com.apple.security.pkcs12.9866F575-85ED-5B44-80DE-BB927BD9613D PayloadType com.apple.security.pkcs12 PayloadUUID 9866F575-85ED-5B44-80DE-BB927BD9613D PayloadVersion 1 PayloadCertificateFileName ca.crt PayloadContent LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNvVENDQWlhZ0F3SUJBZ0lVWVE5OVlHc0U3akRyRHE5M1dUVFdNa2FNN0lVd0NnWUlLb1pJemowRUF3SXcKRlRFVE1CRUdBMVVFQXd3S01UQXVPVGt1TUM0eE1EQWVGdzB5TlRBNE1ETXhNalU1TWpkYUZ3MHpOVEE0TURFeApNalU1TWpkYU1CVXhFekFSQmdOVkJBTU1DakV3TGprNUxqQXVNVEF3ZGpBUUJnY3Foa2pPUFFJQkJnVXJnUVFBCklnTmlBQVNBMkpZSVJIVEhxTW5yR0NvSUZnOFJWejN2MlFkakdKbmtGM2YySWE0cy9WNUxhUCtXUDBQaERFRjMKcFZIUnpIS2QybnRrMERCUk5PaWgrL0JpUStsUWhmRVQ4dFdIK21mQWswSGVtc2dSelJJR2FkeFBWeGkxcGlxSgpzTDh1V1U2amdnRTFNSUlCTVRBZEJnTlZIUTRFRmdRVXYvNXBPR09BR2VuV1hUZ2RJK2Roaks5SzZLMHdVQVlEClZSMGpCRWt3UjRBVXYvNXBPR09BR2VuV1hUZ2RJK2Roaks5SzZLMmhHYVFYTUJVeEV6QVJCZ05WQkFNTUNqRXcKTGprNUxqQXVNVENDRkdFUGZXQnJCTzR3Nnc2dmQxazAxakpHak95Rk1CSUdBMVVkRXdFQi93UUlNQVlCQWY4QwpBUUF3Z1p3R0ExVWRIZ0VCL3dTQmtUQ0JqcUJtTUFxSENBcGpBQXIvLy8vL01DdUNLVGsxTkRaa05UYzBMVE5tClpEWXROVGhtTkMwNVlXTTJMVEpqTmpsallqYzFOV1JpTnk1aGJHZHZNQ3VCS1RrMU5EWmtOVGMwTFRObVpEWXQKTlRobU5DMDVZV00yTFRKak5qbGpZamMxTldSaU55NWhiR2R2b1NRd0lvY2dBQUFBQUFBQUFBQUFBQUFBQUFBQQpBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQXdDd1lEVlIwUEJBUURBZ0VHTUFvR0NDcUdTTTQ5QkFNQ0Eya0FNR1lDCk1RQ3NXUU9pbmhoczR5WlNPdnVwUElRS3c3aE1wS2tFaUtTNlJ0UmZydlpvaEdRSzkyT0tYc0VUTGQ3WVBoM04KUkJBQ01RQzhXQWUzNVBYY2crSlk4cGFkcmk0ZC91MklUcmVDWEFSdWhVanlwbStVY3kxcVE1QTE4d2pqNi9LVgpKSllsYmZrPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t PayloadDescription Adds a CA root certificate PayloadDisplayName algo-test-server PayloadIdentifier com.apple.security.root.C09491AA-8ED1-5327-A61F-81CE4E3A686C PayloadType com.apple.security.root PayloadUUID C09491AA-8ED1-5327-A61F-81CE4E3A686C PayloadVersion 1 PayloadDisplayName AlgoVPN algo-test-server IKEv2 PayloadIdentifier donut.local.95AC5C22-8E5B-5049-A6E0-247F765E8548 PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID 79370BB1-869C-5F0E-B5E4-F8332DF530E9 PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/manual/cacert.pem ================================================ -----BEGIN CERTIFICATE----- MIICoTCCAiagAwIBAgIUYQ99YGsE7jDrDq93WTTWMkaM7IUwCgYIKoZIzj0EAwIw FTETMBEGA1UEAwwKMTAuOTkuMC4xMDAeFw0yNTA4MDMxMjU5MjdaFw0zNTA4MDEx MjU5MjdaMBUxEzARBgNVBAMMCjEwLjk5LjAuMTAwdjAQBgcqhkjOPQIBBgUrgQQA IgNiAASA2JYIRHTHqMnrGCoIFg8RVz3v2QdjGJnkF3f2Ia4s/V5LaP+WP0PhDEF3 pVHRzHKd2ntk0DBRNOih+/BiQ+lQhfET8tWH+mfAk0HemsgRzRIGadxPVxi1piqJ sL8uWU6jggE1MIIBMTAdBgNVHQ4EFgQUv/5pOGOAGenWXTgdI+dhjK9K6K0wUAYD VR0jBEkwR4AUv/5pOGOAGenWXTgdI+dhjK9K6K2hGaQXMBUxEzARBgNVBAMMCjEw Ljk5LjAuMTCCFGEPfWBrBO4w6w6vd1k01jJGjOyFMBIGA1UdEwEB/wQIMAYBAf8C AQAwgZwGA1UdHgEB/wSBkTCBjqBmMAqHCApjAAr/////MCuCKTk1NDZkNTc0LTNm ZDYtNThmNC05YWM2LTJjNjljYjc1NWRiNy5hbGdvMCuBKTk1NDZkNTc0LTNmZDYt NThmNC05YWM2LTJjNjljYjc1NWRiNy5hbGdvoSQwIocgAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAwCwYDVR0PBAQDAgEGMAoGCCqGSM49BAMCA2kAMGYC MQCsWQOinhhs4yZSOvupPIQKw7hMpKkEiKS6RtRfrvZohGQK92OKXsETLd7YPh3N RBACMQC8WAe35PXcg+JY8padri4d/u2ITreCXARuhUjypm+Ucy1qQ5A18wjj6/KV JJYlbfk= -----END CERTIFICATE----- ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/manual/testuser1.conf ================================================ conn algovpn-10.99.0.10 fragmentation=yes rekey=no dpdaction=clear keyexchange=ikev2 compress=no dpddelay=35s ike=aes256gcm16-prfsha512-ecp384! esp=aes256gcm16-ecp384! right=10.99.0.10 rightid=10.99.0.10 rightsubnet=0.0.0.0/0 rightauth=pubkey leftsourceip=%config leftauth=pubkey leftcert=testuser1.crt leftfirewall=yes left=%defaultroute auto=add ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/manual/testuser1.secrets ================================================ 10.99.0.10 : ECDSA testuser1.key ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/manual/testuser2.conf ================================================ conn algovpn-10.99.0.10 fragmentation=yes rekey=no dpdaction=clear keyexchange=ikev2 compress=no dpddelay=35s ike=aes256gcm16-prfsha512-ecp384! esp=aes256gcm16-ecp384! right=10.99.0.10 rightid=10.99.0.10 rightsubnet=0.0.0.0/0 rightauth=pubkey leftsourceip=%config leftauth=pubkey leftcert=testuser2.crt leftfirewall=yes left=%defaultroute auto=add ================================================ FILE: tests/integration/test-configs/10.99.0.10/ipsec/manual/testuser2.secrets ================================================ 10.99.0.10 : ECDSA testuser2.key ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/index.txt ================================================ testuser1 testuser2 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/preshared/10.99.0.10 ================================================ Ggpzqj5CnamCMBaKQCC+xih3lfj+I1tOfImOizyDLkA= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/preshared/testuser1 ================================================ CSLeU66thNW52DkY6MVJ2A5VodnxbsC7EklcrHPCKco= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/preshared/testuser2 ================================================ WUuCbhaOJfPtCrwU4EnlpqVmmPuaJJYYyzc2sy+afVQ= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/private/10.99.0.10 ================================================ EPokMfsIC6Heg4/tm9gaMt2rRwXjACwvmdJAXO/byH8= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/private/testuser1 ================================================ OC3EYbHLzszqmYqFlC22bnPDoTHp4ORULg9vCphbcEY= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/private/testuser2 ================================================ yKU40Lrt5xutKuXHcJipej0wdqPVExuGmjoPzBar/GI= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/public/10.99.0.10 ================================================ IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/public/testuser1 ================================================ yoUuE/xoUE4bbR4enH9lmOc+lLB0mecK6ifMwiajDz4= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/.pki/public/testuser2 ================================================ zJ76JrM4mYQk8QIGMIZy9V9lORvw75lh3ByhgXbH1kA= ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/apple/ios/testuser1.mobileconfig ================================================ PayloadContent IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.algo-test-server9D18FBEE-C185-5F8B-9A48-C873BB65BB8E PayloadType com.apple.vpn.managed PayloadUUID algo-test-server9D18FBEE-C185-5F8B-9A48-C873BB65BB8E PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server VPN OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Password RemoteAddress 10.99.0.10:51820 VPNSubType com.wireguard.ios VPNType VPN VendorConfig WgQuickConfig [Interface] PrivateKey = OC3EYbHLzszqmYqFlC22bnPDoTHp4ORULg9vCphbcEY= Address = 10.19.49.2 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = CSLeU66thNW52DkY6MVJ2A5VodnxbsC7EklcrHPCKco= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 PayloadDisplayName AlgoVPN algo-test-server WireGuard PayloadIdentifier donut.local.D503FCD6-107F-5C1A-94C2-EE8821F144CD PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID 2B1947FC-5FDD-56F5-8C60-E553E7F8C788 PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/apple/ios/testuser2.mobileconfig ================================================ PayloadContent IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.algo-test-server9D18FBEE-C185-5F8B-9A48-C873BB65BB8E PayloadType com.apple.vpn.managed PayloadUUID algo-test-server9D18FBEE-C185-5F8B-9A48-C873BB65BB8E PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server VPN OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Password RemoteAddress 10.99.0.10:51820 VPNSubType com.wireguard.ios VPNType VPN VendorConfig WgQuickConfig [Interface] PrivateKey = yKU40Lrt5xutKuXHcJipej0wdqPVExuGmjoPzBar/GI= Address = 10.19.49.3 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = WUuCbhaOJfPtCrwU4EnlpqVmmPuaJJYYyzc2sy+afVQ= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 PayloadDisplayName AlgoVPN algo-test-server WireGuard PayloadIdentifier donut.local.45803596-C851-5118-8AD2-563672058D8F PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID AAAFB2ED-1F04-5973-85B6-5C0F8E63ABF1 PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/apple/macos/testuser1.mobileconfig ================================================ PayloadContent IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.algo-test-server3B9A4690-0B5D-5BC3-A5C5-21305566D87F PayloadType com.apple.vpn.managed PayloadUUID algo-test-server3B9A4690-0B5D-5BC3-A5C5-21305566D87F PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server VPN OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Password RemoteAddress 10.99.0.10:51820 VPNSubType com.wireguard.macos VPNType VPN VendorConfig WgQuickConfig [Interface] PrivateKey = OC3EYbHLzszqmYqFlC22bnPDoTHp4ORULg9vCphbcEY= Address = 10.19.49.2 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = CSLeU66thNW52DkY6MVJ2A5VodnxbsC7EklcrHPCKco= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 PayloadDisplayName AlgoVPN algo-test-server WireGuard PayloadIdentifier donut.local.9D99E158-71EF-58AB-A74C-CC609791EEBF PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID ADE17621-2434-5FE8-995B-C2531F35DCCB PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/apple/macos/testuser2.mobileconfig ================================================ PayloadContent IPv4 OverridePrimary 1 PayloadDescription Configures VPN settings PayloadDisplayName algo-test-server PayloadIdentifier com.apple.vpn.managed.algo-test-server3B9A4690-0B5D-5BC3-A5C5-21305566D87F PayloadType com.apple.vpn.managed PayloadUUID algo-test-server3B9A4690-0B5D-5BC3-A5C5-21305566D87F PayloadVersion 1 Proxies HTTPEnable 0 HTTPSEnable 0 UserDefinedName AlgoVPN algo-test-server VPN OnDemandEnabled 0 OnDemandRules Action Connect AuthenticationMethod Password RemoteAddress 10.99.0.10:51820 VPNSubType com.wireguard.macos VPNType VPN VendorConfig WgQuickConfig [Interface] PrivateKey = yKU40Lrt5xutKuXHcJipej0wdqPVExuGmjoPzBar/GI= Address = 10.19.49.3 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = WUuCbhaOJfPtCrwU4EnlpqVmmPuaJJYYyzc2sy+afVQ= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 PayloadDisplayName AlgoVPN algo-test-server WireGuard PayloadIdentifier donut.local.B177D923-93FA-5491-8B28-20964A3892A6 PayloadOrganization AlgoVPN PayloadRemovalDisallowed PayloadType Configuration PayloadUUID B1842E16-8F73-571B-A3FE-5A150D955F29 PayloadVersion 1 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/testuser1.conf ================================================ [Interface] PrivateKey = OC3EYbHLzszqmYqFlC22bnPDoTHp4ORULg9vCphbcEY= Address = 10.19.49.2 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = CSLeU66thNW52DkY6MVJ2A5VodnxbsC7EklcrHPCKco= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 ================================================ FILE: tests/integration/test-configs/10.99.0.10/wireguard/testuser2.conf ================================================ [Interface] PrivateKey = yKU40Lrt5xutKuXHcJipej0wdqPVExuGmjoPzBar/GI= Address = 10.19.49.3 DNS = 8.8.8.8,8.8.4.4 [Peer] PublicKey = IJFSpegTMGKoK5EtJaX2uH/hBWxq8ZpNOJIBMZnE4w0= PresharedKey = WUuCbhaOJfPtCrwU4EnlpqVmmPuaJJYYyzc2sy+afVQ= AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.99.0.10:51820 ================================================ FILE: tests/integration/test-run.log ================================================ Building Docker images... #1 [internal] load local bake definitions #1 reading from stdin 1.57kB done #1 DONE 0.0s #2 [client-ubuntu internal] load build definition from Dockerfile.client-ubuntu #2 transferring dockerfile: 716B done #2 DONE 0.0s #3 [algo-server internal] load build definition from Dockerfile.server #3 transferring dockerfile: 1.01kB done #3 DONE 0.0s #4 [client-debian internal] load build definition from Dockerfile.client-debian #4 transferring dockerfile: 713B done #4 DONE 0.0s #5 [algo-server internal] load metadata for docker.io/library/ubuntu:22.04 #5 DONE 0.3s #6 [client-ubuntu internal] load .dockerignore #6 transferring context: 248B done #6 DONE 0.0s #7 [client-ubuntu 1/6] FROM docker.io/library/ubuntu:22.04@sha256:1ec65b2719518e27d4d25f104d93f9fac60dc437f81452302406825c46fcc9cb #7 DONE 0.0s #8 [client-ubuntu internal] load build context #8 transferring context: 122B 0.0s done #8 DONE 0.0s #9 [client-ubuntu 4/6] COPY tests/integration/client-test-utils.sh /usr/local/bin/test-utils.sh #9 CACHED #10 [client-ubuntu 3/6] RUN mkdir -p /etc/wireguard /etc/swanctl #10 CACHED #11 [client-ubuntu 2/6] RUN apt-get update && apt-get install -y wireguard wireguard-tools strongswan strongswan-swanctl iproute2 iputils-ping dnsutils curl tcpdump net-tools iptables && rm -rf /var/lib/apt/lists/* #11 CACHED #12 [client-ubuntu 5/6] RUN chmod +x /usr/local/bin/test-utils.sh #12 CACHED #13 [client-ubuntu 6/6] WORKDIR /root #13 CACHED #14 [algo-server internal] load build context #14 transferring context: 23.33kB 0.0s done #14 DONE 0.0s #15 [algo-server 2/8] RUN apt-get update && apt-get install -y python3 python3-pip python3-venv ansible wireguard wireguard-tools strongswan strongswan-swanctl strongswan-pki iptables iproute2 openssl curl dnsutils iputils-ping net-tools sudo kmod && rm -rf /var/lib/apt/lists/* #15 CACHED #16 [algo-server 3/8] WORKDIR /algo #16 CACHED #17 [client-ubuntu] exporting to image #17 exporting layers done #17 writing image sha256:059dedd3689f34422b93aa1debd7772e35ebb1d79c249d46a8dedde010b72272 done #17 naming to docker.io/library/integration-client-ubuntu done #17 DONE 0.0s #18 [client-ubuntu] resolving provenance for metadata file #18 DONE 0.0s #19 [algo-server 4/8] COPY . /algo/ #19 DONE 0.0s #20 [client-debian internal] load metadata for docker.io/library/debian:12 #20 DONE 0.5s #6 [client-debian internal] load .dockerignore #6 transferring context: 248B done #6 DONE 0.0s #21 [client-debian 1/6] FROM docker.io/library/debian:12@sha256:b6507e340c43553136f5078284c8c68d86ec8262b1724dde73c325e8d3dcdeba #21 DONE 0.0s #8 [client-debian internal] load build context #8 DONE 0.0s #22 [client-debian 2/6] RUN apt-get update && apt-get install -y wireguard wireguard-tools strongswan strongswan-swanctl iproute2 iputils-ping dnsutils curl tcpdump net-tools iptables && rm -rf /var/lib/apt/lists/* #22 CACHED #23 [client-debian 5/6] RUN chmod +x /usr/local/bin/test-utils.sh #23 CACHED #24 [client-debian 3/6] RUN mkdir -p /etc/wireguard /etc/swanctl #24 CACHED #25 [client-debian 4/6] COPY tests/integration/client-test-utils.sh /usr/local/bin/test-utils.sh #25 CACHED #26 [client-debian 6/6] WORKDIR /root #26 CACHED #27 [client-debian] exporting to image #27 exporting layers done #27 writing image sha256:729aab21a679247723575dee700bcf3a114b84293bfe165cd2f733312b3bf016 done #27 naming to docker.io/library/integration-client-debian done #27 DONE 0.0s #28 [client-debian] resolving provenance for metadata file #28 DONE 0.0s #29 [algo-server 5/8] RUN python3 -m pip install --upgrade pip && pip3 install -r requirements.txt #29 0.263 Requirement already satisfied: pip in /usr/lib/python3/dist-packages (22.0.2) #29 0.352 Collecting pip #29 0.442 Downloading pip-25.2-py3-none-any.whl (1.8 MB) #29 0.589 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 12.0 MB/s eta 0:00:00 #29 0.613 Installing collected packages: pip #29 0.613 Attempting uninstall: pip #29 0.613 Found existing installation: pip 22.0.2 #29 0.614 Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr #29 0.614 Can't uninstall 'pip'. No files were found to uninstall. #29 0.934 Successfully installed pip-25.2 #29 0.934 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv #29 1.212 Collecting ansible==9.1.0 (from -r requirements.txt (line 1)) #29 1.240 Downloading ansible-9.1.0-py3-none-any.whl.metadata (7.9 kB) #29 1.256 Collecting jinja2~=3.1.3 (from -r requirements.txt (line 2)) #29 1.265 Downloading jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB) #29 1.267 Requirement already satisfied: netaddr in /usr/lib/python3/dist-packages (from -r requirements.txt (line 3)) (0.8.0) #29 1.298 Collecting ansible-core~=2.16.1 (from ansible==9.1.0->-r requirements.txt (line 1)) #29 1.305 Downloading ansible_core-2.16.14-py3-none-any.whl.metadata (6.9 kB) #29 1.308 Requirement already satisfied: MarkupSafe>=2.0 in /usr/lib/python3/dist-packages (from jinja2~=3.1.3->-r requirements.txt (line 2)) (2.0.1) #29 1.311 Requirement already satisfied: PyYAML>=5.1 in /usr/lib/python3/dist-packages (from ansible-core~=2.16.1->ansible==9.1.0->-r requirements.txt (line 1)) (5.4.1) #29 1.311 Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible-core~=2.16.1->ansible==9.1.0->-r requirements.txt (line 1)) (3.4.8) #29 1.311 Requirement already satisfied: packaging in /usr/lib/python3/dist-packages (from ansible-core~=2.16.1->ansible==9.1.0->-r requirements.txt (line 1)) (21.3) #29 1.327 Collecting resolvelib<1.1.0,>=0.5.3 (from ansible-core~=2.16.1->ansible==9.1.0->-r requirements.txt (line 1)) #29 1.336 Downloading resolvelib-1.0.1-py2.py3-none-any.whl.metadata (4.0 kB) #29 1.349 Downloading ansible-9.1.0-py3-none-any.whl (48.1 MB) #29 4.967 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.1/48.1 MB 13.3 MB/s 0:00:03 #29 4.979 Downloading jinja2-3.1.6-py3-none-any.whl (134 kB) #29 4.997 Downloading ansible_core-2.16.14-py3-none-any.whl (2.3 MB) #29 5.182 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 12.2 MB/s 0:00:00 #29 5.197 Downloading resolvelib-1.0.1-py2.py3-none-any.whl (17 kB) #29 5.348 Installing collected packages: resolvelib, jinja2, ansible-core, ansible #29 5.354 Attempting uninstall: jinja2 #29 5.354 Found existing installation: Jinja2 3.0.3 #29 5.355 Uninstalling Jinja2-3.0.3: #29 5.660 Successfully uninstalled Jinja2-3.0.3 #29 16.17 #29 16.17 Successfully installed ansible-9.1.0 ansible-core-2.16.14 jinja2-3.1.6 resolvelib-1.0.1 #29 16.17 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning. #29 DONE 16.3s #30 [algo-server 6/8] RUN mkdir -p /etc/algo #30 DONE 0.1s #31 [algo-server 7/8] COPY tests/integration/server-entrypoint.sh /entrypoint.sh #31 DONE 0.0s #32 [algo-server 8/8] RUN chmod +x /entrypoint.sh #32 DONE 0.1s #33 [algo-server] exporting to image #33 exporting layers #33 exporting layers 2.7s done #33 writing image sha256:cc11c548d399d99c372404653a95784693b8472baadb19d1d0d8b9294143a921 done #33 naming to docker.io/library/integration-algo-server done #33 DONE 2.7s #34 [algo-server] resolving provenance for metadata file #34 DONE 0.0s integration-algo-server Built integration-client-ubuntu Built integration-client-debian Built Starting test environment... Container algo-server Recreate Container algo-server Recreated Container algo-server Starting Container algo-server Started Waiting for Algo server to provision... Waiting for provisioning to complete... (0/300 seconds) Waiting for provisioning to complete... (10/300 seconds) Waiting for provisioning to complete... (20/300 seconds) Waiting for provisioning to complete... (30/300 seconds) Waiting for provisioning to complete... (40/300 seconds) Waiting for provisioning to complete... (50/300 seconds) Waiting for provisioning to complete... (60/300 seconds) Waiting for provisioning to complete... (70/300 seconds) Waiting for provisioning to complete... (80/300 seconds) ERROR: Algo server container stopped unexpectedly Container logs: algo-server | Starting Algo server container... algo-server | Running Algo provisioning... algo-server | Get:1 http://ports.ubuntu.com/ubuntu-ports jammy InRelease [270 kB] algo-server | Get:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease [128 kB] algo-server | Get:3 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease [127 kB] algo-server | Get:4 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease [129 kB] algo-server | Get:5 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 Packages [1758 kB] algo-server | Get:6 http://ports.ubuntu.com/ubuntu-ports jammy/restricted arm64 Packages [24.2 kB] algo-server | Get:7 http://ports.ubuntu.com/ubuntu-ports jammy/multiverse arm64 Packages [224 kB] algo-server | Get:8 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 Packages [17.2 MB] algo-server | Get:9 http://ports.ubuntu.com/ubuntu-ports jammy-updates/universe arm64 Packages [1572 kB] algo-server | Get:10 http://ports.ubuntu.com/ubuntu-ports jammy-updates/multiverse arm64 Packages [52.7 kB] algo-server | Get:11 http://ports.ubuntu.com/ubuntu-ports jammy-updates/restricted arm64 Packages [4694 kB] algo-server | Get:12 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 Packages [3220 kB] algo-server | Get:13 http://ports.ubuntu.com/ubuntu-ports jammy-backports/universe arm64 Packages [33.3 kB] algo-server | Get:14 http://ports.ubuntu.com/ubuntu-ports jammy-backports/main arm64 Packages [82.8 kB] algo-server | Get:15 http://ports.ubuntu.com/ubuntu-ports jammy-security/restricted arm64 Packages [4510 kB] algo-server | Get:16 http://ports.ubuntu.com/ubuntu-ports jammy-security/multiverse arm64 Packages [27.2 kB] algo-server | Get:17 http://ports.ubuntu.com/ubuntu-ports jammy-security/universe arm64 Packages [1275 kB] algo-server | Get:18 http://ports.ubuntu.com/ubuntu-ports jammy-security/main arm64 Packages [2916 kB] algo-server | Fetched 38.3 MB in 3s (12.0 MB/s) algo-server | Reading package lists... algo-server | [WARNING]: Found variable using reserved name: no_log algo-server | Using /algo/ansible.cfg as config file algo-server | algo-server | PLAY [Algo VPN Setup] ********************************************************** algo-server | algo-server | TASK [Gathering Facts] ********************************************************* algo-server | ok: [localhost] algo-server | algo-server | TASK [Playbook dir stat] ******************************************************* algo-server | ok: [localhost] => {"changed": false, "stat": {"atime": 1754231772.3685358, "attr_flags": "", "attributes": [], "block_size": 4096, "blocks": 8, "charset": "unknown", "ctime": 1754231775.268547, "dev": 48, "device_type": 0, "executable": true, "exists": true, "gid": 0, "gr_name": "root", "inode": 5790103, "isblk": false, "ischr": false, "isdir": true, "isfifo": false, "isgid": false, "islnk": false, "isreg": false, "issock": false, "isuid": false, "mimetype": "unknown", "mode": "0755", "mtime": 1754231775.268547, "nlink": 1, "path": "/algo", "pw_name": "root", "readable": true, "rgrp": true, "roth": true, "rusr": true, "size": 4096, "uid": 0, "version": null, "wgrp": false, "woth": false, "writeable": true, "wusr": true, "xgrp": true, "xoth": true, "xusr": true}} algo-server | algo-server | TASK [Ensure Ansible is not being run in a world writable directory] *********** algo-server | ok: [localhost] => { algo-server | "changed": false, algo-server | "msg": "All assertions passed" algo-server | } algo-server | [DEPRECATION WARNING]: Use 'ansible.utils.ipaddr' module instead. This feature algo-server | will be removed from ansible.netcommon in a release after 2024-01-01. algo-server | Deprecation warnings can be disabled by setting deprecation_warnings=False in algo-server | ansible.cfg. algo-server | [WARNING]: The value '' is not a valid IP address or network, passing this algo-server | value to ipaddr filter might result in breaking change in future. algo-server | algo-server | TASK [Ensure the requirements installed] *************************************** algo-server | ok: [localhost] => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"} algo-server | algo-server | TASK [Set required ansible version as a fact] ********************************** algo-server | ok: [localhost] => (item=ansible==9.1.0) => {"ansible_facts": {"required_ansible_version": {"op": "==", "ver": "9.1.0"}}, "ansible_loop_var": "item", "changed": false, "item": "ansible==9.1.0"} algo-server | algo-server | TASK [Just get the list from default pip] ************************************** algo-server | ok: [localhost] => {"changed": false, "packages": {"pip": {"Babel": [{"name": "Babel", "source": "pip", "version": "2.8.0"}], "Jinja2": [{"name": "Jinja2", "source": "pip", "version": "3.1.6"}], "MarkupSafe": [{"name": "MarkupSafe", "source": "pip", "version": "2.0.1"}], "PyGObject": [{"name": "PyGObject", "source": "pip", "version": "3.42.1"}], "PyYAML": [{"name": "PyYAML", "source": "pip", "version": "5.4.1"}], "ansible": [{"name": "ansible", "source": "pip", "version": "9.1.0"}], "ansible-base": [{"name": "ansible-base", "source": "pip", "version": "2.10.8"}], "ansible-core": [{"name": "ansible-core", "source": "pip", "version": "2.16.14"}], "apache-libcloud": [{"name": "apache-libcloud", "source": "pip", "version": "3.2.0"}], "argcomplete": [{"name": "argcomplete", "source": "pip", "version": "1.8.1"}], "certifi": [{"name": "certifi", "source": "pip", "version": "2020.6.20"}], "chardet": [{"name": "chardet", "source": "pip", "version": "4.0.0"}], "cryptography": [{"name": "cryptography", "source": "pip", "version": "3.4.8"}], "dbus-python": [{"name": "dbus-python", "source": "pip", "version": "1.2.18"}], "dnspython": [{"name": "dnspython", "source": "pip", "version": "2.1.0"}], "httplib2": [{"name": "httplib2", "source": "pip", "version": "0.20.2"}], "idna": [{"name": "idna", "source": "pip", "version": "3.3"}], "jmespath": [{"name": "jmespath", "source": "pip", "version": "0.10.0"}], "lockfile": [{"name": "lockfile", "source": "pip", "version": "0.12.2"}], "netaddr": [{"name": "netaddr", "source": "pip", "version": "0.8.0"}], "ntlm-auth": [{"name": "ntlm-auth", "source": "pip", "version": "1.4.0"}], "packaging": [{"name": "packaging", "source": "pip", "version": "21.3"}], "pip": [{"name": "pip", "source": "pip", "version": "25.2"}], "pycryptodomex": [{"name": "pycryptodomex", "source": "pip", "version": "3.11.0"}], "pykerberos": [{"name": "pykerberos", "source": "pip", "version": "1.1.14"}], "pyparsing": [{"name": "pyparsing", "source": "pip", "version": "2.4.7"}], "pytz": [{"name": "pytz", "source": "pip", "version": "2022.1"}], "pywinrm": [{"name": "pywinrm", "source": "pip", "version": "0.3.0"}], "requests": [{"name": "requests", "source": "pip", "version": "2.25.1"}], "requests-kerberos": [{"name": "requests-kerberos", "source": "pip", "version": "0.12.0"}], "requests-ntlm": [{"name": "requests-ntlm", "source": "pip", "version": "1.1.0"}], "requests-toolbelt": [{"name": "requests-toolbelt", "source": "pip", "version": "0.9.1"}], "resolvelib": [{"name": "resolvelib", "source": "pip", "version": "1.0.1"}], "selinux": [{"name": "selinux", "source": "pip", "version": "3.3"}], "setuptools": [{"name": "setuptools", "source": "pip", "version": "59.6.0"}], "simplejson": [{"name": "simplejson", "source": "pip", "version": "3.17.6"}], "six": [{"name": "six", "source": "pip", "version": "1.16.0"}], "urllib3": [{"name": "urllib3", "source": "pip", "version": "1.26.5"}], "wheel": [{"name": "wheel", "source": "pip", "version": "0.37.1"}], "xmltodict": [{"name": "xmltodict", "source": "pip", "version": "0.12.0"}]}}} algo-server | algo-server | TASK [Verify Python meets Algo VPN requirements] ******************************* algo-server | ok: [localhost] => { algo-server | "changed": false, algo-server | "msg": "All assertions passed" algo-server | } algo-server | algo-server | TASK [Verify Ansible meets Algo VPN requirements] ****************************** algo-server | ok: [localhost] => { algo-server | "changed": false, algo-server | "msg": "All assertions passed" algo-server | } algo-server | algo-server | PLAY [Ask user for the input] ************************************************** algo-server | algo-server | TASK [Gathering Facts] ********************************************************* algo-server | ok: [localhost] algo-server | algo-server | TASK [Set facts based on the input] ******************************************** algo-server | ok: [localhost] => {"ansible_facts": {"algo_provider": "local"}, "changed": false} algo-server | [WARNING]: Not waiting for response to prompt as stdin is not interactive algo-server | algo-server | TASK [Cellular On Demand prompt] *********************************************** algo-server | ok: [localhost] => {"changed": false, "delta": 0, "echo": true, "rc": 0, "start": "2025-08-03 14:36:20.857514", "stderr": "", "stdout": "Paused for 0.0 minutes", "stop": "2025-08-03 14:36:20.858168", "user_input": ""} algo-server | algo-server | TASK [Wi-Fi On Demand prompt] ************************************************** algo-server | ok: [localhost] => {"changed": false, "delta": 0, "echo": true, "rc": 0, "start": "2025-08-03 14:36:20.869924", "stderr": "", "stdout": "Paused for 0.0 minutes", "stop": "2025-08-03 14:36:20.870503", "user_input": ""} algo-server | algo-server | TASK [Set facts based on the input] ******************************************** algo-server | ok: [localhost] => {"ansible_facts": {"algo_dns_adblocking": false, "algo_ondemand_cellular": false, "algo_ondemand_wifi": false, "algo_ondemand_wifi_exclude": "X251bGw=", "algo_server_name": "algo", "algo_ssh_tunneling": false, "algo_store_pki": true}, "changed": false} algo-server | algo-server | PLAY [Provision the server] **************************************************** algo-server | algo-server | TASK [Gathering Facts] ********************************************************* algo-server | ok: [localhost] algo-server | algo-server | TASK [Display the invocation environment] ************************************** algo-server | changed: [localhost] => {"changed": true, "cmd": "./algo-showenv.sh 'algo_provider \"local\"' 'algo_ondemand_cellular \"False\"' 'algo_ondemand_wifi \"False\"' 'algo_ondemand_wifi_exclude \"X251bGw=\"' 'algo_dns_adblocking \"False\"' 'algo_ssh_tunneling \"False\"' 'wireguard_enabled \"True\"' 'dns_encryption \"False\"' > /dev/tty || true\n", "delta": "0:00:00.000892", "end": "2025-08-03 14:36:21.491766", "msg": "", "rc": 0, "start": "2025-08-03 14:36:21.490874", "stderr": "/bin/sh: 1: cannot create /dev/tty: No such device or address", "stderr_lines": ["/bin/sh: 1: cannot create /dev/tty: No such device or address"], "stdout": "", "stdout_lines": []} algo-server | algo-server | TASK [Install the requirements] ************************************************ algo-server | changed: [localhost] => {"changed": true, "cmd": ["/usr/bin/python3", "-m", "pip.__main__", "install", "pyOpenSSL>=0.15", "segno"], "name": ["pyOpenSSL>=0.15", "segno"], "requirements": null, "state": "present", "stderr": "WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.\n", "stderr_lines": ["WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning."], "stdout": "Collecting pyOpenSSL>=0.15\n Downloading pyopenssl-25.1.0-py3-none-any.whl.metadata (17 kB)\nCollecting segno\n Downloading segno-1.6.6-py3-none-any.whl.metadata (7.7 kB)\nCollecting cryptography<46,>=41.0.5 (from pyOpenSSL>=0.15)\n Downloading cryptography-45.0.5-cp37-abi3-manylinux_2_34_aarch64.whl.metadata (5.7 kB)\nCollecting typing-extensions>=4.9 (from pyOpenSSL>=0.15)\n Downloading typing_extensions-4.14.1-py3-none-any.whl.metadata (3.0 kB)\nCollecting cffi>=1.14 (from cryptography<46,>=41.0.5->pyOpenSSL>=0.15)\n Downloading cffi-1.17.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (1.5 kB)\nCollecting pycparser (from cffi>=1.14->cryptography<46,>=41.0.5->pyOpenSSL>=0.15)\n Downloading pycparser-2.22-py3-none-any.whl.metadata (943 bytes)\nDownloading pyopenssl-25.1.0-py3-none-any.whl (56 kB)\nDownloading cryptography-45.0.5-cp37-abi3-manylinux_2_34_aarch64.whl (4.2 MB)\n ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 11.6 MB/s 0:00:00\nDownloading segno-1.6.6-py3-none-any.whl (76 kB)\nDownloading cffi-1.17.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (448 kB)\nDownloading typing_extensions-4.14.1-py3-none-any.whl (43 kB)\nDownloading pycparser-2.22-py3-none-any.whl (117 kB)\nInstalling collected packages: typing-extensions, segno, pycparser, cffi, cryptography, pyOpenSSL\n Attempting uninstall: cryptography\n Found existing installation: cryptography 3.4.8\n Uninstalling cryptography-3.4.8:\n Successfully uninstalled cryptography-3.4.8\n\nSuccessfully installed cffi-1.17.1 cryptography-45.0.5 pyOpenSSL-25.1.0 pycparser-2.22 segno-1.6.6 typing-extensions-4.14.1\n", "stdout_lines": ["Collecting pyOpenSSL>=0.15", " Downloading pyopenssl-25.1.0-py3-none-any.whl.metadata (17 kB)", "Collecting segno", " Downloading segno-1.6.6-py3-none-any.whl.metadata (7.7 kB)", "Collecting cryptography<46,>=41.0.5 (from pyOpenSSL>=0.15)", " Downloading cryptography-45.0.5-cp37-abi3-manylinux_2_34_aarch64.whl.metadata (5.7 kB)", "Collecting typing-extensions>=4.9 (from pyOpenSSL>=0.15)", " Downloading typing_extensions-4.14.1-py3-none-any.whl.metadata (3.0 kB)", "Collecting cffi>=1.14 (from cryptography<46,>=41.0.5->pyOpenSSL>=0.15)", " Downloading cffi-1.17.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (1.5 kB)", "Collecting pycparser (from cffi>=1.14->cryptography<46,>=41.0.5->pyOpenSSL>=0.15)", " Downloading pycparser-2.22-py3-none-any.whl.metadata (943 bytes)", "Downloading pyopenssl-25.1.0-py3-none-any.whl (56 kB)", "Downloading cryptography-45.0.5-cp37-abi3-manylinux_2_34_aarch64.whl (4.2 MB)", " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 11.6 MB/s 0:00:00", "Downloading segno-1.6.6-py3-none-any.whl (76 kB)", "Downloading cffi-1.17.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (448 kB)", "Downloading typing_extensions-4.14.1-py3-none-any.whl (43 kB)", "Downloading pycparser-2.22-py3-none-any.whl (117 kB)", "Installing collected packages: typing-extensions, segno, pycparser, cffi, cryptography, pyOpenSSL", " Attempting uninstall: cryptography", " Found existing installation: cryptography 3.4.8", " Uninstalling cryptography-3.4.8:", " Successfully uninstalled cryptography-3.4.8", "", "Successfully installed cffi-1.17.1 cryptography-45.0.5 pyOpenSSL-25.1.0 pycparser-2.22 segno-1.6.6 typing-extensions-4.14.1"], "version": null, "virtualenv": null} algo-server | algo-server | TASK [Include a provisioning role] ********************************************* algo-server | algo-server | TASK [local : pause] *********************************************************** algo-server | ok: [localhost] => {"changed": false, "delta": 0, "echo": true, "rc": 0, "start": "2025-08-03 14:36:23.852371", "stderr": "", "stdout": "Paused for 0.0 minutes", "stop": "2025-08-03 14:36:23.852907", "user_input": ""} algo-server | algo-server | TASK [local : Set the facts] *************************************************** algo-server | ok: [localhost] => {"ansible_facts": {"cloud_instance_ip": "localhost"}, "changed": false} algo-server | algo-server | TASK [local : Set the facts] *************************************************** algo-server | ok: [localhost] => {"ansible_facts": {"IP_subject_alt_name": "10.99.0.10"}, "changed": false} algo-server | algo-server | TASK [Set subjectAltName as a fact] ******************************************** algo-server | ok: [localhost] => {"ansible_facts": {"IP_subject_alt_name": "10.99.0.10"}, "changed": false} algo-server | algo-server | TASK [Add the server to an inventory group] ************************************ algo-server | changed: [localhost] => {"add_host": {"groups": ["vpn-host"], "host_name": "localhost", "host_vars": {"IP_subject_alt_name": "10.99.0.10", "algo_dns_adblocking": false, "algo_ondemand_cellular": false, "algo_ondemand_wifi": false, "algo_ondemand_wifi_exclude": "X251bGw=", "algo_provider": "local", "algo_server_name": "algo-test-server", "algo_ssh_tunneling": false, "algo_store_pki": true, "alternative_ingress_ip": false, "ansible_connection": "local", "ansible_python_interpreter": "/usr/bin/python3", "ansible_ssh_port": "22", "ansible_ssh_user": "root", "cloudinit": false}}, "changed": true} algo-server | algo-server | TASK [debug] ******************************************************************* algo-server | ok: [localhost] => { algo-server | "IP_subject_alt_name": "10.99.0.10" algo-server | } algo-server | [WARNING]: Reset is not implemented for this connection algo-server | algo-server | TASK [Wait 600 seconds for target connection to become reachable/usable] ******* algo-server | ok: [localhost] => (item=localhost) => {"ansible_loop_var": "item", "changed": false, "elapsed": 0, "item": "localhost"} algo-server | algo-server | PLAY [Configure the server and install required software] ********************** algo-server | algo-server | TASK [common : Check the system] *********************************************** algo-server | ok: [localhost] => {"changed": false, "rc": 0, "stderr": "", "stderr_lines": [], "stdout": "Linux algo-server 6.8.0-50-generic #51-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov 9 18:03:35 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux\n", "stdout_lines": ["Linux algo-server 6.8.0-50-generic #51-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov 9 18:03:35 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux"]} algo-server | algo-server | TASK [common : include_tasks] ************************************************** algo-server | included: /algo/roles/common/tasks/ubuntu.yml for localhost algo-server | algo-server | TASK [common : Gather facts] *************************************************** algo-server | ok: [localhost] algo-server | algo-server | TASK [common : Install unattended-upgrades] ************************************ algo-server | changed: [localhost] => {"cache_update_time": 1754231778, "cache_updated": false, "changed": true, "stderr": "debconf: delaying package configuration, since apt-utils is not installed\n", "stderr_lines": ["debconf: delaying package configuration, since apt-utils is not installed"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following additional packages will be installed:\n libnss-systemd libpam-systemd python3-distro-info systemd-sysv\nSuggested packages:\n bsd-mailx default-mta | mail-transport-agent needrestart powermgmt-base\nThe following NEW packages will be installed:\n libnss-systemd libpam-systemd python3-distro-info systemd-sysv\n unattended-upgrades\n0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 405 kB of archives.\nAfter this operation, 1853 kB of additional disk space will be used.\nGet:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 systemd-sysv arm64 249.11-0ubuntu3.16 [10.5 kB]\nGet:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libnss-systemd arm64 249.11-0ubuntu3.16 [133 kB]\nGet:3 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libpam-systemd arm64 249.11-0ubuntu3.16 [205 kB]\nGet:4 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-distro-info all 1.1ubuntu0.2 [6554 B]\nGet:5 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 unattended-upgrades all 2.8ubuntu1 [49.4 kB]\nFetched 405 kB in 0s (3673 kB/s)\nSelecting previously unselected package systemd-sysv.\r\n(Reading database ... \r(Reading database ... 5%\r(Reading database ... 10%\r(Reading database ... 15%\r(Reading database ... 20%\r(Reading database ... 25%\r(Reading database ... 30%\r(Reading database ... 35%\r(Reading database ... 40%\r(Reading database ... 45%\r(Reading database ... 50%\r(Reading database ... 55%\r(Reading database ... 60%\r(Reading database ... 65%\r(Reading database ... 70%\r(Reading database ... 75%\r(Reading database ... 80%\r(Reading database ... 85%\r(Reading database ... 90%\r(Reading database ... 95%\r(Reading database ... 100%\r(Reading database ... 73818 files and directories currently installed.)\r\nPreparing to unpack .../systemd-sysv_249.11-0ubuntu3.16_arm64.deb ...\r\nUnpacking systemd-sysv (249.11-0ubuntu3.16) ...\r\nSelecting previously unselected package libnss-systemd:arm64.\r\nPreparing to unpack .../libnss-systemd_249.11-0ubuntu3.16_arm64.deb ...\r\nUnpacking libnss-systemd:arm64 (249.11-0ubuntu3.16) ...\r\nSelecting previously unselected package libpam-systemd:arm64.\r\nPreparing to unpack .../libpam-systemd_249.11-0ubuntu3.16_arm64.deb ...\r\nUnpacking libpam-systemd:arm64 (249.11-0ubuntu3.16) ...\r\nSelecting previously unselected package python3-distro-info.\r\nPreparing to unpack .../python3-distro-info_1.1ubuntu0.2_all.deb ...\r\nUnpacking python3-distro-info (1.1ubuntu0.2) ...\r\nSelecting previously unselected package unattended-upgrades.\r\nPreparing to unpack .../unattended-upgrades_2.8ubuntu1_all.deb ...\r\nUnpacking unattended-upgrades (2.8ubuntu1) ...\r\nSetting up systemd-sysv (249.11-0ubuntu3.16) ...\r\nSetting up libnss-systemd:arm64 (249.11-0ubuntu3.16) ...\r\nFirst installation detected...\r\nChecking NSS setup...\r\nSetting up libpam-systemd:arm64 (249.11-0ubuntu3.16) ...\r\nSetting up python3-distro-info (1.1ubuntu0.2) ...\r\nSetting up unattended-upgrades (2.8ubuntu1) ...\r\n\r\nCreating config file /etc/apt/apt.conf.d/20auto-upgrades with new version\r\n\r\nCreating config file /etc/apt/apt.conf.d/50unattended-upgrades with new version\r\nProcessing triggers for libc-bin (2.35-0ubuntu3.10) ...\r\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "The following additional packages will be installed:", " libnss-systemd libpam-systemd python3-distro-info systemd-sysv", "Suggested packages:", " bsd-mailx default-mta | mail-transport-agent needrestart powermgmt-base", "The following NEW packages will be installed:", " libnss-systemd libpam-systemd python3-distro-info systemd-sysv", " unattended-upgrades", "0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.", "Need to get 405 kB of archives.", "After this operation, 1853 kB of additional disk space will be used.", "Get:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 systemd-sysv arm64 249.11-0ubuntu3.16 [10.5 kB]", "Get:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libnss-systemd arm64 249.11-0ubuntu3.16 [133 kB]", "Get:3 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libpam-systemd arm64 249.11-0ubuntu3.16 [205 kB]", "Get:4 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-distro-info all 1.1ubuntu0.2 [6554 B]", "Get:5 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 unattended-upgrades all 2.8ubuntu1 [49.4 kB]", "Fetched 405 kB in 0s (3673 kB/s)", "Selecting previously unselected package systemd-sysv.", "(Reading database ... ", "(Reading database ... 5%", "(Reading database ... 10%", "(Reading database ... 15%", "(Reading database ... 20%", "(Reading database ... 25%", "(Reading database ... 30%", "(Reading database ... 35%", "(Reading database ... 40%", "(Reading database ... 45%", "(Reading database ... 50%", "(Reading database ... 55%", "(Reading database ... 60%", "(Reading database ... 65%", "(Reading database ... 70%", "(Reading database ... 75%", "(Reading database ... 80%", "(Reading database ... 85%", "(Reading database ... 90%", "(Reading database ... 95%", "(Reading database ... 100%", "(Reading database ... 73818 files and directories currently installed.)", "Preparing to unpack .../systemd-sysv_249.11-0ubuntu3.16_arm64.deb ...", "Unpacking systemd-sysv (249.11-0ubuntu3.16) ...", "Selecting previously unselected package libnss-systemd:arm64.", "Preparing to unpack .../libnss-systemd_249.11-0ubuntu3.16_arm64.deb ...", "Unpacking libnss-systemd:arm64 (249.11-0ubuntu3.16) ...", "Selecting previously unselected package libpam-systemd:arm64.", "Preparing to unpack .../libpam-systemd_249.11-0ubuntu3.16_arm64.deb ...", "Unpacking libpam-systemd:arm64 (249.11-0ubuntu3.16) ...", "Selecting previously unselected package python3-distro-info.", "Preparing to unpack .../python3-distro-info_1.1ubuntu0.2_all.deb ...", "Unpacking python3-distro-info (1.1ubuntu0.2) ...", "Selecting previously unselected package unattended-upgrades.", "Preparing to unpack .../unattended-upgrades_2.8ubuntu1_all.deb ...", "Unpacking unattended-upgrades (2.8ubuntu1) ...", "Setting up systemd-sysv (249.11-0ubuntu3.16) ...", "Setting up libnss-systemd:arm64 (249.11-0ubuntu3.16) ...", "First installation detected...", "Checking NSS setup...", "Setting up libpam-systemd:arm64 (249.11-0ubuntu3.16) ...", "Setting up python3-distro-info (1.1ubuntu0.2) ...", "Setting up unattended-upgrades (2.8ubuntu1) ...", "", "Creating config file /etc/apt/apt.conf.d/20auto-upgrades with new version", "", "Creating config file /etc/apt/apt.conf.d/50unattended-upgrades with new version", "Processing triggers for libc-bin (2.35-0ubuntu3.10) ..."]} algo-server | algo-server | TASK [common : Configure unattended-upgrades] ********************************** algo-server | changed: [localhost] => {"changed": true, "checksum": "ed74b36a000a932393d6d1f4c47186bcd895a515", "dest": "/etc/apt/apt.conf.d/50unattended-upgrades", "gid": 0, "group": "root", "md5sum": "ead855b06ced87c51e33071acab35bf3", "mode": "0644", "owner": "root", "size": 3797, "src": "/root/.ansible/tmp/ansible-tmp-1754231789.302889-995-157903953471024/source", "state": "file", "uid": 0} algo-server | algo-server | TASK [common : Periodic upgrades configured] *********************************** algo-server | changed: [localhost] => {"changed": true, "checksum": "eac74547eec217a356899a6d8a377d3f1522851a", "dest": "/etc/apt/apt.conf.d/10periodic", "gid": 0, "group": "root", "md5sum": "4e7d1cf7c590a703ad853f2658fb8eeb", "mode": "0644", "owner": "root", "size": 168, "src": "/root/.ansible/tmp/ansible-tmp-1754231789.5252056-1025-265113230477430/source", "state": "file", "uid": 0} algo-server | algo-server | TASK [common : Disable MOTD on login and SSHD] ********************************* algo-server | changed: [localhost] => (item={'regexp': '^session.*optional.*pam_motd.so.*', 'line': '# MOTD DISABLED', 'file': '/etc/pam.d/login'}) => {"ansible_loop_var": "item", "changed": true, "item": {"file": "/etc/pam.d/login", "line": "# MOTD DISABLED", "regexp": "^session.*optional.*pam_motd.so.*"}, "msg": "2 replacements made", "rc": 0} algo-server | ok: [localhost] => (item={'regexp': '^session.*optional.*pam_motd.so.*', 'line': '# MOTD DISABLED', 'file': '/etc/pam.d/sshd'}) => {"ansible_loop_var": "item", "changed": false, "item": {"file": "/etc/pam.d/sshd", "line": "# MOTD DISABLED", "regexp": "^session.*optional.*pam_motd.so.*"}, "msg": "", "rc": 0} algo-server | algo-server | TASK [common : Ensure fallback resolvers are set] ****************************** algo-server | changed: [localhost] => {"changed": true, "gid": 0, "group": "root", "mode": "0644", "msg": "option changed", "owner": "root", "path": "/etc/systemd/resolved.conf", "size": 1422, "state": "file", "uid": 0} algo-server | algo-server | TASK [common : Loopback for services configured] ******************************* algo-server | changed: [localhost] => {"changed": true, "checksum": "38bd687506a689a469b3dd4a25190324d6b8f146", "dest": "/etc/systemd/network/10-algo-lo100.network", "gid": 0, "group": "root", "md5sum": "274ffd4d7caf66f754ca3c5e5cad049e", "mode": "0644", "owner": "root", "size": 97, "src": "/root/.ansible/tmp/ansible-tmp-1754231789.9961534-1068-186978330039061/source", "state": "file", "uid": 0} algo-server | algo-server | TASK [common : systemd services enabled and started] *************************** algo-server | changed: [localhost] => (item=systemd-networkd) => {"ansible_loop_var": "item", "changed": true, "enabled": true, "item": "systemd-networkd", "name": "systemd-networkd", "state": "started", "status": {"ActiveState": "active", "LoadState": "loaded", "SubState": "running"}} algo-server | changed: [localhost] => (item=systemd-resolved) => {"ansible_loop_var": "item", "changed": true, "enabled": true, "item": "systemd-resolved", "name": "systemd-resolved", "state": "started", "status": {"ActiveState": "active", "LoadState": "loaded", "SubState": "running"}} algo-server | algo-server | RUNNING HANDLER [common : restart systemd-networkd] **************************** algo-server | changed: [localhost] => {"changed": true, "name": "systemd-networkd", "state": "restarted", "status": {"ActiveState": "active", "LoadState": "loaded", "SubState": "running"}} algo-server | algo-server | RUNNING HANDLER [common : restart systemd-resolved] **************************** algo-server | changed: [localhost] => {"changed": true, "name": "systemd-resolved", "state": "restarted", "status": {"ActiveState": "active", "LoadState": "loaded", "SubState": "running"}} algo-server | algo-server | TASK [common : Check apparmor support] ***************************************** algo-server | fatal: [localhost]: FAILED! => {"changed": false, "cmd": "apparmor_status", "msg": "[Errno 2] No such file or directory: b'apparmor_status'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []} algo-server | ...ignoring algo-server | algo-server | TASK [common : Define facts] *************************************************** algo-server | ok: [localhost] => {"ansible_facts": {"p12_export_password": "j6xqfQax2"}, "changed": false} algo-server | algo-server | TASK [common : Set facts] ****************************************************** algo-server | ok: [localhost] => {"ansible_facts": {"CA_password": "cGJkMmasHgeGjkg6", "IP_subject_alt_name": "10.99.0.10"}, "changed": false} algo-server | algo-server | TASK [common : Set IPv6 support as a fact] ************************************* algo-server | ok: [localhost] => {"ansible_facts": {"ipv6_support": false}, "changed": false} algo-server | algo-server | TASK [common : Check size of MTU] ********************************************** algo-server | ok: [localhost] => {"ansible_facts": {"reduce_mtu": "0"}, "changed": false} algo-server | algo-server | TASK [common : Set OS specific facts] ****************************************** algo-server | ok: [localhost] => {"ansible_facts": {"sysctl": [{"item": "net.ipv4.ip_forward", "value": 1}, {"item": "net.ipv4.conf.all.forwarding", "value": 1}, {"item": "", "value": 1}], "tools": ["git", "screen", "apparmor-utils", "uuid-runtime", "coreutils", "iptables-persistent", "cgroup-tools", "openssl", "gnupg2", "cron"]}, "changed": false} algo-server | algo-server | TASK [common : Install tools] ************************************************** algo-server | changed: [localhost] => {"cache_update_time": 1754231778, "cache_updated": false, "changed": true, "stderr": "debconf: delaying package configuration, since apt-utils is not installed\n", "stderr_lines": ["debconf: delaying package configuration, since apt-utils is not installed"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following additional packages will be installed:\n apparmor git-man less libcgroup1 libcurl3-gnutls liberror-perl libutempter0\n netfilter-persistent python3-apparmor python3-libapparmor\nSuggested packages:\n apparmor-profiles-extra vim-addon-manager anacron logrotate checksecurity\n default-mta | mail-transport-agent gettext-base git-daemon-run\n | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb git-cvs\n git-mediawiki git-svn byobu | screenie | iselect ncurses-term\nThe following NEW packages will be installed:\n apparmor apparmor-utils cgroup-tools cron git git-man gnupg2\n iptables-persistent less libcgroup1 libcurl3-gnutls liberror-perl\n libutempter0 netfilter-persistent python3-apparmor python3-libapparmor\n screen uuid-runtime\n0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 6288 kB of archives.\nAfter this operation, 27.5 MB of additional disk space will be used.\nGet:1 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 cron arm64 3.0pl1-137ubuntu3 [73.1 kB]\nGet:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 uuid-runtime arm64 2.37.2-4ubuntu3.4 [31.8 kB]\nGet:3 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 netfilter-persistent all 1.0.16 [7440 B]\nGet:4 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 iptables-persistent all 1.0.16 [6488 B]\nGet:5 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 less arm64 590-1ubuntu0.22.04.3 [141 kB]\nGet:6 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 apparmor arm64 3.0.4-2ubuntu2.4 [576 kB]\nGet:7 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-libapparmor arm64 3.0.4-2ubuntu2.4 [29.4 kB]\nGet:8 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-apparmor all 3.0.4-2ubuntu2.4 [81.1 kB]\nGet:9 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 apparmor-utils all 3.0.4-2ubuntu2.4 [59.5 kB]\nGet:10 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 libcgroup1 arm64 2.0-2 [50.3 kB]\nGet:11 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 cgroup-tools arm64 2.0-2 [72.1 kB]\nGet:12 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libcurl3-gnutls arm64 7.81.0-1ubuntu1.20 [279 kB]\nGet:13 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 liberror-perl all 0.17029-1 [26.5 kB]\nGet:14 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 git-man all 1:2.34.1-1ubuntu1.15 [955 kB]\nGet:15 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 git arm64 1:2.34.1-1ubuntu1.15 [3224 kB]\nGet:16 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libutempter0 arm64 1.2.1-2build2 [8774 B]\nGet:17 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 screen arm64 4.9.0-1 [661 kB]\nGet:18 http://ports.ubuntu.com/ubuntu-ports jammy-updates/universe arm64 gnupg2 all 2.2.27-3ubuntu2.4 [5544 B]\nFetched 6288 kB in 1s (10.6 MB/s)\nSelecting previously unselected package cron.\r\n(Reading database ... \r(Reading database ... 5%\r(Reading database ... 10%\r(Reading database ... 15%\r(Reading database ... 20%\r(Reading database ... 25%\r(Reading database ... 30%\r(Reading database ... 35%\r(Reading database ... 40%\r(Reading database ... 45%\r(Reading database ... 50%\r(Reading database ... 55%\r(Reading database ... 60%\r(Reading database ... 65%\r(Reading database ... 70%\r(Reading database ... 75%\r(Reading database ... 80%\r(Reading database ... 85%\r(Reading database ... 90%\r(Reading database ... 95%\r(Reading database ... 100%\r(Reading database ... 73890 files and directories currently installed.)\r\nPreparing to unpack .../00-cron_3.0pl1-137ubuntu3_arm64.deb ...\r\nUnpacking cron (3.0pl1-137ubuntu3) ...\r\nSelecting previously unselected package uuid-runtime.\r\nPreparing to unpack .../01-uuid-runtime_2.37.2-4ubuntu3.4_arm64.deb ...\r\nUnpacking uuid-runtime (2.37.2-4ubuntu3.4) ...\r\nSelecting previously unselected package netfilter-persistent.\r\nPreparing to unpack .../02-netfilter-persistent_1.0.16_all.deb ...\r\nUnpacking netfilter-persistent (1.0.16) ...\r\nSelecting previously unselected package iptables-persistent.\r\nPreparing to unpack .../03-iptables-persistent_1.0.16_all.deb ...\r\nUnpacking iptables-persistent (1.0.16) ...\r\nSelecting previously unselected package less.\r\nPreparing to unpack .../04-less_590-1ubuntu0.22.04.3_arm64.deb ...\r\nUnpacking less (590-1ubuntu0.22.04.3) ...\r\nSelecting previously unselected package apparmor.\r\nPreparing to unpack .../05-apparmor_3.0.4-2ubuntu2.4_arm64.deb ...\r\nUnpacking apparmor (3.0.4-2ubuntu2.4) ...\r\nSelecting previously unselected package python3-libapparmor.\r\nPreparing to unpack .../06-python3-libapparmor_3.0.4-2ubuntu2.4_arm64.deb ...\r\nUnpacking python3-libapparmor (3.0.4-2ubuntu2.4) ...\r\nSelecting previously unselected package python3-apparmor.\r\nPreparing to unpack .../07-python3-apparmor_3.0.4-2ubuntu2.4_all.deb ...\r\nUnpacking python3-apparmor (3.0.4-2ubuntu2.4) ...\r\nSelecting previously unselected package apparmor-utils.\r\nPreparing to unpack .../08-apparmor-utils_3.0.4-2ubuntu2.4_all.deb ...\r\nUnpacking apparmor-utils (3.0.4-2ubuntu2.4) ...\r\nSelecting previously unselected package libcgroup1:arm64.\r\nPreparing to unpack .../09-libcgroup1_2.0-2_arm64.deb ...\r\nUnpacking libcgroup1:arm64 (2.0-2) ...\r\nSelecting previously unselected package cgroup-tools.\r\nPreparing to unpack .../10-cgroup-tools_2.0-2_arm64.deb ...\r\nUnpacking cgroup-tools (2.0-2) ...\r\nSelecting previously unselected package libcurl3-gnutls:arm64.\r\nPreparing to unpack .../11-libcurl3-gnutls_7.81.0-1ubuntu1.20_arm64.deb ...\r\nUnpacking libcurl3-gnutls:arm64 (7.81.0-1ubuntu1.20) ...\r\nSelecting previously unselected package liberror-perl.\r\nPreparing to unpack .../12-liberror-perl_0.17029-1_all.deb ...\r\nUnpacking liberror-perl (0.17029-1) ...\r\nSelecting previously unselected package git-man.\r\nPreparing to unpack .../13-git-man_1%3a2.34.1-1ubuntu1.15_all.deb ...\r\nUnpacking git-man (1:2.34.1-1ubuntu1.15) ...\r\nSelecting previously unselected package git.\r\nPreparing to unpack .../14-git_1%3a2.34.1-1ubuntu1.15_arm64.deb ...\r\nUnpacking git (1:2.34.1-1ubuntu1.15) ...\r\nSelecting previously unselected package libutempter0:arm64.\r\nPreparing to unpack .../15-libutempter0_1.2.1-2build2_arm64.deb ...\r\nUnpacking libutempter0:arm64 (1.2.1-2build2) ...\r\nSelecting previously unselected package screen.\r\nPreparing to unpack .../16-screen_4.9.0-1_arm64.deb ...\r\nUnpacking screen (4.9.0-1) ...\r\nSelecting previously unselected package gnupg2.\r\nPreparing to unpack .../17-gnupg2_2.2.27-3ubuntu2.4_all.deb ...\r\nUnpacking gnupg2 (2.2.27-3ubuntu2.4) ...\r\nSetting up python3-libapparmor (3.0.4-2ubuntu2.4) ...\r\nSetting up gnupg2 (2.2.27-3ubuntu2.4) ...\r\nSetting up cron (3.0pl1-137ubuntu3) ...\r\nAdding group `crontab' (GID 111) ...\r\nDone.\r\nMock systemctl: operation '' recorded but not implemented\r\ninvoke-rc.d: policy-rc.d denied execution of start.\r\nSetting up less (590-1ubuntu0.22.04.3) ...\r\nSetting up libcurl3-gnutls:arm64 (7.81.0-1ubuntu1.20) ...\r\nSetting up liberror-perl (0.17029-1) ...\r\nSetting up apparmor (3.0.4-2ubuntu2.4) ...\r\nSetting up libutempter0:arm64 (1.2.1-2build2) ...\r\nSetting up netfilter-persistent (1.0.16) ...\r\nMock systemctl: operation '' recorded but not implemented\r\ninvoke-rc.d: policy-rc.d denied execution of restart.\r\nSetting up uuid-runtime (2.37.2-4ubuntu3.4) ...\r\nAdding group `uuidd' (GID 112) ...\r\nDone.\r\nWarning: The home dir /run/uuidd you specified can't be accessed: No such file or directory\r\nAdding system user `uuidd' (UID 106) ...\r\nAdding new user `uuidd' (UID 106) with group `uuidd' ...\r\nNot creating home directory `/run/uuidd'.\r\nMock systemctl: operation '' recorded but not implemented\r\ninvoke-rc.d: policy-rc.d denied execution of start.\r\nSetting up python3-apparmor (3.0.4-2ubuntu2.4) ...\r\nSetting up git-man (1:2.34.1-1ubuntu1.15) ...\r\nSetting up libcgroup1:arm64 (2.0-2) ...\r\nSetting up cgroup-tools (2.0-2) ...\r\nSetting up screen (4.9.0-1) ...\r\nSetting up iptables-persistent (1.0.16) ...\r\nupdate-alternatives: using /lib/systemd/system/netfilter-persistent.service to provide /lib/systemd/system/iptables.service (iptables.service) in auto mode\r\nSetting up apparmor-utils (3.0.4-2ubuntu2.4) ...\r\nSetting up git (1:2.34.1-1ubuntu1.15) ...\r\nProcessing triggers for libc-bin (2.35-0ubuntu3.10) ...\r\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "The following additional packages will be installed:", " apparmor git-man less libcgroup1 libcurl3-gnutls liberror-perl libutempter0", " netfilter-persistent python3-apparmor python3-libapparmor", "Suggested packages:", " apparmor-profiles-extra vim-addon-manager anacron logrotate checksecurity", " default-mta | mail-transport-agent gettext-base git-daemon-run", " | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb git-cvs", " git-mediawiki git-svn byobu | screenie | iselect ncurses-term", "The following NEW packages will be installed:", " apparmor apparmor-utils cgroup-tools cron git git-man gnupg2", " iptables-persistent less libcgroup1 libcurl3-gnutls liberror-perl", " libutempter0 netfilter-persistent python3-apparmor python3-libapparmor", " screen uuid-runtime", "0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.", "Need to get 6288 kB of archives.", "After this operation, 27.5 MB of additional disk space will be used.", "Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 cron arm64 3.0pl1-137ubuntu3 [73.1 kB]", "Get:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 uuid-runtime arm64 2.37.2-4ubuntu3.4 [31.8 kB]", "Get:3 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 netfilter-persistent all 1.0.16 [7440 B]", "Get:4 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 iptables-persistent all 1.0.16 [6488 B]", "Get:5 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 less arm64 590-1ubuntu0.22.04.3 [141 kB]", "Get:6 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 apparmor arm64 3.0.4-2ubuntu2.4 [576 kB]", "Get:7 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-libapparmor arm64 3.0.4-2ubuntu2.4 [29.4 kB]", "Get:8 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-apparmor all 3.0.4-2ubuntu2.4 [81.1 kB]", "Get:9 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 apparmor-utils all 3.0.4-2ubuntu2.4 [59.5 kB]", "Get:10 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 libcgroup1 arm64 2.0-2 [50.3 kB]", "Get:11 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 cgroup-tools arm64 2.0-2 [72.1 kB]", "Get:12 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libcurl3-gnutls arm64 7.81.0-1ubuntu1.20 [279 kB]", "Get:13 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 liberror-perl all 0.17029-1 [26.5 kB]", "Get:14 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 git-man all 1:2.34.1-1ubuntu1.15 [955 kB]", "Get:15 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 git arm64 1:2.34.1-1ubuntu1.15 [3224 kB]", "Get:16 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libutempter0 arm64 1.2.1-2build2 [8774 B]", "Get:17 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 screen arm64 4.9.0-1 [661 kB]", "Get:18 http://ports.ubuntu.com/ubuntu-ports jammy-updates/universe arm64 gnupg2 all 2.2.27-3ubuntu2.4 [5544 B]", "Fetched 6288 kB in 1s (10.6 MB/s)", "Selecting previously unselected package cron.", "(Reading database ... ", "(Reading database ... 5%", "(Reading database ... 10%", "(Reading database ... 15%", "(Reading database ... 20%", "(Reading database ... 25%", "(Reading database ... 30%", "(Reading database ... 35%", "(Reading database ... 40%", "(Reading database ... 45%", "(Reading database ... 50%", "(Reading database ... 55%", "(Reading database ... 60%", "(Reading database ... 65%", "(Reading database ... 70%", "(Reading database ... 75%", "(Reading database ... 80%", "(Reading database ... 85%", "(Reading database ... 90%", "(Reading database ... 95%", "(Reading database ... 100%", "(Reading database ... 73890 files and directories currently installed.)", "Preparing to unpack .../00-cron_3.0pl1-137ubuntu3_arm64.deb ...", "Unpacking cron (3.0pl1-137ubuntu3) ...", "Selecting previously unselected package uuid-runtime.", "Preparing to unpack .../01-uuid-runtime_2.37.2-4ubuntu3.4_arm64.deb ...", "Unpacking uuid-runtime (2.37.2-4ubuntu3.4) ...", "Selecting previously unselected package netfilter-persistent.", "Preparing to unpack .../02-netfilter-persistent_1.0.16_all.deb ...", "Unpacking netfilter-persistent (1.0.16) ...", "Selecting previously unselected package iptables-persistent.", "Preparing to unpack .../03-iptables-persistent_1.0.16_all.deb ...", "Unpacking iptables-persistent (1.0.16) ...", "Selecting previously unselected package less.", "Preparing to unpack .../04-less_590-1ubuntu0.22.04.3_arm64.deb ...", "Unpacking less (590-1ubuntu0.22.04.3) ...", "Selecting previously unselected package apparmor.", "Preparing to unpack .../05-apparmor_3.0.4-2ubuntu2.4_arm64.deb ...", "Unpacking apparmor (3.0.4-2ubuntu2.4) ...", "Selecting previously unselected package python3-libapparmor.", "Preparing to unpack .../06-python3-libapparmor_3.0.4-2ubuntu2.4_arm64.deb ...", "Unpacking python3-libapparmor (3.0.4-2ubuntu2.4) ...", "Selecting previously unselected package python3-apparmor.", "Preparing to unpack .../07-python3-apparmor_3.0.4-2ubuntu2.4_all.deb ...", "Unpacking python3-apparmor (3.0.4-2ubuntu2.4) ...", "Selecting previously unselected package apparmor-utils.", "Preparing to unpack .../08-apparmor-utils_3.0.4-2ubuntu2.4_all.deb ...", "Unpacking apparmor-utils (3.0.4-2ubuntu2.4) ...", "Selecting previously unselected package libcgroup1:arm64.", "Preparing to unpack .../09-libcgroup1_2.0-2_arm64.deb ...", "Unpacking libcgroup1:arm64 (2.0-2) ...", "Selecting previously unselected package cgroup-tools.", "Preparing to unpack .../10-cgroup-tools_2.0-2_arm64.deb ...", "Unpacking cgroup-tools (2.0-2) ...", "Selecting previously unselected package libcurl3-gnutls:arm64.", "Preparing to unpack .../11-libcurl3-gnutls_7.81.0-1ubuntu1.20_arm64.deb ...", "Unpacking libcurl3-gnutls:arm64 (7.81.0-1ubuntu1.20) ...", "Selecting previously unselected package liberror-perl.", "Preparing to unpack .../12-liberror-perl_0.17029-1_all.deb ...", "Unpacking liberror-perl (0.17029-1) ...", "Selecting previously unselected package git-man.", "Preparing to unpack .../13-git-man_1%3a2.34.1-1ubuntu1.15_all.deb ...", "Unpacking git-man (1:2.34.1-1ubuntu1.15) ...", "Selecting previously unselected package git.", "Preparing to unpack .../14-git_1%3a2.34.1-1ubuntu1.15_arm64.deb ...", "Unpacking git (1:2.34.1-1ubuntu1.15) ...", "Selecting previously unselected package libutempter0:arm64.", "Preparing to unpack .../15-libutempter0_1.2.1-2build2_arm64.deb ...", "Unpacking libutempter0:arm64 (1.2.1-2build2) ...", "Selecting previously unselected package screen.", "Preparing to unpack .../16-screen_4.9.0-1_arm64.deb ...", "Unpacking screen (4.9.0-1) ...", "Selecting previously unselected package gnupg2.", "Preparing to unpack .../17-gnupg2_2.2.27-3ubuntu2.4_all.deb ...", "Unpacking gnupg2 (2.2.27-3ubuntu2.4) ...", "Setting up python3-libapparmor (3.0.4-2ubuntu2.4) ...", "Setting up gnupg2 (2.2.27-3ubuntu2.4) ...", "Setting up cron (3.0pl1-137ubuntu3) ...", "Adding group `crontab' (GID 111) ...", "Done.", "Mock systemctl: operation '' recorded but not implemented", "invoke-rc.d: policy-rc.d denied execution of start.", "Setting up less (590-1ubuntu0.22.04.3) ...", "Setting up libcurl3-gnutls:arm64 (7.81.0-1ubuntu1.20) ...", "Setting up liberror-perl (0.17029-1) ...", "Setting up apparmor (3.0.4-2ubuntu2.4) ...", "Setting up libutempter0:arm64 (1.2.1-2build2) ...", "Setting up netfilter-persistent (1.0.16) ...", "Mock systemctl: operation '' recorded but not implemented", "invoke-rc.d: policy-rc.d denied execution of restart.", "Setting up uuid-runtime (2.37.2-4ubuntu3.4) ...", "Adding group `uuidd' (GID 112) ...", "Done.", "Warning: The home dir /run/uuidd you specified can't be accessed: No such file or directory", "Adding system user `uuidd' (UID 106) ...", "Adding new user `uuidd' (UID 106) with group `uuidd' ...", "Not creating home directory `/run/uuidd'.", "Mock systemctl: operation '' recorded but not implemented", "invoke-rc.d: policy-rc.d denied execution of start.", "Setting up python3-apparmor (3.0.4-2ubuntu2.4) ...", "Setting up git-man (1:2.34.1-1ubuntu1.15) ...", "Setting up libcgroup1:arm64 (2.0-2) ...", "Setting up cgroup-tools (2.0-2) ...", "Setting up screen (4.9.0-1) ...", "Setting up iptables-persistent (1.0.16) ...", "update-alternatives: using /lib/systemd/system/netfilter-persistent.service to provide /lib/systemd/system/iptables.service (iptables.service) in auto mode", "Setting up apparmor-utils (3.0.4-2ubuntu2.4) ...", "Setting up git (1:2.34.1-1ubuntu1.15) ...", "Processing triggers for libc-bin (2.35-0ubuntu3.10) ..."]} algo-server | algo-server | TASK [common : include_tasks] ************************************************** algo-server | included: /algo/roles/common/tasks/iptables.yml for localhost algo-server | algo-server | TASK [common : Iptables configured] ******************************************** algo-server | changed: [localhost] => (item={'src': 'rules.v4.j2', 'dest': '/etc/iptables/rules.v4'}) => {"ansible_loop_var": "item", "changed": true, "checksum": "72b2166dab8060974a72ce2be670711869338f5c", "dest": "/etc/iptables/rules.v4", "gid": 0, "group": "root", "item": {"dest": "/etc/iptables/rules.v4", "src": "rules.v4.j2"}, "md5sum": "0ba6bbff320d49c1c5392c5b5ae324e9", "mode": "0640", "owner": "root", "size": 3211, "src": "/root/.ansible/tmp/ansible-tmp-1754231795.9110847-1824-197214830210453/source", "state": "file", "uid": 0} algo-server | algo-server | TASK [common : Sysctl tuning] ************************************************** algo-server | changed: [localhost] => (item={'item': 'net.ipv4.ip_forward', 'value': 1}) => {"ansible_loop_var": "item", "changed": true, "item": {"item": "net.ipv4.ip_forward", "value": 1}} algo-server | changed: [localhost] => (item={'item': 'net.ipv4.conf.all.forwarding', 'value': 1}) => {"ansible_loop_var": "item", "changed": true, "item": {"item": "net.ipv4.conf.all.forwarding", "value": 1}} algo-server | algo-server | RUNNING HANDLER [common : restart iptables] ************************************ algo-server | changed: [localhost] => {"changed": true, "name": "netfilter-persistent", "status": {"enabled": {"changed": false, "rc": null, "stderr": null, "stdout": null}, "restarted": {"changed": true, "rc": 0, "stderr": "run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables start\nrun-parts: executing /usr/share/netfilter-persistent/plugins.d/25-ip6tables start\n", "stdout": " * Loading netfilter rules...\n ...done.\n"}}} algo-server | algo-server | TASK [wireguard : Ensure the required directories exist] *********************** algo-server | changed: [localhost] => (item=configs/10.99.0.10/wireguard//.pki//preshared) => {"ansible_loop_var": "item", "changed": true, "gid": 0, "group": "root", "item": "configs/10.99.0.10/wireguard//.pki//preshared", "mode": "0755", "owner": "root", "path": "configs/10.99.0.10/wireguard//.pki//preshared", "size": 4096, "state": "directory", "uid": 0} algo-server | changed: [localhost] => (item=configs/10.99.0.10/wireguard//.pki//private) => {"ansible_loop_var": "item", "changed": true, "gid": 0, "group": "root", "item": "configs/10.99.0.10/wireguard//.pki//private", "mode": "0755", "owner": "root", "path": "configs/10.99.0.10/wireguard//.pki//private", "size": 4096, "state": "directory", "uid": 0} algo-server | changed: [localhost] => (item=configs/10.99.0.10/wireguard//.pki//public) => {"ansible_loop_var": "item", "changed": true, "gid": 0, "group": "root", "item": "configs/10.99.0.10/wireguard//.pki//public", "mode": "0755", "owner": "root", "path": "configs/10.99.0.10/wireguard//.pki//public", "size": 4096, "state": "directory", "uid": 0} algo-server | changed: [localhost] => (item=configs/10.99.0.10/wireguard//apple/ios) => {"ansible_loop_var": "item", "changed": true, "gid": 0, "group": "root", "item": "configs/10.99.0.10/wireguard//apple/ios", "mode": "0755", "owner": "root", "path": "configs/10.99.0.10/wireguard//apple/ios", "size": 4096, "state": "directory", "uid": 0} algo-server | changed: [localhost] => (item=configs/10.99.0.10/wireguard//apple/macos) => {"ansible_loop_var": "item", "changed": true, "gid": 0, "group": "root", "item": "configs/10.99.0.10/wireguard//apple/macos", "mode": "0755", "owner": "root", "path": "configs/10.99.0.10/wireguard//apple/macos", "size": 4096, "state": "directory", "uid": 0} algo-server | algo-server | TASK [wireguard : Include tasks for Ubuntu] ************************************ algo-server | included: /algo/roles/wireguard/tasks/ubuntu.yml for localhost algo-server | algo-server | TASK [wireguard : WireGuard installed] ***************************************** algo-server | fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to update apt cache: unknown reason"} algo-server | algo-server | TASK [include_tasks] *********************************************************** algo-server | included: /algo/playbooks/rescue.yml for localhost algo-server | algo-server | TASK [debug] ******************************************************************* algo-server | ok: [localhost] => { algo-server | "fail_hint": "VARIABLE IS NOT DEFINED!: 'fail_hint' is undefined. 'fail_hint' is undefined" algo-server | } algo-server | algo-server | TASK [Fail the installation] *************************************************** algo-server | fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed as requested from task"} algo-server | algo-server | PLAY RECAP ********************************************************************* algo-server | localhost : ok=50 changed=17 unreachable=0 failed=1 skipped=41 rescued=1 ignored=1 algo-server | ================================================ FILE: tests/test-aws-credentials.yml ================================================ --- # Test AWS credential reading from files # Run with: ansible-playbook tests/test-aws-credentials.yml - name: Test AWS credential file reading hosts: localhost gather_facts: no vars: # These would normally come from config.cfg cloud_providers: ec2: use_existing_eip: false tasks: - name: Test with environment variables block: - include_tasks: ../roles/cloud-ec2/tasks/prompts.yml vars: algo_server_name: test-server - assert: that: - access_key == "test_env_key" - secret_key == "test_env_secret" msg: "Environment variables should take precedence" vars: AWS_ACCESS_KEY_ID: "test_env_key" AWS_SECRET_ACCESS_KEY: "test_env_secret" environment: AWS_ACCESS_KEY_ID: "test_env_key" AWS_SECRET_ACCESS_KEY: "test_env_secret" - name: Test with command line variables block: - include_tasks: ../roles/cloud-ec2/tasks/prompts.yml vars: aws_access_key: "test_cli_key" aws_secret_key: "test_cli_secret" algo_server_name: test-server region: "us-east-1" - assert: that: - access_key == "test_cli_key" - secret_key == "test_cli_secret" msg: "Command line variables should take precedence over everything" - name: Test reading from credentials file block: - name: Create test credentials directory file: path: /tmp/test-aws state: directory mode: '0700' - name: Create test credentials file copy: dest: /tmp/test-aws/credentials mode: '0600' content: | [default] aws_access_key_id = test_file_key aws_secret_access_key = test_file_secret [test-profile] aws_access_key_id = test_profile_key aws_secret_access_key = test_profile_secret aws_session_token = test_session_token - name: Test default profile include_tasks: ../roles/cloud-ec2/tasks/prompts.yml vars: algo_server_name: test-server region: "us-east-1" environment: HOME: /tmp/test-aws AWS_ACCESS_KEY_ID: "" AWS_SECRET_ACCESS_KEY: "" - assert: that: - access_key == "test_file_key" - secret_key == "test_file_secret" msg: "Should read from default profile" - name: Test custom profile include_tasks: ../roles/cloud-ec2/tasks/prompts.yml vars: algo_server_name: test-server region: "us-east-1" environment: HOME: /tmp/test-aws AWS_PROFILE: "test-profile" AWS_ACCESS_KEY_ID: "" AWS_SECRET_ACCESS_KEY: "" - assert: that: - access_key == "test_profile_key" - secret_key == "test_profile_secret" - session_token == "test_session_token" msg: "Should read from custom profile with session token" - name: Cleanup test directory file: path: /tmp/test-aws state: absent ================================================ FILE: tests/test-local-config.sh ================================================ #!/bin/bash # Simple test that verifies Algo can generate configurations without errors set -e echo "Testing Algo configuration generation..." # Generate SSH key if it doesn't exist if [ ! -f ~/.ssh/id_rsa ]; then ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' fi # Create a minimal test configuration cat > test-config.cfg << 'EOF' users: - test-user cloud_providers: local: server: localhost endpoint: 127.0.0.1 wireguard_enabled: true ipsec_enabled: false dns_adblocking: false ssh_tunneling: false store_pki: true tests: true algo_provider: local algo_server_name: test-server algo_ondemand_cellular: false algo_ondemand_wifi: false algo_ondemand_wifi_exclude: "" algo_dns_adblocking: false algo_ssh_tunneling: false wireguard_PersistentKeepalive: 0 wireguard_network: 10.19.49.0/24 wireguard_network_ipv6: fd9d:bc11:4020::/48 wireguard_port: 51820 dns_encryption: false subjectAltName_type: IP subjectAltName: 127.0.0.1 IP_subject_alt_name: 127.0.0.1 algo_server: localhost algo_user: ubuntu ansible_ssh_user: ubuntu algo_ssh_port: 22 endpoint: 127.0.0.1 server: localhost ssh_user: ubuntu CA_password: "test-password-123" p12_export_password: "test-export-password" EOF # Run Ansible in check mode to verify templates work echo "Running Ansible in check mode..." uv run ansible-playbook main.yml \ -i "localhost," \ -c local \ -e @test-config.cfg \ -e "provider=local" \ --check \ --diff \ --tags "configuration" \ --skip-tags "restart_services,tests,assert,cloud,facts_install" echo "Configuration generation test passed!" # Clean up rm -f test-config.cfg ================================================ FILE: tests/test-wireguard-async.yml ================================================ --- # Test WireGuard async result structure handling # This simulates the async_status result structure to verify our fix - name: Test WireGuard async result handling hosts: localhost gather_facts: no vars: # Simulate the actual structure that async_status with with_items returns # This is the key insight: async_status results contain the original item info mock_wg_genkey_results: results: - item: "user1" # This comes from the original wg_genkey.results item stdout: "mock_private_key_1" # This is the command output changed: true rc: 0 failed: false finished: true - item: "10.10.10.1" # This comes from the original wg_genkey.results item stdout: "mock_private_key_2" # This is the command output changed: true rc: 0 failed: false finished: true wireguard_pki_path: "/tmp/test-wireguard-pki" tasks: - name: Create test directories file: path: "{{ item }}" state: directory mode: '0700' loop: - "{{ wireguard_pki_path }}/private" - "{{ wireguard_pki_path }}/preshared" - name: Test private key saving (using with_items like the actual code) copy: dest: "{{ wireguard_pki_path }}/private/{{ item.item }}" content: "{{ item.stdout }}" mode: "0600" when: item.changed loop: "{{ mock_wg_genkey_results.results }}" - name: Verify files were created correctly stat: path: "{{ wireguard_pki_path }}/private/{{ item }}" register: file_check loop: - "user1" - "10.10.10.1" - name: Assert files exist assert: that: - item.stat.exists - item.stat.mode == "0600" msg: "Private key file should exist with correct permissions" loop: "{{ file_check.results }}" - name: Verify file contents slurp: src: "{{ wireguard_pki_path }}/private/{{ item }}" register: file_contents loop: - "user1" - "10.10.10.1" - name: Assert file contents are correct assert: that: - (file_contents.results[0].content | b64decode) == "mock_private_key_1" - (file_contents.results[1].content | b64decode) == "mock_private_key_2" msg: "File contents should match expected values" # Test the error handling path too - name: Test error condition handling debug: msg: "Would display error for {{ item.item }}" when: item.rc is defined and item.rc != 0 loop: "{{ mock_wg_genkey_results.results }}" # This should not trigger since our mock data has rc: 0 - name: Cleanup test directory file: path: "{{ wireguard_pki_path }}" state: absent ================================================ FILE: tests/test-wireguard-fix.yml ================================================ --- # Test the corrected WireGuard async pattern - name: Test corrected WireGuard async pattern hosts: localhost gather_facts: no vars: test_users: ["testuser1", "testuser2"] IP_subject_alt_name: "127.0.0.1" wireguard_pki_path: "/tmp/test-fixed-wireguard" tasks: - name: Create test directory file: path: "{{ wireguard_pki_path }}/private" state: directory mode: '0700' - name: Generate keys (parallel) - simulating wg genkey command: echo "mock_private_key_for_{{ item }}" register: wg_genkey loop: "{{ test_users + [IP_subject_alt_name] }}" async: 10 poll: 0 - name: Wait for completion - simulating async_status async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ wg_genkey.results }}" register: wg_genkey_results until: wg_genkey_results.finished retries: 15 delay: 1 - name: Save using CORRECTED pattern - item.item.item copy: dest: "{{ wireguard_pki_path }}/private/{{ item.item.item }}" content: "{{ item.stdout }}" mode: "0600" when: item.changed loop: "{{ wg_genkey_results.results }}" - name: Verify files were created with correct names stat: path: "{{ wireguard_pki_path }}/private/{{ item }}" register: file_check loop: - "testuser1" - "testuser2" - "127.0.0.1" - name: Assert all files exist assert: that: - item.stat.exists msg: "File should exist: {{ item.stat.path }}" loop: "{{ file_check.results }}" - name: Cleanup file: path: "{{ wireguard_pki_path }}" state: absent - debug: msg: "✅ WireGuard async fix test PASSED - item.item.item is the correct pattern!" ================================================ FILE: tests/test-wireguard-real-async.yml ================================================ --- # CRITICAL TEST: WireGuard Async Structure Debugging # ================================================== # This test validates the complex triple-nested data structure created by: # async + register + loop -> async_status + register + loop # # DO NOT DELETE: This test prevented production deployment failures by revealing # that the access pattern is item.item.item (not item.item as initially assumed). # # Run with: ansible-playbook tests/test-wireguard-real-async.yml -v # Purpose: Debug and validate the async result structure when using with_items - name: Test real WireGuard async pattern hosts: localhost gather_facts: no vars: test_users: ["testuser1", "testuser2"] IP_subject_alt_name: "127.0.0.1" wireguard_pki_path: "/tmp/test-real-wireguard" tasks: - name: Create test directory file: path: "{{ wireguard_pki_path }}/private" state: directory mode: '0700' - name: Simulate the actual async pattern - Generate keys (parallel) command: echo "mock_private_key_for_{{ item }}" register: wg_genkey loop: "{{ test_users + [IP_subject_alt_name] }}" async: 10 poll: 0 - name: Debug - Show wg_genkey structure debug: var: wg_genkey - name: Simulate the actual async pattern - Wait for completion async_status: jid: "{{ item.ansible_job_id }}" loop: "{{ wg_genkey.results }}" register: wg_genkey_results until: wg_genkey_results.finished retries: 15 delay: 1 - name: Debug - Show wg_genkey_results structure (the real issue) debug: var: wg_genkey_results - name: Try to save using the current failing pattern copy: dest: "{{ wireguard_pki_path }}/private/{{ item.item }}" content: "{{ item.stdout }}" mode: "0600" when: item.changed loop: "{{ wg_genkey_results.results }}" failed_when: false - name: Cleanup file: path: "{{ wireguard_pki_path }}" state: absent ================================================ FILE: tests/test_cloud_init_template.py ================================================ #!/usr/bin/env python3 """ Cloud-init template validation test. This test validates that the cloud-init template for DigitalOcean deployments renders correctly and produces valid YAML that cloud-init can parse. This test helps prevent regressions like issue #14800 where YAML formatting issues caused cloud-init to fail completely, resulting in SSH timeouts. Usage: python3 tests/test_cloud_init_template.py Or from project root: python3 -m pytest tests/test_cloud_init_template.py -v """ import sys from pathlib import Path import yaml # Add project root to path for imports if needed PROJECT_ROOT = Path(__file__).parent.parent sys.path.insert(0, str(PROJECT_ROOT)) def create_expected_cloud_init(): """ Create the expected cloud-init content that should be generated by our template after the YAML indentation fix. """ return """#cloud-config # CRITICAL: The above line MUST be exactly "#cloud-config" (no space after #) # This is required by cloud-init's YAML parser. Adding a space breaks parsing # and causes all cloud-init directives to be skipped, resulting in SSH timeouts. # See: https://github.com/trailofbits/algo/issues/14800 output: {all: '| tee -a /var/log/cloud-init-output.log'} package_update: true package_upgrade: true packages: - sudo users: - default - name: algo homedir: /home/algo sudo: ALL=(ALL) NOPASSWD:ALL groups: adm,netdev shell: /bin/bash lock_passwd: true ssh_authorized_keys: - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDTest algo-test" write_files: - path: /etc/ssh/sshd_config content: | Port 4160 AllowGroups algo PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication no UsePAM yes X11Forwarding yes PrintMotd no AcceptEnv LANG LC_* Subsystem sftp /usr/lib/openssh/sftp-server runcmd: - set -x - ufw --force reset - sudo apt-get remove -y --purge sshguard || true - systemctl restart sshd.service """ class TestCloudInitTemplate: """Test class for cloud-init template validation.""" def test_yaml_validity(self): """Test that the expected cloud-init YAML is valid.""" print("🧪 Testing YAML validity...") cloud_init_content = create_expected_cloud_init() try: parsed = yaml.safe_load(cloud_init_content) print("✅ YAML parsing successful") assert parsed is not None, "YAML should parse to a non-None value" return parsed except yaml.YAMLError as e: print(f"❌ YAML parsing failed: {e}") assert False, f"YAML parsing failed: {e}" def test_required_sections(self): """Test that all required cloud-init sections are present.""" print("🧪 Testing required sections...") parsed = self.test_yaml_validity() required_sections = ["package_update", "package_upgrade", "packages", "users", "write_files", "runcmd"] missing = [section for section in required_sections if section not in parsed] assert not missing, f"Missing required sections: {missing}" print("✅ All required sections present") def test_ssh_configuration(self): """Test that SSH configuration is correct.""" print("🧪 Testing SSH configuration...") parsed = self.test_yaml_validity() write_files = parsed.get("write_files", []) assert write_files, "write_files section should be present" # Find sshd_config file sshd_config = None for file_entry in write_files: if file_entry.get("path") == "/etc/ssh/sshd_config": sshd_config = file_entry break assert sshd_config, "sshd_config file should be in write_files" content = sshd_config.get("content", "") assert content, "sshd_config should have content" # Check required SSH configurations required_configs = ["Port 4160", "AllowGroups algo", "PermitRootLogin no", "PasswordAuthentication no"] missing = [config for config in required_configs if config not in content] assert not missing, f"Missing SSH configurations: {missing}" # Verify proper formatting - first line should be Port directive lines = content.strip().split("\n") assert lines[0].strip() == "Port 4160", f"First line should be 'Port 4160', got: {lines[0]!r}" print("✅ SSH configuration correct") def test_user_creation(self): """Test that algo user will be created correctly.""" print("🧪 Testing user creation...") parsed = self.test_yaml_validity() users = parsed.get("users", []) assert users, "users section should be present" # Find algo user algo_user = None for user in users: if isinstance(user, dict) and user.get("name") == "algo": algo_user = user break assert algo_user, "algo user should be defined" # Check required user properties required_props = ["sudo", "groups", "shell", "ssh_authorized_keys"] missing = [prop for prop in required_props if prop not in algo_user] assert not missing, f"algo user missing properties: {missing}" # Verify sudo configuration sudo_config = algo_user.get("sudo", "") assert "NOPASSWD:ALL" in sudo_config, f"sudo config should allow passwordless access: {sudo_config}" print("✅ User creation correct") def test_runcmd_section(self): """Test that runcmd section will restart SSH correctly.""" print("🧪 Testing runcmd section...") parsed = self.test_yaml_validity() runcmd = parsed.get("runcmd", []) assert runcmd, "runcmd section should be present" # Check for SSH restart command ssh_restart_found = False for cmd in runcmd: if "systemctl restart sshd" in str(cmd): ssh_restart_found = True break assert ssh_restart_found, f"SSH restart command not found in runcmd: {runcmd}" print("✅ runcmd section correct") def test_indentation_consistency(self): """Test that sshd_config content has consistent indentation.""" print("🧪 Testing indentation consistency...") cloud_init_content = create_expected_cloud_init() # Extract the sshd_config content lines lines = cloud_init_content.split("\n") in_sshd_content = False sshd_lines = [] for line in lines: if "content: |" in line: in_sshd_content = True continue elif in_sshd_content: if line.strip() == "" and len(sshd_lines) > 0: break if line.startswith("runcmd:"): break sshd_lines.append(line) assert sshd_lines, "Should be able to extract sshd_config content" # Check that all non-empty lines have consistent 6-space indentation non_empty_lines = [line for line in sshd_lines if line.strip()] assert non_empty_lines, "sshd_config should have content" for line in non_empty_lines: # Each line should start with exactly 6 spaces assert line.startswith(" ") and not line.startswith(" "), ( f"Line should have exactly 6 spaces indentation: {line!r}" ) print("✅ Indentation is consistent") def run_tests(): """Run all tests manually (for non-pytest usage).""" print("🚀 Cloud-init template validation tests") print("=" * 50) test_instance = TestCloudInitTemplate() try: test_instance.test_yaml_validity() test_instance.test_required_sections() test_instance.test_ssh_configuration() test_instance.test_user_creation() test_instance.test_runcmd_section() test_instance.test_indentation_consistency() print("=" * 50) print("🎉 ALL TESTS PASSED!") print("✅ Cloud-init template is working correctly") print("✅ DigitalOcean deployment should succeed") return True except AssertionError as e: print(f"❌ Test failed: {e}") return False except Exception as e: print(f"❌ Unexpected error: {e}") return False if __name__ == "__main__": success = run_tests() sys.exit(0 if success else 1) ================================================ FILE: tests/test_package_preinstall.py ================================================ #!/usr/bin/env python3 import unittest from jinja2 import Template class TestPackagePreinstall(unittest.TestCase): def setUp(self): """Set up test fixtures.""" # Create a simplified test template with just the packages section self.packages_template = Template(""" packages: - sudo {% if performance_preinstall_packages | default(false) %} # Universal tools always needed by Algo (performance optimization) - git - screen - apparmor-utils - uuid-runtime - coreutils - iptables-persistent - cgroup-tools {% endif %} """) def test_preinstall_disabled_by_default(self): """Test that package pre-installation is disabled by default.""" # Test with default config (performance_preinstall_packages not set) rendered = self.packages_template.render({}) # Should only have sudo package self.assertIn("- sudo", rendered) self.assertNotIn("- git", rendered) self.assertNotIn("- screen", rendered) self.assertNotIn("- apparmor-utils", rendered) def test_preinstall_enabled(self): """Test that package pre-installation works when enabled.""" # Test with pre-installation enabled rendered = self.packages_template.render({"performance_preinstall_packages": True}) # Should have sudo and all universal packages self.assertIn("- sudo", rendered) self.assertIn("- git", rendered) self.assertIn("- screen", rendered) self.assertIn("- apparmor-utils", rendered) self.assertIn("- uuid-runtime", rendered) self.assertIn("- coreutils", rendered) self.assertIn("- iptables-persistent", rendered) self.assertIn("- cgroup-tools", rendered) def test_preinstall_disabled_explicitly(self): """Test that package pre-installation is disabled when set to false.""" # Test with pre-installation explicitly disabled rendered = self.packages_template.render({"performance_preinstall_packages": False}) # Should only have sudo package self.assertIn("- sudo", rendered) self.assertNotIn("- git", rendered) self.assertNotIn("- screen", rendered) self.assertNotIn("- apparmor-utils", rendered) def test_package_count(self): """Test that the correct number of packages are included.""" # Default: should only have sudo (1 package) rendered_default = self.packages_template.render({}) lines_default = [line.strip() for line in rendered_default.split("\n") if line.strip().startswith("- ")] self.assertEqual(len(lines_default), 1) # Enabled: should have sudo + 7 universal packages (8 total) rendered_enabled = self.packages_template.render({"performance_preinstall_packages": True}) lines_enabled = [line.strip() for line in rendered_enabled.split("\n") if line.strip().startswith("- ")] self.assertEqual(len(lines_enabled), 8) if __name__ == "__main__": unittest.main() ================================================ FILE: tests/unit/test_ansible_12_boolean_fix.py ================================================ #!/usr/bin/env python3 """ Test that verifies the fix for Ansible 12.0.0 boolean type checking. This test reads the actual YAML files to ensure they don't produce string booleans. """ import re from pathlib import Path class TestAnsible12BooleanFix: """Tests to verify Ansible 12.0.0 boolean compatibility.""" def test_ipv6_support_not_string_boolean(self): """Verify ipv6_support in facts.yml doesn't produce string 'true'/'false'.""" facts_file = Path(__file__).parent.parent.parent / "roles/common/tasks/facts.yml" with open(facts_file) as f: content = f.read() # Check that we're NOT using the broken pattern broken_pattern = r'ipv6_support:\s*".*\}true\{.*\}false\{.*"' assert not re.search(broken_pattern, content), ( "ipv6_support is using string literals 'true'/'false' which breaks Ansible 12" ) # Check that we ARE using the correct pattern correct_pattern = r'ipv6_support:\s*".*is\s+defined.*"' assert re.search(correct_pattern, content), "ipv6_support should use 'is defined' which returns a boolean" def test_input_yml_algo_variables_not_string_boolean(self): """Verify algo_* variables in input.yml don't produce string 'false'.""" input_file = Path(__file__).parent.parent.parent / "input.yml" with open(input_file) as f: content = f.read() # Variables to check algo_vars = [ "algo_ondemand_cellular", "algo_ondemand_wifi", "algo_dns_adblocking", "algo_ssh_tunneling", "algo_store_pki", ] for var in algo_vars: # Find the variable definition var_pattern = rf"{var}:.*?\n(.*?)\n\s*algo_" match = re.search(var_pattern, content, re.DOTALL) if match: var_content = match.group(1) # Check that we're NOT using string literal 'false' # The broken pattern: {%- else %}false{% endif %} assert not re.search(r"\{%-?\s*else\s*%\}false\{%", var_content), ( f"{var} is using string literal 'false' which breaks Ansible 12" ) # Check that we ARE using {{ false }} # The correct pattern: {%- else %}{{ false }}{% endif %} if "else" in var_content: assert "{{ false }}" in var_content or "{{ true }}" in var_content or "| bool" in var_content, ( f"{var} should use '{{{{ false }}}}' or '{{{{ true }}}}' for boolean values" ) def test_no_bare_true_false_in_templates(self): """Scan for any remaining bare 'true'/'false' in Jinja2 expressions.""" # Patterns that indicate string boolean literals (bad) bad_patterns = [ r"\{%[^%]*\}true\{%", # %}true{% r"\{%[^%]*\}false\{%", # %}false{% r"%\}true\{%", # %}true{% r"%\}false\{%", # %}false{% ] files_to_check = [ Path(__file__).parent.parent.parent / "roles/common/tasks/facts.yml", Path(__file__).parent.parent.parent / "input.yml", ] for file_path in files_to_check: with open(file_path) as f: content = f.read() for pattern in bad_patterns: matches = re.findall(pattern, content) assert not matches, ( f"Found string boolean literal in {file_path.name}: {matches}. " f"Use '{{{{ true }}}}' or '{{{{ false }}}}' instead." ) def test_conditional_uses_of_variables(self): """Check that when: conditions using these variables will work with booleans.""" # Files that might have 'when:' conditions files_to_check = [ Path(__file__).parent.parent.parent / "roles/common/tasks/iptables.yml", Path(__file__).parent.parent.parent / "server.yml", Path(__file__).parent.parent.parent / "users.yml", ] for file_path in files_to_check: if not file_path.exists(): continue with open(file_path) as f: content = f.read() # Find when: conditions when_patterns = re.findall(r"when:\s*(\w+)\s*$", content, re.MULTILINE) # These variables must be booleans for Ansible 12 boolean_vars = ["ipv6_support", "algo_dns_adblocking", "algo_ssh_tunneling"] for var in when_patterns: if var in boolean_vars: # This is good - we're using the variable directly # which requires it to be a boolean in Ansible 12 pass # Test passes if we get here ================================================ FILE: tests/unit/test_basic_sanity.py ================================================ #!/usr/bin/env python3 """ Basic sanity tests for Algo VPN that don't require deployment """ import os import subprocess import sys import yaml def test_python_version(): """Ensure we're running on Python 3.11+""" assert sys.version_info >= (3, 11), f"Python 3.11+ required, got {sys.version}" print("✓ Python version check passed") def test_pyproject_file_exists(): """Check that pyproject.toml exists and has dependencies""" assert os.path.exists("pyproject.toml"), "pyproject.toml not found" with open("pyproject.toml") as f: content = f.read() assert "dependencies" in content, "No dependencies section in pyproject.toml" assert "ansible" in content, "ansible dependency not found" assert "jinja2" in content, "jinja2 dependency not found" assert "netaddr" in content, "netaddr dependency not found" print("✓ pyproject.toml exists with required dependencies") def test_config_file_valid(): """Check that config.cfg is valid YAML""" assert os.path.exists("config.cfg"), "config.cfg not found" with open("config.cfg") as f: try: config = yaml.safe_load(f) assert isinstance(config, dict), "config.cfg should parse as a dictionary" print("✓ config.cfg is valid YAML") except yaml.YAMLError as e: raise AssertionError(f"config.cfg is not valid YAML: {e}") from e def test_ansible_syntax(): """Check that main playbook has valid syntax""" result = subprocess.run(["ansible-playbook", "main.yml", "--syntax-check"], capture_output=True, text=True) assert result.returncode == 0, f"Ansible syntax check failed:\n{result.stderr}" print("✓ Ansible playbook syntax is valid") def test_shellcheck(): """Run shellcheck on shell scripts""" shell_scripts = ["algo", "install.sh"] for script in shell_scripts: if os.path.exists(script): result = subprocess.run(["shellcheck", script], capture_output=True, text=True) assert result.returncode == 0, f"Shellcheck failed for {script}:\n{result.stdout}" print(f"✓ {script} passed shellcheck") def test_dockerfile_exists(): """Check that Dockerfile exists and is not empty""" assert os.path.exists("Dockerfile"), "Dockerfile not found" with open("Dockerfile") as f: content = f.read() assert len(content) > 100, "Dockerfile seems too small" assert "FROM" in content, "Dockerfile missing FROM statement" print("✓ Dockerfile exists and looks valid") def test_cloud_init_header_format(): """Check that cloud-init header is exactly '#cloud-config' without space""" cloud_init_file = "files/cloud-init/base.yml" assert os.path.exists(cloud_init_file), f"{cloud_init_file} not found" with open(cloud_init_file) as f: first_line = f.readline().rstrip("\n\r") # The first line MUST be exactly "#cloud-config" (no space after #) # This regression was introduced in PR #14775 and broke DigitalOcean deployments # See: https://github.com/trailofbits/algo/issues/14800 assert first_line == "#cloud-config", ( f"cloud-init header must be exactly '#cloud-config' (no space), " f"got '{first_line}'. This breaks cloud-init YAML parsing and causes SSH timeouts." ) print("✓ cloud-init header format is correct") if __name__ == "__main__": # Change to repo root os.chdir(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) tests = [ test_python_version, test_pyproject_file_exists, test_config_file_valid, test_ansible_syntax, test_shellcheck, test_dockerfile_exists, test_cloud_init_header_format, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_boolean_variables.py ================================================ #!/usr/bin/env python3 """ Test that Ansible variables produce proper boolean types, not strings. This prevents issues with Ansible 12.0.0's strict type checking. """ import jinja2 def render_template(template_str, variables=None): """Render a Jinja2 template with given variables.""" env = jinja2.Environment() template = env.from_string(template_str) return template.render(variables or {}) class TestBooleanVariables: """Test that critical variables produce actual booleans.""" def test_ipv6_support_produces_boolean(self): """Ensure ipv6_support produces boolean, not string 'true'/'false'.""" # Test with gateway defined (should be boolean True) template = "{{ ansible_default_ipv6['gateway'] is defined }}" vars_with_gateway = {"ansible_default_ipv6": {"gateway": "fe80::1"}} result = render_template(template, vars_with_gateway) assert result == "True" # Jinja2 renders boolean True as string "True" # Test without gateway (should be boolean False) vars_no_gateway = {"ansible_default_ipv6": {}} result = render_template(template, vars_no_gateway) assert result == "False" # Jinja2 renders boolean False as string "False" # The key is that we're NOT producing string literals "true" or "false" bad_template = "{% if ansible_default_ipv6['gateway'] is defined %}true{% else %}false{% endif %}" result_bad = render_template(bad_template, vars_no_gateway) assert result_bad == "false" # This is a string literal, not a boolean # Verify our fix doesn't produce string literals assert result != "false" # Our fix produces "False" (from boolean), not "false" (string literal) def test_algo_variables_boolean_fallbacks(self): """Ensure algo_* variables produce booleans in their fallback cases.""" # Test the fixed template (produces boolean) good_template = "{% if var is defined %}{{ var | bool }}{%- else %}{{ false }}{% endif %}" result_good = render_template(good_template, {}) assert result_good == "False" # Boolean False renders as "False" # Test the old broken template (produces string) bad_template = "{% if var is defined %}{{ var | bool }}{%- else %}false{% endif %}" result_bad = render_template(bad_template, {}) assert result_bad == "false" # String literal "false" # Verify they're different assert result_good != result_bad assert result_good == "False" and result_bad == "false" def test_boolean_filter_on_strings(self): """Test that the bool filter correctly converts string values.""" # Since we can't test Ansible's bool filter directly in Jinja2, # we test the pattern we're using in our templates # Test that our templates don't use raw string "true"/"false" # which would fail in Ansible 12 bad_pattern = "{%- else %}false{% endif %}" good_pattern = "{%- else %}{{ false }}{% endif %}" # The bad pattern produces a string literal result_bad = render_template("{% if var is defined %}something" + bad_pattern, {}) assert "false" in result_bad # String literal # The good pattern produces a boolean value result_good = render_template("{% if var is defined %}something" + good_pattern, {}) assert "False" in result_good # Boolean False rendered as "False" def test_ansible_12_conditional_compatibility(self): """ Test that our fixes work with Ansible 12's strict type checking. This simulates what Ansible 12 will do with our variables. """ # Our fixed template - produces actual boolean fixed_ipv6 = "{{ ansible_default_ipv6['gateway'] is defined }}" fixed_algo = "{% if var is defined %}{{ var | bool }}{%- else %}{{ false }}{% endif %}" # Simulate the boolean value in a conditional context # In Ansible 12, this would fail if it's a string "true"/"false" vars_with_gateway = {"ansible_default_ipv6": {"gateway": "fe80::1"}} ipv6_result = render_template(fixed_ipv6, vars_with_gateway) # The result should be "True" (boolean rendered), not "true" (string literal) assert ipv6_result == "True" assert ipv6_result != "true" # Test algo variable fallback algo_result = render_template(fixed_algo, {}) assert algo_result == "False" assert algo_result != "false" def test_regression_no_string_booleans(self): """ Regression test: ensure we never produce string literals 'true' or 'false'. This is what breaks Ansible 12.0.0. """ # These patterns should NOT appear in our fixed code bad_patterns = [ "{}true{}", "{}false{}", "{%- else %}true{% endif %}", "{%- else %}false{% endif %}", ] # Test that our fixed templates don't produce string boolean literals fixed_template = "{{ ansible_default_ipv6['gateway'] is defined }}" for _pattern in bad_patterns: assert "true" not in fixed_template.replace(" ", "") assert "false" not in fixed_template.replace(" ", "") # Test algo variable fix fixed_algo = "{% if var is defined %}{{ var | bool }}{%- else %}{{ false }}{% endif %}" assert "{}false{}" not in fixed_algo.replace(" ", "") assert "{{ false }}" in fixed_algo ================================================ FILE: tests/unit/test_cloud_provider_configs.py ================================================ #!/usr/bin/env python3 """ Test cloud provider instance type configurations. Validates config.cfg against known-deprecated instance types that will fail at deployment time. Based on issue #14730 (Hetzner cx->cpx migration). Why not regex format validation? Providers constantly add new instance families (AWS m7.*, g5.*, etc.). Regex patterns would break on legitimate new values. Instead, we only check for KNOWN-BAD values that are definitively deprecated. """ from pathlib import Path import yaml # Only values that are KNOWN to fail - update when providers deprecate more DEPRECATED_VALUES = { # Intel CX series removed Sept 2024 - AMD CPX series still available # https://docs.hetzner.com/cloud/servers/deprecated-plans/ "hetzner": {"server_type": ["cx11", "cx21", "cx31", "cx41", "cx51"]}, # Old naming scheme deprecated ~2018, use s-*vcpu-* format "digitalocean": {"size": ["512mb", "1gb", "2gb", "4gb", "8gb", "16gb"]}, # Previous gen, unavailable in VPC after EC2-Classic retirement # https://aws.amazon.com/ec2/previous-generation/ "ec2": {"size": ["t1.micro", "m1.small", "m1.medium", "m1.large"]}, } REQUIRED_FIELDS = { "ec2": ["size"], "digitalocean": ["size", "image"], "hetzner": ["server_type", "image"], "vultr": ["size", "os"], "linode": ["type", "image"], "gce": ["size", "image"], "azure": ["size"], "lightsail": ["size", "image"], "scaleway": ["size", "image"], } def load_config(): """Load config.cfg from the repository root.""" config_path = Path(__file__).parents[2] / "config.cfg" return yaml.safe_load(config_path.read_text()) def test_no_deprecated_instance_types(): """Catch deprecated instance types before deployment fails.""" providers = load_config().get("cloud_providers", {}) for provider, fields in DEPRECATED_VALUES.items(): if provider not in providers: continue for field, deprecated in fields.items(): value = providers[provider].get(field) assert value not in deprecated, f"{provider}.{field}='{value}' is deprecated and will fail" def test_required_fields_present(): """Ensure critical fields aren't empty.""" providers = load_config().get("cloud_providers", {}) for provider, fields in REQUIRED_FIELDS.items(): if provider not in providers: continue for field in fields: value = providers[provider].get(field) # Skip nested dicts (like ec2.image which has subfields) if isinstance(value, dict): continue assert value, f"{provider}.{field} is empty or missing" def test_no_malformed_values(): """Basic sanity - no control chars, reasonable length.""" providers = load_config().get("cloud_providers", {}) for provider, settings in providers.items(): if not isinstance(settings, dict): continue for field, value in settings.items(): if not isinstance(value, str): continue assert "\n" not in value, f"{provider}.{field} contains newline" assert len(value) <= 128, f"{provider}.{field} too long ({len(value)} chars)" ================================================ FILE: tests/unit/test_comprehensive_boolean_scan.py ================================================ #!/usr/bin/env python3 """ Test suite to prevent Ansible 12+ boolean type errors in Algo VPN codebase. Background: ----------- Ansible 12.0.0 introduced strict boolean type checking that breaks deployments when string values like "true" or "false" are used in conditionals. This causes errors like: "Conditional result (True) was derived from value of type 'str'" What This Test Protects Against: --------------------------------- 1. String literals "true"/"false" being used instead of actual booleans 2. Bare true/false in Jinja2 else clauses (should be {{ true }}/{{ false }}) 3. String comparisons in when: conditions (e.g., var == "true") 4. Variables being set to string booleans instead of actual booleans Test Scope: ----------- - Only tests Algo's own code (roles/, playbooks/, etc.) - Excludes external dependencies (.env/, ansible_collections/) - Excludes CloudFormation templates which require string booleans - Excludes test files which may use different patterns Mutation Testing Verified: -------------------------- All tests have been verified to catch their target issues through mutation testing: - Introducing bare 'false' in else clause → caught by test_no_bare_false_in_jinja_else - Using string boolean in facts.yml → caught by test_verify_our_fixes_are_correct - Adding string boolean assignments → caught by test_no_other_problematic_patterns Related Issues: --------------- - PR #14834: Fixed initial boolean type issues for Ansible 12 - Issue #14835: Fixed double-templating issues exposed by Ansible 12 """ import re from pathlib import Path class TestComprehensiveBooleanScan: """Scan entire codebase for potential string boolean issues.""" def get_yaml_files(self): """Get all YAML files in the Algo project, excluding external dependencies.""" root = Path(__file__).parent.parent.parent yaml_files = [] # Define directories to scan (Algo's actual code) algo_dirs = [ "roles", "playbooks", "library", "files/cloud-init", # Include cloud-init templates but not CloudFormation ] # Add root-level YAML files yaml_files.extend(root.glob("*.yml")) yaml_files.extend(root.glob("*.yaml")) # Add YAML files from Algo directories for dir_name in algo_dirs: dir_path = root / dir_name if dir_path.exists(): yaml_files.extend(dir_path.glob("**/*.yml")) yaml_files.extend(dir_path.glob("**/*.yaml")) # Exclude patterns excluded = [ ".venv", # Virtual environment ".env", # Another virtual environment pattern "venv", # Yet another virtual environment "test", # Test files (but keep our own tests) "molecule", # Molecule test files "site-packages", # Python packages "ansible_collections", # External Ansible collections "stack.yaml", # CloudFormation templates (use string booleans by design) "stack.yml", # CloudFormation templates ".git", # Git directory "__pycache__", # Python cache ] # Filter out excluded paths and CloudFormation templates filtered = [] for f in yaml_files: path_str = str(f) # Skip if path contains any excluded pattern if any(exc in path_str for exc in excluded): continue # Skip CloudFormation templates in files/ directories if "/files/" in path_str and f.name in ["stack.yaml", "stack.yml"]: continue filtered.append(f) return filtered def test_no_string_true_false_in_set_fact(self): """Scan all YAML files for set_fact with string 'true'/'false'.""" issues = [] pattern = re.compile(r'set_fact:.*?\n.*?:\s*".*\}(true|false)\{.*"', re.MULTILINE | re.DOTALL) for yaml_file in self.get_yaml_files(): with open(yaml_file) as f: content = f.read() matches = pattern.findall(content) if matches: issues.append(f"{yaml_file.name}: Found string boolean in set_fact: {matches}") assert not issues, "Found string booleans in set_fact:\n" + "\n".join(issues) def test_no_bare_false_in_jinja_else(self): """Check for bare 'false' after else in Jinja expressions.""" issues = [] # Pattern for {%- else %}false{% (should be {{ false }}) pattern = re.compile(r"\{%-?\s*else\s*%\}(true|false)\{%") for yaml_file in self.get_yaml_files(): with open(yaml_file) as f: content = f.read() matches = pattern.findall(content) if matches: issues.append(f"{yaml_file.name}: Found bare '{matches[0]}' after else") assert not issues, "Found bare true/false in else clauses:\n" + "\n".join(issues) def test_when_conditions_use_booleans(self): """Verify 'when:' conditions that use our variables.""" boolean_vars = [ "ipv6_support", "algo_dns_adblocking", "algo_ssh_tunneling", "algo_ondemand_cellular", "algo_ondemand_wifi", "algo_store_pki", ] potential_issues = [] for yaml_file in self.get_yaml_files(): with open(yaml_file) as f: lines = f.readlines() for i, line in enumerate(lines): if "when:" in line: for var in boolean_vars: if var in line: # Check if it's a simple condition (good) or comparing to string (bad) if ( f'{var} == "true"' in line or f'{var} == "false"' in line or f'{var} != "true"' in line or f'{var} != "false"' in line ): potential_issues.append( f"{yaml_file.name}:{i + 1}: Comparing {var} to string in when condition" ) assert not potential_issues, "Found string comparisons in when conditions:\n" + "\n".join(potential_issues) def test_template_files_boolean_usage(self): """Check Jinja2 template files for boolean usage.""" root = Path(__file__).parent.parent.parent template_files = list(root.glob("**/*.j2")) issues = [] for template_file in template_files: if ".venv" in str(template_file): continue with open(template_file) as f: content = f.read() # Check for conditionals using our boolean variables if "ipv6_support" in content: # Look for string comparisons if 'ipv6_support == "true"' in content or 'ipv6_support == "false"' in content: issues.append(f"{template_file.name}: Comparing ipv6_support to string") # Check it's used correctly in if statements if re.search(r'{%\s*if\s+ipv6_support\s*==\s*["\']true["\']', content): issues.append(f"{template_file.name}: String comparison with ipv6_support") assert not issues, "Found issues in template files:\n" + "\n".join(issues) def test_all_when_conditions_would_work(self): """Test that all when: conditions in the codebase would work with boolean types.""" root = Path(__file__).parent.parent.parent test_files = [ root / "roles/common/tasks/iptables.yml", root / "server.yml", root / "users.yml", root / "roles/dns/tasks/main.yml", ] for test_file in test_files: if not test_file.exists(): continue with open(test_file) as f: content = f.read() # Find all when: conditions when_lines = re.findall(r"when:\s*([^\n]+)", content) for when_line in when_lines: # Check if it's using one of our boolean variables if any(var in when_line for var in ["ipv6_support", "algo_dns_adblocking", "algo_ssh_tunneling"]): # Ensure it's not comparing to strings assert '"true"' not in when_line, f"String comparison in {test_file.name}: {when_line}" assert '"false"' not in when_line, f"String comparison in {test_file.name}: {when_line}" assert "'true'" not in when_line, f"String comparison in {test_file.name}: {when_line}" assert "'false'" not in when_line, f"String comparison in {test_file.name}: {when_line}" def test_no_other_problematic_patterns(self): """Look for patterns that would cause Ansible 12 boolean type issues in Algo code.""" # These patterns would break Ansible 12's strict boolean checking problematic_patterns = [ (r':\s*["\']true["\']$', "Assigning string 'true' to variable"), (r':\s*["\']false["\']$', "Assigning string 'false' to variable"), (r'default\(["\']true["\']\)', "Using string 'true' as default"), (r'default\(["\']false["\']\)', "Using string 'false' as default"), ] # Known safe exceptions in Algo safe_patterns = [ "booleans_map", # This maps string inputs to booleans "test_", # Test files may use different patterns "molecule", # Molecule tests "ANSIBLE_", # Environment variables are strings "validate_certs", # Some modules accept string booleans "Default:", # CloudFormation parameter defaults ] issues = [] for yaml_file in self.get_yaml_files(): # Skip files that aren't Ansible playbooks/tasks/vars parts_to_check = ["tasks", "vars", "defaults", "handlers", "meta", "playbooks"] main_files = ["main.yml", "users.yml", "server.yml", "input.yml"] if not any(part in str(yaml_file) for part in parts_to_check) and yaml_file.name not in main_files: continue with open(yaml_file) as f: lines = f.readlines() for i, line in enumerate(lines): # Skip comments and empty lines stripped_line = line.strip() if not stripped_line or stripped_line.startswith("#"): continue for pattern, description in problematic_patterns: if re.search(pattern, line): # Check if it's a known safe pattern if not any(safe in line for safe in safe_patterns): # This is a real issue that would break Ansible 12 rel_path = yaml_file.relative_to(Path(__file__).parent.parent.parent) issues.append(f"{rel_path}:{i + 1}: {description} - {stripped_line}") # All Algo code should be fixed assert not issues, "Found boolean type issues that would break Ansible 12:\n" + "\n".join(issues[:10]) def test_verify_our_fixes_are_correct(self): """Verify our specific fixes are in place and correct.""" # Check facts.yml facts_file = Path(__file__).parent.parent.parent / "roles/common/tasks/facts.yml" with open(facts_file) as f: content = f.read() # Should use 'is defined', not string literals assert "is defined" in content, "facts.yml should use 'is defined'" old_pattern = "ipv6_support: \"{% if ansible_default_ipv6['gateway'] is defined %}" old_pattern += 'true{% else %}false{% endif %}"' assert old_pattern not in content, "facts.yml still has the old string boolean pattern" # Check input.yml input_file = Path(__file__).parent.parent.parent / "input.yml" with open(input_file) as f: content = f.read() # Count occurrences of the fix assert content.count("{{ false }}") >= 5, "input.yml should have at least 5 instances of {{ false }}" assert "{%- else %}false{% endif %}" not in content, "input.yml still has bare 'false'" def test_templates_handle_booleans_correctly(self): """Test that template files handle boolean variables correctly.""" templates_to_check = [ ("roles/wireguard/templates/server.conf.j2", "ipv6_support"), ("roles/strongswan/templates/ipsec.conf.j2", "ipv6_support"), ("roles/dns/templates/dnscrypt-proxy.toml.j2", "ipv6_support"), ] for template_path, var_name in templates_to_check: template_file = Path(__file__).parent.parent.parent / template_path if not template_file.exists(): continue with open(template_file) as f: content = f.read() if var_name in content: # Verify it's used in conditionals, not compared to strings assert f'{var_name} == "true"' not in content, f"{template_path} compares {var_name} to string 'true'" assert f'{var_name} == "false"' not in content, f"{template_path} compares {var_name} to string 'false'" # It should be used directly in if statements or with | bool filter if f"if {var_name}" in content or f"{var_name} |" in content: pass # Good - using it as a boolean ================================================ FILE: tests/unit/test_config_validation.py ================================================ #!/usr/bin/env python3 """ Test configuration file validation without deployment """ import configparser import os import re import subprocess import sys import tempfile def test_wireguard_config_format(): """Test that we can validate WireGuard config format""" # Sample minimal WireGuard config sample_config = """[Interface] PrivateKey = aGVsbG8gd29ybGQgdGhpcyBpcyBub3QgYSByZWFsIGtleQo= Address = 10.19.49.2/32 DNS = 10.19.49.1 [Peer] PublicKey = U29tZVB1YmxpY0tleVRoYXRJc05vdFJlYWxseVZhbGlkCg== AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 192.168.1.1:51820 """ # Validate it has required sections config = configparser.ConfigParser() config.read_string(sample_config) assert "Interface" in config, "Missing [Interface] section" assert "Peer" in config, "Missing [Peer] section" # Validate required fields assert config["Interface"].get("PrivateKey"), "Missing PrivateKey" assert config["Interface"].get("Address"), "Missing Address" assert config["Peer"].get("PublicKey"), "Missing PublicKey" assert config["Peer"].get("AllowedIPs"), "Missing AllowedIPs" print("✓ WireGuard config format validation passed") def test_base64_key_format(): """Test that keys are in valid base64 format""" # Base64 keys can have variable length, just check format key_pattern = re.compile(r"^[A-Za-z0-9+/]+=*$") test_keys = [ "aGVsbG8gd29ybGQgdGhpcyBpcyBub3QgYSByZWFsIGtleQo=", "U29tZVB1YmxpY0tleVRoYXRJc05vdFJlYWxseVZhbGlkCg==", ] for key in test_keys: assert key_pattern.match(key), f"Invalid key format: {key}" print("✓ Base64 key format validation passed") def test_ip_address_format(): """Test IP address and CIDR notation validation""" ip_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}$") endpoint_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$") # Test CIDR notation assert ip_pattern.match("10.19.49.2/32"), "Invalid CIDR notation" assert ip_pattern.match("192.168.1.0/24"), "Invalid CIDR notation" # Test endpoint format assert endpoint_pattern.match("192.168.1.1:51820"), "Invalid endpoint format" print("✓ IP address format validation passed") def test_mobile_config_xml(): """Test that mobile config files would be valid XML""" # First check if xmllint is available xmllint_check = subprocess.run(["which", "xmllint"], capture_output=True, text=True) if xmllint_check.returncode != 0: print("⚠ Skipping XML validation test (xmllint not installed)") return sample_mobileconfig = """ PayloadDisplayName Algo VPN PayloadIdentifier com.algo-vpn.ios PayloadType Configuration PayloadVersion 1 """ with tempfile.NamedTemporaryFile(mode="w", suffix=".mobileconfig", delete=False) as f: f.write(sample_mobileconfig) temp_file = f.name try: # Use xmllint to validate result = subprocess.run(["xmllint", "--noout", temp_file], capture_output=True, text=True) assert result.returncode == 0, f"XML validation failed: {result.stderr}" print("✓ Mobile config XML validation passed") finally: os.unlink(temp_file) def test_port_ranges(): """Test that configured ports are in valid ranges""" valid_ports = [22, 80, 443, 500, 4500, 51820] for port in valid_ports: assert 1 <= port <= 65535, f"Invalid port number: {port}" # Test common VPN ports assert 500 in valid_ports, "Missing IKE port 500" assert 4500 in valid_ports, "Missing IPsec NAT-T port 4500" assert 51820 in valid_ports, "Missing WireGuard port 51820" print("✓ Port range validation passed") if __name__ == "__main__": tests = [ test_wireguard_config_format, test_base64_key_format, test_ip_address_format, test_mobile_config_xml, test_port_ranges, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_destroy.py ================================================ """Tests for the destroy playbook and provider destroy task files.""" import os import subprocess import yaml # type: ignore[import-untyped] PROVIDERS = [ "digitalocean", "ec2", "lightsail", "azure", "gce", "hetzner", "vultr", "scaleway", "openstack", "cloudstack", "linode", ] REGION_REQUIRED_PROVIDERS = ["ec2", "lightsail", "gce", "scaleway", "vultr"] def test_destroy_playbook_exists(): """destroy.yml must exist at repo root.""" assert os.path.exists("destroy.yml"), "destroy.yml not found" def test_destroy_playbook_valid_yaml(): """destroy.yml must be valid YAML.""" with open("destroy.yml") as f: data = yaml.safe_load(f) assert isinstance(data, list), "destroy.yml should be a YAML list" assert len(data) == 1, "destroy.yml should have one play" play = data[0] assert play["hosts"] == "localhost" assert play["gather_facts"] is False def test_destroy_playbook_syntax(): """destroy.yml must pass ansible-playbook --syntax-check.""" result = subprocess.run( ["ansible-playbook", "destroy.yml", "--syntax-check"], capture_output=True, text=True, ) assert result.returncode == 0, f"Syntax check failed:\n{result.stderr}" def test_destroy_playbook_has_rescue(): """destroy.yml must include a rescue block for error handling.""" with open("destroy.yml") as f: content = f.read() assert "rescue:" in content assert "rescue.yml" in content def test_destroy_playbook_has_confirmation(): """destroy.yml must have a confirmation step.""" with open("destroy.yml") as f: content = f.read() assert "confirm" in content.lower() def test_all_provider_destroy_files_exist(): """Every cloud provider must have a destroy.yml task file.""" for provider in PROVIDERS: path = f"roles/cloud-{provider}/tasks/destroy.yml" assert os.path.exists(path), f"Missing destroy task file: {path}" def test_all_provider_destroy_files_valid_yaml(): """Every provider destroy.yml must be valid YAML.""" for provider in PROVIDERS: path = f"roles/cloud-{provider}/tasks/destroy.yml" with open(path) as f: data = yaml.safe_load(f) assert isinstance(data, list), f"{path} should be a YAML list" def test_provider_destroy_uses_absent_state(): """Each provider destroy file must use state: absent (or expunged).""" for provider in PROVIDERS: path = f"roles/cloud-{provider}/tasks/destroy.yml" with open(path) as f: content = f.read() assert "absent" in content or "expunged" in content, f"{path} missing state: absent/expunged" def test_ec2_destroy_uses_cloudformation(): """EC2 destroy should delete the CloudFormation stack.""" with open("roles/cloud-ec2/tasks/destroy.yml") as f: content = f.read() assert "cloudformation" in content assert "stack_name" in content def test_lightsail_destroy_uses_cloudformation(): """Lightsail destroy should delete the CloudFormation stack.""" with open("roles/cloud-lightsail/tasks/destroy.yml") as f: content = f.read() assert "cloudformation" in content assert "stack_name" in content def test_gce_destroy_cleans_subsidiary_resources(): """GCE destroy should clean up firewall, static IP, and network.""" with open("roles/cloud-gce/tasks/destroy.yml") as f: content = f.read() assert "gcp_compute_firewall" in content assert "gcp_compute_address" in content assert "gcp_compute_network" in content def test_vultr_destroy_cleans_firewall_group(): """Vultr destroy should remove the firewall group.""" with open("roles/cloud-vultr/tasks/destroy.yml") as f: content = f.read() assert "firewall_group" in content def test_openstack_destroy_cleans_security_group(): """OpenStack destroy should remove the security group.""" with open("roles/cloud-openstack/tasks/destroy.yml") as f: content = f.read() assert "security_group" in content def test_cloudstack_destroy_cleans_security_group(): """CloudStack destroy should remove the security group.""" with open("roles/cloud-cloudstack/tasks/destroy.yml") as f: content = f.read() assert "security_group" in content def test_subsidiary_cleanup_is_best_effort(): """Subsidiary resource cleanup should use failed_when: false.""" files_with_subsidiary = { "gce": ["gcp_compute_address", "gcp_compute_firewall", "gcp_compute_network"], "vultr": ["firewall_group"], "openstack": ["security_group"], "cloudstack": ["security_group"], } for provider, _resources in files_with_subsidiary.items(): path = f"roles/cloud-{provider}/tasks/destroy.yml" with open(path) as f: content = f.read() assert "failed_when: false" in content, f"{path} should use failed_when: false for subsidiary cleanup" def test_linode_uses_label_not_name(): """Linode module uses 'label' parameter, not 'name'.""" with open("roles/cloud-linode/tasks/destroy.yml") as f: content = f.read() assert "label:" in content, "Linode destroy should use 'label' parameter" def test_azure_deletes_resource_group(): """Azure destroy should delete the entire resource group.""" with open("roles/cloud-azure/tasks/destroy.yml") as f: content = f.read() assert "azure_rm_resourcegroup" in content assert "force_delete_nonempty" in content def test_algo_script_has_destroy_command(): """The algo shell script must include the destroy subcommand.""" with open("algo") as f: content = f.read() assert "destroy)" in content assert "destroy.yml" in content def test_algo_script_destroy_requires_ip(): """The destroy command should validate that an IP is provided.""" with open("algo") as f: content = f.read() assert "server_ip=$2" in content def test_server_yml_stores_algo_region(): """server.yml should store algo_region in .config.yml.""" with open("server.yml") as f: content = f.read() assert "algo_region" in content def test_destroy_playbook_validates_region_for_required_providers(): """destroy.yml must check region for ec2/lightsail/gce/scaleway.""" with open("destroy.yml") as f: content = f.read() for provider in REGION_REQUIRED_PROVIDERS: assert provider in content, f"destroy.yml should reference {provider} in region validation" def test_destroy_playbook_loads_server_config(): """destroy.yml must load .config.yml from the configs directory.""" with open("destroy.yml") as f: content = f.read() assert ".config.yml" in content assert "include_vars" in content ================================================ FILE: tests/unit/test_docker_localhost_deployment.py ================================================ #!/usr/bin/env python3 """ Simplified Docker-based localhost deployment tests Verifies services can start and config files exist in expected locations """ import os import subprocess import sys def check_docker_available(): """Check if Docker is available""" try: result = subprocess.run(["docker", "--version"], capture_output=True, text=True) return result.returncode == 0 except FileNotFoundError: return False def test_wireguard_config_validation(): """Test that WireGuard configs can be validated""" # Create a test WireGuard config config = """[Interface] PrivateKey = EEHcgpEB8JIlUZpYnt3PqJJgfwgRGDQNlGH7gYkMVGo= Address = 10.19.49.1/24,fd9d:bc11:4020::1/64 ListenPort = 51820 [Peer] PublicKey = lIiWMxCWtXG5hqZECMXm7mA/4pNKKqtJIBZ5Fc1SeHg= AllowedIPs = 10.19.49.2/32,fd9d:bc11:4020::2/128 """ # Just validate the format required_sections = ["[Interface]", "[Peer]"] required_fields = ["PrivateKey", "Address", "PublicKey", "AllowedIPs"] for section in required_sections: if section not in config: print(f"✗ Missing {section} section") return False for field in required_fields: if field not in config: print(f"✗ Missing {field} field") return False print("✓ WireGuard config format is valid") return True def test_strongswan_config_validation(): """Test that StrongSwan configs can be validated""" config = """config setup charondebug="ike 1" uniqueids=never conn %default keyexchange=ikev2 ike=aes128-sha256-modp2048 esp=aes128-sha256-modp2048 conn ikev2-pubkey left=%any leftid=@10.0.0.1 leftcert=server.crt right=%any rightauth=pubkey """ # Validate format if "config setup" not in config: print("✗ Missing 'config setup' section") return False if "conn %default" not in config: print("✗ Missing 'conn %default' section") return False if "keyexchange=ikev2" not in config: print("✗ Missing IKEv2 configuration") return False print("✓ StrongSwan config format is valid") return True def test_docker_algo_image(): """Test that the Algo Docker image can be built""" # Check if Dockerfile exists if not os.path.exists("Dockerfile"): print("✗ Dockerfile not found") return False # Read Dockerfile and validate basic structure with open("Dockerfile") as f: dockerfile_content = f.read() required_elements = [ "FROM", # Base image "RUN", # Build commands "COPY", # Copy Algo files "python", # Python dependency ] missing = [] for element in required_elements: if element not in dockerfile_content: missing.append(element) if missing: print(f"✗ Dockerfile missing elements: {', '.join(missing)}") return False print("✓ Dockerfile structure is valid") return True def test_localhost_deployment_requirements(): """Test that localhost deployment requirements are met""" requirements = { "Python 3.8+": sys.version_info >= (3, 8), "Ansible installed": subprocess.run(["which", "ansible"], capture_output=True).returncode == 0, "Main playbook exists": os.path.exists("main.yml"), "Project config exists": os.path.exists("pyproject.toml"), "Config template exists": os.path.exists("config.cfg.example") or os.path.exists("config.cfg"), } all_met = True for req, met in requirements.items(): if met: print(f"✓ {req}") else: print(f"✗ {req}") all_met = False return all_met if __name__ == "__main__": print("Running Docker localhost deployment tests...") print("=" * 50) # First check if Docker is available docker_available = check_docker_available() if not docker_available: print("⚠ Docker not available - some tests will be limited") tests = [ test_wireguard_config_validation, test_strongswan_config_validation, test_docker_algo_image, test_localhost_deployment_requirements, ] failed = 0 for test in tests: print(f"\n{test.__name__}:") try: if not test(): failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 print("\n" + "=" * 50) if failed > 0: print(f"❌ {failed} tests failed") sys.exit(1) else: print(f"✅ All {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_double_templating.py ================================================ """ Test to detect double Jinja2 templating issues in YAML files. This test prevents Ansible 12+ errors from embedded templates in Jinja2 expressions. The pattern `{{ lookup('file', '{{ var }}') }}` is invalid and must be `{{ lookup('file', var) }}` instead. Issue: https://github.com/trailofbits/algo/issues/14835 """ import re from pathlib import Path import pytest def find_yaml_files() -> list[Path]: """Find all YAML files in the repository.""" repo_root = Path(__file__).parent.parent.parent yaml_files = [] # Include all .yml and .yaml files for pattern in ["**/*.yml", "**/*.yaml"]: yaml_files.extend(repo_root.glob(pattern)) # Exclude test files and vendor directories excluded_dirs = {"venv", ".venv", "env", ".git", "__pycache__", ".pytest_cache"} yaml_files = [f for f in yaml_files if not any(excluded in f.parts for excluded in excluded_dirs)] return sorted(yaml_files) def detect_double_templating(content: str) -> list[tuple[int, str]]: """ Detect double templating patterns in file content. Returns list of (line_number, problematic_line) tuples. """ issues = [] # Pattern 1: lookup() with embedded {{ }} # Matches: lookup('file', '{{ var }}') or lookup("file", "{{ var }}") pattern1 = r"lookup\s*\([^)]*['\"]{{[^}]*}}['\"][^)]*\)" # Pattern 2: Direct nested {{ {{ }} }} pattern2 = r"{{\s*[^}]*{{\s*[^}]*}}" # Pattern 3: Embedded templates in quoted strings within Jinja2 # This catches cases like value: "{{ '{{ var }}' }}" pattern3 = r"{{\s*['\"][^'\"]*{{[^}]*}}[^'\"]*['\"]" lines = content.split("\n") for i, line in enumerate(lines, 1): # Skip comments stripped = line.split("#")[0] if not stripped.strip(): continue if re.search(pattern1, stripped) or re.search(pattern2, stripped) or re.search(pattern3, stripped): issues.append((i, line)) return issues def test_no_double_templating(): """Test that no YAML files contain double templating patterns.""" yaml_files = find_yaml_files() all_issues = {} for yaml_file in yaml_files: try: content = yaml_file.read_text() issues = detect_double_templating(content) if issues: # Store relative path for cleaner output rel_path = yaml_file.relative_to(Path(__file__).parent.parent.parent) all_issues[str(rel_path)] = issues except Exception: # Skip binary files or files we can't read continue if all_issues: # Format error message for clarity error_msg = "\n\nDouble templating issues found:\n" error_msg += "=" * 60 + "\n" for file_path, issues in all_issues.items(): error_msg += f"\n{file_path}:\n" for line_num, line in issues: error_msg += f" Line {line_num}: {line.strip()}\n" error_msg += "\n" + "=" * 60 + "\n" error_msg += "Fix: Replace '{{ var }}' with var inside lookup() calls\n" error_msg += "Example: lookup('file', '{{ SSH_keys.public }}') → lookup('file', SSH_keys.public)\n" pytest.fail(error_msg) def test_specific_known_issues(): """ Test for specific known double-templating issues. This ensures our detection catches the actual bugs from issue #14835. """ # These are the actual problematic patterns from the codebase known_bad_patterns = [ "{{ lookup('file', '{{ SSH_keys.public }}') }}", '{{ lookup("file", "{{ credentials_file_path }}") }}', "value: \"{{ lookup('file', '{{ SSH_keys.public }}') }}\"", "PayloadContentCA: \"{{ lookup('file' , '{{ ipsec_pki_path }}/cacert.pem')|b64encode }}\"", ] for pattern in known_bad_patterns: issues = detect_double_templating(pattern) assert issues, f"Failed to detect known bad pattern: {pattern}" def test_valid_patterns_not_flagged(): """ Test that valid templating patterns are not flagged as errors. """ valid_patterns = [ "{{ lookup('file', SSH_keys.public) }}", "{{ lookup('file', credentials_file_path) }}", "value: \"{{ lookup('file', SSH_keys.public) }}\"", "{{ item.1 }}.mobileconfig", "{{ loop.index }}. {{ r.server }} ({{ r.IP_subject_alt_name }})", "PayloadContentCA: \"{{ lookup('file', ipsec_pki_path + '/cacert.pem')|b64encode }}\"", "ssh_pub_key: \"{{ lookup('file', SSH_keys.public) }}\"", ] for pattern in valid_patterns: issues = detect_double_templating(pattern) assert not issues, f"Valid pattern incorrectly flagged: {pattern}" if __name__ == "__main__": # Run the test directly for debugging test_specific_known_issues() test_valid_patterns_not_flagged() test_no_double_templating() print("All tests passed!") ================================================ FILE: tests/unit/test_generated_configs.py ================================================ #!/usr/bin/env python3 """ Test that generated configuration files have valid syntax This validates WireGuard, StrongSwan, SSH, and other configs """ import re import subprocess import sys def check_command_available(cmd): """Check if a command is available on the system""" try: subprocess.run([cmd, "--version"], capture_output=True, check=False) return True except FileNotFoundError: return False def test_wireguard_config_syntax(): """Test WireGuard configuration file syntax""" # Sample WireGuard config based on Algo's template sample_config = """[Interface] Address = 10.19.49.2/32,fd9d:bc11:4020::2/128 PrivateKey = SAMPLE_PRIVATE_KEY_BASE64== DNS = 1.1.1.1,1.0.0.1 [Peer] PublicKey = SAMPLE_PUBLIC_KEY_BASE64== PresharedKey = SAMPLE_PRESHARED_KEY_BASE64== AllowedIPs = 0.0.0.0/0,::/0 Endpoint = 10.0.0.1:51820 PersistentKeepalive = 25 """ # Validate config structure errors = [] # Check for required sections if "[Interface]" not in sample_config: errors.append("Missing [Interface] section") if "[Peer]" not in sample_config: errors.append("Missing [Peer] section") # Validate Interface section interface_match = re.search(r"\[Interface\](.*?)\[Peer\]", sample_config, re.DOTALL) if interface_match: interface_section = interface_match.group(1) # Check required fields if not re.search(r"Address\s*=", interface_section): errors.append("Missing Address in Interface section") if not re.search(r"PrivateKey\s*=", interface_section): errors.append("Missing PrivateKey in Interface section") # Validate IP addresses address_match = re.search(r"Address\s*=\s*([^\n]+)", interface_section) if address_match: addresses = address_match.group(1).split(",") for addr in addresses: addr = addr.strip() # Basic IP validation if not re.match(r"^\d+\.\d+\.\d+\.\d+/\d+$", addr) and not re.match(r"^[0-9a-fA-F:]+/\d+$", addr): errors.append(f"Invalid IP address format: {addr}") # Validate Peer section peer_match = re.search(r"\[Peer\](.*)", sample_config, re.DOTALL) if peer_match: peer_section = peer_match.group(1) # Check required fields if not re.search(r"PublicKey\s*=", peer_section): errors.append("Missing PublicKey in Peer section") if not re.search(r"AllowedIPs\s*=", peer_section): errors.append("Missing AllowedIPs in Peer section") if not re.search(r"Endpoint\s*=", peer_section): errors.append("Missing Endpoint in Peer section") # Validate endpoint format endpoint_match = re.search(r"Endpoint\s*=\s*([^\n]+)", peer_section) if endpoint_match: endpoint = endpoint_match.group(1).strip() if not re.match(r"^[\d\.\:]+:\d+$", endpoint): errors.append(f"Invalid Endpoint format: {endpoint}") if errors: print("✗ WireGuard config validation failed:") for error in errors: print(f" - {error}") assert False, "WireGuard config validation failed" else: print("✓ WireGuard config syntax validation passed") def test_strongswan_ipsec_conf(): """Test StrongSwan ipsec.conf syntax""" # Sample ipsec.conf based on Algo's template sample_config = """config setup charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2, mgr 2" strictcrlpolicy=yes uniqueids=never conn %default keyexchange=ikev2 dpdaction=clear dpddelay=35s dpdtimeout=150s compress=yes ikelifetime=24h lifetime=8h rekey=yes reauth=yes fragmentation=yes ike=aes128gcm16-prfsha512-ecp256,aes128-sha2_256-modp2048 esp=aes128gcm16-ecp256,aes128-sha2_256-modp2048 conn ikev2-pubkey auto=add left=%any leftid=@10.0.0.1 leftcert=server.crt leftsendcert=always leftsubnet=0.0.0.0/0,::/0 right=%any rightid=%any rightauth=pubkey rightsourceip=10.19.49.0/24,fd9d:bc11:4020::/64 rightdns=1.1.1.1,1.0.0.1 """ errors = [] # Check for required sections if "config setup" not in sample_config: errors.append("Missing 'config setup' section") if "conn %default" not in sample_config: errors.append("Missing 'conn %default' section") # Validate connection settings conn_pattern = re.compile(r"conn\s+(\S+)") connections = conn_pattern.findall(sample_config) if len(connections) < 2: # Should have at least %default and one other errors.append("Not enough connection definitions") # Check for required parameters in connections required_params = ["keyexchange", "left", "right"] for param in required_params: if f"{param}=" not in sample_config: errors.append(f"Missing required parameter: {param}") # Validate IP subnet formats subnet_pattern = re.compile(r"(left|right)subnet\s*=\s*([^\n]+)") for match in subnet_pattern.finditer(sample_config): subnets = match.group(2).split(",") for subnet in subnets: subnet = subnet.strip() if subnet != "0.0.0.0/0" and subnet != "::/0": if not re.match(r"^\d+\.\d+\.\d+\.\d+/\d+$", subnet) and not re.match(r"^[0-9a-fA-F:]+/\d+$", subnet): errors.append(f"Invalid subnet format: {subnet}") if errors: print("✗ StrongSwan ipsec.conf validation failed:") for error in errors: print(f" - {error}") assert False, "ipsec.conf validation failed" else: print("✓ StrongSwan ipsec.conf syntax validation passed") def test_ssh_config_syntax(): """Test SSH tunnel configuration syntax""" # Sample SSH config for tunneling sample_config = """Host algo-tunnel HostName 10.0.0.1 User algo Port 4160 IdentityFile ~/.ssh/algo.pem StrictHostKeyChecking no UserKnownHostsFile /dev/null ServerAliveInterval 60 ServerAliveCountMax 3 LocalForward 1080 127.0.0.1:1080 """ errors = [] # Parse SSH config format lines = sample_config.strip().split("\n") current_host = None for line in lines: line = line.strip() if not line or line.startswith("#"): continue if line.startswith("Host "): current_host = line.split()[1] elif current_host and " " in line: key, value = line.split(None, 1) # Validate common SSH options if key == "Port": try: port = int(value) if not 1 <= port <= 65535: errors.append(f"Invalid port number: {port}") except ValueError: errors.append(f"Port must be a number: {value}") elif key == "LocalForward": # Format: LocalForward [bind_address:]port host:hostport parts = value.split() if len(parts) != 2: errors.append(f"Invalid LocalForward format: {value}") if not current_host: errors.append("No Host definition found") if errors: print("✗ SSH config validation failed:") for error in errors: print(f" - {error}") assert False, "SSH config validation failed" else: print("✓ SSH config syntax validation passed") def test_iptables_rules_syntax(): """Test iptables rules syntax""" # Sample iptables rules based on Algo's rules.v4.j2 sample_rules = """*nat :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 10.19.49.0/24 ! -d 10.19.49.0/24 -j MASQUERADE COMMIT *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p icmp --icmp-type echo-request -j ACCEPT -A INPUT -p tcp --dport 4160 -j ACCEPT -A INPUT -p udp --dport 51820 -j ACCEPT -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A FORWARD -s 10.19.49.0/24 -j ACCEPT COMMIT """ errors = [] # Check table definitions tables = re.findall(r"\*(\w+)", sample_rules) if "filter" not in tables: errors.append("Missing *filter table") if "nat" not in tables: errors.append("Missing *nat table") # Check for COMMIT statements commit_count = sample_rules.count("COMMIT") if commit_count != len(tables): errors.append(f"Number of COMMIT statements ({commit_count}) doesn't match tables ({len(tables)})") # Validate chain policies chain_pattern = re.compile(r"^:(\w+)\s+(ACCEPT|DROP|REJECT)\s+\[\d+:\d+\]", re.MULTILINE) chains = chain_pattern.findall(sample_rules) required_chains = [("INPUT", "DROP"), ("FORWARD", "DROP"), ("OUTPUT", "ACCEPT")] for chain, _policy in required_chains: if not any(c[0] == chain for c in chains): errors.append(f"Missing required chain: {chain}") # Validate rule syntax rule_pattern = re.compile(r"^-[AI]\s+(\w+)", re.MULTILINE) rules = rule_pattern.findall(sample_rules) if len(rules) < 5: errors.append("Insufficient firewall rules") # Check for essential security rules if "-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT" not in sample_rules: errors.append("Missing stateful connection tracking rule") if errors: print("✗ iptables rules validation failed:") for error in errors: print(f" - {error}") assert False, "iptables rules validation failed" else: print("✓ iptables rules syntax validation passed") def test_dns_config_syntax(): """Test dnsmasq configuration syntax""" # Sample dnsmasq config sample_config = """user=nobody group=nogroup interface=eth0 interface=wg0 bind-interfaces bogus-priv no-resolv no-poll server=1.1.1.1 server=1.0.0.1 local-ttl=300 cache-size=10000 log-queries log-facility=/var/log/dnsmasq.log conf-dir=/etc/dnsmasq.d/,*.conf addn-hosts=/var/lib/algo/dns/adblock.hosts """ errors = [] # Parse config for line in sample_config.strip().split("\n"): line = line.strip() if not line or line.startswith("#"): continue # Most dnsmasq options are key=value or just key if "=" in line: key, value = line.split("=", 1) # Validate specific options if key == "interface": if not re.match(r"^[a-zA-Z0-9\-_]+$", value): errors.append(f"Invalid interface name: {value}") elif key == "server": # Basic IP validation if not re.match(r"^\d+\.\d+\.\d+\.\d+$", value) and not re.match(r"^[0-9a-fA-F:]+$", value): errors.append(f"Invalid DNS server IP: {value}") elif key == "cache-size": try: size = int(value) if size < 0: errors.append(f"Invalid cache size: {size}") except ValueError: errors.append(f"Cache size must be a number: {value}") # Check for required options required = ["interface", "server"] for req in required: if f"{req}=" not in sample_config: errors.append(f"Missing required option: {req}") if errors: print("✗ dnsmasq config validation failed:") for error in errors: print(f" - {error}") assert False, "dnsmasq config validation failed" else: print("✓ dnsmasq config syntax validation passed") if __name__ == "__main__": tests = [ test_wireguard_config_syntax, test_strongswan_ipsec_conf, test_ssh_config_syntax, test_iptables_rules_syntax, test_dns_config_syntax, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} config syntax tests passed!") ================================================ FILE: tests/unit/test_iptables_rules.py ================================================ #!/usr/bin/env python3 """ Test iptables rules logic for VPN traffic routing. These tests verify that the iptables rules templates generate correct NAT rules for both WireGuard and IPsec VPN traffic. """ from pathlib import Path import pytest from jinja2 import Environment, FileSystemLoader def _ansible_bool(value): """Simulate the Ansible bool filter for test purposes.""" if isinstance(value, bool): return value if isinstance(value, str): return value.lower() not in ("false", "no", "0", "") return bool(value) def load_template(template_name): """Load a Jinja2 template from the roles/common/templates directory.""" template_dir = Path(__file__).parent.parent.parent / "roles" / "common" / "templates" env = Environment(loader=FileSystemLoader(str(template_dir))) env.filters["bool"] = _ansible_bool return env.get_template(template_name) def test_wireguard_nat_rules_ipv4(): """Test that WireGuard traffic gets proper NAT rules without policy matching.""" template = load_template("rules.v4.j2") # Test with WireGuard enabled result = template.render( ipsec_enabled=False, wireguard_enabled=True, wireguard_network_ipv4="10.49.0.0/16", wireguard_port=51820, wireguard_port_avoid=53, wireguard_port_actual=51820, ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.49.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # Verify NAT rule exists with output interface and without policy matching assert "-A POSTROUTING -s 10.49.0.0/16 -o eth0 -j MASQUERADE" in result # Verify no policy matching in WireGuard NAT rules assert "-A POSTROUTING -s 10.49.0.0/16 -m policy" not in result def test_ipsec_nat_rules_ipv4(): """Test that IPsec traffic gets proper NAT rules without policy matching.""" template = load_template("rules.v4.j2") # Test with IPsec enabled result = template.render( ipsec_enabled=True, wireguard_enabled=False, strongswan_network="10.48.0.0/16", strongswan_network_ipv6="2001:db8::/48", ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.48.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # Verify NAT rule exists with output interface and without policy matching assert "-A POSTROUTING -s 10.48.0.0/16 -o eth0 -j MASQUERADE" in result # Verify no policy matching in IPsec NAT rules (this was the bug) assert "-A POSTROUTING -s 10.48.0.0/16 -m policy --pol none" not in result def test_both_vpns_nat_rules_ipv4(): """Test NAT rules when both VPN types are enabled.""" template = load_template("rules.v4.j2") result = template.render( ipsec_enabled=True, wireguard_enabled=True, strongswan_network="10.48.0.0/16", wireguard_network_ipv4="10.49.0.0/16", strongswan_network_ipv6="2001:db8::/48", wireguard_network_ipv6="2001:db8:a160::/48", wireguard_port=51820, wireguard_port_avoid=53, wireguard_port_actual=51820, ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.49.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # Both should have NAT rules with output interface assert "-A POSTROUTING -s 10.48.0.0/16 -o eth0 -j MASQUERADE" in result assert "-A POSTROUTING -s 10.49.0.0/16 -o eth0 -j MASQUERADE" in result # Neither should have policy matching assert "-m policy --pol none" not in result def test_alternative_ingress_snat(): """Test that alternative ingress IP uses SNAT instead of MASQUERADE.""" template = load_template("rules.v4.j2") result = template.render( ipsec_enabled=True, wireguard_enabled=True, strongswan_network="10.48.0.0/16", wireguard_network_ipv4="10.49.0.0/16", strongswan_network_ipv6="2001:db8::/48", wireguard_network_ipv6="2001:db8:a160::/48", wireguard_port=51820, wireguard_port_avoid=53, wireguard_port_actual=51820, ansible_default_ipv4={"interface": "eth0"}, snat_aipv4="192.168.1.100", # Alternative ingress IP BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.49.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # Should use SNAT with specific IP and output interface instead of MASQUERADE assert "-A POSTROUTING -s 10.48.0.0/16 -o eth0 -j SNAT --to 192.168.1.100" in result assert "-A POSTROUTING -s 10.49.0.0/16 -o eth0 -j SNAT --to 192.168.1.100" in result assert "MASQUERADE" not in result def test_ipsec_forward_rule_has_policy_match(): """Test that IPsec FORWARD rules still use policy matching (this is correct).""" template = load_template("rules.v4.j2") result = template.render( ipsec_enabled=True, wireguard_enabled=False, strongswan_network="10.48.0.0/16", strongswan_network_ipv6="2001:db8::/48", ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.48.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # FORWARD rule should have policy match (this is correct and should stay) assert "-A FORWARD -m conntrack --ctstate NEW -s 10.48.0.0/16 -m policy --pol ipsec --dir in -j ACCEPT" in result def test_wireguard_forward_rule_no_policy_match(): """Test that WireGuard FORWARD rules don't use policy matching.""" template = load_template("rules.v4.j2") result = template.render( ipsec_enabled=False, wireguard_enabled=True, wireguard_network_ipv4="10.49.0.0/16", wireguard_port=51820, wireguard_port_avoid=53, wireguard_port_actual=51820, ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="10.49.0.1", ansible_ssh_port=22, reduce_mtu=0, ) # WireGuard FORWARD rule should NOT have any policy match assert "-A FORWARD -m conntrack --ctstate NEW -s 10.49.0.0/16 -j ACCEPT" in result assert "-A FORWARD -m conntrack --ctstate NEW -s 10.49.0.0/16 -m policy" not in result def test_output_interface_in_nat_rules(): """Test that output interface is specified in NAT rules.""" template = load_template("rules.v4.j2") result = template.render( snat_aipv4=False, wireguard_enabled=True, ipsec_enabled=True, wireguard_network_ipv4="10.49.0.0/16", strongswan_network="10.48.0.0/16", ansible_default_ipv4={"interface": "eth0", "address": "10.0.0.1"}, ansible_default_ipv6={"interface": "eth0", "address": "fd9d:bc11:4020::1"}, wireguard_port_actual=51820, wireguard_port_avoid=53, wireguard_port=51820, ansible_ssh_port=22, reduce_mtu=0, ) # Check that output interface is specified for both VPNs assert "-A POSTROUTING -s 10.49.0.0/16 -o eth0 -j MASQUERADE" in result assert "-A POSTROUTING -s 10.48.0.0/16 -o eth0 -j MASQUERADE" in result # Ensure we don't have rules without output interface assert "-A POSTROUTING -s 10.49.0.0/16 -j MASQUERADE" not in result assert "-A POSTROUTING -s 10.48.0.0/16 -j MASQUERADE" not in result def test_dns_firewall_restricted_to_vpn(): """Test that DNS access is restricted to VPN clients only.""" template = load_template("rules.v4.j2") result = template.render( ipsec_enabled=True, wireguard_enabled=True, strongswan_network="10.48.0.0/16", wireguard_network_ipv4="10.49.0.0/16", strongswan_network_ipv6="2001:db8::/48", wireguard_network_ipv6="2001:db8:a160::/48", wireguard_port=51820, wireguard_port_avoid=53, wireguard_port_actual=51820, ansible_default_ipv4={"interface": "eth0"}, snat_aipv4=None, BetweenClients_DROP=True, block_smb=True, block_netbios=True, local_service_ip="172.23.198.242", ansible_ssh_port=22, reduce_mtu=0, ) # DNS should only be accessible from VPN subnets assert "-A INPUT -s 10.48.0.0/16,10.49.0.0/16 -d 172.23.198.242 -p udp --dport 53 -j ACCEPT" in result # Should NOT have unrestricted DNS access assert "-A INPUT -d 172.23.198.242 -p udp --dport 53 -j ACCEPT" not in result if __name__ == "__main__": pytest.main([__file__, "-v"]) ================================================ FILE: tests/unit/test_lightsail_boto3_fix.py ================================================ #!/usr/bin/env python """ Test for AWS Lightsail boto3 parameter fix. Verifies that get_aws_connection_info() works without the deprecated boto3 parameter. Addresses issue #14822. """ import importlib.util import os import sys import unittest from unittest.mock import MagicMock, patch # Add the library directory to the path sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../library")) class TestLightsailBoto3Fix(unittest.TestCase): """Test that lightsail_region_facts.py works without boto3 parameter.""" def setUp(self): """Set up test fixtures.""" # Mock the ansible module_utils since we're testing outside of Ansible self.mock_modules = { "ansible.module_utils.basic": MagicMock(), "ansible.module_utils.ec2": MagicMock(), "ansible.module_utils.aws.core": MagicMock(), } # Apply mocks self.patches = [] for module_name, mock_module in self.mock_modules.items(): patcher = patch.dict("sys.modules", {module_name: mock_module}) patcher.start() self.patches.append(patcher) def tearDown(self): """Clean up patches.""" for patcher in self.patches: patcher.stop() def test_lightsail_region_facts_imports(self): """Test that lightsail_region_facts can be imported.""" try: # Import the module spec = importlib.util.spec_from_file_location( "lightsail_region_facts", os.path.join(os.path.dirname(__file__), "../../library/lightsail_region_facts.py"), ) assert spec is not None, "Failed to create module spec" assert spec.loader is not None, "Module spec has no loader" module = importlib.util.module_from_spec(spec) # This should not raise an error spec.loader.exec_module(module) # Verify the module loaded self.assertIsNotNone(module) self.assertTrue(hasattr(module, "main")) except Exception as e: self.fail(f"Failed to import lightsail_region_facts: {e}") def test_get_aws_connection_info_called_without_boto3(self): """Test that get_aws_connection_info is called without boto3 parameter.""" # Mock get_aws_connection_info to track calls mock_get_aws_connection_info = MagicMock(return_value=("us-west-2", None, {})) with patch("ansible.module_utils.ec2.get_aws_connection_info", mock_get_aws_connection_info): # Import the module spec = importlib.util.spec_from_file_location( "lightsail_region_facts", os.path.join(os.path.dirname(__file__), "../../library/lightsail_region_facts.py"), ) assert spec is not None, "Failed to create module spec" assert spec.loader is not None, "Module spec has no loader" module = importlib.util.module_from_spec(spec) # Mock AnsibleModule mock_ansible_module = MagicMock() mock_ansible_module.params = {} mock_ansible_module.check_mode = False with patch("ansible.module_utils.basic.AnsibleModule", return_value=mock_ansible_module): # Execute the module try: spec.loader.exec_module(module) module.main() except SystemExit: # Module calls exit_json or fail_json which raises SystemExit pass except Exception: # We expect some exceptions since we're mocking, but we want to check the call pass # Verify get_aws_connection_info was called if mock_get_aws_connection_info.called: # Get the call arguments call_args = mock_get_aws_connection_info.call_args # Ensure boto3=True is NOT in the arguments if call_args: # Check positional arguments if call_args[0]: # args self.assertTrue( len(call_args[0]) <= 1, "get_aws_connection_info should be called with at most 1 positional arg (module)", ) # Check keyword arguments if call_args[1]: # kwargs self.assertNotIn( "boto3", call_args[1], "get_aws_connection_info should not be called with boto3 parameter" ) def test_no_boto3_parameter_in_source(self): """Verify that boto3 parameter is not present in the source code.""" lightsail_path = os.path.join(os.path.dirname(__file__), "../../library/lightsail_region_facts.py") with open(lightsail_path) as f: content = f.read() # Check that boto3=True is not in the file self.assertNotIn( "boto3=True", content, "boto3=True parameter should not be present in lightsail_region_facts.py" ) # Check that boto3 parameter is not used with get_aws_connection_info self.assertNotIn( "get_aws_connection_info(module, boto3", content, "get_aws_connection_info should not be called with boto3 parameter", ) def test_regression_issue_14822(self): """ Regression test for issue #14822. Ensures that the deprecated boto3 parameter is not used. """ # This test documents the specific issue that was fixed # The boto3 parameter was deprecated and removed in amazon.aws collection # that comes with Ansible 11.x lightsail_path = os.path.join(os.path.dirname(__file__), "../../library/lightsail_region_facts.py") with open(lightsail_path) as f: lines = f.readlines() # Find the line that calls get_aws_connection_info for line_num, line in enumerate(lines, 1): if "get_aws_connection_info" in line and "region" in line: # This should be around line 85 # Verify it doesn't have boto3=True self.assertNotIn("boto3", line, f"Line {line_num} should not contain boto3 parameter") # Verify the correct format self.assertIn( "get_aws_connection_info(module)", line, f"Line {line_num} should call get_aws_connection_info(module) without boto3", ) break else: self.fail("Could not find get_aws_connection_info call in lightsail_region_facts.py") if __name__ == "__main__": unittest.main() ================================================ FILE: tests/unit/test_list_servers.py ================================================ """Tests for scripts/list_servers.py.""" import importlib.util import json import subprocess import sys from pathlib import Path import pytest # Load list_servers module from scripts/ (not a Python package) _script = Path(__file__).resolve().parents[2] / "scripts" / "list_servers.py" _spec = importlib.util.spec_from_file_location("list_servers", str(_script)) _mod = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(_mod) list_servers = _mod.list_servers @pytest.fixture() def configs_dir(tmp_path): """Create a temporary configs directory with sample configs.""" server1 = tmp_path / "10.0.0.1" server1.mkdir() (server1 / ".config.yml").write_text("server: 10.0.0.1\nalgo_provider: digitalocean\nalgo_server_name: algo\n") server2 = tmp_path / "10.0.0.2" server2.mkdir() (server2 / ".config.yml").write_text("server: 10.0.0.2\nalgo_provider: ec2\nalgo_server_name: prod\n") return tmp_path def test_empty_directory(tmp_path): """Empty configs directory returns empty list.""" assert list_servers(tmp_path) == [] def test_missing_directory(tmp_path): """Non-existent path returns empty list via glob.""" assert list_servers(tmp_path / "nonexistent") == [] def test_lists_servers(configs_dir): """Parses .config.yml files and returns server metadata.""" servers = list_servers(configs_dir) assert len(servers) == 2 names = {s["algo_server_name"] for s in servers} assert names == {"algo", "prod"} def test_sorted_output(configs_dir): """Servers are returned in sorted directory order.""" servers = list_servers(configs_dir) ips = [s["server"] for s in servers] assert ips == ["10.0.0.1", "10.0.0.2"] def test_skips_empty_yaml(tmp_path): """Empty YAML files (parsing to None) are skipped.""" server = tmp_path / "10.0.0.5" server.mkdir() (server / ".config.yml").write_text("") assert list_servers(tmp_path) == [] def test_cli_output(tmp_path): """CLI outputs valid JSON to stdout.""" server = tmp_path / "10.0.0.1" server.mkdir() (server / ".config.yml").write_text("server: 10.0.0.1\nalgo_server_name: test\n") result = subprocess.run( [sys.executable, "scripts/list_servers.py", str(tmp_path)], capture_output=True, text=True, check=True, ) data = json.loads(result.stdout) assert len(data) == 1 assert data[0]["server"] == "10.0.0.1" def test_cli_missing_dir(): """CLI outputs empty JSON array for missing directory.""" result = subprocess.run( [ sys.executable, "scripts/list_servers.py", "/nonexistent/path", ], capture_output=True, text=True, check=True, ) assert json.loads(result.stdout) == [] ================================================ FILE: tests/unit/test_openssl_compatibility.py ================================================ #!/usr/bin/env python3 """ Test PKI certificate validation for Ansible-generated certificates Hybrid approach: validates actual certificates when available, else tests templates/config Based on issues #14755, #14718 - Apple device compatibility Issues #75, #153 - Security enhancements (name constraints, EKU restrictions) """ import glob import os import re import subprocess import sys from datetime import UTC from cryptography import x509 from cryptography.x509.oid import ExtensionOID, NameOID def find_generated_certificates(): """Find Ansible-generated certificate files in configs directory""" # Look for configs directory structure created by Ansible config_patterns = [ "configs/*/ipsec/.pki/cacert.pem", "../configs/*/ipsec/.pki/cacert.pem", # From tests/unit directory "../../configs/*/ipsec/.pki/cacert.pem", # Alternative path ] for pattern in config_patterns: ca_certs = glob.glob(pattern) if ca_certs: base_path = os.path.dirname(ca_certs[0]) return { "ca_cert": ca_certs[0], "base_path": base_path, "server_certs": glob.glob(f"{base_path}/certs/*.crt"), "p12_files": glob.glob(f"{base_path.replace('/.pki', '')}/manual/*.p12"), } return None def test_openssl_version_detection(): """Test that we can detect OpenSSL version for compatibility checks""" result = subprocess.run(["openssl", "version"], capture_output=True, text=True) assert result.returncode == 0, "Failed to get OpenSSL version" # Parse version - e.g., "OpenSSL 3.0.2 15 Mar 2022" version_match = re.search(r"OpenSSL\s+(\d+)\.(\d+)\.(\d+)", result.stdout) assert version_match, f"Can't parse OpenSSL version: {result.stdout}" major = int(version_match.group(1)) minor = int(version_match.group(2)) print(f"✓ OpenSSL version detected: {major}.{minor}") return (major, minor) def validate_ca_certificate_real(cert_files): """Validate actual Ansible-generated CA certificate""" # Read the actual CA certificate generated by Ansible with open(cert_files["ca_cert"], "rb") as f: cert_data = f.read() certificate = x509.load_pem_x509_certificate(cert_data) # Check Basic Constraints basic_constraints = certificate.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS).value assert basic_constraints.ca is True, "CA certificate should have CA:TRUE" assert basic_constraints.path_length == 0, "CA should have pathlen:0 constraint" # Check Key Usage key_usage = certificate.extensions.get_extension_for_oid(ExtensionOID.KEY_USAGE).value assert key_usage.key_cert_sign is True, "CA should have keyCertSign usage" assert key_usage.crl_sign is True, "CA should have cRLSign usage" # Check Extended Key Usage (Issue #75) eku = certificate.extensions.get_extension_for_oid(ExtensionOID.EXTENDED_KEY_USAGE).value assert x509.oid.ExtendedKeyUsageOID.SERVER_AUTH in eku, "CA should allow signing server certificates" assert x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH in eku, "CA should allow signing client certificates" assert x509.ObjectIdentifier("1.3.6.1.5.5.7.3.17") in eku, "CA should have IPsec End Entity EKU" # Check Name Constraints (Issue #75) - defense against certificate misuse name_constraints = certificate.extensions.get_extension_for_oid(ExtensionOID.NAME_CONSTRAINTS).value assert name_constraints.permitted_subtrees is not None, "CA should have permitted name constraints" assert name_constraints.excluded_subtrees is not None, "CA should have excluded name constraints" # Verify public domains are excluded excluded_dns = [ constraint.value for constraint in name_constraints.excluded_subtrees if isinstance(constraint, x509.DNSName) ] public_domains = [".com", ".org", ".net", ".gov", ".edu", ".mil", ".int"] for domain in public_domains: assert domain in excluded_dns, f"CA should exclude public domain {domain}" # Verify private IP ranges are excluded (Issue #75) excluded_ips = [ constraint.value for constraint in name_constraints.excluded_subtrees if isinstance(constraint, x509.IPAddress) ] assert len(excluded_ips) > 0, "CA should exclude private IP ranges" # Verify email domains are also excluded (Issue #153) excluded_emails = [ constraint.value for constraint in name_constraints.excluded_subtrees if isinstance(constraint, x509.RFC822Name) ] email_domains = [".com", ".org", ".net", ".gov", ".edu", ".mil", ".int"] for domain in email_domains: assert domain in excluded_emails, f"CA should exclude email domain {domain}" print(f"✓ Real CA certificate has proper security constraints: {cert_files['ca_cert']}") def validate_ca_certificate_config(): """Validate CA certificate configuration in Ansible files (CI mode)""" # Check that the Ansible task file has proper CA certificate configuration openssl_task_file = find_ansible_file("roles/strongswan/tasks/openssl.yml") if not openssl_task_file: print("⚠ Could not find openssl.yml task file") return with open(openssl_task_file) as f: content = f.read() # Verify key security configurations are present security_checks = [ ("name_constraints_permitted", "Name constraints should be configured"), ("name_constraints_excluded", "Excluded name constraints should be configured"), ("extended_key_usage", "Extended Key Usage should be configured"), ("1.3.6.1.5.5.7.3.17", "IPsec End Entity OID should be present"), ("serverAuth", "Server authentication EKU should be present"), ("clientAuth", "Client authentication EKU should be present"), ("basic_constraints", "Basic constraints should be configured"), ("CA:TRUE", "CA certificate should be marked as CA"), ("pathlen:0", "Path length constraint should be set"), ] for check, message in security_checks: assert check in content, f"Missing security configuration: {message}" # Verify public domains are excluded public_domains = [".com", ".org", ".net", ".gov", ".edu", ".mil", ".int"] for domain in public_domains: # Handle both double quotes and single quotes in YAML assert f'"DNS:{domain}"' in content or f"'DNS:{domain}'" in content, ( f"Public domain {domain} should be excluded" ) # Verify private IP ranges are excluded private_ranges = ["10.0.0.0", "172.16.0.0", "192.168.0.0"] for ip_range in private_ranges: assert ip_range in content, f"Private IP range {ip_range} should be excluded" # Verify email domains are excluded (Issue #153) email_domains = [".com", ".org", ".net", ".gov", ".edu", ".mil", ".int"] for domain in email_domains: # Handle both double quotes and single quotes in YAML assert f'"email:{domain}"' in content or f"'email:{domain}'" in content, ( f"Email domain {domain} should be excluded" ) # Verify IPv6 constraints are present (Issue #153) assert "IP:::/0" in content, "IPv6 all addresses should be excluded" print("✓ CA certificate configuration has proper security constraints") def test_ca_certificate(): """Test CA certificate - uses real certs if available, else validates config (Issue #75, #153)""" cert_files = find_generated_certificates() if cert_files: validate_ca_certificate_real(cert_files) else: validate_ca_certificate_config() def validate_server_certificates_real(cert_files): """Validate actual Ansible-generated server certificates""" # Filter to only actual server certificates (not client certs) # Server certificates contain IP addresses in the filename import re server_certs = [ f for f in cert_files["server_certs"] if not f.endswith("/cacert.pem") and re.search(r"\d+\.\d+\.\d+\.\d+\.crt$", f) ] if not server_certs: print("⚠ No server certificates found") return for server_cert_path in server_certs: with open(server_cert_path, "rb") as f: cert_data = f.read() certificate = x509.load_pem_x509_certificate(cert_data) # Check it's not a CA certificate basic_constraints = certificate.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS).value assert basic_constraints.ca is False, "Server certificate should not be a CA" # Check Extended Key Usage (Issue #75) eku = certificate.extensions.get_extension_for_oid(ExtensionOID.EXTENDED_KEY_USAGE).value assert x509.oid.ExtendedKeyUsageOID.SERVER_AUTH in eku, "Server cert must have serverAuth EKU" assert x509.ObjectIdentifier("1.3.6.1.5.5.7.3.17") in eku, "Server cert should have IPsec End Entity EKU" # Security check: Server certificates should NOT have clientAuth to prevent role confusion (Issue #153) assert x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH not in eku, ( "Server cert should NOT have clientAuth EKU for role separation" ) # Check SAN extension exists (required for Apple devices) try: san = certificate.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME).value assert len(san) > 0, "Server certificate must have SAN extension for Apple device compatibility" except x509.ExtensionNotFound: assert False, "Server certificate missing SAN extension - required for modern clients" print(f"✓ Real server certificate valid: {os.path.basename(server_cert_path)}") def validate_server_certificates_config(): """Validate server certificate configuration in Ansible files (CI mode)""" openssl_task_file = find_ansible_file("roles/strongswan/tasks/openssl.yml") if not openssl_task_file: print("⚠ Could not find openssl.yml task file") return with open(openssl_task_file) as f: content = f.read() # Look for server certificate CSR section server_csr_section = re.search(r"Create CSRs for server certificate.*?register: server_csr", content, re.DOTALL) if not server_csr_section: print("⚠ Could not find server certificate CSR section") return server_section = server_csr_section.group(0) # Check server certificate CSR configuration server_checks = [ ("subject_alt_name", "Server certificates should have SAN extension"), ("serverAuth", "Server certificates should have serverAuth EKU"), ("1.3.6.1.5.5.7.3.17", "Server certificates should have IPsec End Entity EKU"), ("digitalSignature", "Server certificates should have digital signature usage"), ("keyEncipherment", "Server certificates should have key encipherment usage"), ] for check, message in server_checks: assert check in server_section, f"Missing server certificate configuration: {message}" # Security check: Server certificates should NOT have clientAuth (Issue #153) # Look for clientAuth in extended_key_usage section, not in comments eku_lines = [ line for line in server_section.split("\n") if "extended_key_usage:" in line or (line.strip().startswith("- ") and "clientAuth" in line) ] has_client_auth = any("clientAuth" in line for line in eku_lines if line.strip().startswith("- ")) assert not has_client_auth, "Server certificates should NOT have clientAuth EKU for role separation" # Verify SAN extension is configured for Apple compatibility assert "subjectAltName" in server_section, "Server certificates missing SAN configuration for Apple compatibility" print("✓ Server certificate configuration has proper EKU and SAN settings") def test_server_certificates(): """Test server certificates - uses real certs if available, else validates config""" cert_files = find_generated_certificates() if cert_files: validate_server_certificates_real(cert_files) else: validate_server_certificates_config() def validate_client_certificates_real(cert_files): """Validate actual Ansible-generated client certificates""" # Find client certificates (not CA cert, not server cert with IP/DNS name) client_certs = [] for cert_path in cert_files["server_certs"]: if "cacert.pem" in cert_path: continue with open(cert_path, "rb") as f: cert_data = f.read() certificate = x509.load_pem_x509_certificate(cert_data) # Check if this looks like a client cert vs server cert cn = certificate.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value # Server certs typically have IP addresses or domain names as CN if not (cn.replace(".", "").isdigit() or ("." in cn and len(cn.split(".")) == 4)): client_certs.append((cert_path, certificate)) if not client_certs: print("⚠ No client certificates found") return for cert_path, certificate in client_certs: # Check it's not a CA certificate basic_constraints = certificate.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS).value assert basic_constraints.ca is False, "Client certificate should not be a CA" # Check Extended Key Usage restrictions (Issue #75) eku = certificate.extensions.get_extension_for_oid(ExtensionOID.EXTENDED_KEY_USAGE).value assert x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH in eku, "Client cert must have clientAuth EKU" assert x509.ObjectIdentifier("1.3.6.1.5.5.7.3.17") in eku, "Client cert should have IPsec End Entity EKU" # Security check: Client certificates should NOT have serverAuth (prevents impersonation) (Issue #153) assert x509.oid.ExtendedKeyUsageOID.SERVER_AUTH not in eku, ( "Client cert must NOT have serverAuth EKU to prevent server impersonation" ) # Check SAN extension for email try: san = certificate.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME).value email_sans = [name.value for name in san if isinstance(name, x509.RFC822Name)] assert len(email_sans) > 0, "Client certificate should have email SAN" except x509.ExtensionNotFound: print(f"⚠ Client certificate missing SAN extension: {os.path.basename(cert_path)}") print(f"✓ Real client certificate valid: {os.path.basename(cert_path)}") def validate_client_certificates_config(): """Validate client certificate configuration in Ansible files (CI mode)""" openssl_task_file = find_ansible_file("roles/strongswan/tasks/openssl.yml") if not openssl_task_file: print("⚠ Could not find openssl.yml task file") return with open(openssl_task_file) as f: content = f.read() # Look for client certificate CSR section client_csr_section = re.search( r"Create CSRs for client certificates.*?register: client_csr_jobs", content, re.DOTALL ) if not client_csr_section: print("⚠ Could not find client certificate CSR section") return client_section = client_csr_section.group(0) # Check client certificate configuration client_checks = [ ("clientAuth", "Client certificates should have clientAuth EKU"), ("1.3.6.1.5.5.7.3.17", "Client certificates should have IPsec End Entity EKU"), ("digitalSignature", "Client certificates should have digital signature usage"), ("keyEncipherment", "Client certificates should have key encipherment usage"), ("email:", "Client certificates should have email SAN"), ] for check, message in client_checks: assert check in client_section, f"Missing client certificate configuration: {message}" # Security check: Client certificates should NOT have serverAuth (Issue #153) # Look for serverAuth in extended_key_usage section, not in comments eku_lines = [ line for line in client_section.split("\n") if "extended_key_usage:" in line or (line.strip().startswith("- ") and "serverAuth" in line) ] has_server_auth = any("serverAuth" in line for line in eku_lines if line.strip().startswith("- ")) assert not has_server_auth, "Client certificates must NOT have serverAuth EKU to prevent server impersonation" # Verify client certificates use unique email domains (Issue #153) assert "openssl_constraint_random_id" in client_section, ( "Client certificates should use unique email domain per deployment" ) print("✓ Client certificate configuration has proper EKU restrictions (no serverAuth)") def test_client_certificates(): """Test client certificates - uses real certs if available, else validates config (Issue #75, #153)""" cert_files = find_generated_certificates() if cert_files: validate_client_certificates_real(cert_files) else: validate_client_certificates_config() def validate_pkcs12_files_real(cert_files): """Validate actual Ansible-generated PKCS#12 files""" if not cert_files.get("p12_files"): print("⚠ No PKCS#12 files found") return major, _minor = test_openssl_version_detection() for p12_file in cert_files["p12_files"]: assert os.path.exists(p12_file), f"PKCS#12 file should exist: {p12_file}" # Test that PKCS#12 file can be read (validates format) legacy_flag = ["-legacy"] if major >= 3 else [] result = subprocess.run( [ "openssl", "pkcs12", "-info", "-in", p12_file, "-passin", "pass:", # Try empty password first "-noout", ] + legacy_flag, capture_output=True, text=True, ) # PKCS#12 files should be readable (even if password-protected) # We're just testing format validity, not trying to extract contents if result.returncode != 0: # Try with common password patterns if empty password fails print(f"⚠ PKCS#12 file may require password: {os.path.basename(p12_file)}") print(f"✓ Real PKCS#12 file exists: {os.path.basename(p12_file)}") def validate_pkcs12_files_config(): """Validate PKCS#12 file configuration in Ansible files (CI mode)""" openssl_task_file = find_ansible_file("roles/strongswan/tasks/openssl.yml") if not openssl_task_file: print("⚠ Could not find openssl.yml task file") return with open(openssl_task_file) as f: content = f.read() # Check PKCS#12 generation configuration p12_checks = [ ("openssl_pkcs12", "PKCS#12 generation should be configured"), ("encryption_level", "PKCS#12 encryption level should be configured"), ("compatibility2022", "PKCS#12 should use Apple-compatible encryption"), ("friendly_name", "PKCS#12 should have friendly names"), ("other_certificates", "PKCS#12 should include CA certificate for full chain"), ("passphrase", "PKCS#12 files should be password protected"), ('mode: "0600"', "PKCS#12 files should have secure permissions"), ] for check, message in p12_checks: assert check in content, f"Missing PKCS#12 configuration: {message}" print("✓ PKCS#12 configuration has proper Apple device compatibility settings") def test_pkcs12_files(): """Test PKCS#12 files - uses real files if available, else validates config (Issue #14755, #14718)""" cert_files = find_generated_certificates() if cert_files: validate_pkcs12_files_real(cert_files) else: validate_pkcs12_files_config() def validate_certificate_chain_real(cert_files): """Validate actual Ansible-generated certificate chain""" # Load CA certificate with open(cert_files["ca_cert"], "rb") as f: ca_cert_data = f.read() ca_certificate = x509.load_pem_x509_certificate(ca_cert_data) # Test that all other certificates are signed by the CA other_certs = [f for f in cert_files["server_certs"] if f != cert_files["ca_cert"]] if not other_certs: print("⚠ No client/server certificates found to validate") return for cert_path in other_certs: with open(cert_path, "rb") as f: cert_data = f.read() certificate = x509.load_pem_x509_certificate(cert_data) # Verify the certificate was signed by our CA assert certificate.issuer == ca_certificate.subject, f"Certificate {cert_path} not signed by CA" # Verify certificate is currently valid (not expired) from datetime import datetime now = datetime.now(UTC) assert certificate.not_valid_before_utc <= now, f"Certificate {cert_path} not yet valid" assert certificate.not_valid_after_utc >= now, f"Certificate {cert_path} has expired" print(f"✓ Real certificate chain valid: {os.path.basename(cert_path)}") print("✓ All real certificates properly signed by CA") def validate_certificate_chain_config(): """Validate certificate chain configuration in Ansible files (CI mode)""" openssl_task_file = find_ansible_file("roles/strongswan/tasks/openssl.yml") if not openssl_task_file: print("⚠ Could not find openssl.yml task file") return with open(openssl_task_file) as f: content = f.read() # Check certificate signing configuration chain_checks = [ ("provider: ownca", "Certificates should be signed by own CA"), ("ownca_path", "CA certificate path should be specified"), ("ownca_privatekey_path", "CA private key path should be specified"), ("ownca_privatekey_passphrase", "CA private key should be password protected"), ("certificate_validity_days: 3650", "Certificate validity should be configurable (default 10 years)"), ( 'ownca_not_after: "+{{ certificate_validity_days }}d"', "Certificates should use configurable validity period", ), ('ownca_not_before: "-1d"', "Certificates should have backdated start time"), ("curve: secp384r1", "Should use strong elliptic curve cryptography"), ("type: ECC", "Should use elliptic curve keys for better security"), ] for check, message in chain_checks: assert check in content, f"Missing certificate chain configuration: {message}" print("✓ Certificate chain configuration properly set up for CA signing") def test_certificate_chain(): """Test certificate chain - uses real certs if available, else validates config""" cert_files = find_generated_certificates() if cert_files: validate_certificate_chain_real(cert_files) else: validate_certificate_chain_config() def find_ansible_file(relative_path): """Find Ansible file from various possible locations""" # Try different base paths possible_bases = [ ".", # Current directory "..", # Parent directory (from tests/unit) "../..", # Grandparent (from tests/unit to project root) "../../..", # Alternative deep path ] for base in possible_bases: full_path = os.path.join(base, relative_path) if os.path.exists(full_path): return full_path return None if __name__ == "__main__": tests = [ test_openssl_version_detection, test_ca_certificate, test_server_certificates, test_client_certificates, test_pkcs12_files, test_certificate_chain, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_scaleway_fix.py ================================================ #!/usr/bin/env python3 """ Test Scaleway role fixes for issue #14846 This test validates that: 1. The Scaleway role uses the modern 'project' parameter instead of deprecated 'organization' 2. The Marketplace API is used for image lookup instead of the broken scaleway_image_info module 3. The prompts include organization/project ID collection """ import sys from pathlib import Path import yaml def load_yaml_file(file_path): """Load and parse a YAML file""" with open(file_path) as f: return yaml.safe_load(f) def test_scaleway_main_uses_project_parameter(): """Test that main.yml uses 'project' instead of deprecated 'organization' parameter""" main_yml = Path("roles/cloud-scaleway/tasks/main.yml") assert main_yml.exists(), "Scaleway main.yml not found" with open(main_yml) as f: content = f.read() # Should NOT use the broken scaleway_organization_info module assert "scaleway_organization_info" not in content, ( "Still using broken scaleway_organization_info module (issue #14846)" ) # Should NOT use the broken scaleway_image_info module assert "scaleway_image_info" not in content, "Still using broken scaleway_image_info module" # Should use project parameter (modern approach) assert "project:" in content, "Missing 'project:' parameter in scaleway_compute calls" assert "algo_scaleway_org_id" in content, "Missing algo_scaleway_org_id variable reference" # Should NOT use deprecated organization parameter assert 'organization: "{{' not in content, "Still using deprecated 'organization' parameter" # Should use Marketplace API for image lookup assert "api-marketplace.scaleway.com" in content, "Not using Scaleway Marketplace API for image lookup" print("✓ Scaleway main.yml uses modern 'project' parameter") def test_scaleway_prompts_collect_org_id(): """Test that prompts.yml collects organization/project ID from user""" prompts_yml = Path("roles/cloud-scaleway/tasks/prompts.yml") assert prompts_yml.exists(), "Scaleway prompts.yml not found" with open(prompts_yml) as f: content = f.read() # Should prompt for organization ID assert "Organization ID" in content, "Missing prompt for Scaleway Organization ID" # Should set algo_scaleway_org_id fact assert "algo_scaleway_org_id:" in content, "Missing algo_scaleway_org_id fact definition" # Should support SCW_DEFAULT_ORGANIZATION_ID env var assert "SCW_DEFAULT_ORGANIZATION_ID" in content, ( "Missing support for SCW_DEFAULT_ORGANIZATION_ID environment variable" ) # Should mention console.scaleway.com for finding the ID assert "console.scaleway.com" in content, "Missing instructions on where to find Organization ID" print("✓ Scaleway prompts.yml collects organization/project ID") def test_scaleway_config_has_valid_settings(): """Test that config.cfg has valid Scaleway settings""" config_file = Path("config.cfg") assert config_file.exists(), "config.cfg not found" with open(config_file) as f: content = f.read() # Should have scaleway section assert "scaleway:" in content, "Missing Scaleway configuration section" # Should specify Ubuntu 22.04 assert "Ubuntu 22.04" in content or "ubuntu" in content.lower(), "Missing Ubuntu image specification" print("✓ config.cfg has valid Scaleway settings") def test_scaleway_marketplace_api_usage(): """Test that the role correctly uses Scaleway Marketplace API""" main_yml = Path("roles/cloud-scaleway/tasks/main.yml") with open(main_yml) as f: content = f.read() # Should use uri module to fetch from Marketplace API assert "uri:" in content, "Not using uri module for API calls" # Should filter for Ubuntu 22.04 Jammy assert "Ubuntu" in content and "22" in content, "Not filtering for Ubuntu 22.04 image" # Should set scaleway_image_id variable assert "scaleway_image_id" in content, "Missing scaleway_image_id variable for image UUID" print("✓ Scaleway role uses Marketplace API correctly") if __name__ == "__main__": tests = [ test_scaleway_main_uses_project_parameter, test_scaleway_prompts_collect_org_id, test_scaleway_config_has_valid_settings, test_scaleway_marketplace_api_usage, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_strongswan_templates.py ================================================ #!/usr/bin/env python3 """ Enhanced tests for StrongSwan templates. Tests all strongswan role templates with various configurations. """ import os import sys import uuid from jinja2 import Environment, FileSystemLoader, StrictUndefined # Add parent directory to path for fixtures sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from fixtures import load_test_variables def mock_to_uuid(value): """Mock the to_uuid filter""" return str(uuid.uuid5(uuid.NAMESPACE_DNS, str(value))) def mock_bool(value): """Mock the bool filter""" return str(value).lower() in ("true", "1", "yes", "on") def mock_version(version_string, comparison): """Mock the version comparison filter""" # Simple mock - just return True for now return True def mock_b64encode(value): """Mock base64 encoding""" import base64 if isinstance(value, str): value = value.encode("utf-8") return base64.b64encode(value).decode("ascii") def mock_b64decode(value): """Mock base64 decoding""" import base64 return base64.b64decode(value).decode("utf-8") def get_strongswan_test_variables(scenario="default"): """Get test variables for StrongSwan templates with different scenarios.""" base_vars = load_test_variables() # Add StrongSwan specific variables strongswan_vars = { "ipsec_config_path": "/etc/ipsec.d", "ipsec_pki_path": "/etc/ipsec.d", "strongswan_enabled": True, "strongswan_network": "10.19.48.0/24", "strongswan_network_ipv6": "fd9d:bc11:4021::/64", "strongswan_log_level": "2", "openssl_constraint_random_id": "test-" + str(uuid.uuid4()), "subjectAltName": "IP:10.0.0.1,IP:2600:3c01::f03c:91ff:fedf:3b2a", "subjectAltName_type": "IP", "subjectAltName_client": "IP:10.0.0.1", "ansible_default_ipv6": {"address": "2600:3c01::f03c:91ff:fedf:3b2a"}, "openssl_version": "3.0.0", "p12_export_password": "test-password", "ike_lifetime": "24h", "ipsec_lifetime": "8h", "ike_dpd": "30s", "ipsec_dead_peer_detection": True, "rekey_margin": "3m", "rekeymargin": "3m", "dpddelay": "35s", "keyexchange": "ikev2", "ike_cipher": "aes128gcm16-prfsha512-ecp256", "esp_cipher": "aes128gcm16-ecp256", "leftsourceip": "10.19.48.1", "leftsubnet": "0.0.0.0/0,::/0", "rightsourceip": "10.19.48.2/24,fd9d:bc11:4021::2/64", } # Merge with base variables test_vars = {**base_vars, **strongswan_vars} # Apply scenario-specific overrides if scenario == "ipv4_only": test_vars["ipv6_support"] = False test_vars["subjectAltName"] = "IP:10.0.0.1" test_vars["ansible_default_ipv6"] = None elif scenario == "dns_hostname": test_vars["IP_subject_alt_name"] = "vpn.example.com" test_vars["subjectAltName"] = "DNS:vpn.example.com" test_vars["subjectAltName_type"] = "DNS" elif scenario == "openssl_legacy": test_vars["openssl_version"] = "1.1.1" return test_vars def test_strongswan_templates(): """Test all StrongSwan templates with various configurations.""" templates = [ "roles/strongswan/templates/ipsec.conf.j2", "roles/strongswan/templates/ipsec.secrets.j2", "roles/strongswan/templates/strongswan.conf.j2", "roles/strongswan/templates/charon.conf.j2", "roles/strongswan/templates/client_ipsec.conf.j2", "roles/strongswan/templates/client_ipsec.secrets.j2", "roles/strongswan/templates/100-CustomLimitations.conf.j2", ] scenarios = ["default", "ipv4_only", "dns_hostname", "openssl_legacy"] errors = [] tested = 0 for template_path in templates: if not os.path.exists(template_path): print(f" ⚠️ Skipping {template_path} (not found)") continue template_dir = os.path.dirname(template_path) template_name = os.path.basename(template_path) for scenario in scenarios: tested += 1 test_vars = get_strongswan_test_variables(scenario) try: env = Environment(loader=FileSystemLoader(template_dir), undefined=StrictUndefined) # Add mock filters env.filters["to_uuid"] = mock_to_uuid env.filters["bool"] = mock_bool env.filters["b64encode"] = mock_b64encode env.filters["b64decode"] = mock_b64decode env.tests["version"] = mock_version # For client templates, add item context if "client" in template_name: test_vars["item"] = "testuser" template = env.get_template(template_name) output = template.render(**test_vars) # Basic validation assert len(output) > 0, f"Empty output from {template_path} ({scenario})" # Specific validations based on template if "ipsec.conf" in template_name and "client" not in template_name: assert "conn" in output, "Missing connection definition" if scenario != "ipv4_only" and test_vars.get("ipv6_support"): assert "::/0" in output or "fd9d:bc11" in output, "Missing IPv6 configuration" if "ipsec.secrets" in template_name: assert "PSK" in output or "ECDSA" in output, "Missing authentication method" if "strongswan.conf" in template_name: assert "charon" in output, "Missing charon configuration" print(f" ✅ {template_name} ({scenario})") except Exception as e: errors.append(f"{template_path} ({scenario}): {e!s}") print(f" ❌ {template_name} ({scenario}): {e!s}") if errors: print(f"\n❌ StrongSwan template tests failed with {len(errors)} errors") for error in errors[:5]: print(f" {error}") return False else: print(f"\n✅ All StrongSwan template tests passed ({tested} tests)") return True def test_openssl_template_constraints(): """Test the OpenSSL task template that had the inline comment issue.""" # This tests the actual openssl.yml task file to ensure our fix works import yaml openssl_path = "roles/strongswan/tasks/openssl.yml" if not os.path.exists(openssl_path): print("⚠️ OpenSSL tasks file not found") return True try: with open(openssl_path) as f: content = yaml.safe_load(f) # Find the CA CSR task ca_csr_task = None for task in content: if isinstance(task, dict) and task.get("name", "").startswith("Create certificate signing request"): ca_csr_task = task break if ca_csr_task: # Check that name_constraints_permitted is properly formatted csr_module = ca_csr_task.get("community.crypto.openssl_csr_pipe", {}) constraints = csr_module.get("name_constraints_permitted", "") # The constraints should be a Jinja2 template without inline comments if "#" in str(constraints): # Check if the # is within {{ }} import re jinja_blocks = re.findall(r"\{\{.*?\}\}", str(constraints), re.DOTALL) for block in jinja_blocks: if "#" in block: print("❌ Found inline comment in Jinja2 expression") return False print("✅ OpenSSL template constraints validated") return True except Exception as e: print(f"⚠️ Error checking OpenSSL tasks: {e}") return True # Don't fail the test for this def test_mobileconfig_template(): """Test the mobileconfig template with various scenarios.""" template_path = "roles/strongswan/templates/mobileconfig.j2" if not os.path.exists(template_path): print("⚠️ Mobileconfig template not found") return True # Skip this test - mobileconfig.j2 is too tightly coupled to Ansible runtime # It requires complex mock objects (item.1.stdout) and many dynamic variables # that are generated during playbook execution print("⚠️ Skipping mobileconfig template test (requires Ansible runtime context)") return True test_cases = [ { "name": "iPhone with cellular on-demand", "algo_ondemand_cellular": "true", "algo_ondemand_wifi": "false", }, { "name": "iPad with WiFi on-demand", "algo_ondemand_cellular": "false", "algo_ondemand_wifi": "true", "algo_ondemand_wifi_exclude": "MyHomeNetwork,OfficeWiFi", }, { "name": "Mac without on-demand", "algo_ondemand_cellular": "false", "algo_ondemand_wifi": "false", }, ] errors = [] for test_case in test_cases: test_vars = get_strongswan_test_variables() test_vars.update(test_case) # Mock Ansible task result format for item class MockTaskResult: def __init__(self, content): self.stdout = content test_vars["item"] = ("testuser", MockTaskResult("TU9DS19QS0NTMTJfQ09OVEVOVA==")) # Tuple with mock result test_vars["PayloadContentCA_base64"] = "TU9DS19DQV9DRVJUX0JBU0U2NA==" # Valid base64 test_vars["PayloadContentUser_base64"] = "TU9DS19VU0VSX0NFUlRfQkFTRTY0" # Valid base64 test_vars["pkcs12_PayloadCertificateUUID"] = str(uuid.uuid4()) test_vars["PayloadContent"] = "TU9DS19QS0NTMTJfQ09OVEVOVA==" # Valid base64 for PKCS12 test_vars["algo_server_name"] = "test-algo-vpn" test_vars["VPN_PayloadIdentifier"] = str(uuid.uuid4()) test_vars["CA_PayloadIdentifier"] = str(uuid.uuid4()) test_vars["PayloadContentCA"] = "TU9DS19DQV9DRVJUX0NPTlRFTlQ=" # Valid base64 try: env = Environment(loader=FileSystemLoader("roles/strongswan/templates"), undefined=StrictUndefined) # Add mock filters env.filters["to_uuid"] = mock_to_uuid env.filters["b64encode"] = mock_b64encode env.filters["b64decode"] = mock_b64decode template = env.get_template("mobileconfig.j2") output = template.render(**test_vars) # Validate output assert " 10: print(f" ... and {len(errors) - 10} more") assert False, "Template syntax errors found" else: print(f"✓ Template syntax check passed ({len(templates) - skipped} templates, {skipped} skipped)") def test_critical_templates(): """Test that critical templates render with test data""" critical_templates = [ "roles/wireguard/templates/client.conf.j2", "roles/strongswan/templates/ipsec.conf.j2", "roles/strongswan/templates/ipsec.secrets.j2", "roles/dns/templates/adblock.sh.j2", "roles/dns/templates/dnsmasq.conf.j2", "roles/common/templates/rules.v4.j2", "roles/common/templates/rules.v6.j2", ] test_vars = get_test_variables() errors = [] for template_path in critical_templates: if not os.path.exists(template_path): continue # Skip if template doesn't exist try: template_dir = os.path.dirname(template_path) template_name = os.path.basename(template_path) env = Environment(loader=FileSystemLoader(template_dir), undefined=StrictUndefined) # Add mock functions env.globals["lookup"] = mock_lookup env.filters["to_uuid"] = mock_to_uuid env.filters["bool"] = mock_bool template = env.get_template(template_name) # Add item context for templates that use loops # With modern loop syntax, item is the username string directly if "client" in template_name: test_vars["item"] = "test-user" # Try to render output = template.render(**test_vars) # Basic validation - should produce some output assert len(output) > 0, f"Empty output from {template_path}" except UndefinedError as e: errors.append(f"{template_path}: Missing variable - {e}") except Exception as e: errors.append(f"{template_path}: Render error - {e}") if errors: print("✗ Critical template rendering failed:") for error in errors: print(f" - {error}") assert False, "Critical template rendering errors" else: print("✓ Critical template rendering test passed") def test_variable_consistency(): """Check that commonly used variables are defined consistently""" # Variables that should be used consistently across templates common_vars = [ "server_name", "IP_subject_alt_name", "wireguard_port", "wireguard_network", "dns_servers", "users", ] # Check if main.yml defines these if os.path.exists("main.yml"): with open("main.yml") as f: content = f.read() missing = [] for var in common_vars: # Simple check - could be improved if var not in content: missing.append(var) if missing: print(f"⚠ Variables possibly not defined in main.yml: {missing}") print("✓ Variable consistency check completed") def test_wireguard_ipv6_endpoints(): """Test that WireGuard client configs properly format IPv6 endpoints""" test_cases = [ # IPv4 address - should not be bracketed {"IP_subject_alt_name": "192.168.1.100", "expected_endpoint": "Endpoint = 192.168.1.100:51820"}, # IPv6 address - should be bracketed { "IP_subject_alt_name": "2600:3c01::f03c:91ff:fedf:3b2a", "expected_endpoint": "Endpoint = [2600:3c01::f03c:91ff:fedf:3b2a]:51820", }, # Hostname - should not be bracketed {"IP_subject_alt_name": "vpn.example.com", "expected_endpoint": "Endpoint = vpn.example.com:51820"}, # IPv6 with zone ID - should be bracketed {"IP_subject_alt_name": "fe80::1%eth0", "expected_endpoint": "Endpoint = [fe80::1%eth0]:51820"}, ] template_path = "roles/wireguard/templates/client.conf.j2" if not os.path.exists(template_path): print(f"⚠ Skipping IPv6 endpoint test - {template_path} not found") return base_vars = get_test_variables() errors = [] for test_case in test_cases: try: # Set up test variables test_vars = {**base_vars, **test_case} # With modern loop syntax, item is the username string directly test_vars["item"] = "test-user" # Render template env = Environment(loader=FileSystemLoader("roles/wireguard/templates"), undefined=StrictUndefined) env.globals["lookup"] = mock_lookup template = env.get_template("client.conf.j2") output = template.render(**test_vars) # Check if the expected endpoint format is in the output if test_case["expected_endpoint"] not in output: errors.append( f"Expected '{test_case['expected_endpoint']}' for IP '{test_case['IP_subject_alt_name']}' but not found in output" ) # Print relevant part of output for debugging for line in output.split("\n"): if "Endpoint" in line: errors.append(f" Found: {line.strip()}") except Exception as e: errors.append(f"Error testing {test_case['IP_subject_alt_name']}: {e}") if errors: print("✗ WireGuard IPv6 endpoint test failed:") for error in errors: print(f" - {error}") assert False, "IPv6 endpoint formatting errors" else: print("✓ WireGuard IPv6 endpoint test passed (4 test cases)") def test_template_conditionals(): """Test templates with different conditional states""" test_cases = [ # WireGuard enabled, IPsec disabled { "wireguard_enabled": True, "ipsec_enabled": False, "dns_encryption": True, "dns_adblocking": True, "algo_ssh_tunneling": False, }, # IPsec enabled, WireGuard disabled { "wireguard_enabled": False, "ipsec_enabled": True, "dns_encryption": False, "dns_adblocking": False, "algo_ssh_tunneling": True, }, # Both enabled { "wireguard_enabled": True, "ipsec_enabled": True, "dns_encryption": True, "dns_adblocking": True, "algo_ssh_tunneling": True, }, ] base_vars = get_test_variables() for i, test_case in enumerate(test_cases): # Merge test case with base vars test_vars = {**base_vars, **test_case} # Test a few templates that have conditionals conditional_templates = [ "roles/common/templates/rules.v4.j2", ] for template_path in conditional_templates: if not os.path.exists(template_path): continue try: template_dir = os.path.dirname(template_path) template_name = os.path.basename(template_path) env = Environment(loader=FileSystemLoader(template_dir), undefined=StrictUndefined) # Add mock functions env.globals["lookup"] = mock_lookup env.filters["to_uuid"] = mock_to_uuid env.filters["bool"] = mock_bool template = env.get_template(template_name) output = template.render(**test_vars) # Verify conditionals work if test_case.get("wireguard_enabled"): assert str(test_vars["wireguard_port"]) in output, f"WireGuard port missing when enabled (case {i})" except Exception as e: print(f"✗ Conditional test failed for {template_path} case {i}: {e}") raise print("✓ Template conditional tests passed") if __name__ == "__main__": # Check if we have Jinja2 available try: import jinja2 # noqa: F401 except ImportError: print("⚠ Skipping template tests - jinja2 not installed") print(" Run: pip install jinja2") sys.exit(0) tests = [ test_template_syntax, test_critical_templates, test_variable_consistency, test_wireguard_ipv6_endpoints, test_template_conditionals, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} template tests passed!") ================================================ FILE: tests/unit/test_user_management.py ================================================ #!/usr/bin/env python3 """ Test user management functionality without deployment Based on issues #14745, #14746, #14738, #14726 """ import os import re import sys import tempfile import yaml def test_user_list_parsing(): """Test that user lists in config.cfg are parsed correctly""" test_config = """ users: - alice - bob - charlie - user-with-dash - user_with_underscore """ config = yaml.safe_load(test_config) users = config.get("users", []) assert len(users) == 5, f"Expected 5 users, got {len(users)}" assert "alice" in users, "Missing user 'alice'" assert "user-with-dash" in users, "Dash in username not handled" assert "user_with_underscore" in users, "Underscore in username not handled" # Test that usernames are valid username_pattern = re.compile(r"^[a-zA-Z0-9_-]+$") for user in users: assert username_pattern.match(user), f"Invalid username format: {user}" print("✓ User list parsing test passed") def test_server_selection_format(): """Test server selection string parsing (issue #14727)""" # Test various server display formats test_cases = [ {"display": "1. 192.168.1.100 (algo-server)", "expected_ip": "192.168.1.100", "expected_name": "algo-server"}, {"display": "2. 10.0.0.1 (production-vpn)", "expected_ip": "10.0.0.1", "expected_name": "production-vpn"}, { "display": "3. vpn.example.com (example-server)", "expected_ip": "vpn.example.com", "expected_name": "example-server", }, ] # Pattern to extract IP and name from display string pattern = re.compile(r"^\d+\.\s+([^\s]+)\s+\(([^)]+)\)$") for case in test_cases: match = pattern.match(case["display"]) assert match, f"Failed to parse: {case['display']}" ip_or_host = match.group(1) name = match.group(2) assert ip_or_host == case["expected_ip"], f"Wrong IP extracted: {ip_or_host}" assert name == case["expected_name"], f"Wrong name extracted: {name}" print("✓ Server selection format test passed") def test_ssh_key_preservation(): """Test that SSH keys aren't regenerated unnecessarily""" with tempfile.TemporaryDirectory() as tmpdir: ssh_key_path = os.path.join(tmpdir, "test_key") # Simulate existing SSH key with open(ssh_key_path, "w") as f: f.write("EXISTING_SSH_KEY_CONTENT") with open(f"{ssh_key_path}.pub", "w") as f: f.write("ssh-rsa EXISTING_PUBLIC_KEY") # Record original content with open(ssh_key_path) as f: original_content = f.read() # Test that key is preserved when it already exists assert os.path.exists(ssh_key_path), "SSH key should exist" assert os.path.exists(f"{ssh_key_path}.pub"), "SSH public key should exist" # Verify content hasn't changed with open(ssh_key_path) as f: current_content = f.read() assert current_content == original_content, "SSH key was modified" print("✓ SSH key preservation test passed") def test_ca_password_handling(): """Test CA password validation and handling""" # Test password requirements valid_passwords = ["SecurePassword123!", "Algo-VPN-2024", "Complex#Pass@Word999"] invalid_passwords = [ "", # Empty "short", # Too short "password with spaces", # Spaces not allowed in some contexts ] # Basic password validation for pwd in valid_passwords: assert len(pwd) >= 12, f"Password too short: {pwd}" assert " " not in pwd, f"Password contains spaces: {pwd}" for pwd in invalid_passwords: issues = [] if len(pwd) < 12: issues.append("too short") if " " in pwd: issues.append("contains spaces") if not pwd: issues.append("empty") assert issues, f"Expected validation issues for: {pwd}" print("✓ CA password handling test passed") def test_user_config_generation(): """Test that user configs would be generated correctly""" users = ["alice", "bob", "charlie"] server_name = "test-server" # Simulate config file structure for user in users: # Test WireGuard config path wg_path = f"configs/{server_name}/wireguard/{user}.conf" assert user in wg_path, "Username not in WireGuard config path" # Test IPsec config path ipsec_path = f"configs/{server_name}/ipsec/{user}.p12" assert user in ipsec_path, "Username not in IPsec config path" # Test SSH tunnel config path ssh_path = f"configs/{server_name}/ssh-tunnel/{user}.pem" assert user in ssh_path, "Username not in SSH config path" print("✓ User config generation test passed") def test_duplicate_user_handling(): """Test handling of duplicate usernames""" test_config = """ users: - alice - bob - alice - charlie """ config = yaml.safe_load(test_config) users = config.get("users", []) # Check for duplicates unique_users = list(set(users)) assert len(unique_users) < len(users), "Duplicates should be detected" # Test that duplicates can be identified seen = set() duplicates = [] for user in users: if user in seen: duplicates.append(user) seen.add(user) assert "alice" in duplicates, "Duplicate 'alice' not detected" print("✓ Duplicate user handling test passed") if __name__ == "__main__": tests = [ test_user_list_parsing, test_server_selection_format, test_ssh_key_preservation, test_ca_password_handling, test_user_config_generation, test_duplicate_user_handling, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_wireguard_key_generation.py ================================================ #!/usr/bin/env python3 """ Test WireGuard key generation - focused on x25519_pubkey module integration Addresses test gap identified in tests/README.md line 63-67: WireGuard private/public key generation """ import base64 import os import subprocess import sys import tempfile # Add library directory to path to import our custom module sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "library")) def test_wireguard_tools_available(): """Test that WireGuard tools are available for validation""" try: result = subprocess.run(["wg", "--version"], capture_output=True, text=True) assert result.returncode == 0, "WireGuard tools not available" print(f"✓ WireGuard tools available: {result.stdout.strip()}") return True except FileNotFoundError: print("⚠ WireGuard tools not available - skipping validation tests") return False def test_x25519_module_import(): """Test that our custom x25519_pubkey module can be imported and used""" try: import x25519_pubkey # noqa: F401 print("✓ x25519_pubkey module imports successfully") return True except ImportError as e: assert False, f"Cannot import x25519_pubkey module: {e}" def generate_test_private_key(): """Generate a test private key using the same method as Algo""" with tempfile.NamedTemporaryFile(suffix=".raw", delete=False) as temp_file: raw_key_path = temp_file.name try: # Generate 32 random bytes for X25519 private key (same as community.crypto does) import secrets raw_data = secrets.token_bytes(32) # Write raw key to file (like community.crypto openssl_privatekey with format: raw) with open(raw_key_path, "wb") as f: f.write(raw_data) assert len(raw_data) == 32, f"Private key should be 32 bytes, got {len(raw_data)}" b64_key = base64.b64encode(raw_data).decode() print(f"✓ Generated private key (base64): {b64_key[:12]}...") return raw_key_path, b64_key except Exception: # Clean up on error if os.path.exists(raw_key_path): os.unlink(raw_key_path) raise def test_x25519_pubkey_from_raw_file(): """Test our x25519_pubkey module with raw private key file""" raw_key_path, _b64_key = generate_test_private_key() try: # Import here so we can mock the module_utils if needed # Mock the AnsibleModule for testing class MockModule: def __init__(self, params): self.params = params self.result = {} def fail_json(self, **kwargs): raise Exception(f"Module failed: {kwargs}") def exit_json(self, **kwargs): self.result = kwargs with tempfile.NamedTemporaryFile(suffix=".pub", delete=False) as temp_pub: public_key_path = temp_pub.name try: # Test the module logic directly import x25519_pubkey from x25519_pubkey import run_module original_AnsibleModule = x25519_pubkey.AnsibleModule try: # Mock the module call mock_module = MockModule( {"private_key_path": raw_key_path, "public_key_path": public_key_path, "private_key_b64": None} ) x25519_pubkey.AnsibleModule = lambda **kwargs: mock_module # Run the module run_module() # Check the result assert "public_key" in mock_module.result assert mock_module.result["changed"] assert os.path.exists(public_key_path) with open(public_key_path) as f: derived_pubkey = f.read().strip() # Validate base64 format try: decoded = base64.b64decode(derived_pubkey, validate=True) assert len(decoded) == 32, f"Public key should be 32 bytes, got {len(decoded)}" except Exception as e: assert False, f"Invalid base64 public key: {e}" print(f"✓ Derived public key from raw file: {derived_pubkey[:12]}...") return derived_pubkey finally: x25519_pubkey.AnsibleModule = original_AnsibleModule finally: if os.path.exists(public_key_path): os.unlink(public_key_path) finally: if os.path.exists(raw_key_path): os.unlink(raw_key_path) def test_x25519_pubkey_from_b64_string(): """Test our x25519_pubkey module with base64 private key string""" raw_key_path, b64_key = generate_test_private_key() try: class MockModule: def __init__(self, params): self.params = params self.result = {} def fail_json(self, **kwargs): raise Exception(f"Module failed: {kwargs}") def exit_json(self, **kwargs): self.result = kwargs import x25519_pubkey from x25519_pubkey import run_module original_AnsibleModule = x25519_pubkey.AnsibleModule try: mock_module = MockModule({"private_key_b64": b64_key, "private_key_path": None, "public_key_path": None}) x25519_pubkey.AnsibleModule = lambda **kwargs: mock_module # Run the module run_module() # Check the result assert "public_key" in mock_module.result derived_pubkey = mock_module.result["public_key"] # Validate base64 format try: decoded = base64.b64decode(derived_pubkey, validate=True) assert len(decoded) == 32, f"Public key should be 32 bytes, got {len(decoded)}" except Exception as e: assert False, f"Invalid base64 public key: {e}" print(f"✓ Derived public key from base64 string: {derived_pubkey[:12]}...") return derived_pubkey finally: x25519_pubkey.AnsibleModule = original_AnsibleModule finally: if os.path.exists(raw_key_path): os.unlink(raw_key_path) def test_wireguard_validation(): """Test that our derived keys work with actual WireGuard tools""" if not test_wireguard_tools_available(): return # Generate keys using our method raw_key_path, b64_key = generate_test_private_key() try: # Derive public key using our module class MockModule: def __init__(self, params): self.params = params self.result = {} def fail_json(self, **kwargs): raise Exception(f"Module failed: {kwargs}") def exit_json(self, **kwargs): self.result = kwargs import x25519_pubkey from x25519_pubkey import run_module original_AnsibleModule = x25519_pubkey.AnsibleModule try: mock_module = MockModule({"private_key_b64": b64_key, "private_key_path": None, "public_key_path": None}) x25519_pubkey.AnsibleModule = lambda **kwargs: mock_module run_module() derived_pubkey = mock_module.result["public_key"] finally: x25519_pubkey.AnsibleModule = original_AnsibleModule with tempfile.NamedTemporaryFile(mode="w", suffix=".conf", delete=False) as temp_config: # Create a WireGuard config using our keys wg_config = f"""[Interface] PrivateKey = {b64_key} Address = 10.19.49.1/24 [Peer] PublicKey = {derived_pubkey} AllowedIPs = 10.19.49.2/32 """ temp_config.write(wg_config) config_path = temp_config.name try: # Test that WireGuard can parse our config result = subprocess.run(["wg-quick", "strip", config_path], capture_output=True, text=True) assert result.returncode == 0, f"WireGuard rejected our config: {result.stderr}" # Test key derivation with wg pubkey command wg_result = subprocess.run(["wg", "pubkey"], input=b64_key, capture_output=True, text=True) if wg_result.returncode == 0: wg_derived = wg_result.stdout.strip() assert wg_derived == derived_pubkey, f"Key mismatch: wg={wg_derived} vs ours={derived_pubkey}" print("✓ WireGuard validation: keys match wg pubkey output") else: print(f"⚠ Could not validate with wg pubkey: {wg_result.stderr}") print("✓ WireGuard accepts our generated configuration") finally: if os.path.exists(config_path): os.unlink(config_path) finally: if os.path.exists(raw_key_path): os.unlink(raw_key_path) def test_key_consistency(): """Test that the same private key always produces the same public key""" # Generate one private key to reuse raw_key_path, b64_key = generate_test_private_key() try: def derive_pubkey_from_same_key(): class MockModule: def __init__(self, params): self.params = params self.result = {} def fail_json(self, **kwargs): raise Exception(f"Module failed: {kwargs}") def exit_json(self, **kwargs): self.result = kwargs import x25519_pubkey from x25519_pubkey import run_module original_AnsibleModule = x25519_pubkey.AnsibleModule try: mock_module = MockModule( { "private_key_b64": b64_key, # SAME key each time "private_key_path": None, "public_key_path": None, } ) x25519_pubkey.AnsibleModule = lambda **kwargs: mock_module run_module() return mock_module.result["public_key"] finally: x25519_pubkey.AnsibleModule = original_AnsibleModule # Derive public key multiple times from same private key pubkey1 = derive_pubkey_from_same_key() pubkey2 = derive_pubkey_from_same_key() assert pubkey1 == pubkey2, f"Key derivation not consistent: {pubkey1} vs {pubkey2}" print("✓ Key derivation is consistent") finally: if os.path.exists(raw_key_path): os.unlink(raw_key_path) if __name__ == "__main__": tests = [ test_x25519_module_import, test_x25519_pubkey_from_raw_file, test_x25519_pubkey_from_b64_string, test_key_consistency, test_wireguard_validation, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} failed: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} error: {e}") failed += 1 if failed > 0: print(f"\n{failed} tests failed") sys.exit(1) else: print(f"\nAll {len(tests)} tests passed!") ================================================ FILE: tests/unit/test_yaml_jinja2_expressions.py ================================================ #!/usr/bin/env python3 """ Test that Jinja2 expressions within YAML files are valid. This catches issues like inline comments in Jinja2 expressions within YAML task files. """ import re from pathlib import Path import pytest import yaml from jinja2 import Environment, StrictUndefined, TemplateSyntaxError def find_yaml_files_with_jinja2(): """Find all YAML files that might contain Jinja2 expressions.""" yaml_files = [] # Look for YAML files in roles that are likely to have Jinja2 patterns = ["roles/**/tasks/*.yml", "roles/**/defaults/*.yml", "roles/**/vars/*.yml", "playbooks/*.yml", "*.yml"] skip_dirs = {".git", ".venv", "venv", ".env", "configs"} for pattern in patterns: for path in Path(".").glob(pattern): if not any(skip_dir in path.parts for skip_dir in skip_dirs): yaml_files.append(path) return sorted(yaml_files) def extract_jinja2_expressions(content): """Extract all Jinja2 expressions from text content.""" expressions = [] # Find {{ ... }} expressions (variable interpolations) for match in re.finditer(r"\{\{(.+?)\}\}", content, re.DOTALL): expressions.append( { "type": "variable", "content": match.group(1), "full": match.group(0), "start": match.start(), "end": match.end(), } ) # Find {% ... %} expressions (control structures) for match in re.finditer(r"\{%(.+?)%\}", content, re.DOTALL): expressions.append( { "type": "control", "content": match.group(1), "full": match.group(0), "start": match.start(), "end": match.end(), } ) return expressions def find_line_number(content, position): """Find the line number for a given position in content.""" return content[:position].count("\n") + 1 def validate_jinja2_expression(expression, context_vars=None): """ Validate a single Jinja2 expression. Returns (is_valid, error_message) """ if context_vars is None: context_vars = get_test_variables() # First check for inline comments - this is the main issue we want to catch if "#" in expression["content"]: # Check if the # is within a list or dict literal content = expression["content"] # Remove strings to avoid false positives cleaned = re.sub(r'"[^"]*"', '""', content) cleaned = re.sub(r"'[^']*'", "''", cleaned) # Look for # that appears to be a comment # The # should have something before it (not at start) and something after (the comment text) # Also check for # at the start of a line within the expression if "#" in cleaned: # Check each line in the cleaned expression for line in cleaned.split("\n"): line = line.strip() if "#" in line: # If # appears and it's not escaped (\#) hash_idx = line.find("#") if hash_idx >= 0: # Check if it's escaped if hash_idx == 0 or line[hash_idx - 1] != "\\": # This looks like an inline comment return ( False, "Inline comment (#) found in Jinja2 expression - comments must be outside expressions", ) try: env = Environment(undefined=StrictUndefined) # Add common Ansible filters (expanded list) env.filters["bool"] = lambda x: bool(x) env.filters["default"] = lambda x, d="": x if x else d env.filters["to_uuid"] = lambda x: "mock-uuid" env.filters["b64encode"] = lambda x: "mock-base64" env.filters["b64decode"] = lambda x: "mock-decoded" env.filters["version"] = lambda x, op: True env.filters["ternary"] = lambda x, y, z=None: y if x else (z if z is not None else "") env.filters["regex_replace"] = lambda x, p, r: x env.filters["difference"] = lambda x, y: list(set(x) - set(y)) env.filters["strftime"] = lambda fmt, ts: "mock-timestamp" env.filters["int"] = lambda x: int(x) if x else 0 env.filters["list"] = lambda x: list(x) env.filters["map"] = lambda x, *args: x env.tests["version"] = lambda x, op: True # Wrap the expression in appropriate delimiters for parsing if expression["type"] == "variable": template_str = "{{" + expression["content"] + "}}" else: template_str = "{%" + expression["content"] + "%}" # Try to compile the template template = env.from_string(template_str) # Try to render it with test variables # This will catch undefined variables and runtime errors template.render(**context_vars) return True, None except TemplateSyntaxError as e: # Check for the specific inline comment issue if "#" in expression["content"]: # Check if the # is within a list or dict literal content = expression["content"] # Remove strings to avoid false positives cleaned = re.sub(r'"[^"]*"', '""', content) cleaned = re.sub(r"'[^']*'", "''", cleaned) # Look for # that appears to be a comment (not in string, not escaped) if re.search(r"[^\\\n]#[^\}]", cleaned): return False, "Inline comment (#) found in Jinja2 expression - comments must be outside expressions" return False, f"Syntax error: {e.message}" except Exception as e: # Be lenient - we mainly care about inline comments and basic syntax # Ignore runtime errors (undefined vars, missing attributes, etc.) error_str = str(e).lower() if any(ignore in error_str for ignore in ["undefined", "has no attribute", "no filter"]): return True, None # These are runtime issues, not syntax issues return False, f"Error: {e!s}" def get_test_variables(): """Get a comprehensive set of test variables for expression validation.""" return { # Network configuration "IP_subject_alt_name": "10.0.0.1", "server_name": "algo-vpn", "wireguard_port": 51820, "wireguard_network": "10.19.49.0/24", "wireguard_network_ipv6": "fd9d:bc11:4021::/64", "strongswan_network": "10.19.48.0/24", "strongswan_network_ipv6": "fd9d:bc11:4020::/64", # Feature flags "ipv6_support": True, "dns_encryption": True, "dns_adblocking": True, "wireguard_enabled": True, "ipsec_enabled": True, # OpenSSL/PKI "openssl_constraint_random_id": "test-uuid-12345", "CA_password": "test-password", "p12_export_password": "test-p12-password", "ipsec_pki_path": "/etc/ipsec.d", "ipsec_config_path": "/etc/ipsec.d", "subjectAltName": "IP:10.0.0.1,DNS:vpn.example.com", "subjectAltName_type": "IP", # Ansible variables "ansible_default_ipv4": {"address": "10.0.0.1"}, "ansible_default_ipv6": {"address": "2600:3c01::f03c:91ff:fedf:3b2a"}, "ansible_distribution": "Ubuntu", "ansible_distribution_version": "22.04", "ansible_date_time": {"epoch": "1234567890"}, # User management "users": ["alice", "bob", "charlie"], "all_users": ["alice", "bob", "charlie", "david"], # Common variables "item": "test-item", "algo_provider": "local", "algo_server_name": "algo-vpn", "dns_servers": ["1.1.1.1", "1.0.0.1"], # OpenSSL version for conditionals "openssl_version": "3.0.0", # IPsec configuration "certificate_validity_days": 3650, "ike_cipher": "aes128gcm16-prfsha512-ecp256", "esp_cipher": "aes128gcm16-ecp256", } def validate_yaml_file(yaml_path, check_inline_comments_only=False): """ Validate all Jinja2 expressions in a YAML file. Returns (has_inline_comments, list_of_inline_comment_errors, list_of_other_errors) """ inline_comment_errors = [] other_errors = [] try: with open(yaml_path) as f: content = f.read() # First, check if it's valid YAML try: yaml.safe_load(content) except yaml.YAMLError: # YAML syntax error, not our concern here return False, [], [] # Extract all Jinja2 expressions expressions = extract_jinja2_expressions(content) if not expressions: return False, [], [] # No Jinja2 expressions to validate # Validate each expression for expr in expressions: is_valid, error = validate_jinja2_expression(expr) if not is_valid: line_num = find_line_number(content, expr["start"]) error_msg = f"{yaml_path}:{line_num}: {error}" # Separate inline comment errors from other errors if error and "inline comment" in error.lower(): inline_comment_errors.append(error_msg) # Show context for inline comment errors if len(expr["full"]) < 200: inline_comment_errors.append(f" Expression: {expr['full'][:100]}...") elif not check_inline_comments_only: other_errors.append(error_msg) except Exception as e: if not check_inline_comments_only: other_errors.append(f"{yaml_path}: Error reading file: {e}") return len(inline_comment_errors) > 0, inline_comment_errors, other_errors def test_regression_openssl_inline_comments(): """ Regression test for the specific OpenSSL inline comment bug that was reported. Tests that we correctly detect inline comments in the exact pattern that caused the issue. """ # The problematic expression that was reported problematic_expr = """{{ [ subjectAltName_type + ':' + IP_subject_alt_name + ('/255.255.255.255' if subjectAltName_type == 'IP' else ''), 'DNS:' + openssl_constraint_random_id, # Per-deployment UUID prevents cross-deployment reuse 'email:' + openssl_constraint_random_id # Unique email domain isolates certificate scope ] + ( ['IP:' + ansible_default_ipv6['address'] + '/128'] if ipv6_support else [] ) }}""" # The fixed expression (without inline comments) fixed_expr = """{{ [ subjectAltName_type + ':' + IP_subject_alt_name + ('/255.255.255.255' if subjectAltName_type == 'IP' else ''), 'DNS:' + openssl_constraint_random_id, 'email:' + openssl_constraint_random_id ] + ( ['IP:' + ansible_default_ipv6['address'] + '/128'] if ipv6_support else [] ) }}""" # Test the problematic expression - should fail expr_with_comments = { "type": "variable", "content": problematic_expr[2:-2], # Remove {{ }} "full": problematic_expr, } is_valid, error = validate_jinja2_expression(expr_with_comments) assert not is_valid, "Should have detected inline comments in problematic expression" assert "inline comment" in error.lower(), f"Expected inline comment error, got: {error}" # Test the fixed expression - should pass expr_fixed = { "type": "variable", "content": fixed_expr[2:-2], # Remove {{ }} "full": fixed_expr, } is_valid, error = validate_jinja2_expression(expr_fixed) assert is_valid, f"Fixed expression should pass but got error: {error}" def test_edge_cases_inline_comments(): """ Test various edge cases for inline comment detection. Ensures we correctly handle hashes in strings, escaped hashes, and various comment patterns. """ test_cases = [ # (expression, should_pass, description) ("{{ 'string with # hash' }}", True, "Hash in string should pass"), ('{{ "another # in string" }}', True, "Hash in double-quoted string should pass"), ("{{ var # comment }}", False, "Simple inline comment should fail"), ("{{ var1 + var2 # This is an inline comment }}", False, "Inline comment with text should fail"), (r"{{ '\#' + 'escaped hash' }}", True, "Escaped hash should pass"), ("{% if true # comment %}", False, "Comment in control block should fail"), ("{% for item in list # loop comment %}", False, "Comment in for loop should fail"), ("{{ {'key': 'value # not a comment'} }}", True, "Hash in dict string value should pass"), ("{{ url + '/#anchor' }}", True, "URL fragment should pass"), ("{{ '#FF0000' }}", True, "Hex color code should pass"), ("{{ var }} # comment outside", True, "Comment outside expression should pass"), ( """{{ [ 'item1', # comment here 'item2' ] }}""", False, "Multi-line with inline comment should fail", ), ] for expr_str, should_pass, description in test_cases: # For the "comment outside" case, extract just the Jinja2 expression if "{{" in expr_str and "#" in expr_str and expr_str.index("#") > expr_str.index("}}"): # Comment is outside the expression - extract just the expression part match = re.search(r"(\{\{.+?\}\})", expr_str) if match: actual_expr = match.group(1) expr_type = "variable" content = actual_expr[2:-2].strip() else: continue elif expr_str.strip().startswith("{{"): expr_type = "variable" content = expr_str.strip()[2:-2] actual_expr = expr_str.strip() elif expr_str.strip().startswith("{%"): expr_type = "control" content = expr_str.strip()[2:-2] actual_expr = expr_str.strip() else: continue expr = {"type": expr_type, "content": content, "full": actual_expr} is_valid, error = validate_jinja2_expression(expr) if should_pass: assert is_valid, f"{description}: {error}" else: assert not is_valid, f"{description}: Should have failed but passed" assert "inline comment" in (error or "").lower(), ( f"{description}: Expected inline comment error, got: {error}" ) def test_yaml_files_no_inline_comments(): """ Test that all YAML files in the project don't contain inline comments in Jinja2 expressions. """ yaml_files = find_yaml_files_with_jinja2() all_inline_comment_errors = [] files_with_inline_comments = [] for yaml_file in yaml_files: has_inline_comments, inline_errors, _ = validate_yaml_file(yaml_file, check_inline_comments_only=True) if has_inline_comments: files_with_inline_comments.append(str(yaml_file)) all_inline_comment_errors.extend(inline_errors) # Assert no inline comments found assert not all_inline_comment_errors, ( f"Found inline comments in {len(files_with_inline_comments)} files:\n" + "\n".join(all_inline_comment_errors[:10]) # Show first 10 errors ) def test_openssl_file_specifically(): """ Specifically test the OpenSSL file that had the original bug. """ openssl_file = Path("roles/strongswan/tasks/openssl.yml") if not openssl_file.exists(): pytest.skip(f"{openssl_file} not found") has_inline_comments, inline_errors, _ = validate_yaml_file(openssl_file) assert not has_inline_comments, f"Found inline comments in {openssl_file}:\n" + "\n".join(inline_errors) ================================================ FILE: tests/validate_jinja2_templates.py ================================================ #!/usr/bin/env python3 """ Validate all Jinja2 templates in the Algo codebase. This script checks for: 1. Syntax errors (including inline comments in expressions) 2. Undefined variables 3. Common anti-patterns """ import re import sys from pathlib import Path from jinja2 import Environment, FileSystemLoader, StrictUndefined, TemplateSyntaxError, meta def find_jinja2_templates(root_dir: str = ".") -> list[Path]: """Find all Jinja2 template files in the project.""" templates = [] patterns = ["**/*.j2", "**/*.jinja2", "**/*.yml.j2", "**/*.conf.j2"] # Skip these directories skip_dirs = {".git", ".venv", "venv", ".env", "configs", "__pycache__", ".cache"} for pattern in patterns: for path in Path(root_dir).glob(pattern): # Skip if in a directory we want to ignore if not any(skip_dir in path.parts for skip_dir in skip_dirs): templates.append(path) return sorted(templates) def check_inline_comments_in_expressions(template_content: str, template_path: Path) -> list[str]: """ Check for inline comments (#) within Jinja2 expressions. This is the error we just fixed in openssl.yml. """ errors = [] # Pattern to find Jinja2 expressions jinja_pattern = re.compile(r"\{\{.*?\}\}|\{%.*?%\}", re.DOTALL) for match in jinja_pattern.finditer(template_content): expression = match.group() lines = expression.split("\n") for i, line in enumerate(lines): # Check for # that's not in a string # Simple heuristic: if # appears after non-whitespace and not in quotes if "#" in line: # Remove quoted strings to avoid false positives cleaned = re.sub(r'"[^"]*"', "", line) cleaned = re.sub(r"'[^']*'", "", cleaned) if "#" in cleaned: # Check if it's likely a comment (has text after it) hash_pos = cleaned.index("#") if hash_pos > 0 and cleaned[hash_pos - 1 : hash_pos] != "\\": line_num = template_content[: match.start()].count("\n") + i + 1 errors.append( f"{template_path}:{line_num}: Inline comment (#) found in Jinja2 expression. " f"Move comments outside the expression." ) return errors def check_undefined_variables(template_path: Path) -> list[str]: """ Parse template and extract all undefined variables. This helps identify what variables need to be provided. """ errors = [] try: with open(template_path) as f: template_content = f.read() env = Environment(undefined=StrictUndefined) ast = env.parse(template_content) undefined_vars = meta.find_undeclared_variables(ast) # Common Ansible variables that are always available ansible_builtins = { "ansible_default_ipv4", "ansible_default_ipv6", "ansible_hostname", "ansible_distribution", "ansible_distribution_version", "ansible_facts", "inventory_hostname", "hostvars", "groups", "group_names", "play_hosts", "ansible_version", "ansible_user", "ansible_host", "item", "ansible_loop", "ansible_index", "lookup", } # Filter out known Ansible variables unknown_vars = undefined_vars - ansible_builtins # Only report if there are truly unknown variables if unknown_vars and len(unknown_vars) < 20: # Avoid noise from templates with many vars errors.append(f"{template_path}: Uses undefined variables: {', '.join(sorted(unknown_vars))}") except Exception: # Don't report parse errors here, they're handled elsewhere pass return errors def validate_template_syntax(template_path: Path) -> tuple[bool, list[str]]: """ Validate a single template for syntax errors. Returns (is_valid, list_of_errors) """ errors = [] # Skip full parsing for templates that use Ansible-specific features heavily # We still check for inline comments but skip full template parsing ansible_specific_templates = { "dnscrypt-proxy.toml.j2", # Uses |bool filter "mobileconfig.j2", # Uses |to_uuid filter and complex item structures "vpn-dict.j2", # Uses |to_uuid filter } if template_path.name in ansible_specific_templates: # Still check for inline comments but skip full parsing try: with open(template_path) as f: template_content = f.read() errors.extend(check_inline_comments_in_expressions(template_content, template_path)) except Exception: pass return len(errors) == 0, errors try: with open(template_path) as f: template_content = f.read() # Check for inline comments first (our custom check) errors.extend(check_inline_comments_in_expressions(template_content, template_path)) # Try to parse the template env = Environment(loader=FileSystemLoader(template_path.parent), undefined=StrictUndefined) # Add mock Ansible filters to avoid syntax errors env.filters["bool"] = lambda x: x env.filters["to_uuid"] = lambda x: x env.filters["b64encode"] = lambda x: x env.filters["b64decode"] = lambda x: x env.filters["regex_replace"] = lambda x, y, z: x env.filters["default"] = lambda x, d: x if x else d # This will raise TemplateSyntaxError if there's a syntax problem env.get_template(template_path.name) # Also check for undefined variables (informational) # Commenting out for now as it's too noisy, but useful for debugging # errors.extend(check_undefined_variables(template_path)) except TemplateSyntaxError as e: errors.append(f"{template_path}:{e.lineno}: Syntax error: {e.message}") except UnicodeDecodeError: errors.append(f"{template_path}: Unable to decode file (not UTF-8)") except Exception as e: errors.append(f"{template_path}: Error: {e!s}") return len(errors) == 0, errors def check_common_antipatterns(template_path: Path) -> list[str]: """Check for common Jinja2 anti-patterns.""" warnings = [] try: with open(template_path) as f: content = f.read() # Check for missing spaces around filters if re.search(r"\{\{[^}]+\|[^ ]", content): warnings.append(f"{template_path}: Missing space after filter pipe (|)") # Check for deprecated 'when' in Jinja2 (should use if) if re.search(r"\{%\s*when\s+", content): warnings.append(f"{template_path}: Use 'if' instead of 'when' in Jinja2 templates") # Check for extremely long expressions (harder to debug) for match in re.finditer(r"\{\{(.+?)\}\}", content, re.DOTALL): if len(match.group(1)) > 200: line_num = content[: match.start()].count("\n") + 1 warnings.append( f"{template_path}:{line_num}: Very long expression (>200 chars), consider breaking it up" ) except Exception: pass # Ignore errors in anti-pattern checking return warnings def main(): """Main validation function.""" print("🔍 Validating Jinja2 templates in Algo...\n") # Find all templates templates = find_jinja2_templates() print(f"Found {len(templates)} Jinja2 templates\n") all_errors = [] all_warnings = [] valid_count = 0 # Validate each template for template in templates: is_valid, errors = validate_template_syntax(template) warnings = check_common_antipatterns(template) if is_valid: valid_count += 1 else: all_errors.extend(errors) all_warnings.extend(warnings) # Report results print(f"✅ {valid_count}/{len(templates)} templates have valid syntax") if all_errors: print(f"\n❌ Found {len(all_errors)} errors:\n") for error in all_errors: print(f" ERROR: {error}") if all_warnings: print(f"\n⚠️ Found {len(all_warnings)} warnings:\n") for warning in all_warnings: print(f" WARN: {warning}") if all_errors: print("\n❌ Template validation FAILED") return 1 else: print("\n✅ All templates validated successfully!") return 0 if __name__ == "__main__": sys.exit(main()) ================================================ FILE: users.yml ================================================ --- - name: Manage VPN Users hosts: localhost gather_facts: false tags: always vars_files: - config.cfg tasks: - when: server is undefined 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 - 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 when: algo_server == 'localhost' or algo_provider | default('') == 'local' 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 - name: Test SSH connectivity to server wait_for: host: "{{ algo_server }}" port: "{{ ansible_ssh_port | default(ssh_port) | int }}" timeout: 10 register: ssh_check failed_when: false 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 | bool 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: "{% if algo_server == 'localhost' %}{{ ansible_playbook_python }}{% else %}/usr/bin/python3{% endif %}" 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 | bool - import_role: name: strongswan when: ipsec_enabled | bool tags: ipsec - import_role: name: ssh_tunneling when: algo_ssh_tunneling | bool - 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