Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .github/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ services:
- ../pykmip/certs:/ssl
- ../pykmip/policy.json:/etc/pykmip/policies/policy.json
- ../pykmip/server.conf:/etc/pykmip/server.conf
# A KMS that accepts connections and never answers
unresponsive-kmip:
network_mode: host
profiles: ['pykmip']
image: ${CLOUDSERVER_IMAGE}
# node does not stop on SIGTERM as PID 1
init: true
entrypoint: ['node', '-e', "require('net').createServer(() => {}).listen(5697)"]
localkms:
network_mode: host
profiles: ['localkms']
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,11 @@ jobs:
> config.json
working-directory: tests/functional/sse-kms-migration
- name: Setup CI services
run: docker compose up -d --quiet-pull redis pykmip localkms cloudserver-sse-before-migration
# The KMS that never answers must listen before cloudserver checks every KMS at start-up
run: |
docker compose up -d --quiet-pull unresponsive-kmip
bash ../../wait_for_local_port.bash 5697 40
docker compose up -d --quiet-pull redis pykmip localkms cloudserver-sse-before-migration
working-directory: .github/docker
- name: Run file KMIP tests
env:
Expand Down
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ the default KMS. With `kmsHideScalityArn` (on by default), responses return key
IDs without ARN only for keys of the default KMS, so a returned key ID names the
same key when sent back. The deep health check has one entry per KMS, keyed by
`kms:` and its `providerName`; a failing KMS never fails start-up or readiness.
Each attempt of a request to a `kmip` or `aws_kms` KMS fails after
`requestTimeoutMs` of its entry, 5000 by default.

| Protocol | Description |
| --------- | ------------------------------------------------------ |
Expand Down
38 changes: 34 additions & 4 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function findConfigFile(fileName) {
const defaultHealthChecks = { allowFrom: ['127.0.0.1/8', '::1'] };

const defaultLocalCache = { host: '127.0.0.1', port: 6379 };

// Time limit of each attempt of a request to a kmip or aws_kms KMS
const defaultKmsRequestTimeoutMs = 5000;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This turns a time limit on for every existing kmip entry, and in arsenal 8.6.4 it counts time spent waiting for a pipeline slot (pipelineDepth, 8 by default). On a timeout, _dropConversation fails every in-flight and deferred request on that transport. So a burst that queues past 5 s against a slow but healthy KMIP server now fails many requests at once with a 500, where before they only waited. Consider leaving the limit off when requestTimeoutMs is unset, or at least note this behaviour change in the release notes.


const defaultExternalBackendsConfig = {
// eslint-disable-next-line camelcase
aws_s3: {
Expand Down Expand Up @@ -691,6 +695,24 @@ class Config extends EventEmitter {
return kms;
}

/**
* @param {object} block - the settings of a kmip or aws_kms kms entry
* @returns {number} the time limit of each attempt of a request to that
* KMS, in milliseconds
*/
_parseKmsRequestTimeout(block) {
const { requestTimeoutMs } = block;
if (requestTimeoutMs === undefined) {
return defaultKmsRequestTimeoutMs;
}
assert(
Number.isInteger(requestTimeoutMs) && requestTimeoutMs > 0,
'bad config: kms entry requestTimeoutMs must be a positive integer, ' +
`got ${JSON.stringify(requestTimeoutMs)}`,
);
return requestTimeoutMs;
}

_parseKmsAWS(block) {
const { providerName, region, endpoint, ak, sk, tls, noAwsArn } = block;

Expand All @@ -707,6 +729,7 @@ class Config extends EventEmitter {
endpoint,
ak,
sk,
requestTimeoutMs: this._parseKmsRequestTimeout(block),
};

if (region) {
Expand Down Expand Up @@ -751,9 +774,10 @@ class Config extends EventEmitter {
* @param {object} transportKmip - a KMIP transport from the config
* @param {object} environment - `process.env` for the default kms entry,
* whose settings override the S3KMIP_* variables, `{}` for the others
* @param {number} requestTimeoutMs - time limit of each request
* @returns {object} the transport passed to the KMIP client
*/
_parseKmipTransport(transportKmip, environment) {
_parseKmipTransport(transportKmip, environment, requestTimeoutMs) {
const transport = {
/** Specify the request pipeline depth here.
* If for some reason the server sends the replies
Expand All @@ -764,6 +788,7 @@ class Config extends EventEmitter {
* Note: 0 is not an appropriate value and will fall back to 1.
*/
pipelineDepth: environment.S3KMIP_PIPELINE_DEPTH || 8,
requestTimeoutMs,
tls: {
port: environment.S3KMIP_PORT || 5696,
// ignore multiple hosts via env
Expand Down Expand Up @@ -848,10 +873,11 @@ class Config extends EventEmitter {
kmip.client.bucketNameAttributeName = block.client.bucketNameAttributeName;
}
}
const requestTimeoutMs = this._parseKmsRequestTimeout(block);
if (!block.transport) {
kmip.transport = this._parseKmipTransport({}, environment);
kmip.transport = this._parseKmipTransport({}, environment, requestTimeoutMs);
} else if (Array.isArray(block.transport)) {
kmip.transport = block.transport.map(t => this._parseKmipTransport(t, environment));
kmip.transport = block.transport.map(t => this._parseKmipTransport(t, environment, requestTimeoutMs));
if (block.retries !== undefined) {
assert(
Number.isInteger(block.retries) && block.retries >= 0,
Expand All @@ -866,7 +892,7 @@ class Config extends EventEmitter {
kmip.retries = kmip.transport.length - 1;
}
} else {
kmip.transport = this._parseKmipTransport(block.transport, environment);
kmip.transport = this._parseKmipTransport(block.transport, environment, requestTimeoutMs);
}
return kmip;
}
Expand Down Expand Up @@ -898,6 +924,10 @@ class Config extends EventEmitter {
isDefault === undefined || typeof isDefault === 'boolean',
'bad config: kms entry default must be a boolean',
);
assert(
block.requestTimeoutMs === undefined || [KmsProtocol.kmip, KmsProtocol.aws_kms].includes(protocol),
'bad config: requestTimeoutMs is only for kmip and aws_kms kms entries',
);
const { providerName } = block;
assert(providerName, `bad config: ${protocol} kms entry must define providerName`);
assert(isValidProvider(providerName), 'bad config: kms entry providerName must be lowercase alphanumeric only');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@opentelemetry/instrumentation-http": "~0.222.0",
"@opentelemetry/instrumentation-ioredis": "~0.70.0",
"@opentelemetry/instrumentation-mongodb": "~0.75.0",
"@scality/arsenal": "^8.6.1",
"@scality/arsenal": "^8.6.4",
"@scality/bucketclient": "scality/bucketclient#8.3.0",
"@scality/cloudserverclient": "1.0.13",
"@scality/scubaclient": "1.2.2",
Expand Down
48 changes: 39 additions & 9 deletions tests/functional/kmip/serverside_encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const http = require('http');
const https = require('https');
const assert = require('assert');
const logger = { info: msg => process.stdout.write(`${msg}\n`) };

// A KMS of the server config that accepts connections and never answers
const unresponsiveKmsProviderName = 'unresponsive';
const async = require('async');

function _createBucketWithHeaders(name, headers, done) {
Expand Down Expand Up @@ -228,7 +231,9 @@ describe('KMIP backed server-side encryption', () => {
describe('KMIP backed server-side encryption with other KMSs configured', () => {
const createBucket = promisify(_createBucket);
const createBucketWithHeaders = promisify(_createBucketWithHeaders);
const nonDefaultEntries = serverConfig.kms.filter(entry => !entry.default);
const nonDefaultEntries = serverConfig.kms.filter(
entry => !entry.default && entry.providerName !== unresponsiveKmsProviderName,
);
const body = 'I am the best content ever';
let bucketName;
let objectName;
Expand Down Expand Up @@ -490,6 +495,18 @@ describe('KMIP backed server-side encryption with other KMSs configured', () =>
await assertStoredAndRefusedOnWrite(encryptedBucketName);
});
});

describe('with a key of a KMS that does not answer', () => {
const keyArn = `${makeScalityArnPrefix(KmsType.external, KmsProtocol.kmip, unresponsiveKmsProviderName)}1`;

it('should fail PutObject with an internal error after the time limit of the KMS', () =>
assert.rejects(putObject(bucketName, objectName, keyArn), err => {
assert.strictEqual(err.name, 'InternalError');
assert.strictEqual(err.$metadata.httpStatusCode, 500);
assert.match(err.message, /ETIMEDOUT/);
return true;
}));
});
});

describe('KMS health in the deep health check', () => {
Expand All @@ -506,16 +523,29 @@ describe('KMS health in the deep health check', () => {
});
}

it('should report every configured KMS, keyed by kms: and the provider name', async () => {
it('should report every configured KMS that answers, keyed by kms: and the provider name', async () => {
const { statusCode, body } = await getDeepHealthcheck();

assert.strictEqual(statusCode, 200);
serverConfig.kms.forEach(({ protocol, providerName }) => {
const { lastChecked, ...health } = body[`kms:${providerName}`];
assert.deepStrictEqual(health, { code: 200, message: 'OK' }, `KMS ${providerName}`);
// A KMS whose client has no health check reports OK without being checked;
// today only the KMIP client has one
assert.strictEqual(lastChecked !== undefined, protocol === KmsProtocol.kmip, `KMS ${providerName}`);
});
serverConfig.kms
.filter(({ providerName }) => providerName !== unresponsiveKmsProviderName)
.forEach(({ protocol, providerName }) => {
const { lastChecked, ...health } = body[`kms:${providerName}`];
assert.deepStrictEqual(health, { code: 200, message: 'OK' }, `KMS ${providerName}`);
// A KMS whose client has no health check reports OK without being checked;
// today only the KMIP client has one
assert.strictEqual(lastChecked !== undefined, protocol === KmsProtocol.kmip, `KMS ${providerName}`);
});
});

it('should report an unresponsive KMS as failed after its time limit, without blocking start-up', async () => {
const { statusCode, body } = await getDeepHealthcheck();

assert.strictEqual(statusCode, 200);
const { code, message, description } = body[`kms:${unresponsiveKmsProviderName}`];
assert.strictEqual(code, 500);
assert.strictEqual(message, 'KMS health check failed');
// Checked at start-up, while the KMS was already listening
assert.match(description, /ETIMEDOUT/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
{
"protocol": "file",
"providerName": "scality"
},
{
"protocol": "kmip",
"providerName": "unresponsive",
"requestTimeoutMs": 1000,
"transport": { "tls": { "host": "127.0.0.1", "port": 5697 } }
}
]
}
42 changes: 42 additions & 0 deletions tests/unit/testConfigs/parseKms.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('parseKms Function', () => {
assert.strictEqual(entry.settings.transport.tls.host, 'kmip.example.com');
assert.strictEqual(entry.settings.transport.tls.port, 5696);
assert.strictEqual(entry.settings.transport.pipelineDepth, 8);
assert.strictEqual(entry.settings.transport.requestTimeoutMs, 5000);
assert.deepStrictEqual(entry.settings.client, {
compoundCreateActivate: false,
bucketNameAttributeName: '',
Expand Down Expand Up @@ -129,9 +130,31 @@ describe('parseKms Function', () => {
endpoint: 'https://kms.example.com',
ak: 'accessKey',
sk: 'secretKey',
requestTimeoutMs: 5000,
});
});

it('should apply the requestTimeoutMs of a kmip entry to every transport of its cluster', () => {
configInstance._parseKms({
kms: [
{
...kmipEntry,
requestTimeoutMs: 2000,
transport: [{ tls: { host: 'kmip1' } }, { tls: { host: 'kmip2' } }],
},
],
});
assert.deepStrictEqual(
configInstance.kms[0].settings.transport.map(transport => transport.requestTimeoutMs),
[2000, 2000],
);
});

it('should apply the requestTimeoutMs of an aws_kms entry', () => {
configInstance._parseKms({ kms: [{ ...awsEntry, default: true, requestTimeoutMs: 2000 }] });
assert.strictEqual(configInstance.kms[0].settings.requestTimeoutMs, 2000);
});

it('should parse a file entry', () => {
configInstance._parseKms({ kms: [{ ...fileEntry, default: true }] });
assert.deepStrictEqual(configInstance.kms, [
Expand Down Expand Up @@ -236,6 +259,24 @@ describe('parseKms Function', () => {
);
});

[0, '2000'].forEach(requestTimeoutMs => {
it(`should reject requestTimeoutMs ${JSON.stringify(requestTimeoutMs)}`, () => {
assert.throws(
() => configInstance._parseKms({ kms: [{ ...kmipEntry, requestTimeoutMs }] }),
/kms entry requestTimeoutMs must be a positive integer/,
);
});
});

[{ ...fileEntry, default: true }, safeNetEntry].forEach(entry => {
it(`should reject requestTimeoutMs on a ${entry.protocol} entry`, () => {
assert.throws(
() => configInstance._parseKms({ kms: [{ ...entry, requestTimeoutMs: 2000 }] }),
/requestTimeoutMs is only for kmip and aws_kms kms entries/,
);
});
});

it('should reject a default that is not a boolean', () => {
assert.throws(
() => configInstance._parseKms({ kms: [{ ...kmipEntry, default: 'true' }] }),
Expand Down Expand Up @@ -367,6 +408,7 @@ describe('parseKms Function', () => {
assert.strictEqual(settings.transport.tls.host, 'kmip.example.com');
assert.strictEqual(settings.transport.tls.port, '5697');
assert.strictEqual(settings.transport.pipelineDepth, '4');
assert.strictEqual(settings.transport.requestTimeoutMs, 5000);
assert.deepStrictEqual(settings.client, {
compoundCreateActivate: true,
bucketNameAttributeName: 'bucket',
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/testConfigs/parseKmsAWS.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('parseKmsAWS Function', () => {
endpoint: 'https://example.com',
ak: 'accessKey',
sk: 'secretKey',
requestTimeoutMs: 5000,
});
});

Expand All @@ -61,6 +62,7 @@ describe('parseKmsAWS Function', () => {
endpoint: 'https://example.com',
ak: 'accessKey',
sk: 'secretKey',
requestTimeoutMs: 5000,
region: 'us-west-2',
});
});
Expand All @@ -85,6 +87,7 @@ describe('parseKmsAWS Function', () => {
endpoint: 'https://example.com',
ak: 'accessKey',
sk: 'secretKey',
requestTimeoutMs: 5000,
tls: {
rejectUnauthorized: true,
minVersion: 'TLSv1.2',
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,10 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.2.tgz#78d476333d85d5b1c792e257bca74ba080da49a4"
integrity sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==

"@scality/arsenal@^8.6.0", "@scality/arsenal@^8.6.1":
version "8.6.1"
resolved "https://registry.yarnpkg.com/@scality/arsenal/-/arsenal-8.6.1.tgz#f2db3ec8184646282872850d1cce3c16870f053c"
integrity sha512-EwKYj0htAbDvDmu4h3EeIG1RwwxGCRvUixQN8NHx9bJIHS5qucQLvNCQ45BNR0q4MDIza3fyE6Xn7DF5hxBBUQ==
"@scality/arsenal@^8.6.0", "@scality/arsenal@^8.6.4":
version "8.6.4"
resolved "https://registry.yarnpkg.com/@scality/arsenal/-/arsenal-8.6.4.tgz#f1ebb196835f103a613632c42b6ba3ba8ca13008"
integrity sha512-tAFQ8Xq7ukRR64Y+JGKTpX+3AfcdDK6Q1RC7Np8couFElhn0OpRz7p6mP7MgmMeUfC4J4d/5S8/DG2BFNVPINQ==
dependencies:
"@aws-sdk/client-kms" "^3.975.0"
"@aws-sdk/client-s3" "^3.975.0"
Expand All @@ -1332,7 +1332,7 @@
"@opentelemetry/sdk-node" "^0.223.0"
"@opentelemetry/sdk-trace-base" "^2.12.0"
"@scality/hdclient" "^1.3.2"
"@smithy/node-http-handler" "^4.3.0"
"@smithy/node-http-handler" "^4.4.0"
"@smithy/protocol-http" "^5.3.5"
JSONStream "^1.3.5"
agentkeepalive "^4.6.0"
Expand Down Expand Up @@ -1585,7 +1585,7 @@
"@smithy/types" "^3.7.2"
tslib "^2.6.2"

"@smithy/node-http-handler@^4.12.1", "@smithy/node-http-handler@^4.3.0":
"@smithy/node-http-handler@^4.12.1", "@smithy/node-http-handler@^4.4.0":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@smithy/node-http-handler/-/node-http-handler-4.13.0.tgz#cc26fbea5572a482b35cb43ca55c0d182e4eff70"
integrity sha512-/GGcPoNJ2nzGytdAanpbx7mpp9Coa8LP+/Rpmbktr8YeLuIXs9B0SEz+X3AeonHdyzOIFJdKbN7jOZ+Tj+pMGw==
Expand Down
Loading