Skip to content

OSAC-3373: extend SessionContext with tenantId - #111

Merged
openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
rawagner:OSAC_3373
Aug 3, 2026
Merged

OSAC-3373: extend SessionContext with tenantId#111
openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
rawagner:OSAC_3373

Conversation

@rawagner

@rawagner rawagner commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Extract tenantId from the Keycloak organization claim and wire it through the Go proxy login info endpoint to the React session context.

  • Add TenantIdFromToken reading the Keycloak organization claim
  • Include tenantId in /api/login/info response
  • Add tenantId to SessionContextValue and SessionProvider
  • Update useOIDCLogin to track and return tenantId
  • Add unit tests for useSession with tenantId
  • Show tenant in Masthead

Assisted-by: Claude Code noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Tenant information is now retrieved during sign-in and carried through the application session.
    • The tenant ID is displayed beneath the masthead title when available.
    • Added support for translated tenant labels.
  • Bug Fixes

    • Improved handling of missing or invalid tenant information during authentication.
  • Tests

    • Added coverage for tenant session data and missing tenant IDs.

@openshift-ci-robot

openshift-ci-robot commented Jul 31, 2026

Copy link
Copy Markdown

@rawagner: This pull request references OSAC-3373 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Extract tenantId from the Keycloak organization claim and wire it through the Go proxy login info endpoint to the React session context.

  • Add TenantIdFromToken reading the Keycloak organization claim
  • Include tenantId in /api/login/info response
  • Add tenantId to SessionContextValue and SessionProvider
  • Update useOIDCLogin to track and return tenantId
  • Add unit tests for useSession with tenantId
  • Show tenant in Masthead

Assisted-by: Claude Code noreply@anthropic.com

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rawagner, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e54aed07-6ac8-437e-9111-63d4d6f57f09

📥 Commits

Reviewing files that changed from the base of the PR and between b0545a3 and 5b1cf4c.

📒 Files selected for processing (8)
  • apps/app-frontend/src/App.tsx
  • apps/app-frontend/src/hooks/oidc-login.tsx
  • apps/app-frontend/src/shell/ShellMasthead.tsx
  • libs/i18n/locales/en/translation.json
  • libs/ui-components/src/hooks/use-session.test.tsx
  • libs/ui-components/src/hooks/use-session.tsx
  • proxy/auth/handler.go
  • proxy/auth/userinfo.go

Walkthrough

The change extracts tenantId from the OIDC token, returns it from the login hook, stores it in session context, and displays it in the masthead when available.

Changes

Tenant ID propagation

Layer / File(s) Summary
Tenant ID extraction and login response
proxy/auth/handler.go, proxy/auth/userinfo.go
The proxy extracts the first organization claim from the ID token and includes it as TenantID in the login response.
Tenant ID session wiring
apps/app-frontend/src/hooks/oidc-login.tsx, apps/app-frontend/src/App.tsx, libs/ui-components/src/hooks/use-session.tsx, libs/ui-components/src/hooks/use-session.test.tsx
The login hook stores and returns tenantId. SessionProvider accepts and exposes it. Tests cover propagation, empty values, and missing provider errors.
Tenant ID masthead display
apps/app-frontend/src/shell/ShellMasthead.tsx, libs/i18n/locales/en/translation.json
The masthead conditionally renders the translated tenant label below the title.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IDToken
  participant GetLoginInfo
  participant useOIDCLogin
  participant SessionProvider
  participant ShellMasthead
  IDToken->>GetLoginInfo: provide organization claim
  GetLoginInfo->>useOIDCLogin: return TenantID in login response
  useOIDCLogin->>SessionProvider: provide tenantId
  SessionProvider->>ShellMasthead: expose tenantId through session
  ShellMasthead-->>ShellMasthead: render translated tenant label when tenantId exists
Loading

Possibly related PRs

  • osac-project/osac-ui#109: Both changes modify useOIDCLogin; this PR adds tenantId while the related PR changes role handling.

Suggested reviewers: larsks, rccrdpccl, elayaharoni

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding tenantId to SessionContext.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No-Hardcoded-Secrets ✅ Passed The full patch contains no private-key material, credential URLs, JWT/API-key shapes, long base64/hex blobs, or sensitive-name assignments to string literals.
No-Weak-Crypto ✅ Passed PR additions contain no MD5, SHA1, DES, RC4, Blowfish, ECB, crypto APIs, or secret comparisons; TenantIdFromToken only decodes and reads a JSON claim.
No-Injection-Vectors ✅ Passed The PR only decodes JWT claims, JSON-encodes the response, and renders tenantId as React text; no listed SQL, shell, eval/exec, pickle, YAML, os.system, or innerHTML sink is introduced.
Container-Privileges ✅ Passed The PR changes no container or Kubernetes manifest. No forbidden privilege settings exist; the production Containerfile stage runs as USER 1001.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no logging calls or log fields. It only extracts tenantId, returns it in the login response, stores it in session context, and displays it in the masthead.
Ai-Attribution ✅ Passed The HEAD commit includes the required Assisted-by: Claude Code <noreply@anthropic.com> trailer, and no AI tool uses a Co-authored-by trailer.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/ui-components/src/hooks/use-session.test.tsx`:
- Around line 16-18: Update the role expectation in the useSession test to match
SessionProvider’s preserved value, changing the expected role from “tenant-user”
to “tenantUser”; leave the tenantId and username assertions unchanged.

In `@proxy/auth/userinfo.go`:
- Around line 78-80: The for loop iterating over orgMap with a return statement
on the first iteration is non-deterministic because Go maps do not preserve
iteration order. Replace this arbitrary selection with a deterministic approach:
either validate that orgMap contains exactly one organization key before
selecting it, or derive the tenant ID from an explicit claim value in the input
instead of iterating the map. This ensures the same tenant is consistently
returned across all requests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 86642dd9-2dfa-4d57-b0c9-8a68ecedc246

📥 Commits

Reviewing files that changed from the base of the PR and between 57ca666 and 7fe4dae.

📒 Files selected for processing (8)
  • apps/app-frontend/src/App.tsx
  • apps/app-frontend/src/hooks/oidc-login.tsx
  • apps/app-frontend/src/shell/ShellMasthead.tsx
  • libs/i18n/locales/en/translation.json
  • libs/ui-components/src/hooks/use-session.test.tsx
  • libs/ui-components/src/hooks/use-session.tsx
  • proxy/auth/handler.go
  • proxy/auth/userinfo.go

Comment thread libs/ui-components/src/hooks/use-session.test.tsx
Comment thread proxy/auth/userinfo.go
@rawagner
rawagner force-pushed the OSAC_3373 branch 2 times, most recently from 2a99512 to b0545a3 Compare August 3, 2026 07:50
<Title headingLevel="h4" size="lg">
Red Hat OSAC
</Title>
{tenantId && <div>{t('Tenant: {{ tenantId }}', { tenantId })}</div>}

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.

maybe here can use SubtleContent instead of the div?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good idea. Replaced with SubtleContent

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@proxy/auth/userinfo.go`:
- Around line 69-74: Update TenantIdFromToken and the JWT parsing flow in
jwtClaims to cryptographically validate the token before reading organization,
including signature, issuer, audience, expiry, and nbf checks. Preserve the
existing empty-string result for invalid or unverifiable tokens, and only return
the organization key after validation succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: osac-project/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5b8aad52-cba9-44f7-b8ed-ceda7df7e808

📥 Commits

Reviewing files that changed from the base of the PR and between 2a99512 and b0545a3.

📒 Files selected for processing (8)
  • apps/app-frontend/src/App.tsx
  • apps/app-frontend/src/hooks/oidc-login.tsx
  • apps/app-frontend/src/shell/ShellMasthead.tsx
  • libs/i18n/locales/en/translation.json
  • libs/ui-components/src/hooks/use-session.test.tsx
  • libs/ui-components/src/hooks/use-session.tsx
  • proxy/auth/handler.go
  • proxy/auth/userinfo.go

Comment thread proxy/auth/userinfo.go
Extract tenantId from the Keycloak organization claim and wire it
through the Go proxy login info endpoint to the React session context.

- Add TenantIdFromToken reading the Keycloak organization claim
- Include tenantId in /api/login/info response
- Add tenantId to SessionContextValue and SessionProvider
- Update useOIDCLogin to track and return tenantId
- Add unit tests for useSession with tenantId
- Show tenant in Masthead

Signed-off-by: Rastislav Wagner <rawagner@redhat.com>
Assisted-by: Claude Code <noreply@anthropic.com>
@openshift-ci openshift-ci Bot added the lgtm label Aug 3, 2026
@openshift-ci

openshift-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ElayAharoni, rawagner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [ElayAharoni,rawagner]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 2c80dd2 into osac-project:main Aug 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants