Skip to content

Commit 7fd4a1b

Browse files
committed
Show auth chooser when GCP OAuth is enabled
When GCP OAuth is configured, show the auth chooser dialog instead of automatically redirecting to the token page. This allows users to choose between Google Sign In and token authentication. The redirect to token page is now conditional on GCP OAuth being disabled, which preserves backward compatibility with e2e tests and non-GCP deployments. Also updated GCPLoginButton to only show when GCP OAuth is explicitly enabled via environment variable, not based on cluster type detection.
1 parent 4edbd8c commit 7fd4a1b

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

frontend/src/components/authchooser/index.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { getAppUrl } from '../../helpers/getAppUrl';
2626
import { getCluster, getClusterPrefixedPath } from '../../lib/cluster';
2727
import { useClustersConf } from '../../lib/k8s';
2828
import { testAuth } from '../../lib/k8s/api/v1/clusterApi';
29+
import { isGCPOAuthEnabled } from '../../lib/k8s/gke';
2930
import { queryClient } from '../../lib/queryClient';
3031
import { createRouteURL } from '../../lib/router/createRouteURL';
3132
import { getRoute } from '../../lib/router/getRoute';
@@ -160,21 +161,33 @@ function AuthChooser({ children }: AuthChooserProps) {
160161
if (cluster.useToken === false) {
161162
history.replace(from);
162163
} else if (!clusterAuthType) {
163-
// we know that it requires token and also doesn't have oidc configured
164-
// so let's redirect to token page
165-
history.replace({
166-
pathname: generatePath(getClusterPrefixedPath('token'), {
167-
cluster: clusterName as string,
168-
}),
164+
// Check if GCP OAuth is enabled before auto-redirecting to token page.
165+
// If GCP OAuth is enabled, we want to show the auth chooser so users can
166+
// choose between Google Sign In and token authentication.
167+
isGCPOAuthEnabled().then(gcpEnabled => {
168+
if (!gcpEnabled && !cancelledRef.current) {
169+
// GCP OAuth not enabled, so redirect to token page
170+
history.replace({
171+
pathname: generatePath(getClusterPrefixedPath('token'), {
172+
cluster: clusterName as string,
173+
}),
174+
});
175+
}
176+
// If GCP OAuth is enabled, stay on auth chooser to show both options
169177
});
170178
}
171179
}
172180
});
173181
} else if (cluster.useToken) {
174-
history.replace({
175-
pathname: generatePath(getClusterPrefixedPath('token'), {
176-
cluster: clusterName as string,
177-
}),
182+
// Check if GCP OAuth is enabled before auto-redirecting
183+
isGCPOAuthEnabled().then(gcpEnabled => {
184+
if (!gcpEnabled && !cancelledRef.current) {
185+
history.replace({
186+
pathname: generatePath(getClusterPrefixedPath('token'), {
187+
cluster: clusterName as string,
188+
}),
189+
});
190+
}
178191
});
179192
}
180193
},

frontend/src/components/cluster/GCPLoginButton.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Box, Button, ButtonProps } from '@mui/material';
1818
import React from 'react';
1919
import { useTranslation } from 'react-i18next';
2020
import { Cluster } from '../../lib/k8s/cluster';
21-
import { initiateGCPLogin, isGCPOAuthEnabled, isGKECluster } from '../../lib/k8s/gke';
21+
import { initiateGCPLogin, isGCPOAuthEnabled } from '../../lib/k8s/gke';
2222

2323
export interface GCPLoginButtonProps {
2424
/** The cluster to authenticate to */
@@ -37,7 +37,8 @@ export interface GCPLoginButtonProps {
3737

3838
/**
3939
* A button component that initiates Google OAuth login for GKE clusters.
40-
* Only renders if GCP OAuth is enabled in the backend, or if the cluster is detected as a GKE cluster.
40+
* Only renders if GCP OAuth is enabled in the backend via the HEADLAMP_CONFIG_GCP_OAUTH_ENABLED
41+
* environment variable.
4142
*/
4243
export function GCPLoginButton({
4344
cluster,
@@ -65,8 +66,8 @@ export function GCPLoginButton({
6566
});
6667
}, []);
6768

68-
// Show button if GCP OAuth is enabled OR if it's a GKE cluster
69-
const shouldShowButton = gcpOAuthEnabled === true || isGKECluster(cluster);
69+
// Only show button if GCP OAuth is enabled via environment variable
70+
const shouldShowButton = gcpOAuthEnabled === true;
7071

7172
if (!shouldShowButton) {
7273
return null;

0 commit comments

Comments
 (0)