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
address reviews
Andrey2f20ebfa0625
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.tsindex e3f582e727..450fcead50 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts@@ -79,8 +79,8 @@ type TGatewayV2ServiceFactoryDep = {dynamicSecretDAL: Pick<TDynamicSecretDALFactory, "findByGatewayId" | "countByGatewayId">;identityKubernetesAuthDAL: Pick<TIdentityKubernetesAuthDALFactory, "findByGatewayId" | "countByGatewayId">;pkiDiscoveryConfigDAL: Pick<TPkiDiscoveryConfigDALFactory, "findByGatewayId" | "countByGatewayId">;- pamAccountDAL: Pick<TPamAccountDALFactory, "findByGatewayId" | "countByGatewayId">;- pamAccountTemplateDAL: Pick<TPamAccountTemplateDALFactory, "findByGatewayId" | "countByGatewayId">;+ pamAccountDAL: Pick<TPamAccountDALFactory, "findByGatewayId" | "countByGatewayIds">;+ pamAccountTemplateDAL: Pick<TPamAccountTemplateDALFactory, "findByGatewayId" | "countByGatewayIds">;resourceAuthMethodService: Pick<TResourceAuthMethodServiceFactory,| "initAtCreate"@@ -337,8 +337,8 @@ export const gatewayV2ServiceFactory = ({gatewayIds.map((id) => identityKubernetesAuthDAL.countByGatewayId(id).then((count) => ({ id, count })))),Promise.all(gatewayIds.map((id) => pkiDiscoveryConfigDAL.countByGatewayId(id).then((count) => ({ id, count })))),- Promise.all(gatewayIds.map((id) => pamAccountDAL.countByGatewayId(id).then((count) => ({ id, count })))),- Promise.all(gatewayIds.map((id) => pamAccountTemplateDAL.countByGatewayId(id).then((count) => ({ id, count }))))+ pamAccountDAL.countByGatewayIds(gatewayIds),+ pamAccountTemplateDAL.countByGatewayIds(gatewayIds)]);const countMap = new Map<string, number>();diff --git a/backend/src/ee/services/pam-account-template/pam-account-template-dal.ts b/backend/src/ee/services/pam-account-template/pam-account-template-dal.tsindex 7eae03bbeb..05091cbcf2 100644--- a/backend/src/ee/services/pam-account-template/pam-account-template-dal.ts+++ b/backend/src/ee/services/pam-account-template/pam-account-template-dal.ts@@ -69,14 +69,14 @@ export const pamAccountTemplateDALFactory = (db: TDbClient) => {.where(`${TableName.PamAccountTemplate}.gatewayId`, gatewayId).select("id", "name", "type");- const countByGatewayId = async (gatewayId: string, tx?: Knex) => {- const result = await (tx || db.replicaNode())(TableName.PamAccountTemplate)- .where(`${TableName.PamAccountTemplate}.gatewayId`, gatewayId)- .count("id")- .first();-- return parseInt(String(result?.count || "0"), 10);- };+ const countByGatewayIds = async (gatewayIds: string[], tx?: Knex) =>+ (await (tx || db.replicaNode())(TableName.PamAccountTemplate)+ .whereIn(`${TableName.PamAccountTemplate}.gatewayId`, gatewayIds)+ .groupBy(`${TableName.PamAccountTemplate}.gatewayId`)+ .select(`${TableName.PamAccountTemplate}.gatewayId as id`, db.raw("count(*)::int as count"))) as {+ id: string;+ count: number;+ }[];return {...orm,@@ -84,6 +84,6 @@ export const pamAccountTemplateDALFactory = (db: TDbClient) => {countAccountsByTemplateId,getTemplateRotationStats,findByGatewayId,- countByGatewayId+ countByGatewayIds};};diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.tsindex 91cb60e7c7..05aa423dee 100644--- a/backend/src/ee/services/pam-account/pam-account-dal.ts+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts@@ -125,6 +125,8 @@ export type TPamAccountDetail = TPamAccounts &isStale: boolean;};+const effectiveGatewayIdSql = `coalesce("${TableName.PamAccount}"."gatewayId", "${TableName.PamAccountTemplate}"."gatewayId")`;+export type TPamAccountDALFactory = ReturnType<typeof pamAccountDALFactory>;export const pamAccountDALFactory = (db: TDbClient) => {@@ -505,7 +507,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {const docs = await (tx || db.replicaNode())(TableName.PamAccount).join(TableName.PamAccountTemplate, `${TableName.PamAccount}.templateId`, `${TableName.PamAccountTemplate}.id`).leftJoin(TableName.PamFolder, `${TableName.PamAccount}.folderId`, `${TableName.PamFolder}.id`)- .where(`${TableName.PamAccount}.gatewayId`, gatewayId)+ .whereRaw(`${effectiveGatewayIdSql} = ?`, [gatewayId]).select(`${TableName.PamAccount}.id`,`${TableName.PamAccount}.name`,@@ -516,19 +518,20 @@ export const pamAccountDALFactory = (db: TDbClient) => {return docs as { id: string; name: string; accountType: string; folderName: string | null }[];};- const countByGatewayId = async (gatewayId: string, tx?: Knex) => {- const result = await (tx || db.replicaNode())(TableName.PamAccount)- .where(`${TableName.PamAccount}.gatewayId`, gatewayId)- .count("id")- .first();-- return parseInt(String(result?.count || "0"), 10);- };+ const countByGatewayIds = async (gatewayIds: string[], tx?: Knex) =>+ (await (tx || db.replicaNode())(TableName.PamAccount)+ .join(TableName.PamAccountTemplate, `${TableName.PamAccount}.templateId`, `${TableName.PamAccountTemplate}.id`)+ .whereRaw(`${effectiveGatewayIdSql} = ANY(?::uuid[])`, [gatewayIds])+ .groupByRaw(effectiveGatewayIdSql)+ .select(db.raw(`${effectiveGatewayIdSql} as id`), db.raw("count(*)::int as count"))) as {+ id: string;+ count: number;+ }[];return {...orm,findByGatewayId,- countByGatewayId,+ countByGatewayIds,findAccessible,findByIdWithDetails,findByIdsWithDetails,diff --git a/frontend/src/hooks/api/gateways-v2/types.ts b/frontend/src/hooks/api/gateways-v2/types.tsindex 982a457558..635069e2fc 100644--- a/frontend/src/hooks/api/gateways-v2/types.ts+++ b/frontend/src/hooks/api/gateways-v2/types.ts@@ -153,6 +153,6 @@ export type TGatewayConnectedResources = {dynamicSecrets: TGatewayConnectedDynamicSecret[];kubernetesAuths: TGatewayConnectedKubernetesAuth[];pkiDiscoveryConfigs: TGatewayConnectedPkiDiscoveryConfig[];- pamAccounts: TGatewayConnectedPamAccount[];- pamAccountTemplates: TGatewayConnectedPamAccountTemplate[];+ pamAccounts?: TGatewayConnectedPamAccount[];+ pamAccountTemplates?: TGatewayConnectedPamAccountTemplate[];};diff --git a/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayConnectedResourcesSection/GatewayConnectedResourcesSection.tsx b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayConnectedResourcesSection/GatewayConnectedResourcesSection.tsxindex 06e53bbd1b..b7ed3b7e79 100644--- a/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayConnectedResourcesSection/GatewayConnectedResourcesSection.tsx+++ b/frontend/src/pages/organization/NetworkingPage/GatewayDetailsByIDPage/components/GatewayConnectedResourcesSection/GatewayConnectedResourcesSection.tsx@@ -37,8 +37,8 @@ const totalCountOf = (r: TGatewayConnectedResources | undefined) =>r.dynamicSecrets.length +r.kubernetesAuths.length +r.pkiDiscoveryConfigs.length +- r.pamAccounts.length +- r.pamAccountTemplates.length+ (r.pamAccounts?.length ?? 0) ++ (r.pamAccountTemplates?.length ?? 0): 0;const ResourceRow = ({@@ -171,15 +171,15 @@ export const GatewayConnectedResourcesSection = ({ gatewayId }: Props) => {</AccordionItem>)}- {(resources?.pamAccounts.length ?? 0) > 0 && (+ {(resources?.pamAccounts?.length ?? 0) > 0 && (<AccordionItem value="pam-accounts"><AccordionTrigger><span className="flex-1">PAM Accounts</span>- <Badge variant="neutral">{resources?.pamAccounts.length}</Badge>+ <Badge variant="neutral">{resources?.pamAccounts?.length}</Badge></AccordionTrigger><AccordionContent className="group-data-[variant=default]/accordion:p-3"><ItemGroup>- {resources?.pamAccounts.map((a) => (+ {resources?.pamAccounts?.map((a) => (<ResourceRowkey={a.id}name={a.name}@@ -196,15 +196,15 @@ export const GatewayConnectedResourcesSection = ({ gatewayId }: Props) => {</AccordionItem>)}- {(resources?.pamAccountTemplates.length ?? 0) > 0 && (+ {(resources?.pamAccountTemplates?.length ?? 0) > 0 && (<AccordionItem value="pam-account-templates"><AccordionTrigger><span className="flex-1">PAM Account Templates</span>- <Badge variant="neutral">{resources?.pamAccountTemplates.length}</Badge>+ <Badge variant="neutral">{resources?.pamAccountTemplates?.length}</Badge></AccordionTrigger><AccordionContent className="group-data-[variant=default]/accordion:p-3"><ItemGroup>- {resources?.pamAccountTemplates.map((t) => (+ {resources?.pamAccountTemplates?.map((t) => (<ResourceRowkey={t.id}name={t.name}