Browse code

Persist-key: enable persist-key option by default

Change the default behavior of the OpenVPN configuration
by enabling the persist-key option by default.

This means that all the keys will be kept in memory
across restart.

Trac: #1405
Change-Id: I57f1c2ed42bd9dfd43577238749a9b7f4c1419ff
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Message-Id: <20240307140355.32644-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28347.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gianmarco De Gregori authored on 2024/03/07 23:03:55
Showing 14 changed files
... ...
@@ -20,6 +20,8 @@ NTLMv1 authentication support for HTTP proxies has been removed.
20 20
     When configured to authenticate with NTLMv1 (``ntlm`` keyword in
21 21
     ``--http-proxy``) OpenVPN will try NTLMv2 instead.
22 22
 
23
+``persist-key`` option has been enabled by default.
24
+    All the keys will be kept in memory across restart.
23 25
 
24 26
 Overview of changes in 2.6
25 27
 ==========================
... ...
@@ -39,7 +39,6 @@ Here is an example of connection profile usage::
39 39
    http-proxy 192.168.0.8 8080
40 40
    </connection>
41 41
 
42
-   persist-key
43 42
    persist-tun
44 43
    pkcs12 client.p12
45 44
    remote-cert-tls server
... ...
@@ -302,17 +302,6 @@ which mode OpenVPN is configured as.
302 302
   Change process priority after initialization (``n`` greater than 0 is
303 303
   lower priority, ``n`` less than zero is higher priority).
304 304
 
305
-  Don't re-read key files across :code:`SIGUSR1` or ``--ping-restart``.
306
-
307
-  This option can be combined with ``--user`` to allow restarts
308
-  triggered by the :code:`SIGUSR1` signal. Normally if you drop root
309
-  privileges in OpenVPN, the daemon cannot be restarted since it will now
310
-  be unable to re-read protected key files.
311
-
312
-  This option solves the problem by persisting keys across :code:`SIGUSR1`
313
-  resets, so they don't need to be re-read.
314
-
315 305
 --providers providers
316 306
   Load the list of (OpenSSL) providers. This is mainly useful for using an
317 307
   external provider for key management like tpm2-openssl or to load the
... ...
@@ -402,7 +391,7 @@ which mode OpenVPN is configured as.
402 402
 
403 403
   Like with chroot, complications can result when scripts or restarts are
404 404
   executed after the setcon operation, which is why you should really
405
-  consider using the ``--persist-key`` and ``--persist-tun`` options.
405
+  consider using the ``--persist-tun`` option.
406 406
 
407 407
 --status args
408 408
   Write operational status to ``file`` every ``n`` seconds. ``n`` defaults
... ...
@@ -283,7 +283,7 @@ the local and the remote host.
283 283
   See the signals section below for more information on :code:`SIGUSR1`.
284 284
 
285 285
   Note that the behavior of ``SIGUSR1`` can be modified by the
286
-  ``--persist-tun``, ``--persist-key``, ``--persist-local-ip`` and
286
+  ``--persist-tun``, ``--persist-local-ip`` and
287 287
   ``--persist-remote-ip`` options.
288 288
 
289 289
   Also note that ``--ping-exit`` and ``--ping-restart`` are mutually
... ...
@@ -452,7 +452,7 @@ fast hardware. SSL/TLS authentication must be used in this mode.
452 452
   ``--route``, ``--route-gateway``, ``--route-delay``,
453 453
   ``--redirect-gateway``, ``--ip-win32``, ``--dhcp-option``, ``--dns``,
454 454
   ``--inactive``, ``--ping``, ``--ping-exit``, ``--ping-restart``,
455
-  ``--setenv``, ``--auth-token``, ``--persist-key``, ``--persist-tun``,
455
+  ``--setenv``, ``--auth-token``, ``--persist-tun``,
456 456
   ``--echo``, ``--comp-lzo``, ``--socket-flags``, ``--sndbuf``,
457 457
   ``--rcvbuf``, ``--session-timeout``
458 458
 
... ...
@@ -10,9 +10,8 @@ SIGNALS
10 10
     Like :code:`SIGHUP``, except don't re-read configuration file, and
11 11
     possibly don't close and reopen TUN/TAP device, re-read key files,
12 12
     preserve local IP address/port, or preserve most recently authenticated
13
-    remote IP address/port based on ``--persist-tun``, ``--persist-key``,
14
-    ``--persist-local-ip`` and ``--persist-remote-ip`` options respectively
15
-    (see above).
13
+    remote IP address/port based on ``--persist-tun``, ``--persist-local-ip``
14
+    and ``--persist-remote-ip`` options respectively (see above).
16 15
 
17 16
     This signal may also be internally generated by a timeout condition,
18 17
     governed by the ``--ping-restart`` option.
... ...
@@ -42,3 +42,6 @@ longer supported
42 42
 
43 43
 --prng
44 44
   Removed in OpenVPN 2.6.  We now always use the PRNG of the SSL library.
45
+
46
+--persist-key
47
+  Ignored since OpenVPN 2.7. Keys are now always persisted across restarts.
45 48
\ No newline at end of file
... ...
@@ -62,7 +62,6 @@ nobind
62 62
 ;group openvpn
63 63
 
64 64
 # Try to preserve some state across restarts.
65
-persist-key
66 65
 persist-tun
67 66
 
68 67
 # If you are connecting through an
... ...
@@ -274,11 +274,10 @@ cipher AES-256-CBC
274 274
 ;user openvpn
275 275
 ;group openvpn
276 276
 
277
-# The persist options will try to avoid
277
+# The persist option will try to avoid
278 278
 # accessing certain resources on restart
279 279
 # that may no longer be accessible because
280 280
 # of the privilege downgrade.
281
-persist-key
282 281
 persist-tun
283 282
 
284 283
 # Output a short status file showing
... ...
@@ -89,7 +89,6 @@ secret key.txt
89 89
 ; ping-restart 60
90 90
 ; ping-timer-rem
91 91
 ; persist-tun
92
-; persist-key
93 92
 ; resolv-retry 86400
94 93
 
95 94
 # keep-alive ping
... ...
@@ -3559,14 +3559,6 @@ do_option_warnings(struct context *c)
3559 3559
         {
3560 3560
             msg(M_WARN, "WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail");
3561 3561
         }
3562
-        if (!o->persist_key
3563
-#ifdef ENABLE_PKCS11
3564
-            && !o->pkcs11_id
3565
-#endif
3566
-            )
3567
-        {
3568
-            msg(M_WARN, "WARNING: you are using user/group/chroot/setcon without persist-key -- this may cause restarts to fail");
3569
-        }
3570 3562
     }
3571 3563
 
3572 3564
     if (o->chroot_dir && !(o->username && o->groupname))
... ...
@@ -3857,7 +3849,7 @@ static void
3857 3857
 do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)
3858 3858
 {
3859 3859
     /*
3860
-     * always free the tls_auth/crypt key. If persist_key is true, the key will
3860
+     * always free the tls_auth/crypt key. The key will
3861 3861
      * be reloaded from memory (pre-cached)
3862 3862
      */
3863 3863
     free_key_ctx(&c->c1.ks.tls_crypt_v2_server_key);
... ...
@@ -3866,7 +3858,7 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)
3866 3866
     buf_clear(&c->c1.ks.tls_crypt_v2_wkc);
3867 3867
     free_buf(&c->c1.ks.tls_crypt_v2_wkc);
3868 3868
 
3869
-    if (!(c->sig->signal_received == SIGUSR1 && c->options.persist_key))
3869
+    if (!(c->sig->signal_received == SIGUSR1))
3870 3870
     {
3871 3871
         key_schedule_free(&c->c1.ks, free_ssl_ctx);
3872 3872
     }
... ...
@@ -48,7 +48,7 @@
48 48
 
49 49
 /*
50 50
  * Our global key schedules, packaged thusly
51
- * to facilitate --persist-key.
51
+ * to facilitate key persistence.
52 52
  */
53 53
 
54 54
 struct key_schedule
... ...
@@ -273,7 +273,6 @@ static const char usage_message[] =
273 273
     "--persist-tun   : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n"
274 274
     "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n"
275 275
     "--persist-local-ip  : Keep local IP address across SIGUSR1 or --ping-restart.\n"
276
-    "--persist-key   : Don't re-read key files across SIGUSR1 or --ping-restart.\n"
277 276
 #if PASSTOS_CAPABILITY
278 277
     "--passtos       : TOS passthrough (applies to IPv4 only).\n"
279 278
 #endif
... ...
@@ -1857,7 +1856,6 @@ show_settings(const struct options *o)
1857 1857
     SHOW_BOOL(persist_tun);
1858 1858
     SHOW_BOOL(persist_local_ip);
1859 1859
     SHOW_BOOL(persist_remote_ip);
1860
-    SHOW_BOOL(persist_key);
1861 1860
 
1862 1861
 #if PASSTOS_CAPABILITY
1863 1862
     SHOW_BOOL(passtos);
... ...
@@ -3240,18 +3238,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
3240 3240
         ce->tls_crypt_v2_file_inline = o->tls_crypt_v2_file_inline;
3241 3241
     }
3242 3242
 
3243
-    /* Pre-cache tls-auth/crypt(-v2) key file if persist-key was specified and
3243
+    /* Pre-cache tls-auth/crypt(-v2) key file if
3244 3244
      * keys were not already embedded in the config file.
3245 3245
      */
3246
-    if (o->persist_key)
3247
-    {
3248
-        connection_entry_preload_key(&ce->tls_auth_file,
3249
-                                     &ce->tls_auth_file_inline, &o->gc);
3250
-        connection_entry_preload_key(&ce->tls_crypt_file,
3251
-                                     &ce->tls_crypt_file_inline, &o->gc);
3252
-        connection_entry_preload_key(&ce->tls_crypt_v2_file,
3253
-                                     &ce->tls_crypt_v2_file_inline, &o->gc);
3254
-    }
3246
+    connection_entry_preload_key(&ce->tls_auth_file,
3247
+                                 &ce->tls_auth_file_inline, &o->gc);
3248
+    connection_entry_preload_key(&ce->tls_crypt_file,
3249
+                                 &ce->tls_crypt_file_inline, &o->gc);
3250
+    connection_entry_preload_key(&ce->tls_crypt_v2_file,
3251
+                                 &ce->tls_crypt_v2_file_inline, &o->gc);
3252
+
3255 3253
 
3256 3254
     if (!proto_is_udp(ce->proto) && ce->explicit_exit_notification)
3257 3255
     {
... ...
@@ -6963,7 +6959,8 @@ add_option(struct options *options,
6963 6963
     else if (streq(p[0], "persist-key") && !p[1])
6964 6964
     {
6965 6965
         VERIFY_PERMISSION(OPT_P_PERSIST);
6966
-        options->persist_key = true;
6966
+        msg(M_WARN, "DEPRECATED: --persist-key option ignored. "
6967
+            "Keys are now always persisted across restarts. ");
6967 6968
     }
6968 6969
     else if (streq(p[0], "persist-local-ip") && !p[1])
6969 6970
     {
... ...
@@ -344,7 +344,6 @@ struct options
344 344
     bool persist_tun;           /* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */
345 345
     bool persist_local_ip;      /* Don't re-resolve local address on SIGUSR1 or PING_RESTART */
346 346
     bool persist_remote_ip;     /* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */
347
-    bool persist_key;           /* Don't re-read key files on SIGUSR1 or PING_RESTART */
348 347
 
349 348
 #if PASSTOS_CAPABILITY
350 349
     bool passtos;