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
fix(pam): validate account gateway bindings consistently
Andreyed34d556f4df
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts b/backend/src/ee/services/gateway-pool/gateway-pool-service.tsindex 8ea562184c..47d06c2a45 100644--- a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts+++ b/backend/src/ee/services/gateway-pool/gateway-pool-service.ts@@ -447,6 +447,29 @@ export const gatewayPoolServiceFactory = ({}};+ const assertGatewayBindingInOrg = async ({+ gatewayId,+ gatewayPoolId,+ orgId+ }: {+ gatewayId?: string | null;+ gatewayPoolId?: string | null;+ orgId: string;+ }) => {+ if (gatewayId) {+ const gateway = await gatewayV2DAL.findById(gatewayId);+ if (!gateway || gateway.orgId !== orgId) {+ throw new NotFoundError({ message: `Gateway with ID '${gatewayId}' not found` });+ }+ }+ if (gatewayPoolId) {+ const pool = await gatewayPoolDAL.findById(gatewayPoolId);+ if (!pool || pool.orgId !== orgId) {+ throw new NotFoundError({ message: `Gateway pool with ID '${gatewayPoolId}' not found` });+ }+ }+ };+// Return gatewayId directly, or pick a random healthy pool member. Null when neither is set.const resolveEffectiveGatewayId = async ({gatewayId,@@ -515,6 +538,7 @@ export const gatewayPoolServiceFactory = ({getConnectedResources,getConnectedResourcesCount,resolveAttachableGatewayFromPool,+ assertGatewayBindingInOrg,resolveEffectiveGatewayId};};diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.tsindex 31b745a671..eb42335b4f 100644--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts@@ -81,7 +81,10 @@ const buildService = (updateById},gatewayV2Service: { getPlatformConnectionDetailsByGatewayId: vi.fn() },- gatewayPoolService: { resolveEffectiveGatewayId: vi.fn(async () => "gw-1") },+ gatewayPoolService: {+ resolveEffectiveGatewayId: vi.fn(async () => "gw-1"),+ assertGatewayBindingInOrg: vi.fn(async () => undefined)+ },kmsService: { createCipherPairWithDataKey: vi.fn(async () => identityCipher) },permissionService: { getProjectPermission: vi.fn(), getResourcePermission: vi.fn() },projectDAL: { findById: vi.fn(async () => ({ id: "proj-1", orgId: "org-1" })) },diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.tsindex a8b3cac4ac..ff82378f58 100644--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts@@ -47,7 +47,7 @@ import {type TPamAccountHeartbeatServiceFactoryDep = {pamAccountDAL: TPamAccountDALFactory;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId" | "assertGatewayBindingInOrg">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;permissionService: TPermissionServiceFactory;projectDAL: Pick<TProjectDALFactory, "findById">;@@ -160,6 +160,12 @@ export const pamAccountHeartbeatServiceFactory = ({}}+ await gatewayPoolService.assertGatewayBindingInOrg({+ gatewayId: account.gatewayId ?? account.templateGatewayId,+ gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolId,+ orgId+ });+// The shared connection test only reaches these over TCP; the rotation handlers hold the real probe.if (isWindowsRotatableType(accountType)) {const handler = rotationHandlers[accountType as TRotatableType];diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.tsindex e0e1b70354..25e12e3b4d 100644--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts@@ -85,7 +85,8 @@ const buildService = (kmsService: { createCipherPairWithDataKey: vi.fn(async () => identityCipher) },keyStore: { acquireLock: vi.fn(async () => ({ release: vi.fn(async () => undefined) })) },gatewayV2Service: { getPlatformConnectionDetailsByGatewayId: vi.fn() },- gatewayPoolService: { resolveEffectiveGatewayId: vi.fn() },+ gatewayPoolService: { resolveEffectiveGatewayId: vi.fn(), assertGatewayBindingInOrg: vi.fn(async () => undefined) },+ projectDAL: { findById: vi.fn(async () => ({ id: "proj-1", orgId: "org-1" })) },pamAccountDependencyDAL: { findByAccountId: vi.fn(async () => []), updateById: vi.fn(async () => undefined) },rotationHandlers};diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.tsindex 33b2b2b69a..a8918b45f6 100644--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts@@ -92,7 +92,7 @@ type TPamAccountRotationServiceFactoryDep = {kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;keyStore: Pick<TKeyStoreFactory, "acquireLock">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId" | "assertGatewayBindingInOrg">;pamAccountDependencyDAL: Pick<TPamAccountDependencyDALFactory, "findByAccountId" | "updateById">;rotationHandlers?: typeof PAM_ROTATION_FACTORY_MAP;};@@ -598,6 +598,15 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic} = await resolveRotator(account, targetCredentials, connectionDetails, { gatewayId, gatewayPoolId });handler.validateRotatorCredential?.({ accountType, password: auth.password });if (isDelegated) assertRotatorSameResource(accountType, rotatorConnectionDetails, connectionDetails);++ const project = await projectDAL.findById(projectId);+ if (!project) throw new NotFoundError({ message: "Project not found" });+ await gatewayPoolService.assertGatewayBindingInOrg({+ gatewayId: rotatorGatewayId,+ gatewayPoolId: rotatorGatewayPoolId,+ orgId: project.orgId+ });+// A delegated local account can't be logged in as to verify, so validate via the admin rotator instead.const verifyVia = isDelegated && accountType === PamAccountType.Windows ? auth : undefined;diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex dffb35bea7..bff755c383 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -134,7 +134,7 @@ type TPamAccountServiceFactoryDep = {>;gatewayPoolService: Pick<TGatewayPoolServiceFactory,- "resolveAttachableGatewayFromPool" | "resolveEffectiveGatewayId"+ "resolveAttachableGatewayFromPool" | "resolveEffectiveGatewayId" | "assertGatewayBindingInOrg">;appConnectionDAL: Pick<TAppConnectionDALFactory, "findOne" | "findById">;pamAccessRequestService: Pick<@@ -638,6 +638,12 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>return true;}+ await gatewayPoolService.assertGatewayBindingInOrg({+ gatewayId: gateway.gatewayId ?? gateway.templateGatewayId,+ gatewayPoolId: gateway.gatewayPoolId ?? gateway.templateGatewayPoolId,+ orgId+ });+const effectiveGatewayId = gateway.gatewayId ?? gateway.templateGatewayId;const gatewayId = await gatewayPoolService.resolveEffectiveGatewayId({gatewayId: effectiveGatewayId,@@ -749,7 +755,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>await validateGatewayAttachment(deps,effectiveGatewayId,- effectiveGatewayId ? null : (gatewayPoolId ?? template.gatewayPoolId),+ gatewayPoolId ?? (effectiveGatewayId ? null : template.gatewayPoolId),ctx,{ inheritedFrom: gatewayId ? undefined : `Account template '${template.name}'` });@@ -940,7 +946,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>await validateGatewayAttachment(deps,effectiveGatewayId,- effectiveGatewayId ? null : (nextGatewayPoolId ?? nextTemplateGatewayPoolId),+ gatewayPoolId ?? (effectiveGatewayId ? null : (nextGatewayPoolId ?? nextTemplateGatewayPoolId)),ctx,{previousGatewayId: existing.gatewayId ?? existing.templateGatewayId,diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.tsindex a94b708221..3e3c9cf5fb 100644--- a/backend/src/ee/services/pam-session/pam-session-service.ts+++ b/backend/src/ee/services/pam-session/pam-session-service.ts@@ -104,7 +104,7 @@ type TPamSessionServiceFactoryDep = {permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getResourcePermission">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPAMConnectionDetails">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId" | "assertGatewayBindingInOrg">;userDAL: Pick<TUserDALFactory, "findById">;pamSessionExpirationService: Pick<TPamSessionExpirationServiceFactory, "scheduleSessionExpiration">;mfaSessionService: Pick<@@ -707,6 +707,11 @@ export const pamSessionServiceFactory = ({enforceRecordingConfig(account);+ await gatewayPoolService.assertGatewayBindingInOrg({+ gatewayId: account.gatewayId ?? account.templateGatewayId,+ gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolId,+ orgId: actor.actorOrgId+ });const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({gatewayId: account.gatewayId ?? account.templateGatewayId,gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolIddiff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.tsindex aadcc49d27..1763cac388 100644--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts@@ -82,7 +82,10 @@ type TPamWebAccessServiceFactoryDep = {membershipDAL: Pick<TMembershipDALFactory, "lockOrgMembershipForUser" | "findResourceMembershipsForActor">;membershipRoleDAL: Pick<TMembershipRoleDALFactory, "find">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPAMConnectionDetails">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId" | "runWithPoolFailover">;+ gatewayPoolService: Pick<+ TGatewayPoolServiceFactory,+ "resolveEffectiveGatewayId" | "runWithPoolFailover" | "assertGatewayBindingInOrg"+ >;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;userDAL: Pick<TUserDALFactory, "findById">;mfaSessionService: Pick<@@ -534,6 +537,11 @@ export const pamWebAccessServiceFactory = ({sessionDurationCapMs = Math.min(sessionDurationCapMs, launchAccessRemainingMs);}+ await gatewayPoolService.assertGatewayBindingInOrg({+ gatewayId: account.gatewayId ?? account.templateGatewayId,+ gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolId,+ orgId+ });const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({gatewayId: account.gatewayId ?? account.templateGatewayId,gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolId