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

Use encoding/json for SessionState serialization #63

Merged
merged 9 commits into from Mar 20, 2019

Conversation

yaegashi
Copy link
Contributor

@yaegashi yaegashi commented Feb 14, 2019

Description

This PR implements more generic way to serialize session state to be stored in browser cookie.

  • Use json.Marshal/Unmarshal in EncodeSessionState/DecodeSessionState.
  • Remove accountInfo function. It's always serialized in JSON.
  • Support legacy session state cookies generated by older versions.
  • Use json:",omitempty" tag and SessionStateJSON struct to encode SessionState without exposing unused members.
  • Update existing tests to adapt to changes above.
  • Add table driven tests in TestEncodeSessionState/DecodeSessionState.

Motivation and Context

Using JSON greatly simplifies implementation of SessionState serialization and makes it much easier to extend in future, like adding IDToken which recently happened.

For more specific example, I have a plan to enable azure provider to pass session user's group information retrieved from Azure AD to the upstream using X-Forwarded-Groups header.

How Has This Been Tested?

  • All existing unit tests passed.
  • New table driven tests include detailed checks for JSON and legacy serialization.

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.

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.

Looks pretty good in general, one minor thing I picked up on about the non-ciphered case maybe not preserving existing behaviour?

It might be nice to have a legacyDecode that would decode older sessions if they don't unmarshal into JSON (basically the original DecodeSessionState), this would mean we don't force people to re-authenticate if they already have an existing session. If we do this I would add a TODO to then remove it in a couple of releases time, WDYT @yaegashi @syscll? I'm not 100% certain this is worth doing but might be a slightly smoother upgrade for people

providers/session_state.go Outdated Show resolved Hide resolved
@loshz
Copy link
Member

loshz commented Feb 19, 2019

@yaegashi great job on this 👍

@JoelSpeed I agree with what you're saying, but I don't think re-authenticating is the worst thing?

@yaegashi yaegashi force-pushed the session-state-json branch 2 times, most recently from 7d6fa21 to 4101e11 Compare February 19, 2019 17:18
@yaegashi
Copy link
Contributor Author

@JoelSpeed @syscll Thanks for the comments. Actually I did't think it's so important to keep cookie compatibility across versions either, but I added support for older session cookies and a bit more strict tests anyway.

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.

Thanks for adding the legacy decode, I think that's a great way to keep faith in the project!
Couple of minor things picked up, one ignore error by the looks of it which we should fix and then the annoying encoding of the zero value of time.

Looks pretty good but I'd like to have a few days to think and see if I can come up with a workaround for this zero time problem that would mean it doesn't zero to a "wrong" value and get encoded. Let me know if you have any ideas!

providers/session_state.go Outdated Show resolved Hide resolved
providers/session_state_test.go Outdated Show resolved Hide resolved
@costelmoraru
Copy link
Contributor

Hi @yaegashi ,
any chance you can incorporate in this PR also the encryption/decryption of the user and email part of the session state, since your PR is a big change in the serialisation method?
Can you please have a look at #67 ?

@yaegashi
Copy link
Contributor Author

yaegashi commented Mar 5, 2019

@costelmoraru Your changes will break the cookie compatibility across versions this PR tries to honor. Please make it stay as a separate PR for now. You might need to implement the transition from unencrypted cookies.

@JoelSpeed What do you think about it? And I think the current code of this PR is ready for your review regarding time.Time zero value workaround. Please take a look in order to make this PR done!

JoelSpeed
JoelSpeed previously approved these changes Mar 5, 2019
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.

I think for now it is best to leave the changes from #67 out of this and follow up with a separate PR, this is primarily because this PR is large enough already and is ready at this point.

@yaegashi The only thing I need now is an update to the Changelog detailing the changes you have made in this PR and I'm happy to get this merged

@yaegashi
Copy link
Contributor Author

yaegashi commented Mar 6, 2019

@JoelSpeed Updated CHANGELOG.md and rebased to master. You could amend my log description if needed.

CI failure has persisted since yesterday? It seems something is wrong with google-api-go-client upstream.

@costelmoraru
Copy link
Contributor

@JoelSpeed can you please have this one merged into master?

@loshz
Copy link
Member

loshz commented Mar 19, 2019

Looks like there are some conflicts in the CHANGELOG that need resolving first.

@yaegashi
Copy link
Contributor Author

@JoelSpeed Please review and merge this.

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.

Looks great, thanks @yaegashi!!!

@JoelSpeed JoelSpeed merged commit 2070fae into oauth2-proxy:master Mar 20, 2019
@yaegashi yaegashi deleted the session-state-json branch March 20, 2019 18:55
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.

None yet

4 participants