Compare commits
15
Commits
cd65d6aea1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36d2845a3a | ||
|
|
0edc2c531f | ||
|
|
99ada6fab7 | ||
|
|
299397f4f9 | ||
|
|
acb5c4ba82 | ||
|
|
746e37f077 | ||
|
|
6c86e1bf08 | ||
|
|
86c47eec4f | ||
|
|
853e852753 | ||
|
|
76c82f83c1 | ||
|
|
c23ff11194 | ||
|
|
82d44662b4 | ||
|
|
22394db088 | ||
|
|
3f4899c73a | ||
|
|
4403bc0f4e |
@@ -1,2 +1,4 @@
|
||||
exclude_paths:
|
||||
- .gitea/
|
||||
skip_list:
|
||||
- partial-become
|
||||
|
||||
@@ -20,7 +20,11 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run ansible-lint
|
||||
run: ansible-lint
|
||||
env:
|
||||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||
run: |
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
ansible-lint
|
||||
|
||||
|
||||
syntax-check:
|
||||
@@ -38,11 +42,16 @@ jobs:
|
||||
env:
|
||||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||
run: |
|
||||
ansible-playbook --syntax-check playbooks/openvpn.yml
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
ansible-inventory --list > /dev/null
|
||||
for playbook in playbooks/*.yml; do
|
||||
echo "Syntax checking ${playbook}"
|
||||
ansible-playbook --syntax-check "$playbook"
|
||||
done
|
||||
|
||||
|
||||
deploy-prod:
|
||||
name: Deploy OpenVPN
|
||||
name: Deploy VPN Networking and OpenVPN
|
||||
runs-on: hetzner-ubuntu-latest
|
||||
|
||||
needs:
|
||||
@@ -69,7 +78,11 @@ jobs:
|
||||
env:
|
||||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||
run: |
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||
ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||
ansible-playbook playbooks/openvpn.yml
|
||||
ansible-playbook playbooks/monitoring-exporter.yml
|
||||
|
||||
|
||||
sbom:
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
name: OpenVPN JWT Identity Preparation
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
vpn_host:
|
||||
description: Inventory hostname of the VPN server to prepare
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
prepare-identity:
|
||||
name: Prepare VPN JWT identity
|
||||
runs-on: hetzner-ubuntu-latest
|
||||
|
||||
container:
|
||||
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup SSH
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
run: |
|
||||
set -eu
|
||||
mkdir -p ~/.ssh
|
||||
printf '%s\n' "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keygen -y -f ~/.ssh/id_ed25519 > /dev/null
|
||||
|
||||
- name: Install Ansible collections
|
||||
run: ansible-galaxy collection install -r requirements.yml
|
||||
|
||||
- name: Validate selected VPN host
|
||||
env:
|
||||
VPN_HOST: ${{ github.event.inputs.vpn_host }}
|
||||
run: |
|
||||
set -eu
|
||||
ansible-inventory -i inventories/prod/hosts.ini --list | python3 -c '
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
inventory = json.load(sys.stdin)
|
||||
selected_host = os.environ["VPN_HOST"]
|
||||
vpn_hosts = inventory.get("vpn_nodes", {}).get("hosts", [])
|
||||
if selected_host not in vpn_hosts:
|
||||
print("vpn_host must exactly match a host in the vpn_nodes inventory group", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
'
|
||||
|
||||
- name: Prepare JWT identity
|
||||
env:
|
||||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||
VPN_HOST: ${{ github.event.inputs.vpn_host }}
|
||||
run: |
|
||||
set -eu
|
||||
ansible-playbook \
|
||||
-i inventories/prod/hosts.ini \
|
||||
playbooks/openvpn-pki-identity.yml \
|
||||
--limit "$VPN_HOST"
|
||||
|
||||
- name: Upload public JWT key
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: openvpn-pki-public-keys
|
||||
path: artifacts/openvpn-pki-public-keys/*.pem
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
@@ -0,0 +1 @@
|
||||
/artifacts/openvpn-pki-public-keys/
|
||||
+98
-86
@@ -15,98 +15,110 @@ include:
|
||||
ansible-lint:
|
||||
stage: validate
|
||||
script:
|
||||
- export ANSIBLE_CONFIG=$CI_PROJECT_DIR/ansible.cfg
|
||||
- ansible-galaxy collection install -r requirements.yml
|
||||
- ansible-lint
|
||||
|
||||
syntax-check:
|
||||
stage: validate
|
||||
script:
|
||||
- export ANSIBLE_CONFIG=$CI_PROJECT_DIR/ansible.cfg
|
||||
- ansible-playbook --syntax-check playbooks/openvpn.yml
|
||||
|
||||
deploy-prod:
|
||||
extends: .openbao-with-secrets
|
||||
stage: deploy
|
||||
|
||||
id_tokens:
|
||||
OPENBAO_ID_TOKEN:
|
||||
aud: "https://openbao.helmholz.local:8200"
|
||||
|
||||
variables:
|
||||
OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||
script:
|
||||
- ansible-galaxy collection install -r requirements.yml
|
||||
- ansible-inventory --list > /dev/null
|
||||
- |
|
||||
set -eu
|
||||
|
||||
echo "Setting up SSH..."
|
||||
mkdir -p ~/.ssh
|
||||
|
||||
printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||
ansible-playbook playbooks/openvpn.yml
|
||||
when: manual
|
||||
|
||||
sbom:
|
||||
extends: .openbao-with-secrets
|
||||
stage: security
|
||||
|
||||
id_tokens:
|
||||
OPENBAO_ID_TOKEN:
|
||||
aud: "https://openbao.helmholz.local:8200"
|
||||
|
||||
variables:
|
||||
OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||
needs:
|
||||
- deploy-prod
|
||||
script:
|
||||
- |
|
||||
set -eu
|
||||
|
||||
echo "Setting up SSH..."
|
||||
mkdir -p ~/.ssh
|
||||
|
||||
printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||
ansible-playbook playbooks/sbom.yml
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- reports/sbom/
|
||||
expire_in: 365 days
|
||||
|
||||
trivy:sbom:
|
||||
stage: security
|
||||
needs:
|
||||
- job: sbom
|
||||
artifacts: true
|
||||
script:
|
||||
- ls -R reports || true
|
||||
- mkdir -p reports/trivy
|
||||
- |
|
||||
if compgen -G "reports/sbom/*.json" > /dev/null; then
|
||||
for sbom in reports/sbom/*.json; do
|
||||
filename=$(basename "$sbom" .json)
|
||||
|
||||
echo "Scanning $sbom"
|
||||
|
||||
trivy sbom \
|
||||
--format json \
|
||||
--output "reports/trivy/${filename}-trivy.json" \
|
||||
--exit-code 0 \
|
||||
"$sbom"
|
||||
trivy sbom \
|
||||
--format table \
|
||||
--output "reports/trivy/${filename}-trivy.txt" \
|
||||
--exit-code 0 \
|
||||
"$sbom"
|
||||
for playbook in playbooks/*.yml; do
|
||||
echo "Syntax checking ${playbook}"
|
||||
ansible-playbook --syntax-check "$playbook"
|
||||
done
|
||||
else
|
||||
echo "No SBOM files found."
|
||||
exit 1
|
||||
fi
|
||||
artifacts:
|
||||
when: always
|
||||
expire_in: 365 days
|
||||
paths:
|
||||
- reports/trivy/
|
||||
|
||||
# deploy-prod:
|
||||
# extends: .openbao-with-secrets
|
||||
# stage: deploy
|
||||
|
||||
# id_tokens:
|
||||
# OPENBAO_ID_TOKEN:
|
||||
# aud: "https://openbao.helmholz.local:8200"
|
||||
|
||||
# variables:
|
||||
# OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||
# script:
|
||||
# - |
|
||||
# set -eu
|
||||
|
||||
# echo "Setting up SSH..."
|
||||
# mkdir -p ~/.ssh
|
||||
|
||||
# printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
# chmod 600 ~/.ssh/id_ed25519
|
||||
# export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||
# ansible-galaxy collection install -r requirements.yml
|
||||
# ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||
# ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||
# ansible-playbook playbooks/openvpn.yml
|
||||
# when: manual
|
||||
|
||||
# sbom:
|
||||
# extends: .openbao-with-secrets
|
||||
# stage: security
|
||||
|
||||
# id_tokens:
|
||||
# OPENBAO_ID_TOKEN:
|
||||
# aud: "https://openbao.helmholz.local:8200"
|
||||
|
||||
# variables:
|
||||
# OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||
# needs:
|
||||
# - deploy-prod
|
||||
# script:
|
||||
# - |
|
||||
# set -eu
|
||||
|
||||
# echo "Setting up SSH..."
|
||||
# mkdir -p ~/.ssh
|
||||
|
||||
# printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
# chmod 600 ~/.ssh/id_ed25519
|
||||
# export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||
# ansible-playbook playbooks/sbom.yml
|
||||
# artifacts:
|
||||
# when: always
|
||||
# paths:
|
||||
# - reports/sbom/
|
||||
# expire_in: 365 days
|
||||
|
||||
# trivy:sbom:
|
||||
# stage: security
|
||||
# needs:
|
||||
# - job: sbom
|
||||
# artifacts: true
|
||||
# script:
|
||||
# - ls -R reports || true
|
||||
# - mkdir -p reports/trivy
|
||||
# - |
|
||||
# if compgen -G "reports/sbom/*.json" > /dev/null; then
|
||||
# for sbom in reports/sbom/*.json; do
|
||||
# filename=$(basename "$sbom" .json)
|
||||
|
||||
# echo "Scanning $sbom"
|
||||
|
||||
# trivy sbom \
|
||||
# --format json \
|
||||
# --output "reports/trivy/${filename}-trivy.json" \
|
||||
# --exit-code 0 \
|
||||
# "$sbom"
|
||||
# trivy sbom \
|
||||
# --format table \
|
||||
# --output "reports/trivy/${filename}-trivy.txt" \
|
||||
# --exit-code 0 \
|
||||
# "$sbom"
|
||||
# done
|
||||
# else
|
||||
# echo "No SBOM files found."
|
||||
# exit 1
|
||||
# fi
|
||||
# artifacts:
|
||||
# when: always
|
||||
# expire_in: 365 days
|
||||
# paths:
|
||||
# - reports/trivy/
|
||||
|
||||
@@ -24,3 +24,86 @@ ansible-playbook playbooks/openvpn.yml
|
||||
```
|
||||
|
||||
The target hosts must run Ubuntu 24.04 and Ansible must gather facts.
|
||||
|
||||
## Private VM internet access
|
||||
|
||||
The `vpn-gateway` VM provides NAT for private VPN nodes. A private VM sends
|
||||
internet-bound traffic to the Hetzner private-network router (`10.0.0.1`). The
|
||||
Hetzner network route for `0.0.0.0/0` then delivers it to the gateway's private
|
||||
address (`10.100.0.4`), where iptables masquerades it out `eth0`. The route in
|
||||
Hetzner's network and the operating-system default route on each private VM are
|
||||
separate settings: both must exist. The gateway itself keeps its public default
|
||||
route through `eth0`.
|
||||
|
||||
`vpn_nodes` contains private VPN nodes and `nat_gateways` contains only the
|
||||
gateway. Add new private VMs to `vpn_nodes` with their management address and
|
||||
private address, and set the private routing role variables in host/group vars
|
||||
if their interface or gateway differs. Do not add a gateway to `vpn_nodes`.
|
||||
The routing role detects Netplan or systemd-networkd and adds only a route
|
||||
fragment; review the host's existing route metrics and manager before rollout.
|
||||
The Netplan fragment adds a metric 100 default route. Internal destinations
|
||||
continue to use more-specific routes; validate the FreeRADIUS NodePort path on
|
||||
each host.
|
||||
|
||||
Install required collections with `ansible-galaxy collection install -r
|
||||
requirements.yml`, then check syntax and deploy independently:
|
||||
|
||||
```sh
|
||||
ansible-playbook --syntax-check playbooks/nat-gateway.yml
|
||||
ansible-playbook --syntax-check playbooks/private-vpn-routing.yml
|
||||
ansible-playbook --check playbooks/nat-gateway.yml --limit nat_gateways
|
||||
ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||
ansible-playbook --check playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||
ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||
```
|
||||
|
||||
Check mode cannot validate actual kernel routes or persistence and may report
|
||||
handlers without applying them. `netplan apply` and restarting
|
||||
systemd-networkd can briefly interrupt remote connectivity; schedule route
|
||||
rollout with console access or a maintenance window. Do not reboot automatically.
|
||||
|
||||
Verify the gateway after deployment (and separately after a planned reboot):
|
||||
|
||||
```sh
|
||||
sysctl net.ipv4.ip_forward
|
||||
iptables -t nat -S POSTROUTING
|
||||
iptables -S FORWARD
|
||||
systemctl is-enabled nat-gateway-firewall.service
|
||||
systemctl status nat-gateway-firewall.service --no-pager
|
||||
ip -4 route show default
|
||||
```
|
||||
|
||||
Expect forwarding value `1`, the subnet-specific MASQUERADE and two narrow
|
||||
FORWARD rules, an enabled firewall persistence service, and the gateway public
|
||||
default via `eth0`. The service re-adds only these scoped rules at boot and
|
||||
does not save or flush the full firewall ruleset. On each private VM:
|
||||
|
||||
```sh
|
||||
ip -4 route show default
|
||||
ip -4 route get 8.8.8.8
|
||||
getent hosts google.com
|
||||
curl -I --max-time 10 https://google.com
|
||||
```
|
||||
|
||||
Also connect to the existing FreeRADIUS NodePort endpoint using its configured
|
||||
address and port. DNS and NodePort checks require live network access. The
|
||||
inventory gateway IP/interface values are taken from the supplied task; verify
|
||||
them against the live Hetzner VM before applying.
|
||||
|
||||
## Monitoring exporter
|
||||
|
||||
Run `playbooks/monitoring-exporter.yml` for the VPN nodes and NAT gateway.
|
||||
Set `monitoring_vm_ip` in `inventories/prod/group_vars/all.yml` to the monitoring
|
||||
VM's address on the `10.100.0.x` private network. It is the only allowed source
|
||||
to TCP port 9100. The identical `node_exporter` role defaults to port 9100,
|
||||
binds to `private_ip` then `keepalived_src_ip` then `ansible_host`, and uses
|
||||
`monitoring_vm_ip` as its firewall source. It creates the root-owned,
|
||||
world-readable `/var/lib/node_exporter/textfile` directory and enables
|
||||
systemd, conntrack, filesystem, netdev, textfile, time, and timex collectors;
|
||||
`node_exporter_systemd_unit_filter` restricts unit metrics.
|
||||
|
||||
On the NAT gateway, `nat_gateway_node_exporter_port` defaults to 9100 and
|
||||
`nat_gateway_node_exporter_allowed_source` uses `monitoring_vm_ip`. Both the
|
||||
ACCEPT for that source and DROP for all other sources on the port are written
|
||||
into `ensure-nat-gateway-firewall.j2`, so the gateway firewall persistence
|
||||
service owns them.
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
timezone: Europe/Berlin
|
||||
# Required: monitoring VM private address on the 10.100.0.x private network.
|
||||
monitoring_vm_ip: "10.100.0.30"
|
||||
common_packages:
|
||||
- vim
|
||||
- curl
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
[vpn_nodes]
|
||||
vpn01 ansible_host=65.108.95.144 private_ip=10.100.0.1
|
||||
# vpn01 ansible_host=65.108.95.144 private_ip=10.100.0.1
|
||||
vpn01-test ansible_host=10.100.0.2 private_ip=10.100.0.2
|
||||
vpn02-test ansible_host=10.100.0.5 private_ip=10.100.0.5
|
||||
# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3
|
||||
|
||||
[nat_gateways]
|
||||
vpn-gateway ansible_host=178.104.249.28 private_ip=10.100.0.4
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: Configure node exporter on VPN nodes
|
||||
hosts: vpn_nodes
|
||||
become: true
|
||||
roles:
|
||||
- role: node_exporter
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Configure node exporter and firewall on NAT gateway
|
||||
hosts: nat_gateways
|
||||
become: true
|
||||
roles:
|
||||
- role: nat_gateway
|
||||
- role: node_exporter
|
||||
vars:
|
||||
node_exporter_manage_firewall: false
|
||||
tags: [monitoring]
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Configure NAT gateway
|
||||
hosts: nat_gateways
|
||||
become: true
|
||||
roles: [nat_gateway]
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Prepare OpenVPN JWT identities
|
||||
hosts: vpn_nodes
|
||||
become: true
|
||||
|
||||
roles:
|
||||
- role: openvpn_pki
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Configure private VPN node default routes
|
||||
hosts: vpn_nodes
|
||||
become: true
|
||||
roles: [private_routing]
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
collections:
|
||||
- name: ansible.posix
|
||||
- name: community.general
|
||||
- name: community.crypto
|
||||
@@ -14,6 +14,8 @@
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
update_cache_retries: 5
|
||||
update_cache_retry_max_delay: 12
|
||||
|
||||
- name: Upgrade packages
|
||||
ansible.builtin.apt:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
nat_gateway_private_cidr: 10.100.0.0/16
|
||||
nat_gateway_private_interface: enp7s0
|
||||
nat_gateway_public_interface: eth0
|
||||
nat_gateway_firewall_script: /usr/local/sbin/ensure-nat-gateway-firewall
|
||||
# Exporter firewall accepts this private source and drops all others on its port.
|
||||
nat_gateway_node_exporter_port: 9100
|
||||
nat_gateway_node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Apply NAT gateway sysctl
|
||||
ansible.builtin.command: sysctl --system
|
||||
changed_when: false
|
||||
- name: Restart NAT gateway firewall persistence
|
||||
ansible.builtin.systemd:
|
||||
name: nat-gateway-firewall.service
|
||||
enabled: true
|
||||
daemon_reload: true
|
||||
state: restarted
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
- name: Install iptables tools
|
||||
ansible.builtin.apt:
|
||||
name: [iptables, prometheus-node-exporter]
|
||||
state: present
|
||||
|
||||
- name: Install idempotent NAT firewall restore script
|
||||
ansible.builtin.template:
|
||||
src: ensure-nat-gateway-firewall.j2
|
||||
dest: "{{ nat_gateway_firewall_script }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0750"
|
||||
notify: Restart NAT gateway firewall persistence
|
||||
|
||||
- name: Install NAT firewall persistence unit
|
||||
ansible.builtin.template:
|
||||
src: nat-gateway-firewall.service.j2
|
||||
dest: /etc/systemd/system/nat-gateway-firewall.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Restart NAT gateway firewall persistence
|
||||
|
||||
- name: Enable NAT firewall persistence at boot
|
||||
ansible.builtin.systemd:
|
||||
name: nat-gateway-firewall.service
|
||||
enabled: true
|
||||
daemon_reload: true
|
||||
state: started
|
||||
|
||||
- name: Configure persistent IPv4 forwarding
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/sysctl.d/99-nat-gateway.conf
|
||||
content: "net.ipv4.ip_forward=1\n"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Apply NAT gateway sysctl
|
||||
|
||||
- name: Enable IPv4 forwarding immediately
|
||||
ansible.posix.sysctl:
|
||||
name: net.ipv4.ip_forward
|
||||
value: "1"
|
||||
sysctl_file: /etc/sysctl.d/99-nat-gateway.conf
|
||||
reload: true
|
||||
|
||||
- name: Create node exporter textfile directory
|
||||
ansible.builtin.file:
|
||||
path: /var/lib/node_exporter/textfile
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Allow private subnet outbound through public interface
|
||||
ansible.builtin.iptables:
|
||||
table: nat
|
||||
chain: POSTROUTING
|
||||
source: "{{ nat_gateway_private_cidr }}"
|
||||
out_interface: "{{ nat_gateway_public_interface }}"
|
||||
jump: MASQUERADE
|
||||
state: present
|
||||
notify: Restart NAT gateway firewall persistence
|
||||
|
||||
- name: Allow private subnet forwarding to public interface
|
||||
ansible.builtin.iptables:
|
||||
chain: FORWARD
|
||||
in_interface: "{{ nat_gateway_private_interface }}"
|
||||
out_interface: "{{ nat_gateway_public_interface }}"
|
||||
source: "{{ nat_gateway_private_cidr }}"
|
||||
jump: ACCEPT
|
||||
state: present
|
||||
notify: Restart NAT gateway firewall persistence
|
||||
|
||||
- name: Allow established return traffic to private subnet
|
||||
ansible.builtin.iptables:
|
||||
chain: FORWARD
|
||||
in_interface: "{{ nat_gateway_public_interface }}"
|
||||
out_interface: "{{ nat_gateway_private_interface }}"
|
||||
destination: "{{ nat_gateway_private_cidr }}"
|
||||
ctstate: [ESTABLISHED, RELATED]
|
||||
jump: ACCEPT
|
||||
state: present
|
||||
notify: Restart NAT gateway firewall persistence
|
||||
|
||||
- name: Assert gateway retains public default route
|
||||
ansible.builtin.command: ip -4 route show default
|
||||
register: nat_gateway_default_route
|
||||
changed_when: false
|
||||
failed_when: nat_gateway_public_interface not in nat_gateway_default_route.stdout
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
iptables -t nat -C POSTROUTING -s {{ nat_gateway_private_cidr }} -o {{ nat_gateway_public_interface }} -j MASQUERADE 2>/dev/null || \
|
||||
iptables -t nat -A POSTROUTING -s {{ nat_gateway_private_cidr }} -o {{ nat_gateway_public_interface }} -j MASQUERADE
|
||||
|
||||
iptables -C FORWARD -i {{ nat_gateway_private_interface }} -o {{ nat_gateway_public_interface }} -s {{ nat_gateway_private_cidr }} -j ACCEPT 2>/dev/null || \
|
||||
iptables -A FORWARD -i {{ nat_gateway_private_interface }} -o {{ nat_gateway_public_interface }} -s {{ nat_gateway_private_cidr }} -j ACCEPT
|
||||
|
||||
iptables -C FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null || \
|
||||
iptables -A FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
iptables -C INPUT -p tcp -s {{ nat_gateway_node_exporter_allowed_source }} --dport {{ nat_gateway_node_exporter_port }} -j ACCEPT 2>/dev/null || \
|
||||
iptables -I INPUT 1 -p tcp -s {{ nat_gateway_node_exporter_allowed_source }} --dport {{ nat_gateway_node_exporter_port }} -j ACCEPT
|
||||
|
||||
iptables -C INPUT -p tcp --dport {{ nat_gateway_node_exporter_port }} -j DROP 2>/dev/null || \
|
||||
iptables -I INPUT 2 -p tcp --dport {{ nat_gateway_node_exporter_port }} -j DROP
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Ensure scoped NAT gateway firewall rules are present
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart={{ nat_gateway_firewall_script }}
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# Bind to private_ip, then the LB keepalived source IP, and use public ansible_host
|
||||
# only if neither private address is configured.
|
||||
node_exporter_listen_address: "{{ private_ip | default(keepalived_src_ip | default(ansible_host)) }}"
|
||||
# TCP listener port for node_exporter.
|
||||
node_exporter_port: 9100
|
||||
# Required: set to monitoring_vm_ip in inventory/group_vars.
|
||||
node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||
# Root-owned, world-readable textfile collector directory.
|
||||
node_exporter_textfile_dir: /var/lib/node_exporter/textfile
|
||||
# Restrict systemd collector output to relevant service units.
|
||||
node_exporter_systemd_unit_filter: "^(openvpn.*|squid@.*|keepalived.service|nat-gateway-firewall.service)$"
|
||||
# Collect systemd, connection tracking, filesystem, network, textfile, time, and timex metrics.
|
||||
node_exporter_collectors:
|
||||
- systemd
|
||||
- conntrack
|
||||
- filesystem
|
||||
- netdev
|
||||
- textfile
|
||||
- time
|
||||
- timex
|
||||
# Use iptables allow/drop rules locally; NAT gateway disables this because its
|
||||
# firewall script owns those rules.
|
||||
node_exporter_manage_firewall: true
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Restart node exporter
|
||||
ansible.builtin.systemd:
|
||||
name: prometheus-node-exporter
|
||||
state: restarted
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
- name: Require the monitoring VM private source address
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- monitoring_vm_ip is defined
|
||||
- monitoring_vm_ip | length > 0
|
||||
fail_msg: Set monitoring_vm_ip to the monitoring VM's 10.100.0.x address.
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Install node exporter package
|
||||
ansible.builtin.apt:
|
||||
name: prometheus-node-exporter
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Install iptables persistence packages
|
||||
ansible.builtin.apt:
|
||||
name: [iptables, iptables-persistent]
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Create node exporter textfile directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ node_exporter_textfile_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Configure node exporter arguments
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/default/prometheus-node-exporter
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
content: >-
|
||||
ARGS="--web.listen-address={{ node_exporter_listen_address }}:{{ node_exporter_port }}
|
||||
{% for collector in node_exporter_collectors %}--collector.{{ collector }} {% endfor %}
|
||||
--collector.systemd.unit-include={{ node_exporter_systemd_unit_filter }}
|
||||
--collector.textfile.directory={{ node_exporter_textfile_dir }}"
|
||||
notify: Restart node exporter
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Allow monitoring VM to access node exporter
|
||||
ansible.builtin.iptables:
|
||||
chain: INPUT
|
||||
protocol: tcp
|
||||
destination_port: "{{ node_exporter_port }}"
|
||||
source: "{{ node_exporter_allowed_source }}"
|
||||
jump: ACCEPT
|
||||
comment: Allow monitoring VM node exporter
|
||||
action: insert
|
||||
rule_num: 1
|
||||
register: node_exporter_allow_rule
|
||||
tags: [monitoring]
|
||||
when: node_exporter_manage_firewall
|
||||
|
||||
- name: Drop other node exporter access
|
||||
ansible.builtin.iptables:
|
||||
chain: INPUT
|
||||
protocol: tcp
|
||||
destination_port: "{{ node_exporter_port }}"
|
||||
jump: DROP
|
||||
comment: Drop other node exporter access
|
||||
action: insert
|
||||
rule_num: 2
|
||||
register: node_exporter_drop_rule
|
||||
tags: [monitoring]
|
||||
when: node_exporter_manage_firewall
|
||||
|
||||
- name: Persist node exporter firewall rules
|
||||
ansible.builtin.command: netfilter-persistent save
|
||||
when:
|
||||
- node_exporter_manage_firewall
|
||||
- node_exporter_allow_rule is changed or node_exporter_drop_rule is changed
|
||||
changed_when: true
|
||||
tags: [monitoring]
|
||||
|
||||
- name: Enable and start node exporter
|
||||
ansible.builtin.systemd:
|
||||
name: prometheus-node-exporter
|
||||
state: started
|
||||
enabled: true
|
||||
tags: [monitoring]
|
||||
@@ -1,25 +1,30 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEIzCCAwugAwIBAgIIXQADw2Y0rCkwDQYJKoZIhvcNAQELBQAwdDELMAkGA1UE
|
||||
MIIFHTCCBAWgAwIBAgIIQ5gRV6nKlhwwDQYJKoZIhvcNAQELBQAwdDELMAkGA1UE
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9KGUhmscFr4SMG+lUr9dJRiO2SExfjXbbl
|
||||
cSfL92cad72mPyaSdayTgEaE/VA6RNBy4XVGuKx8zaeJ5cZmLQhHYvhogEKXfta3
|
||||
iEpzAoIBAQCD2b1Zqe/J72U/03u4OjXKG3BsLimXn8VNirXzjwv4JYb/bb3NRufa
|
||||
QfXbeC+LfYAJp1Cb0b7SZyBcLEyLmWYu4Yrc6v2KthFKnxSqf7ycfjmL2sFhKC8A
|
||||
eNESwb21YfE8cDRJcxWMLaB0RT3h0BFSrJm9kQrXGYfzVuzqZzYuJsHWEklrKqyM
|
||||
EiEpcjnVHYKtirndZKQG02GVlj+O0hbzTTI6W1ZIllVBUeKU93qstLQOm4AxHgs3
|
||||
FAEi9b1uMxpUKM3GP9NPlzyOiC68cdunFBz0mqDgXgvtO0QB1Z6ClWl8vrXLFkJ6
|
||||
ceN81JI+TRgN5QC8mr1+asuMdTQqfyzxAoIBAGueFquOes04tOWzKOnwI/jKMsUM
|
||||
tbC5sTFEb/Prub4OFWPU+AIGHmcTICF8ez7iiZFkPcJFQ4xqcWl41e3YBQaYTRCz
|
||||
2RUwyk3CLLcSdLIH6u6CeND+XVtI3RrKPuy/64N4pMEbIgeM/UMJc9xyNWyQCMmQ
|
||||
gl8bseanfRM1zLUkyCvE6QFLjsjFJkQUHzEM4qTUKqIxLx/Y5tED6LhkqS39sbEO
|
||||
4i/+d+Atz5uRtA3ziCXkokbfE8VYFOivAgqiGzVR60MR0Ptctnf7esM/KNefHS9f
|
||||
kAC98L5t3Qvf73hSFVJfZB8a7GSbobsfAo//YHVEm0Gm5SS/9N4THfafMJI=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
-----BEGIN OpenVPN Static key V1-----
|
||||
50233c0e81ad6e32db57614c6475e318
|
||||
3b89cc7d5955d14d86ecb94574f2c813
|
||||
0de8f6ee461eedd7c7c8dc412f3ef5da
|
||||
08fbff0d8216b05c9c8b288ba05b4262
|
||||
3b6869c97763ccb5c871edf274ce2631
|
||||
eaf92c23c2eb200d5296cdb7194ea366
|
||||
21556274bc5b26e584c6e44b28d2d0e7
|
||||
bb1b31b5a3ea115ec87f519a70543746
|
||||
1e26900f527c3e6e2a2c8b4ae34127e1
|
||||
7f85b059a7d88198b9b6a659958db81e
|
||||
238b1257805a97509d47b53b697721d0
|
||||
a54044df487f4441a95e41e39118fda5
|
||||
3040f9a3ea581f4b43875b36b17a4566
|
||||
5f968e0d3262a0eb1b56c03acac7cf40
|
||||
f5d8111f55b51aa00926948f282af910
|
||||
51c00fd604de92af7612823a560a6c2c
|
||||
-----END OpenVPN Static key V1-----
|
||||
@@ -22,6 +22,7 @@
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Restart openvpn
|
||||
|
||||
- name: Deploy server private key
|
||||
ansible.builtin.copy:
|
||||
@@ -30,3 +31,13 @@
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
notify: Restart openvpn
|
||||
|
||||
- name: Deploy tls-crypt key
|
||||
ansible.builtin.copy:
|
||||
src: certs/tls-crypt.key
|
||||
dest: "{{ openvpn_cert_dir }}/tls-crypt.key"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
notify: Restart openvpn
|
||||
|
||||
@@ -28,6 +28,7 @@ client-connect /etc/openvpn/scripts/client-connect.sh
|
||||
ca {{ openvpn_cert_dir }}/ca.crt
|
||||
cert {{ openvpn_cert_dir }}/server.crt
|
||||
key {{ openvpn_cert_dir }}/server.key
|
||||
tls-crypt {{ openvpn_cert_dir }}/tls-crypt.key
|
||||
|
||||
dh none
|
||||
ecdh-curve prime256v1
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# OpenVPN PKI JWT identity preparation
|
||||
|
||||
This role prepares one local JWT RSA identity per VPN server so an administrator
|
||||
can register each public key with the existing OpenBao JWT configuration. It
|
||||
does not configure OpenBao or request certificates.
|
||||
|
||||
## Prepare an identity
|
||||
|
||||
Run the dedicated playbook, limiting it to the new VPN server when appropriate:
|
||||
|
||||
```bash
|
||||
ansible-playbook \
|
||||
-i inventories/prod/hosts.ini \
|
||||
playbooks/openvpn-pki-identity.yml \
|
||||
--limit vpn01-test
|
||||
```
|
||||
|
||||
The playbook targets `vpn_nodes` and uses privilege escalation. It creates the
|
||||
identity on the selected server; it does not deploy certificates or alter the
|
||||
OpenVPN service.
|
||||
|
||||
## Key locations and retrieval
|
||||
|
||||
The server stores its root-owned identity in `/etc/vault-jwt/` by default:
|
||||
|
||||
- `private.pem`: RSA 3072-bit private key, mode `0600`.
|
||||
- `public.pem`: corresponding PEM public key, mode `0644`.
|
||||
|
||||
Only `public.pem` is fetched to the controller, as
|
||||
`artifacts/openvpn-pki-public-keys/<inventory_hostname>.pem`. The artifacts
|
||||
directory is ignored by Git. The private key is generated on the VPN server
|
||||
with `community.crypto.openssl_privatekey`; it is never fetched.
|
||||
|
||||
## Register the public key in OpenBao
|
||||
|
||||
Provide the fetched PEM public key to the OpenBao administrator using the
|
||||
approved secure process. The administrator should combine the new PEM public
|
||||
key with all currently registered PEM public keys into a bundle, then update
|
||||
the existing JWT authentication configuration with that complete bundle. The
|
||||
update must preserve every previously registered key; replacing the configured
|
||||
key set with only the new key would invalidate identities already in use.
|
||||
Public-key registration is a manual administrator operation and is not
|
||||
performed by this role.
|
||||
|
||||
## Existing identity behavior
|
||||
|
||||
The role creates a missing identity only when both key files are absent. If
|
||||
both already exist, it leaves them unchanged and fetches the existing public
|
||||
key again. If exactly one key file exists, the role fails rather than
|
||||
replacing or silently repairing the identity. Investigate and recover the
|
||||
matching pair deliberately before rerunning. Do not delete or replace the
|
||||
private key as a routine way to resolve errors: OpenBao registrations depend
|
||||
on the corresponding public key.
|
||||
|
||||
The private key must remain on its VPN server because it is the credential
|
||||
used to prove that server's identity. Copying it to the controller or
|
||||
registering it with OpenBao would defeat the separation between private key
|
||||
custody and public-key registration.
|
||||
|
||||
## Requirements
|
||||
|
||||
Install the `community.crypto` collection on the Ansible controller. It is not
|
||||
currently listed in the repository's `requirements.yml`.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
openvpn_pki_jwt_directory: /etc/vault-jwt
|
||||
openvpn_pki_jwt_private_key_path: "{{ openvpn_pki_jwt_directory }}/private.pem"
|
||||
openvpn_pki_jwt_public_key_path: "{{ openvpn_pki_jwt_directory }}/public.pem"
|
||||
openvpn_pki_jwt_rsa_bits: 3072
|
||||
openvpn_pki_public_key_artifact_directory: "{{ playbook_dir }}/../artifacts/openvpn-pki-public-keys"
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
- name: Create JWT identity directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ openvpn_pki_jwt_directory }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0700"
|
||||
|
||||
- name: Check for existing JWT private key
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
register: openvpn_pki_jwt_private_key_stat
|
||||
|
||||
- name: Check for existing JWT public key
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
register: openvpn_pki_jwt_public_key_stat
|
||||
|
||||
- name: Refuse incomplete JWT identity
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- openvpn_pki_jwt_private_key_stat.stat.exists == openvpn_pki_jwt_public_key_stat.stat.exists
|
||||
fail_msg: >-
|
||||
Only one JWT key file exists. Refusing to replace or repair an existing
|
||||
identity automatically. Inspect the files and recover the matching key
|
||||
pair deliberately before rerunning this playbook.
|
||||
|
||||
- name: Generate JWT RSA private key
|
||||
community.crypto.openssl_privatekey:
|
||||
path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
type: RSA
|
||||
size: "{{ openvpn_pki_jwt_rsa_bits }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
when: not openvpn_pki_jwt_private_key_stat.stat.exists
|
||||
|
||||
- name: Generate JWT public key from existing private key
|
||||
community.crypto.openssl_publickey:
|
||||
path: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
privatekey_path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
format: PEM
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: not openvpn_pki_jwt_public_key_stat.stat.exists
|
||||
|
||||
- name: Create public key artifact directory on controller
|
||||
ansible.builtin.file:
|
||||
path: "{{ openvpn_pki_public_key_artifact_directory }}"
|
||||
state: directory
|
||||
mode: "0700"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
- name: Fetch JWT public key to controller
|
||||
ansible.builtin.fetch:
|
||||
src: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
dest: "{{ openvpn_pki_public_key_artifact_directory }}/{{ inventory_hostname }}.pem"
|
||||
flat: true
|
||||
validate_checksum: true
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- name: Import JWT identity preparation tasks
|
||||
ansible.builtin.import_tasks: identity.yml
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
private_routing_interface: enp7s0
|
||||
private_routing_gateway: 10.0.0.1
|
||||
private_routing_metric: 100
|
||||
private_routing_nameservers:
|
||||
- 1.1.1.1
|
||||
- 9.9.9.9
|
||||
@@ -0,0 +1,93 @@
|
||||
---
|
||||
- name: Find Netplan configuration files
|
||||
ansible.builtin.find:
|
||||
paths: /etc/netplan
|
||||
patterns: "*.yaml,*.yml"
|
||||
file_type: file
|
||||
register: private_routing_netplan_files
|
||||
failed_when: false
|
||||
|
||||
- name: Determine whether systemd-networkd manages the interface
|
||||
ansible.builtin.command: networkctl status "{{ private_routing_interface }}"
|
||||
register: private_routing_networkctl
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
when: private_routing_netplan_files.matched | default(0) == 0
|
||||
|
||||
- name: Refuse unknown network manager rather than overwrite network settings
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (private_routing_netplan_files.matched | default(0) > 0) or
|
||||
(private_routing_networkctl.rc | default(1) == 0)
|
||||
fail_msg: >-
|
||||
No Netplan configuration or active systemd-networkd interface found for
|
||||
{{ private_routing_interface }}; refusing to change network configuration.
|
||||
|
||||
# ---- Netplan path ----
|
||||
- name: Install Netplan route drop-in
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/netplan/99-private-vpn-default-route.yaml
|
||||
content: |
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
{{ private_routing_interface }}:
|
||||
routes:
|
||||
- to: default
|
||||
via: {{ private_routing_gateway }}
|
||||
metric: {{ private_routing_metric }}
|
||||
nameservers:
|
||||
addresses: {{ private_routing_nameservers | to_json }}
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
validate: python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" %s
|
||||
when: private_routing_netplan_files.matched | default(0) > 0
|
||||
|
||||
- name: Apply Netplan route configuration
|
||||
ansible.builtin.command: netplan apply
|
||||
changed_when: false
|
||||
when: private_routing_netplan_files.matched | default(0) > 0
|
||||
|
||||
# ---- systemd-networkd path ----
|
||||
- name: Install systemd-networkd route drop-in
|
||||
ansible.builtin.copy:
|
||||
dest: "/etc/systemd/network/90-{{ private_routing_interface }}-private-vpn-route.network"
|
||||
content: |
|
||||
[Match]
|
||||
Name={{ private_routing_interface }}
|
||||
|
||||
[Network]
|
||||
{% for ns in private_routing_nameservers %}
|
||||
DNS={{ ns }}
|
||||
{% endfor %}
|
||||
|
||||
[Route]
|
||||
Destination=0.0.0.0/0
|
||||
Gateway={{ private_routing_gateway }}
|
||||
Metric={{ private_routing_metric }}
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: private_routing_netplan_files.matched | default(0) == 0
|
||||
|
||||
- name: Apply systemd-networkd route configuration
|
||||
ansible.builtin.systemd:
|
||||
name: systemd-networkd
|
||||
state: restarted
|
||||
when: private_routing_netplan_files.matched | default(0) == 0
|
||||
|
||||
# ---- Verification (both paths) ----
|
||||
- name: Verify selected route to internet
|
||||
ansible.builtin.command: ip -4 route get 8.8.8.8
|
||||
register: private_routing_route_get
|
||||
changed_when: false
|
||||
failed_when: private_routing_gateway not in private_routing_route_get.stdout or private_routing_interface not in private_routing_route_get.stdout
|
||||
|
||||
- name: Verify DNS resolution through the gateway
|
||||
ansible.builtin.command: getent hosts archive.ubuntu.com
|
||||
register: private_routing_dns_check
|
||||
changed_when: false
|
||||
retries: 5
|
||||
delay: 3
|
||||
until: private_routing_dns_check.rc == 0
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
- name: Check if Syft is installed
|
||||
ansible.builtin.command: syft version
|
||||
register: syft_check
|
||||
register: sbom_syft_check
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
url: https://raw.githubusercontent.com/anchore/syft/main/install.sh
|
||||
dest: /tmp/install-syft.sh
|
||||
mode: "0755"
|
||||
when: syft_check.rc != 0
|
||||
when: sbom_syft_check.rc != 0
|
||||
|
||||
- name: Install Syft
|
||||
ansible.builtin.command:
|
||||
cmd: /tmp/install-syft.sh -b /usr/local/bin
|
||||
when: syft_check.rc != 0
|
||||
when: sbom_syft_check.rc != 0
|
||||
changed_when: true
|
||||
|
||||
- name: Create report directory
|
||||
|
||||
Reference in New Issue
Block a user