Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PYTHONPATH=src uvicorn sdp.api:app --reload
`SDP_SQLITE_PATH=.local/sdp-evidence.sqlite3`를 지정하면 production credential 없이도 같은 evidence store protocol을 로컬 SQLite fallback으로 검증할 수 있습니다. `SDP_DATABASE_URL`이 있으면 Postgres가 SQLite보다 우선합니다.
`SDP_LOG_SINK_URL=file://.local/sdp-requests.jsonl`과 `SDP_REQUEST_ID_HEADER=X-Request-Id`를 지정하면 request id, tenant, actor, route, status, latency, evidence ids만 body 없이 request observation log로 기록됩니다.
REST connector secret은 `SDP_CONNECTOR_SECRET_REF_PREFIX=SDP_CONNECTOR_SECRET_` 기준의 env secret reference로 조회합니다. 예: `SDP_CONNECTOR_SECRET_REST_CONNECTOR_MARKETING_CAMPAIGN_TOKEN` 값은 presence만 검증하며 API 응답에는 노출하지 않습니다.
OIDC token verification은 `SDP_OIDC_ISSUER`, `SDP_OIDC_AUDIENCE`, `SDP_OIDC_JWKS_URL`, `SDP_OIDC_GROUP_ROLE_MAP`를 사용합니다.
OIDC token verification은 `SDP_OIDC_ISSUER`, `SDP_OIDC_AUDIENCE`, `SDP_OIDC_JWKS_URL`, `SDP_OIDC_GROUP_ROLE_MAP`를 사용하며, 서명 검증 후 Keyverse의 `org`/`role` claim을 tenant 및 제한된 SDP RBAC role로 매핑합니다. `workspace`는 현재 workspace-scoped resource model이 없어 인증 claim shape로만 허용하며, tenant나 권한으로 사용하지 않습니다.

Docker 기반 로컬 데모는 다음 명령으로 실행합니다.

Expand Down
2 changes: 1 addition & 1 deletion docs/implementation-compliance.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

- `GET /enterprise/readiness`: 20억 원 valuation target, package/submodule decision, storage/connector capability, enterprise gates, Figma Code Connect disabled artifact.
- `GET /enterprise/production-readiness`: demo release와 paid pilot readiness를 분리하고, Postgres evidence store, OIDC JWKS verification, connector credential vault, request observability export의 환경변수·acceptance criteria·blocker를 노출한다. Postgres evidence store, OIDC JWKS verification, request observability export, connector credential vault가 구현되어 남은 paid-pilot blocker는 0개다.
- `POST /enterprise/auth/oidc-verify`: issuer/audience/expiry/JWKS 서명 검증 후 group allow-list mapping으로 `ActorContext`를 생성하고 raw token은 응답에 포함하지 않는다.
- `POST /enterprise/auth/oidc-verify`: issuer/audience/expiry/JWKS 서명 검증 후 group allow-list와 Keyverse `org`/`role` mapping으로 `ActorContext`를 생성하고 raw token은 응답에 포함하지 않는다.
- `GET /enterprise/evidence-pack`: metadata validation, SHACL-compatible validation, steward queue, ontology mapping coverage, policy/audit counts, controls, KPI ids, proof endpoints.
- `GET /enterprise/console`: buyer/operator가 evidence, KPI, controls, connector 상태를 브라우저에서 확인하는 no-build-dependency UI.
- 증빙 테스트:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = [
"fastapi==0.139.0",
"psycopg[binary]==3.3.4",
"PyJWT[crypto]==2.13.0",
"cryptography==50.0.0",
"pydantic==2.13.4",
"uvicorn==0.51.0",
]
Expand Down
235 changes: 178 additions & 57 deletions requirements-dev.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements-test.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
fastapi==0.139.0
psycopg[binary]==3.3.4
PyJWT[crypto]==2.13.0
cryptography==50.0.0
pydantic==2.13.4
uvicorn==0.51.0
pytest==9.1.1
Expand Down
258 changes: 130 additions & 128 deletions requirements-test.txt

Large diffs are not rendered by default.

106 changes: 50 additions & 56 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,58 +118,56 @@ click==8.4.2 \
--hash=sha256:9a6cea6e60b17ebe0a44c5cc636d94f09bd66142c1cd7d8b4cd731c4917a15f6 \
--hash=sha256:e6f9f66136c816745b9d65817da91d61d957fb16e02e4dcd0552553c5a197b76
# via uvicorn
colorama==0.4.6 \
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
# via click
cryptography==49.0.0 \
--hash=sha256:026ac7423e6fa66872d3bf889be5974507da3944f866f704fa200eadacd00001 \
--hash=sha256:07cab27cc7b7e0fd28e5e26bb9eeedde5c135c868b46de4a27845abe94af6122 \
--hash=sha256:084ef1af862eb07ec46d25f68689f2102a9fc0e05ce7b80f14f5fe51e4eef0f6 \
--hash=sha256:0b82e28ee398a386f0807bba7884d30f25218855690f45115831bcce5d90822c \
--hash=sha256:0e959b578856a3924bc0cbb710fc12c387b9412a951389f3ca61704a9e25f325 \
--hash=sha256:0f21641cf4b30fca7aee061ced0ec7ad7b073518088b7c9969a297c0ae796c69 \
--hash=sha256:196ecd6a36e4e9aa10270393bb98d8df88fccee0bf1e5128b91ae4eb4375896d \
--hash=sha256:2400ef9c9e2299a25614eb1dea3db54a69b1349efd043bfac9c67630d136df36 \
--hash=sha256:28d8b15e6275f12c8a207dc309dfa957903c927d08d0cc937ee3f63f200693cc \
--hash=sha256:2afe9051da7ae7bd5905da5a949280c7d2bb75682e188f650a9d0f2756b834c6 \
--hash=sha256:2eda353d8a27bcbcaa4cbed18994a74ab4d19a2ca897db188ea269ab9b71419b \
--hash=sha256:32703d93296f5c1f4b53349ad3a250c2cae0fdecd3a3dd5d47e616d8d616af27 \
--hash=sha256:33cd0565932807baddb67b96dbee92f2c374b5c89dee09fd74079aeb8c8dba61 \
--hash=sha256:35b151772baff2c74cba7fa290ceaff4c3b11c0c881eb93eb5dbc05a7cfbba18 \
--hash=sha256:36d1709f992593689b45bda411498d62c6e365f2ca00b84657d4dadd24de16db \
--hash=sha256:42b0684e0e40cf26122427802486f6d93aea593612603a94fbf260c7eb1e9c1b \
--hash=sha256:4ae387c9cb68ea569ca17e490d66d8142b81c3cc814bf179974b7d146e490bbb \
--hash=sha256:53ecee2e23f7169b6117e99fc8a944e5e50f79e69758a83b52a00cb98ab2b2d2 \
--hash=sha256:66ec79c3904820572d7e987abdf304281f141d37ad9a489b8e97066e7b9b6459 \
--hash=sha256:67e1d20ad9ef3a563c59ef22e7a8a0b8210bd26604369ea4a30a7c66aefe504e \
--hash=sha256:6f2debedf9ca60cf1d5bd466475638af5130f89965605cd818484d19987d3a21 \
--hash=sha256:6fc361c34fb6aac015ce19435876635e5c6d21db31998b0920f675f131e043b8 \
--hash=sha256:73a205dce83953d131a4aa1e0fd917a2fd1c5b1eef251e9d7152efefcbf5caf7 \
--hash=sha256:7abcee80084cda3f7691f3eb1ce480d8df49cec637b429aa35986c1de71738aa \
--hash=sha256:8c25ceb16df5b9435f3f6a9829204985b0e0cbee3b48aacd432c7d2c850b44d9 \
--hash=sha256:966fe0e9c67490071f14c0d2b1cb2dfb3023c5ce39457343931415f08382f2db \
--hash=sha256:9e82dcc8e56052715fb18b2429e3bca4823b1629136a2084fc45a9a5cecb9b64 \
--hash=sha256:b20133d204d2bb56ba047642199603876c872026ca53e79c35b83772ab2cc505 \
--hash=sha256:b39efa323140595abd3ecca8529d321ae50f55f3aa3ba9cc81ea56a6011953d5 \
--hash=sha256:b47db11c2c3525083296069b98ac5221907455e989ae0c2e3008bde851921615 \
--hash=sha256:b87e65d263b3e5d3bb92a57e2a6638e2f31110fa7aa890c7b2dbba42248d0a3f \
--hash=sha256:b970c6da94d5bb18629db453d14f2a1300f6bf59b61e9b82377931ef95504866 \
--hash=sha256:be9fcb48a55f023493482827d4f459bd263cc20efde64f204b97c123201850c6 \
--hash=sha256:c2bc30226390d60ea19d9f82b19db005fe0452154a23c1c410c12ea801e43561 \
--hash=sha256:c83782480a4a9da4d0feb51950131ba32e12e70813848b3343f6e18c28a66838 \
--hash=sha256:cbc77da8c523d5abd028635ba850a6966fcee2c82e2bf65a41d1d8afe0f98be9 \
--hash=sha256:ccac2bfebc306b862133e3bb71f3f6ee8bb525240089b2d952e4144b3a6d5da7 \
--hash=sha256:d0527ce944105f257f605a827d6ebead966c752038b6e8656abb9c5edee6fc68 \
--hash=sha256:d8ecde755e2e91bf773fc94e8c9d730cd7f2007004cb492263a794ec3899a1c8 \
--hash=sha256:e3fb64c420688e5319ae25113a354015abbd8dffbfbc41781a1ea66fc7622ac3 \
--hash=sha256:e5dfc1e64de5677cec922ffa8da89c546d0415bf6efdf081842e5d44c84e1f0e \
--hash=sha256:ec5e529fb80935c94fe7b729f9972b50e351a0e6b50aa294fd5cabb109fcc29a \
--hash=sha256:f37d847238971164fdbc68ade6f6574aecc9c0af714190e2083429ff68f4ce9d \
--hash=sha256:f78ff2c9ed8dc2d036b0f4d640e22522213d047c1b14e61205a7e55c80a494d4 \
--hash=sha256:f89660a348f4f78a92366240a61404e337586ef7f5909a2fef59ca88ef505493 \
--hash=sha256:fc1e275c2f1d97b1a6450b8b0ea3ebfa6e087a611c2b26cb2404d48588abab7b
# via pyjwt
cryptography==50.0.0 \
--hash=sha256:031e2d5dd4bb9caa3ca9c82e5a197fd8ae680232cee62603d1a813f3f07e3d03 \
--hash=sha256:06a32a980526a6ab9a4b9bf8f7385800791e2bb960903cb6b530e4817509a3b7 \
--hash=sha256:07479a1cb08219ab719147e742e76090c9c773321959bb94946fffdd397a6437 \
--hash=sha256:07949c449a1abcf60d1ee6e88956d89404c7df3c8258f46589e912988e551987 \
--hash=sha256:105110f43a471dbd0060b9c9516cb8a6a79233631a04cc2ba16f28323ac6e025 \
--hash=sha256:11b74db56cdbe3cdee6e3f6982ecb70334fa10dce99ed58bf7894aaaa3b2a037 \
--hash=sha256:12b9c6996425c76ea6c457ace4f3073e715b8c545add07cd1a8f3a4f90691269 \
--hash=sha256:1489e263a8048bb8b6a8bac662eb2d402ea5d2b7b4699b72f385f1e2772db105 \
--hash=sha256:19736989797678c6af1e55cd49055cdbcb55d8f6b5583ac5335f933aba9101dc \
--hash=sha256:1b4a266766514614f8aa60416e71f2fc6e575d36e7bdc90f644fadb2f4b75b95 \
--hash=sha256:2a8183b489dc1f7f80f135780fadc1108f14b31b8a40411c7a5b17425f65f28b \
--hash=sha256:37fdb0d0111f1e2ff07139dfb79f1b49531f8e213c46f1163dd7642979b58c47 \
--hash=sha256:3f5735ffe4996d28b809371756219f5354864902a3b9e7c0b9ee87041209fc9c \
--hash=sha256:49e7d93abdbd2990caced757e5fade25302f719c3c8fb6e6fff2dde98999fc41 \
--hash=sha256:5e34edd123674534acd70147f0ca331eaa2c74e6325fb2028c886aa26ba0b68c \
--hash=sha256:62598a8a57f815db4c6259a4e97d857dab56697e7de8e8ab02352ab74da1995d \
--hash=sha256:65c2c3add92b45fd0709db8594536aea39c2a67af0e27ffcf049c498501140b7 \
--hash=sha256:6ba6a53445bd3cfa809ef3ef5f1589aa6ba08784a1d962bf47d0940e871dab1c \
--hash=sha256:6e7d61120573a7f2cd94cc095f9e81f6967c61ccdf194285aa143ecec8e0b708 \
--hash=sha256:7cec5b856506da6defb290f30c9ee687d5f5e8cb0bd3f6459dde43b0b4fa40ef \
--hash=sha256:80b63928fa35083b33966ce1efb70e5b9607181e49dcd1c22c8c005e319f667f \
--hash=sha256:82148ec5bddac30b51a5b3c1945075f896fa022cb93f8e4a01e9f6ee95292c5f \
--hash=sha256:828743d939e9629bc267b8e2d08d8bb67cd4319c771a33d4b18b22dd8fb7440a \
--hash=sha256:8d89f3976b10b4ce31118de72329025f70d2c6ead14a8217c5514dd2c6d5a78f \
--hash=sha256:8eb5e1172eb569ea8a872796576e6a67c276351728b6455d5beb01242b027c6a \
--hash=sha256:900131fafd8aead39ac7dd3a7e833be754c17a95cfd91221636949fe4eb0aa8a \
--hash=sha256:910d11e1a385c654bf738bf3e6b8e6ed5de0f5610fcae2be9e5b398d8081d20e \
--hash=sha256:910e1d2668e7de9648f2bcee30e180db2a6b15c30f887d7c4c93ddf96e3992e3 \
--hash=sha256:9aa87839c383bdbab6ef865787a1fb877af8dd03464c4400322726feaaadfc6d \
--hash=sha256:a1b30560f2acc95aa8b2e06e716a13dbfc97314747b80d9707e307f77b40d6b3 \
--hash=sha256:a91296cb61e8df6f86d0c19cc4068228da256bf59bf86049fbd821084565327f \
--hash=sha256:b42a28c1844fd9de8f3f7d540e36b66f3a9c83fceac7170ebc7a6a19edd9dcae \
--hash=sha256:bd1c592e4d5974f0d08d4888e432157adba757c66da0246918e43677fafa2d30 \
--hash=sha256:c87f62a3d3b9888ed0fdde100ec06aa61ca9cd44bad9057d1dff9a516b5f5bb9 \
--hash=sha256:c99c003e088647b8a5b7c145d6f78c335f6348332b62e142d411c4b63d1460b9 \
--hash=sha256:ccdc4a71a4dabae05de219404f9f4abc38e3b58422177ff93d0da05967dafa07 \
--hash=sha256:d24fead1d4d076e1bfb006dcec392074a3cd8d7b4fc8a595aa64073b2b7a96ba \
--hash=sha256:d58c3db7cd6eed54e6c06744db55456b65ebd7492ddeae9c1e93cfca7aa857d3 \
--hash=sha256:d764dcf130c428ef66786f866dd750f53182bc608813489915e9fc106bb0c82f \
--hash=sha256:df2a58a472f332225671c35b0a830208b86d004f82baa8530fa3782c85646533 \
--hash=sha256:e722f16708d854fe924790e051061f6704a472c3bac347b6fd88033ea8dd0dc5 \
--hash=sha256:ecfed7367f965a0328cfbdd70da860f15441f002f613185668c6e6ebf5a0ac11 \
--hash=sha256:eeac2acb5a20ed25e0ad6d1df9891a520b78b404266b6d11778f25d5d691a6c9 \
--hash=sha256:f59e38625469987d7ef6d495323c55e7db6c212eaf6112267e0d3b565a2e9c9f \
--hash=sha256:f89831ef99dd7dd169ab06d63a831adb9e20a87aac6d380266bbda5823349169 \
--hash=sha256:fd9192b7b70c573d7f214eb1ae35e00d359f6f5e4b27c7e21e30de1fc6204645
# via
# semantic-data-portal (pyproject.toml)
# pyjwt
fastapi==0.139.0 \
--hash=sha256:99ab7b2d92223c76d6cf10757ab3f89d45b38267fc20b2a136cf02f6beac3145 \
--hash=sha256:cf15e1e9e667ddb0ad63811e60bd11390d1aac838ca4a7a23f421807b2308189
Expand Down Expand Up @@ -397,10 +395,6 @@ typing-inspection==0.4.2 \
# via
# fastapi
# pydantic
tzdata==2026.2 \
--hash=sha256:9173fde7d80d9018e02a662e168e5a2d04f87c41ea174b139fbef642eda62d10 \
--hash=sha256:bbe9af844f658da81a5f95019480da3a89415801f6cc966806612cc7169bffe7
# via psycopg
uvicorn==0.51.0 \
--hash=sha256:5d38af6cd620f2ae3849fb44fd4879e0890aa1febe8d47eb355fb45d93fe6a5b \
--hash=sha256:f6f4b69b657c312f516dd2d268ab9ae6f254b11e4bac504f37b2ab58b24dd0b0
Expand Down
66 changes: 62 additions & 4 deletions src/sdp/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@
"sdp-security": ["security"],
}

_KEYVERSE_ROLE_MAP = {
"member": ["data-analyst"],
"data-analyst": ["data-analyst"],
"data-admin": ["data-admin", "data-analyst"],
"admin": ["admin", "data-analyst"],
"platform-admin": ["platform-admin", "admin", "data-analyst"],
"security": ["security"],
}
Comment on lines +31 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Keyverse data-admin maps to an inert application role

_KEYVERSE_ROLE_MAP maps data-admin to ["data-admin", "data-analyst"], but src/sdp/policy.py recognizes only admin/platform-admin/data-analyst/security; data-admin appears there only as an obligation string. The data-admin role is therefore inert — non-escalating, but it grants no authority beyond data-analyst.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


_SUBJECT_CLAIMS = ("preferred_username", "email", "sub")
_TENANT_CLAIMS = ("tenant_id", "tid", "organization", "org")
_ALLOWED_JWT_ALGORITHMS = {"RS256", "RS384", "RS512", "ES256", "ES384", "ES512"}


Expand Down Expand Up @@ -57,6 +67,23 @@ def _claim_values(value: Any) -> list[str]:
return [str(value)]


def _single_string_claim(value: Any, claim_name: str) -> str | None:
"""Return one optional string claim, rejecting ambiguous claim shapes.

Signed identity claims that grant application roles must have one explicit
string value. Accepting arrays or coercing arbitrary values could merge
multiple authorities or invoke surprising conversions at the authorization
boundary, so malformed role claims fail closed.
"""
if value is None:
return None
if not isinstance(value, str):
raise ValueError(f"{claim_name} claim must be a string")
if not value.strip():
raise ValueError(f"{claim_name} claim must be non-empty")
return value


def oidc_role_claims(claims: dict[str, Any]) -> list[str]:
return _claim_values(claims.get("roles"))

Expand All @@ -75,8 +102,7 @@ def load_oidc_role_map() -> dict[str, list[str]]:
def validate_oidc_claim_shape(claims: dict[str, Any]) -> None:
if not any(claims.get(key) for key in _SUBJECT_CLAIMS):
raise ValueError("missing subject claim")
if not (claims.get("tenant_id") or claims.get("tid") or claims.get("organization")):
raise ValueError("missing tenant claim")
_tenant_claim_value(claims)
if "exp" not in claims:
raise ValueError("missing exp claim")

Expand All @@ -89,6 +115,23 @@ def validate_oidc_claim_shape(claims: dict[str, Any]) -> None:
raise ValueError("expired token claims")


def _tenant_claim_value(claims: dict[str, Any]) -> str:
"""Validate all tenant aliases before selecting the first configured one."""
tenant_ids: list[str] = []
for key in _TENANT_CLAIMS:
if key not in claims:
continue
tenant_id = _single_string_claim(claims[key], key)
if tenant_id is None:
raise ValueError("missing tenant claim")
tenant_ids.append(tenant_id)
if not tenant_ids:
raise ValueError("missing tenant claim")
if len(set(tenant_ids)) != 1:
raise ValueError("conflicting tenant claims")
return tenant_ids[0]
Comment on lines +135 to +149

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Multiple tenant aliases now reject on any mismatch

_tenant_claim_value (authz.py) validates every present tenant alias and raises conflicting tenant claims if any differ, replacing the old precedence selection. A token carrying both a tenant id and a differently-valued organization/org display name was previously accepted but is now rejected outright. Worth confirming no target IdP emits distinct tenant aliases.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.



def resolve_oidc_actor_context(
claims: dict[str, Any],
*,
Expand All @@ -102,12 +145,15 @@ def resolve_oidc_actor_context(
or claims.get("sub")
or "anonymous"
)
tenant_id = str(claims.get("tenant_id") or claims.get("tid") or claims.get("organization") or "")
tenant_id = _tenant_claim_value(claims)
groups = _claim_values(claims.get("groups"))

roles: set[str] = set()
for group in groups:
roles.update(mapping.get(group, []))
role = _single_string_claim(claims.get("role"), "role")
if role:
roles.update(_KEYVERSE_ROLE_MAP.get(role, []))

return ActorContext(subject=str(subject), tenant_id=tenant_id, roles=sorted(roles))

Expand Down Expand Up @@ -141,6 +187,12 @@ def _select_jwk(jwks: dict[str, Any], kid: str | None) -> dict[str, Any]:
raise ValueError("no matching jwks key")


def _validate_jwt_header(header: dict[str, Any]) -> None:
"""Reject critical JWT extensions because this verifier supports none."""
if "crit" in header:
raise ValueError("unsupported critical JWT header")


def verify_oidc_jwks_token(
token: str,
*,
Expand All @@ -163,7 +215,13 @@ def verify_oidc_jwks_token(
jwks = _load_jwks_from_url(jwks_url)

try:
header = jwt.get_unverified_header(token)
try:
header = jwt.get_unverified_header(token)
except InvalidTokenError as exc:
if "Unsupported critical extension" in str(exc):
raise ValueError("unsupported critical JWT header") from exc
raise
_validate_jwt_header(header)
alg = header.get("alg")
if alg not in _ALLOWED_JWT_ALGORITHMS:
raise ValueError("unsupported token algorithm")
Expand Down
42 changes: 38 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ def test_oidc_jwks_verification_maps_verified_token_without_token_leak():
"iss": "https://idp.example.com/",
"aud": "semantic-data-portal",
"email": "analyst@example.com",
"tenant_id": "buyer-demo",
"groups": ["sdp-analysts"],
"roles": ["sdp-platform-admins"],
"org": "buyer-demo",
"workspace": "workspace-buyer",
"role": "member",
"exp": int(time()) + 3600,
},
private_key,
Expand All @@ -440,10 +440,44 @@ def test_oidc_jwks_verification_maps_verified_token_without_token_leak():
assert body["actor_context"]["subject"] == "analyst@example.com"
assert body["actor_context"]["tenant_id"] == "buyer-demo"
assert body["actor_context"]["roles"] == ["data-analyst"]
assert body["ignored_role_claims"] == ["sdp-platform-admins"]
assert body["ignored_role_claims"] == []
assert token not in json.dumps(body)


def test_oidc_jwks_verification_rejects_unsupported_critical_header():
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
jwk = json.loads(RSAAlgorithm.to_jwk(private_key.public_key()))
jwk.update({"kid": "buyer-key-crit", "alg": "RS256", "use": "sig"})
token = jwt.encode(
{
"iss": "https://idp.example.com/",
"aud": "semantic-data-portal",
"email": "analyst@example.com",
"org": "buyer-demo",
"exp": int(time()) + 3600,
},
private_key,
algorithm="RS256",
headers={
"kid": "buyer-key-crit",
"crit": ["https://example.com/custom-extension"],
},
)

response = client.post(
"/enterprise/auth/oidc-verify",
json={
"token": token,
"issuer": "https://idp.example.com/",
"audience": "semantic-data-portal",
"jwks": {"keys": [jwk]},
},
)

assert response.status_code == 400
assert "critical JWT header" in response.json()["detail"]


def test_oidc_jwks_verification_rejects_wrong_audience():
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
jwk = json.loads(RSAAlgorithm.to_jwk(private_key.public_key()))
Expand Down
Loading
Loading