Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: added visibility for connected resources to gateway
Sheen Capadnganf4a34fd93908
diff --git a/backend/src/ee/routes/v2/gateway-router.ts b/backend/src/ee/routes/v2/gateway-router.tsindex 03cea15b3f..6c67766b3e 100644--- a/backend/src/ee/routes/v2/gateway-router.ts+++ b/backend/src/ee/routes/v2/gateway-router.ts@@ -157,4 +157,90 @@ export const registerGatewayV2Router = async (server: FastifyZodProvider) => {return pamSessionKey;}});++ server.route({+ method: "GET",+ url: "/:id/resources",+ config: {+ rateLimit: readLimit+ },+ schema: {+ operationId: "getGatewayConnectedResources",+ params: z.object({+ id: z.string().uuid()+ }),+ response: {+ 200: z.object({+ appConnections: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ app: z.string(),+ projectId: z.string().nullish(),+ projectName: z.string().nullish()+ })+ ),+ dynamicSecrets: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ folderId: z.string(),+ projectId: z.string(),+ projectName: z.string(),+ environmentSlug: z.string()+ })+ ),+ pamResources: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ projectId: z.string(),+ projectName: z.string(),+ resourceType: z.string()+ })+ ),+ pamDiscoverySources: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ projectId: z.string(),+ projectName: z.string()+ })+ ),+ kubernetesAuths: z.array(+ z.object({+ id: z.string(),+ identityId: z.string(),+ identityName: z.string()+ })+ ),+ mcpServers: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ projectId: z.string(),+ projectName: z.string()+ })+ ),+ pkiDiscoveryConfigs: z.array(+ z.object({+ id: z.string(),+ name: z.string(),+ projectId: z.string(),+ projectName: z.string()+ })+ )+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const resources = await server.services.gatewayV2.getConnectedResources({+ orgPermission: req.permission,+ gatewayId: req.params.id+ });++ return resources;+ }+ });};diff --git a/backend/src/ee/services/ai-mcp-server/ai-mcp-server-dal.ts b/backend/src/ee/services/ai-mcp-server/ai-mcp-server-dal.tsindex b0798c3ba6..e48869fa6c 100644--- a/backend/src/ee/services/ai-mcp-server/ai-mcp-server-dal.ts+++ b/backend/src/ee/services/ai-mcp-server/ai-mcp-server-dal.ts@@ -1,3 +1,5 @@+import { Knex } from "knex";+import { TDbClient } from "@app/db";import { TableName } from "@app/db/schemas";import { ormify } from "@app/lib/knex";@@ -7,5 +9,19 @@ export type TAiMcpServerDALFactory = ReturnType<typeof aiMcpServerDALFactory>;export const aiMcpServerDALFactory = (db: TDbClient) => {const aiMcpServerOrm = ormify(db, TableName.AiMcpServer);- return aiMcpServerOrm;+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.AiMcpServer)+ .leftJoin(TableName.Project, `${TableName.AiMcpServer}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.AiMcpServer}.gatewayId`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.AiMcpServer),+ db.ref("name").withSchema(TableName.AiMcpServer),+ db.ref("projectId").withSchema(TableName.AiMcpServer),+ db.ref("name").withSchema(TableName.Project).as("projectName")+ );++ return docs;+ };++ return { ...aiMcpServerOrm, findByGatewayId };};diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-dal.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-dal.tsindex 4f99008a5a..55af744838 100644--- a/backend/src/ee/services/dynamic-secret/dynamic-secret-dal.ts+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-dal.ts@@ -33,6 +33,19 @@ export interface TDynamicSecretDALFactory extends Omit<TOrmify<TableName.Dynamicfilter: TFindFilter<TDynamicSecrets>,arg?: TFindOpt<TDynamicSecrets>) => Promise<TDynamicSecretWithMetadata[]>;+ findByGatewayId: (+ gatewayId: string,+ tx?: Knex+ ) => Promise<+ Array<{+ id: string;+ name: string;+ folderId: string;+ projectId: string;+ projectName: string | null;+ environmentSlug: string;+ }>+ >;}export const dynamicSecretDALFactory = (db: TDbClient): TDynamicSecretDALFactory => {@@ -182,5 +195,23 @@ export const dynamicSecretDALFactory = (db: TDbClient): TDynamicSecretDALFactory}};- return { ...orm, listDynamicSecretsByFolderIds, findOne, findWithMetadata };+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.DynamicSecret)+ .leftJoin(TableName.SecretFolder, `${TableName.DynamicSecret}.folderId`, `${TableName.SecretFolder}.id`)+ .leftJoin(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)+ .leftJoin(TableName.Project, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.DynamicSecret}.gatewayV2Id`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.DynamicSecret),+ db.ref("name").withSchema(TableName.DynamicSecret),+ db.ref("folderId").withSchema(TableName.DynamicSecret),+ db.ref("projectId").withSchema(TableName.Environment),+ db.ref("name").withSchema(TableName.Project).as("projectName"),+ db.ref("slug").withSchema(TableName.Environment).as("environmentSlug")+ );++ return docs;+ };++ return { ...orm, listDynamicSecretsByFolderIds, findOne, findWithMetadata, findByGatewayId };};diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.tsindex 9ae9099a3a..267cdf101f 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts@@ -13,6 +13,7 @@ import { GatewayProxyProtocol } from "@app/lib/gateway/types";import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";import { logger } from "@app/lib/logger";import { OrgServiceActor } from "@app/lib/types";+import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";import { constructPemChainFromCerts } from "@app/services/certificate/certificate-fns";import { CertExtendedKeyUsage, CertKeyAlgorithm, CertKeyUsage } from "@app/services/certificate/certificate-types";@@ -20,6 +21,7 @@ import {createSerialNumber,keyAlgorithmToAlgCfg} from "@app/services/certificate-authority/certificate-authority-fns";+import { TIdentityKubernetesAuthDALFactory } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-dal";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { KmsDataKey } from "@app/services/kms/kms-types";import { TNotificationServiceFactory } from "@app/services/notification/notification-service";@@ -27,9 +29,14 @@ import { NotificationType } from "@app/services/notification/notification-types"import { TOrgDALFactory } from "@app/services/org/org-dal";import { TSmtpService } from "@app/services/smtp/smtp-service";+import { TAiMcpServerDALFactory } from "../ai-mcp-server/ai-mcp-server-dal";+import { TDynamicSecretDALFactory } from "../dynamic-secret/dynamic-secret-dal";+import { TPamDiscoverySourceDALFactory } from "../pam-discovery/pam-discovery-source-dal";+import { TPamResourceDALFactory } from "../pam-resource/pam-resource-dal";import { PamResource } from "../pam-resource/pam-resource-enums";import { OrgPermissionGatewayActions, OrgPermissionSubjects } from "../permission/org-permission";import { TPermissionServiceFactory } from "../permission/permission-service-types";+import { TPkiDiscoveryConfigDALFactory } from "../pki-discovery/pki-discovery-config-dal";import { TRelayDALFactory } from "../relay/relay-dal";import { TRelayServiceFactory } from "../relay/relay-service";import { GATEWAY_ACTOR_OID, GATEWAY_ROUTING_INFO_OID, PAM_INFO_OID } from "./gateway-v2-constants";@@ -47,6 +54,13 @@ type TGatewayV2ServiceFactoryDep = {orgDAL: Pick<TOrgDALFactory, "findOrgMembersByRole">;notificationService: Pick<TNotificationServiceFactory, "createUserNotifications">;smtpService: Pick<TSmtpService, "sendMail">;+ appConnectionDAL: Pick<TAppConnectionDALFactory, "findByGatewayId">;+ dynamicSecretDAL: Pick<TDynamicSecretDALFactory, "findByGatewayId">;+ pamResourceDAL: Pick<TPamResourceDALFactory, "findByGatewayId">;+ pamDiscoverySourceDAL: Pick<TPamDiscoverySourceDALFactory, "findByGatewayId">;+ identityKubernetesAuthDAL: Pick<TIdentityKubernetesAuthDALFactory, "findByGatewayId">;+ aiMcpServerDAL: Pick<TAiMcpServerDALFactory, "findByGatewayId">;+ pkiDiscoveryConfigDAL: Pick<TPkiDiscoveryConfigDALFactory, "findByGatewayId">;};export type TGatewayV2ServiceFactory = ReturnType<typeof gatewayV2ServiceFactory>;@@ -59,7 +73,14 @@ export const gatewayV2ServiceFactory = ({relayDAL,permissionService,orgDAL,- notificationService+ notificationService,+ appConnectionDAL,+ dynamicSecretDAL,+ pamResourceDAL,+ pamDiscoverySourceDAL,+ identityKubernetesAuthDAL,+ aiMcpServerDAL,+ pkiDiscoveryConfigDAL}: TGatewayV2ServiceFactoryDep) => {const $validateIdentityAccessToGateway = async (orgId: string, actorId: string, actorAuthMethod: ActorAuthMethod) => {const { permission } = await permissionService.getOrgPermission({@@ -927,6 +948,61 @@ export const gatewayV2ServiceFactory = ({}};+ const getConnectedResources = async ({+ orgPermission,+ gatewayId+ }: {+ orgPermission: OrgServiceActor;+ gatewayId: string;+ }) => {+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: orgPermission.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: `Gateway ${gatewayId} not found` });+ }++ const { permission } = await permissionService.getOrgPermission({+ actor: orgPermission.type,+ actorId: orgPermission.id,+ orgId: gateway.orgId,+ actorAuthMethod: orgPermission.authMethod,+ actorOrgId: orgPermission.orgId,+ scope: OrganizationActionScope.Any+ });++ ForbiddenError.from(permission).throwUnlessCan(+ OrgPermissionGatewayActions.ListGateways,+ OrgPermissionSubjects.Gateway+ );++ const [+ appConnections,+ dynamicSecrets,+ pamResources,+ pamDiscoverySources,+ kubernetesAuths,+ mcpServers,+ pkiDiscoveryConfigs+ ] = await Promise.all([+ appConnectionDAL.findByGatewayId(gatewayId),+ dynamicSecretDAL.findByGatewayId(gatewayId),+ pamResourceDAL.findByGatewayId(gatewayId),+ pamDiscoverySourceDAL.findByGatewayId(gatewayId),+ identityKubernetesAuthDAL.findByGatewayId(gatewayId),+ aiMcpServerDAL.findByGatewayId(gatewayId),+ pkiDiscoveryConfigDAL.findByGatewayId(gatewayId)+ ]);++ return {+ appConnections,+ dynamicSecrets,+ pamResources,+ pamDiscoverySources,+ kubernetesAuths,+ mcpServers,+ pkiDiscoveryConfigs+ };+ };+return {listGateways,registerGateway,@@ -935,6 +1011,7 @@ export const gatewayV2ServiceFactory = ({deleteGatewayById,heartbeat,getPamSessionKey,- healthcheckNotify+ healthcheckNotify,+ getConnectedResources};};diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-types.ts b/backend/src/ee/services/gateway-v2/gateway-v2-types.tsindex d004053831..1bca7412ed 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-types.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-types.ts@@ -11,3 +11,64 @@ export type TGatewayV2ConnectionDetails = {serverCertificateChain: string;};};++export type TGatewayConnectedAppConnection = {+ id: string;+ name: string;+ app: string;+ projectId?: string | null;+ projectName?: string;+};++export type TGatewayConnectedDynamicSecret = {+ id: string;+ name: string;+ folderId: string;+ projectId?: string;+ projectName?: string;+ environmentSlug?: string;+};++export type TGatewayConnectedPamResource = {+ id: string;+ name: string;+ projectId: string;+ projectName?: string;+ resourceType: string;+};++export type TGatewayConnectedPamDiscoverySource = {+ id: string;+ name: string;+ projectId: string;+ projectName?: string;+};++export type TGatewayConnectedKubernetesAuth = {+ id: string;+ identityId: string;+};++export type TGatewayConnectedMcpServer = {+ id: string;+ name: string;+ projectId: string;+ projectName?: string;+};++export type TGatewayConnectedPkiDiscoveryConfig = {+ id: string;+ name: string;+ projectId: string;+ projectName?: string;+};++export type TGatewayConnectedResources = {+ appConnections: TGatewayConnectedAppConnection[];+ dynamicSecrets: TGatewayConnectedDynamicSecret[];+ pamResources: TGatewayConnectedPamResource[];+ pamDiscoverySources: TGatewayConnectedPamDiscoverySource[];+ kubernetesAuths: TGatewayConnectedKubernetesAuth[];+ mcpServers: TGatewayConnectedMcpServer[];+ pkiDiscoveryConfigs: TGatewayConnectedPkiDiscoveryConfig[];+};diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts b/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.tsindex ee752b0495..188d5ee637 100644--- a/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts+++ b/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts@@ -113,9 +113,24 @@ export const pamDiscoverySourceDALFactory = (db: TDbClient) => {}};+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.PamDiscoverySource)+ .leftJoin(TableName.Project, `${TableName.PamDiscoverySource}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.PamDiscoverySource}.gatewayId`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.PamDiscoverySource),+ db.ref("name").withSchema(TableName.PamDiscoverySource),+ db.ref("projectId").withSchema(TableName.PamDiscoverySource),+ db.ref("name").withSchema(TableName.Project).as("projectName")+ );++ return docs;+ };+return {...orm,findByProjectId,- findDueForScan+ findDueForScan,+ findByGatewayId};};diff --git a/backend/src/ee/services/pam-resource/pam-resource-dal.ts b/backend/src/ee/services/pam-resource/pam-resource-dal.tsindex 655880ea58..6259cbd212 100644--- a/backend/src/ee/services/pam-resource/pam-resource-dal.ts+++ b/backend/src/ee/services/pam-resource/pam-resource-dal.ts@@ -2,14 +2,15 @@ import { Knex } from "knex";import RE2 from "re2";import { TDbClient } from "@app/db";-import { TableName } from "@app/db/schemas";+import { TableName, TPamResources } from "@app/db/schemas";import { DatabaseError } from "@app/lib/errors";import { ormify, selectAllTableCols } from "@app/lib/knex";import { OrderByDirection } from "@app/lib/types";import { applyMetadataFilter } from "@app/services/resource-metadata/resource-metadata-fns";import { PamResourceOrderBy } from "./pam-resource-enums";-import { TPamResourceWithFavorite } from "./pam-resource-types";++type TPamResourceWithFavorite = TPamResources & { isFavorite: boolean };export type TPamResourceDALFactory = ReturnType<typeof pamResourceDALFactory>;export const pamResourceDALFactory = (db: TDbClient) => {@@ -148,5 +149,20 @@ export const pamResourceDALFactory = (db: TDbClient) => {}};- return { ...orm, findById, findByProjectId, findMetadataByResourceIds, findByAdServerResourceId };+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.PamResource)+ .leftJoin(TableName.Project, `${TableName.PamResource}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.PamResource}.gatewayId`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.PamResource),+ db.ref("name").withSchema(TableName.PamResource),+ db.ref("projectId").withSchema(TableName.PamResource),+ db.ref("resourceType").withSchema(TableName.PamResource),+ db.ref("name").withSchema(TableName.Project).as("projectName")+ );++ return docs;+ };++ return { ...orm, findById, findByProjectId, findMetadataByResourceIds, findByAdServerResourceId, findByGatewayId };};diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-config-dal.ts b/backend/src/ee/services/pki-discovery/pki-discovery-config-dal.tsindex fa4d4f20fa..f4fc179246 100644--- a/backend/src/ee/services/pki-discovery/pki-discovery-config-dal.ts+++ b/backend/src/ee/services/pki-discovery/pki-discovery-config-dal.ts@@ -149,6 +149,20 @@ export const pkiDiscoveryConfigDALFactory = (db: TDbClient) => {}};+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.PkiDiscoveryConfig)+ .leftJoin(TableName.Project, `${TableName.PkiDiscoveryConfig}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.PkiDiscoveryConfig}.gatewayId`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.PkiDiscoveryConfig),+ db.ref("name").withSchema(TableName.PkiDiscoveryConfig),+ db.ref("projectId").withSchema(TableName.PkiDiscoveryConfig),+ db.ref("name").withSchema(TableName.Project).as("projectName")+ );++ return docs;+ };+return {...pkiDiscoveryConfigOrm,findByProjectId,@@ -156,6 +170,7 @@ export const pkiDiscoveryConfigDALFactory = (db: TDbClient) => {findDueForScan,findByIdWithInstallationCounts,findByName,- claimScanSlot+ claimScanSlot,+ findByGatewayId};};diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 3fdae85fe5..894dae4e77 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -1258,6 +1258,10 @@ export const registerRoutes = async (const orgGatewayConfigV2DAL = orgGatewayConfigV2DalFactory(db);+ const pamResourceDAL = pamResourceDALFactory(db);+ const pamDiscoverySourceDAL = pamDiscoverySourceDALFactory(db);+ const aiMcpServerDAL = aiMcpServerDALFactory(db);+const sshCertificateAuthorityService = sshCertificateAuthorityServiceFactory({sshCertificateAuthorityDAL,sshCertificateAuthoritySecretDAL,@@ -1409,7 +1413,14 @@ export const registerRoutes = async (permissionService,orgDAL,notificationService,- smtpService+ smtpService,+ appConnectionDAL,+ dynamicSecretDAL,+ pamResourceDAL,+ pamDiscoverySourceDAL,+ identityKubernetesAuthDAL,+ aiMcpServerDAL,+ pkiDiscoveryConfigDAL});const secretSyncQueue = secretSyncQueueFactory({@@ -2718,17 +2729,14 @@ export const registerRoutes = async (});const pamFolderDAL = pamFolderDALFactory(db);- const pamResourceDAL = pamResourceDALFactory(db);const pamResourceFavoriteDAL = pamResourceFavoriteDALFactory(db);const pamAccountDAL = pamAccountDALFactory(db);const pamSessionDAL = pamSessionDALFactory(db);- const pamDiscoverySourceDAL = pamDiscoverySourceDALFactory(db);const pamDiscoveryRunDAL = pamDiscoveryRunDALFactory(db);const pamDiscoverySourceResourcesDAL = pamDiscoverySourceResourcesDALFactory(db);const pamDiscoverySourceAccountsDAL = pamDiscoverySourceAccountsDALFactory(db);const pamDiscoverySourceDependenciesDAL = pamDiscoverySourceDependenciesDALFactory(db);const pamAccountDependenciesDAL = pamAccountDependenciesDALFactory(db);- const aiMcpServerDAL = aiMcpServerDALFactory(db);const aiMcpServerToolDAL = aiMcpServerToolDALFactory(db);const aiMcpServerUserCredentialDAL = aiMcpServerUserCredentialDALFactory(db);const aiMcpActivityLogDAL = aiMcpActivityLogDALFactory(db);diff --git a/backend/src/services/app-connection/app-connection-dal.ts b/backend/src/services/app-connection/app-connection-dal.tsindex 4db0c2cdc7..0411f4980a 100644--- a/backend/src/services/app-connection/app-connection-dal.ts+++ b/backend/src/services/app-connection/app-connection-dal.ts@@ -154,5 +154,20 @@ export const appConnectionDALFactory = (db: TDbClient) => {});};- return { ...appConnectionOrm, findAppConnectionUsageById, findWithProjectDetails };+ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.AppConnection)+ .leftJoin(TableName.Project, `${TableName.AppConnection}.projectId`, `${TableName.Project}.id`)+ .where(`${TableName.AppConnection}.gatewayId`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.AppConnection),+ db.ref("name").withSchema(TableName.AppConnection),+ db.ref("app").withSchema(TableName.AppConnection),+ db.ref("projectId").withSchema(TableName.AppConnection),+ db.ref("name").withSchema(TableName.Project).as("projectName")+ );++ return docs;+ };++ return { ...appConnectionOrm, findAppConnectionUsageById, findWithProjectDetails, findByGatewayId };};diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-dal.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-dal.tsindex df59191010..9bf3394fe4 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-dal.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-dal.ts@@ -1,3 +1,5 @@+import { Knex } from "knex";+import { TDbClient } from "@app/db";import { TableName } from "@app/db/schemas";import { ormify } from "@app/lib/knex";@@ -6,5 +8,19 @@ export type TIdentityKubernetesAuthDALFactory = ReturnType<typeof identityKubernexport const identityKubernetesAuthDALFactory = (db: TDbClient) => {const kubernetesAuthOrm = ormify(db, TableName.IdentityKubernetesAuth);- return kubernetesAuthOrm;++ const findByGatewayId = async (gatewayId: string, tx?: Knex) => {+ const docs = await (tx || db.replicaNode())(TableName.IdentityKubernetesAuth)+ .leftJoin(TableName.Identity, `${TableName.IdentityKubernetesAuth}.identityId`, `${TableName.Identity}.id`)+ .where(`${TableName.IdentityKubernetesAuth}.gatewayV2Id`, gatewayId)+ .select(+ db.ref("id").withSchema(TableName.IdentityKubernetesAuth),+ db.ref("identityId").withSchema(TableName.IdentityKubernetesAuth),+ db.ref("name").withSchema(TableName.Identity).as("identityName")+ );++ return docs;+ };++ return { ...kubernetesAuthOrm, findByGatewayId };};diff --git a/frontend/src/hooks/api/gateways-v2/index.tsx b/frontend/src/hooks/api/gateways-v2/index.tsxindex f8dd99d037..177955438b 100644--- a/frontend/src/hooks/api/gateways-v2/index.tsx+++ b/frontend/src/hooks/api/gateways-v2/index.tsx@@ -1 +1,3 @@export * from "./mutations";+export * from "./queries";+export * from "./types";diff --git a/frontend/src/hooks/api/gateways-v2/queries.tsx b/frontend/src/hooks/api/gateways-v2/queries.tsxnew file mode 100644index 0000000000..3dffca664d--- /dev/null+++ b/frontend/src/hooks/api/gateways-v2/queries.tsx@@ -0,0 +1,28 @@+import { useQuery } from "@tanstack/react-query";++import { apiRequest } from "@app/config/request";++import { TGatewayConnectedResources } from "./types";++export const gatewaysV2QueryKeys = {+ allKey: () => ["gateways-v2"],+ connectedResourcesKey: (gatewayId: string) => [+ ...gatewaysV2QueryKeys.allKey(),+ "connected-resources",+ gatewayId+ ],+ connectedResources: (gatewayId: string) => ({+ queryKey: gatewaysV2QueryKeys.connectedResourcesKey(gatewayId),+ queryFn: async () => {+ const { data } = await apiRequest.get<TGatewayConnectedResources>(+ `/api/v2/gateways/${gatewayId}/resources`+ );+ return data;+ },+ enabled: Boolean(gatewayId)+ })+};++export const useGetGatewayConnectedResources = (gatewayId: string) => {+ return useQuery(gatewaysV2QueryKeys.connectedResources(gatewayId));+};diff --git a/frontend/src/hooks/api/gateways-v2/types.ts b/frontend/src/hooks/api/gateways-v2/types.tsindex 69bc217023..1ffe1c5617 100644--- a/frontend/src/hooks/api/gateways-v2/types.ts+++ b/frontend/src/hooks/api/gateways-v2/types.ts@@ -10,3 +10,65 @@ export type TGatewayV2 = {id: string;};};++export type TGatewayConnectedAppConnection = {+ id: string;+ name: string;+ app: string;+ projectId?: string | null;+ projectName?: string | null;+};++export type TGatewayConnectedDynamicSecret = {+ id: string;+ name: string;+ folderId: string;+ projectId: string;+ projectName: string;+ environmentSlug: string;+};++export type TGatewayConnectedPamResource = {+ id: string;+ name: string;+ projectId: string;+ projectName: string;+ resourceType: string;+};++export type TGatewayConnectedPamDiscoverySource = {+ id: string;+ name: string;+ projectId: string;+ projectName: string;+};++export type TGatewayConnectedKubernetesAuth = {+ id: string;+ identityId: string;+ identityName: string;+};++export type TGatewayConnectedMcpServer = {+ id: string;+ name: string;+ projectId: string;+ projectName: string;+};++export type TGatewayConnectedPkiDiscoveryConfig = {+ id: string;+ name: string;+ projectId: string;+ projectName: string;+};++export type TGatewayConnectedResources = {+ appConnections: TGatewayConnectedAppConnection[];+ dynamicSecrets: TGatewayConnectedDynamicSecret[];+ pamResources: TGatewayConnectedPamResource[];+ pamDiscoverySources: TGatewayConnectedPamDiscoverySource[];+ kubernetesAuths: TGatewayConnectedKubernetesAuth[];+ mcpServers: TGatewayConnectedMcpServer[];+ pkiDiscoveryConfigs: TGatewayConnectedPkiDiscoveryConfig[];+};diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsxindex 4b5015cab9..77cc741524 100644--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx@@ -5,6 +5,7 @@ import {faEdit,faEllipsisV,faInfoCircle,+ faLink,faMagnifyingGlass,faPlus,faSearch,@@ -45,9 +46,13 @@ import {import { withPermission } from "@app/hoc";import { usePopUp } from "@app/hooks";import { gatewaysQueryKeys, useDeleteGatewayById } from "@app/hooks/api/gateways";-import { useDeleteGatewayV2ById } from "@app/hooks/api/gateways-v2";+import {+ useDeleteGatewayV2ById,+ useGetGatewayConnectedResources+} from "@app/hooks/api/gateways-v2";import { EditGatewayDetailsModal } from "./components/EditGatewayDetailsModal";+import { GatewayConnectedResourcesDrawer } from "./components/GatewayConnectedResourcesDrawer";import { GatewayDeployModal } from "./components/GatewayDeployModal";const GatewayHealthStatus = ({ heartbeat }: { heartbeat?: string }) => {@@ -69,15 +74,65 @@ const GatewayHealthStatus = ({ heartbeat }: { heartbeat?: string }) => {);};+type GatewayConnectedCellProps = {+ gatewayId: string;+ isV1: boolean;+ onClick: () => void;+};++const GatewayConnectedCell = ({ gatewayId, isV1, onClick }: GatewayConnectedCellProps) => {+ const { data: resources, isPending } = useGetGatewayConnectedResources(isV1 ? "" : gatewayId);++ if (isV1) {+ return <span className="text-mineshaft-400">—</span>;+ }++ if (isPending) {+ return <span className="text-mineshaft-400">...</span>;+ }++ const totalCount = resources+ ? resources.appConnections.length ++ resources.dynamicSecrets.length ++ resources.pamResources.length ++ resources.pamDiscoverySources.length ++ resources.kubernetesAuths.length ++ resources.mcpServers.length ++ resources.pkiDiscoveryConfigs.length+ : 0;++ if (totalCount === 0) {+ return <span className="text-mineshaft-400">—</span>;+ }++ return (+ <button+ type="button"+ onClick={onClick}+ className="flex items-center gap-1.5 text-primary-400 hover:text-primary-300"+ >+ <FontAwesomeIcon icon={faLink} className="h-3 w-3" />+ <span>+ {totalCount} resource{totalCount !== 1 ? "s" : ""}+ </span>+ </button>+ );+};+export const GatewayTab = withPermission(() => {const [search, setSearch] = useState("");+ const [selectedGateway, setSelectedGateway] = useState<{+ id: string;+ name: string;+ } | null>(null);const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list());const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["deployGateway","deleteGateway",- "editDetails"+ "editDetails",+ "connectedResources"] as const);const deleteGatewayById = useDeleteGatewayById();@@ -135,7 +190,8 @@ export const GatewayTab = withPermission(<Table><THead><Tr>- <Th className="w-1/2">Name</Th>+ <Th className="w-1/3">Name</Th>+ <Th>Connected</Th><Th>Health Check<Tooltip@@ -151,7 +207,7 @@ export const GatewayTab = withPermission(</THead><TBody>{isGatewaysLoading && (- <TableSkeleton innerKey="gateway-table" columns={4} key="gateway-table" />+ <TableSkeleton innerKey="gateway-table" columns={5} key="gateway-table" />)}{filteredGateway?.map((el) => (<Tr key={el.id}>@@ -163,6 +219,16 @@ export const GatewayTab = withPermission(</span></div></Td>+ <Td>+ <GatewayConnectedCell+ gatewayId={el.id}+ isV1={el.isV1}+ onClick={() => {+ setSelectedGateway({ id: el.id, name: el.name });+ handlePopUpOpen("connectedResources");+ }}+ />+ </Td><Td><GatewayHealthStatus heartbeat={el.heartbeat} /></Td>@@ -259,6 +325,17 @@ export const GatewayTab = withPermission(isOpen={popUp.deployGateway.isOpen}onOpenChange={(isOpen) => handlePopUpToggle("deployGateway", isOpen)}/>+ {selectedGateway && (+ <GatewayConnectedResourcesDrawer+ isOpen={popUp.connectedResources.isOpen}+ onOpenChange={(isOpen) => {+ handlePopUpToggle("connectedResources", isOpen);+ if (!isOpen) setSelectedGateway(null);+ }}+ gatewayId={selectedGateway.id}+ gatewayName={selectedGateway.name}+ />+ )}</TableContainer></div></div>diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayConnectedResourcesDrawer.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayConnectedResourcesDrawer.tsxnew file mode 100644index 0000000000..1e3ec48d02--- /dev/null+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayConnectedResourcesDrawer.tsx@@ -0,0 +1,287 @@+import { faChevronDown, faChevronRight, faLink } from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { Link } from "@tanstack/react-router";++import { Drawer, DrawerContent, Spinner } from "@app/components/v2";+import { useOrganization } from "@app/context";+import { useToggle } from "@app/hooks";+import {+ TGatewayConnectedResources,+ useGetGatewayConnectedResources+} from "@app/hooks/api/gateways-v2";++type Props = {+ isOpen: boolean;+ onOpenChange: (isOpen: boolean) => void;+ gatewayId: string;+ gatewayName: string;+};++type ResourceSectionProps = {+ title: string;+ count: number;+ children: React.ReactNode;+ icon?: React.ReactNode;+};++const ResourceSection = ({ title, count, children, icon }: ResourceSectionProps) => {+ const [isExpanded, setIsExpanded] = useToggle(true);++ if (count === 0) return null;++ return (+ <div className="border-b border-mineshaft-600 last:border-b-0">+ <button+ type="button"+ onClick={() => setIsExpanded.toggle()}+ className="flex w-full items-center gap-2 px-1 py-3 text-left hover:bg-mineshaft-700/30"+ >+ <FontAwesomeIcon+ icon={isExpanded ? faChevronDown : faChevronRight}+ className="h-3 w-3 text-mineshaft-400"+ />+ {icon}+ <span className="flex-1 text-sm font-medium text-mineshaft-100">{title}</span>+ <span className="rounded bg-mineshaft-600 px-2 py-0.5 text-xs text-mineshaft-300">+ {count}+ </span>+ </button>+ {isExpanded && <div className="pb-3 pl-6">{children}</div>}+ </div>+ );+};++type ResourceItemProps = {+ name: string;+ subtitle?: string;+ to?: string;+ params?: Record<string, string>;+};++const ResourceItem = ({ name, subtitle, to, params }: ResourceItemProps) => {+ const content = (+ <div className="py-1.5">+ <div className="text-sm text-mineshaft-100">{name}</div>+ {subtitle && <div className="text-xs text-mineshaft-400">{subtitle}</div>}+ </div>+ );++ if (to && params) {+ return (+ <Link+ to={to as "/"}+ params={params}+ className="-mx-2 block rounded px-2 hover:bg-mineshaft-700/50"+ >+ {content}+ </Link>+ );+ }++ return <div className="-mx-2 px-2">{content}</div>;+};++const getTotalResourceCount = (resources: TGatewayConnectedResources | undefined): number => {+ if (!resources) return 0;+ return (+ resources.appConnections.length ++ resources.dynamicSecrets.length ++ resources.pamResources.length ++ resources.pamDiscoverySources.length ++ resources.kubernetesAuths.length ++ resources.mcpServers.length ++ resources.pkiDiscoveryConfigs.length+ );+};++const getResourceTypeCount = (resources: TGatewayConnectedResources | undefined): number => {+ if (!resources) return 0;+ let count = 0;+ if (resources.appConnections.length > 0) count += 1;+ if (resources.dynamicSecrets.length > 0) count += 1;+ if (resources.pamResources.length > 0) count += 1;+ if (resources.pamDiscoverySources.length > 0) count += 1;+ if (resources.kubernetesAuths.length > 0) count += 1;+ if (resources.mcpServers.length > 0) count += 1;+ if (resources.pkiDiscoveryConfigs.length > 0) count += 1;+ return count;+};++export const GatewayConnectedResourcesDrawer = ({+ isOpen,+ onOpenChange,+ gatewayId,+ gatewayName+}: Props) => {+ const { currentOrg } = useOrganization();+ const { data: resources, isPending } = useGetGatewayConnectedResources(isOpen ? gatewayId : "");++ const totalCount = getTotalResourceCount(resources);+ const typeCount = getResourceTypeCount(resources);++ return (+ <Drawer isOpen={isOpen} onOpenChange={onOpenChange}>+ <DrawerContent+ title="Connected Resources"+ subTitle={gatewayName}+ className="w-[400px]"+ footerContent={+ totalCount > 0 ? (+ <div className="text-xs text-mineshaft-400">+ To delete this gateway, first remove or reassign these connected resources.+ </div>+ ) : null+ }+ >+ {isPending ? (+ <div className="flex h-32 items-center justify-center">+ <Spinner size="lg" />+ </div>+ ) : (+ <div>+ <div className="mb-4 text-sm text-mineshaft-300">+ {totalCount > 0 ? (+ <>+ {totalCount} resource{totalCount !== 1 ? "s" : ""} connected across {typeCount}{" "}+ type{typeCount !== 1 ? "s" : ""}+ </>+ ) : (+ "No resources connected to this gateway"+ )}+ </div>++ <div className="rounded-md border border-mineshaft-600">+ <ResourceSection+ title="App Connections"+ count={resources?.appConnections.length ?? 0}+ icon={<FontAwesomeIcon icon={faLink} className="h-3 w-3 text-primary-500" />}+ >+ {resources?.appConnections.map((conn) => (+ <ResourceItem+ key={conn.id}+ name={conn.name}+ subtitle={+ conn.projectName+ ? `${conn.app} · ${conn.projectName}`+ : `${conn.app} · Organization`+ }+ to="/organizations/$orgId/app-connections/"+ params={{ orgId: currentOrg.id }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="Dynamic Secrets"+ count={resources?.dynamicSecrets.length ?? 0}+ icon={<span className="text-yellow-500">✧</span>}+ >+ {resources?.dynamicSecrets.map((ds) => (+ <ResourceItem+ key={ds.id}+ name={ds.name}+ subtitle={`${ds.environmentSlug} · ${ds.projectName}`}+ to="/organizations/$orgId/projects/secret-management/$projectId/secrets/$envSlug"+ params={{+ orgId: currentOrg.id,+ projectId: ds.projectId,+ envSlug: ds.environmentSlug+ }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="PAM Resources"+ count={resources?.pamResources.length ?? 0}+ icon={<span className="text-green-500">⊕</span>}+ >+ {resources?.pamResources.map((res) => (+ <ResourceItem+ key={res.id}+ name={res.name}+ subtitle={`${res.resourceType} · ${res.projectName}`}+ to="/organizations/$orgId/projects/pam/$projectId/resources/"+ params={{ orgId: currentOrg.id, projectId: res.projectId }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="Discovery Sources"+ count={resources?.pamDiscoverySources.length ?? 0}+ icon={<span className="text-blue-500">◎</span>}+ >+ {resources?.pamDiscoverySources.map((source) => (+ <ResourceItem+ key={source.id}+ name={source.name}+ subtitle={source.projectName}+ to="/organizations/$orgId/projects/pam/$projectId/discovery/"+ params={{ orgId: currentOrg.id, projectId: source.projectId }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="Kubernetes Auth"+ count={resources?.kubernetesAuths.length ?? 0}+ icon={<span className="text-purple-500">⎈</span>}+ >+ {resources?.kubernetesAuths.map((auth) => (+ <ResourceItem+ key={auth.id}+ name={auth.identityName}+ subtitle="Kubernetes Auth"+ to="/organizations/$orgId/identities/$identityId"+ params={{ orgId: currentOrg.id, identityId: auth.identityId }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="MCP Servers"+ count={resources?.mcpServers.length ?? 0}+ icon={<span className="text-cyan-500">⬡</span>}+ >+ {resources?.mcpServers.map((server) => (+ <ResourceItem+ key={server.id}+ name={server.name}+ subtitle={server.projectName}+ to="/organizations/$orgId/projects/ai/$projectId/mcp-servers/$serverId"+ params={{+ orgId: currentOrg.id,+ projectId: server.projectId,+ serverId: server.id+ }}+ />+ ))}+ </ResourceSection>++ <ResourceSection+ title="PKI Discovery"+ count={resources?.pkiDiscoveryConfigs.length ?? 0}+ icon={<span className="text-orange-500">🔐</span>}+ >+ {resources?.pkiDiscoveryConfigs.map((config) => (+ <ResourceItem+ key={config.id}+ name={config.name}+ subtitle={config.projectName}+ to="/organizations/$orgId/projects/cert-manager/$projectId/discovery/$discoveryId"+ params={{+ orgId: currentOrg.id,+ projectId: config.projectId,+ discoveryId: config.id+ }}+ />+ ))}+ </ResourceSection>+ </div>+ </div>+ )}+ </DrawerContent>+ </Drawer>+ );+};