Skip to content

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

feat(pam): ssh log & ca cert improvements

x0b6cc997f65b
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
index 50ff0cb749..8dc8a28d35 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
@@ -747,7 +747,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
config: { rateLimit: readLimit },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req, reply) => {
- const { publicKey: caPublicKey } = await server.services.pamAccount.getSshCaPublicKey({
+ const result = await server.services.pamAccount.getOrCreateSshCa({
accountId: req.params.accountId,
projectId: req.internalPamProjectId,
actorId: req.permission.id,
@@ -755,6 +755,22 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod
});
+ const caPublicKey = result.publicKey;
+
+ if (result.created) {
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ projectId: req.internalPamProjectId,
+ event: {
+ type: EventType.PAM_ACCOUNT_SSH_CA_CREATE,
+ metadata: {
+ accountId: req.params.accountId,
+ keyAlgorithm: result.keyAlgorithm!
+ }
+ }
+ });
+ }
const setupScript = `#!/bin/bash
set -e
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
index 9119a8fa0a..ba3d681fc8 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
@@ -62,6 +62,7 @@ import {
import { ConnectionDetailsForm } from "./ConnectionDetailsForm";
import { CreateFolderModal } from "./CreateFolderModal";
import { CredentialsForm } from "./CredentialsForm";
+import { SshCaSetupCallout } from "./SshCaSetupCallout";
const CREATE_FOLDER_VALUE = "__create_folder__";
@@ -473,7 +474,10 @@ export const CreateAccountSheet = ({ isOpen, onOpenChange, defaultFolderId }: Pr
{(selectedMetadata?.credentialFields.length ?? 0) > 0 && (
<div className="mt-2">
<h3 className="mb-3 text-sm font-medium text-foreground">Credentials</h3>
- <CredentialsForm control={control} />
+ <div className="flex flex-col gap-4">
+ <CredentialsForm control={control} />
+ <SshCaSetupCallout control={control} />
+ </div>
</div>
)}
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx
index e875a90847..eb912574fb 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx
@@ -35,6 +35,7 @@ import {
} from "./accountFormSchema";
import { ConnectionDetailsForm } from "./ConnectionDetailsForm";
import { CredentialsForm } from "./CredentialsForm";
+import { SshCaSetupCallout } from "./SshCaSetupCallout";
function filterUnchangedCredentials(
credentials: Record<string, unknown>
@@ -300,8 +301,9 @@ export const EditAccountForm = ({ accountId, onDirtyChange }: Props) => {
<CardTitle className="text-base">Credentials</CardTitle>
<CardDescription>Authentication used to connect to this account.</CardDescription>
</CardHeader>
- <CardContent>
+ <CardContent className="flex flex-col gap-4">
<CredentialsForm control={control} />
+ <SshCaSetupCallout control={control} accountId={accountId} />
</CardContent>
</Card>
)}
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/SshCaSetupCallout.tsx b/frontend/src/pages/pam/PamAccountsPage/components/SshCaSetupCallout.tsx
new file mode 100644
index 0000000000..527186b06c
--- /dev/null
+++ b/frontend/src/pages/pam/PamAccountsPage/components/SshCaSetupCallout.tsx
@@ -0,0 +1,72 @@
+import { Control, useWatch } from "react-hook-form";
+import { AlertTriangle, Copy } from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import { Button, DocumentationLinkBadge } from "@app/components/v3";
+import { PamAccountType } from "@app/hooks/api/pam";
+import { getAuthToken } from "@app/hooks/api/reactQuery";
+import { PamDocsUrls } from "@app/pages/pam/pam-docs-urls";
+
+import { TAccountFormValues } from "./accountFormSchema";
+
+const SSH_CERTIFICATE_AUTH_METHOD = "certificate";
+
+const buildInstallCommand = (accountId: string) =>
+ `curl -sSf -H "Authorization: Bearer ${getAuthToken()}" "${window.location.origin}/api/v1/pam/accounts/${accountId}/ssh-ca-setup" | sudo bash`;
+
+type Props = {
+ control: Control<TAccountFormValues>;
+ accountId?: string; // present only when editing an existing account
+};
+
+export const SshCaSetupCallout = ({ control, accountId }: Props) => {
+ const accountType = useWatch({ control, name: "accountType" });
+ const credentials = useWatch({ control, name: "credentials" }) as
+ | Record<string, unknown>
+ | undefined;
+
+ if (
+ accountType !== PamAccountType.SSH ||
+ credentials?.authMethod !== SSH_CERTIFICATE_AUTH_METHOD
+ ) {
+ return null;
+ }
+
+ const handleCopy = () => {
+ if (!accountId) return;
+ navigator.clipboard.writeText(buildInstallCommand(accountId));
+ createNotification({ type: "success", text: "Install command copied to clipboard" });
+ };
+
+ return (
+ <div className="rounded-md border border-warning/40 bg-warning/5 p-3">
+ <div className="flex items-start gap-2">
+ <AlertTriangle className="mt-0.5 size-4 shrink-0 text-warning" />
+ <div className="min-w-0 flex-1 text-sm">
+ <div className="flex items-center gap-2">
+ <p className="font-medium text-warning">SSH CA setup required</p>
+ <DocumentationLinkBadge href={PamDocsUrls.guides.sshCertificateAuth} />
+ </div>
+ <p className="mt-1 text-muted">
+ Certificate authentication requires the target host to trust Infisical&apos;s SSH
+ certificate authority. Copy the install command and run it on the host as root,
+ otherwise certificate-based sessions will fail.
+ </p>
+
+ {accountId ? (
+ <Button type="button" variant="warning" size="xs" className="mt-3" onClick={handleCopy}>
+ <Copy />
+ Copy install command
+ </Button>
+ ) : (
+ <p className="mt-2 text-muted">
+ After creating this account, open it and use{" "}
+ <span className="font-medium text-foreground">Copy install command</span> to get the
+ command for the target host.
+ </p>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx b/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
index 0bcccae2e4..bb8216b306 100644
--- a/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
@@ -62,12 +62,27 @@ const decodeBase64Utf8 = (b64: string): string => {
}
};
+// matches ANSI/VT escape sequences emitted by a terminal (colors, cursor moves, etc.)
+const ANSI_ESCAPE_REGEX =
+ // eslint-disable-next-line no-control-regex
+ /[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[a-zA-Z\d]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g;
+
+// turns raw terminal bytes into readable log text by stripping escape sequences
+const cleanTerminalOutput = (raw: string): string =>
+ raw
+ .replace(ANSI_ESCAPE_REGEX, "")
+ // eslint-disable-next-line no-control-regex
+ .replace(/[\u0000-\u0008\u000B-\u001F\u007F]/g, "")
+ .trim();
+
const getLogText = (log: TPamSessionLog): string => {
if ("input" in log && "output" in log) {
return [log.input, log.output].filter(Boolean).join(" ");
}
if ("data" in log) {
- return decodeBase64Utf8(log.data);
+ // resize events carry window dimensions, not terminal content. skip them
+ if (log.eventType === "resize") return "";
+ return cleanTerminalOutput(decodeBase64Utf8(log.data));
}
if ("method" in log) {
return `${log.method} ${log.url}`;
@@ -96,15 +111,21 @@ const isDestructiveQuery = (text: string): boolean => {
};
const LogEntry = ({
- log,
text,
bodyText,
- highlight
+ highlight,
+ showTimestamp,
+ timestampLabel,
+ separatorAbove,
+ isGroupEnd
}: {
- log: TPamSessionLog;
text: string;
bodyText: string | null;
highlight: string;
+ showTimestamp: boolean;
+ timestampLabel: string;
+ separatorAbove: boolean;
+ isGroupEnd: boolean;
}) => {
const [expanded, setExpanded] = useState(false);
const [overflows, setOverflows] = useState(false);
@@ -129,17 +150,21 @@ const LogEntry = ({
const body = (
<>
- <div className="mb-1 flex items-center gap-2">
- <span className="font-mono text-[11px] tracking-tight text-muted">
- {format(new Date(log.timestamp), "MMM d, h:mm:ss a")}
- </span>
- {destructive && (
- <span className="flex items-center gap-1 text-[11px] font-medium text-danger">
- <AlertTriangleIcon className="size-3" />
- Destructive
- </span>
- )}
- </div>
+ {(showTimestamp || destructive) && (
+ <div className="mb-1 flex items-center gap-2">
+ {showTimestamp && (
+ <span className="font-mono text-[11px] tracking-tight text-muted">
+ {timestampLabel}
+ </span>
+ )}
+ {destructive && (
+ <span className="flex items-center gap-1 text-[11px] font-medium text-danger">
+ <AlertTriangleIcon className="size-3" />
+ Destructive
+ </span>
+ )}
+ </div>
+ )}
<div className="flex items-start gap-2">
{expandable && (
<ChevronRightIcon
@@ -163,9 +188,10 @@ const LogEntry = ({
</>
);
- const rowClass = `border-b border-border px-4 py-2.5 transition-colors last:border-b-0 ${
- destructive ? "bg-danger/5" : ""
- }`;
+ // lines in the same timestamp group flow together tightly with no separators
+ const rowClass = `px-4 transition-colors ${separatorAbove ? "border-t border-border" : ""} ${
+ showTimestamp ? "pt-2.5" : "pt-0.5"
+ } ${isGroupEnd ? "pb-2.5" : "pb-0.5"} ${destructive ? "bg-danger/5" : ""}`;
if (expandable) {
return (
@@ -310,35 +336,97 @@ export const SessionDetailSheet = ({ sessionId, isOpen, onOpenChange, onTerminat
</div>
);
} else {
- logContent = (
- <div>
- {filteredEvents.map((event, i) => {
- if (isBrokenChunkMarker(event)) {
- return (
- <div
- key={`broken-chunk-${event.chunkIndex}`}
- className="flex items-center gap-2 border-b border-border bg-warning/5 px-4 py-2 text-xs text-warning last:border-b-0"
- >
- <AlertTriangleIcon className="size-3.5 shrink-0" />
- <span>{event.message}</span>
- </div>
- );
- }
-
- const log = event as TPamSessionLog;
- const d = decoded.get(event);
- return (
- <LogEntry
- key={`log-${log.timestamp}-${i + 1}`}
- log={log}
- text={d?.text ?? ""}
- bodyText={d?.body ?? null}
- highlight={logSearch}
- />
- );
- })}
- </div>
- );
+ // first pass: resolve which rows render and collapse repeated timestamps
+ let prevTimestampLabel: string | null = null;
+ const items: (
+ | { kind: "marker"; key: string; message: string }
+ | {
+ kind: "log";
+ key: string;
+ text: string;
+ bodyText: string | null;
+ showTimestamp: boolean;
+ timestampLabel: string;
+ }
+ )[] = [];
+
+ filteredEvents.forEach((event, i) => {
+ if (isBrokenChunkMarker(event)) {
+ prevTimestampLabel = null;
+ items.push({
+ kind: "marker",
+ key: `broken-chunk-${event.chunkIndex}`,
+ message: event.message
+ });
+ return;
+ }
+
+ const log = event as TPamSessionLog;
+ const d = decoded.get(event);
+ const text = d?.text ?? "";
+
+ if (!text) return;
+
+ const timestampLabel = format(new Date(log.timestamp), "MMM d, h:mm:ss a");
+ const showTimestamp = timestampLabel !== prevTimestampLabel;
+ prevTimestampLabel = timestampLabel;
+
+ items.push({
+ kind: "log",
+ key: `log-${log.timestamp}-${i + 1}`,
+ text,
+ bodyText: d?.body ?? null,
+ showTimestamp,
+ timestampLabel
+ });
+ });
+
+ // second pass: a log line ends its group when the next rendered row starts a new group or isn't a log line
+ const rows = items.map((item, idx) => {
+ const separatorAbove = idx > 0 && (item.kind === "marker" || item.showTimestamp);
+
+ if (item.kind === "marker") {
+ return (
+ <div
+ key={item.key}
+ className={`flex items-center gap-2 bg-warning/5 px-4 py-2 text-xs text-warning ${
+ separatorAbove ? "border-t border-border" : ""
+ }`}
+ >
+ <AlertTriangleIcon className="size-3.5 shrink-0" />
+ <span>{item.message}</span>
+ </div>
+ );
+ }
+
+ const next = items[idx + 1];
+ const isGroupEnd = !next || next.kind === "marker" || next.showTimestamp;
+
+ return (
+ <LogEntry
+ key={item.key}
+ text={item.text}
+ bodyText={item.bodyText}
+ highlight={logSearch}
+ showTimestamp={item.showTimestamp}
+ timestampLabel={item.timestampLabel}
+ separatorAbove={separatorAbove}
+ isGroupEnd={isGroupEnd}
+ />
+ );
+ });
+
+ logContent =
+ rows.length === 0 ? (
+ <div className="flex flex-col items-center justify-center gap-2 p-10 text-center">
+ <ClipboardListIcon className="size-6 text-muted" />
+ <p className="text-sm text-muted">
+ {logSearch ? "No logs match your search" : "No logs recorded for this session"}
+ </p>
+ </div>
+ ) : (
+ <div>{rows}</div>
+ );
}
const isRdpSession =