Skip to content

Commit c39c30f

Browse files
committed
fix: only validate oidc setting if authentication method is set to oidc
1 parent da22d18 commit c39c30f

File tree

5 files changed

+108
-7
lines changed

5 files changed

+108
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Fixed
1111
- Correct FAPI header to `x-fapi-interaction-id` [PR #1557](https://github.com/3scale/APIcast/pull/1557) [THREESCALE-11957](https://issues.redhat.com/browse/THREESCALE-11957)
12+
- Only validate oidc setting if authentication method is set to oidc [PR #1568](https://github.com/3scale/APIcast/pull/1568) [THREESCALE-11441](https://issues.redhat.com/browse/THREESCALE-11441)
1213

1314
### Added
1415
- Update APIcast schema manifest [PR #1550](https://github.com/3scale/APIcast/pull/1550)

gateway/src/apicast/configuration_loader/oidc.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ _M.discovery = require('resty.oidc.discovery').new()
2121

2222
local function load_service(service)
2323
if not service or not service.proxy then return nil end
24+
local proxy = service.proxy
25+
26+
-- Only fetch OIDC configuration if authentication method is set to 'oidc'
27+
local authentication = proxy.authentication_method or service.backend_version
28+
29+
if authentication ~= 'oidc' then
30+
return nil
31+
end
32+
2433
local result = _M.discovery:call(service.proxy.oidc_issuer_endpoint)
2534

2635
if result and service.id then

gateway/src/apicast/configuration_loader/remote_v2.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ local function service_config_endpoint(portal_endpoint, service_id, env, version
103103
end
104104

105105
local function get_oidc_issuer_endpoint(proxy_content)
106-
return proxy_content.proxy and proxy_content.proxy.oidc_issuer_endpoint
106+
return proxy_content.proxy and (proxy_content.proxy.authentication_method == "oidc") and proxy_content.proxy.oidc_issuer_endpoint
107107
end
108108

109109
local function parse_proxy_configs(self, proxy_configs)

spec/configuration_loader/oidc_spec.lua

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@ describe('OIDC Configuration loader', function()
2424
assert(loader.call(config))
2525
end)
2626

27+
it('ignores config with oidc_issuer_endpoint but not oidc authentication mode', function()
28+
local config = cjson.encode{
29+
services = {
30+
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]' } },
31+
{ id = 42 },
32+
}
33+
}
34+
35+
assert(loader.call(config))
36+
end)
37+
2738
it('forwards all parameters', function()
2839
assert.same({'{"oidc":[]}', 'one', 'two'}, { loader.call('{}', 'one', 'two')})
2940
end)
3041

3142
it('gets openid configuration', function()
3243
local config = {
3344
services = {
34-
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]' } },
45+
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]', authentication_method = 'oidc' }},
3546
}
3647
}
3748

@@ -58,7 +69,8 @@ describe('OIDC Configuration loader', function()
5869
{
5970
"id": 21,
6071
"proxy": {
61-
"oidc_issuer_endpoint": "https://user:[email protected]"
72+
"oidc_issuer_endpoint": "https://user:[email protected]",
73+
"authentication_method": "oidc"
6274
}
6375
}
6476
],
@@ -97,5 +109,50 @@ describe('OIDC Configuration loader', function()
97109

98110
loader.call(cjson.encode(config))
99111
end)
112+
113+
it('ignore openid configuration if authentication_method is not oidc', function()
114+
local config = {
115+
services = {
116+
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://user:[email protected]', authentication_method = '1' }},
117+
}
118+
}
119+
120+
test_backend
121+
.expect{ url = "https://example.com/.well-known/openid-configuration" }
122+
.respond_with{
123+
status = 200,
124+
headers = { content_type = 'application/json' },
125+
body = [[{"jwks_uri":"http://example.com/jwks","issuer":"https://example.com"}]],
126+
}
127+
128+
test_backend
129+
.expect{ url = "http://example.com/jwks" }
130+
.respond_with{
131+
status = 200,
132+
headers = { content_type = 'application/json' },
133+
body = [[{"keys":[]}]],
134+
}
135+
136+
local oidc = loader.call(cjson.encode(config))
137+
local expected_oidc = cjson.decode([[
138+
{
139+
"services": [
140+
{
141+
"id": 21,
142+
"proxy": {
143+
"oidc_issuer_endpoint": "https://user:[email protected]",
144+
"authentication_method": "1"
145+
}
146+
}
147+
],
148+
"oidc": [
149+
{
150+
"service_id": 21
151+
}
152+
]
153+
}
154+
]])
155+
assert.same(expected_oidc, cjson.decode(oidc))
156+
end)
100157
end)
101158
end)

spec/configuration_loader/remote_v2_spec.lua

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ describe('Configuration Remote Loader V2', function()
251251
environment = 'sandbox',
252252
content = {
253253
id = 42, backend_version = 1,
254-
proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' }
254+
proxy = {
255+
authentication_method= 'oidc',
256+
oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/'
257+
}
255258
}
256259
}
257260
}
@@ -311,6 +314,28 @@ UwIDAQAB
311314
} },
312315
}, config.oidc)
313316
end)
317+
318+
it('ignore OIDC configuration when authentication_method is not oidc', function()
319+
test_backend.expect{ url = 'http://example.com/admin/api/services/42/proxy/configs/staging/latest.json' }.
320+
respond_with{ status = 200, body = cjson.encode(
321+
{
322+
proxy_config = {
323+
version = 2,
324+
environment = 'sandbox',
325+
content = {
326+
id = 42, backend_version = 1,
327+
proxy = {
328+
authentication_method= '1',
329+
oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/'
330+
}
331+
}
332+
}
333+
}
334+
) }
335+
336+
local config = assert(loader:config({ id = 42 }, 'staging', 'latest'))
337+
assert.is_nil(config.oidc)
338+
end)
314339
end)
315340

316341
describe(':index_per_service', function()
@@ -580,7 +605,10 @@ UwIDAQAB
580605
{
581606
proxy_config = {
582607
content = {
583-
proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' }
608+
proxy = {
609+
authentication_method= 'oidc',
610+
oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/'
611+
}
584612
}
585613
}
586614
}
@@ -730,7 +758,10 @@ UwIDAQAB
730758
content = {
731759
id = 2,
732760
backend_version = 1,
733-
proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' }
761+
proxy = {
762+
authentication_method= 'oidc',
763+
oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/'
764+
}
734765
}
735766
}
736767
}
@@ -920,7 +951,10 @@ UwIDAQAB
920951
content = {
921952
id = 2,
922953
backend_version = 1,
923-
proxy = { oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/' }
954+
proxy = {
955+
authentication_method= 'oidc',
956+
oidc_issuer_endpoint = 'http://user:[email protected]/auth/realms/foo/'
957+
}
924958
}
925959
}
926960
}

0 commit comments

Comments
 (0)