Skip to content

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

Merge remote-tracking branch 'origin /main' into feat/PAM-184

Carlos Monastyrskiebc599f6cf65
diff --cc backend/src/ee/services/pam-account/pam-account-service.ts
index 0aaedc5e61,16da4990e4..8e6153b1b3
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@@ -607,28 -680,15 +680,25 @@@ export const pamAccountServiceFactory
})
);
- const decryptedAccount = await decryptAccount(accountWithResource, accountWithResource.projectId, kmsService);
+ const decryptedAccount = await decryptAccount(accountWithParent, accountWithParent.projectId, kmsService);
+ // Resolve whether the policy enforces a reason at access time so the UI can
+ // gate the access flow without needing pam-account-policy:read permission.
+ let requireReason = false;
- if (accountWithResource.policyId) {
- const policy = await pamAccountPolicyDAL.findById(accountWithResource.policyId);
++ if (accountWithParent.policyId) {
++ const policy = await pamAccountPolicyDAL.findById(accountWithParent.policyId);
+ const policyRules = (policy?.rules ?? {}) as TPolicyRules;
+ requireReason = Boolean(policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason]);
+ }
+
return {
...decryptedAccount,
+ ...formatAccountParent({
+ resource: accountWithParent.resource,
+ domain: accountWithParent.domain
+ }),
- metadata: accountMetadata
+ metadata: accountMetadata,
- requireReason,
- resourceType: accountWithResource.resource.resourceType,
- resource: {
- id: accountWithResource.resource.id,
- name: accountWithResource.resource.name,
- resourceType: accountWithResource.resource.resourceType,
- rotationCredentialsConfigured: !!accountWithResource.resource.encryptedRotationAccountCredentials
- }
++ requireReason
};
};
diff --cc backend/src/ee/services/pam-resource/pam-resource-schemas.ts
index f41d0b7599,46eeca5366..0af9b9ef2c
--- a/backend/src/ee/services/pam-resource/pam-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-schemas.ts
@@@ -79,12 -83,16 +83,17 @@@ export const BasePamAccountSchemaWithRe
id: true,
name: true,
resourceType: true
- }).extend({
- rotationCredentialsConfigured: z.boolean()
- }),
+ })
+ .extend({
+ rotationCredentialsConfigured: z.boolean()
+ })
+ .nullable()
+ .optional(),
+ domain: PamDomainsSchema.pick({ id: true, name: true, domainType: true }).nullable().optional(),
policyName: z.string().nullable().optional(),
lastRotationMessage: z.string().nullable().optional(),
-- rotationStatus: z.string().nullable().optional()
++ rotationStatus: z.string().nullable().optional(),
++ requireReason: z.boolean().default(false)
});
export const BaseCreatePamAccountSchema = z.object({
diff --cc backend/src/ee/services/pam-web-access/pam-web-access-service.ts
index 27560a56f6,6baa684c8b..b148e7c57c
--- 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
@@@ -179,8 -172,10 +179,12 @@@ export const pamWebAccessServiceFactor
throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });
}
+ const trimmedReason = reason?.trim() || null;
+
+ if (!account.resourceId) {
+ throw new BadRequestError({ message: "Web access is only available for resource-backed accounts" });
+ }
+
const resource = await pamResourceDAL.findById(account.resourceId);
if (!resource) {
diff --cc frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
index 6219ebe61e,73dad528d0..2dcd87c9f5
--- a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
+++ b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
@@@ -22,13 -19,13 +22,13 @@@ const TerminalContent = (
const [sessionEnded, setSessionEnded] = useState(false);
const { containerRef, isConnected, disconnect, reconnect } = useWebAccessSession({
- accountId,
+ accountId: account.id,
projectId,
orgId,
- resourceName: account.resource.name,
- accountName: account.name,
- resourceType: account.resource.resourceType,
+ resourceName: account?.resource?.name ?? "",
+ accountName: account?.name ?? "",
+ resourceType: account?.resource?.resourceType ?? "",
+ reason,
onSessionEnd: () => setSessionEnded(true)
});
@@@ -116,31 -129,11 +116,31 @@@ const PageContent = () =>
);
}
- if (account?.resource?.resourceType === PamResourceType.Postgres) {
- return <PamDataExplorerPage />;
+ if (!account) {
+ return (
+ <div className="flex h-screen w-screen items-center justify-center bg-[#0d1117]">
+ <p className="text-mineshaft-300">Could not find PAM Account with ID {accountId}</p>
+ </div>
+ );
}
- return <TerminalContent accountId={accountId!} projectId={projectId!} orgId={orgId!} />;
+ return (
+ <ReasonGate account={account}>
+ {(reason) => {
- if (account.resource.resourceType === PamResourceType.Postgres) {
++ if (account.resource?.resourceType === PamResourceType.Postgres) {
+ return <PamDataExplorerPage reason={reason} />;
+ }
+ return (
+ <TerminalContent
+ account={account}
+ projectId={projectId!}
+ orgId={orgId!}
+ reason={reason}
+ />
+ );
+ }}
+ </ReasonGate>
+ );
};
export const PamAccountAccessPage = () => {
diff --cc frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
index d46b054353,f19aa1d17c..416a132da6
--- a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
@@@ -40,9 -39,9 +39,10 @@@ import
} from "@app/hooks/api/pam";
import { useManualRotateAccount } from "@app/hooks/api/pam/mutations";
import { pamKeys } from "@app/hooks/api/pam/queries";
+ import { PAM_DOMAIN_TYPE_MAP, PamDomainType } from "@app/hooks/api/pamDomain";
import { PamAccessAccountModal } from "../PamAccountsPage/components/PamAccessAccountModal";
+import { PamAwsIamAccessReasonModal } from "../PamAccountsPage/components/PamAwsIamAccessReasonModal";
import { PamDeleteAccountModal } from "../PamAccountsPage/components/PamDeleteAccountModal";
import { PamRequestAccountAccessModal } from "../PamAccountsPage/components/PamRequestAccountAccessModal";
import { PamUpdateAccountModal } from "../PamAccountsPage/components/PamUpdateAccountModal";
@@@ -96,7 -79,7 +80,8 @@@ const PageContent = () =>
"accessAccount",
"requestAccount",
"deleteAccount",
- "awsIamReason"
++ "awsIamReason",
+ "selectResource"
] as const);
const queryClient = useQueryClient();
@@@ -158,8 -166,8 +168,8 @@@
return;
}
- if (account.resource.resourceType === PamResourceType.AwsIam) {
+ if (account.resource?.resourceType === PamResourceType.AwsIam) {
- accessAwsIam(account);
+ handlePopUpOpen("awsIamReason", { account });
} else {
handlePopUpOpen("accessAccount", { account });
}
diff --cc frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
index 436c3d42b2,d9f87b6ba0..84caecc723
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
@@@ -68,12 -68,11 +68,12 @@@ export const PamAccessAccountModal = (
}, [duration]);
const command = useMemo(() => {
-- if (!account) return "";
-
++ if (!account?.resource) return "";
++ const { resource } = account;
+ const base = (verb: string) =>
- `infisical pam ${verb} access --resource ${account.resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
++ `infisical pam ${verb} access --resource ${resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
- if (!account.resource) return "";
-
-- switch (account.resource.resourceType) {
++ switch (resource.resourceType) {
case PamResourceType.Postgres:
case PamResourceType.MySQL:
case PamResourceType.MsSQL:
diff --cc frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx
index acb5b8f25e,bda8e61733..8b04602e1d
--- a/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx
@@@ -8,8 -8,8 +8,8 @@@ export const useAccessAwsIamAccount = (
const accessPamAccount = useAccessPamAccount();
const [loadingAccountId, setLoadingAccountId] = useState<string | null>(null);
- const accessAwsIam = async (account: TPamAccount) => {
+ const accessAwsIam = async (account: TPamAccount, reason?: string) => {
- if (account.resource.resourceType !== PamResourceType.AwsIam) {
+ if (account.resource?.resourceType !== PamResourceType.AwsIam) {
return false;
}
@@@ -18,11 -18,10 +18,11 @@@
try {
const response = await accessPamAccount.mutateAsync({
accountId: account.id,
- resourceName: account.resource.name,
+ resourceName: account.resource?.name ?? "",
accountName: account.name,
projectId: account.projectId,
- duration: `${(account.credentials as TAwsIamCredentials).defaultSessionDuration}s`
+ duration: `${(account.credentials as TAwsIamCredentials).defaultSessionDuration}s`,
+ reason
});
if (response.consoleUrl) {
diff --cc frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
index 9797a378a3,2b1c404794..92e95c331c
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
@@@ -260,8 -271,8 +273,8 @@@ export const PamResourceAccountsSectio
return;
}
- if (account.resource.resourceType === PamResourceType.AwsIam) {
+ if (account.resource?.resourceType === PamResourceType.AwsIam) {
- accessAwsIam(account);
+ handlePopUpOpen("awsIamReason", { account });
} else {
handlePopUpOpen("accessAccount", { account });
}