Skip to content

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

Address PR comments

Carlos Monastyrskie0b782b4009d
diff --git a/backend/src/db/migrations/20260417245211_pam-session-reason.ts b/backend/src/db/migrations/20260417245211_pam-session-reason.ts
index 57cad699b7..85c4d31f20 100644
--- a/backend/src/db/migrations/20260417245211_pam-session-reason.ts
+++ b/backend/src/db/migrations/20260417245211_pam-session-reason.ts
@@ -7,7 +7,7 @@ export async function up(knex: Knex): Promise<void> {
const hasCol = await knex.schema.hasColumn(TableName.PamSession, "reason");
if (!hasCol) {
await knex.schema.alterTable(TableName.PamSession, (t) => {
- t.text("reason").nullable();
+ t.string("reason", 1000).nullable();
});
}
}
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 8e6153b1b3..cafb883925 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -185,6 +185,16 @@ export const pamAccountServiceFactory = ({
};
};
+ // Resolve whether the given policy enforces RequireReason at access time.
+ // Surfaced on account responses so the UI can gate access without needing
+ // pam-account-policy:read permission.
+ const resolveRequireReason = async (policyId?: string | null) => {
+ if (!policyId) return false;
+ const policy = await pamAccountPolicyDAL.findById(policyId);
+ const policyRules = (policy?.rules ?? {}) as TPolicyRules;
+ return Boolean(policy?.isActive && policyRules[PamAccountPolicyRuleType.RequireReason]);
+ };
+
const create = async (
{
credentials,
@@ -312,7 +322,8 @@ export const pamAccountServiceFactory = ({
resource: parent.isResource ? parent.raw : null,
domain: parent.isResource ? null : parent.raw
}),
- metadata: insertedMetadata?.map(({ id, key, value }) => ({ id, key, value: value ?? "" })) ?? []
+ metadata: insertedMetadata?.map(({ id, key, value }) => ({ id, key, value: value ?? "" })) ?? [],
+ requireReason: await resolveRequireReason(account.policyId)
};
} catch (err) {
if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {
@@ -467,7 +478,8 @@ export const pamAccountServiceFactory = ({
resource,
domain: parent.isResource ? null : parent.raw
}),
- metadata: existingMeta[accountId] || []
+ metadata: existingMeta[accountId] || [],
+ requireReason: await resolveRequireReason(account.policyId)
};
}
@@ -501,7 +513,8 @@ export const pamAccountServiceFactory = ({
resource,
domain: parent.isResource ? null : parent.raw
}),
- metadata: freshMeta[accountId] || []
+ metadata: freshMeta[accountId] || [],
+ requireReason: await resolveRequireReason(updatedAccount.policyId)
};
} catch (err) {
if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {
@@ -682,15 +695,6 @@ export const pamAccountServiceFactory = ({
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 (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({
@@ -698,7 +702,7 @@ export const pamAccountServiceFactory = ({
domain: accountWithParent.domain
}),
metadata: accountMetadata,
- requireReason
+ requireReason: await resolveRequireReason(accountWithParent.policyId)
};
};
diff --git a/docs/documentation/platform/pam/product-reference/account-policies.mdx b/docs/documentation/platform/pam/product-reference/account-policies.mdx
index 663e50354a..5baf51880a 100644
--- a/docs/documentation/platform/pam/product-reference/account-policies.mdx
+++ b/docs/documentation/platform/pam/product-reference/account-policies.mdx
@@ -14,6 +14,7 @@ An account policy is a named, project-scoped configuration that contains one or
|---|---|---|
| **Command Blocking** | Prevents execution of commands matching specified regex patterns. | SSH |
| **Session Log Masking** | Redacts data matching specified regex patterns from session logs. | All resource types |
+| **Require Access Reason** | Requires the user to provide a reason before a session can start. The reason is stored for audit. | All resource types |
A policy can be **active** or **inactive**. Only active policies are enforced during sessions.
@@ -34,6 +35,7 @@ Navigate to your PAM project sidebar and click **Account Policies**, then click
- **Command Blocking**: Add one or more regex patterns. Commands matching any of these patterns will be blocked during SSH sessions.
- **Session Log Masking**: Add one or more regex patterns. Any data matching these patterns will be redacted in session logs.
+ - **Require Access Reason**: Forces the user to provide a non-empty reason before they can start a session. When the rule is active, the CLI prompts for a reason (or accepts the `--reason` flag) and the browser shows a Reason Required screen before the session is created.
For each rule, click the **+** button to add additional patterns.
diff --git a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
index 2dcd87c9f5..0d9fa7a016 100644
--- a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
+++ b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
@@ -17,7 +17,7 @@ const TerminalContent = ({
account: TPamAccount;
projectId: string;
orgId: string;
- reason: string;
+ reason?: string;
}) => {
const [sessionEnded, setSessionEnded] = useState(false);
@@ -124,6 +124,12 @@ const PageContent = () => {
);
}
+ // SSH uses inline terminal prompts for reason — bypass the upfront ReasonGate so the
+ // approval prompt and reason prompt render in the same terminal stream, in order.
+ if (account.resource?.resourceType === PamResourceType.SSH) {
+ return <TerminalContent account={account} projectId={projectId!} orgId={orgId!} />;
+ }
+
return (
<ReasonGate account={account}>
{(reason) => {
diff --git a/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts b/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
index eb5679adfa..b97ea99465 100644
--- a/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
+++ b/frontend/src/pages/pam/PamAccountAccessPage/useWebAccessSession.ts
@@ -47,6 +47,9 @@ export const useWebAccessSession = ({
const nextPromptRejecterRef = useRef<((reason: Error) => void) | null>(null);
const onSessionEndRef = useRef(onSessionEnd);
+ // Seed with the prop so non-SSH flows (which collect reason via the upfront ReasonGate)
+ // pass it on the first connect; SSH leaves it undefined and uses the inline terminal prompt.
+ const submittedReasonRef = useRef<string | undefined>(reason);
useEffect(() => {
onSessionEndRef.current = onSessionEnd;
@@ -239,7 +242,7 @@ export const useWebAccessSession = ({
try {
const { data } = await apiRequest.post<{ ticket: string }>(
`/api/v1/pam/accounts/${accountId}/web-access-ticket`,
- { projectId, reason }
+ { projectId, reason: submittedReasonRef.current }
);
if (containerEl) {
containerEl.style.width = "";
@@ -331,7 +334,7 @@ export const useWebAccessSession = ({
terminal.reset();
const { data: retryData } = await apiRequest.post<{ ticket: string }>(
`/api/v1/pam/accounts/${accountId}/web-access-ticket`,
- { projectId, mfaSessionId, reason }
+ { projectId, mfaSessionId, reason: submittedReasonRef.current }
);
openWebSocket(terminal, retryData.ticket);
} catch {
@@ -400,9 +403,28 @@ export const useWebAccessSession = ({
return;
}
+ if (axiosErr?.response?.data?.error === "PAM_REASON_REQUIRED") {
+ terminal.write("\r\nThis account requires a reason for access.\r\n");
+
+ const reasonInput = await prompt("\r\nEnter reason: ");
+
+ if (!reasonInput.trim()) {
+ terminal.write("\r\nA reason is required to continue.\r\n");
+ await prompt("\r\nPress Enter to try again.");
+ terminal.reset();
+ connect();
+ return;
+ }
+
+ submittedReasonRef.current = reasonInput.trim();
+ terminal.reset();
+ connect();
+ return;
+ }
+
terminal.write("\r\nFailed to connect. Please close and try again.\r\n");
}
- }, [accountId, projectId, orgId, resourceName, accountName, reason, containerEl, openWebSocket]);
+ }, [accountId, projectId, orgId, resourceName, accountName, containerEl, openWebSocket]);
const disconnect = useCallback(() => {
const ws = wsRef.current;
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionDetailsSection.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionDetailsSection.tsx
index 24074046ef..05da111c50 100644
--- a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionDetailsSection.tsx
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionDetailsSection.tsx
@@ -108,7 +108,13 @@ export const PamSessionDetailsSection = ({
</DetailItem>
<DetailItem label="Reason">
- <p className="break-words whitespace-pre-wrap">{reason || "—"}</p>
+ {reason ? (
+ <div className="max-h-32 overflow-y-auto rounded border border-mineshaft-600 bg-mineshaft-800 p-2">
+ <p className="break-words whitespace-pre-wrap">{reason}</p>
+ </div>
+ ) : (
+ <p>—</p>
+ )}
</DetailItem>
<DetailItem label="Created At">