Files
vpn-node-config/roles/openvpn_pki/README.md
T
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

2.1 KiB

OpenVPN PKI certificate lifecycle

This role manages the OpenVPN server certificate through the configured OpenBao PKI signing endpoint. JWT identity management belongs to the separate openvpn_jwt role, which runs before this role in playbooks/openvpn.yml.

Task layout

tasks/main.yml delegates to focused stages:

  • runtime.yml: OpenBao CLI, runtime packages, and company VPN CA fingerprint.
  • setup.yml: certificate directories, OpenBao API CA, and lifecycle scripts.
  • service.yml: protected configuration and systemd service/timer.
  • initial_certificate.yml: initial issuance only when server.crt is absent.

Subsequent Ansible deployments do not renew an existing certificate. The daily systemd timer invokes the lifecycle script, which decides whether the certificate needs renewal.

On initial setup, the certificate is issued before OpenVPN is restarted or started. Ansible then flushes the restart handler, which restarts OpenVPN and waits for TAP before bringing it up and attaching it to the bridge. A separate start/TAP task runs only when no restart handler ran. The daily timer is enabled after the initial issuance attempt.

CA configuration

The OpenBao API CA is deployed to /root/openbao-ca.crt and is used only for OpenBao API TLS. The company VPN Root CA deployed by the openvpn role at /etc/openvpn/certs/ca.crt anchors OpenVPN server certificate validation. The role calculates that certificate's SHA-256 fingerprint on the VPN node.

Certificate configuration

Configure node-specific names in inventory. For example:

openvpn_pki_certificate_common_name: "{{ inventory_hostname }}"
openvpn_pki_certificate_dns_sans:
  - "{{ inventory_hostname }}"

Set openvpn_pki_bao_addr, openvpn_pki_bao_cacert, and openvpn_pki_sign_endpoint to match the OpenBao deployment. The lifecycle script runs as root from /usr/local/libexec/openvpn-pki/, using the protected configuration at /etc/openvpn/openbao-vpn.conf. It uses the same flock lock for initial issuance and timer runs.

Requirements

Install the collections listed in the repository's requirements.yml, including community.crypto for the openvpn_jwt role.