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
feat: add unexportable flag to KMS keys
bernie-gd568093e819a
diff --git a/backend/src/db/migrations/20260612000000_add-is-exportable-to-kms-keys.ts b/backend/src/db/migrations/20260612000000_add-is-exportable-to-kms-keys.tsnew file mode 100644index 0000000000..eb068b05ce--- /dev/null+++ b/backend/src/db/migrations/20260612000000_add-is-exportable-to-kms-keys.ts@@ -0,0 +1,23 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ const hasIsExportableColumn = await knex.schema.hasColumn(TableName.KmsKey, "isExportable");++ if (!hasIsExportableColumn) {+ await knex.schema.alterTable(TableName.KmsKey, (t) => {+ t.boolean("isExportable").notNullable().defaultTo(true);+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ const hasIsExportableColumn = await knex.schema.hasColumn(TableName.KmsKey, "isExportable");++ if (hasIsExportableColumn) {+ await knex.schema.alterTable(TableName.KmsKey, (t) => {+ t.dropColumn("isExportable");+ });+ }+}diff --git a/backend/src/db/schemas/kms-keys.ts b/backend/src/db/schemas/kms-keys.tsindex 45ff699971..6c4fd2a681 100644--- a/backend/src/db/schemas/kms-keys.ts+++ b/backend/src/db/schemas/kms-keys.ts@@ -18,7 +18,8 @@ export const KmsKeysSchema = z.object({updatedAt: z.date(),projectId: z.string().nullable().optional(),keyUsage: z.string().default("encrypt-decrypt"),- kmipMetadata: z.unknown().nullable().optional()+ kmipMetadata: z.unknown().nullable().optional(),+ isExportable: z.boolean().default(true)});export type TKmsKeys = z.infer<typeof KmsKeysSchema>;diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 01bccd72ae..fd5d9b79aa 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -4302,6 +4302,7 @@ interface CreateCmekEvent {name: string;description?: string;encryptionAlgorithm: SymmetricKeyAlgorithm | AsymmetricKeyAlgorithm;+ isExportable?: boolean;};}diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 8492e44a37..338deee33f 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2482,7 +2482,9 @@ export const KMS = {name: "The name of the key to be created. Must be slug-friendly.",description: "An optional description of the key.",encryptionAlgorithm: "The algorithm to use when performing cryptographic operations with the key.",- type: "The type of key to be created, either encrypt-decrypt or sign-verify, based on your intended use for the key."+ type: "The type of key to be created, either encrypt-decrypt or sign-verify, based on your intended use for the key.",+ isExportable:+ "Whether the raw key material can be exported after creation. When set to false, the key can never be exported regardless of permissions. This cannot be changed after creation."},UPDATE_KEY: {keyId: "The ID of the key to be updated.",diff --git a/backend/src/server/routes/v1/cmek-router.ts b/backend/src/server/routes/v1/cmek-router.tsindex fc88317bed..8dd69d8741 100644--- a/backend/src/server/routes/v1/cmek-router.ts+++ b/backend/src/server/routes/v1/cmek-router.ts@@ -80,7 +80,8 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {.enum(AllowedEncryptionKeyAlgorithms).optional().default(SymmetricKeyAlgorithm.AES_GCM_256)- .describe(KMS.CREATE_KEY.encryptionAlgorithm)+ .describe(KMS.CREATE_KEY.encryptionAlgorithm),+ isExportable: z.boolean().optional().default(true).describe(KMS.CREATE_KEY.isExportable)}).superRefine((data, ctx) => {if (@@ -115,7 +116,7 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {const {- body: { projectId, name, description, encryptionAlgorithm, keyUsage },+ body: { projectId, name, description, encryptionAlgorithm, keyUsage, isExportable },permission} = req;@@ -126,7 +127,8 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {name,description,encryptionAlgorithm: encryptionAlgorithm as TCmekKeyEncryptionAlgorithm,- keyUsage+ keyUsage,+ isExportable},permission);@@ -140,7 +142,8 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {keyId: cmek.id,name,description,- encryptionAlgorithm: encryptionAlgorithm as TCmekKeyEncryptionAlgorithm+ encryptionAlgorithm: encryptionAlgorithm as TCmekKeyEncryptionAlgorithm,+ isExportable}}});@@ -576,7 +579,8 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {name: keyNameSchema,keyUsage: z.nativeEnum(KmsKeyUsage),encryptionAlgorithm: z.enum(AllowedEncryptionKeyAlgorithms),- keyMaterial: z.string().min(1)+ keyMaterial: z.string().min(1),+ isExportable: z.boolean().optional().default(true).describe(KMS.CREATE_KEY.isExportable)}).superRefine((data, ctx) => {if (@@ -630,7 +634,8 @@ export const registerCmekRouter = async (server: FastifyZodProvider) => {name: k.name,algorithm: k.encryptionAlgorithm as TCmekKeyEncryptionAlgorithm,keyUsage: k.keyUsage,- keyMaterial: k.keyMaterial+ keyMaterial: k.keyMaterial,+ isExportable: k.isExportable}))},permissiondiff --git a/backend/src/services/cmek/cmek-service.ts b/backend/src/services/cmek/cmek-service.tsindex 48a2b42640..0351e79404 100644--- a/backend/src/services/cmek/cmek-service.ts+++ b/backend/src/services/cmek/cmek-service.ts@@ -314,6 +314,7 @@ export const cmekServiceFactory = ({if (!key) throw new NotFoundError({ message: `Key with ID "${keyId}" not found` });if (!key.projectId || key.isReserved) throw new BadRequestError({ message: "Key is not customer managed" });if (key.isDisabled) throw new BadRequestError({ message: "Key is disabled" });+ if (!key.isExportable) throw new BadRequestError({ message: "Key is not exportable" });const { permission } = await permissionService.getProjectPermission({actor: actor.type,@@ -357,6 +358,7 @@ export const cmekServiceFactory = ({if (!key.projectId || key.isReserved)throw new BadRequestError({ message: `Key with ID "${key.id}" is not customer managed` });if (key.isDisabled) throw new BadRequestError({ message: `Key with ID "${key.id}" is disabled` });+ if (!key.isExportable) throw new BadRequestError({ message: `Key with ID "${key.id}" is not exportable` });projectIds.add(key.projectId);}@@ -569,6 +571,7 @@ export const cmekServiceFactory = ({algorithm: entry.algorithm,name: entry.name,isReserved: false,+ isExportable: entry.isExportable,projectId,orgId: actor.orgId,keyUsage: entry.keyUsagediff --git a/backend/src/services/cmek/cmek-types.ts b/backend/src/services/cmek/cmek-types.tsindex ff5c7b16f6..185aa0213f 100644--- a/backend/src/services/cmek/cmek-types.ts+++ b/backend/src/services/cmek/cmek-types.ts@@ -13,6 +13,7 @@ export type TCreateCmekDTO = {description?: string;encryptionAlgorithm: TCmekKeyEncryptionAlgorithm;keyUsage: KmsKeyUsage;+ isExportable?: boolean;};export type TUpdabteCmekByIdDTO = {@@ -66,6 +67,7 @@ export type TCmekBulkImportKeyEntry = {algorithm: TCmekKeyEncryptionAlgorithm;keyUsage: KmsKeyUsage;keyMaterial: string;+ isExportable?: boolean;};export type TCmekBulkImportKeysDTO = {diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.tsindex fec6c1b0e0..ab309aff95 100644--- a/backend/src/services/kms/kms-service.ts+++ b/backend/src/services/kms/kms-service.ts@@ -95,6 +95,7 @@ export const kmsServiceFactory = ({const generateKmsKey = async ({orgId,isReserved = true,+ isExportable = true,tx,name,projectId,@@ -136,6 +137,7 @@ export const kmsServiceFactory = ({keyUsage,orgId,isReserved,+ isExportable,projectId,description},@@ -381,6 +383,12 @@ export const kmsServiceFactory = ({});}+ if (!kmsDoc.isExportable) {+ throw new BadRequestError({+ message: "Cannot get key material for non-exportable key"+ });+ }+const keyCipher = symmetricCipherService(SymmetricKeyAlgorithm.AES_GCM_256);const kmsKey = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY);@@ -397,6 +405,9 @@ export const kmsServiceFactory = ({if (kmsDoc.externalKms) {throw new BadRequestError({ message: `Cannot get key material for external key [kmsId=${kmsDoc.id}]` });}+ if (!kmsDoc.isExportable) {+ throw new BadRequestError({ message: `Cannot get key material for non-exportable key [kmsId=${kmsDoc.id}]` });+ }const keyCipher = symmetricCipherService(SymmetricKeyAlgorithm.AES_GCM_256);const keyMaterial = keyCipher.decrypt(kmsDoc.internalKms?.encryptedKey as Buffer, ROOT_ENCRYPTION_KEY);@@ -406,7 +417,17 @@ export const kmsServiceFactory = ({};const importKeyMaterial = async (- { key, algorithm, name, isReserved, projectId, orgId, keyUsage, kmipMetadata }: TImportKeyMaterialDTO,+ {+ key,+ algorithm,+ name,+ isReserved,+ isExportable = true,+ projectId,+ orgId,+ keyUsage,+ kmipMetadata+ }: TImportKeyMaterialDTO,tx?: Knex) => {verifyKeyTypeAndAlgorithm(keyUsage, algorithm);@@ -475,6 +496,7 @@ export const kmsServiceFactory = ({keyUsage,orgId,isReserved,+ isExportable,projectId,kmipMetadata},diff --git a/backend/src/services/kms/kms-types.ts b/backend/src/services/kms/kms-types.tsindex 27c6b45726..f59990d7d7 100644--- a/backend/src/services/kms/kms-types.ts+++ b/backend/src/services/kms/kms-types.ts@@ -34,6 +34,7 @@ export type TGenerateKMSDTO = {encryptionAlgorithm?: SymmetricKeyAlgorithm | AsymmetricKeyAlgorithm;keyUsage?: KmsKeyUsage;isReserved?: boolean;+ isExportable?: boolean;name?: string;description?: string;tx?: Knex;@@ -100,6 +101,7 @@ export type TImportKeyMaterialDTO = {algorithm: SymmetricKeyAlgorithm | AsymmetricKeyAlgorithm;name?: string;isReserved: boolean;+ isExportable?: boolean;projectId: string;orgId: string;keyUsage: KmsKeyUsage;diff --git a/docs/documentation/platform/kms/overview.mdx b/docs/documentation/platform/kms/overview.mdxindex 98106f4543..c98e700239 100644--- a/docs/documentation/platform/kms/overview.mdx+++ b/docs/documentation/platform/kms/overview.mdx@@ -49,6 +49,7 @@ In the following steps, we explore how to generate a key and use it to encrypt d- Key Usage: The type of key to create (e.g `Encrypt/Decrypt` for encryption, and `Sign/Verify` for signing).- Algorithm: The encryption algorithm associated with the key (e.g. `AES-GCM-256`).- Description: An optional description of what the intended usage is for the key.+ - Allow Export: Whether the raw key material can be exported later. When disabled, the key material can never leave Infisical, regardless of permissions. This cannot be changed after the key is created.</Step>@@ -402,11 +403,17 @@ The exported file is a JSON array where each entry is one of the following shapeThe exported file contains sensitive cryptographic key material. Store it securely and do not share it.</Warning>+<Note>+ Keys created with **Allow Export** disabled are non-exportable. They cannot be selected for export,+ and any export request for them (including over KMIP) is rejected, regardless of the caller's permissions.+</Note>+### Bulk Import1. Navigate to **Project > Key Management**.2. In the top-right of the keys table, click the dropdown arrow next to **Add Key** and select **Import Keys**.3. Upload a `.json` file matching the export format described above (drag and drop, or click to browse).+ Each entry may also include an optional `"isExportable": false` field to import the key as non-exportable.4. A preview of the keys to be imported is shown, along with any validation errors.diff --git a/frontend/src/hooks/api/cmeks/types.ts b/frontend/src/hooks/api/cmeks/types.tsindex a1063db64b..b0c6f3692a 100644--- a/frontend/src/hooks/api/cmeks/types.ts+++ b/frontend/src/hooks/api/cmeks/types.ts@@ -16,6 +16,7 @@ export type TCmek = {projectId: string;isDisabled: boolean;isReserved: boolean;+ isExportable: boolean;orgId: string;version: number;createdAt: string;@@ -26,6 +27,7 @@ type ProjectRef = { projectId: string };type KeyRef = { keyId: string };export type TCreateCmek = Pick<TCmek, "name" | "description" | "encryptionAlgorithm" | "keyUsage"> &+ Partial<Pick<TCmek, "isExportable">> &ProjectRef;export type TUpdateCmek = KeyRef &Partial<Pick<TCmek, "name" | "description" | "isDisabled">> &@@ -114,6 +116,7 @@ export type TCmekBulkImportKeyEntry = {keyUsage: KmsKeyUsage;encryptionAlgorithm: AsymmetricKeyAlgorithm | SymmetricKeyAlgorithm;keyMaterial: string;+ isExportable?: boolean;};export type TCmekBulkImportKeysDTO = {diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekBulkImportModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekBulkImportModal.tsxindex 2422fba155..4102cb4d08 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekBulkImportModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekBulkImportModal.tsx@@ -49,6 +49,7 @@ type ParsedKey = {keyMaterial?: string;privateKey?: string;publicKey?: string;+ isExportable?: boolean;};type ValidationError = {@@ -110,6 +111,9 @@ const validateEntry = (entry: unknown, index: number): ValidationError | null =>if (!e.algorithm || typeof e.algorithm !== "string") {return { index, message: '"algorithm" is required' };}+ if (e.isExportable !== undefined && typeof e.isExportable !== "boolean") {+ return { index, message: '"isExportable" must be a boolean' };+ }if (e.keyType === "encrypt-decrypt") {const validSymmetric = Object.values(SymmetricKeyAlgorithm) as string[];if (!validSymmetric.includes(e.algorithm)) {@@ -239,7 +243,8 @@ export const CmekBulkImportModal = ({ isOpen, onOpenChange, projectId }: Props)name: k.name,keyUsage: k.keyType as KmsKeyUsage,encryptionAlgorithm: k.algorithm as never,- keyMaterial: k.keyType === "sign-verify" ? (k.privateKey ?? "") : (k.keyMaterial ?? "")+ keyMaterial: k.keyType === "sign-verify" ? (k.privateKey ?? "") : (k.keyMaterial ?? ""),+ isExportable: k.isExportable}))});if (errors.length === 0) {diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekExportKeyModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekExportKeyModal.tsxindex 0af79de4d0..a98d8fd889 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekExportKeyModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekExportKeyModal.tsx@@ -36,11 +36,13 @@ const ExportKeyForm = ({ cmek }: FormProps) => {ProjectPermissionSub.Cmek);+ const canExportKeyMaterial = canExportPrivateKey && cmek.isExportable;+const { data: privateKeyData, isPending: isPrivateKeyPending } = useGetCmekPrivateKey(cmek?.id ?? "",{- // Only fetch private key if user has ExportPrivateKey permission- enabled: Boolean(cmek?.id) && canExportPrivateKey+ // Only fetch private key if user has ExportPrivateKey permission and the key allows export+ enabled: Boolean(cmek?.id) && canExportKeyMaterial});@@ -66,7 +68,7 @@ const ExportKeyForm = ({ cmek }: FormProps) => {};const isLoading =- (canExportPrivateKey && isPrivateKeyPending) ||+ (canExportKeyMaterial && isPrivateKeyPending) ||(isAsymmetricKey && canReadPublicKey && isPublicKeyPending);if (isLoading) {@@ -79,7 +81,7 @@ const ExportKeyForm = ({ cmek }: FormProps) => {return (<div>- {canExportPrivateKey && privateKeyData?.privateKey && (+ {canExportKeyMaterial && privateKeyData?.privateKey && (<><div className="mb-4 flex items-center justify-between"><h2>{isAsymmetricKey ? "Private Key (Base64)" : "Key Material (Base64)"}</h2>diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekModal.tsxindex ececf5ccee..1dae5cbc3d 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekModal.tsx@@ -12,6 +12,7 @@ import {ModalContent,Select,SelectItem,+ Switch,TextArea} from "@app/components/v2";import { Badge } from "@app/components/v3";@@ -32,7 +33,8 @@ const formSchema = z.object({name: slugSchema({ min: 1, max: 32, field: "Name" }),description: z.string().max(500).optional(),encryptionAlgorithm: z.enum(AllowedEncryptionKeyAlgorithms),- keyUsage: z.nativeEnum(KmsKeyUsage)+ keyUsage: z.nativeEnum(KmsKeyUsage),+ isExportable: z.boolean()});export type FormData = z.infer<typeof formSchema>;@@ -68,7 +70,8 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {name: cmek?.name,description: cmek?.description,encryptionAlgorithm: SymmetricKeyAlgorithm.AES_GCM_256,- keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT+ keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT,+ isExportable: cmek?.isExportable ?? true}});@@ -76,7 +79,8 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {encryptionAlgorithm,name,description,- keyUsage+ keyUsage,+ isExportable}: FormData) => {const mutation = isUpdate? updateCmek.mutateAsync({ keyId: cmek.id, projectId, name, description })@@ -85,7 +89,10 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {name,description,keyUsage,- encryptionAlgorithm: encryptionAlgorithm as AsymmetricKeyAlgorithm | SymmetricKeyAlgorithm+ encryptionAlgorithm: encryptionAlgorithm as+ | AsymmetricKeyAlgorithm+ | SymmetricKeyAlgorithm,+ isExportable});await mutation;@@ -220,6 +227,19 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {{...register("description")}/></FormControl>+ {!isUpdate && (+ <Controller+ control={control}+ name="isExportable"+ render={({ field: { onChange, value } }) => (+ <FormControl helperText="When disabled, the key material can never be exported from Infisical. This cannot be changed after the key is created.">+ <Switch id="is-exportable" isChecked={value} onCheckedChange={onChange}>+ Allow Export+ </Switch>+ </FormControl>+ )}+ />+ )}<div className="flex items-center"><ButtonclassName="mr-4"diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekTable.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekTable.tsxindex 38ef988987..f533201e0d 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekTable.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekTable.tsx@@ -152,7 +152,7 @@ export const CmekTable = () => {setSelectedKeyIds([]);}, [page]);- const selectableKeys = keys.filter((k) => !k.isDisabled);+ const selectableKeys = keys.filter((k) => !k.isDisabled && k.isExportable);const isPageSelected =selectableKeys.length > 0 && selectableKeys.every((k) => selectedKeyIds.includes(k.id));const isPageIndeterminate =@@ -464,6 +464,7 @@ export const CmekTable = () => {description,encryptionAlgorithm,isDisabled,+ isExportable,keyUsage} = cmek;const { variant, label } = getStatusBadgeProps(isDisabled);@@ -472,9 +473,10 @@ export const CmekTable = () => {const isAsymmetricKey = Object.values(AsymmetricKeyAlgorithm).includes(encryptionAlgorithm as AsymmetricKeyAlgorithm);+ // unexportable asymmetric keys can still surface their public key in the export modalconst cannotExportKey = isAsymmetricKey- ? cannotExportPrivateKey && cannotReadKey- : cannotExportPrivateKey;+ ? (cannotExportPrivateKey || !isExportable) && cannotReadKey+ : cannotExportPrivateKey || !isExportable;return (<TableRow@@ -484,7 +486,7 @@ export const CmekTable = () => {onMouseLeave={() => setCopyCipherText("")}><TableCell>- {isDisabled ? (+ {isDisabled || !isExportable ? (<Tooltip><TooltipTrigger asChild><span className="inline-flex">@@ -496,7 +498,11 @@ export const CmekTable = () => {/></span></TooltipTrigger>- <TooltipContent>Disabled keys cannot be exported</TooltipContent>+ <TooltipContent>+ {isDisabled+ ? "Disabled keys cannot be exported"+ : "This key was created as non-exportable"}+ </TooltipContent></Tooltip>) : (<Checkbox@@ -568,7 +574,21 @@ export const CmekTable = () => {</TableCell><TableCell className="uppercase">{encryptionAlgorithm}</TableCell><TableCell>- <Badge variant={variant}>{label}</Badge>+ <div className="flex items-center gap-1">+ <Badge variant={variant}>{label}</Badge>+ {!isExportable && (+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="inline-flex">+ <Badge variant="neutral">Non-Exportable</Badge>+ </span>+ </TooltipTrigger>+ <TooltipContent>+ The key material of this key can never be exported+ </TooltipContent>+ </Tooltip>+ )}+ </div></TableCell><TableCell>{version}</TableCell><TableCell>