diff --git a/backend/src/db/migrations/20251010111410_add-kmip-metadata.ts b/backend/src/db/migrations/20251010111410_add-kmip-metadata.ts new file mode 100644 index 000000000..2875cc0ad --- /dev/null +++ b/backend/src/db/migrations/20251010111410_add-kmip-metadata.ts @@ -0,0 +1,19 @@ +import { Knex } from "knex"; + +import { TableName } from "../schemas"; + +export async function up(knex: Knex): Promise { + if (!(await knex.schema.hasColumn(TableName.KmsKey, "kmipMetadata"))) { + await knex.schema.alterTable(TableName.KmsKey, (t) => { + t.jsonb("kmipMetadata"); + }); + } +} + +export async function down(knex: Knex): Promise { + if (await knex.schema.hasColumn(TableName.KmsKey, "kmipMetadata")) { + await knex.schema.alterTable(TableName.KmsKey, (t) => { + t.dropColumn("kmipMetadata"); + }); + } +} diff --git a/backend/src/db/schemas/kms-keys.ts b/backend/src/db/schemas/kms-keys.ts index ccb779d57..45ff69997 100644 --- a/backend/src/db/schemas/kms-keys.ts +++ b/backend/src/db/schemas/kms-keys.ts @@ -17,7 +17,8 @@ export const KmsKeysSchema = z.object({ createdAt: z.date(), updatedAt: z.date(), projectId: z.string().nullable().optional(), - keyUsage: z.string().default("encrypt-decrypt") + keyUsage: z.string().default("encrypt-decrypt"), + kmipMetadata: z.unknown().nullable().optional() }); export type TKmsKeys = z.infer; diff --git a/backend/src/ee/routes/v1/kmip-spec-router.ts b/backend/src/ee/routes/v1/kmip-spec-router.ts index 9a1f4902c..c7db12de9 100644 --- a/backend/src/ee/routes/v1/kmip-spec-router.ts +++ b/backend/src/ee/routes/v1/kmip-spec-router.ts @@ -128,7 +128,8 @@ export const registerKmipSpecRouter = async (server: FastifyZodProvider) => { 200: z.object({ id: z.string(), value: z.string(), - algorithm: z.string() + algorithm: z.string(), + kmipMetadata: z.record(z.any()).optional() }) } }, @@ -433,7 +434,8 @@ export const registerKmipSpecRouter = async (server: FastifyZodProvider) => { body: z.object({ key: z.string(), name: z.string(), - algorithm: z.nativeEnum(SymmetricKeyAlgorithm) + algorithm: z.nativeEnum(SymmetricKeyAlgorithm), + kmipMetadata: z.record(z.any()).optional() }), response: { 200: z.object({ diff --git a/backend/src/ee/services/kmip/kmip-operation-service.ts b/backend/src/ee/services/kmip/kmip-operation-service.ts index 2808108df..27f59a99f 100644 --- a/backend/src/ee/services/kmip/kmip-operation-service.ts +++ b/backend/src/ee/services/kmip/kmip-operation-service.ts @@ -183,7 +183,8 @@ export const kmipOperationServiceFactory = ({ algorithm: completeKeyDetails.internalKms.encryptionAlgorithm, isActive: !key.isDisabled, createdAt: key.createdAt, - updatedAt: key.updatedAt + updatedAt: key.updatedAt, + kmipMetadata: key.kmipMetadata as Record }; }; @@ -373,7 +374,8 @@ export const kmipOperationServiceFactory = ({ actor, actorId, actorAuthMethod, - actorOrgId + actorOrgId, + kmipMetadata }: TKmipRegisterDTO) => { const { permission } = await permissionService.getOrgPermission( actor, @@ -405,7 +407,8 @@ export const kmipOperationServiceFactory = ({ isReserved: false, projectId, keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT, - orgId: project.orgId + orgId: project.orgId, + kmipMetadata }); return kmsKey; diff --git a/backend/src/ee/services/kmip/kmip-types.ts b/backend/src/ee/services/kmip/kmip-types.ts index 81d0d8766..c37d511c6 100644 --- a/backend/src/ee/services/kmip/kmip-types.ts +++ b/backend/src/ee/services/kmip/kmip-types.ts @@ -78,6 +78,7 @@ export type TKmipRegisterDTO = { name: string; key: string; algorithm: SymmetricKeyAlgorithm; + kmipMetadata?: Record; } & KmipOperationBaseDTO; export type TSetupOrgKmipDTO = { diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.ts index 995919c55..4de44a345 100644 --- a/backend/src/services/kms/kms-service.ts +++ b/backend/src/services/kms/kms-service.ts @@ -392,7 +392,7 @@ export const kmsServiceFactory = ({ }; const importKeyMaterial = async ( - { key, algorithm, name, isReserved, projectId, orgId, keyUsage }: TImportKeyMaterialDTO, + { key, algorithm, name, isReserved, projectId, orgId, keyUsage, kmipMetadata }: TImportKeyMaterialDTO, tx?: Knex ) => { // daniel: currently we only support imports for encrypt/decrypt keys @@ -416,7 +416,8 @@ export const kmsServiceFactory = ({ keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT, orgId, isReserved, - projectId + projectId, + kmipMetadata }, db ); diff --git a/backend/src/services/kms/kms-types.ts b/backend/src/services/kms/kms-types.ts index ca2401bb6..eaf0adbde 100644 --- a/backend/src/services/kms/kms-types.ts +++ b/backend/src/services/kms/kms-types.ts @@ -99,4 +99,5 @@ export type TImportKeyMaterialDTO = { projectId: string; orgId: string; keyUsage: KmsKeyUsage; + kmipMetadata?: Record; };