Files
vpn-node-config/roles/openvpn_jwt
gitea_admin 4b8e7f3592
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
refactor(vpn): split JWT identity and OpenVPN certificate lifecycle
- 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
2026-11-27 17:58:46 +01:00
..

OpenVPN JWT identity

This role manages each VPN node's local RSA identity and JWT generator. It is separate from openvpn_pki, which manages the OpenVPN server certificate.

tasks/main.yml delegates to three focused task files:

  • generator.yml installs the configured generator and checks its Python interpreter and dependencies.
  • keys.yml creates or validates the RSA private/public key pair.
  • public_key.yml fetches only the public key to the controller.

Run the dedicated identity playbook for selected nodes:

ansible-playbook \
  -i inventories/prod/hosts.ini \
  playbooks/openvpn-jwt-identity.yml \
  --limit vpn01-test

The Gitea workflow .gitea/workflows/openvpn-jwt-identity.yml runs after the main OpenVPN workflow succeeds. It selects every vpn_nodes host whose openvpn_jwt_registered value is false or missing. It uploads the resulting PEM files as the openvpn-jwt-public-keys artifact. An administrator adds each new public key to OpenBao's existing trusted-key bundle while preserving the other keys. After registration is confirmed, set that host's openvpn_jwt_registered value to true; the regular OpenVPN deployment can then proceed for that VM.

The regular openvpn.yml deployment skips the openvpn, openvpn_jwt, and openvpn_pki roles when the flag is false or absent. Shared base roles still run.

The private key remains on the VPN node at /etc/vault-jwt/private.pem by default, with root ownership and mode 0600. Only the public key is copied to artifacts/openvpn-jwt-public-keys/<inventory_hostname>.pem for manual registration with OpenBao. The role does not configure OpenBao.

Existing keys must be a matching RSA pair at the configured size. The role fails without replacing an incomplete, invalid, wrong-size, or mismatched identity.

Install the collections in requirements.yml, including community.crypto, on the Ansible controller before running this role.

The role creates the Python virtual environment and installs the pinned PyJWT[crypto] dependency. Override openvpn_jwt_virtualenv to change the environment location. If you also override openvpn_jwt_python, point it to an interpreter inside that same environment. openvpn_jwt_role and openvpn_jwt_generator_args configure the generator invocation used by the certificate lifecycle script.