Files
vpn-node-config/roles/openvpn_pki
gitea_admin 787cbd9e96
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 44s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m6s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Failing after 1m23s
OpenVPN Ansible / Generate SBOM (push) Skipped
OpenVPN Ansible / Scan SBOM with Trivy (push) Skipped
fix(pki): show safe initial certificate errors
2026-11-27 18:36:39 +01:00
..

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.