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
9 changes: 9 additions & 0 deletions lib/api/bucketPutObjectLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ function bucketPutObjectLock(authInfo, request, log, callback) {
(bucket, objectLockConfig, next) => {
const isObjectLockEnabled = bucket.isObjectLockEnabled();
process.nextTick(() => {
if (bucket.isPullReplicationSink()) {
return next(
errorInstances.InvalidBucketState.customizeDescription(
'This bucket is a pull replication sink, so its Object Lock configuration ' +
'cannot be changed',
),
bucket,
);
}
if (!isObjectLockEnabled) {
return next(
errorInstances.InvalidBucketState.customizeDescription(
Expand Down
14 changes: 14 additions & 0 deletions lib/api/bucketPutVersioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const ingestionVersioningErrorMessage =
const objectLockErrorMessage =
'An Object Lock configuration is present on this bucket, so the versioning state cannot be changed.';

const pullReplicationSourceErrorMessage =
'This bucket is a pull replication source, so versioning cannot be suspended.';

const pullReplicationSinkErrorMessage =
'This bucket is a pull replication sink, so the versioning state cannot be changed.';

/**
* Format of xml request:

Expand Down Expand Up @@ -139,6 +145,14 @@ function bucketPutVersioning(authInfo, request, log, callback) {
return next(null, bucket, versioningConfiguration);
}),
(bucket, versioningConfiguration, next) => {
if (bucket.isPullReplicationSink()) {
next(errorInstances.InvalidBucketState.customizeDescription(pullReplicationSinkErrorMessage));
return;
}
if (versioningConfiguration.Status === 'Suspended' && bucket.isPullReplicationSource()) {
next(errorInstances.InvalidBucketState.customizeDescription(pullReplicationSourceErrorMessage));
return;
}
// check if replication is enabled if versioning is being suspended
const replicationConfig = bucket.getReplicationConfiguration();
const isIngestionBucket = bucket.isIngestionBucket && bucket.isIngestionBucket();
Expand Down
8 changes: 8 additions & 0 deletions lib/api/objectPutLegalHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ function objectPutLegalHold(authInfo, request, log, callback) {
// see S3C-7592
return next(errors.MethodNotAllowed, bucket);
}
if (bucket.isPullReplicationSink()) {
return next(
errorInstances.InvalidBucketState.customizeDescription(
'This bucket is a pull replication sink, so object legal hold cannot be changed',
),
bucket,
);
}
if (!bucket.isObjectLockEnabled()) {
log.trace('object lock not enabled on bucket', { method: 'objectPutLegalHold' });
return next(
Expand Down
8 changes: 8 additions & 0 deletions lib/api/objectPutRetention.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ function objectPutRetention(authInfo, request, log, callback) {
log.trace('version is a delete marker', { method: 'objectPutRetention' });
return next(errors.MethodNotAllowed, bucket);
}
if (bucket.isPullReplicationSink()) {
return next(
errorInstances.InvalidBucketState.customizeDescription(
'This bucket is a pull replication sink, so object retention cannot be changed',
),
bucket,
);
}
if (!bucket.isObjectLockEnabled()) {
log.trace('object lock not enabled on bucket', { method: 'objectPutRetention' });
return next(
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.7",
"@scality/arsenal": "^8.7.5",
"@scality/bucketclient": "scality/bucketclient#8.3.0",
"@scality/cloudserverclient": "1.0.13",
"@scality/scubaclient": "1.2.2",
Expand Down
184 changes: 184 additions & 0 deletions tests/functional/aws-node-sdk/test/bucket/pullReplicationMarkers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const assert = require('assert');
const { promisify } = require('util');
const {
S3Client,
CreateBucketCommand,
DeleteBucketCommand,
DeleteObjectCommand,
GetBucketVersioningCommand,
GetObjectLockConfigurationCommand,
HeadObjectCommand,
PutBucketTaggingCommand,
PutBucketVersioningCommand,
PutObjectCommand,
PutObjectLegalHoldCommand,
PutObjectLockConfigurationCommand,
PutObjectRetentionCommand,
} = require('@aws-sdk/client-s3');

const checkError = require('../../lib/utility/checkError');
const getConfig = require('../support/config');
const metadata = require('../../../../../lib/metadata/wrapper');
const { DummyRequestLogger } = require('../../../../unit/helpers');

const bucketName = `pull-replication-bucket-${Date.now()}`;
const log = new DummyRequestLogger();
const getBucket = promisify(metadata.getBucket.bind(metadata));
const updateBucket = promisify(metadata.updateBucket.bind(metadata));

// the markers are written by the D/R bootstrap in practice, never through the S3 API
async function setMarkers(sources, sinks) {
const bucket = await getBucket(bucketName, log);
if (sources) {
bucket.setPullReplicationSources(sources);
}
if (sinks) {
bucket.setPullReplicationSinks(sinks);
}
await updateBucket(bucketName, bucket, log);
}

async function assertInvalidBucketState(promise) {
try {
await promise;
} catch (err) {
checkError(err, 'InvalidBucketState', 409);
return;
}
throw new Error('Expected InvalidBucketState error');
}

describe('pull replication markers', () => {
let s3;

const putVersioning = Status =>
s3.send(new PutBucketVersioningCommand({ Bucket: bucketName, VersioningConfiguration: { Status } }));

const assertVersioning = async status => {
const data = await s3.send(new GetBucketVersioningCommand({ Bucket: bucketName }));
assert.strictEqual(data.Status, status);
};

before(async () => {
s3 = new S3Client(getConfig('default', { signatureVersion: 'v4' }));
await promisify(metadata.setup.bind(metadata))();
});

afterEach(() => s3.send(new DeleteBucketCommand({ Bucket: bucketName })));

describe('on a bucket without markers', () => {
beforeEach(async () => {
await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
await putVersioning('Enabled');
});

it('should suspend versioning', async () => {
await putVersioning('Suspended');
await assertVersioning('Suspended');
});
});

describe('on a source bucket', () => {
beforeEach(async () => {
await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
await putVersioning('Enabled');
await setMarkers({ 'dr-1': {} }, undefined);
});

it('should not suspend versioning', async () => {
await assertInvalidBucketState(putVersioning('Suspended'));
await assertVersioning('Enabled');
});

it('should enable versioning', async () => {
await putVersioning('Enabled');
await assertVersioning('Enabled');
});

it('should keep the marker through another bucket update', async () => {
await s3.send(
new PutBucketTaggingCommand({
Bucket: bucketName,
Tagging: { TagSet: [{ Key: 'key', Value: 'value' }] },
}),
);
await assertInvalidBucketState(putVersioning('Suspended'));
});
});

describe('on a sink bucket', () => {
beforeEach(async () => {
await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
await putVersioning('Enabled');
await setMarkers(undefined, { 'dr-1': {} });
});

it('should not suspend versioning', async () => {
await assertInvalidBucketState(putVersioning('Suspended'));
await assertVersioning('Enabled');
});

it('should not enable versioning', async () => {
await assertInvalidBucketState(putVersioning('Enabled'));
});
});

describe('on a sink bucket with object lock', () => {
const objectName = 'object';
let versionId;

beforeEach(async () => {
await s3.send(new CreateBucketCommand({ Bucket: bucketName, ObjectLockEnabledForBucket: true }));
({ VersionId: versionId } = await s3.send(new PutObjectCommand({ Bucket: bucketName, Key: objectName })));
await setMarkers(undefined, { 'dr-1': {} });
});

afterEach(() =>
s3.send(new DeleteObjectCommand({ Bucket: bucketName, Key: objectName, VersionId: versionId })),
);

it('should not put an object retention', async () => {
await assertInvalidBucketState(
s3.send(
new PutObjectRetentionCommand({
Bucket: bucketName,
Key: objectName,
Retention: { Mode: 'GOVERNANCE', RetainUntilDate: new Date(Date.now() + 24 * 3600 * 1000) },
}),
),
);
const data = await s3.send(new HeadObjectCommand({ Bucket: bucketName, Key: objectName }));
assert.strictEqual(data.ObjectLockMode, undefined);
});

it('should not put an object legal hold', async () => {
await assertInvalidBucketState(
s3.send(
new PutObjectLegalHoldCommand({
Bucket: bucketName,
Key: objectName,
LegalHold: { Status: 'ON' },
}),
),
);
const data = await s3.send(new HeadObjectCommand({ Bucket: bucketName, Key: objectName }));
assert.strictEqual(data.ObjectLockLegalHoldStatus, undefined);
});

it('should not put an object lock configuration', async () => {
await assertInvalidBucketState(
s3.send(
new PutObjectLockConfigurationCommand({
Bucket: bucketName,
ObjectLockConfiguration: {
ObjectLockEnabled: 'Enabled',
Rule: { DefaultRetention: { Mode: 'GOVERNANCE', Days: 1 } },
},
}),
),
);
const data = await s3.send(new GetObjectLockConfigurationCommand({ Bucket: bucketName }));
assert.strictEqual(data.ObjectLockConfiguration.Rule, undefined);
});
});
});
18 changes: 18 additions & 0 deletions tests/unit/api/bucketPutObjectLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,23 @@ describe('putBucketObjectLock API', () => {
});
});
});

it('should not change the object lock config of a pull replication sink', done => {
metadata.getBucket(bucketName, log, (err, bucket) => {
assert.ifError(err);
bucket.setPullReplicationSinks({ 'dr-1': {} });
metadata.updateBucket(bucketName, bucket, log, err => {
assert.ifError(err);
bucketPutObjectLock(authInfo, putObjLockRequest, log, err => {
assert.strictEqual(err?.message, 'InvalidBucketState');
return metadata.getBucket(bucketName, log, (err, bucket) => {
assert.ifError(err);
assert.strictEqual(bucket.getObjectLockConfiguration(), undefined);
return done();
});
});
});
});
});
});
});
68 changes: 68 additions & 0 deletions tests/unit/api/bucketPutVersioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ function _getPutBucketRequest(xml) {
return request;
}

function _setPullReplicationMarkers(sources, sinks, cb) {
metadata.getBucket(bucketName, log, (err, bucket) => {
if (err) {
return cb(err);
}
if (sources) {
bucket.setPullReplicationSources(sources);
}
if (sinks) {
bucket.setPullReplicationSinks(sinks);
}
return metadata.updateBucket(bucketName, bucket, log, cb);
});
}

function _putVersioningRequest(xml) {
const request = {
bucketName,
Expand Down Expand Up @@ -118,6 +133,59 @@ describe('bucketPutVersioning API', () => {
done,
);
});

const pullReplicationTests = [
{
msg: 'should not suspend versioning on a pull replication source',
sources: { 'dr-1': {} },
input: xmlSuspendVersioning,
error: true,
},
{
msg: 'should enable versioning on a pull replication source',
sources: { 'dr-1': {} },
input: xmlEnableVersioning,
error: false,
},
{
msg: 'should not suspend versioning on a pull replication sink',
sinks: { 'dr-1': {} },
input: xmlSuspendVersioning,
error: true,
},
{
msg: 'should not enable versioning on a pull replication sink',
sinks: { 'dr-1': {} },
input: xmlEnableVersioning,
error: true,
},
];
pullReplicationTests.forEach(test =>
it(test.msg, done => {
async.series(
[
next => bucketPutVersioning(authInfo, _putVersioningRequest(xmlEnableVersioning), log, next),
next => _setPullReplicationMarkers(test.sources, test.sinks, next),
next =>
bucketPutVersioning(authInfo, _putVersioningRequest(test.input), log, err => {
if (test.error) {
assert.strictEqual(err?.message, 'InvalidBucketState');
} else {
assert.ifError(err);
}
next();
}),
next =>
metadata.getBucket(bucketName, log, (err, bucket) => {
assert.ifError(err);
assert.strictEqual(bucket.getVersioningConfiguration().Status, 'Enabled');
next();
}),
],
done,
);
}),
);
});

describe('with version disabled location constraint', () => {
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/api/objectPutLegalHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,23 @@ describe('putObjectLegalHold API', () => {
});
});
});

it('should not change the legal hold of an object in a pull replication sink', done => {
metadata.getBucket(bucketName, log, (err, bucket) => {
assert.ifError(err);
bucket.setPullReplicationSinks({ 'dr-1': {} });
metadata.updateBucket(bucketName, bucket, log, err => {
assert.ifError(err);
objectPutLegalHold(authInfo, putLegalHoldReq('ON'), log, err => {
assert.strictEqual(err?.message, 'InvalidBucketState');
return metadata.getObjectMD(bucketName, objectName, {}, log, (err, objMD) => {
assert.ifError(err);
assert.strictEqual(objMD.legalHold, undefined);
return done();
});
});
});
});
});
});
});
Loading
Loading