Skip to content

Commit

Permalink
Merge pull request #5624 from opsmill/pog-loosen-requirements-for-oic…
Browse files Browse the repository at this point in the history
…d-IFC-1194

Loosen requirements of token verification for OIDC id_token groups
  • Loading branch information
ogenstad authored Jan 30, 2025
2 parents 7461545 + 62b07b1 commit 39bc69d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/infrahub/api/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ async def _get_id_token_groups(
algorithms=oidc_config.id_token_signing_alg_values_supported,
audience=client_id,
issuer=str(oidc_config.issuer),
options={"verify_signature": False, "verify_aud": False, "verify_iss": False},
)

return decoded_token.get("groups", [])
31 changes: 31 additions & 0 deletions backend/tests/unit/api/test_oidc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import time
import uuid
from copy import deepcopy
from typing import Any

import httpx
Expand Down Expand Up @@ -40,6 +41,36 @@ async def test_get_id_token_groups_for_oidc() -> None:
assert groups == ["operators"]


async def test_get_id_token_groups_for_oidc_invalid_issuer() -> None:
memory_http = MemoryHTTP()
service = InfrahubServices(http=memory_http)
client_id = "testing-oicd-1234"

helper = OIDCTestHelper()
token_response = helper.generate_token_response(
username="testuser",
groups=["operators"],
client_id=client_id,
issuer=str(OIDC_CONFIG.issuer),
)

memory_http.add_get_response(
url=str(OIDC_CONFIG.jwks_uri),
response=httpx.Response(status_code=200, content=json.dumps(helper.jwks_payload)),
)
config = deepcopy(OIDC_CONFIG)
config.issuer = Url("https://something-incorrect.example.com")

groups = await _get_id_token_groups(
oidc_config=config,
service=service,
payload=token_response,
client_id=client_id,
)

assert groups == ["operators"]


async def test_get_id_token_groups_for_oidc_no_id_token() -> None:
memory_http = MemoryHTTP()
service = InfrahubServices(http=memory_http)
Expand Down
1 change: 1 addition & 0 deletions changelog/5623.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Loosened requirement for group discovery using OIDC and id_token. This will probably be reverted or presented as a configuration option in the future.

0 comments on commit 39bc69d

Please sign in to comment.