Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating JwksFetcher interface and impl #4225

Closed
wants to merge 0 commits into from
Closed

Creating JwksFetcher interface and impl #4225

wants to merge 0 commits into from

Conversation

nickrmc83
Copy link
Contributor

JwksFetcher wraps up HTTP acquisition of JWKS strings converting them into a concrete type on the way.
JwksFetcher is reusable so can be used in a wider context.

Tests updated and fixed where necessary.

Signed-off-by: Nick A. Smith [email protected]

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Description:
We are in the process of implementing a new Envoy filter based on the design presented here and wish to re-use existing logic in the jwt_authn filter. We've split out the logic we're interested in into a new class called JwksFetcher. Later PRs will re-use the split out logic an OpenID Connect filter.

Risk Level:
Medium
Testing:
Add replacement and additional unit tests for the logic that's been moved.
Docs Changes:
None
Release Notes:
[Optional Fixes #Issue]
[Optional Deprecated:]

@nickrmc83 nickrmc83 requested a review from lizan as a code owner August 22, 2018 15:41
@nickrmc83
Copy link
Contributor Author

Ping @lizan @qiwzhang . Can you take a look at this PR please? I've moved a small amount of code about so that we can re-use the JwksFetcher in multiple filters.

namespace HttpFilters {
namespace Common {

class JwksFetcher {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comment to describe its usage? especially if its instance can be re-used for multiple fetching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e6b6b0

/*
* Close/stop any inflight request.
*/
virtual void close() PURE;
Copy link
Contributor

Choose a reason for hiding this comment

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

rename it to cancel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to cancel() in e6b6b0 as per review comment.


class JwksFetcher {
public:
typedef std::unique_ptr<JwksFetcher> JwksFetcherPtr;
Copy link
Contributor

Choose a reason for hiding this comment

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

move xxxPtr definition to outside of class xxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in e6b6b0 as per review comment.

AuthenticatorPtr Authenticator::create(FilterConfigSharedPtr config) {
return std::make_unique<AuthenticatorImpl>(config);
AuthenticatorPtr Authenticator::create(FilterConfigSharedPtr config,
Common::JwksFetcher::JwksFetcherPtr& fetcher) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use && since you are using std::move for fetcher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in e6b6b0 as per review comment.

return std::make_unique<AuthenticatorImpl>(config);
AuthenticatorPtr Authenticator::create(FilterConfigSharedPtr config,
Common::JwksFetcher::JwksFetcherPtr& fetcher) {
return std::make_unique<AuthenticatorImpl>(config, fetcher);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we call std::move for fetcher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in e6b6b0 as per review comment.

@@ -46,8 +46,9 @@ FilterFactory::createFilterFactoryFromProtoTyped(const JwtAuthentication& proto_
validateJwtConfig(proto_config);
auto filter_config = std::make_shared<FilterConfig>(proto_config, prefix, context);
return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamDecoderFilter(
std::make_shared<Filter>(filter_config->stats(), Authenticator::create(filter_config)));
auto jwks_fetcher = Common::JwksFetcher::create(filter_config->cm());
Copy link
Contributor

Choose a reason for hiding this comment

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

can we pass a lambda function as fetcher_factory so fetcher is only created when it is needed, not always for each request?

@nickrmc83
Copy link
Contributor Author

This has turned into a bit of a mess. I'll fix before more review. Apologies

@nickrmc83 nickrmc83 closed this Aug 24, 2018
@nickrmc83
Copy link
Contributor Author

I've closed this PR as the history had become very messy. The failure on the CI and resultant DCO instructions around rebasing have not been kind. I'll create a new version.

htuch pushed a commit that referenced this pull request Sep 14, 2018
JwksFetcher wraps up HTTP acquisition of JWKS strings converting them into a concrete type on the way.
JwksFetcher is reusable so can be used in a wider context.

Tests updated and fixed where necessary.

We are in the process of implementing a new Envoy filter based on the design presented here and wish to re-use existing logic in the jwt_authn filter. We've split out the logic we're interested in into a new class called JwksFetcher. Later PRs will re-use the split out logic an OpenID Connect filter.

This is the second crack at this PR (see #4225 which went horribly wrong after following the DCO rebase guidelines).

Risk Level: Medium
Testing: Add replacement and additional unit tests for the logic that's been moved.

Signed-off-by: Nick A. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants