misc: add kmip metadata field

This commit is contained in:
Sheen Capadngan
2025-10-10 19:56:51 +08:00
parent 01b6c29996
commit 659ed7365d
7 changed files with 36 additions and 8 deletions
@@ -0,0 +1,19 @@
import { Knex } from "knex";
import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
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<void> {
if (await knex.schema.hasColumn(TableName.KmsKey, "kmipMetadata")) {
await knex.schema.alterTable(TableName.KmsKey, (t) => {
t.dropColumn("kmipMetadata");
});
}
}
+2 -1
View File
@@ -17,7 +17,8 @@ export const KmsKeysSchema = z.object({
createdAt: z.date(), createdAt: z.date(),
updatedAt: z.date(), updatedAt: z.date(),
projectId: z.string().nullable().optional(), 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<typeof KmsKeysSchema>; export type TKmsKeys = z.infer<typeof KmsKeysSchema>;
+4 -2
View File
@@ -128,7 +128,8 @@ export const registerKmipSpecRouter = async (server: FastifyZodProvider) => {
200: z.object({ 200: z.object({
id: z.string(), id: z.string(),
value: 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({ body: z.object({
key: z.string(), key: z.string(),
name: z.string(), name: z.string(),
algorithm: z.nativeEnum(SymmetricKeyAlgorithm) algorithm: z.nativeEnum(SymmetricKeyAlgorithm),
kmipMetadata: z.record(z.any()).optional()
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -183,7 +183,8 @@ export const kmipOperationServiceFactory = ({
algorithm: completeKeyDetails.internalKms.encryptionAlgorithm, algorithm: completeKeyDetails.internalKms.encryptionAlgorithm,
isActive: !key.isDisabled, isActive: !key.isDisabled,
createdAt: key.createdAt, createdAt: key.createdAt,
updatedAt: key.updatedAt updatedAt: key.updatedAt,
kmipMetadata: key.kmipMetadata as Record<string, unknown>
}; };
}; };
@@ -373,7 +374,8 @@ export const kmipOperationServiceFactory = ({
actor, actor,
actorId, actorId,
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId,
kmipMetadata
}: TKmipRegisterDTO) => { }: TKmipRegisterDTO) => {
const { permission } = await permissionService.getOrgPermission( const { permission } = await permissionService.getOrgPermission(
actor, actor,
@@ -405,7 +407,8 @@ export const kmipOperationServiceFactory = ({
isReserved: false, isReserved: false,
projectId, projectId,
keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT, keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT,
orgId: project.orgId orgId: project.orgId,
kmipMetadata
}); });
return kmsKey; return kmsKey;
@@ -78,6 +78,7 @@ export type TKmipRegisterDTO = {
name: string; name: string;
key: string; key: string;
algorithm: SymmetricKeyAlgorithm; algorithm: SymmetricKeyAlgorithm;
kmipMetadata?: Record<string, unknown>;
} & KmipOperationBaseDTO; } & KmipOperationBaseDTO;
export type TSetupOrgKmipDTO = { export type TSetupOrgKmipDTO = {
+3 -2
View File
@@ -392,7 +392,7 @@ export const kmsServiceFactory = ({
}; };
const importKeyMaterial = async ( const importKeyMaterial = async (
{ key, algorithm, name, isReserved, projectId, orgId, keyUsage }: TImportKeyMaterialDTO, { key, algorithm, name, isReserved, projectId, orgId, keyUsage, kmipMetadata }: TImportKeyMaterialDTO,
tx?: Knex tx?: Knex
) => { ) => {
// daniel: currently we only support imports for encrypt/decrypt keys // daniel: currently we only support imports for encrypt/decrypt keys
@@ -416,7 +416,8 @@ export const kmsServiceFactory = ({
keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT, keyUsage: KmsKeyUsage.ENCRYPT_DECRYPT,
orgId, orgId,
isReserved, isReserved,
projectId projectId,
kmipMetadata
}, },
db db
); );
+1
View File
@@ -99,4 +99,5 @@ export type TImportKeyMaterialDTO = {
projectId: string; projectId: string;
orgId: string; orgId: string;
keyUsage: KmsKeyUsage; keyUsage: KmsKeyUsage;
kmipMetadata?: Record<string, unknown>;
}; };