Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export enum ActionType {
}

export const setUser = (userInfo: UserInfo) => action(ActionType.SetUser, { userInfo });
export const beginImpersonate = (kind: string, name: string, subprotocols: string[]) =>
action(ActionType.BeginImpersonate, { kind, name, subprotocols });

export const beginImpersonate = (
kind: string,
name: string,
subprotocols: string[],
groups?: string[],
) => action(ActionType.BeginImpersonate, { kind, name, subprotocols, groups });
export const endImpersonate = () => action(ActionType.EndImpersonate);
export const setAdmissionWebhookWarning = (id: string, warning: AdmissionWebhookWarning) =>
action(ActionType.SetAdmissionWebhookWarning, { id, warning });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const coreReducer = (
kind: action.payload.kind,
name: action.payload.name,
subprotocols: action.payload.subprotocols,
groups: action.payload.groups,
},
};
case ActionType.EndImpersonate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type ImpersonateKind = {
kind: string;
name: string;
subprotocols: string[];
groups?: string[];
};

export type CoreState = {
Expand Down
23 changes: 19 additions & 4 deletions frontend/public/actions/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export const setActiveNamespace = (namespace: string = '') => {
return action(ActionType.SetActiveNamespace, { namespace });
};

export const startImpersonate = (kind: string, name: string) => async (dispatch, getState) => {
export const startImpersonate = (kind: string, name: string, groups?: string[]) => async (
dispatch,
getState,
) => {
const textEncoder = new TextEncoder();

const imp = getImpersonate(getState());
Expand All @@ -235,12 +238,24 @@ export const startImpersonate = (kind: string, name: string) => async (dispatch,
let subprotocols;
if (kind === 'User') {
subprotocols = [`Impersonate-User.${encodedName}`];
}
if (kind === 'Group') {
} else if (kind === 'Group') {
subprotocols = [`Impersonate-Group.${encodedName}`];
} else if (kind === 'UserWithGroups' && groups && groups.length > 0) {
// User with multiple groups impersonation
// Encode user subprotocol
subprotocols = [`Impersonate-User.${encodedName}`];
// Encode each group as a separate subprotocol
groups.forEach((group) => {
const encodedGroup = Base64.encode(
String.fromCharCode.apply(String, textEncoder.encode(group)),
)
.replace(/=/g, '_')
.replace(/\//g, '-');
subprotocols.push(`Impersonate-Group.${encodedGroup}`);
});
}

dispatch(beginImpersonate(kind, name, subprotocols));
dispatch(beginImpersonate(kind, name, subprotocols, groups));
subsClient.close(false, true);
dispatch(clearSSARFlags());
dispatch(detectFeatures());
Expand Down
13 changes: 13 additions & 0 deletions frontend/public/reducers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ export const defaults = _.mapValues(FLAGS, (flag) => {
);
case FLAGS.DEVCONSOLE_PROXY:
return true;
case FLAGS.IMPERSONATE: {
// FIXME: Check localStorage for override, default to false (disabled)
// This is the flag for the multi-group impersonation feature.
const localStorageValue = localStorage.getItem('bridge/impersonate-enabled');
if (localStorageValue === 'true') {
// eslint-disable-next-line no-console
console.log('[Feature Flag] Impersonation enabled via localStorage');
return true;
}
// eslint-disable-next-line no-console
console.log('[Feature Flag] Impersonation disabled (default or localStorage=false)');
return false;
}
default:
return undefined;
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/public/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ if (process.env.NODE_ENV !== 'production') {
window.store = store;
}

// Temporary: Expose store for testing multi-group impersonation
// TODO: Remove this after testing. This SHOULD NOT BE IN MERGED in production!!!!!
(window as any).store = store;

// Expose UI actions for testing
import * as UIActions from './actions/ui';
(window as any).UIActions = UIActions;
Comment on lines +62 to +68
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Danger: this part of the code just used here for showcasing how you can test this action out. It should be removed before getting merged.


export default store;