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(pam): support AD-account access on Windows resources
bernie-g08bdd49bbb27
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 28504045be..79d4043590 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -733,19 +733,43 @@ export const pamAccountServiceFactory = ({throw new NotFoundError({ message: `Resource with name '${inputResourceName}' not found` });}- // Find account by name within the resource- const account = await pamAccountDAL.findOne({+ // Find account by name within the resource (local-account path).+ let account = await pamAccountDAL.findOne({projectId,resourceId: resource.id,name: inputAccountName});+ // Fallback: when the resource is joined to a domain (e.g. Active Directory),+ // accept a domain account from the linked domain. Domain accounts have+ // domainId set instead of resourceId. The session is recorded against the+ // user-selected resource via selectedResourceId.+ let isDomainAccount = false;+ if (!account && resource.domainId) {+ account = await pamAccountDAL.findOne({+ projectId,+ domainId: resource.domainId,+ name: inputAccountName+ });+ if (account) isDomainAccount = true;+ }+if (!account) {throw new NotFoundError({message: `Account with name '${inputAccountName}' not found for resource '${inputResourceName}'`});}+ // Domain accounts are only valid against resource types that support a+ // domain join. Today that's Windows-only; reject any other combination+ // defensively so a misconfigured resource (with domainId) on a different+ // type doesn't open an unintended access path.+ if (isDomainAccount && resource.resourceType !== PamResource.Windows) {+ throw new BadRequestError({+ message: `Domain account access is only supported for Windows resources`+ });+ }+const trimmedReason = reason?.trim() || null;const fac = APPROVAL_POLICY_FACTORY_MAP[ApprovalPolicyType.PamAccess](ApprovalPolicyType.PamAccess);@@ -949,7 +973,9 @@ export const pamAccountServiceFactory = ({};}- // For gateway-based resources (Postgres, MySQL, SSH), create session first+ // For gateway-based resources (Postgres, MySQL, SSH), create session first.+ // Domain accounts: resourceId stays null (account isn't parented to a resource);+ // selectedResourceId records the user's pick at session-start time.const session = await pamSessionDAL.create({accountName: account.name,actorEmail,@@ -961,7 +987,8 @@ export const pamAccountServiceFactory = ({resourceType: resource.resourceType,status: PamSessionStatus.Starting,accountId: account.id,- resourceId: resource.id,+ resourceId: isDomainAccount ? null : resource.id,+ selectedResourceId: isDomainAccount ? resource.id : null,userId: actor.id,expiresAt: new Date(Date.now() + duration),reason: trimmedReason@@ -1198,8 +1225,15 @@ export const pamAccountServiceFactory = ({const account = await pamAccountDAL.findById(session.accountId);if (!account) throw new NotFoundError({ message: `Account with ID '${session.accountId}' not found` });- const resource = await pamResourceDAL.findById(account.resourceId!);- if (!resource) throw new NotFoundError({ message: `Resource with ID '${account.resourceId}' not found` });+ // Resolve the target resource. For local-account sessions this is account.resourceId;+ // for domain-account sessions (e.g. AD) the account isn't attached to a resource and+ // the user-selected target lives on session.selectedResourceId.+ const resourceId = session.selectedResourceId ?? account.resourceId;+ if (!resourceId) {+ throw new NotFoundError({ message: `Session '${sessionId}' has no associated resource` });+ }+ const resource = await pamResourceDAL.findById(resourceId);+ if (!resource) throw new NotFoundError({ message: `Resource with ID '${resourceId}' not found` });if (resource.gatewayId) {const authorized =@@ -1308,11 +1342,31 @@ export const pamAccountServiceFactory = ({hostname: string;[key: string]: unknown;};++ // AD-account sessions: pull the AD domain name from the linked domain+ // and ship it as the `domain` field. The gateway forwards it to the RDP+ // bridge so NTLM CredSSP authenticates against the domain rather than+ // the local SAM database.+ let domainName: string | undefined;+ if (account.domainId) {+ const domain = await pamDomainDAL.findById(account.domainId);+ if (!domain) {+ throw new NotFoundError({ message: `Domain with ID '${account.domainId}' not found` });+ }+ const domainConnectionDetails = (await decryptDomainConnectionDetails({+ projectId: session.projectId,+ encryptedConnectionDetails: domain.encryptedConnectionDetails,+ kmsService+ })) as { domain: string };+ domainName = domainConnectionDetails.domain;+ }+return {credentials: {...rest,host: hostname,- ...decryptedAccount.credentials+ ...decryptedAccount.credentials,+ ...(domainName ? { domain: domainName } : {})},policyRules,projectId: project.id,diff --git a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.tsindex 0e8fefe9d2..30f2e32367 100644--- a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts+++ b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts@@ -135,6 +135,8 @@ export const WindowsSessionCredentialsSchema = zuseWinrmHttps: z.boolean(),winrmRejectUnauthorized: z.boolean(),winrmCaCert: z.string().optional(),- winrmTlsServerName: z.string().optional()+ winrmTlsServerName: z.string().optional(),+ // Set on AD-account sessions; gateway/bridge use this for NTLM domain-qualified auth.+ domain: z.string().optional()}).and(WindowsAccountCredentialsSchema);