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 initial session-store interface and implementation #147

Merged
merged 21 commits into from
May 20, 2019
Merged

Conversation

JoelSpeed
Copy link
Member

@JoelSpeed JoelSpeed commented May 7, 2019

Description

This adds a SessionStore interface that can/will be used by the proxy to provide both client-side and server-side session storage implementations.

This PR is mainly copying and pasting code without much tidy up (especially in the cookie store implementation) but does add some tests to the SessionStore using ginkgo and gomega.

I haven't implemented using the SessionStore in the proxy itself yet so this PR should make no functional changes (bar the config changes that have been made).

I will follow with a separate PR to implement the SessionStore in the main proxy.

CC @brianv0

Motivation and Context

We want to add server side sessions, see issue #138

How Has This Been Tested?

Test suite added for SessionStore to ensure cookies have correct values set and Save/Load cycle produces the same session.

I manually tested that the configuration loading changes still work, have performed full authentication flow using image built from this branch

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.

@JoelSpeed JoelSpeed requested review from loshz and a team May 7, 2019 13:15
pkg/apis/options/cookie.go Show resolved Hide resolved
pkg/apis/sessions/interfaces.go Show resolved Hide resolved
@loshz
Copy link
Contributor

loshz commented May 9, 2019

This is really nice, idiomatic code 👍

Couple of questions:

  1. Do we need to consider protecting against race conditions on the cookie store? Or will it never be called concurrently?
  2. you mentioned that the cookie store is mainly copy/paste - where did it originate?
  3. Do we want to test this in some sort of staging env?

@JoelSpeed
Copy link
Member Author

JoelSpeed commented May 9, 2019

Do we need to consider protecting against race conditions on the cookie store? Or will it never be called concurrently?

It definitely can be called concurrently, but at the moment we don't protect against that at all (in master that is). I'm not sure how you could lock across multiple instances to prevent it being called concurrently for a particular user so I was planning to just leave this pretty much as is. This PR plus #148 should be functionally equivalent to the existing behaviour.

I would like to add a lockable session store implementation at some point but that will likely have to be a server side session store implementation.

The only reason this would cause a problem being called concurrently is if you are using session refreshing with the upstream provider who rotates keys (looking at OIDC here) on every refresh, then you can end up with users being logged out periodically unless you do some caching fun in front of the proxy. This has been on my mind for a while... 😅

you mentioned that the cookie store is mainly copy/paste - where did it originate?

If you check #148, the actual implementation should just be all the code (pretty much) deleted from oauth2_proxy.go and moved into pkg/sessions/cookie/session_store.go

Do we want to test this in some sort of staging env?

Im planning to build an image from #148 and will deploy it somewhere for testing, maybe internally at Pusher 🤔 I'll make sure we test it for a few days and see that everything is working as expected before we merge any of this code. I would like to (long term) set up so proper acceptance/black box tests for this project though I'm not entirely sure how to test projects with UIs, will need some research doing.

if value != "" {
value = cookie.SignedValue(s.CookieSecret, s.CookieName, value, now)
}
c := s.makeCookie(req, s.CookieName, value, expiration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the signature of makeCookie include a now time.Time?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually made the same change in #148, do you think I should move the change across to this PR?

https://github.com/pusher/oauth2_proxy/pull/148/files#diff-6795d5c635b0b599acbb55d7272d11f8R114

// interface that stores sessions in client side cookies
type SessionStore struct {
CookieCipher *cookie.Cipher
CookieDomain string
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be sending along the options.CookieOptions struct? This might make makeCookie a bit more usable across different store implementations

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a great idea! If we keep the CookieOptions struct we can move makeCookie to a shared package and make it reusable, I'll do that and join it to #148

@brianv0 brianv0 mentioned this pull request May 11, 2019
3 tasks
wonderhoss
wonderhoss previously approved these changes May 17, 2019
Copy link
Contributor

@wonderhoss wonderhoss 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
Copy link
Member Author

I've rebased, upped the linter timeout to stop the tests timing out, added a changelog entry and started a documentation page for the session storage stuff so will need another quick review on that last two commits before merge

@JoelSpeed JoelSpeed requested a review from wonderhoss May 20, 2019 09:14
@JoelSpeed JoelSpeed merged commit 17e97ab into master May 20, 2019
@JoelSpeed JoelSpeed deleted the session-store branch May 10, 2020 09:10
Jing-ze pushed a commit to Jing-ze/oauth2-proxy that referenced this pull request Nov 19, 2024
Signed-off-by: bitliu <bitliu@tencent.com>
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.

4 participants