-
Notifications
You must be signed in to change notification settings - Fork 171
THREESCALE-11441 only validate oidc setting if authentication method is set to oidc #1568
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
Open
tkan145
wants to merge
1
commit into
3scale:master
Choose a base branch
from
tkan145:THREESCALE-11441
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,13 +21,22 @@ _M.discovery = require('resty.oidc.discovery').new() | |||||
|
|
||||||
| local function load_service(service) | ||||||
| if not service or not service.proxy then return nil end | ||||||
| local result = _M.discovery:call(service.proxy.oidc_issuer_endpoint) | ||||||
| local proxy = service.proxy | ||||||
|
|
||||||
| if result and service.id then | ||||||
| result.service_id = service.id | ||||||
| -- Only fetch OIDC configuration if authentication method is set to 'oidc' | ||||||
| local authentication = proxy.authentication_method or service.backend_version | ||||||
|
|
||||||
| if authentication and authentication == 'oidc' then | ||||||
| local result = _M.discovery:call(service.proxy.oidc_issuer_endpoint) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. proxy already declared on the top
Suggested change
|
||||||
|
|
||||||
| if result and service.id then | ||||||
| result.service_id = service.id | ||||||
| end | ||||||
|
|
||||||
| return result | ||||||
| end | ||||||
|
|
||||||
| return result | ||||||
| return nil | ||||||
| end | ||||||
|
|
||||||
| function _M.call(...) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,25 @@ describe('OIDC Configuration loader', function() | |
| assert(loader.call(config)) | ||
| end) | ||
|
|
||
| it('ignores config with oidc_issuer_endpoint but not oidc authentication mode', function() | ||
| local config = cjson.encode{ | ||
| services = { | ||
| { id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]' } }, | ||
| { id = 42 }, | ||
| } | ||
| } | ||
|
|
||
| assert(loader.call(config)) | ||
| end) | ||
|
|
||
| it('forwards all parameters', function() | ||
| assert.same({'{"oidc":[]}', 'one', 'two'}, { loader.call('{}', 'one', 'two')}) | ||
| end) | ||
|
|
||
| it('gets openid configuration', function() | ||
| local config = { | ||
| services = { | ||
| { id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]' } }, | ||
| { id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]', authentication_method = 'oidc' }}, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -58,7 +69,8 @@ describe('OIDC Configuration loader', function() | |
| { | ||
| "id": 21, | ||
| "proxy": { | ||
| "oidc_issuer_endpoint": "https://user:[email protected]" | ||
| "oidc_issuer_endpoint": "https://user:[email protected]", | ||
| "authentication_method": "oidc" | ||
| } | ||
| } | ||
| ], | ||
|
|
@@ -97,5 +109,50 @@ describe('OIDC Configuration loader', function() | |
|
|
||
| loader.call(cjson.encode(config)) | ||
| end) | ||
|
|
||
| it('ignore openid configuration if authentication_method is not oidc', function() | ||
| local config = { | ||
| services = { | ||
| { id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]', authentication_method = '1' }}, | ||
| } | ||
| } | ||
|
|
||
| test_backend | ||
| .expect{ url = "https://example.com/.well-known/openid-configuration" } | ||
| .respond_with{ | ||
| status = 200, | ||
| headers = { content_type = 'application/json' }, | ||
| body = [[{"jwks_uri":"http://example.com/jwks","issuer":"https://example.com"}]], | ||
| } | ||
|
|
||
| test_backend | ||
| .expect{ url = "http://example.com/jwks" } | ||
| .respond_with{ | ||
| status = 200, | ||
| headers = { content_type = 'application/json' }, | ||
| body = [[{"keys":[]}]], | ||
| } | ||
|
|
||
| local oidc = loader.call(cjson.encode(config)) | ||
| local expected_oidc = cjson.decode([[ | ||
| { | ||
| "services": [ | ||
| { | ||
| "id": 21, | ||
| "proxy": { | ||
| "oidc_issuer_endpoint": "https://user:[email protected]", | ||
| "authentication_method": "1" | ||
| } | ||
| } | ||
| ], | ||
| "oidc": [ | ||
| { | ||
| "service_id": 21 | ||
| } | ||
| ] | ||
| } | ||
| ]]) | ||
| assert.same(expected_oidc, cjson.decode(oidc)) | ||
| end) | ||
| end) | ||
| end) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -251,7 +251,10 @@ describe('Configuration Remote Loader V2', function() | |||||
| environment = 'sandbox', | ||||||
| content = { | ||||||
| id = 42, backend_version = 1, | ||||||
| proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' } | ||||||
| proxy = { | ||||||
| authentication_method= 'oidc', | ||||||
| oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -311,6 +314,28 @@ UwIDAQAB | |||||
| } }, | ||||||
| }, config.oidc) | ||||||
| end) | ||||||
|
|
||||||
| it('ingore OIDC configuration when authentication_method is not oidc', function() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| test_backend.expect{ url = 'http://example.com/admin/api/services/42/proxy/configs/staging/latest.json' }. | ||||||
| respond_with{ status = 200, body = cjson.encode( | ||||||
| { | ||||||
| proxy_config = { | ||||||
| version = 2, | ||||||
| environment = 'sandbox', | ||||||
| content = { | ||||||
| id = 42, backend_version = 1, | ||||||
| proxy = { | ||||||
| authentication_method= '1', | ||||||
| oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| ) } | ||||||
|
|
||||||
| local config = assert(loader:config({ id = 42 }, 'staging', 'latest')) | ||||||
| assert.is_nil(config.oidc) | ||||||
| end) | ||||||
| end) | ||||||
|
|
||||||
| describe(':index_per_service', function() | ||||||
|
|
@@ -580,7 +605,10 @@ UwIDAQAB | |||||
| { | ||||||
| proxy_config = { | ||||||
| content = { | ||||||
| proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' } | ||||||
| proxy = { | ||||||
| authentication_method= 'oidc', | ||||||
| oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -730,7 +758,10 @@ UwIDAQAB | |||||
| content = { | ||||||
| id = 2, | ||||||
| backend_version = 1, | ||||||
| proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' } | ||||||
| proxy = { | ||||||
| authentication_method= 'oidc', | ||||||
| oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -920,7 +951,10 @@ UwIDAQAB | |||||
| content = { | ||||||
| id = 2, | ||||||
| backend_version = 1, | ||||||
| proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' } | ||||||
| proxy = { | ||||||
| authentication_method= 'oidc', | ||||||
| oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment could go away by simply extracting a guard from the code below:
The
if authenticationpart seems redundant anyway (nilis already unequal to 'oidc').Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
authenticationcan take the following values:1: user_key2: app_id/app_keyoidc: OIDCnil: But if theoidc_issuer_endpointis provided, then in this case we don't want to query OIDC endpointTherefore, an if statement is needed.