1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-23 00:40:46 +02:00
Commit Graph

59 Commits

Author SHA1 Message Date
67501f004f Implement refresh relying on obtaining lock 2021-12-06 14:05:58 +00:00
327211cec9 Refreshing with an invalid session should work
I would like this test to pass, but it currently doesn't. With the 
current implementation, there is a race, if the session is locked, but 
releases before the "handleObtainLockError" starts, then you'll get an 
error, which is not desirable
2021-12-03 23:44:18 +00:00
1478fefe92 Remove lock release via peek
This doesn't seem right, its not what I'd expect from the session store 
implemented locks.

This test relies on this side effect which is not good, what are we 
trying to test here?
2021-12-03 23:42:42 +00:00
b734de16e6 Refactor refreshSession method to reduce number of return 2021-12-03 23:07:40 +00:00
2781ea1c95 Try to wait for lock, when obtaining lock failed 2021-12-03 23:07:40 +00:00
360c753d6f Remove unnecessary err variable definition 2021-12-03 23:07:39 +00:00
0cb8d23222 Simplify for loop for waiting for lock 2021-12-03 23:07:38 +00:00
d9e0933e54 Move validateSession back into refreshSessionIfNeeded 2021-12-03 23:06:46 +00:00
ad8ce2f6a4 Add concurrent requests tests 2021-12-03 23:06:45 +00:00
c5ea345daf Add tests, which consider session lock 2021-12-03 23:06:44 +00:00
fca2d76f33 Fix tests for stored_session.go in middleware 2021-12-03 23:06:43 +00:00
d8663a19a9 Remove unnecessary log output 2021-12-03 23:06:42 +00:00
a8de9862cd Update logger message 2021-12-03 23:06:41 +00:00
88ab07930e Update update session from store 2021-12-03 23:06:41 +00:00
ccd7a91b2b Add more specific error when updating from store 2021-12-03 23:06:40 +00:00
c6d8cd1ea4 Remove one return statement in getValidatedSession 2021-12-03 23:06:39 +00:00
86ba2f41ce Refactor StoredSessionHandler 2021-12-03 23:06:38 +00:00
518e619289 Move session locking to refreshSessionIfNeeded method 2021-12-03 23:06:37 +00:00
76e3cb3e9a Use const for delay and expire time 2021-12-03 23:06:36 +00:00
0f545e14d4 Lock session state when refreshing 2021-12-03 23:06:35 +00:00
d8deaa124b Improve error message when no cookie is found 2021-10-13 19:08:11 +01:00
ccbb98acd9 fix(1356): test if session variable is null (#1357)
* fix(1356): test if session variable is null

* fix(1356): adding changelog

Co-authored-by: Hedi Harzallah <hharzalla@talend.com>
2021-09-09 12:12:29 +01:00
8967873659 Updated dependency versions which include CVE fixes (#1276)
* switched to github.com/golang-jwt/jwt and updated golang.org/x/crypto to include CVE fixes

* added #1276 to changelog

Co-authored-by: Joshua Vécsei <git@vecsei.me>
2021-07-29 17:45:41 +01:00
0b4bc36554 Upgrade go-oidc to v3 (#1264) 2021-07-17 09:55:05 -07:00
ff914d7e17 Use ErrNotImplemented in default refresh implementation 2021-06-22 17:04:42 -07:00
593125152d Standarize provider refresh implemention & logging 2021-06-22 17:04:30 -07:00
7fa6d2d024 Manage session time fields centrally 2021-06-21 21:54:52 -07:00
7e80e5596b RefreshSessions immediately when called 2021-06-21 21:54:52 -07:00
41cd418a5d Fix - Refresh Session not working for multiple cookies (#1209) (#1227)
* Fix - Refresh Session not working for multiple cookies (#1209)

* added comments for flattenheaders fix

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Updated Changelog.md

Co-authored-by: Rishi Kambil <rishi.kambil@lntinfotech.com>
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
2021-06-09 10:22:33 +01:00
f648c54d87 Add redis lock feature (#1063)
* Add sensible logging flag to default setup for logger

* Add Redis lock

* Fix default value flag for sensitive logging

* Split RefreshSessionIfNeeded in two methods and use Redis lock

* Small adjustments to doc and code

* Remove sensible logging

* Fix method names in ticket.go

* Revert "Fix method names in ticket.go"

This reverts commit 408ba1a1a5.

* Fix methods name in ticket.go

* Remove block in Redis client get

* Increase lock time to 1 second

* Perform retries, if session store is locked

* Reverse if condition, because it should return if session does not have to be refreshed

* Update go.sum

* Update MockStore

* Return error if loading session fails

* Fix and update tests

* Change validSession to session in docs and strings

* Change validSession to session in docs and strings

* Fix docs

* Fix wrong field name

* Fix linting

* Fix imports for linting

* Revert changes except from locking functionality

* Add lock feature on session state

* Update from master

* Remove errors package, because it is not used

* Only pass context instead of request to lock

* Use lock key

* By default use NoOpLock

* Remove debug output

* Update ticket_test.go

* Map internal error to sessions error

* Add ErrLockNotObtained

* Enable lock peek for all redis clients

* Use lock key prefix consistent

* Fix imports

* Use exists method for peek lock

* Fix imports

* Fix imports

* Fix imports

* Remove own Dockerfile

* Fix imports

* Fix tests for ticket and session store

* Fix session store test

* Update pkg/apis/sessions/interfaces.go

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Do not wrap lock method

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

* Use errors package for lock constants

* Use better naming for initLock function

* Add comments

* Add session store lock test

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Add cookies after saving session

* Add mock lock

* Fix imports for mock_lock.go

* Store mock lock for key

* Apply elapsed time on mock lock

* Check if lock is initially applied

* Reuse existing lock

* Test all lock methods

* Update CHANGELOG.md

* Use redis client methods in redis.lock for release an refresh

* Use lock key suffix instead of prefix for lock key

* Add comments for Lock interface

* Update comment for Lock interface

* Update CHANGELOG.md

* Change LockSuffix to const

* Check lock on already loaded session

* Use global var for loadedSession in lock tests

* Use lock instance for refreshing and releasing of lock

* Update possible error type for Refresh

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
2021-06-02 19:08:19 +01:00
64f0a9f580 Reinstate preferEmailToUser behaviour for basic auth sessions 2021-03-22 13:13:26 +00:00
c1267bb92d Request ID Logging (#1087)
* Add RequestID to the RequestScope

* Expose RequestID to auth & request loggers

* Use the RequestID in templated HTML pages

* Allow customizing the RequestID header

* Document new Request ID support

* Add more cases to scope/requestID tests

* Split Get vs Generate RequestID funtionality

* Add {{.RequestID}} to the request logger tests

* Move RequestID management to RequestScope

* Use HTML escape instead of sanitization for Request ID rendering
2021-03-21 18:20:57 +00:00
602dac7852 Move Logging to Middleware Package (#1070)
* Use a specialized ResponseWriter in middleware

* Track User & Upstream in RequestScope

* Wrap responses in our custom ResponseWriter

* Add tests for logging middleware

* Inject upstream metadata into request scope

* Use custom ResponseWriter only in logging middleware

* Assume RequestScope is never nil
2021-03-06 17:27:16 +00:00
220b3708fc Add support for setting groups on session when using basic auth (#1064)
* Add support for setting groups on session when using basic auth

* Refactoring based on feedback

* Attribution
2021-02-25 13:02:23 -08:00
a7c8a233ba Add Prometheus metrics endpoint
Add the Prometheus http.Handler to serve metrics at MetricsPath ("/metrics"
by default). This allows Prometheus to scrape metrics from OAuth2 Proxy.

Add a new middleware NewRequestMetrics and attach it to the preAuth
chain. This will collect metrics on all requests made to OAuth2 Proxy

Collapse some calls to Prinf() and os.Exit(1) to Fatalf as they are
equivalent. main() has a strict 50 lines limit so brevity in these
calls appreciated
2021-02-15 13:45:26 +00:00
b6cca79cb9 Ensure errors in tests are logged to the GinkgoWriter 2021-02-10 19:50:04 +00:00
c3f31b4dd5 Flatten array-based response headers 2021-02-03 16:48:26 -08:00
b541805dc1 Use comma separated multiple values for header (#799)
* Use comma separated value for multiple claims

* Fix lint error

* Fix more tests

* Fix one more test

* Always flatten the headers

* Ensure we test the real multi-groups

* Only update map when necessary

* Update CHANGELOG

* Move to the right location of change log

* Fix blank line
2021-01-22 08:48:34 +00:00
f054682fb7 Make HTTPS Redirect middleware Reverse Proxy aware 2021-01-16 13:55:48 -08:00
6fb3274ca3 Refactor organization of scope aware request utils
Reorganized the structure of the Request Utils due to their widespread use
resulting in circular imports issues (mostly because of middleware & logger).
2021-01-16 13:55:48 -08:00
b625de9490 Track the ReverseProxy option in the request Scope
This allows for proper handling of reverse proxy based headers throughout
the lifecycle of a request.
2021-01-16 13:55:48 -08:00
5f8f856260 Remove failed bearer tokens from logs 2020-11-28 10:25:12 -08:00
22f60e9b63 Generalize and extend default CreateSessionFromToken 2020-11-28 10:25:12 -08:00
44fa8316a1 Aggregate error logging on JWT chain failures 2020-11-28 10:25:12 -08:00
3e9717d489 Decouple TokenToSession from OIDC & add a generic VerifyFunc 2020-11-28 10:25:11 -08:00
6743e3991d Add header injector middlewares 2020-10-07 18:24:58 +01:00
3fa42edb73 Fix import path for v7 (#800)
* fix import path for v7

find ./ -name "*.go" | xargs sed -i -e 's|"github.com/oauth2-proxy/oauth2-proxy|"github.com/oauth2-proxy/oauth2-proxy/v7|'

* fix module path

* go mod tidy

* fix installation docs

* update CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
2020-09-29 17:44:42 +01:00
29b24793e3 Use X-Forwarded-Host consistently 2020-08-31 08:31:45 -07:00
b6e78efc1e Add x-oauth-basic nosec annotation & address gosec unhandled errors 2020-08-10 15:15:16 -07:00
d69fd6af22 Allow Logging to stdout with separate Error Log Channel (#718)
* Add dedicated error logging writer

* Document new errors to stdout flag

* Update changelog

* Thread-safe the log buffer

* Address feedback

* Remove duplication by adding log level

* Clean up error formatting

* Apply suggestions from code review

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
2020-08-10 11:44:08 +01:00