From 14c8cef074ae091b52060b04a19b8bb64a3ba2bc Mon Sep 17 00:00:00 2001 From: Dimitrios Vasilas Date: Fri, 20 Nov 2026 16:50:14 +0200 Subject: [PATCH] CLDSRV-1084: Name the KMS and the key in the logs of failed KMS requests Key creation and deletion failures are now logged at error level, like data key failures. --- lib/kms/wrapper.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/kms/wrapper.js b/lib/kms/wrapper.js index cad0368722..7c19fa3214 100644 --- a/lib/kms/wrapper.js +++ b/lib/kms/wrapper.js @@ -14,6 +14,7 @@ const vault = require('../auth/vault'); const Cache = require('./Cache'); const { KmsProtocol, + KmsType, makeBackend, isScalityKmsArn, extractDetailFromArn, @@ -283,6 +284,22 @@ function belongsToMigrationSource(storedKey, migrationBackend) { return !detail.type || getClientIdentifier(detail) === getClientIdentifier(migrationBackend); } +/** + * Log fields naming the KMS of a failed request, and the key it used. + * A key without arn prefix is named with the arn of the KMS it was sent to. + * Keys of an internal KMS are not named: their KeyId is the master key. + * @param {object} kmsClient - client the request was sent to + * @param {string} [keyId] - KeyId the request used, from getClientForKey + * @returns {object} `{ provider, keyArn }`, without `keyArn` if no key was used or the KMS is internal + */ +function kmsFailureFields(kmsClient, keyId) { + const { type, provider, arnPrefix } = kmsClient.backend; + if (keyId === undefined || type === KmsType.internal) { + return { provider }; + } + return { provider, keyArn: `${arnPrefix}${keyId}` }; +} + class KMS { /** Access to client for tests (to create a key without vault check and bucket) */ static get client() { @@ -351,7 +368,12 @@ class KMS { // Otherwise, create a default master encryption key, later its id will be stored at the bucket metadata level. return client.createBucketKey(bucket.getName(), log, (err, masterKeyId, masterKeyArn) => { if (err) { - log.debug('error from kms', { implName, error: err }); + log.error('KMS failed to create a bucket key', { + implName, + ...kmsFailureFields(client), + bucketName: bucket.getName(), + error: err, + }); return cb(err); } log.trace('bucket key created in kms'); @@ -436,7 +458,11 @@ class KMS { } return client.destroyBucketKey(key, log, err => { if (err) { - log.debug('error from kms', { implName, error: err }); + log.error('KMS failed to destroy a bucket key', { + implName, + ...kmsFailureFields(client, key), + error: err, + }); return cb(err); } log.trace('bucket key destroyed in kms'); @@ -596,7 +622,11 @@ class KMS { ], (err, cipherBundle) => { if (err) { - log.error('error processing cipher bundle', { implName, error: err }); + log.error('error processing cipher bundle', { + implName, + ...kmsFailureFields(client, key), + error: err, + }); } return cb(err, cipherBundle); }, @@ -686,7 +716,11 @@ class KMS { ], (err, decipherBundle) => { if (err) { - log.error('error processing decipher bundle', { implName: _impl, error: err }); + log.error('error processing decipher bundle', { + implName: _impl, + ...kmsFailureFields(client, key), + error: err, + }); return cb(err); } return cb(err, decipherBundle);