Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(pam): use fqdn:slug wire format for AD-account access

bernie-ga49c34f1e816
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index c65e882cd7..da7387630f 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -742,30 +742,48 @@ export const pamAccountServiceFactory = ({
throw new NotFoundError({ message: `Resource with name '${inputResourceName}' not found` });
}
- const localAccount = await pamAccountDAL.findOne({
- projectId,
- resourceId: resource.id,
- name: inputAccountName
- });
- const domainAccount = resource.domainId
- ? await pamAccountDAL.findOne({
- projectId,
- domainId: resource.domainId,
- name: inputAccountName
- })
- : null;
-
- // Reject collisions explicitly: 'Administrator' commonly exists in both the
- // local SAM and AD, and (resourceName, accountName) alone can't distinguish.
- if (localAccount && domainAccount) {
- throw new BadRequestError({
- message: `Both a local and a domain account named '${inputAccountName}' exist on resource '${inputResourceName}'. Rename one to disambiguate.`
+ // Wire format for AD-domain accounts is `<fqdn>:<slug>` (e.g.
+ // 'corp.example.com:administrator'). PAM slugs can't contain ':' so the
+ // separator is unambiguous. Plain `<slug>` routes to the local bucket.
+ const colonIdx = inputAccountName.indexOf(":");
+ const isDomainAccount = colonIdx !== -1;
+ const accountSlug = isDomainAccount ? inputAccountName.slice(colonIdx + 1) : inputAccountName;
+ const fqdnHint = isDomainAccount ? inputAccountName.slice(0, colonIdx) : null;
+
+ let account = null as Awaited<ReturnType<typeof pamAccountDAL.findOne>> | null;
+ if (isDomainAccount) {
+ if (!resource.domainId) {
+ throw new BadRequestError({
+ message: `Resource '${inputResourceName}' is not joined to a domain`
+ });
+ }
+ const domain = await pamDomainDAL.findById(resource.domainId);
+ if (!domain) {
+ throw new NotFoundError({ message: `Domain with ID '${resource.domainId}' not found` });
+ }
+ const domainConn = (await decryptDomainConnectionDetails({
+ projectId,
+ encryptedConnectionDetails: domain.encryptedConnectionDetails,
+ kmsService
+ })) as { domain: string };
+ if (domainConn.domain.toLowerCase() !== fqdnHint?.toLowerCase()) {
+ throw new BadRequestError({
+ message: `Resource '${inputResourceName}' is not joined to '${fqdnHint}'`
+ });
+ }
+ account = await pamAccountDAL.findOne({
+ projectId,
+ domainId: resource.domainId,
+ name: accountSlug
+ });
+ } else {
+ account = await pamAccountDAL.findOne({
+ projectId,
+ resourceId: resource.id,
+ name: accountSlug
});
}
- const account = localAccount ?? domainAccount;
- const isDomainAccount = !localAccount && !!domainAccount;
-
if (!account) {
throw new NotFoundError({
message: `Account with name '${inputAccountName}' not found for resource '${inputResourceName}'`
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
index 8b976be801..61629e6fe8 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
@@ -10,7 +10,11 @@ import { FormLabel, IconButton, Input, Modal, ModalContent } from "@app/componen
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization } from "@app/context";
import { PamResourceType, TPamAccount } from "@app/hooks/api/pam";
-import { TPamDomainRelatedResource } from "@app/hooks/api/pamDomain";
+import {
+ PamDomainType,
+ TPamDomainRelatedResource,
+ useGetPamDomainById
+} from "@app/hooks/api/pamDomain";
import { PamAwsIamAccessSection } from "./PamAwsIamAccessSection";
@@ -82,10 +86,25 @@ export const PamAccessAccountModal = ({
const targetResource = selectedResource ?? account?.resource;
+ // Domain accounts need the AD FQDN to disambiguate from a like-named local
+ // account on the same resource. The list-accounts payload only carries the
+ // domain slug; fetch the full domain row to read connectionDetails.domain.
+ const { data: domain } = useGetPamDomainById(
+ account?.domain?.domainType ?? PamDomainType.ActiveDirectory,
+ account?.domainId || undefined,
+ { enabled: !!account?.domainId }
+ );
+
const command = useMemo(() => {
if (!account || !targetResource) return "";
+ // For AD-domain accounts the wire identity is `<fqdn>:<slug>` so the
+ // backend routes to the domain bucket; local accounts pass just `<slug>`.
+ const accountArg =
+ account.domainId && domain?.connectionDetails.domain
+ ? `${domain.connectionDetails.domain}:${account.name}`
+ : account.name;
const base = (verb: string) =>
- `infisical pam ${verb} access --resource ${targetResource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
+ `infisical pam ${verb} access --resource ${targetResource.name} --account ${accountArg} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
switch (targetResource.resourceType) {
case PamResourceType.Postgres:
@@ -104,7 +123,7 @@ export const PamAccessAccountModal = ({
default:
return "";
}
- }, [account, targetResource, projectId, cliDuration, siteURL]);
+ }, [account, targetResource, domain, projectId, cliDuration, siteURL]);
if (!account) return null;