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 claude comments
Carlos Monastyrskif6425d518773
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.tsindex 88f93b4fd5..162c4b73ab 100644--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts@@ -73,7 +73,8 @@ const SanitizedAccountSchema = z.and(z.object({credentialsConfigured: z.boolean(),- dependencyCount: z.number().default(0)+ dependencyCount: z.number().default(0),+ requireReason: z.boolean().default(false)}));diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 40155001e7..0aaedc5e61 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -609,9 +609,19 @@ export const pamAccountServiceFactory = ({const decryptedAccount = await decryptAccount(accountWithResource, accountWithResource.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);+ const policyRules = (policy?.rules ?? {}) as TPolicyRules;+ requireReason = Boolean(policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason]);+ }+return {...decryptedAccount,metadata: accountMetadata,+ requireReason,resourceType: accountWithResource.resource.resourceType,resource: {id: accountWithResource.resource.id,@@ -658,17 +668,6 @@ export const pamAccountServiceFactory = ({const trimmedReason = reason?.trim() || null;- if (account.policyId) {- const policy = await pamAccountPolicyDAL.findById(account.policyId);- const policyRules = (policy?.rules ?? {}) as TPolicyRules;- if (policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason] && !trimmedReason) {- throw new BadRequestError({- message: "A reason is required to access this account",- name: "PAM_REASON_REQUIRED"- });- }- }-const fac = APPROVAL_POLICY_FACTORY_MAP[ApprovalPolicyType.PamAccess](ApprovalPolicyType.PamAccess);const inputs = {@@ -717,6 +716,19 @@ export const pamAccountServiceFactory = ({);}+ // Reason check is intentionally placed after the approval/permission gates so+ // its distinct error code does not leak policy configuration to unauthorized actors.+ if (account.policyId) {+ const policy = await pamAccountPolicyDAL.findById(account.policyId);+ const policyRules = (policy?.rules ?? {}) as TPolicyRules;+ if (policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason] && !trimmedReason) {+ throw new BadRequestError({+ message: "A reason is required to access this account",+ name: "PAM_REASON_REQUIRED"+ });+ }+ }+const project = await projectDAL.findById(account.projectId);if (!project) throw new NotFoundError({ message: `Project with ID '${account.projectId}' not found` });diff --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 7849cc2996..27560a56f6 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@@ -181,17 +181,6 @@ export const pamWebAccessServiceFactory = ({const trimmedReason = reason?.trim() || null;- if (account.policyId) {- const policy = await pamAccountPolicyDAL.findById(account.policyId);- const policyRules = (policy?.rules ?? {}) as TPolicyRules;- if (policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason] && !trimmedReason) {- throw new BadRequestError({- message: "A reason is required to access this account",- name: "PAM_REASON_REQUIRED"- });- }- }-const resource = await pamResourceDAL.findById(account.resourceId);if (!resource) {@@ -257,6 +246,19 @@ export const pamWebAccessServiceFactory = ({);}+ // Reason check is intentionally placed after the approval/permission gates so+ // its distinct error code does not leak policy configuration to unauthorized actors.+ if (account.policyId) {+ const policy = await pamAccountPolicyDAL.findById(account.policyId);+ const policyRules = (policy?.rules ?? {}) as TPolicyRules;+ if (policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason] && !trimmedReason) {+ throw new BadRequestError({+ message: "A reason is required to access this account",+ name: "PAM_REASON_REQUIRED"+ });+ }+ }+// MFA checkif (account.requireMfa && !mfaSessionId) {const project = await projectDAL.findById(account.projectId);diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsxindex d9fca70c1c..cac382f0e5 100644--- a/frontend/src/hooks/api/pam/queries.tsx+++ b/frontend/src/hooks/api/pam/queries.tsx@@ -60,7 +60,6 @@ export const pamKeys = {projectId,{ search }],- getAccountPolicy: (policyId: string) => [...pamKeys.accountPolicy(), "get", policyId],getSession: (sessionId: string) => [...pamKeys.session(), "get", sessionId],getSessionLogs: (sessionId: string) => [...pamKeys.session(), "logs", sessionId],listSessions: (projectId: string) => [...pamKeys.session(), "list", projectId],@@ -487,29 +486,3 @@ export const useListPamAccountPolicies = (...options});};--export const useGetPamAccountPolicy = (- policyId: string | null | undefined,- options?: Omit<- UseQueryOptions<- TPamAccountPolicy,- unknown,- TPamAccountPolicy,- ReturnType<typeof pamKeys.getAccountPolicy>- >,- "queryKey" | "queryFn" | "enabled"- >-) => {- return useQuery({- queryKey: pamKeys.getAccountPolicy(policyId ?? ""),- queryFn: async () => {- const { data } = await apiRequest.get<{ policy: TPamAccountPolicy }>(- `/api/v1/pam/account-policies/${policyId}`- );-- return data.policy;- },- enabled: Boolean(policyId),- ...options- });-};diff --git a/frontend/src/hooks/api/pam/types/base-account.ts b/frontend/src/hooks/api/pam/types/base-account.tsindex 03bb08c550..884b092899 100644--- a/frontend/src/hooks/api/pam/types/base-account.ts+++ b/frontend/src/hooks/api/pam/types/base-account.ts@@ -15,6 +15,7 @@ export interface TBasePamAccount {description?: string | null;credentialsConfigured: boolean;requireMfa?: boolean | null;+ requireReason?: boolean;lastRotatedAt?: string | null;lastRotationMessage?: string | null;rotationStatus?: string | null;diff --git a/frontend/src/pages/pam/PamAccountAccessPage/ReasonGate.tsx b/frontend/src/pages/pam/PamAccountAccessPage/ReasonGate.tsxindex 5dbf39eeff..90f2f425d7 100644--- a/frontend/src/pages/pam/PamAccountAccessPage/ReasonGate.tsx+++ b/frontend/src/pages/pam/PamAccountAccessPage/ReasonGate.tsx@@ -2,7 +2,7 @@ import { ReactNode, useState } from "react";import { AlertTriangleIcon } from "lucide-react";import { Button } from "@app/components/v3/generic/Button";-import { PamAccountPolicyRuleType, TPamAccount, useGetPamAccountPolicy } from "@app/hooks/api/pam";+import { TPamAccount } from "@app/hooks/api/pam";type Props = {account: TPamAccount;@@ -14,18 +14,11 @@ export const ReasonGate = ({ account, children }: Props) => {const [draft, setDraft] = useState("");const [touched, setTouched] = useState(false);- const { data: policy, isPending: isPolicyQueryPending } = useGetPamAccountPolicy(- account.policyId- );- const isPolicyLoading = Boolean(account.policyId) && isPolicyQueryPending;-if (submittedReason !== null) {return <>{children(submittedReason)}</>;}- const isReasonRequired = Boolean(- policy?.isActive && policy.rules?.[PamAccountPolicyRuleType.RequireReason]- );+ const isReasonRequired = Boolean(account.requireReason);const trimmed = draft.trim();const canContinue = !isReasonRequired || trimmed.length > 0;@@ -41,51 +34,40 @@ export const ReasonGate = ({ account, children }: Props) => {return (<div className="flex h-screen w-screen flex-col items-center justify-center gap-3 bg-bunker-800">- {isPolicyLoading ? (- <p className="text-xs text-mineshaft-400">Loading account policy...</p>- ) : (- <>- {isReasonRequired ? <AlertTriangleIcon className="size-8 text-mineshaft-400" /> : null}- <h2 className="text-sm font-medium text-mineshaft-100">- {isReasonRequired ? "Reason Required" : "Before You Continue"}- </h2>- <p className="max-w-sm text-center text-xs text-mineshaft-400">- {isReasonRequired- ? "This account's policy requires a reason for access. The reason will be stored with the session for audit purposes."- : "Optionally provide a reason for this session. The reason will be stored with the session for audit purposes."}- </p>- <div className="flex w-full max-w-sm flex-col gap-2">- <textarea- className="w-full rounded border border-mineshaft-600 bg-bunker-700 px-3 py-2 text-xs text-mineshaft-200 placeholder:text-mineshaft-500 focus:border-mineshaft-400 focus:outline-none"- placeholder={- isReasonRequired- ? "e.g. Investigating incident INC-1234"- : "Optional — e.g. Running migration for release 2.4"- }- rows={3}- maxLength={1000}- value={draft}- onChange={(e) => setDraft(e.target.value)}- onKeyDown={(e) => {- if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {- handleSubmit();- }- }}- />- {showError && <p className="text-xs text-red-400">A reason is required to continue.</p>}- <div className="flex justify-center gap-2">- <Button- variant="outline"- size="xs"- isDisabled={isReasonRequired && trimmed.length === 0}- onClick={handleSubmit}- >- {!isReasonRequired && trimmed.length === 0 ? "Skip & Continue" : "Continue"}- </Button>- </div>- </div>- </>- )}+ {isReasonRequired ? <AlertTriangleIcon className="size-8 text-mineshaft-400" /> : null}+ <h2 className="text-sm font-medium text-mineshaft-100">+ {isReasonRequired ? "Reason Required" : "Before You Continue"}+ </h2>+ <p className="max-w-sm text-center text-xs text-mineshaft-400">+ {isReasonRequired+ ? "This account's policy requires a reason for access. The reason will be stored with the session for audit purposes."+ : "Optionally provide a reason for this session. The reason will be stored with the session for audit purposes."}+ </p>+ <div className="flex w-full max-w-sm flex-col gap-2">+ <textarea+ className="w-full rounded border border-mineshaft-600 bg-bunker-700 px-3 py-2 text-xs text-mineshaft-200 placeholder:text-mineshaft-500 focus:border-mineshaft-400 focus:outline-none"+ placeholder={+ isReasonRequired+ ? "e.g. Investigating incident INC-1234"+ : "Optional, e.g. Running migration for release 2.4"+ }+ rows={3}+ maxLength={1000}+ value={draft}+ onChange={(e) => setDraft(e.target.value)}+ onKeyDown={(e) => {+ if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {+ handleSubmit();+ }+ }}+ />+ {showError && <p className="text-xs text-red-400">A reason is required to continue.</p>}+ <div className="flex justify-center gap-2">+ <Button variant="outline" size="xs" onClick={handleSubmit}>+ {!isReasonRequired && trimmed.length === 0 ? "Skip & Continue" : "Continue"}+ </Button>+ </div>+ </div></div>);};diff --git a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsxindex 9bf4db3950..d46b054353 100644--- a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx+++ b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx@@ -42,6 +42,7 @@ import { useManualRotateAccount } from "@app/hooks/api/pam/mutations";import { pamKeys } from "@app/hooks/api/pam/queries";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";@@ -91,10 +92,11 @@ const PageContent = () => {const [isEditModalOpen, setIsEditModalOpen] = useState(false);- const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([+ const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp(["accessAccount","requestAccount",- "deleteAccount"+ "deleteAccount",+ "awsIamReason"] as const);const queryClient = useQueryClient();@@ -157,7 +159,7 @@ const PageContent = () => {}if (account.resource.resourceType === PamResourceType.AwsIam) {- accessAwsIam(account);+ handlePopUpOpen("awsIamReason", { account });} else {handlePopUpOpen("accessAccount", { account });}@@ -329,6 +331,19 @@ const PageContent = () => {projectId={projectId!}/>+ <PamAwsIamAccessReasonModal+ isOpen={popUp.awsIamReason.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("awsIamReason", isOpen)}+ account={popUp.awsIamReason.data?.account}+ isPending={isAwsAccessPending}+ onSubmit={async (reason) => {+ const targetAccount = popUp.awsIamReason.data?.account;+ if (!targetAccount) return;+ handlePopUpClose("awsIamReason");+ await accessAwsIam(targetAccount, reason);+ }}+ />+<PamRequestAccountAccessModalisOpen={popUp.requestAccount.isOpen}onOpenChange={(isOpen) => handlePopUpToggle("requestAccount", isOpen)}diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessReasonModal.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessReasonModal.tsxnew file mode 100644index 0000000000..2202e242b3--- /dev/null+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessReasonModal.tsx@@ -0,0 +1,87 @@+import { useEffect, useState } from "react";++import { Button, Modal, ModalContent, TextArea } from "@app/components/v2";+import { TPamAccount } from "@app/hooks/api/pam";++type Props = {+ account?: TPamAccount;+ isOpen: boolean;+ isPending?: boolean;+ onOpenChange: (isOpen: boolean) => void;+ onSubmit: (reason: string) => void;+};++export const PamAwsIamAccessReasonModal = ({+ account,+ isOpen,+ isPending,+ onOpenChange,+ onSubmit+}: Props) => {+ const [reason, setReason] = useState("");+ const [touched, setTouched] = useState(false);++ useEffect(() => {+ if (isOpen) {+ setReason("");+ setTouched(false);+ }+ }, [isOpen, account?.id]);++ if (!account) return null;++ const isReasonRequired = Boolean(account.requireReason);+ const trimmed = reason.trim();+ const canSubmit = !isReasonRequired || trimmed.length > 0;+ const showError = touched && isReasonRequired && trimmed.length === 0;++ const handleSubmit = () => {+ if (!canSubmit) {+ setTouched(true);+ return;+ }+ onSubmit(trimmed);+ };++ return (+ <Modal isOpen={isOpen} onOpenChange={onOpenChange}>+ <ModalContent+ className="max-w-md"+ title={isReasonRequired ? "Reason Required" : "Open AWS Console"}+ subTitle={+ isReasonRequired+ ? "This account's policy requires a reason for access."+ : "Optionally provide a reason for this session."+ }+ >+ <div className="mt-1 flex flex-col gap-2">+ <TextArea+ value={reason}+ onChange={(e) => setReason(e.target.value)}+ placeholder={+ isReasonRequired+ ? "e.g. Investigating incident INC-1234"+ : "Optional, e.g. Reviewing IAM permissions"+ }+ rows={3}+ maxLength={1000}+ isError={showError}+ />+ {showError && <p className="text-xs text-red">A reason is required to continue.</p>}+ <div className="mt-2 flex justify-end gap-2">+ <Button+ variant="outline_bg"+ colorSchema="secondary"+ onClick={() => onOpenChange(false)}+ >+ Cancel+ </Button>+ <Button isLoading={isPending} onClick={handleSubmit}>+ {!isReasonRequired && trimmed.length === 0 ? "Skip & Continue" : "Continue"}+ </Button>+ </div>+ </div>+ </ModalContent>+ </Modal>+ );+};diff --git a/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx b/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsxindex 4d9cd9b642..acb5b8f25e 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/useAccessAwsIamAccount.tsx@@ -8,7 +8,7 @@ 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) {return false;}@@ -21,7 +21,8 @@ export const useAccessAwsIamAccount = () => {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 --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsxindex 8452da8951..9797a378a3 100644--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx@@ -69,6 +69,7 @@ import {import { PamAccessAccountModal } from "../../PamAccountsPage/components/PamAccessAccountModal";import { PamAddAccountModal } from "../../PamAccountsPage/components/PamAddAccountModal";+import { PamAwsIamAccessReasonModal } from "../../PamAccountsPage/components/PamAwsIamAccessReasonModal";import { PamDeleteAccountModal } from "../../PamAccountsPage/components/PamDeleteAccountModal";import { PamRequestAccountAccessModal } from "../../PamAccountsPage/components/PamRequestAccountAccessModal";import { PamUpdateAccountModal } from "../../PamAccountsPage/components/PamUpdateAccountModal";@@ -111,12 +112,13 @@ export const PamResourceAccountsSection = ({ resource }: Props) => {const [pendingMetadataEntries, setPendingMetadataEntries] = useState<MetadataFilterEntry[]>([]);const [appliedMetadataEntries, setAppliedMetadataEntries] = useState<MetadataFilterEntry[]>([]);- const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([+ const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp(["addAccount","accessAccount","requestAccount","updateAccount",- "deleteAccount"+ "deleteAccount",+ "awsIamReason"] as const);const isTableFiltered = Boolean(appliedMetadataEntries.some((e) => e.key.trim()));@@ -259,7 +261,7 @@ export const PamResourceAccountsSection = ({ resource }: Props) => {}if (account.resource.resourceType === PamResourceType.AwsIam) {- accessAwsIam(account);+ handlePopUpOpen("awsIamReason", { account });} else {handlePopUpOpen("accessAccount", { account });}@@ -629,6 +631,19 @@ export const PamResourceAccountsSection = ({ resource }: Props) => {projectId={projectId!}/>+ <PamAwsIamAccessReasonModal+ isOpen={popUp.awsIamReason.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("awsIamReason", isOpen)}+ account={popUp.awsIamReason.data?.account}+ isPending={Boolean(loadingAccountId)}+ onSubmit={async (reason) => {+ const account = popUp.awsIamReason.data?.account;+ if (!account) return;+ handlePopUpClose("awsIamReason");+ await accessAwsIam(account, reason);+ }}+ />+<PamRequestAccountAccessModalisOpen={popUp.requestAccount.isOpen}onOpenChange={(isOpen) => handlePopUpToggle("requestAccount", isOpen)}