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

jwtValidation and forwardTokenField filters #1811

Merged
merged 1 commit into from
Sep 10, 2021
Merged

Conversation

abinet
Copy link
Contributor

@abinet abinet commented Jul 8, 2021

The filter extracts Authorization Bearer token, validates using public keys of Authorization server and stores info into same map as oauthOidcUserInfo does. So we can use oidcClaimsQuery for filtering based on claims extracted from the token.

Filter parameters are:

jwtValidation(authorization_provider_url, claims, upstream_headers)
Here is the example of usage:

zalando.org/skipper-filter: jwtValidation("https://login.microsoftonline.com/<tenant_id>/v2.0/",
"sub", "X-Remote-User:sub") -> oidcClaimsQuery("/:groups.#[=="group-a"]","/:groups.#[=="group-b"]")

#1810

@AlexanderYastrebov AlexanderYastrebov added the wip work in progress label Jul 8, 2021
@aryszka
Copy link
Contributor

aryszka commented Jul 9, 2021

I like the name jwtValidation because it's simple, but it may not fit well with the existing conventions of the authnz filters. What are the thoughts of others on this?

@szuecs
Copy link
Member

szuecs commented Jul 15, 2021

I think naming us fine, but only reading the pr message, I think we miss an auto refresh of JKS. Keys (public keys). See tokenintrospection filters for issuer well known configuration integration.

@abinet abinet force-pushed the master branch 3 times, most recently from dc8745a to 11a740a Compare August 9, 2021 16:08
@abinet
Copy link
Contributor Author

abinet commented Aug 16, 2021

I suppose to have resolved all the issues mentioned by review. @szuecs @AlexanderYastrebov can you have a look once you get time please.

@szuecs
Copy link
Member

szuecs commented Sep 8, 2021

Other than the godoc is fine to merge IMO.
We could make the critical sections even smaller in registerKeyFunction(). We could split it into 2 there, because we only need to guard the map access.
If you want to go further you could also change the Mutex to RWMutex and use RLock() and Lock(), because we rarely use the write lock to update the map and we read much more often (every request), but that's optimization which we might not need.

@abinet

This comment has been minimized.

@AlexanderYastrebov
Copy link
Member

AlexanderYastrebov commented Sep 9, 2021

@abinet Please update PR description to match the implementation (you may squash commits and write a detailed commit message that could be used as PR description)

@AlexanderYastrebov

This comment has been minimized.

@abinet

This comment has been minimized.

@AlexanderYastrebov

This comment has been minimized.

@szuecs
Copy link
Member

szuecs commented Sep 9, 2021

please rebase to master as we merged the fix for master, thanks

@szuecs
Copy link
Member

szuecs commented Sep 9, 2021

The last missing piece IMO is #1811 (comment).
To be more clear, I would like to have it like this:

func registerKeyFunction(url string) (err error) {
	m.RLock()
	if _, ok := jwksMap[url]; ok {
		m.Unlock()
		return nil
	}
	m.Unlock()
....
	jwks, err := keyfunc.Get(url, options)
	if err != nil {
		return fmt.Errorf("failed to get the JWKs from the given URL %s Error:%w", url, err)
	}
	m.Lock()
	jwksMap[url] = jwks
	m.Unlock()
	return nil
}

I want to have it because keyfunc.Get( can take long blocking all Requests with the write lock.
And we have now only small critical sections, of course we needed to write a bit more lines, but this is fine.

@abinet abinet changed the title jwt validation filter jwtValidation and forwardTokenField filters Sep 9, 2021
@szuecs szuecs added ready-for-review and removed wip work in progress labels Sep 9, 2021
@szuecs
Copy link
Member

szuecs commented Sep 9, 2021

👍

@aryszka
Copy link
Contributor

aryszka commented Sep 10, 2021

👍

1 similar comment
@szuecs
Copy link
Member

szuecs commented Sep 10, 2021

👍

@szuecs szuecs merged commit b4e4555 into zalando:master Sep 10, 2021
@szuecs
Copy link
Member

szuecs commented Sep 10, 2021

@abinet Thanks great work!

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

Successfully merging this pull request may close these issues.

5 participants