refactor(vpn): split JWT identity and OpenVPN certificate lifecycle
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 43s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m8s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 3m32s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 18s
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 43s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m8s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 3m32s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 18s
- Add a dedicated role and workflow to generate VPN JWT identities and export public keys - Run identity preparation automatically for VPN nodes awaiting OpenBao registration - Gate OpenVPN and PKI setup until each node is registered - Split PKI setup into runtime, configuration, service, and initial certificate tasks - Restore TAP and bridge attachment after OpenVPN restarts - Remove bundled server certificate and private key
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
name: OpenVPN JWT Identity Preparation
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- OpenVPN Ansible
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
prepare-identities:
|
||||
name: Prepare unregistered VPN identities
|
||||
runs-on: hetzner-ubuntu-latest
|
||||
if: >-
|
||||
github.event.workflow_run.conclusion == 'success' &&
|
||||
github.event.workflow_run.head_branch == 'main'
|
||||
|
||||
container:
|
||||
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.workflow_run.head_sha }}
|
||||
|
||||
- name: Find VPN nodes awaiting JWT registration
|
||||
id: pending
|
||||
run: |
|
||||
set -eu
|
||||
ansible-inventory -i inventories/prod/hosts.ini --list |
|
||||
python3 -c '
|
||||
import json
|
||||
import sys
|
||||
|
||||
inventory = json.load(sys.stdin)
|
||||
vpn_hosts = inventory.get("vpn_nodes", {}).get("hosts", [])
|
||||
hostvars = inventory.get("_meta", {}).get("hostvars", {})
|
||||
pending = []
|
||||
for hostname in vpn_hosts:
|
||||
registered = hostvars.get(hostname, {}).get("openvpn_jwt_registered", False)
|
||||
if str(registered).strip().lower() not in {"true", "yes", "1", "on"}:
|
||||
pending.append(hostname)
|
||||
|
||||
print(",".join(pending))
|
||||
' > /tmp/openvpn-jwt-pending-hosts
|
||||
pending_hosts=$(cat /tmp/openvpn-jwt-pending-hosts)
|
||||
if [ -n "$pending_hosts" ]; then
|
||||
echo "has_hosts=true" >> "$GITHUB_OUTPUT"
|
||||
echo "hosts=$pending_hosts" >> "$GITHUB_OUTPUT"
|
||||
echo "Preparing JWT identities for: $pending_hosts"
|
||||
else
|
||||
echo "has_hosts=false" >> "$GITHUB_OUTPUT"
|
||||
echo "No VPN nodes are awaiting JWT registration."
|
||||
fi
|
||||
|
||||
- name: Setup SSH
|
||||
if: steps.pending.outputs.has_hosts == 'true'
|
||||
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
|
||||
if: steps.pending.outputs.has_hosts == 'true'
|
||||
run: ansible-galaxy collection install -r requirements.yml
|
||||
|
||||
- name: Prepare JWT identities
|
||||
if: steps.pending.outputs.has_hosts == 'true'
|
||||
env:
|
||||
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||
PENDING_HOSTS: ${{ steps.pending.outputs.hosts }}
|
||||
run: |
|
||||
set -eu
|
||||
ansible-playbook \
|
||||
-i inventories/prod/hosts.ini \
|
||||
playbooks/openvpn-jwt-identity.yml \
|
||||
--limit "$PENDING_HOSTS"
|
||||
|
||||
- name: Upload public JWT keys
|
||||
if: steps.pending.outputs.has_hosts == 'true'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: openvpn-jwt-public-keys
|
||||
path: artifacts/openvpn-jwt-public-keys/*.pem
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
@@ -1,71 +0,0 @@
|
||||
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
|
||||
Reference in New Issue
Block a user