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
improvement(dynamic-secrets): add JSON API for SSH CA public key (#5979)
Saif Ur Rahman6fe20adbc4be
diff --git a/backend/src/ee/routes/v1/dynamic-secret-router.ts b/backend/src/ee/routes/v1/dynamic-secret-router.tsindex df57997e0a..40dcbab2f6 100644--- a/backend/src/ee/routes/v1/dynamic-secret-router.ts+++ b/backend/src/ee/routes/v1/dynamic-secret-router.ts@@ -572,6 +572,38 @@ echo ""}});+ server.route({+ method: "GET",+ url: "/ssh-ca-public-key/:dynamicSecretId",+ config: {+ rateLimit: readLimit+ },+ schema: {+ operationId: "getSshDynamicSecretCaPublicKey",+ description: "Get SSH dynamic secret CA public key",+ params: z.object({+ dynamicSecretId: z.string().uuid()+ }),+ response: {+ 200: z.object({+ caPublicKey: z.string()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const { caPublicKey } = await server.services.dynamicSecret.getSshCaPublicKey({+ dynamicSecretId: req.params.dynamicSecretId,+ actor: req.permission.type,+ actorId: req.permission.id,+ actorAuthMethod: req.permission.authMethod,+ actorOrgId: req.permission.orgId+ });++ return { caPublicKey };+ }+ });+server.route({method: "POST",url: "/entra-id/users",diff --git a/backend/src/ee/services/ssh/ssh-certificate-authority-fns.ts b/backend/src/ee/services/ssh/ssh-certificate-authority-fns.tsindex 21da4bc163..821b5df5b4 100644--- a/backend/src/ee/services/ssh/ssh-certificate-authority-fns.ts+++ b/backend/src/ee/services/ssh/ssh-certificate-authority-fns.ts@@ -82,7 +82,7 @@ export const createSshKeyPair = async (keyAlgorithm: SshCertKeyAlgorithm) => {if (keyBits !== null) {args.push("-b", keyBits);}- args.push("-f", privateKeyFile, "-N", "");+ args.push("-f", privateKeyFile, "-N", "", "-C", "Infisical");// Generate the SSH key pair// The "-N ''" sets an empty passphrasediff --git a/docs/docs.json b/docs/docs.jsonindex d78b0d79da..a6c64ee838 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -507,6 +507,7 @@"documentation/platform/dynamic-secrets/sap-ase","documentation/platform/dynamic-secrets/sap-hana","documentation/platform/dynamic-secrets/snowflake",+ "documentation/platform/dynamic-secrets/ssh","documentation/platform/dynamic-secrets/totp","documentation/platform/dynamic-secrets/kubernetes","documentation/platform/dynamic-secrets/vertica"diff --git a/docs/documentation/platform/dynamic-secrets/ssh.mdx b/docs/documentation/platform/dynamic-secrets/ssh.mdxnew file mode 100644index 0000000000..afe43cf6a7--- /dev/null+++ b/docs/documentation/platform/dynamic-secrets/ssh.mdx@@ -0,0 +1,161 @@+---+title: "SSH Certificates"+description: "Learn how to dynamically generate short-lived SSH certificates."+---++The Infisical SSH dynamic secret allows you to generate ephemeral SSH certificates on demand, signed by an auto-generated Certificate Authority (CA). Instead of distributing static SSH keys, each lease produces a short-lived private key and a signed certificate that expires automatically.++## How It Works++When you create an SSH dynamic secret, Infisical generates an internal CA key pair. Target hosts are configured to trust this CA. When a lease is requested, Infisical generates an ephemeral key pair, signs the public key with the CA, and returns the private key and signed certificate. The certificate expires when the lease TTL ends — no manual key rotation or revocation needed.++## Set up Dynamic Secrets with SSH++<Steps>+ <Step title="Open Secret Overview Dashboard">+ Open the Secret Overview dashboard and select the environment in which you would like to add a dynamic secret.++ + </Step>+ <Step title="Click on the 'Add Dynamic Secret' button">+ + </Step>+ <Step title="Select 'SSH'">+ Select **SSH** from the dynamic secret type list.++ + </Step>+ <Step title="Provide the inputs for dynamic secret parameters">+ <ParamField path="Secret Name" type="string" required>+ Name by which you want the secret to be referenced+ </ParamField>++ <ParamField path="Default TTL" type="string" required>+ Default time-to-live for a generated certificate (e.g. `1h`, `8h`)+ </ParamField>++ <ParamField path="Max TTL" type="string" required>+ Maximum time-to-live for a generated certificate+ </ParamField>++ <ParamField path="Allowed Principals" type="list" required>+ The usernames this dynamic secret can issue certificates for (e.g. `ubuntu`, `deploy`, `root`). When creating a lease, the requester selects a subset of these principals.+ </ParamField>++ <ParamField path="Key Algorithm" type="string" required>+ Algorithm for the ephemeral key pairs generated per lease. Supported options: **ED25519** (default, recommended), **RSA 2048**, **RSA 4096**, **ECDSA P-256**, **ECDSA P-384**.+ </ParamField>++ + </Step>+ <Step title="Click 'Submit'">+ After submitting the form, a **Certificate Authentication Setup** modal will appear with two options for configuring target hosts to trust the CA:++ - **Automated setup**: A `curl | sudo bash` command that installs the CA certificate, configures `TrustedUserCAKeys` in `sshd_config`, and restarts the SSH service.+ - **Manual setup**: The raw CA public key, which you can reveal and copy to install manually on target hosts.++ ++ <Note>+ You must configure your target SSH servers to trust the CA before certificate-based authentication will work. This only needs to be done once per host.+ </Note>+ </Step>+ <Step title="Configure target hosts">+ **Option A — Automated setup**++ Run the provided command on each target host:+ ```bash+ curl -H "Authorization: Bearer <your-token>" "https://<your-infisical-url>/api/v1/dynamic-secrets/ssh-ca-setup/<dynamic-secret-id>" | sudo bash+ ```++ This script will:+ - Write the CA public key to `/etc/ssh/infisical_ca.pub`+ - Add `TrustedUserCAKeys /etc/ssh/infisical_ca.pub` to `/etc/ssh/sshd_config`+ - Validate the SSH configuration and restart the SSH service++ **Option B — Manual setup**++ 1. Copy the CA public key (available via the eye icon in the setup modal or the edit form)+ 2. Save it to `/etc/ssh/infisical_ca.pub` on the target host+ 3. Add the following line to `/etc/ssh/sshd_config`:+ ```+ TrustedUserCAKeys /etc/ssh/infisical_ca.pub+ ```+ 4. Restart the SSH service++ You can also retrieve the CA public key programmatically:+ ```bash+ curl -H "Authorization: Bearer <your-token>" "https://<your-infisical-url>/api/v1/dynamic-secrets/ssh-ca-public-key/<dynamic-secret-id>"+ ```+ This returns a JSON response: `{ "caPublicKey": "ssh-ed25519 AAAA..." }`+ </Step>+ <Step title="Generate dynamic secrets">+ Once you've configured the dynamic secret and set up target hosts, you're ready to generate on-demand credentials.+ To do this, simply click on the **Generate** button which appears when hovering over the dynamic secret item.++ ++ When generating a lease, you will need to provide:++ <ParamField path="TTL" type="string" required>+ How long the certificate should be valid for. Must be within the Max TTL configured on the dynamic secret.+ </ParamField>++ <ParamField path="Principals" type="list" required>+ One or more usernames (from the allowed principals) that the certificate should be valid for.+ </ParamField>++ ++ Once you click **Submit**, a new lease will be generated containing:+ - **Private Key** — the ephemeral SSH private key (downloadable as `key.pem`)+ - **Signed Certificate** — the SSH certificate signed by the CA (downloadable as `cert.pub`)++ Both can be downloaded or copied directly from the UI.++ ++ <Warning>+ Copy or download these credentials immediately. You will not be able to see them again after closing the modal.+ </Warning>+ </Step>+ <Step title="Use the certificate to connect">+ After downloading `key.pem` (private key) and `cert.pub` (signed certificate), set the correct permissions and connect:++ ```bash+ # Set private key permissions+ chmod 600 key.pem++ # Connect to the target host+ ssh -i key.pem -o CertificateFile=cert.pub <principal>@<hostname>+ ```++ Replace `<principal>` with one of the principals included in the certificate and `<hostname>` with the target host address.+ </Step>+</Steps>++## Audit or Revoke Leases++Once you have created one or more leases, you will be able to access them by clicking on the respective dynamic secret item on the dashboard.++++This will allow you to see the expiration time of the lease or delete the lease before its set time to live.++++<Note>+ SSH certificates are time-bound and expire automatically. Revoking a lease in Infisical removes the record, but the certificate remains valid until its TTL expires.+</Note>++## Edit Dynamic Secret++To update the configuration of an existing SSH dynamic secret (principals, key algorithm, TTL, or to access the CA setup options), click on the dynamic secret item and select **Edit**.++++## Renew Leases++<Note>+ SSH certificate leases cannot be renewed because the certificate validity is baked in at signing time. To get a new certificate, create a new lease.+</Note>diff --git a/docs/images/platform/dynamic-secrets/ssh/add-dynamic-secret-button.png b/docs/images/platform/dynamic-secrets/ssh/add-dynamic-secret-button.pngnew file mode 100644index 0000000000..0c7c14482eBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/add-dynamic-secret-button.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/ca-setup-modal.png b/docs/images/platform/dynamic-secrets/ssh/ca-setup-modal.pngnew file mode 100644index 0000000000..c6dd342eafBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/ca-setup-modal.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/edit-dynamic-secret.png b/docs/images/platform/dynamic-secrets/ssh/edit-dynamic-secret.pngnew file mode 100644index 0000000000..60aa981df2Binary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/edit-dynamic-secret.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/generate-lease-form.png b/docs/images/platform/dynamic-secrets/ssh/generate-lease-form.pngnew file mode 100644index 0000000000..be1fb414e2Binary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/generate-lease-form.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/hover-generate-lease.png b/docs/images/platform/dynamic-secrets/ssh/hover-generate-lease.pngnew file mode 100644index 0000000000..4528494c7dBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/hover-generate-lease.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/hover-view-leases.png b/docs/images/platform/dynamic-secrets/ssh/hover-view-leases.pngnew file mode 100644index 0000000000..7d1effc33eBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/hover-view-leases.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/lease-credentials.png b/docs/images/platform/dynamic-secrets/ssh/lease-credentials.pngnew file mode 100644index 0000000000..c6f6d9ef8dBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/lease-credentials.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/lease-expiry.png b/docs/images/platform/dynamic-secrets/ssh/lease-expiry.pngnew file mode 100644index 0000000000..3e4ad64e09Binary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/lease-expiry.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/secret-overview-dashboard.png b/docs/images/platform/dynamic-secrets/ssh/secret-overview-dashboard.pngnew file mode 100644index 0000000000..f786843b79Binary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/secret-overview-dashboard.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/select-ssh-provider.png b/docs/images/platform/dynamic-secrets/ssh/select-ssh-provider.pngnew file mode 100644index 0000000000..75e8debde9Binary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/select-ssh-provider.png differdiff --git a/docs/images/platform/dynamic-secrets/ssh/ssh-configuration-form.png b/docs/images/platform/dynamic-secrets/ssh/ssh-configuration-form.pngnew file mode 100644index 0000000000..0e7242743aBinary files /dev/null and b/docs/images/platform/dynamic-secrets/ssh/ssh-configuration-form.png differdiff --git a/frontend/src/hooks/api/dynamicSecret/index.ts b/frontend/src/hooks/api/dynamicSecret/index.tsindex 3d6e403bc4..b56e1f01e6 100644--- a/frontend/src/hooks/api/dynamicSecret/index.ts+++ b/frontend/src/hooks/api/dynamicSecret/index.ts@@ -2,5 +2,6 @@ export { useCreateDynamicSecret, useDeleteDynamicSecret, useUpdateDynamicSecretexport {useGetDynamicSecretDetails,useGetDynamicSecrets,- useGetDynamicSecretsOfAllEnv+ useGetDynamicSecretsOfAllEnv,+ useGetSshCaPublicKey} from "./queries";diff --git a/frontend/src/hooks/api/dynamicSecret/queries.ts b/frontend/src/hooks/api/dynamicSecret/queries.tsindex 860e8917a0..75a00bfade 100644--- a/frontend/src/hooks/api/dynamicSecret/queries.ts+++ b/frontend/src/hooks/api/dynamicSecret/queries.ts@@ -18,7 +18,9 @@ export const dynamicSecretKeys = {}: Pick<TListDynamicSecretDTO, "path" | "environmentSlug" | "projectSlug">) =>[{ projectSlug, environmentSlug, path }, "dynamic-secrets"] as const,details: ({ path, environmentSlug, projectSlug, name }: TDetailsDynamicSecretDTO) =>- [{ projectSlug, path, environmentSlug, name }, "dynamic-secret-details"] as const+ [{ projectSlug, path, environmentSlug, name }, "dynamic-secret-details"] as const,+ sshCaPublicKey: (dynamicSecretId: string) =>+ [{ dynamicSecretId }, "dynamic-secret-ssh-ca-public-key"] as const};export const useGetDynamicSecrets = ({@@ -152,3 +154,22 @@ export const useGetDynamicSecretsOfAllEnv = ({return { dynamicSecrets, isDynamicSecretPresentInEnv, dynamicSecretNames };};++export const useGetSshCaPublicKey = ({+ dynamicSecretId,+ enabled = true+}: {+ dynamicSecretId: string;+ enabled?: boolean;+}) => {+ return useQuery({+ queryKey: dynamicSecretKeys.sshCaPublicKey(dynamicSecretId),+ enabled: Boolean(dynamicSecretId) && enabled,+ queryFn: async () => {+ const { data } = await apiRequest.get<{ caPublicKey: string }>(+ `/api/v1/dynamic-secrets/ssh-ca-public-key/${dynamicSecretId}`+ );+ return data.caPublicKey;+ }+ });+};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SshInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SshInputForm.tsxindex 80cb8080b8..437838e827 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SshInputForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SshInputForm.tsx@@ -3,6 +3,7 @@ import { Controller, useForm } from "react-hook-form";import { faCopy } from "@fortawesome/free-regular-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";+import { EyeIcon, EyeOffIcon } from "lucide-react";import ms from "ms";import { z } from "zod";@@ -20,7 +21,7 @@ import {SelectItem,Tag} from "@app/components/v2";-import { useCreateDynamicSecret } from "@app/hooks/api";+import { useCreateDynamicSecret, useGetSshCaPublicKey } from "@app/hooks/api";import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";import { getAuthToken } from "@app/hooks/api/reactQuery";import { SshCertKeyAlgorithm, sshCertKeyAlgorithms } from "@app/hooks/api/sshCa/constants";@@ -102,6 +103,12 @@ export const SshInputForm = ({const [showSetupModal, setShowSetupModal] = useState(false);const [createdDynamicSecretId, setCreatedDynamicSecretId] = useState<string | null>(null);const [principalInput, setPrincipalInput] = useState("");+ const [isPublicKeyVisible, setIsPublicKeyVisible] = useState(false);++ const { data: caPublicKey } = useGetSshCaPublicKey({+ dynamicSecretId: createdDynamicSecretId || "",+ enabled: showSetupModal && !!createdDynamicSecretId+ });const createDynamicSecret = useCreateDynamicSecret();@@ -369,6 +376,48 @@ export const SshInputForm = ({<span>- Configure SSH to trust certificate-based authentication</span><span>- Restart the SSH service</span></div>+ <span className="mt-4 text-sm text-muted">+ Or, copy the CA public key to install it manually:+ </span>+ <div className="mt-2 flex items-center gap-1">+ <Input+ type={isPublicKeyVisible ? "text" : "password"}+ value={caPublicKey || ""}+ isDisabled+ />+ <IconButton+ ariaLabel="toggle visibility"+ variant="plain"+ colorSchema="secondary"+ size="sm"+ onClick={() => setIsPublicKeyVisible((v) => !v)}+ className="size-8 shrink-0"+ >+ {isPublicKeyVisible ? (+ <EyeOffIcon className="size-4 text-label" />+ ) : (+ <EyeIcon className="size-4 text-label" />+ )}+ </IconButton>+ <IconButton+ ariaLabel="copy"+ variant="plain"+ colorSchema="secondary"+ size="sm"+ onClick={() => {+ if (caPublicKey) {+ navigator.clipboard.writeText(caPublicKey);+ createNotification({+ text: "CA public key copied to clipboard",+ type: "info"+ });+ }+ }}+ className="size-8 shrink-0"+ >+ <FontAwesomeIcon icon={faCopy} className="text-label" />+ </IconButton>+ </div></div><div className="mt-6 flex justify-end"><Buttondiff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSshForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSshForm.tsxindex fd49d976b6..d3bbf000d4 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSshForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSshForm.tsx@@ -3,7 +3,7 @@ import { Controller, useForm } from "react-hook-form";import { faCopy } from "@fortawesome/free-regular-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";-import { ChevronDownIcon, ShieldIcon } from "lucide-react";+import { ChevronDownIcon, EyeIcon, EyeOffIcon, ShieldIcon } from "lucide-react";import ms from "ms";import { twMerge } from "tailwind-merge";import { z } from "zod";@@ -19,7 +19,7 @@ import {SelectItem,Tag} from "@app/components/v2";-import { useUpdateDynamicSecret } from "@app/hooks/api";+import { useGetSshCaPublicKey, useUpdateDynamicSecret } from "@app/hooks/api";import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";import { getAuthToken } from "@app/hooks/api/reactQuery";import { SshCertKeyAlgorithm, sshCertKeyAlgorithms } from "@app/hooks/api/sshCa/constants";@@ -102,6 +102,12 @@ export const EditDynamicSecretSshForm = ({const [principalInput, setPrincipalInput] = useState("");const [cmdOpen, setCmdOpen] = useState(false);+ const [isPublicKeyVisible, setIsPublicKeyVisible] = useState(false);++ const { data: caPublicKey } = useGetSshCaPublicKey({+ dynamicSecretId: dynamicSecret.id,+ enabled: cmdOpen+ });const updateDynamicSecret = useUpdateDynamicSecret();@@ -286,7 +292,10 @@ export const EditDynamicSecretSshForm = ({<buttontype="button"- onClick={() => setCmdOpen(!cmdOpen)}+ onClick={() => {+ if (cmdOpen) setIsPublicKeyVisible(false);+ setCmdOpen(!cmdOpen);+ }}className="flex w-full cursor-pointer flex-col rounded-md border border-border bg-container p-3 text-sm hover:bg-container-hover"><div className="flex gap-2.5">@@ -344,6 +353,52 @@ export const EditDynamicSecretSshForm = ({<span>- Configure SSH to trust certificate-based authentication</span><span>- Restart the SSH service</span></div>+ <span className="mt-4 text-sm text-muted">+ Or, copy the CA public key to install it manually:+ </span>+ <div className="mt-1 flex items-center gap-1">+ <Input+ type={isPublicKeyVisible ? "text" : "password"}+ value={caPublicKey || ""}+ isDisabled+ />+ <IconButton+ ariaLabel="toggle visibility"+ variant="plain"+ colorSchema="secondary"+ size="sm"+ onClick={(e) => {+ e.stopPropagation();+ setIsPublicKeyVisible((v) => !v);+ }}+ className="size-8 shrink-0"+ >+ {isPublicKeyVisible ? (+ <EyeOffIcon className="size-4 text-label" />+ ) : (+ <EyeIcon className="size-4 text-label" />+ )}+ </IconButton>+ <IconButton+ ariaLabel="copy"+ variant="plain"+ colorSchema="secondary"+ size="sm"+ onClick={(e) => {+ e.stopPropagation();+ if (caPublicKey) {+ navigator.clipboard.writeText(caPublicKey);+ createNotification({+ text: "CA public key copied to clipboard",+ type: "info"+ });+ }+ }}+ className="size-8 shrink-0"+ >+ <FontAwesomeIcon icon={faCopy} className="text-label" />+ </IconButton>+ </div></div></div></div>