Skip to content

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

Merge branch 'main' into PAM-93

x03220598a81423fa94
diff --cc backend/src/ee/services/pam-account/pam-account-service.ts
index e7a4ef29a6,245783e27d..b0c89be071
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@@ -888,21 -916,13 +920,22 @@@ export const pamAccountServiceFactory
accountId: account.id,
resourceId: resource.id,
userId: actor.id,
- expiresAt,
+ expiresAt: credentials.expiresAt,
- startedAt: new Date()
+ startedAt: new Date(),
+ reason: trimmedReason
});
+ // Cache the AccessKeyId so /aws-console-url can verify the caller is
+ // submitting credentials that actually belong to this session
+ const ttlSeconds = Math.max(1, Math.floor((credentials.expiresAt.getTime() - Date.now()) / 1000));
+ await keyStore.setItemWithExpiry(
+ KeyStorePrefixes.PamAwsIamAccessKeyId(session.id),
+ ttlSeconds,
+ credentials.accessKeyId
+ );
+
// Schedule session expiration job to run at expiresAt
- await pamSessionExpirationService.scheduleSessionExpiration(session.id, expiresAt);
+ await pamSessionExpirationService.scheduleSessionExpiration(session.id, credentials.expiresAt);
return {
sessionId: session.id,
diff --cc frontend/src/pages/cert-manager/ApprovalRequestDetailPage/route.tsx
index b873fb10ea,92a6c365d2..a1eac7393c
--- a/frontend/src/pages/cert-manager/ApprovalRequestDetailPage/route.tsx
+++ b/frontend/src/pages/cert-manager/ApprovalRequestDetailPage/route.tsx
@@@ -1,17 -1,17 +1,17 @@@
--import { createFileRoute } from "@tanstack/react-router";
--import { zodValidator } from "@tanstack/zod-adapter";
--import { z } from "zod";
++import { createFileRoute } from '@tanstack/react-router'
++import { zodValidator } from '@tanstack/zod-adapter'
++import { z } from 'zod'
--import { ApprovalPolicyType } from "@app/hooks/api/approvalPolicies";
++import { ApprovalPolicyType } from '@app/hooks/api/approvalPolicies'
--import { ApprovalRequestDetailPage } from "./ApprovalRequestDetailPage";
++import { ApprovalRequestDetailPage } from './ApprovalRequestDetailPage'
const ApprovalRequestSearchSchema = z.object({
-- policyType: z.nativeEnum(ApprovalPolicyType).optional()
--});
++ policyType: z.nativeEnum(ApprovalPolicyType).optional(),
++})
export const Route = createFileRoute(
- "/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approval-requests/$approvalRequestId"
- "/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approvals/$approvalRequestId"
++ '/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approvals/$approvalRequestId',
)({
component: ApprovalRequestDetailPage,
validateSearch: zodValidator(ApprovalRequestSearchSchema),
@@@ -20,9 -20,9 +20,9 @@@
breadcrumbs: [
...context.breadcrumbs,
{
-- label: "Approval Request"
-- }
-- ]
-- };
-- }
--});
++ label: 'Approval Request',
++ },
++ ],
++ }
++ },
++})
diff --cc frontend/src/pages/cert-manager/ApprovalsPage/route.tsx
index 5f8cfeb64c,bbbab5deac..765e104842
--- a/frontend/src/pages/cert-manager/ApprovalsPage/route.tsx
+++ b/frontend/src/pages/cert-manager/ApprovalsPage/route.tsx
@@@ -1,16 -1,16 +1,19 @@@
--import { createFileRoute } from "@tanstack/react-router";
--import { zodValidator } from "@tanstack/zod-adapter";
--import { z } from "zod";
++import { createFileRoute } from '@tanstack/react-router'
++import { zodValidator } from '@tanstack/zod-adapter'
++import { z } from 'zod'
--import { ApprovalsPage } from "./ApprovalsPage";
++import { ApprovalsPage } from './ApprovalsPage'
const ApprovalsSearchSchema = z.object({
-- selectedTab: z.string().optional().default("requests"),
-- section: z.enum(["certificates", "code-signing"]).optional().default("certificates")
--});
++ selectedTab: z.string().optional().default('requests'),
++ section: z
++ .enum(['certificates', 'code-signing'])
++ .optional()
++ .default('certificates'),
++})
export const Route = createFileRoute(
- "/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approvals"
- "/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approvals/"
++ '/_authenticate/_inject-org-details/_org-layout/organizations/$orgId/projects/cert-manager/$projectId/_cert-manager-layout/approvals/',
)({
component: ApprovalsPage,
validateSearch: zodValidator(ApprovalsSearchSchema),
@@@ -19,9 -19,9 +22,9 @@@
breadcrumbs: [
...context.breadcrumbs,
{
-- label: "Approvals"
-- }
-- ]
-- };
-- }
--});
++ label: 'Approvals',
++ },
++ ],
++ }
++ },
++})
diff --cc frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
index 6071608781,416a132da6..d2c6adf1b8
--- a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
@@@ -73,8 -75,8 +74,9 @@@ const PageContent = () =>
const isDomainAccount = !!domainId;
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
++ const [accessReason, setAccessReason] = useState<string | undefined>(undefined);
- const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
+ const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
"accessAccount",
"requestAccount",
"deleteAccount",
@@@ -318,9 -326,22 +325,26 @@@
<PamAccessAccountModal
isOpen={popUp.accessAccount.isOpen}
-- onOpenChange={(isOpen) => handlePopUpToggle("accessAccount", isOpen)}
++ onOpenChange={(isOpen) => {
++ handlePopUpToggle("accessAccount", isOpen);
++ if (!isOpen) setAccessReason(undefined);
++ }}
account={popUp.accessAccount.data?.account}
projectId={projectId!}
++ reason={accessReason}
+ />
+
+ <PamAwsIamAccessReasonModal
+ isOpen={popUp.awsIamReason.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("awsIamReason", isOpen)}
+ account={popUp.awsIamReason.data?.account}
- isPending={isAwsAccessPending}
- onSubmit={async (reason) => {
++ onSubmit={(reason) => {
+ const targetAccount = popUp.awsIamReason.data?.account;
+ if (!targetAccount) return;
+ handlePopUpClose("awsIamReason");
- await accessAwsIam(targetAccount, reason);
++ setAccessReason(reason || undefined);
++ handlePopUpOpen("accessAccount", { account: targetAccount });
+ }}
/>
<PamRequestAccountAccessModal
diff --cc frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
index 7348aa3ce0,84caecc723..49a4ca45c5
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
@@@ -18,9 -16,9 +18,16 @@@ type Props =
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
projectId: string;
++ reason?: string;
};
--export const PamAccessAccountModal = ({ isOpen, onOpenChange, account, projectId }: Props) => {
++export const PamAccessAccountModal = ({
++ isOpen,
++ onOpenChange,
++ account,
++ projectId,
++ reason
++}: Props) => {
const { currentOrg } = useOrganization();
const [duration, setDuration] = useState("4h");
@@@ -107,94 -104,83 +115,95 @@@
title="Access Account"
subTitle={`Connect to ${account.name}`}
>
- <div className="py-1">
- <p className="text-sm font-medium text-mineshaft-400">Terminal</p>
- <p className="mb-2 text-xs text-mineshaft-400">Connect using the Infisical CLI</p>
- <FormLabel
- label="Duration"
- tooltipText="The maximum duration of your session. Ex: 1h, 3w, 30d"
- />
- <Input
- value={duration}
- onChange={(e) => setDuration(e.target.value)}
- placeholder="permanent"
- isError={!isDurationValid}
+ {isAwsIam ? (
+ <PamAwsIamAccessSection
+ account={account}
+ projectId={projectId}
++ reason={reason}
+ onClose={() => onOpenChange(false)}
/>
- <FormLabel label="CLI Command" className="mt-4" />
- <div className="flex gap-2">
- <Input value={command} isDisabled />
- <IconButton
- ariaLabel="copy"
- variant="outline_bg"
- colorSchema="secondary"
- isDisabled={!isDurationValid}
- onClick={() => {
- navigator.clipboard.writeText(command);
-
- createNotification({
- text: "Command copied to clipboard",
- type: "info"
- });
-
- onOpenChange(false);
- }}
- className="w-10"
- >
- <FontAwesomeIcon icon={faCopy} />
- </IconButton>
- </div>
- <a
- href="https://infisical.com/docs/cli/overview"
- target="_blank"
- className="mt-2 flex h-4 w-fit items-center gap-2 border-b border-mineshaft-400 text-sm text-mineshaft-400 transition-colors duration-100 hover:border-yellow-400 hover:text-yellow-400"
- rel="noreferrer"
- >
- <span>Install the Infisical CLI</span>
- <FontAwesomeIcon icon={faUpRightFromSquare} className="size-3" />
- </a>
- </div>
- {showWebAccess && (
+ ) : (
<>
- <div className="relative my-6">
- <div className="absolute inset-0 flex items-center">
- <div className="w-full border-t border-mineshaft-600" />
- </div>
- <div className="relative flex justify-center text-xs">
- <span className="bg-mineshaft-800 px-2 text-mineshaft-400">OR</span>
- </div>
- </div>
<div className="py-1">
- <p className="text-sm font-medium text-mineshaft-400">Browser</p>
- <p className="mb-2 text-xs text-mineshaft-400">Connect directly from your browser</p>
+ <p className="text-sm font-medium text-mineshaft-400">Terminal</p>
+ <p className="mb-2 text-xs text-mineshaft-400">Connect using the Infisical CLI</p>
+ <FormLabel
+ label="Duration"
+ tooltipText="The maximum duration of your session. Ex: 1h, 3w, 30d"
+ />
+ <Input
+ value={duration}
+ onChange={(e) => setDuration(e.target.value)}
+ placeholder="permanent"
+ isError={!isDurationValid}
+ />
+ <FormLabel label="CLI Command" className="mt-4" />
<div className="flex gap-2">
- <Link
- to={ROUTE_PATHS.Pam.PamAccountAccessPage.path}
- params={{
- orgId: currentOrg.id,
- projectId,
- resourceType: account.resource?.resourceType ?? "",
- resourceId: account.resource?.id ?? "",
- accountId: account.id
+ <Input value={command} isDisabled />
+ <IconButton
+ ariaLabel="copy"
+ variant="outline_bg"
+ colorSchema="secondary"
+ onClick={() => {
+ navigator.clipboard.writeText(command);
+
+ createNotification({
+ text: "Command copied to clipboard",
+ type: "info"
+ });
+
+ onOpenChange(false);
}}
- target="_blank"
- className="flex w-full items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-black transition-colors hover:bg-primary/80"
+ className="w-10"
>
- <FontAwesomeIcon icon={faTerminal} />
- Connect in Browser
- </Link>
+ <FontAwesomeIcon icon={faCopy} />
+ </IconButton>
</div>
+ <a
+ href="https://infisical.com/docs/cli/overview"
+ target="_blank"
+ className="mt-2 flex h-4 w-fit items-center gap-2 border-b border-mineshaft-400 text-sm text-mineshaft-400 transition-colors duration-100 hover:border-yellow-400 hover:text-yellow-400"
+ rel="noreferrer"
+ >
+ <span>Install the Infisical CLI</span>
+ <FontAwesomeIcon icon={faUpRightFromSquare} className="size-3" />
+ </a>
</div>
+ {showWebAccess && (
+ <>
+ <div className="relative my-6">
+ <div className="absolute inset-0 flex items-center">
+ <div className="w-full border-t border-mineshaft-600" />
+ </div>
+ <div className="relative flex justify-center text-xs">
+ <span className="bg-mineshaft-800 px-2 text-mineshaft-400">OR</span>
+ </div>
+ </div>
+ <div className="py-1">
+ <p className="text-sm font-medium text-mineshaft-400">Browser</p>
+ <p className="mb-2 text-xs text-mineshaft-400">
+ Connect directly from your browser
+ </p>
+ <div className="flex gap-2">
+ <Link
+ to={ROUTE_PATHS.Pam.PamAccountAccessPage.path}
+ params={{
+ orgId: currentOrg.id,
+ projectId,
+ resourceType: account.resource?.resourceType ?? "",
+ resourceId: account.resource?.id ?? "",
+ accountId: account.id
+ }}
+ target="_blank"
+ className="flex w-full items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-black transition-colors hover:bg-primary/80"
+ >
+ <FontAwesomeIcon icon={faTerminal} />
+ Connect in Browser
+ </Link>
+ </div>
+ </div>
+ </>
+ )}
</>
)}
</ModalContent>
diff --cc frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessSection.tsx
index f3cc74017d,0000000000..b4ce51e9ac
mode 100644,000000..100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessSection.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAwsIamAccessSection.tsx
@@@ -1,203 -1,0 +1,205 @@@
+import { useEffect, useRef, useState } from "react";
+import { CopyIcon, ExternalLinkIcon } from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import { ContentLoader } from "@app/components/v2";
+import { Button, IconButton, Input, Label } from "@app/components/v3";
+import { TPamAccount, useAccessPamAccount, useGetAwsIamConsoleUrl } from "@app/hooks/api/pam";
+import { TAwsIamCredentials } from "@app/hooks/api/pam/types";
+
+const formatExpiry = (expiresAt: string) => {
+ const remainingMs = new Date(expiresAt).getTime() - Date.now();
+ if (remainingMs <= 0) return "Expired";
+
+ const totalMinutes = Math.floor(remainingMs / 60_000);
+ const hours = Math.floor(totalMinutes / 60);
+ const minutes = totalMinutes % 60;
+ return hours > 0 ? `Expires in ${hours}h ${minutes}m` : `Expires in ${minutes}m`;
+};
+
+type TStsCredentials = {
+ accessKeyId: string;
+ secretAccessKey: string;
+ sessionToken: string;
+ expiresAt: string;
+};
+
+type Props = {
+ account: TPamAccount;
+ projectId: string;
++ reason?: string;
+ onClose: () => void;
+};
+
- export const PamAwsIamAccessSection = ({ account, projectId, onClose }: Props) => {
++export const PamAwsIamAccessSection = ({ account, projectId, reason, onClose }: Props) => {
+ const accessPamAccount = useAccessPamAccount();
+ const getAwsIamConsoleUrl = useGetAwsIamConsoleUrl();
+
+ const [credentials, setCredentials] = useState<TStsCredentials | null>(null);
+ const [sessionId, setSessionId] = useState<string | null>(null);
+ const [error, setError] = useState<string | null>(null);
+ const [, setNow] = useState(Date.now());
+
+ // Guards against React 18 StrictMode's double-invoked effect, which would
+ // otherwise issue two STS sessions for a single modal open
+ const hasRequestedRef = useRef(false);
+
+ useEffect(() => {
+ const id = window.setInterval(() => setNow(Date.now()), 60_000);
+ return () => window.clearInterval(id);
+ }, []);
+
+ useEffect(() => {
+ if (hasRequestedRef.current) return;
+ hasRequestedRef.current = true;
+
+ const run = async () => {
+ try {
+ const response = await accessPamAccount.mutateAsync({
+ accountId: account.id,
+ resourceName: account.resource?.name ?? "",
+ accountName: account.name,
+ projectId,
- duration: `${(account.credentials as TAwsIamCredentials).defaultSessionDuration}s`
++ duration: `${(account.credentials as TAwsIamCredentials).defaultSessionDuration}s`,
++ reason
+ });
+
+ if (
+ !response.accessKeyId ||
+ !response.secretAccessKey ||
+ !response.sessionToken ||
+ !response.expiresAt
+ ) {
+ setError("Backend did not return AWS credentials");
+ return;
+ }
+
+ setCredentials({
+ accessKeyId: response.accessKeyId,
+ secretAccessKey: response.secretAccessKey,
+ sessionToken: response.sessionToken,
+ expiresAt: response.expiresAt
+ });
+ setSessionId(response.sessionId);
+ } catch (err) {
+ setError(err instanceof Error ? err.message : "Failed to generate AWS session credentials");
+ }
+ };
+
+ run().catch(() => {});
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ const handleCopy = (text: string, label: string) => {
+ navigator.clipboard.writeText(text).catch(() => {});
+ createNotification({ text: `${label} copied to clipboard`, type: "info" });
+ };
+
+ const handleOpenConsole = async () => {
+ if (!sessionId || !credentials) return;
+ try {
+ const { consoleUrl } = await getAwsIamConsoleUrl.mutateAsync({
+ sessionId,
+ projectId,
+ accessKeyId: credentials.accessKeyId,
+ secretAccessKey: credentials.secretAccessKey,
+ sessionToken: credentials.sessionToken
+ });
+ window.open(consoleUrl, "_blank", "noopener,noreferrer");
+ createNotification({ text: "AWS Console opened in a new tab", type: "success" });
+ onClose();
+ } catch (err) {
+ createNotification({
+ text: err instanceof Error ? err.message : "Failed to open AWS Console",
+ type: "error"
+ });
+ }
+ };
+
+ if (error) {
+ return (
+ <div
+ role="alert"
+ className="rounded-md border border-danger/20 bg-danger/5 p-4 text-sm text-danger"
+ >
+ {error}
+ </div>
+ );
+ }
+
+ if (!credentials) {
+ return (
+ <div className="flex h-40 items-center justify-center">
+ <ContentLoader />
+ </div>
+ );
+ }
+
+ const fields = [
+ { label: "Access Key ID", value: credentials.accessKeyId },
+ { label: "Secret Access Key", value: credentials.secretAccessKey },
+ { label: "Session Token", value: credentials.sessionToken }
+ ];
+
+ return (
+ <div className="flex flex-col gap-4">
+ <div>
+ <div className="flex items-center justify-between">
+ <div>
+ <p className="text-sm font-medium text-foreground">Credentials</p>
+ <p className="text-xs text-muted">
+ Use with the AWS CLI, SDKs, or paste into <code>~/.aws/credentials</code>
+ </p>
+ </div>
+ <p className="text-xs text-muted">{formatExpiry(credentials.expiresAt)}</p>
+ </div>
+
+ <div className="mt-3 flex flex-col gap-3">
+ {fields.map(({ label, value }) => (
+ <div key={label}>
+ <Label className="mb-1 text-label">{label}</Label>
+ <div className="flex gap-2">
+ <Input value={value} readOnly />
+ <IconButton
+ aria-label={`Copy ${label}`}
+ variant="outline"
+ onClick={() => handleCopy(value, label)}
+ >
+ <CopyIcon />
+ </IconButton>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+
+ <div className="relative my-2">
+ <div className="absolute inset-0 flex items-center">
+ <div className="w-full border-t border-border" />
+ </div>
+ <div className="relative flex justify-center text-xs">
+ <span className="bg-mineshaft-800 px-2 text-muted">OR</span>
+ </div>
+ </div>
+
+ <div>
+ <p className="text-sm font-medium text-foreground">Browser</p>
+ <p className="mb-2 text-xs text-muted">
+ Open the AWS Console signed in as the same temporary session
+ </p>
+ <Button
+ variant="project"
+ size="md"
+ isFullWidth
+ isPending={getAwsIamConsoleUrl.isPending}
+ onClick={() => {
+ handleOpenConsole().catch(() => {});
+ }}
+ >
+ <ExternalLinkIcon />
+ Open in AWS Console
+ </Button>
+ </div>
+ </div>
+ );
+};
diff --cc frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
index 1f84612ea6,92e95c331c..1a6f43f8aa
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
@@@ -98,6 -101,6 +99,7 @@@ export const PamResourceAccountsSectio
const [search, setSearch] = useState("");
const [debouncedSearch] = useDebounce(search);
const [rotatingAccountIds, setRotatingAccountIds] = useState<Set<string>>(new Set());
++ const [accessReason, setAccessReason] = useState<string | undefined>(undefined);
const [pendingMetadataEntries, setPendingMetadataEntries] = useState<MetadataFilterEntry[]>([]);
const [appliedMetadataEntries, setAppliedMetadataEntries] = useState<MetadataFilterEntry[]>([]);
@@@ -637,9 -647,22 +644,26 @@@
<PamAccessAccountModal
isOpen={popUp.accessAccount.isOpen}
-- onOpenChange={(isOpen) => handlePopUpToggle("accessAccount", isOpen)}
++ onOpenChange={(isOpen) => {
++ handlePopUpToggle("accessAccount", isOpen);
++ if (!isOpen) setAccessReason(undefined);
++ }}
account={popUp.accessAccount.data?.account}
projectId={projectId!}
++ reason={accessReason}
+ />
+
+ <PamAwsIamAccessReasonModal
+ isOpen={popUp.awsIamReason.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("awsIamReason", isOpen)}
+ account={popUp.awsIamReason.data?.account}
- isPending={Boolean(loadingAccountId)}
- onSubmit={async (reason) => {
++ onSubmit={(reason) => {
+ const account = popUp.awsIamReason.data?.account;
+ if (!account) return;
+ handlePopUpClose("awsIamReason");
- await accessAwsIam(account, reason);
++ setAccessReason(reason || undefined);
++ handlePopUpOpen("accessAccount", { account });
+ }}
/>
<PamRequestAccountAccessModal