diff --git a/backend/src/ee/services/external-kms/external-kms-service.ts b/backend/src/ee/services/external-kms/external-kms-service.ts index 8dd80ce2c..faaace343 100644 --- a/backend/src/ee/services/external-kms/external-kms-service.ts +++ b/backend/src/ee/services/external-kms/external-kms-service.ts @@ -1,7 +1,9 @@ +import { KMSServiceException } from "@aws-sdk/client-kms"; +import { STSServiceException } from "@aws-sdk/client-sts"; import { ForbiddenError } from "@casl/ability"; import slugify from "@sindresorhus/slugify"; -import { BadRequestError, NotFoundError } from "@app/lib/errors"; +import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors"; import { alphaNumericNanoId } from "@app/lib/nanoid"; import { TKmsKeyDALFactory } from "@app/services/kms/kms-key-dal"; import { TKmsServiceFactory } from "@app/services/kms/kms-service"; @@ -71,7 +73,16 @@ export const externalKmsServiceFactory = ({ switch (provider.type) { case KmsProviders.Aws: { - const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs }); + const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs }).catch((error) => { + if (error instanceof STSServiceException || error instanceof KMSServiceException) { + throw new InternalServerError({ + message: error.message ? `AWS error: ${error.message}` : "" + }); + } + + throw error; + }); + // if missing kms key this generate a new kms key id and returns new provider input const newProviderInput = await externalKms.generateInputKmsKey(); sanitizedProviderInput = JSON.stringify(newProviderInput);