Add additional changes for Portal RBAC functionality

This commit is contained in:
Senthamil Sindhu 2024-06-19 15:05:14 -07:00
parent be871737ad
commit 24af64a66d
4 changed files with 42 additions and 20 deletions

View File

@ -185,9 +185,6 @@ export class CassandraProxyAPIs {
export class Queries { export class Queries {
public static CustomPageOption: string = "custom"; public static CustomPageOption: string = "custom";
public static UnlimitedPageOption: string = "unlimited"; public static UnlimitedPageOption: string = "unlimited";
public static setAutomaticRBACOption: string = "Automatic";
public static setTrueRBACOption: string = "True";
public static setFalseRBACOption: string = "False";
public static itemsPerPage: number = 100; public static itemsPerPage: number = 100;
public static unlimitedItemsPerPage: number = 100; // TODO: Figure out appropriate value so it works for accounts with a large number of partitions public static unlimitedItemsPerPage: number = 100; // TODO: Figure out appropriate value so it works for accounts with a large number of partitions
public static containersPerPage: number = 50; public static containersPerPage: number = 50;
@ -199,6 +196,12 @@ export class Queries {
public static readonly DefaultMaxWaitTimeInSeconds = 30; public static readonly DefaultMaxWaitTimeInSeconds = 30;
} }
export class RBACOptions {
public static setAutomaticRBACOption: string = "Automatic";
public static setTrueRBACOption: string = "True";
public static setFalseRBACOption: string = "False";
}
export class SavedQueries { export class SavedQueries {
public static readonly CollectionName: string = "___Query"; public static readonly CollectionName: string = "___Query";
public static readonly DatabaseName: string = "___Cosmos"; public static readonly DatabaseName: string = "___Cosmos";

View File

@ -17,12 +17,23 @@ const _global = typeof self === "undefined" ? window : self;
export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => { export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
const { verb, resourceId, resourceType, headers } = requestInfo; const { verb, resourceId, resourceType, headers } = requestInfo;
if (userContext.features.enableAadDataPlane && userContext.aadToken) { console.log(`AAD Data Plane RBAC enabled "${userContext.dataPlaneRbacEnabled}" `);
if ((userContext.features.enableAadDataPlane || userContext.dataPlaneRbacEnabled) && userContext.aadToken) {
console.log(` Getting Auth token `);
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`; const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
const authorizationToken = `${AUTH_PREFIX}${userContext.aadToken}`; const authorizationToken = `${AUTH_PREFIX}${userContext.aadToken}`;
console.log(`Returning Auth token`);
return authorizationToken; return authorizationToken;
} }
if ((userContext.dataPlaneRbacEnabled) && userContext.authorizationToken) {
console.log(` Getting Portal Auth token `)
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
const authorizationToken = `${AUTH_PREFIX}${userContext.authorizationToken}`;
console.log(`Returning Portal Auth token`);
return authorizationToken;
}
if (configContext.platform === Platform.Emulator) { if (configContext.platform === Platform.Emulator) {
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK. // TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey); await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(verb, resourceId, resourceType, headers, EmulatorMasterKey);

View File

@ -45,11 +45,11 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
: Constants.Queries.CustomPageOption, : Constants.Queries.CustomPageOption,
); );
const [enableDataPlaneRBACOption, setEnableDataPlaneRBACOption] = useState<string>( const [enableDataPlaneRBACOption, setEnableDataPlaneRBACOption] = useState<string>(
LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.Queries.setAutomaticRBACOption LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setAutomaticRBACOption
? Constants.Queries.setAutomaticRBACOption ? Constants.RBACOptions.setAutomaticRBACOption
: LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.Queries.setTrueRBACOption : LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled) === Constants.RBACOptions.setTrueRBACOption
? Constants.Queries.setTrueRBACOption ? Constants.RBACOptions.setTrueRBACOption
: Constants.Queries.setFalseRBACOption : Constants.RBACOptions.setFalseRBACOption
); );
const [ruThresholdEnabled, setRUThresholdEnabled] = useState<boolean>(isRUThresholdEnabled()); const [ruThresholdEnabled, setRUThresholdEnabled] = useState<boolean>(isRUThresholdEnabled());
const [ruThreshold, setRUThreshold] = useState<number>(getRUThreshold()); const [ruThreshold, setRUThreshold] = useState<number>(getRUThreshold());
@ -222,9 +222,14 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
]; ];
const dataPlaneRBACOptionsList: IChoiceGroupOption[] = [ const dataPlaneRBACOptionsList: IChoiceGroupOption[] = [
{ key: Constants.Queries.setAutomaticRBACOption, text: "Automatic" }, { key: Constants.RBACOptions.setAutomaticRBACOption, text: "Automatic" },
{ key: Constants.Queries.setTrueRBACOption, text: "True" }, { key: Constants.RBACOptions.setTrueRBACOption, text: "True" },
{ key: Constants.Queries.setFalseRBACOption, text: "False"} { key: Constants.RBACOptions.setFalseRBACOption, text: "False"}
];
const defaultQueryResultsViewOptionList: IChoiceGroupOption[] = [
{ key: SplitterDirection.Vertical, text: "Vertical" },
{ key: SplitterDirection.Horizontal, text: "Horizontal" },
]; ];
const handleOnPriorityLevelOptionChange = ( const handleOnPriorityLevelOptionChange = (

View File

@ -1,3 +1,4 @@
import * as Constants from "Common/Constants";
import { createUri } from "Common/UrlUtility"; import { createUri } from "Common/UrlUtility";
import { DATA_EXPLORER_RPC_VERSION } from "Contracts/DataExplorerMessagesContract"; import { DATA_EXPLORER_RPC_VERSION } from "Contracts/DataExplorerMessagesContract";
import { FabricMessageTypes } from "Contracts/FabricMessageTypes"; import { FabricMessageTypes } from "Contracts/FabricMessageTypes";
@ -274,7 +275,7 @@ async function configureHostedWithAAD(config: AAD): Promise<Explorer> {
try { try {
if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) {
var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled);
if (isDataPlaneRbacSetting == "Automatic") if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption)
{ {
if (!account.properties.disableLocalAuth) { if (!account.properties.disableLocalAuth) {
keys = await listKeys(subscriptionId, resourceGroup, account.name); keys = await listKeys(subscriptionId, resourceGroup, account.name);
@ -285,7 +286,7 @@ async function configureHostedWithAAD(config: AAD): Promise<Explorer> {
}); });
} }
} }
else if(isDataPlaneRbacSetting == "True") { else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true dataPlaneRbacEnabled: true
}); });
@ -456,7 +457,7 @@ async function configurePortal(): Promise<Explorer> {
// Check for init message // Check for init message
const message: PortalMessage = event.data?.data; const message: PortalMessage = event.data?.data;
const inputs = message?.inputs; const inputs = message?.inputs;
const openAction = message?.openAction; const openAction = message?.openAction;
if (inputs) { if (inputs) {
if ( if (
@ -475,27 +476,29 @@ async function configurePortal(): Promise<Explorer> {
setTimeout(() => explorer.openNPSSurveyDialog(), 3000); setTimeout(() => explorer.openNPSSurveyDialog(), 3000);
} }
let dbAccount = userContext.databaseAccount;
let keys: DatabaseAccountListKeysResult = {}; let keys: DatabaseAccountListKeysResult = {};
const account = userContext.databaseAccount; const account = userContext.databaseAccount;
const subscriptionId = userContext.subscriptionId; const subscriptionId = userContext.subscriptionId;
const resourceGroup = userContext.resourceGroup; const resourceGroup = userContext.resourceGroup;
if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) { if(LocalStorageUtility.hasItem(StorageKey.DataPlaneRbacEnabled)) {
var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled); var isDataPlaneRbacSetting = LocalStorageUtility.getEntryString(StorageKey.DataPlaneRbacEnabled);
if (isDataPlaneRbacSetting == "Automatic") if (isDataPlaneRbacSetting == Constants.RBACOptions.setAutomaticRBACOption)
{ {
if (!account.properties.disableLocalAuth) { if (!account.properties.disableLocalAuth) {
keys = await listKeys(subscriptionId, resourceGroup, account.name); keys = await listKeys(subscriptionId, resourceGroup, account.name);
} }
else { else {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true dataPlaneRbacEnabled: true,
authorizationToken: message.inputs.authorizationToken
}); });
} }
} }
else if(isDataPlaneRbacSetting == "True") { else if(isDataPlaneRbacSetting == Constants.RBACOptions.setTrueRBACOption) {
updateUserContext({ updateUserContext({
dataPlaneRbacEnabled: true dataPlaneRbacEnabled: true,
authorizationToken: message.inputs.authorizationToken
}); });
} }
else { else {