Repository navigation
1962: Reload keyblock from key file on every config reload - #1970
Conversation
|
this needs to be backported to 7.1.x |
zwoop
left a comment
There was a problem hiding this comment.
Initial review. I think this needs some more scrutiny.
|
|
||
| // A Continuation wrapper that calls the static reconfigure() method of the given class. | ||
| template <typename UpdateClass> struct ConfigUpdateContinuation : public Continuation { | ||
| void (*f)(); |
There was a problem hiding this comment.
f seems like an awfully generic name here. I assume it's a "function" of some sort. so name it accordingly IMO.
|
|
||
| void | ||
| SSLConfigParams::LoadTicket() const | ||
| { |
There was a problem hiding this comment.
I likely don't understand this code... But how is this not a race condition? You delete the key block (bad name btw, since it's part of the SSLConfigParams() class), and then create a new one. But the same SSLConfigParams could still be in use by another process?
Shouldn't the entire SSLConfigParams() object be "reloaded" and recycled? Meaning, the one that's owned and managed by the config processor.
| return EVENT_DONE; | ||
| } | ||
| int | ||
| update_func(int /*etype*/, void * /* data */) |
There was a problem hiding this comment.
i'm not grok'ing most of this code. It seems the intent of this template was to always use the CB named ::reconfigure() from the templated class. That doesn't work for this use case?
There was a problem hiding this comment.
This code is useful when you have a ticket key file where content changes but you don't want to change the name of this file in records.config to reload it. Reconfigure() in general loads the whole config. So in a production environment, reloading the whole stack of certificates specified in ssl_multicert.config just for a ticket key update seems unnecessary. However, if there is any change in recods.config or ssl_multicert.config then the corresponding configparams get reloaded again, so that behavior has not changed. This ticket key is only required by the session ticket key callback, hence other config variables in sslconfigparams are not really dependent on this
There was a problem hiding this comment.
yeh, but I think you need to reload the entire SSLConfigParams, no ?
There was a problem hiding this comment.
If we reload SSLConfigParams then, the certificate update handler will get triggered too, since there are parameters in SSLConfigparams affecting certificate params. Since this patch is intended to update the keyblock only, I don't think we need to reload the whole sslconfigparams.
There was a problem hiding this comment.
Unfortunately if any thread is actively using the config structure the it will have its keyfile updated asynchronously. It seems likely to fail. At a minimum the key block pointer should be atomically swapped after the new key block is loaded.
|
I'll have to make a longer comment on the update function issue. I think the use of |
|
Talked with Alan and Susan. Moving the keyblock out from SSLConfigParams and making itself a scoped_config param seems like a better idea. I will update this PR accordingly |
| }; | ||
|
|
||
| struct SSLTicketParams : public ConfigInfo { | ||
| mutable ssl_ticket_key_block *default_global_keyblock; |
There was a problem hiding this comment.
This should not be mutable. If you need that, you're doing something wrong elsewhere.
There was a problem hiding this comment.
Also, a std::unique_ptr might not be amiss here.
|
|
||
| struct SSLTicketParams : public ConfigInfo { | ||
| mutable ssl_ticket_key_block *default_global_keyblock; | ||
| char* ticket_key_filename; |
There was a problem hiding this comment.
should a param be ats_scoped_str? I intend to keep the filename
update: Is the object life-time the scope in this case?
| void | ||
| SSLTicketParams::LoadTicket() const | ||
| { | ||
| ticket_block_free(default_global_keyblock); |
There was a problem hiding this comment.
I think you should do this last, in case something goes wrong, at least you have the old keyblock. It's another reason to use std::unique_ptr - as with ats_scoped_str putting a new block of memory in automatically and simultaneously frees the old block.
| SSLTicketParams* | ||
| SSLTicketKeyConfig::acquire() | ||
| { | ||
| return (SSLTicketParams*)configProcessor.get(configid); |
| return 0; | ||
| } | ||
|
|
||
| template <typename UpdateClass> |
There was a problem hiding this comment.
I don't understand this class. Why not just call schedule_imm directly at the place this is used?
There was a problem hiding this comment.
I need to remove that. Forgot to delete
There was a problem hiding this comment.
BTW. I still need to work on this PR. I pushed this so that I can access this from home
e5b8749 to
4ed8fd5
Compare
|
new commit please review again @SolidWallOfCode @shinrich @zwoop |
shinrich
left a comment
There was a problem hiding this comment.
The restructuring looks good. The ticket file is handled independently of the rest of ssl multicert, and it is always reloaded.
| } | ||
|
|
||
| void | ||
| SSLTicketKeyConfig::release(SSLTicketParams *params) |
There was a problem hiding this comment.
I think you should move these to the .h include file (in the struct), then they get automatically inlined. Simple functions (certainly those with just one line like these) should be inlined with the class / struct IMO.
| SSLTicketParams::~SSLTicketParams() | ||
| { | ||
| cleanup(); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Shocking that clang-format doesn't find this, but add a newline here IMO.
| struct SSLTicketKeyConfig { | ||
| static void startup(); | ||
| static bool reconfigure(); | ||
| static SSLTicketParams *acquire(); |
There was a problem hiding this comment.
As commented below, move the simple implementations up here, for automatic inlinining.
| cleanup(); | ||
| #if HAVE_OPENSSL_SESSION_TICKETS | ||
| SSLConfig::scoped_config params; | ||
| if (REC_ReadConfigStringAlloc(ticket_key_filename, "proxy.config.ssl.server.ticket_key.filename") == REC_ERR_OKAY && |
There was a problem hiding this comment.
Not important, but I personally prefer an empty line between local variable declarations and the code :-).
| SSLTicketKeyConfig::startup() | ||
| { | ||
| auto sslTicketKey = new ConfigUpdateHandler<SSLTicketKeyConfig>(); | ||
| sslTicketKey->attach("proxy.config.ssl.server.ticket_key.filename"); |
There was a problem hiding this comment.
Add an empty line here too, for consistency.
179d4a2
179d4a2 to
e21e53b
Compare
|
[approve ci autest] |
1 similar comment
|
[approve ci autest] |
|
[approve ci docs] |
zwoop
left a comment
There was a problem hiding this comment.
Please squash the commits, and then I'll +1 this. :)
b80b745 to
6732841
Compare
|
[approve ci autest] |
1 similar comment
|
[approve ci autest] |
| { | ||
| return static_cast<SSLTicketParams *>(configProcessor.get(configid)); | ||
| } | ||
| static void |
There was a problem hiding this comment.
As was pointed out on the mailing list, we really prefer an empty line after the } on these functions. I know clang-format can mess with this, but see if you can get it to behave?
| ticket_key_filename = (char *)ats_free_null(ticket_key_filename); | ||
| } | ||
|
|
||
| SSLTicketParams::~SSLTicketParams() |
There was a problem hiding this comment.
This could probably be inlined too. Small ctor's / dtor's are better off in the declaration IMO.
|
@persiaAziz Did you address the latest cosmetic feedback? It's nitpick, but still semi important (particularly the whitespaces). |
6732841 to
bffacd3
Compare
|
@persiaAziz This doesn't cherry-pick cleanly to 7.1.x. It's an easy fix, but to play by the book, can you please make a new PR for the 7.1.x branch which I can merge? |
This patch is for letting the ticket keyblock get updated each time config reload is called. The config 'proxy.config.ssl.server.ticket_key.filename' is attached to sslcertupdate, but the callback function for this update is different to avoid reloading of stack of ssl certificates unnecessarily. Hence if there is a change in the content of ticket key file only, then a call to
config reloadshould load the ticket keyblock only not the entire certificate stack from ssl_multicert.config