Skip to content

Commit 945416f

Browse files
Mohammed AbdiMohammed Abdi
authored andcommitted
add impersonate route hack using token
Signed-off-by: Mohammed Abdi <[email protected]>
1 parent 2535a29 commit 945416f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

backend/src/routes/api/dev-impersonate/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import https from 'https';
33
import createError from 'http-errors';
44
import { setImpersonateAccessToken } from '../../../devFlags';
55
import { KubeFastifyInstance } from '../../../types';
6-
import { DEV_IMPERSONATE_PASSWORD, DEV_IMPERSONATE_USER } from '../../../utils/constants';
6+
import {
7+
DEV_IMPERSONATE_PASSWORD,
8+
DEV_IMPERSONATE_USER,
9+
DEV_IMPERSONATE_TOKEN, // Temporary work around: get impersonate to work through token, becuase of hostname resolve problem and IBM not using oauth proxy
10+
} from '../../../utils/constants';
711
import { createCustomError } from '../../../utils/requestUtils';
812
import { devRoute } from '../../../utils/route-security';
913

@@ -12,6 +16,12 @@ export default async (fastify: KubeFastifyInstance): Promise<void> => {
1216
'/',
1317
devRoute(async (request: FastifyRequest<{ Body: { impersonate: boolean } }>) => {
1418
return new Promise<{ code: number; response: string }>((resolve, reject) => {
19+
// Temporary work around: get impersonate to work through token, becuase of hostname resolve problem and IBM not using oauth proxy
20+
if (DEV_IMPERSONATE_TOKEN) {
21+
setImpersonateAccessToken(DEV_IMPERSONATE_TOKEN);
22+
resolve({ code: 200, response: DEV_IMPERSONATE_TOKEN });
23+
return;
24+
}
1525
const doImpersonate = request.body.impersonate;
1626
if (doImpersonate) {
1727
const apiPath = fastify.kube.config.getCurrentCluster().server;
@@ -71,7 +81,7 @@ export default async (fastify: KubeFastifyInstance): Promise<void> => {
7181
if (e?.code) {
7282
throw createCustomError(
7383
'Error impersonating user',
74-
e.response?.message || 'Impersonating user error',
84+
e.response || 'Impersonating user error',
7585
e.code,
7686
);
7787
}

backend/src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const DEV_MODE = process.env.APP_ENV === 'development';
1010
/** Allows a username to be impersonated in place of the logged in user for testing purposes -- impacts only some API */
1111
export const DEV_IMPERSONATE_USER = DEV_MODE ? process.env.DEV_IMPERSONATE_USER : undefined;
1212
export const DEV_IMPERSONATE_PASSWORD = DEV_MODE ? process.env.DEV_IMPERSONATE_PASSWORD : undefined;
13+
export const DEV_IMPERSONATE_TOKEN = DEV_MODE ? process.env.DEV_IMPERSONATE_TOKEN : undefined; // Temporary work around: get impersonate to work through token, becuase of hostname resolve problem and IBM not using oauth proxy
1314
export const APP_ENV = process.env.APP_ENV;
1415

1516
export const USER_ACCESS_TOKEN = 'x-forwarded-access-token';

0 commit comments

Comments
 (0)