From d516a92897734b290e9a8591c7f5ca5c4aeaade5 Mon Sep 17 00:00:00 2001 From: Dimitrios Vasilas Date: Wed, 21 Oct 2026 09:23:42 +0300 Subject: [PATCH] CLDSRV-1047: Name only the requested key ARN when rejecting a key from an unconfigured KMS Pass the requested key ARN to Arsenal at both checks; the KMIP functional test stays on 9.6, which alone has other KMSs configured. (cherry picked from commit 4be78a84d5b024747826285fd3ee0ed850f27f91) --- lib/kms/wrapper.js | 4 ++-- tests/unit/encryption/kms.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/kms/wrapper.js b/lib/kms/wrapper.js index cd7c5e1ee4..686b83a4c0 100644 --- a/lib/kms/wrapper.js +++ b/lib/kms/wrapper.js @@ -127,7 +127,7 @@ function getClientForKey(key, log) { // if type was extracted, it is a scality arnPrefix, it needs validation // might throw if arn malformed or backend not available // for any request (PUT or GET) - const error = validateKeyDetail(detail, availableBackends); + const error = validateKeyDetail(detail, availableBackends, key); if (error) { log.error('KMS key arn is invalid', { key, detail, availableBackends }); return { error }; @@ -272,7 +272,7 @@ class KMS { // otherwise prepend the current KMS client arnPrefix if (isScalityKmsArn(configuredMasterKeyId)) { const detail = extractDetailFromArn(configuredMasterKeyId); - const error = validateKeyDetail(detail, availableBackends); + const error = validateKeyDetail(detail, availableBackends, configuredMasterKeyId); if (error) { return cb(error); } diff --git a/tests/unit/encryption/kms.js b/tests/unit/encryption/kms.js index 533315e176..cac7270e76 100644 --- a/tests/unit/encryption/kms.js +++ b/tests/unit/encryption/kms.js @@ -48,6 +48,37 @@ describe('KMS unit tests', () => { }); }); + describe('with a key of a KMS that is not configured', () => { + const keyArn = 'arn:scality:kms:external:kmip:unconfigured:key/1'; + + function assertRefusedNamingOnlyTheKey(err) { + assert.strictEqual(err.is.InvalidArgument, true); + assert.strictEqual( + err.description, + `KMS Scality KeyArn "${keyArn}" doesn't match any configured providers`, + ); + } + + it('should refuse it on bucket encryption', done => { + const sseConfig = parseBucketEncryptionHeaders({ + 'x-amz-scal-server-side-encryption': 'aws:kms', + 'x-amz-scal-server-side-encryption-aws-kms-key-id': keyArn, + }); + KMS.bucketLevelEncryption(dummyBucket, sseConfig, log, err => { + assertRefusedNamingOnlyTheKey(err); + done(); + }); + }); + + it('should refuse it on object encryption', done => { + const sseInfo = { algorithm: 'aws:kms', cryptoScheme: 1, mandatory: true, masterKeyId: keyArn }; + KMS.createCipherBundle(sseInfo, log, err => { + assertRefusedNamingOnlyTheKey(err); + done(); + }); + }); + }); + it( 'should not construct a sse info object if ' + 'x-amz-scal-server-side-encryption header contains invalid algorithm option',