mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 14:27:23 +00:00
feat: hsm improvements
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import * as pkcs11js from "pkcs11js";
|
||||
|
||||
import { TEnvConfig } from "@app/lib/config/env";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { KMS_ROOT_CONFIG_UUID } from "@app/services/kms/kms-fns";
|
||||
import { TKmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";
|
||||
import { RootKeyEncryptionStrategy } from "@app/services/kms/kms-types";
|
||||
|
||||
import { TLicenseServiceFactory } from "../license/license-service";
|
||||
import { THsmServiceFactory } from "./hsm-service";
|
||||
import { HsmModule } from "./hsm-types";
|
||||
|
||||
export const initializeHsmModule = (envConfig: Pick<TEnvConfig, "isHsmConfigured" | "HSM_LIB_PATH">) => {
|
||||
@@ -60,3 +66,32 @@ export const initializeHsmModule = (envConfig: Pick<TEnvConfig, "isHsmConfigured
|
||||
getModule
|
||||
};
|
||||
};
|
||||
|
||||
export const isHsmActiveAndEnabled = async ({
|
||||
hsmService,
|
||||
kmsRootConfigDAL,
|
||||
licenseService
|
||||
}: {
|
||||
hsmService: Pick<THsmServiceFactory, "isActive">;
|
||||
kmsRootConfigDAL: Pick<TKmsRootConfigDALFactory, "findById">;
|
||||
licenseService: Pick<TLicenseServiceFactory, "onPremFeatures">;
|
||||
}) => {
|
||||
const isHsmConfigured = await hsmService.isActive();
|
||||
|
||||
// null if the root kms config does not exist
|
||||
let rootKmsConfigEncryptionStrategy: RootKeyEncryptionStrategy | null = null;
|
||||
|
||||
const rootKmsConfig = await kmsRootConfigDAL.findById(KMS_ROOT_CONFIG_UUID).catch(() => null);
|
||||
|
||||
rootKmsConfigEncryptionStrategy = rootKmsConfig?.encryptionStrategy as RootKeyEncryptionStrategy | null;
|
||||
if (rootKmsConfigEncryptionStrategy === RootKeyEncryptionStrategy.HSM && !licenseService.onPremFeatures.hsm) {
|
||||
throw new BadRequestError({
|
||||
message: "Your license does not include HSM integration. Please upgrade to the Enterprise plan to use HSM."
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
rootKmsConfigEncryptionStrategy,
|
||||
isHsmConfigured
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import pkcs11js from "pkcs11js";
|
||||
|
||||
import { RootKeyEncryptionStrategy } from "@app/services/kms/kms-types";
|
||||
|
||||
export type HsmModule = {
|
||||
pkcs11: pkcs11js.PKCS11;
|
||||
isInitialized: boolean;
|
||||
@@ -9,3 +11,8 @@ export enum HsmKeyType {
|
||||
AES = "AES",
|
||||
HMAC = "hmac"
|
||||
}
|
||||
|
||||
export type THsmStatus = {
|
||||
rootKmsConfigEncryptionStrategy: RootKeyEncryptionStrategy | null;
|
||||
isHsmConfigured: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user