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

feat: Add support for Introspection based on headers #2585

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

isodude
Copy link
Contributor

@isodude isodude commented Apr 1, 2024

Set `X-Oauth2-Proxy-Introspect-Token: true' on requests that you want to be introspected. Will affect latency.

Description

Adding the ability to introspect the token when a specific header is set in the incoming request. From what I have come to understand, it's not possible to use Introspection on PKCE (https://salesforce.stackexchange.com/a/299171).

This uses the introspection url already provided by the OIDC endpoint.

Motivation and Context

In e.g. Nginx this makes it possible to make really sure that certain operations validate the token the whole way.

How Has This Been Tested?

  • Logging in
  • Invalidating the token centrally
  • Trying to access the resource again

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

@isodude isodude requested a review from a team as a code owner April 1, 2024 13:18
@isodude isodude marked this pull request as draft April 1, 2024 13:18
@isodude
Copy link
Contributor Author

isodude commented Apr 1, 2024

@tuunit ping

Signed-off-by: Josef Johansson <[email protected]>
@github-actions github-actions bot added the docs label Apr 1, 2024
Signed-off-by: Josef Johansson <[email protected]>
@isodude
Copy link
Contributor Author

isodude commented Apr 2, 2024

Starting to create some tests.

isodude added 2 commits April 2, 2024 18:39
Signed-off-by: Josef Johansson <[email protected]>
Signed-off-by: Josef Johansson <[email protected]>
if opts.SkipJwtBearerTokens {
sessionLoaders := []middlewareapi.TokenToSessionFunc{
provider.CreateSessionFromToken,
if opts.SkipJwtBearerTokens || opts.SkipBearerTokens {
Copy link
Member

Choose a reason for hiding this comment

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

We already considered renaming this flag in another PR. Please don't introduce a second SkipBearerToken. Just remove JWT from the current flag.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand this will break current functionality. So maybe we need to keep the old one and mark it as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it in based on a comment in the PR, based on your suggestion I think :-)

@@ -35,6 +35,10 @@ type RequestScope struct {
// ClearSession indicates whether the user should be logged out or not.
ClearSession bool

// IntrospectToken indicates whether to introspect the session token.
// This is set if the request has the header `X-Oauth2-Proxy-Introspect-Token`.
Copy link
Member

Choose a reason for hiding this comment

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

Is this approach wise? Shouldn't the introspection always happen? This way the client decides when to redo the introspection, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless the client is Nginx, my use case here is to choose what to introspect. I haven't given much thought about cli options with this flag, maybe add --introspection-enable-header which enables this behavior.

E.g. if you want to introspect all write queries, but not read. Or just /admin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the flag, make sense!

I guess it should however also enable the sessiontoken creater.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it such that my header introspection updates the session.

Could we enable that always for --introspect-token and skip the createSessionFromIntrospectedToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a patch doing that. It's wip though, needs testing obviously.

Copy link
Contributor

github-actions bot commented Jun 3, 2024

This pull request has been inactive for 60 days. If the pull request is still relevant please comment to re-activate the pull request. If no action is taken within 7 days, the pull request will be marked closed.

@github-actions github-actions bot added the Stale label Jun 3, 2024
@smehboub
Copy link

smehboub commented Jun 9, 2024

Hello,

Thank you very much all for your work.
Any news on progress ?

Thanks in advance :-)
Rgs

@github-actions github-actions bot removed the Stale label Jun 11, 2024
@stfnzl
Copy link

stfnzl commented Jul 18, 2024

Nice feature! It would be amazing to get this merged!

Copy link
Contributor

This pull request has been inactive for 60 days. If the pull request is still relevant please comment to re-activate the pull request. If no action is taken within 7 days, the pull request will be marked closed.

@github-actions github-actions bot added the Stale label Sep 18, 2024
@github-actions github-actions bot closed this Sep 25, 2024
@tuunit tuunit removed the Stale label Sep 30, 2024
@tuunit tuunit reopened this Sep 30, 2024
@isodude
Copy link
Contributor Author

isodude commented Oct 20, 2024

Should really see this through. The only thing left is to add some test.. not sure how to do them though.

@isodude
Copy link
Contributor Author

isodude commented Dec 27, 2024

@tuunit I'm unsure how to make this merge-able. Would like to help me out a bit? What tests should I implement?

@isodude isodude changed the title Add support for Introspection based on headers feat: Add support for Introspection based on headers Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants