I am experiencing an intriguing issue when running OpenVPN on a Raspberry Pi 4 (running Raspbian 32-bit Lite). The issue appears to be related to the authentication process when OpenVPN is run via SSH, as a systemd service, or inside a Docker container. Here are the specifics:
When I run OpenVPN directly on the Raspberry Pi (with a monitor and keyboard attached), I can successfully establish a VPN connection using the --auth-user-pass flag with a file containing my credentials.
However, when I run the same OpenVPN command via SSH, the VPN connection fails. Specifically, the VPN client sends the authentication but does not receive a response from the server, eventually leading to a timeout.
If I run OpenVPN via SSH and manually input my credentials when prompted, the VPN connection succeeds.
When OpenVPN is set as a systemd service to run at boot, it always fails. However, if I manually start or restart the service after boot, the success depends on where it's done: it succeeds if done directly on the Raspberry Pi, but fails if done via SSH.
Inside a Docker container, the behavior is similar to the systemd service. The VPN connection succeeds when the Docker container is run directly from the Raspberry Pi but fails when the Docker container is run via SSH.
When I intentionally enter incorrect credentials, I can reproduce the same behavior (the server does not respond, leading to a timeout), which leads me to believe that the issue is related to the authentication process.
I've confirmed that the authentication file is accessible and contains the correct credentials in all scenarios.
The SSH account I'm using is the same one I use when working directly on the Raspberry Pi.
In summary, OpenVPN's authentication process behaves inconsistently: it works when run directly on the Raspberry Pi, but fails when run via SSH, as a systemd service, or in a Docker container. I'm seeking to understand why this discrepancy occurs and how I can resolve it. Any insights would be greatly appreciated.
Thank you!
Here's part of the log when the VPN connection times out:
UDP link remote: [AF_INET]someip:someport
WWWW
[UNDEF] Inactivity timeout (--ping-exit), exiting
TCP/UDP: Closing socket
SIGTERM[soft,ping-exit] received, process exiting