Skip to content

Commit 4b9e619

Browse files
amatveev-cfdormando
authored andcommitted
Reload TLS certificates on SIGHUP
SIGHUP is the standard way of forcing daemons to reload their configuration, but memcached only reloads TLS certificates in response to the `refresh_certs` command, which requires a lot more work to issue. When implementing automatic certificate updates, it's a lot more straightforward to follow the standard signal-based approach.
1 parent cd5510f commit 4b9e619

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

doc/tls.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ When this happens we want server to use the new certificate without restarting t
126126
Memcached is a cache and restarting servers affects the latency of applications. We implement
127127
the automatic certificate refresh through a command. Upon receiving the "refresh_certs" command,
128128
the server reloads the certificates and key to the SSL Context object. Existing connection won't be
129-
interrupted but new connections will use the new certificate.
129+
interrupted but new connections will use the new certificate. Additionally to the "refresh_certs"
130+
command, memcached also refreshes its certificates upon receiving the SIGHUP signal.
130131

131132
We understand not all users want to use TLS or have the OpenSSL dependency. Therefore
132133
it's an optional module at the compile time. We can build a TLS capable Memcached server with

memcached.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3918,11 +3918,23 @@ static void clock_handler(const evutil_socket_t fd, const short which, void *arg
39183918
// This function should be quick to avoid delaying the timer.
39193919
assoc_start_expand(stats_state.curr_items);
39203920
// also, if HUP'ed we need to do some maintenance.
3921-
// for now that's just the authfile reload.
3921+
// for now that's just the authfile and TLS certificates reload.
39223922
if (settings.sig_hup) {
39233923
settings.sig_hup = false;
39243924

39253925
authfile_load(settings.auth_file);
3926+
3927+
#ifdef TLS
3928+
if (settings.ssl_ctx != NULL) {
3929+
char *errmsg = NULL;
3930+
refresh_certs(&errmsg);
3931+
if (errmsg != NULL) {
3932+
vperror("Could not reload TLS certificates on SIGHUP: %s", errmsg);
3933+
free(errmsg);
3934+
}
3935+
}
3936+
#endif
3937+
39263938
#ifdef PROXY
39273939
if (settings.proxy_ctx) {
39283940
proxy_start_reload(settings.proxy_ctx);

0 commit comments

Comments
 (0)