Skip to content

VPN audit logging: a pattern that survives discovery

Set up VPN audit logging that answers who connected, when, from where, and what they reached, across OpenVPN, WireGuard, IPsec, and Tailscale. You also get retention rules that hold up when a security auditor asks.

If you run a VPN for a team, you need connection logs that stand up in a security audit, and this is the pattern that produces them. Most self-built VPNs keep logs, yet those logs cannot tell an auditor who connected at 14:32 on March 12 and what that person reached. The fix is to capture five fields per connection, ship them to one central log store, set a retention period (how long the records are kept), and save the query that answers the question. We apply the same pattern to OpenVPN and WireGuard, two open-source VPN engines, to IPsec, the tunnelling protocol behind strongSwan gateways, and to Tailscale, a hosted VPN service where devices connect to each other directly. Each engine exposes the data differently, so the sections below cover the hook for each one.

How to verify

Before reshaping logging, see what the current state captures.

journalctl -u openvpn-server@server --since '24 hours ago' | grep -E 'CLIENT_LIST|TLS|VERIFY'
wg show all
journalctl -u strongswan --since '24 hours ago' | grep -E 'IKE_SA|CHILD_SA'
tailscale status --json | jq '.Peer | .[] | {Hostname, Online, LastSeen}'

A common surprise: OpenVPN’s default verbosity (verb 3) does not write the CLIENT_LIST lines — those come from the status directive, which writes to a different file. WireGuard logs almost nothing on its own; you build the trail from interface counters and external collectors.

What’s happening

An auditor wants five fields per connection:

  1. Who — user identity, ideally the SSO-resolved name, not a cert subject only the gateway understands.
  2. When — connect time, disconnect time. Duration falls out of those two.
  3. From where — public source IP (and ideally the geo-resolution).
  4. What got an IP — the overlay IP assigned to the user (so you can correlate firewall logs).
  5. What was reached — destination flows. This is optional for some compliance regimes; ESI/PCI typically wants it; SOC 2 often does not.

The engines vary in what they expose:

  • OpenVPN — status log writes a snapshot every N seconds; log-append writes connection events. Together they give all five fields.
  • WireGuard — no native event stream. You build one from wg show transfer and wg show latest-handshakes poll output, or from a wrapper like wg-portal or wg-easy.
  • strongSwan (IPsec) — journalctl -u strongswan emits structured events for SA creation, EAP auth, child SA installation. Use charon.filelog for structured output.
  • Tailscale — admin console exposes per-device events; the API gives JSON for SSH events, device joins, ACL evaluations. Configuration audit logs are exportable.

The pattern is the same regardless of engine: emit structured events, ship them to a central log store (Loki, Elasticsearch, Splunk), apply a retention policy, and write a saved query that produces the auditor’s answer.

The procedure

  1. OpenVPN — enable structured logging. In server.conf:

    status /var/log/openvpn/openvpn-status.log 10
    status-version 3
    log-append /var/log/openvpn/openvpn.log
    verb 3
    client-connect /etc/openvpn/scripts/connect.sh
    client-disconnect /etc/openvpn/scripts/disconnect.sh

    The connect/disconnect scripts can emit a single JSON line per event:

    #!/bin/bash
    # /etc/openvpn/scripts/connect.sh
    logger -t openvpn-audit -p local6.info \
      "$(jq -nc \
         --arg event "connect" \
         --arg user "$common_name" \
         --arg src  "$trusted_ip" \
         --arg vip  "$ifconfig_pool_remote_ip" \
         '{event:$event, user:$user, src:$src, vip:$vip, ts:now|todate}')"
  2. WireGuard — poll and emit. A tiny sidecar that runs every 30 seconds:

    #!/bin/bash
    wg show wg0 dump | tail -n +2 | while read pub _ ep _ _ rx tx hs; do
      who=$(grep -B1 "$pub" /etc/wireguard/peers.csv | head -1 | cut -d, -f1)
      printf '{"event":"wg-snapshot","user":"%s","endpoint":"%s","rx":%s,"tx":%s,"handshake":%s,"ts":"%s"}\n' \
        "$who" "$ep" "$rx" "$tx" "$hs" "$(date -Iseconds)"
    done | logger -t wg-audit -p local6.info

    peers.csv is your maintained mapping of public key to user identity.

  3. strongSwan — use charon.filelog for JSON. In /etc/strongswan.d/charon-logging.conf:

    charon {
        filelog {
            /var/log/strongswan-audit.log {
                time_format = %Y-%m-%dT%H:%M:%S
                default = 0
                ike = 2
                cfg = 1
                json = yes
                append = yes
            }
        }
    }

    Reload with swanctl --reload-settings.

  4. Tailscale — pull from the admin API. A cron job that fetches device events daily:

    curl -s -H "Authorization: Bearer $TS_API_KEY" \
      "https://api.tailscale.com/api/v2/tailnet/example.org/devices" | \
      jq -c '.devices[] | {id, hostname, user, addresses, lastSeen, expires}'
  5. Ship to a central log store. We default to Loki + Promtail because the storage is cheap and the query language is friendly for time-bounded “who” questions. Promtail tails /var/log/openvpn/, the wg-audit journal stream, and the strongSwan JSON file, attaches labels (engine=openvpn, user=$user), and pushes to Loki.

  6. Set retention. Three common policies:

    • 90 days for general operational use; matches most SOC 2 retention requirements.
    • 1 year for regulated workloads (PCI, HIPAA-adjacent).
    • 7 years for jurisdictions with statutory retention (some EU public-sector mandates).

    In Loki, this is a single line in compactor.retention_enabled: true + compactor.retention_delete_delay: 2h plus per-stream rules.

  7. Write the auditor’s query. A LogQL example for “everything user alice did on March 12”:

    {engine=~"openvpn|wireguard|strongswan"} |~ "alice"
      | json
      | line_format "{{.ts}} {{.event}} {{.engine}} src={{.src}} vip={{.vip}}"

    Save it. The audit response is then “run this saved query and export the results.”

Operational notes

  • The hardest field to get right is the user identity. Cert subjects, WireGuard public keys, and EAP IDs all need to map back to a human in your IdP. Maintain the mapping; do not rely on the engine to know.
  • Retention longer than 90 days needs encryption at rest. Loki on local disk is fine for short retention; for multi-year, use S3-backed Loki with server-side encryption.
  • Snapshot logs (OpenVPN status, WireGuard polls) are sampled, not exact. A short session that begins and ends between two polls will not appear. For exact records, rely on connect/disconnect events from scripts, not snapshots.
  • Time sync across the fleet matters. Auditors will spot 30-second clock drift between gateway and log store and ask awkward questions. NTP on every box.
  • Logs are themselves a privacy-relevant data store. Anyone with read access to the log store can see who connected to the VPN. Treat the log store with the same ACL discipline as the VPN itself.

In the engagements we run, VPN audit logging is part of the Managed Operations deliverable from day one, not an add-on after the first auditor visit. The pattern above is what we deploy by default — five fields, structured JSON, central store, retention rule, saved query. The hardest part is keeping the user-identity mapping current; the rest is plumbing.