@@ -9,13 +9,13 @@ import { KMSClient,
99 GenerateDataKeyCommand ,
1010 EncryptCommand ,
1111 DecryptCommand ,
12- ListKeysCommand ,
1312 NotFoundException ,
1413 KMSInvalidStateException } from '@aws-sdk/client-kms' ;
1514const { NodeHttpHandler } = require ( '@smithy/node-http-handler' ) ;
1615import * as werelogs from 'werelogs' ;
1716import assert from 'assert' ;
1817import { KMSInterface , KmsBackend , getKeyIdFromArn , KmsProtocol , KmsType , makeBackend } from '../KMSInterface' ;
18+ import { AwsError } from '../types' ;
1919
2020type TLSVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1' ;
2121
@@ -140,7 +140,7 @@ export default class Client implements KMSInterface {
140140 // or aws arn when creating the KMS Key
141141 const arn = `${ this . backend . arnPrefix } ${ keyId } ` ;
142142 cb ( null , keyId , arn ) ;
143- } ) . catch ( err => {
143+ } ) . catch ( ( err : AwsError ) => {
144144 const error = arsenalErrorAWSKMS ( err ) ;
145145 logger . error ( 'AWS KMS: failed to create master encryption key' , { err } ) ;
146146 cb ( error ) ;
@@ -174,9 +174,10 @@ export default class Client implements KMSInterface {
174174 return ;
175175 }
176176 cb ( null ) ;
177- } ) . catch ( err => {
177+ } ) . catch ( ( err : AwsError ) => {
178178 if ( err instanceof NotFoundException || err instanceof KMSInvalidStateException ) {
179- logger . info ( 'AWS KMS: key does not exist or is already pending deletion' , { masterKeyId, error : err } ) ;
179+ // master key does not exist or is already pending deletion
180+ logger . warn ( 'AWS KMS: key does not exist or is already pending deletion' , { masterKeyId, error : err } ) ;
180181 return cb ( null ) ;
181182 }
182183 const error = arsenalErrorAWSKMS ( err ) ;
@@ -208,7 +209,7 @@ export default class Client implements KMSInterface {
208209 const isolatedPlaintext = this . safePlaintext ( data . Plaintext as Buffer ) ;
209210 logger . debug ( 'AWS KMS: data key generated' ) ;
210211 cb ( null , isolatedPlaintext , Buffer . from ( data . CiphertextBlob as Uint8Array ) ) ;
211- } ) . catch ( err => {
212+ } ) . catch ( ( err : AwsError ) => {
212213 const error = arsenalErrorAWSKMS ( err ) ;
213214 logger . error ( 'AWS KMS: failed to generate data key' , { err } ) ;
214215 cb ( error ) ;
@@ -242,8 +243,7 @@ export default class Client implements KMSInterface {
242243
243244 logger . debug ( 'AWS KMS: data key ciphered' ) ;
244245 cb ( null , Buffer . from ( data . CiphertextBlob as Uint8Array ) ) ;
245- return ;
246- } ) . catch ( err => {
246+ } ) . catch ( ( err : AwsError ) => {
247247 const error = arsenalErrorAWSKMS ( err ) ;
248248 logger . error ( 'AWS KMS: failed to cipher data key' , { err } ) ;
249249 cb ( error ) ;
@@ -278,16 +278,27 @@ export default class Client implements KMSInterface {
278278
279279 logger . debug ( 'AWS KMS: data key deciphered' ) ;
280280 cb ( null , isolatedPlaintext ) ;
281- } ) . catch ( err => {
281+ } ) . catch ( ( err : AwsError ) => {
282282 const error = arsenalErrorAWSKMS ( err ) ;
283283 logger . error ( 'AWS KMS: failed to decipher data key' , { err } ) ;
284284 cb ( error ) ;
285285 } ) ;
286286 }
287287
288288 /**
289- * Healthcheck function to verify KMS connectivity
289+ * NOTE1: S3C-4833 KMS healthcheck is disabled in CloudServer
290+ * NOTE2: The best approach for implementing the AWS KMS health check is still under consideration.
291+ * In the meantime, this method is commented out to prevent potential issues related to costs or permissions.
292+ *
293+ * Reasons for commenting out:
294+ * - frequent API calls can lead to increased expenses.
295+ * - access key secret key used must have `kms:ListKeys` permissions
296+ *
297+ * Future potential actions:
298+ * - implement caching mechanisms to reduce the number of API calls.
299+ * - differentiate between error types (e.g., 500 vs. 403) for more effective error handling.
290300 */
301+ /*
291302 healthcheck(logger: werelogs.Logger, cb: (err: Error | null) => void): void {
292303 logger.debug("AWS KMS: performing healthcheck");
293304
@@ -298,10 +309,11 @@ export default class Client implements KMSInterface {
298309 this.client.send(command).then(() => {
299310 logger.debug("AWS KMS healthcheck: list keys succeeded");
300311 cb(null);
301- } ) . catch ( err => {
312+ }).catch(err : AwsError => {
302313 const error = arsenalErrorAWSKMS(err);
303314 logger.error("AWS KMS healthcheck: failed to list keys", { err });
304315 cb(error);
305316 });
306317 }
318+ */
307319}
0 commit comments