Persist-key: enable persist-key option by default.
PATCH 1/1 Persist-key: enable persist-key option by default.
This commit changes the default behavior of the OpenVPN configuration to enable the persist-key option by default.
This means that all the key file content will be kept in memory throughout the lifetime of the VPN connection.
--- doc/man-sections/generic-options.rst | 2 ++ src/openvpn/init.c | 12 ++---------- src/openvpn/options.c | 23 +++++++++++------------ src/openvpn/options.h | 1 - 4 files changed, 15 insertions(+), 23 deletions(-)
doc/man-sections/generic-options.rst +2 -0
@@ -303,6 +303,8 @@ which mode OpenVPN is configured as. lower priority, ``n`` less than zero is higher priority). --persist-key + DEPRECATED OPTION, corresponding behavior is now always enabled. + Don't re-read key files across :code:`SIGUSR1` or ``--ping-restart``. This option can be combined with ``--user`` to allow restarts
src/openvpn/init.c +2 -10
@@ -3606,14 +3606,6 @@ do_option_warnings(struct context *c) {msg (M_WARN ,"WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail" ); } -if (!o->persist_key -#ifdef ENABLE_PKCS11 - && !o->pkcs11_id -#endif - ) - { -msg (M_WARN ,"WARNING: you are using user/group/chroot/setcon without persist-key -- this may cause restarts to fail" ); - } }if (o->chroot_dir && !(o->username && o->groupname))
@@ -3901,7 +3893,7 @@ static void do_close_free_key_schedule(struct context *c, bool free_ssl_ctx) {/* -* always free the tls_auth/crypt key. If persist_key is true, the key will +* always free the tls_auth/crypt key. The key will * be reloaded from memory (pre-cached) */ free_key_ctx (&c->c1.ks.tls_crypt_v2_server_key);
@@ -3910,7 +3902,7 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)buf_clear (&c->c1.ks.tls_crypt_v2_wkc);free_buf (&c->c1.ks.tls_crypt_v2_wkc); -if (!(c->sig->signal_received ==SIGUSR1 && c->options.persist_key)) +if (!(c->sig->signal_received ==SIGUSR1 )) {key_schedule_free (&c->c1.ks, free_ssl_ctx); }
src/openvpn/options.c +11 -12
@@ -1860,7 +1860,6 @@ show_settings(const struct options *o)SHOW_BOOL (persist_tun);SHOW_BOOL (persist_local_ip);SHOW_BOOL (persist_remote_ip); -SHOW_BOOL (persist_key);#if PASSTOS_CAPABILITY SHOW_BOOL (passtos);
@@ -3239,18 +3238,15 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) ce->tls_crypt_v2_file_inline = o->tls_crypt_v2_file_inline; } -/* Pre-cache tls-auth/crypt(-v2) key file if persist-key was specified and +/* Pre-cache tls-auth/crypt(-v2) key file if * keys were not already embedded in the config file. */ -if (o->persist_key) - { -connection_entry_preload_key (&ce->tls_auth_file, - &ce->tls_auth_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_file, - &ce->tls_crypt_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_v2_file, - &ce->tls_crypt_v2_file_inline, &o->gc); - } +connection_entry_preload_key (&ce->tls_auth_file, + &ce->tls_auth_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_file, + &ce->tls_crypt_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_v2_file, + &ce->tls_crypt_v2_file_inline, &o->gc);if (!proto_is_udp (ce->proto) && ce->explicit_exit_notification) {
@@ -6938,7 +6934,10 @@ add_option(struct options *options,else if (streq (p[0 ],"persist-key" ) && !p[1 ]) {VERIFY_PERMISSION (OPT_P_PERSIST ); - options->persist_key = true; +msg (M_WARN ,"DEPRECATED OPTION: --persist-key option ignored." +"The corresponding behavior is now always activated." +"This option will be removed in a future version, " +"please remove it from your configuration." ); }else if (streq (p[0 ],"persist-local-ip" ) && !p[1 ]) {
src/openvpn/options.h +0 -1
@@ -344,7 +344,6 @@ struct optionsbool persist_tun;/* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */ bool persist_local_ip;/* Don't re-resolve local address on SIGUSR1 or PING_RESTART */ bool persist_remote_ip;/* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */ -bool persist_key;/* Don't re-read key files on SIGUSR1 or PING_RESTART */ #if PASSTOS_CAPABILITY bool passtos;
Signature · 1 line
2.37.2
Quoted 21 lines · Gianmarco De Gregori
This commit changes the default behavior of the OpenVPN configuration to enable the persist-key option by default.
This means that all the key file content will be kept in memory throughout the lifetime of the VPN connection.
Fixes Trac #1405Signed-off-by Gianmarco De Gregori <[email protected]...>--- doc/man-sections/generic-options.rst | 2 ++ src/openvpn/init.c | 12 ++---------- src/openvpn/options.c | 23 +++++++++++------------ src/openvpn/options.h | 1 - 4 files changed, 15 insertions(+), 23 deletions(-)doc/man-sections/generic-options.rst +0
-0
doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 306
Quoted 4 lines
doc/man-sections/generic-options.rst +1
-0@@ -303,6 +303,8 @@ which mode OpenVPN is configured as. lower priority, ``n`` less than zero is higher priority). --persist-key + DEPRECATED OPTION, corresponding behavior is now always enabled.
The usual style in the documentation seems to be "**DEPRECATED**". See e.g. --disable-occ in the same file.
Quoted 4 lines
doc/man-sections/generic-options.rst +1
-0+ Don't re-read key files across :code:`SIGUSR1` or ``--ping-restart``. This option can be combined with ``--user`` to allow restarts
[...]
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c +0
-0
Please also add (DEPRECATED) marker in usage_message.
[...]
Regards,
Signature · 1 line
Frank Lichtenheld
PATCH v2 1/1 Persist-key: enable persist-key option by default.
In reply to Gianmarco De GregoriThis commit changes the default behavior of the OpenVPN configuration to enable the persist-key option by default.
This means that all the key file content will be kept in memory throughout the lifetime of the VPN connection.
---
Changes from v1:
* changed "DEPRECATED OPTION" with "**DEPRECATED**" in the documentation and with "(DEPRECATED)" in usage_message().
doc/man-sections/generic-options.rst | 2 ++ src/openvpn/init.c | 13 +++---------- src/openvpn/options.c | 26 +++++++++++++------------- src/openvpn/options.h | 1 - 4 files changed, 18 insertions(+), 24 deletions(-)
doc/man-sections/generic-options.rst +2 -0
@@ -303,6 +303,8 @@ which mode OpenVPN is configured as. lower priority, ``n`` less than zero is higher priority). --persist-key + **DEPRECATED**, corresponding behavior is now always enabled. + Don't re-read key files across :code:`SIGUSR1` or ``--ping-restart``. This option can be combined with ``--user`` to allow restarts
src/openvpn/init.c +3 -10
@@ -3606,14 +3606,6 @@ do_option_warnings(struct context *c) {msg (M_WARN ,"WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail" ); } -if (!o->persist_key -#ifdef ENABLE_PKCS11 - && !o->pkcs11_id -#endif - ) - { -msg (M_WARN ,"WARNING: you are using user/group/chroot/setcon without persist-key -- this may cause restarts to fail" ); - } }if (o->chroot_dir && !(o->username && o->groupname))
@@ -3687,6 +3679,7 @@ do_option_warnings(struct context *c) } } +struct context_buffers *init_context_buffers (const struct frame *frame) {
@@ -3901,7 +3894,7 @@ static void do_close_free_key_schedule(struct context *c, bool free_ssl_ctx) {/* -* always free the tls_auth/crypt key. If persist_key is true, the key will +* always free the tls_auth/crypt key. The key will * be reloaded from memory (pre-cached) */ free_key_ctx (&c->c1.ks.tls_crypt_v2_server_key);
@@ -3910,7 +3903,7 @@ do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)buf_clear (&c->c1.ks.tls_crypt_v2_wkc);free_buf (&c->c1.ks.tls_crypt_v2_wkc); -if (!(c->sig->signal_received ==SIGUSR1 && c->options.persist_key)) +if (!(c->sig->signal_received ==SIGUSR1 )) {key_schedule_free (&c->c1.ks, free_ssl_ctx); }
src/openvpn/options.c +13 -13
@@ -275,7 +275,7 @@ static const char usage_message[] ="--persist-tun : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n" "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n" "--persist-local-ip : Keep local IP address across SIGUSR1 or --ping-restart.\n" -"--persist-key : Don't re-read key files across SIGUSR1 or --ping-restart.\n" +"--persist-key : (DEPRECATED) Don't re-read key files across SIGUSR1 or --ping-restart.\n" #if PASSTOS_CAPABILITY"--passtos : TOS passthrough (applies to IPv4 only).\n" #endif
@@ -1860,7 +1860,6 @@ show_settings(const struct options *o)SHOW_BOOL (persist_tun);SHOW_BOOL (persist_local_ip);SHOW_BOOL (persist_remote_ip); -SHOW_BOOL (persist_key);#if PASSTOS_CAPABILITY SHOW_BOOL (passtos);
@@ -3239,18 +3238,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) ce->tls_crypt_v2_file_inline = o->tls_crypt_v2_file_inline; } -/* Pre-cache tls-auth/crypt(-v2) key file if persist-key was specified and +/* Pre-cache tls-auth/crypt(-v2) key file if * keys were not already embedded in the config file. */ -if (o->persist_key) - { -connection_entry_preload_key (&ce->tls_auth_file, - &ce->tls_auth_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_file, - &ce->tls_crypt_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_v2_file, - &ce->tls_crypt_v2_file_inline, &o->gc); - } +connection_entry_preload_key (&ce->tls_auth_file, + &ce->tls_auth_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_file, + &ce->tls_crypt_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_v2_file, + &ce->tls_crypt_v2_file_inline, &o->gc); +if (!proto_is_udp (ce->proto) && ce->explicit_exit_notification) {
@@ -6938,7 +6935,10 @@ add_option(struct options *options,else if (streq (p[0 ],"persist-key" ) && !p[1 ]) {VERIFY_PERMISSION (OPT_P_PERSIST ); - options->persist_key = true; +msg (M_WARN ,"DEPRECATED: --persist-key option ignored." +"The corresponding behavior will now always be done automatically." +"This option will be removed in a future version, " +"please remove it from your configuration." ); }else if (streq (p[0 ],"persist-local-ip" ) && !p[1 ]) {
src/openvpn/options.h +0 -1
@@ -344,7 +344,6 @@ struct optionsbool persist_tun;/* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */ bool persist_local_ip;/* Don't re-resolve local address on SIGUSR1 or PING_RESTART */ bool persist_remote_ip;/* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */ -bool persist_key;/* Don't re-read key files on SIGUSR1 or PING_RESTART */ #if PASSTOS_CAPABILITY bool passtos;
Signature · 1 line
2.37.2
Quoted 6 lines · Gianmarco De Gregori
This commit changes the default behavior of the OpenVPN configuration to enable the persist-key option by default.
This means that all the key file content will be kept in memory throughout the lifetime of the VPN connection.
Quoted 6 lines
Fixes Trac #1405Signed-off-by Gianmarco De Gregori <[email protected]...>---
Changes from v1:
* changed "DEPRECATED OPTION" with "**DEPRECATED**" in the documentation and with "(DEPRECATED)" inusage_message().
So I looked into the state of our deprecated options in general, triggered by your patch. Based on that I have a lot more feedback this time around ;)
doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 310
Quoted 13 lines
doc/man-sections/generic-options.rst +2
-0@@ -303,6 +303,8 @@ which mode OpenVPN is configured as. lower priority, ``n`` less than zero is higher priority). --persist-key + **DEPRECATED**, corresponding behavior is now always enabled. + Don't re-read key files across :code:`SIGUSR1` or ``--ping-restart``. This option can be combined with ``--user`` to allow restarts
Since the behavior is now always on, we should completely remove the description and instead check whether other documentation needs to be adapted. However, documentation should be added to unsupported-options.rst.
Searching for persist-key throughout the documentation and also the sample/ directory shows a lot of references. All of these need to be adapted.
When updating the documentation we might need to make a special note of the push case. When servers currently push --persist-key then they may want to continue doing that until all their clients have been updated to 2.7. So we should be careful when updating the reference in --push documentation.
[...]
src/openvpn/options.c static const char usage_message[] = · line 278
Quoted 9 lines
index
e4c596b8..caf45b7e100644src/openvpn/options.c +1
-1@@ -275,7 +275,7 @@ static const char usage_message[] ="--persist-tun : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n" "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n" "--persist-local-ip : Keep local IP address across SIGUSR1 or --ping-restart.\n" -"--persist-key : Don't re-read key files across SIGUSR1 or --ping-restart.\n" +"--persist-key : (DEPRECATED) Don't re-read key files across SIGUSR1 or --ping-restart.\n"
Again, since we completely ignore the option, we should probably just remove this line completely. DEPRECATED seems more appropriate for options that still do something but we want to warn about.
Quoted 39 lines
src/openvpn/options.c +8
-11#if PASSTOS_CAPABILITY "--passtos : TOS passthrough (applies to IPv4 only).\n"#endif @@ -1860,7 +1860,6 @@ show_settings(const struct options *o)SHOW_BOOL (persist_tun);SHOW_BOOL (persist_local_ip);SHOW_BOOL (persist_remote_ip); -SHOW_BOOL (persist_key);#if PASSTOS_CAPABILITY SHOW_BOOL (passtos);@@ -3239,18 +3238,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) ce->tls_crypt_v2_file_inline = o->tls_crypt_v2_file_inline; } -/* Pre-cache tls-auth/crypt(-v2) key file if persist-key was specified and +/* Pre-cache tls-auth/crypt(-v2) key file if * keys were not already embedded in the config file. */ -if (o->persist_key) - { -connection_entry_preload_key (&ce->tls_auth_file, - &ce->tls_auth_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_file, - &ce->tls_crypt_file_inline, &o->gc); -connection_entry_preload_key (&ce->tls_crypt_v2_file, - &ce->tls_crypt_v2_file_inline, &o->gc); - } +connection_entry_preload_key (&ce->tls_auth_file, + &ce->tls_auth_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_file, + &ce->tls_crypt_file_inline, &o->gc); +connection_entry_preload_key (&ce->tls_crypt_v2_file, + &ce->tls_crypt_v2_file_inline, &o->gc); +if (!proto_is_udp (ce->proto) && ce->explicit_exit_notification) {
src/openvpn/options.c add_option(struct options *options, · line 6939
Quoted 6 lines
src/openvpn/options.c +2
-1@@ -6938,7 +6935,10 @@ add_option(struct options *options,else if (streq (p[0 ],"persist-key" ) && !p[1 ]) {VERIFY_PERMISSION (OPT_P_PERSIST ); - options->persist_key = true; +msg (M_WARN ,"DEPRECATED: --persist-key option ignored." + "The corresponding behavior will now always be done automatically."
Maybe better: "The corresponding behavior is now always enabled."
src/openvpn/options.c add_option(struct options *options, · line 6944
Quoted 5 lines
src/openvpn/options.c +2
-0+"This option will be removed in a future version, " + "please remove it from your configuration."); }else if (streq (p[0 ],"persist-local-ip" ) && !p[1 ]) {
Regards,
Signature · 1 line
Frank Lichtenheld
Am 09.05.2023 um 17:46 schrieb Gianmarco De Gregori:
Quoted 1 line
- bool
persist_key; /* Don't re-read key files on SIGUSR1 orPING_RESTART*/
The downside of always enabling this option is that you can no longer replace the certificate and key without restarting the server completley.
Arne
Hi,
Quoted 5 lines · Arne Schwabe
Am 09.05.2023 um 17:46 schrieb Gianmarco De Gregori:
Quoted 1 line
- bool
persist_key; /* Don't re-read key files on SIGUSR1 orPING_RESTART*/The downside of always enabling this option is that you can no longer replace the certificate and key without restarting the server completley.
We discussed this, and wondered if anyone is actually doing this.
So, are you aware of anyone doing this? Is there a reason I'm overlooking why this is substantially better than "just do a full restart when changing any part of the config (including keys, even if residing in separate files)"?
Hard restart should be about as fast as full SIGUSR1 restart - "wait for EEN to be delivered, close everything, exit()" vs. "close everything, re-read key files, reopen tun, ..."
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...