diff --git a/src/Common/MongoProxyClient.ts b/src/Common/MongoProxyClient.ts index 5c0f4d743..d5020745c 100644 --- a/src/Common/MongoProxyClient.ts +++ b/src/Common/MongoProxyClient.ts @@ -724,7 +724,15 @@ export function useMongoProxyEndpoint(api: string): boolean { MongoProxyEndpoints.Mooncake, ]; + let canAccessMongoProxy: boolean = userContext.databaseAccount.properties.publicNetworkAccess === "Enabled"; + if ( + configContext.MONGO_PROXY_ENDPOINT !== MongoProxyEndpoints.Local && + userContext.databaseAccount.properties.ipRules?.length > 0 + ) { + canAccessMongoProxy = canAccessMongoProxy && configContext.MONGO_PROXY_OUTBOUND_IPS_ALLOWLISTED; + } return ( + canAccessMongoProxy && configContext.NEW_MONGO_APIS?.includes(api) && activeMongoProxyEndpoints.includes(configContext.MONGO_PROXY_ENDPOINT) ); diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index f675160c6..1877d8f0c 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -54,8 +54,10 @@ export interface ConfigContext { MONGO_BACKEND_ENDPOINT?: string; MONGO_PROXY_ENDPOINT?: string; NEW_MONGO_APIS?: string[]; + MONGO_PROXY_OUTBOUND_IPS_ALLOWLISTED?: boolean; CASSANDRA_PROXY_ENDPOINT?: string; NEW_CASSANDRA_APIS?: string[]; + CASSANDRA_PROXY_OUTBOUND_IPS_ALLOWLISTED: boolean; PROXY_PATH?: string; JUNO_ENDPOINT: string; GITHUB_CLIENT_ID: string; @@ -117,8 +119,10 @@ let configContext: Readonly = { "legacyMongoShell", "bulkdelete", ], + MONGO_PROXY_OUTBOUND_IPS_ALLOWLISTED: false, CASSANDRA_PROXY_ENDPOINT: CassandraProxyEndpoints.Prod, NEW_CASSANDRA_APIS: ["postQuery", "createOrDelete", "getKeys", "getSchema"], + CASSANDRA_PROXY_OUTBOUND_IPS_ALLOWLISTED: false, isTerminalEnabled: false, isPhoenixEnabled: false, }; diff --git a/src/Explorer/Tables/TableDataClient.ts b/src/Explorer/Tables/TableDataClient.ts index 4e0859f95..8ba912bc5 100644 --- a/src/Explorer/Tables/TableDataClient.ts +++ b/src/Explorer/Tables/TableDataClient.ts @@ -757,7 +757,15 @@ export class CassandraAPIDataClient extends TableDataClient { CassandraProxyEndpoints.Mooncake, ]; + let canAccessCassandraProxy: boolean = userContext.databaseAccount.properties.publicNetworkAccess === "Enabled"; + if ( + configContext.CASSANDRA_PROXY_ENDPOINT !== CassandraProxyEndpoints.Development && + userContext.databaseAccount.properties.ipRules?.length > 0 + ) { + canAccessCassandraProxy = canAccessCassandraProxy && configContext.CASSANDRA_PROXY_OUTBOUND_IPS_ALLOWLISTED; + } return ( + canAccessCassandraProxy && configContext.NEW_CASSANDRA_APIS?.includes(api) && activeCassandraProxyEndpoints.includes(configContext.CASSANDRA_PROXY_ENDPOINT) ); diff --git a/src/Explorer/Tabs/Tabs.tsx b/src/Explorer/Tabs/Tabs.tsx index 0996922a3..c0d3a6b65 100644 --- a/src/Explorer/Tabs/Tabs.tsx +++ b/src/Explorer/Tabs/Tabs.tsx @@ -1,7 +1,7 @@ import { IMessageBarStyles, Link, MessageBar, MessageBarButton, MessageBarType } from "@fluentui/react"; import { CassandraProxyEndpoints, MongoProxyEndpoints } from "Common/Constants"; import { sendMessage } from "Common/MessageHandler"; -import { Platform, configContext } from "ConfigContext"; +import { Platform, configContext, updateConfigContext } from "ConfigContext"; import { IpRule } from "Contracts/DataModels"; import { MessageTypes } from "Contracts/ExplorerContracts"; import { CollectionTabKind } from "Contracts/ViewModels"; @@ -397,6 +397,12 @@ const showMongoAndCassandraProxiesNetworkSettingsWarning = (): boolean => { ipAddressesFromIPRules.includes(mongoProxyOutboundIP), ); + if (ipRulesIncludeMongoProxy) { + updateConfigContext({ + MONGO_PROXY_OUTBOUND_IPS_ALLOWLISTED: true, + }); + } + return !ipRulesIncludeMongoProxy; } else if (userContext.apiType === "Cassandra") { const isProdOrMpacCassandraProxyEndpoint: boolean = [ @@ -415,6 +421,12 @@ const showMongoAndCassandraProxiesNetworkSettingsWarning = (): boolean => { (cassandraProxyOutboundIP: string) => ipAddressesFromIPRules.includes(cassandraProxyOutboundIP), ); + if (ipRulesIncludeCassandraProxy) { + updateConfigContext({ + CASSANDRA_PROXY_OUTBOUND_IPS_ALLOWLISTED: true, + }); + } + return !ipRulesIncludeCassandraProxy; } }