Skip to content

Allow openid for integration tests - #1156

Open
oysand wants to merge 1 commit into
equinor:mainfrom
oysand:allow-openid-for-integration-tests
Open

Allow openid for integration tests#1156
oysand wants to merge 1 commit into
equinor:mainfrom
oysand:allow-openid-for-integration-tests

Conversation

@oysand

@oysand oysand commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Ready for review checklist:

  • A self-review has been performed
  • All commits run individually
  • Temporary changes have been removed, like logging, TODO, etc.
  • The PR has been tested locally
  • A test has been written
    • This change doesn't need a new test
  • Relevant issues are linked
  • Remaining work is documented in issues
    • There is no remaining work from this PR that requires new issues
  • The changes do not introduce dead code as unused imports, functions etc.

@oysand
oysand force-pushed the allow-openid-for-integration-tests branch from 683cdf0 to 4a7d705 Compare July 31, 2026 08:02
The configured security scheme.
"""
scopes: dict[str, str] = {
f"api://{settings.AZURE_CLIENT_ID}/user_impersonation": "user_impersonation",

@olaals olaals Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-generated review comment: This observation was produced with AI assistance and should be validated and discussed by the team before deciding on an implementation.

This Entra-style scope name does not establish the access token audience. OAuth/OIDC providers and test servers differ in how they derive aud: some use requested scopes, others require a resource or audience parameter, and others need explicit claim mappings. ISAR then validates aud exactly against AZURE_CLIENT_ID, so a token requested with api://<id>/user_impersonation can be validly issued but rejected because its audience is the full scope or another configured resource. Authorization additionally depends on the non-standard top-level roles claim containing Mission.Control; declaring a scope here does not enforce that scope because the endpoint uses Depends rather than Security(..., scopes=[...]).

I recommend separating provider-neutral settings such as expected audience, authorization scopes, required role/claim name, and discovery URL instead of deriving all of them from AZURE_CLIENT_ID. Configure the test issuer to emit the exact audience and role contract, or support a configurable resource/audience request parameter in the token-producing client. Then test matching and mismatching audience, missing and present Mission.Control, and, if the scope is intended as authorization, enforce and test it explicitly.

Scores

  • Overall importance: 9/10
  • Correctness-related: 10/10
  • Security-related: 9/10
  • Interoperability-related: 9/10
  • Flexibility-related: 8/10
  • Confidence: 9/10

}

if settings.OPENID_CONFIG_URL:
return AzureAuthorizationCodeBearerBase(

@olaals olaals Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-generated review comment: This observation was produced with AI assistance and should be validated and discussed by the team before deciding on an implementation.

Overriding discovery on AzureAuthorizationCodeBearerBase does not make token validation provider-neutral. The dependency still parses tokens into its Azure-specific User model, which requires claims such as ver and models aud as a single string, and its validator currently hard-codes RS256. A standards-compatible provider or test server may omit Azure’s ver claim, emit a valid array-form aud, or advertise another signing algorithm. Such a correctly signed token would still be rejected with 401.

Possible directions are to add a separate generic JWT bearer implementation using PyJWT/Authlib with discovery-backed JWKS and explicit issuer, audience, lifetime, and algorithm validation; introduce an adapter that validates generic claims and maps only the fields ISAR actually needs; or keep this class but describe and test the feature as an Azure-shaped test issuer rather than generic OIDC. If algorithms are configurable, restrict them to an explicit allow-list and cross-check discovery/JWK metadata rather than trusting the token header. Please add integration tests using real discovery/JWKS tokens without ver, with string and array audiences, and with accepted/rejected algorithms.

Scores

  • Overall importance: 10/10
  • Correctness-related: 10/10
  • Security-related: 9/10
  • Interoperability-related: 10/10
  • Flexibility-related: 9/10
  • Confidence: 10/10

@olaals

olaals commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

AI-generated review comment: This observation was produced with AI assistance and should be validated and discussed by the team before deciding on an implementation.

The constructor-level tests verify that URLs are assigned, but they do not prove interoperability or security. A stronger acceptance test would start a standards-compatible OIDC test issuer, load its discovery/JWKS, acquire or build a signed token, and call a protected ISAR endpoint. The matrix should include a valid token, wrong issuer, wrong audience, expired token, unsupported signing algorithm, missing required role, and valid array-form audience if the generic path intends to support the JWT standard broadly.

This would also make the intended contract explicit: whether the feature supports arbitrary OIDC access tokens or only Azure-shaped claims from a configurable issuer. That distinction should be documented because the implementation and operational configuration differ substantially.

Scores

  • Overall importance: 8/10
  • Correctness-related: 8/10
  • Security-related: 8/10
  • Interoperability-related: 9/10
  • Flexibility-related: 6/10
  • Confidence: 9/10

@oysand

oysand commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1158, which uses Keycloak instead of oauth2-mock-server. Leaving this open as the fallback — close it if that one lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants