Merge pull request #2133 from akhilmhdh/feat/aws-kms-sm

fix: slug too big for project fixed
This commit is contained in:
Maidul Islam
2024-07-16 09:50:08 -04:00
committed by GitHub
3 changed files with 14 additions and 11 deletions
@@ -39,7 +39,7 @@ export const registerExternalKmsRouter = async (server: FastifyZodProvider) => {
}, },
schema: { schema: {
body: z.object({ body: z.object({
slug: z.string().min(1).trim().optional(), slug: z.string().min(1).trim().toLowerCase().optional(),
description: z.string().min(1).trim().optional(), description: z.string().min(1).trim().optional(),
provider: ExternalKmsInputSchema provider: ExternalKmsInputSchema
}), }),
@@ -75,7 +75,7 @@ export const registerExternalKmsRouter = async (server: FastifyZodProvider) => {
id: z.string().trim().min(1) id: z.string().trim().min(1)
}), }),
body: z.object({ body: z.object({
slug: z.string().min(1).trim().optional(), slug: z.string().min(1).trim().toLowerCase().optional(),
description: z.string().min(1).trim().optional(), description: z.string().min(1).trim().optional(),
provider: ExternalKmsInputUpdateSchema provider: ExternalKmsInputUpdateSchema
}), }),
@@ -52,7 +52,7 @@ export const externalKmsServiceFactory = ({
actorOrgId actorOrgId
); );
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings); ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);
const kmsSlug = slug ? slugify(slug) : slugify(alphaNumericNanoId(32)); const kmsSlug = slug ? slugify(slug) : slugify(alphaNumericNanoId(8).toLowerCase());
let sanitizedProviderInput = ""; let sanitizedProviderInput = "";
switch (provider.type) { switch (provider.type) {
+11 -8
View File
@@ -56,15 +56,18 @@ export const kmsServiceFactory = ({
const cipher = symmetricCipherService(SymmetricEncryption.AES_GCM_256); const cipher = symmetricCipherService(SymmetricEncryption.AES_GCM_256);
const kmsKeyMaterial = randomSecureBytes(32); const kmsKeyMaterial = randomSecureBytes(32);
const encryptedKeyMaterial = cipher.encrypt(kmsKeyMaterial, ROOT_ENCRYPTION_KEY); const encryptedKeyMaterial = cipher.encrypt(kmsKeyMaterial, ROOT_ENCRYPTION_KEY);
const sanitizedSlug = slug ? slugify(slug) : slugify(alphaNumericNanoId(32)); const sanitizedSlug = slug ? slugify(slug) : slugify(alphaNumericNanoId(8).toLowerCase());
const dbQuery = async (db: Knex) => { const dbQuery = async (db: Knex) => {
const kmsDoc = await kmsDAL.create({ const kmsDoc = await kmsDAL.create(
slug: sanitizedSlug, {
orgId, slug: sanitizedSlug,
isReserved orgId,
}); isReserved
},
db
);
const { encryptedKey, ...doc } = await internalKmsDAL.create( await internalKmsDAL.create(
{ {
version: 1, version: 1,
encryptedKey: encryptedKeyMaterial, encryptedKey: encryptedKeyMaterial,
@@ -73,7 +76,7 @@ export const kmsServiceFactory = ({
}, },
db db
); );
return doc; return kmsDoc;
}; };
if (tx) return dbQuery(tx); if (tx) return dbQuery(tx);
const doc = await kmsDAL.transaction(async (tx2) => dbQuery(tx2)); const doc = await kmsDAL.transaction(async (tx2) => dbQuery(tx2));