Skip to contentSkip to conversation

multi: send RESTART, [P]: on restart when auth-gen-token is used

PATCH In review Kirthik Aditya 1 participant 2 messages Nov 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multi: send RESTART, [P]: on restart when auth-gen-token is used

When a UDP server using --explicit-exit-notify restarts (SIGUSR1/SIGHUP) or exits, it sends a bare RESTART to connected clients. OpenVPN 3 clients treat this as a request to discard their auth-token, so users relying on SSO have to authenticate again, even when the server can still validate their token using --auth-gen-token-secret.

When --auth-gen-token is enabled, send RESTART,[P]: instead to ask clients to keep their auth-token across the restart. OpenVPN 3 only recognises this exact prefix. The next-server case ([N]) is left unchanged because OpenVPN 3 does not support it.

If the token is no longer valid after the restart, the client receives AUTH_FAILED and falls back to normal authentication.

GitHub: closes OpenVPN/openvpn#1099

---
Discussion: https://github.com/OpenVPN/openvpn/issues/1099
Branch: https://github.com/spryzz3n/openvpn/tree/restart-preserve-auth-token
Tested with OpenVPN 2.x client on localhost; not yet with OpenVPN Connect.

 Changes.md                          |  8 ++++++++
 doc/man-sections/client-options.rst |  6 ++++++
 src/openvpn/multi.c                 | 15 +++++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
Changes.md +8 -0
index 89a72fe4..54c6385c 100644
@@ -2,6 +2,14 @@
 
 ## User-visible Changes
 
+* **`explicit-exit-notify` preserves auth-tokens on server restart**
+
+  When a UDP server with `--explicit-exit-notify 1` and `--auth-gen-token`
+  restarts or exits, it now sends `RESTART,[P]:` instead of a bare `RESTART`.
+  This lets OpenVPN 3 based clients (e.g. OpenVPN Connect) reconnect with
+  their auth-token instead of asking the user to authenticate again.
+  OpenVPN 2.x clients now also keep their cached username/password.
+
 * **Parsing Distinguished Names in certificates**
 
   (OpenSSL backend:) OpenVPN now rejects certificates that have a null-byte
doc/man-sections/client-options.rst +6 -0
index 16309f90..c8596c41 100644
@@ -285,6 +285,12 @@ configuration.
   reconnect to the same server, with ``n`` = :code:`2` client will advance
   to the next server.
 
+  If ``--auth-gen-token`` is also used and ``n`` = :code:`1`, the server
+  sends :code:`RESTART,[P]:` instead, asking clients to keep their cached
+  credentials and auth-token. Clients can then reconnect with the token
+  without user interaction, provided the token is still valid after the
+  restart (see ``--auth-gen-token-secret``).
+
   OpenVPN will not send any exit notifications unless this option is
   enabled.
 
src/openvpn/multi.c +13 -2
index 900b5a3b..c6dc932b 100644
@@ -3926,14 +3926,25 @@ is_exit_restart(int sig)
 static void
 multi_push_restart_schedule_exit(struct multi_context *m, bool next_server)
 {
+    /* Preserve auth-token on restart for OpenVPN 3 clients.
+     * Keep the next-server case unchanged for compatibility. */
+    const char *restart_msg = "RESTART";
+    if (next_server)
+    {
+        restart_msg = "RESTART,[N]";
+    }
+    else if (m->top.options.auth_token_generate)
+    {
+        restart_msg = "RESTART,[P]:";
+    }
+
     /* tell all clients to restart */
     for (uint32_t i = 0; i <= m->max_peerid; i++)
     {
         struct multi_instance *mi = m->instances[i];
         if (mi && !mi->halt && proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
         {
-            send_control_channel_string(&mi->context, next_server ? "RESTART,[N]" : "RESTART",
-                                        D_PUSH);
+            send_control_channel_string(&mi->context, restart_msg, D_PUSH);
             multi_schedule_context_wakeup(m, mi);
         }
     }
Signature · 8 lines
2.43.0



_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
#1 lore raw

Hi,

please disregard this patch. As discussed in
https://github.com/OpenVPN/openvpn/issues/1099 the different behaviour is in the OpenVPN 3 client, which purges the auth-token on a bare RESTART while OpenVPN 2.x keeps it. I'll work on a fix for OpenVPN 3 instead.

Thanks,
Kirthik

Quoted 97 lines · Kirthik Aditya

When a UDP server using --explicit-exit-notify restarts (SIGUSR1/SIGHUP) or exits, it sends a bare RESTART to connected clients. OpenVPN 3 clients treat this as a request to discard their auth-token, so users relying on SSO have to authenticate again, even when the server can still validate their token using --auth-gen-token-secret.

When --auth-gen-token is enabled, send RESTART,[P]: instead to ask clients to keep their auth-token across the restart. OpenVPN 3 only recognises this exact prefix. The next-server case ([N]) is left unchanged because OpenVPN 3 does not support it.

If the token is no longer valid after the restart, the client receives AUTH_FAILED and falls back to normal authentication.

GitHub: closes OpenVPN/openvpn#1099

---
Discussion: https://github.com/OpenVPN/openvpn/issues/1099
Branch: https://github.com/spryzz3n/openvpn/tree/restart-preserve-auth-token
Tested with OpenVPN 2.x client on localhost; not yet with OpenVPN Connect.

 Changes.md                          |  8 ++++++++
 doc/man-sections/client-options.rst |  6 ++++++
 src/openvpn/multi.c                 | 15 +++++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
Changes.md +8 -0
index 89a72fe4..54c6385c 100644
@@ -2,6 +2,14 @@
 
 ## User-visible Changes
 
+* **`explicit-exit-notify` preserves auth-tokens on server restart**
+
+  When a UDP server with `--explicit-exit-notify 1` and `--auth-gen-token`
+  restarts or exits, it now sends `RESTART,[P]:` instead of a bare `RESTART`.
+  This lets OpenVPN 3 based clients (e.g. OpenVPN Connect) reconnect with
+  their auth-token instead of asking the user to authenticate again.
+  OpenVPN 2.x clients now also keep their cached username/password.
+
 * **Parsing Distinguished Names in certificates**
 
   (OpenSSL backend:) OpenVPN now rejects certificates that have a null-byte
doc/man-sections/client-options.rst +6 -0
index 16309f90..c8596c41 100644
@@ -285,6 +285,12 @@ configuration.
   reconnect to the same server, with ``n`` = :code:`2` client will advance
   to the next server.
 
+  If ``--auth-gen-token`` is also used and ``n`` = :code:`1`, the server
+  sends :code:`RESTART,[P]:` instead, asking clients to keep their cached
+  credentials and auth-token. Clients can then reconnect with the token
+  without user interaction, provided the token is still valid after the
+  restart (see ``--auth-gen-token-secret``).
+
   OpenVPN will not send any exit notifications unless this option is
   enabled.
 
src/openvpn/multi.c +13 -3
index 900b5a3b..c6dc932b 100644
@@ -3926,14 +3926,25 @@ is_exit_restart(int sig)
 static void
 multi_push_restart_schedule_exit(struct multi_context *m, bool next_server)
 {
+    /* Preserve auth-token on restart for OpenVPN 3 clients.
+     * Keep the next-server case unchanged for compatibility. */
+    const char *restart_msg = "RESTART";
+    if (next_server)
+    {
+        restart_msg = "RESTART,[N]";
+    }
+    else if (m->top.options.auth_token_generate)
+    {
+        restart_msg = "RESTART,[P]:";
+    }
+
     /* tell all clients to restart */
     for (uint32_t i = 0; i <= m->max_peerid; i++)
     {
         struct multi_instance *mi = m->instances[i];
         if (mi && !mi->halt && proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
         {
-            send_control_channel_string(&mi->context, next_server ? "RESTART,[N]" : "RESTART",
-                                        D_PUSH);
+            send_control_channel_string(&mi->context, restart_msg, D_PUSH);
             multi_schedule_context_wakeup(m, mi);
         }
     }
--
Quoted 2 lines

2.43.0

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel