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

236 Commits

Author SHA1 Message Date
ce750e9b30 PKCE Support (#1541)
* Add the allowed_email_domains and the allowed_groups on the auth_request endpoint + support standard wildcard char for validation with sub-domain and email-domain.

Signed-off-by: Valentin Pichard <github@w3st.fr>

* Fix provider data initialisation

* PKCE Support

Adds Code Challenge PKCE support (RFC-7636) and partial
Authorization Server Metadata (RFC-8414) for detecting PKCE support.

- Introduces new option `--force-code-challenge-method` to force a
specific code challenge method (either `S256` or `plain`) for instances
when the server has not implemented RFC-8414 in order to detect
PKCE support on the discovery document.
- In all other cases, if the PKCE support can be determined during discovery
then the `code_challenge_methods_supported` is used and S256 is always
preferred.
- The force command line argument is helpful with some providers like Azure
who supports PKCE but does not list it in their discovery document yet.
- Initial thought was given to just always attempt PKCE since according to spec
additional URL parameters should be dropped by servers which implemented
OAuth 2, however other projects found cases in the wild where this causes 500
errors by buggy implementations.
See: https://github.com/spring-projects/spring-security/pull/7804#issuecomment-578323810
- Due to the fact that the `code_verifier` must be saved between the redirect and
callback, sessions are now created when the redirect takes place with `Authenticated: false`.
The session will be recreated and marked as `Authenticated` on callback.
- Individual provider implementations can choose to include or ignore code_challenge
and code_verifier function parameters passed to them

Note: Technically speaking `plain` is not required to be implemented since
oauth2-proxy will always be able to handle S256 and servers MUST implement
S256 support.
> If the client is capable of using "S256", it MUST use "S256", as "S256"
> is Mandatory To Implement (MTI) on the server.  Clients are permitted
> to use "plain" only if they cannot support "S256" for some technical
> reason and know via out-of-band configuration that the server supports
> "plain".
Ref: RFC-7636 Sec 4.2

oauth2-proxy will always use S256 unless the user explicitly forces `plain`.

Fixes #1361

* Address PR comments by moving pkce generation

* Make PKCE opt-in, move to using the Nonce generater for code verifier

* Make PKCE opt-in, move to using the Nonce generater for code verifier

* Encrypt CodeVerifier in CSRF Token instead of Session

- Update Dex for PKCE support
- Expose HTTPBin for further use cases

* Correct the tests

* Move code challenges into extra params

* Correct typo in code challenge method

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

* Correct the extra space in docs

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

* Address changelog and new line nits

* Add generated docs

Co-authored-by: Valentin Pichard <github@w3st.fr>
Co-authored-by: Joel Speed <joel.speed@hotmail.co.uk>
2022-03-13 10:08:33 +00:00
63727103db Support for passing through URL query parameters from /oauth2/start to the ID provider's login URL.
You must explicitly configure oauth2-proxy (alpha config only) with which parameters are allowed to pass through, and optionally provide an allow-list of valid values and/or regular expressions for each one.  Note that this mechanism subsumes the functionality of the "prompt", "approval_prompt" and "acr_values" legacy configuration options, which must be converted to the equivalent YAML when running in alpha config mode.
2022-02-19 16:11:09 +00:00
1f992b3f87 Integrate new provider verifier into providers 2022-02-19 15:37:57 +00:00
ed3892296e Move OIDC IDToken verifier behind interface 2022-02-19 15:37:54 +00:00
979c3e8cbc Move internal OIDC package to providers package 2022-02-19 15:37:53 +00:00
4eb2a35aa8 Fix provider data initialisation 2022-02-16 16:53:43 +00:00
d162b018a8 Move provider initialisation into providers package 2022-02-16 10:38:05 +00:00
967051314e Integrate claim extractor into providers 2022-02-16 10:28:33 +00:00
25371ea4af improved audience handling to support client credentials access tokens without aud claims (#1204)
* implementation draft

* add cfg options skip-au-when-missing && client-id-verification-claim; enhance the provider data verification logic for sake of the added options

* refactor configs, added logging and add additional claim verification

* simplify logic by just having one configuration similar to oidc-email-claim

* added internal oidc token verifier, so that aud check behavior can be managed with oauth2-proxy and is compatible with extra-jwt-issuers

* refactored verification to reduce complexity

* refactored verification to reduce complexity

* added docs

* adjust tests to support new OIDCAudienceClaim and OIDCExtraAudiences options

* extend unit tests and ensure that audience is set with the value of aud claim configuration

* revert filemodes and update docs

* update docs

* remove unneccesary logging, refactor audience existence check and added additional unit tests

* fix linting issues after rebase on origin/main

* cleanup: use new imports for migrated libraries after rebase on origin/main

* adapt mock in keycloak_oidc_test.go

* allow specifying multiple audience claims, fixed bug where jwt issuers client id was not the being considered and fixed bug where aud claims with multiple audiences has broken the whole validation

* fixed formatting issue

* do not pass the whole options struct to minimize complexity and dependency to the configuration structure

* added changelog entry

* update docs

Co-authored-by: Sofia Weiler <sofia.weiler@aoe.com>
Co-authored-by: Christian Zenker <christian.zenker@aoe.com>
2022-02-15 16:12:22 +00:00
11699a822a Add ValidateSession function to LoginGovProvder to include Auth Header (#1509)
* Add ValidateSession function to LoginGovProvder to include Auth Header

* Update CHANGELOG for PR 1509

* Update logingov_test to include ValidationURL
2022-02-04 09:22:33 +00:00
0fa8fca276 Update ADFS to new jwt lib 2021-12-01 19:16:42 -08:00
bdfca925a3 Handle UPN fallback when profileURL isn't set 2021-12-01 19:08:15 -08:00
1621ea3bba ADFS supports IDToken nonce, use it 2021-12-01 19:08:15 -08:00
4980f6af7d Use upn claim as a fallback in Enrich & Refresh
Only when `email` claim is missing, fallback to `upn` claim which may have it.
2021-12-01 19:08:10 -08:00
a53198725e Use upn as EmailClaim throughout ADFSProvider
By only overriding in the EnrichSession, any Refresh calls
would've overriden it with the `email` claim.
2021-12-01 19:06:02 -08:00
6e54ac2745 Update LinkedIn provider validate URL (#1444)
* update LinkedIn validate URL

Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>

* update changelog

Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>

* update failed unit test

Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
2021-11-19 21:36:33 +00:00
fd5e23e1c5 linkedidn: Update provider to v2 (#1315)
* linkedin: Update provider to v2

* changelog: Add change
2021-10-04 15:58:25 +01:00
e4a8c98e1b Preserve Nickname around refreshes 2021-09-25 16:49:30 -07:00
95f9de5979 Preserve projects after RefreshSession
RefreshSession will override session.Groups with the new
`groups` claims. We need to preserve all `project:` prefixed
groups and reattach them post refresh.
2021-09-25 16:49:30 -07:00
11c2177f18 Use nickname claim as User for GitLab
Previously this was only done in the `EnrichSession` stage
which would've missed Bearer usages & `RefreshSession`
would've overriden the User to the Subject.
2021-09-25 16:49:25 -07:00
c84a5a418f Adjust GitLab options configuration 2021-09-25 16:48:48 -07:00
3092941c57 Use OIDC as base of Gitlab provider 2021-09-25 16:48:48 -07:00
e6223383e5 update keycloak oidc provider and add unit tests 2021-08-02 11:39:50 +02:00
ab54de38cc Extract roles from Keycloak Access Tokens 2021-07-30 09:46:13 +02:00
4c0beb373f Add keycloak-oidc provider based on OIDCProvider 2021-07-30 09:46:13 +02: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
a14c0c2121 Added ADFS Provider 2021-06-13 10:19:56 +02:00
7eeaea0b3f Support nonce checks in OIDC Provider (#967)
* Set and verify a nonce with OIDC

* Create a CSRF object to manage nonces & cookies

* Add missing generic cookie unit tests

* Add config flag to control OIDC SkipNonce

* Send hashed nonces in authentication requests

* Encrypt the CSRF cookie

* Add clarity to naming & add more helper methods

* Make CSRF an interface and keep underlying nonces private

* Add ReverseProxy scope to cookie tests

* Align to new 1.16 SameSite cookie default

* Perform SecretBytes conversion on CSRF cookie crypto

* Make state encoding signatures consistent

* Mock time in CSRF struct via Clock

* Improve InsecureSkipNonce docstring
2021-04-21 10:33:27 +01:00
05c3fa7601 Fix GitLab CVE test case 2021-03-25 10:29:17 -07:00
0279fa7dff Merge pull request from GHSA-652x-m2gr-hppm
* Populate session Groups from userinfo response

* Fix: gitlab tests

Co-authored-by: Wilfried OLLIVIER <wollivier@bearstech.com>
2021-03-25 17:20:45 +00:00
73d9f3809e Panic with GitLab project repository auth (#1113)
* panic with GitLab project repository auth

* /api/v4/projects/:id can return nil permissions

Signed-off-by: Piers Harding <piers@ompka.net>

* Add GitLab test for group no access

Signed-off-by: Piers Harding <piers@ompka.net>
2021-03-25 08:48:20 -07:00
f3209a40e1 extract email from id_token for azure provider (#914)
* extract email from id_token for azure provider

this change fixes a bug when --resource is specified with non-Graph
api and the access token destined to --resource is used to call Graph
api

* fixed typo

* refactor GetEmailAddress to EnrichSessionState

* make getting email from idtoken best effort and fall back to previous behavior when it's absent

* refactor to use jwt package to extract claims

* fix lint

* refactor unit tests to use test table
refactor the get email logic from profile api

* addressing feedback

* added oidc verifier to azure provider and extract email from id_token if present

* fix lint and codeclimate

* refactor to use oidc verifier to verify id_token if oidc is configured

* fixed UT

* addressed comments

* minor refactor

* addressed feedback

* extract email from id_token first and fallback to access token

* fallback to access token as well when id_token doesn't have email claim

* address feedbacks

* updated change log!
2021-03-09 20:53:15 -08:00
9cea4ea89b Update golangci-lint version in CI workflow 2021-02-17 20:25:37 +00:00
b6cca79cb9 Ensure errors in tests are logged to the GinkgoWriter 2021-02-10 19:50:04 +00:00
57640764c0 Use logger for sensitive data logging to be able to disable it (#1002)
* Add sensible logging flag to default setup for logger

* Use logger instead of fmt for info logging with sensible data

* Remove sensible logging flag

* Update CHANGELOG.md

Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
2021-01-20 19:56:13 +00:00
4b28e6886c Handle ValidateURL fallback for nil & empty struct cases 2020-12-24 14:04:20 -08:00
816d9a4566 Use a generic http.HandlerFunc in Keycloak tests 2020-12-24 14:04:19 -08:00
f07a5630f1 Update Keycloak documentation 2020-12-24 14:04:19 -08:00
138a6b128a Use ProfileURL for userinfo EnrichSession calls in Keycloak 2020-12-24 14:04:19 -08:00
0886f8035c Move all Keycloak unit tests to Ginkgo 2020-12-24 14:04:19 -08:00
3369799853 Migrate Keycloak to EnrichSession & support multiple groups 2020-12-24 14:04:19 -08:00
d2ffef2c7e Use global OIDC fields for Gitlab 2020-12-21 16:54:12 -08:00
42f6cef7d6 Improve OIDC error handling 2020-12-21 16:53:05 -08:00
ea5b8cc21f Support non-list and complex groups 2020-12-21 16:52:18 -08:00
eb56f24d6d Deprecate UserIDClaim in config and docs 2020-12-21 16:52:17 -08:00