Skip to content

Support inline jwks from config#1476

Merged
qiwzhang merged 2 commits intoistio:masterfrom
qiwzhang:inline_jwks
Apr 20, 2018
Merged

Support inline jwks from config#1476
qiwzhang merged 2 commits intoistio:masterfrom
qiwzhang:inline_jwks

Conversation

@qiwzhang
Copy link
Copy Markdown
Contributor

@qiwzhang qiwzhang commented Apr 19, 2018

What this PR does / why we need it:

Support sending jwks in the config.

Issue: https://github.com/istio/proxy/issues/1373
Release note:

None

@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Apr 19, 2018
@qiwzhang qiwzhang requested review from diemtvu and quanjielin and removed request for sebastienvas April 19, 2018 21:35
jwt_config_.local_jwks().specifier_case() ==
::envoy::api::v2::core::DataSource::kInlineString) {
Status status =
SetKey(Base64::decode(jwt_config_.local_jwks().inline_string()));
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.

So do you expect the key is base64 encoded?

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.

does it mean pilot side needs encoding the key ?

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.

Yes, Envoy is doing a lot of JsonConvert for filter config. We could not just put json as value here

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 don't do this, if you want inline them with base64 in YAML/JSON, just use inline_bytes, by proto/json spec they are base64 encoded. Don't mix them up.

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.

Done

audiences_.insert(SanitizeAudience(aud));
}

if (jwt_config_.has_local_jwks() &&
Copy link
Copy Markdown
Contributor

@lizan lizan Apr 19, 2018

Choose a reason for hiding this comment

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

Instead of the whole block here, just use Envoy::Config::DataSource::read and you're good with all 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.

Done

const auto& duration = jwt_config_.remote_jwks().cache_duration();
expiration_time_ += std::chrono::seconds(duration.seconds()) +
std::chrono::nanoseconds(duration.nanos());
if (jwt_config_.has_remote_jwks()) {
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'd change SetKey parameter and add a const time_point& expiration, instead of check local/remote here and above.

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.

Done


auto inline_jwks = Config::DataSource::read(jwt_config_.local_jwks(), true);
if (!inline_jwks.empty()) {
Status status = SetKey(Base64::decode(inline_jwks),
Copy link
Copy Markdown
Contributor

@lizan lizan Apr 20, 2018

Choose a reason for hiding this comment

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

No Base64::decode?

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 think it is still better to base64 encod it. Here is my concern, Envoy is using JsonConvert() to convert Struct or Protobuf to other config proto. If we don't base64 encode jwks, jwks is a JSON, it will break. It is safer to base64 encode the jwks.

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.

No please dont, it won't break JSON encoding, a string will be escaped correctly. If you want base64 encoded one, just use inline_bytes, which is by proto spec. You don't want to load base64 encoded from DataSource file. please revert.

@qiwzhang qiwzhang requested a review from JimmyCYJ April 20, 2018 01:27
Copy link
Copy Markdown
Member

@JimmyCYJ JimmyCYJ left a comment

Choose a reason for hiding this comment

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

/lgtm

/approve

@istio-testing
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JimmyCYJ

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@qiwzhang qiwzhang merged commit 4f3fb8f into istio:master Apr 20, 2018
@qiwzhang qiwzhang deleted the inline_jwks branch April 20, 2018 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants