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

Add IDToken for Azure provider #258

Merged
merged 12 commits into from
Oct 17, 2019

Conversation

leyshon
Copy link
Contributor

@leyshon leyshon commented Aug 29, 2019

Description

This adds the IDToken to the session for the Azure provider.

Motivation and Context

This allows it to be passed as a bearer token in the Authorization header to an upstream such as the Kubernetes dashboard. It solves the issue in #131

How Has This Been Tested?

This has been tested against Azure AD to check that it returns the IDToken. It was tested with nginx in auth proxy mode to check that this token could be used to authenticate to the kubernetes dashboard.

As a result of the change the cookie being returned is larger and has to be split. This can cause an issue if using nginx to proxy requiring proxy buffer size be increased (see https://andrewlock.net/fixing-nginx-upstream-sent-too-big-header-error-when-running-an-ingress-controller-in-kubernetes/). I'm not sure therefore if something should be noted in the changelog regarding this.

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.

@leyshon leyshon requested a review from a team August 29, 2019 14:14
Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Code changes look good!

Please add a note to the changelog if possible and for the cookie splitting issue, i would recommend using the new Redis based session storage backend, it resolves the issue of having to fit within the 4kb cookie limit. Could potentially add a note to the documentation about this, WDYT?

@leyshon
Copy link
Contributor Author

leyshon commented Sep 3, 2019

I've added a note to both the documentation and the changelog

loshz
loshz previously approved these changes Sep 3, 2019
Copy link
Member

@loshz loshz left a comment

Choose a reason for hiding this comment

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

LGTM - Thank you and congrats on your first contribution! 🎉

docs/2_auth.md Outdated Show resolved Hide resolved
loshz
loshz previously approved these changes Oct 2, 2019
@iremmats
Copy link

iremmats commented Oct 3, 2019

We just tested this branch and ran into an issue with
[2019/10/03 06:23:31] [oauthproxy.go:745] Error loading cookied session: Cookie "_oa
uth2_proxy" not present

As you say in the conversation/documentation the cookie has been split into _oauth2_proxy_0, _oauth2_proxy_1, _oauth2_proxy_2. We are using the auth-request mode which seems to be the most common.

Nginx has been configured with increased proxy buffer size. Where do we need to make changes now to make this work?

This is how we configure our ingress:
nginx.ingress.kubernetes.io/auth-signin: https://$host/oauth2/start?rd=$request_uri
nginx.ingress.kubernetes.io/auth-url: https://$host/oauth2/auth

@leyshon
Copy link
Contributor Author

leyshon commented Oct 3, 2019

@iremmats What do the logs for the ingress controller say? The log from oauth2-proxy says it's not getting the cookie and the reason for that lies somewhere in nginx so those logs should hold the answer.

@JoelSpeed
Copy link
Member

@iremmats Split cookies with auth request mode can cause issues. Ensuring Nginx properly copies the set-cookie headers across has had many different solutions posted in issues on this repo for a while but it has not really been solved.

Instead, the recommendation is to use redis for session storage, which solves the problem of large cookies by just issuing a session ticket rather than the full session, meaning no more split cookies

docs/2_auth.md Outdated Show resolved Hide resolved
Co-Authored-By: Joel Speed <Joel.speed@hotmail.co.uk>
@xyxiaobai
Copy link

Any idea when this will be merged? I'm looking forward to testing it out! Thanks.

@loshz
Copy link
Member

loshz commented Oct 10, 2019

If we can get the conflicts resolved I think this will be good to go.

@leyshon
Copy link
Contributor Author

leyshon commented Oct 16, 2019

@syscll I've resolved the conflicts if you're able to review it once more. Thanks.

@@ -5,6 +5,8 @@
- [#227](https://github.com/pusher/oauth2_proxy/pull/227) Add Keycloak provider (@Ofinka)
- [#273](https://github.com/pusher/oauth2_proxy/pull/273) Support Go 1.13 (@dio)
- [#275](https://github.com/pusher/oauth2_proxy/pull/275) docker: build from debian buster (@syscll)
- [#258](https://github.com/pusher/oauth2_proxy/pull/258) Add IDToken for Azure provider
- This PR adds the IDToken into the session for the Azure provider allowing requests to a backend to be identified as a specific user. As a consequence, if you are using a cookie to store the session the cookie will now exceed the 4kb size limit and be split into multiple cookies. This can cause problems when using nginx as a proxy, resulting in no cookie being passed at all. Either increase the proxy_buffer_size in nginx or implement the redis session storage (see https://pusher.github.io/oauth2_proxy/configuration#redis-storage)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this note is definitely relevant but maybe the changelog is the wrong place? WDYT @JoelSpeed @steakunderscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also been added to the Azure section of the Authentication documentation in this pull request. Obviously though this is very much worth highlighting to people as I'd imagine it will break a lot of configurations so if there is some where else we can put it to draw peoples attention to it let me know.

Copy link
Member

Choose a reason for hiding this comment

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

I am happy to have a note like this in the changelog, it's important that people are aware of changes like this that may break their setups.

It's the sort of thing I'll copy out to highlight it in the release highlights when I cut the next release

Copy link
Member

@loshz loshz Oct 17, 2019

Choose a reason for hiding this comment

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

Totally happy for it to stay in the changelog 🙂

Copy link
Member

@loshz loshz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@JoelSpeed JoelSpeed merged commit 86977f7 into oauth2-proxy:master Oct 17, 2019
jjo added a commit to vmware-archive/kube-prod-runtime that referenced this pull request Apr 12, 2020
oauth2-proxy wasn't working with oauth2-proy 5.x.x
until I tried with 4.0.0, this smells like related
to a ~recent AD api change.
NOTE that kubeprod is still using old AD api, see [2] below.

Refs:
- [1] "Add IDToken for Azure provider #258"
      oauth2-proxy/oauth2-proxy#258
- [2] "Switch Azure AD graph API to Microsoft Graph API"
      oauth2-proxy/oauth2-proxy@7f72a22
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.

6 participants