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
SSH CA and tweaks
x0322051d27ffeda13e
diff --git a/backend/src/db/migrations/20260603030053_pam-revamp.ts b/backend/src/db/migrations/20260603030053_pam-revamp.tsindex 5c584b5258..87af54a2e8 100644--- a/backend/src/db/migrations/20260603030053_pam-revamp.ts+++ b/backend/src/db/migrations/20260603030053_pam-revamp.ts@@ -402,6 +402,10 @@ export async function up(knex: Knex): Promise<void> {t.uuid("templateId").notNullable().alter();t.binary("encryptedConnectionDetails").notNullable().alter();t.unique(["folderId", "name"]);+ // SSH CA for certificate-based auth+ t.binary("encryptedCaPrivateKey").nullable();+ t.text("caPublicKey").nullable();+ t.string("caKeyAlgorithm").nullable();// Make retained old columns nullable so new accounts can be created without themt.string("projectId", 36).nullable().alter();t.uuid("resourceId").nullable().alter();diff --git a/backend/src/db/schemas/pam-accounts.ts b/backend/src/db/schemas/pam-accounts.tsindex 1a8ae71a19..9f52974121 100644--- a/backend/src/db/schemas/pam-accounts.ts+++ b/backend/src/db/schemas/pam-accounts.ts@@ -32,7 +32,10 @@ export const PamAccountsSchema = z.object({encryptedInternalMetadata: zodBuffer.nullable().optional(),gatewayId: z.string().uuid().nullable().optional(),gatewayPoolId: z.string().uuid().nullable().optional(),- recordingConnectionId: z.string().uuid().nullable().optional()+ recordingConnectionId: z.string().uuid().nullable().optional(),+ encryptedCaPrivateKey: zodBuffer.nullable().optional(),+ caPublicKey: z.string().nullable().optional(),+ caKeyAlgorithm: z.string().nullable().optional()});export type TPamAccounts = z.infer<typeof PamAccountsSchema>;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.tsindex c8b9e85d5c..ff1f872e6b 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@@ -317,6 +317,152 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {}});+ server.route({+ method: "POST",+ url: "/:accountId/ssh-ca",+ schema: {+ operationId: "getOrCreatePamSshCa",+ params: z.object({ accountId: z.string().uuid() }),+ response: {+ 200: z.object({ publicKey: z.string() })+ }+ },+ config: { rateLimit: writeLimit },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const result = await server.services.pamAccount.getOrCreateSshCa({+ accountId: req.params.accountId,+ projectId: req.internalPamProjectId,+ actorId: req.permission.id,+ actor: req.permission.type,+ actorOrgId: req.permission.orgId,+ actorAuthMethod: req.permission.authMethod+ });++ 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!+ }+ }+ });+ }++ return { publicKey: result.publicKey };+ }+ });++ server.route({+ method: "GET",+ url: "/:accountId/ssh-ca-public-key",+ schema: {+ operationId: "getPamSshCaPublicKey",+ params: z.object({ accountId: z.string().uuid() }),+ response: {+ 200: z.object({ publicKey: z.string() })+ }+ },+ config: { rateLimit: readLimit },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ return server.services.pamAccount.getSshCaPublicKey(req.params.accountId);+ }+ });++ server.route({+ method: "GET",+ url: "/:accountId/ssh-ca-setup",+ schema: {+ operationId: "getPamSshCaSetupScript",+ params: z.object({ accountId: z.string().uuid() }),+ response: {+ 200: z.string()+ }+ },+ config: { rateLimit: readLimit },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req, reply) => {+ const { publicKey: caPublicKey } = await server.services.pamAccount.getSshCaPublicKey(req.params.accountId);++ const setupScript = `#!/bin/bash+set -e++CA_PUBLIC_KEY="${caPublicKey}"+CA_FILE="/etc/ssh/infisical_ca.pub"+SSHD_CONFIG="/etc/ssh/sshd_config"++echo "==> Infisical SSH CA Setup"+echo ""++if [ "$(id -u)" -ne 0 ]; then+ echo "Error: This script must be run as root (use sudo)"+ exit 1+fi++echo "==> Writing CA public key to \${CA_FILE}..."+echo "\${CA_PUBLIC_KEY}" > "\${CA_FILE}"+chmod 644 "\${CA_FILE}"+echo " Done."++if grep -q "^TrustedUserCAKeys" "\${SSHD_CONFIG}"; then+ EXISTING_CA_FILE=$(grep "^TrustedUserCAKeys" "\${SSHD_CONFIG}" | awk '{print $2}')+ if [ "\${EXISTING_CA_FILE}" = "\${CA_FILE}" ]; then+ echo "==> TrustedUserCAKeys already configured for \${CA_FILE}"+ else+ echo "Warning: TrustedUserCAKeys is already set to \${EXISTING_CA_FILE}"+ echo " You may need to manually update sshd_config to use \${CA_FILE}"+ echo " or combine multiple CA keys into a single file."+ fi+else+ echo "==> Adding TrustedUserCAKeys to \${SSHD_CONFIG}..."+ echo "" >> "\${SSHD_CONFIG}"+ echo "# Infisical SSH CA - Added by setup script" >> "\${SSHD_CONFIG}"+ echo "TrustedUserCAKeys \${CA_FILE}" >> "\${SSHD_CONFIG}"+ echo " Done."+fi++echo "==> Validating SSH configuration..."+if sshd -t; then+ echo " Configuration is valid."+else+ echo "Error: SSH configuration is invalid. Please check \${SSHD_CONFIG}"+ exit 1+fi++echo "==> Restarting SSH service..."+if command -v systemctl &> /dev/null; then+ if systemctl cat sshd.service &>/dev/null; then+ systemctl restart sshd+ elif systemctl cat ssh.service &>/dev/null; then+ systemctl restart ssh+ else+ echo "Warning: Could not find SSH service. Please restart it manually."+ fi+elif command -v service &> /dev/null; then+ service sshd restart 2>/dev/null || service ssh restart+else+ echo "Warning: Could not detect init system. Please restart sshd manually."+fi+echo " Done."++echo ""+echo "==> Setup complete!"+echo ""+echo "Your SSH server is now configured to trust certificates signed by the Infisical CA."+echo ""+`;++ void reply.header("Content-Type", "text/plain; charset=utf-8");+ return setupScript;+ }+ });+await Promise.all((Object.entries(ACCOUNT_TYPE_CONFIGS) as [TSupportedAccountType, TSupportedConfigValue][]).map(([accountType, config]) =>diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 251c2160af..31222bad8b 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -700,6 +700,7 @@ export enum EventType {PAM_ACCOUNT_CREATE = "pam-account-create",PAM_ACCOUNT_UPDATE = "pam-account-update",PAM_ACCOUNT_DELETE = "pam-account-delete",+ PAM_ACCOUNT_SSH_CA_CREATE = "pam-account-ssh-ca-create",PAM_WEB_ACCESS_SESSION_TICKET_CREATED = "pam-web-access-session-ticket-created",APPROVAL_POLICY_CREATE = "approval-policy-create",APPROVAL_POLICY_UPDATE = "approval-policy-update",@@ -5892,6 +5893,14 @@ interface PamAccountDeleteEvent {};}+interface PamAccountSshCaCreateEvent {+ type: EventType.PAM_ACCOUNT_SSH_CA_CREATE;+ metadata: {+ accountId: string;+ keyAlgorithm: string;+ };+}+interface UpdateCertificateRenewalConfigEvent {type: EventType.UPDATE_CERTIFICATE_RENEWAL_CONFIG;metadata: {@@ -7413,6 +7422,7 @@ export type Event =| PamAccountCreateEvent| PamAccountUpdateEvent| PamAccountDeleteEvent+ | PamAccountSshCaCreateEvent| UpdateCertificateRenewalConfigEvent| UpdateCertificateMetadataEvent| DisableCertificateRenewalConfigEventdiff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 5d3d714412..6e021dfde5 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -9,6 +9,8 @@ import {ResourcePermissionPamResourceActions,ResourcePermissionSub} from "@app/ee/services/permission/resource-permission";+import { createSshKeyPair } from "@app/ee/services/ssh/ssh-certificate-authority-fns";+import { SshCertKeyAlgorithm } from "@app/ee/services/ssh-certificate/ssh-certificate-types";import { DatabaseErrorCode } from "@app/lib/error-codes";import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { TKmsServiceFactory } from "@app/services/kms/kms-service";@@ -407,5 +409,43 @@ export const pamAccountServiceFactory = ({}));};- return { list, listAccessible, getById, create, update, deleteAccount };+ const getOrCreateSshCa = async ({ accountId, projectId, ...ctx }: TGetPamAccountDTO & TActorContext) => {+ const account = await pamAccountDAL.findByIdWithDetails(accountId);+ if (!account || account.projectId !== projectId) {+ throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });+ }++ await checkAccount(accountId, account.folderId, projectId, ResourcePermissionPamResourceActions.EditAccounts, ctx);++ if (account.caPublicKey) {+ return { publicKey: account.caPublicKey, created: false };+ }++ const keyAlgorithm = SshCertKeyAlgorithm.ED25519;+ const { publicKey, privateKey } = await createSshKeyPair(keyAlgorithm);++ const { encryptor } = await getProjectCipher(projectId);+ const encryptedCaPrivateKey = encryptor({ plainText: Buffer.from(privateKey) }).cipherTextBlob;++ await pamAccountDAL.updateById(accountId, {+ encryptedCaPrivateKey,+ caPublicKey: publicKey,+ caKeyAlgorithm: keyAlgorithm+ });++ return { publicKey, created: true, keyAlgorithm };+ };++ const getSshCaPublicKey = async (accountId: string) => {+ const account = await pamAccountDAL.findByIdWithDetails(accountId);+ if (!account) {+ throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });+ }+ if (!account.caPublicKey) {+ throw new BadRequestError({ message: "SSH CA has not been configured for this account" });+ }+ return { publicKey: account.caPublicKey };+ };++ return { list, listAccessible, getById, create, update, deleteAccount, getOrCreateSshCa, getSshCaPublicKey };};diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.tsindex 7cf8703fcd..cf919af783 100644--- a/backend/src/ee/services/pam-session/pam-session-service.ts+++ b/backend/src/ee/services/pam-session/pam-session-service.ts@@ -1,4 +1,7 @@import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";+import { createSshCert, createSshKeyPair } from "@app/ee/services/ssh/ssh-certificate-authority-fns";+import { SshCertType } from "@app/ee/services/ssh/ssh-certificate-authority-types";+import { SshCertKeyAlgorithm } from "@app/ee/services/ssh-certificate/ssh-certificate-types";import { BadRequestError, NotFoundError } from "@app/lib/errors";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { KmsDataKey } from "@app/services/kms/kms-types";@@ -98,6 +101,32 @@ export const pamSessionServiceFactory = ({const connectionDetails = await decrypt(session.projectId, account.encryptedConnectionDetails);const credentials = await decrypt(session.projectId, account.encryptedCredentials);+ if (credentials.authMethod === "certificate" && account.encryptedCaPrivateKey) {+ const { decryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId: session.projectId+ });+ const caPrivateKey = decryptor({+ cipherTextBlob: account.encryptedCaPrivateKey+ }).toString("utf-8");++ const keyAlgorithm = (account.caKeyAlgorithm as SshCertKeyAlgorithm) || SshCertKeyAlgorithm.ED25519;+ const { publicKey: clientPublicKey, privateKey: clientPrivateKey } = await createSshKeyPair(keyAlgorithm);++ const username = credentials.username as string;+ const { signedPublicKey } = await createSshCert({+ caPrivateKey,+ clientPublicKey,+ keyId: `pam-session-${session.id}`,+ principals: [username],+ requestedTtl: "8h",+ certType: SshCertType.USER+ });++ credentials.privateKey = clientPrivateKey;+ credentials.certificate = signedPublicKey;+ }+const sessionStarted = session.status === PamSessionStatus.Starting;let recording: {diff --git a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsxindex b682e64603..29bba6bf2e 100644--- a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx+++ b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx@@ -113,6 +113,10 @@ const PageContent = () => {);}+ if (account.accountType === PamAccountType.SSH) {+ return <TerminalContent account={account} orgId={orgId!} />;+ }+return (<SessionAccessGate account={account}>{({ reason }) => {