Skip to content

1962: Reload keyblock from key file on every config reload - #1970

Merged
persiaAziz-zz merged 1 commit into
apache:masterfrom
persiaAziz-zz:ticketReload
Jun 12, 2017
Merged

persiaAziz-zz merged 1 commit into
apache:masterfrom
persiaAziz-zz:ticketReload

Conversation

@persiaAziz-zz

Copy link
Copy Markdown
Contributor

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 reload should load the ticket keyblock only not the entire certificate stack from ssl_multicert.config

@persiaAziz-zz
persiaAziz-zz requested a review from mlibbey May 24, 2017 15:07
@persiaAziz-zz persiaAziz-zz self-assigned this May 24, 2017
@persiaAziz-zz persiaAziz-zz added this to the 8.0.0 milestone May 24, 2017
@persiaAziz-zz persiaAziz-zz added the Backport Marked for backport for an LTS patch release label May 24, 2017
@persiaAziz-zz persiaAziz-zz modified the milestones: 7.1.x, 8.0.0 May 24, 2017
@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

this needs to be backported to 7.1.x

@zwoop zwoop modified the milestones: 7.1.0, 8.0.0 May 24, 2017

@zwoop zwoop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review. I think this needs some more scrutiny.

Comment thread mgmt/ProxyConfig.h Outdated

// A Continuation wrapper that calls the static reconfigure() method of the given class.
template <typename UpdateClass> struct ConfigUpdateContinuation : public Continuation {
void (*f)();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f seems like an awfully generic name here. I assume it's a "function" of some sort. so name it accordingly IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Comment thread iocore/net/SSLConfig.cc Outdated

void
SSLConfigParams::LoadTicket() const
{

@zwoop zwoop May 24, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread mgmt/ProxyConfig.h Outdated
return EVENT_DONE;
}
int
update_func(int /*etype*/, void * /* data */)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh, but I think you need to reload the entire SSLConfigParams, no ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SolidWallOfCode

Copy link
Copy Markdown
Member

I'll have to make a longer comment on the update function issue. I think the use of std::function could avoid most of the need for the UpdateClass template parameter and simplify other code.

@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

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

Comment thread iocore/net/P_SSLConfig.h Outdated
};

struct SSLTicketParams : public ConfigInfo {
mutable ssl_ticket_key_block *default_global_keyblock;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be mutable. If you need that, you're doing something wrong elsewhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a std::unique_ptr might not be amiss here.

Comment thread iocore/net/P_SSLConfig.h Outdated

struct SSLTicketParams : public ConfigInfo {
mutable ssl_ticket_key_block *default_global_keyblock;
char* ticket_key_filename;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ats_scoped_str?

@persiaAziz-zz persiaAziz-zz Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should a param be ats_scoped_str? I intend to keep the filename

update: Is the object life-time the scope in this case?

Comment thread iocore/net/SSLConfig.cc Outdated
void
SSLTicketParams::LoadTicket() const
{
ticket_block_free(default_global_keyblock);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread iocore/net/SSLConfig.cc Outdated
SSLTicketParams*
SSLTicketKeyConfig::acquire()
{
return (SSLTicketParams*)configProcessor.get(configid);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No C-style casts.

Comment thread mgmt/ProxyConfig.h Outdated
return 0;
}

template <typename UpdateClass>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this class. Why not just call schedule_imm directly at the place this is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to remove that. Forgot to delete

@persiaAziz-zz persiaAziz-zz Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. I still need to work on this PR. I pushed this so that I can access this from home

@persiaAziz-zz

persiaAziz-zz commented Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

new commit please review again @SolidWallOfCode @shinrich @zwoop

@shinrich
shinrich self-requested a review June 6, 2017 21:33
shinrich
shinrich previously approved these changes Jun 6, 2017

@shinrich shinrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restructuring looks good. The ticket file is handled independently of the rest of ssl multicert, and it is always reloaded.

SolidWallOfCode
SolidWallOfCode previously approved these changes Jun 6, 2017
Comment thread iocore/net/SSLConfig.cc Outdated
}

void
SSLTicketKeyConfig::release(SSLTicketParams *params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread iocore/net/SSLConfig.cc Outdated
SSLTicketParams::~SSLTicketParams()
{
cleanup();
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shocking that clang-format doesn't find this, but add a newline here IMO.

Comment thread iocore/net/P_SSLConfig.h Outdated
struct SSLTicketKeyConfig {
static void startup();
static bool reconfigure();
static SSLTicketParams *acquire();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented below, move the simple implementations up here, for automatic inlinining.

Comment thread iocore/net/SSLConfig.cc
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 &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but I personally prefer an empty line between local variable declarations and the code :-).

Comment thread iocore/net/SSLConfig.cc
SSLTicketKeyConfig::startup()
{
auto sslTicketKey = new ConfigUpdateHandler<SSLTicketKeyConfig>();
sslTicketKey->attach("proxy.config.ssl.server.ticket_key.filename");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line here too, for consistency.

@persiaAziz-zz
persiaAziz-zz dismissed stale reviews from SolidWallOfCode and shinrich via 179d4a2 June 7, 2017 21:10
@persiaAziz-zz
persiaAziz-zz force-pushed the ticketReload branch 2 times, most recently from 179d4a2 to e21e53b Compare June 7, 2017 21:13
@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

[approve ci autest]

1 similar comment
@bryancall

Copy link
Copy Markdown
Contributor

[approve ci autest]

@zwoop

zwoop commented Jun 8, 2017

Copy link
Copy Markdown
Contributor

[approve ci docs]

@zwoop zwoop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits, and then I'll +1 this. :)

@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

[approve ci autest]

1 similar comment
@zwoop

zwoop commented Jun 9, 2017

Copy link
Copy Markdown
Contributor

[approve ci autest]

Comment thread iocore/net/P_SSLConfig.h
{
return static_cast<SSLTicketParams *>(configProcessor.get(configid));
}
static void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread iocore/net/SSLConfig.cc Outdated
ticket_key_filename = (char *)ats_free_null(ticket_key_filename);
}

SSLTicketParams::~SSLTicketParams()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be inlined too. Small ctor's / dtor's are better off in the declaration IMO.

@zwoop

zwoop commented Jun 12, 2017

Copy link
Copy Markdown
Contributor

@persiaAziz Did you address the latest cosmetic feedback? It's nitpick, but still semi important (particularly the whitespaces).

@zwoop zwoop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@persiaAziz-zz
persiaAziz-zz merged commit b3adf64 into apache:master Jun 12, 2017
@zwoop

zwoop commented Jun 13, 2017

Copy link
Copy Markdown
Contributor

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport Marked for backport for an LTS patch release Configuration TLS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants