Skip to content

MK8S-197 - UI update to include auth token#4827

Open
ChengYanJin wants to merge 10 commits intodevelopment/133.0from
feature/MK8S-197-UI-update-to-include-auth-token
Open

MK8S-197 - UI update to include auth token#4827
ChengYanJin wants to merge 10 commits intodevelopment/133.0from
feature/MK8S-197-UI-update-to-include-auth-token

Conversation

@ChengYanJin
Copy link
Copy Markdown
Contributor

@ChengYanJin ChengYanJin commented Mar 18, 2026

No description provided.

@ChengYanJin ChengYanJin changed the title Feature/mk8 s 197 UI update to include auth token MK8S-197 - UI update to include auth token Mar 18, 2026
@ChengYanJin ChengYanJin force-pushed the feature/MK8S-197-UI-update-to-include-auth-token branch 2 times, most recently from bed75df to fbba288 Compare March 18, 2026 17:05
@ChengYanJin ChengYanJin changed the title MK8S-197 - UI update to include auth token MK8S-197 - UI prometheus update to include auth token Mar 18, 2026
@ChengYanJin ChengYanJin force-pushed the feature/MK8S-197-UI-update-to-include-auth-token branch 4 times, most recently from 0b309dd to e001070 Compare March 19, 2026 16:16
@ChengYanJin ChengYanJin changed the base branch from feature/MK8S-184-restart-script to development/133.0 March 19, 2026 16:16
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 19, 2026

Hello chengyanjin,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 19, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

@ChengYanJin ChengYanJin marked this pull request as ready for review March 20, 2026 08:41
@ChengYanJin ChengYanJin requested a review from a team as a code owner March 20, 2026 08:41
@ChengYanJin ChengYanJin changed the title MK8S-197 - UI prometheus update to include auth token MK8S-197 - UI update to include auth token Mar 20, 2026
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 23, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

@ChengYanJin ChengYanJin force-pushed the feature/MK8S-197-UI-update-to-include-auth-token branch 4 times, most recently from ce8df24 to 97eeed1 Compare March 24, 2026 09:15
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 24, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

The following reviewers are expecting changes from the author, or must review again:


useEffect(() => {
if (userData?.token) {
setHeaders({ Authorization: `Bearer ${userData.token}` });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ui/src/services/alertmanager/api.ts uses ApiClient (which goes through axios), but PrometheusAuthProvider only calls setHeaders on the Prometheus API client, not the AlertManager API client. The AlertManager requests from the UI side will still be unauthenticated. You need to also call setHeaders on the alertmanager API client with the Bearer token, similar to what you did for Prometheus.

— Claude Code

};
export function getAlerts(alertManagerUrl: string) {
return fetch(alertManagerUrl + '/api/v2/alerts')
export function getAlerts(alertManagerUrl: string, token: string) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The token parameter is typed as string but it can be undefined (since userData?.token may be undefined). The type should be string | undefined to match the actual usage in AlertProvider.tsx line 26.

— Claude Code

const { userData } = useAuth();
const token = userData?.token;
const query = useQuery(
['activeAlerts', token],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Including the token in the query key means every token refresh/rotation will invalidate the cache and refetch all alerts. Consider using a stable query key (e.g. just activeAlerts) since the token is only needed for the request, not for cache identity.

— Claude Code

}
}, [userData?.token]);

if (!ready) return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PrometheusAuthProvider blocks rendering of the entire app (returns null) until the token is available. If userData is slow to resolve or temporarily undefined during token refresh, the entire UI will flash/unmount. Consider rendering children immediately and setting headers as a side effect without blocking, or showing a loading indicator instead of null.

— Claude Code

@claude
Copy link
Copy Markdown

claude bot commented Mar 24, 2026

  • shell-ui/src/alerts/services/alertManager.ts: checkActiveAlertProvider calls getAlerts() with no arguments after the signature was changed to require a token parameter. This will send Authorization: Bearer undefined.
    - Pass the token through or make the parameter optional
    - shell-ui/src/alerts/services/alertManager.ts: token parameter typed as string but receives undefined from userData?.token.
    - Change type to string | undefined (or string?)
    - ui/src/containers/PrometheusAuthProvider.tsx: Only sets auth headers on the Prometheus API client, not the AlertManager API client (ui/src/services/alertmanager/api.ts). AlertManager requests from the UI will still be unauthenticated.
    - Add a setHeaders export to alertmanager/api.ts and call it alongside the Prometheus one
    - shell-ui/src/alerts/AlertProvider.tsx: Token included in the react-query key causes unnecessary cache invalidation on token refresh.
    - Use a stable key like ['activeAlerts']
    - ui/src/containers/PrometheusAuthProvider.tsx: Returns null until token is available, blocking the entire app tree. May cause UI flash on token refresh.
    - Consider rendering children immediately or showing a loader

    Review by Claude Code

@ChengYanJin ChengYanJin force-pushed the feature/MK8S-197-UI-update-to-include-auth-token branch from fa75385 to d09944d Compare March 24, 2026 17:45
@claude
Copy link
Copy Markdown

claude bot commented Mar 24, 2026

  • ui/src/containers/PrometheusAuthProvider.tsx:20setHeaders() is called directly in the render body, causing a side effect on every re-render. This mutates the shared prometheusApiClient during rendering, which violates React's expectation of pure render functions and will trigger warnings in React Strict Mode. Wrap it in useEffect keyed on userData.token.

    Review by Claude Code

@ChengYanJin ChengYanJin force-pushed the feature/MK8S-197-UI-update-to-include-auth-token branch from d09944d to c15b1d0 Compare March 25, 2026 10:01
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 25, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

The following reviewers are expecting changes from the author, or must review again:

@claude
Copy link
Copy Markdown

claude bot commented Mar 25, 2026

  • shell-ui/src/alerts/services/alertManager.ts: checkActiveAlertProvider calls getAlerts() with no arguments after the signature was changed to require (alertManagerUrl, token). This will fail at runtime.
    • Update checkActiveAlertProvider to accept and forward both parameters, or remove it if unused.
  • ui/src/containers/PrometheusAuthProvider.tsx: Auth headers are only set on the Prometheus API client, not on the AlertManager API client (ui/src/services/alertmanager/api.ts). If the AlertManager client in the ui package is called, those requests will also return 401.
    • Add setHeaders to alertmanager/api.ts and call it from this provider, or confirm the client is dead code.

Review by Claude Code

MonPote
MonPote previously approved these changes Mar 25, 2026
Copy link
Copy Markdown
Contributor

@MonPote MonPote left a comment

Choose a reason for hiding this comment

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

LGTM

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 25, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

@scality scality deleted a comment from claude bot Mar 25, 2026
@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 27, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

const { userData } = useAuth();
const token = userData?.token;

useEffect(() => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Race condition: useEffect runs after render, so when token first becomes available, children render (and can trigger Prometheus API calls) before setHeaders has executed. Use useLayoutEffect instead to ensure headers are set before children mount.

— Claude Code

@claude
Copy link
Copy Markdown

claude bot commented Mar 27, 2026

  • Race condition in PrometheusAuthProvider: useEffect fires after render, so children can make Prometheus API calls before setHeaders has been called. Switch to useLayoutEffect to guarantee headers are set before paint/children mount.
  • AlertManager API client missing auth: The alertmanager client in ui/src/services/alertmanager/api.ts is initialized in the saga but never receives auth headers. Either add setHeaders to the alertmanager API module and call it from the provider, or remove the now-unused getAlerts export to prevent future 401s.

Review by Claude Code

@claude
Copy link
Copy Markdown

claude bot commented Mar 27, 2026

  • Race condition in PrometheusAuthProvider: useEffect runs child-first in React, so children's react-query hooks may fire Prometheus requests before setHeaders sets the auth token. Use useLayoutEffect instead to guarantee headers are set before child effects run.
    - Silent no-op in setHeaders: If prometheusApiClient hasn't been initialized yet, the call is silently ignored and the auth header is permanently lost. Add a warning log or throw.

    Review by Claude Code

@Claude Claude AI changed the title MK8S-197 - UI update to include auth token Addressing PR comments Mar 27, 2026
@ChengYanJin ChengYanJin changed the title Addressing PR comments MK8S-197 - UI update to include auth token Mar 27, 2026
@claude
Copy link
Copy Markdown

claude bot commented Mar 27, 2026

  • PrometheusAuthProvider returns null while token is unavailable, blocking the entire app tree (router, toasts, etc.) from rendering
    - Render a loading indicator instead of null, or narrow the provider scope to only Prometheus-dependent components

    - useLayoutEffect used in PrometheusAuthProvider for a non-DOM operation (setting API headers)
    - Use useEffect instead — no DOM measurement is needed here

    - token parameter in getAlerts (alertManager.ts) is optional, allowing unauthenticated requests
    - If auth is now required, make the parameter required to catch missing tokens at compile time

    - console.warn in prometheus/api.ts setHeaders will fire if called before initialize
    - Queue headers for deferred application, or remove the warning since the race is expected

    Review by Claude Code

@ChengYanJin
Copy link
Copy Markdown
Contributor Author

/approve

@bert-e
Copy link
Copy Markdown
Contributor

bert-e commented Mar 27, 2026

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Peer approvals must include at least 1 approval from the following list:

The following options are set: approve

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.

4 participants