Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Address greptile comments

Carlos Monastyrski3308f5b27be4
diff --git a/backend/src/ee/services/kmip/kmip-operation-service.ts b/backend/src/ee/services/kmip/kmip-operation-service.ts
index 65baf57f3e..ab7e3ebed0 100644
--- a/backend/src/ee/services/kmip/kmip-operation-service.ts
+++ b/backend/src/ee/services/kmip/kmip-operation-service.ts
@@ -132,12 +132,6 @@ export const kmipOperationServiceFactory = ({
throw new BadRequestError({ message: "Cannot destroy reserved keys" });
}
- if (key.hasDeleteProtection) {
- throw new BadRequestError({
- message: `Key with ID ${id} has delete protection enabled. Disable delete protection on the key before destroying it.`
- });
- }
-
const completeKeyDetails = await kmsDAL.findByIdWithAssociatedKms(id);
if (!completeKeyDetails) {
throw new NotFoundError({ message: `Key with ID '${id}' not found` });
@@ -154,7 +148,13 @@ export const kmipOperationServiceFactory = ({
});
}
- const kms = kmsDAL.deleteById(id);
+ const [kms] = await kmsDAL.delete({ id, hasDeleteProtection: false });
+
+ if (!kms) {
+ throw new BadRequestError({
+ message: `Key with ID ${id} has delete protection enabled. Disable delete protection on the key before destroying it.`
+ });
+ }
recordKmipOperationMetric({
operationType: KmipOperationType.DESTROY,
diff --git a/backend/src/services/cmek/cmek-service.ts b/backend/src/services/cmek/cmek-service.ts
index a2ccb8c128..a4f9e57b04 100644
--- a/backend/src/services/cmek/cmek-service.ts
+++ b/backend/src/services/cmek/cmek-service.ts
@@ -173,14 +173,14 @@ export const cmekServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionCmekActions.Delete, ProjectPermissionSub.Cmek);
- if (key.hasDeleteProtection) {
+ const [deletedKey] = await kmsDAL.delete({ id: keyId, hasDeleteProtection: false });
+
+ if (!deletedKey) {
throw new BadRequestError({
message: `Key with ID ${keyId} has delete protection enabled. Disable delete protection on the key before deleting it.`
});
}
- await kmsDAL.deleteById(keyId);
-
return key;
};