Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/kms/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/encryption/kms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer asserting the error name over .is, so a failure shows which error was actually returned.

Suggested change
assert.strictEqual(err.is.InvalidArgument, true);
assert.strictEqual(err.message, 'InvalidArgument');

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',
Expand Down
Loading