Skip to content

Commit 8d110bd

Browse files
committed
NC | NSFS | Stop setting the system_owner as the account's name in bucket config
1. Remove the property system_owner as required property in nsfs_bucket_schema. 2. On the newly created bucket, do not set the system_owner value (on manage_nsfs and bucketspace_fs). 3. Remove the system_owner (with the value of the account name) from the current docs in NC NSFS. 4. Update unit test tests and remove the property system_owner. 5. Add the function modify_bucket_on_read in class ConfigFS, and use it from get_bucket_by_name and inside the bucket list in noobaa-cli. Signed-off-by: shirady <57721533+shirady@users.noreply.github.com>
1 parent 68a0cc7 commit 8d110bd

File tree

14 files changed

+89
-34
lines changed

14 files changed

+89
-34
lines changed

docs/NooBaaNonContainerized/CI&Tests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The following is a list of `NC jest tests` files -
103103
8. `test_nc_nsfs_bucket_schema_validation.test.js` - Tests NC bucket schema validation.
104104
9. `test_nc_nsfs_account_schema_validation.test.js` - Tests NC account schema validation.
105105
10. `test_nc_nsfs_new_buckets_path_validation.test.js` - Tests new_buckets_path RW access.
106+
11. `test_config_fs.test.js` - Tests ConfigFS methods.
106107

107108
#### nc_index.js File
108109
* The `nc_index.js` is a file that runs several NC and NSFS mocha related tests.

docs/NooBaaNonContainerized/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ make_bucket: s3bucket
187187
#### 3. Check that the bucket configuration file was created successfully -
188188
```sh
189189
sudo cat /etc/noobaa.conf.d/buckets/s3bucket.json
190-
{"_id":"65cb1efcbec92b33220112d7","name":"s3bucket","owner_account":"65cb1e7c9e6ae40d499c0ae4","system_owner":"account1","bucket_owner":"account1","versioning":"DISABLED","creation_date":"2023-09-26T05:56:16.252Z","path":"/tmp/fs1/s3bucket","should_create_underlying_storage":true}
190+
{"_id":"65cb1efcbec92b33220112d7","name":"s3bucket","owner_account":"65cb1e7c9e6ae40d499c0ae4","bucket_owner":"account1","versioning":"DISABLED","creation_date":"2023-09-26T05:56:16.252Z","path":"/tmp/fs1/s3bucket","should_create_underlying_storage":true}
191191
```
192192
193193
#### 4. Check that the underlying file system bucket directory was created successfully -

src/cmd/manage_nsfs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ async function fetch_bucket_data(action, user_input) {
9494
_id: undefined,
9595
name: user_input.name === undefined ? undefined : String(user_input.name),
9696
owner_account: undefined,
97-
system_owner: user_input.owner, // GAP - needs to be the system_owner (currently it is the account name)
9897
bucket_owner: user_input.owner,
9998
tag: undefined, // if we would add the option to tag a bucket using CLI, this should be changed
10099
versioning: action === ACTIONS.ADD ? 'DISABLED' : undefined,
@@ -596,8 +595,9 @@ async function list_config_files(type, config_path, wide, show_secrets, filters)
596595
let config_files_list = await P.map_with_concurrency(10, entries, async entry => {
597596
if (entry.name.endsWith(JSON_SUFFIX)) {
598597
if (wide || should_filter) {
599-
const full_path = path.join(config_path, entry.name);
600-
const data = await config_fs.get_config_data(full_path, options);
598+
const data = type === TYPES.ACCOUNT ?
599+
await config_fs.get_account_by_name(entry.name, options) :
600+
await config_fs.get_bucket_by_name(entry.name, options);
601601
if (!data) return undefined;
602602
if (should_filter && !filter_list_item(type, data, filters)) return undefined;
603603
// remove secrets on !show_secrets && should filter

src/endpoint/s3/s3_rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async function authorize_request_policy(req) {
230230

231231
const account = req.object_sdk.requesting_account;
232232
const account_identifier = req.object_sdk.nsfs_config_root ? account.name.unwrap() : account.email.unwrap();
233-
const is_system_owner = account_identifier === system_owner.unwrap();
233+
const is_system_owner = Boolean(system_owner) && system_owner.unwrap() === account_identifier;
234234

235235
// @TODO: System owner as a construct should be removed - Temporary
236236
if (is_system_owner) return;

src/sdk/bucketspace_fs.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
121121
};
122122

123123
bucket.name = new SensitiveString(bucket.name);
124-
bucket.system_owner = new SensitiveString(bucket.system_owner);
125124
bucket.bucket_owner = new SensitiveString(bucket.bucket_owner);
126125
bucket.owner_account = {
127126
id: bucket.owner_account,
@@ -291,7 +290,6 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
291290
tag: js_utils.default_value(tag, undefined),
292291
owner_account: account._id,
293292
creator: account._id,
294-
system_owner: new SensitiveString(account.name),
295293
bucket_owner: new SensitiveString(account.name),
296294
versioning: config.NSFS_VERSIONING_ENABLED && lock_enabled ? 'ENABLED' : 'DISABLED',
297295
object_lock_configuration: config.WORM_ENABLED ? {
@@ -675,7 +673,7 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
675673
const account_identifier = account.name.unwrap();
676674
dbg.log1('has_bucket_action_permission:', bucket.name.unwrap(), account_identifier, bucket.bucket_owner.unwrap());
677675

678-
const is_system_owner = account_identifier === bucket.system_owner.unwrap();
676+
const is_system_owner = Boolean(bucket.system_owner) && bucket.system_owner.unwrap() === account_identifier;
679677

680678
// If the system owner account wants to access the bucket, allow it
681679
if (is_system_owner) return true;

src/sdk/config_fs.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ class ConfigFS {
398398
async get_bucket_by_name(bucket_name, options = {}) {
399399
const bucket_path = this.get_bucket_path_by_name(bucket_name);
400400
const bucket = await this.get_config_data(bucket_path, options);
401+
this.adjust_bucket_with_schema_updates(bucket);
401402
return bucket;
402403
}
403404

@@ -440,6 +441,18 @@ class ConfigFS {
440441
const bucket_config_path = this.get_bucket_path_by_name(bucket_name);
441442
await native_fs_utils.delete_config_file(this.fs_context, this.buckets_dir_path, bucket_config_path);
442443
}
444+
445+
/**
446+
* adjust_bucket_with_schema_updates changes the bucket properties according to the schema
447+
* @param {object} bucket
448+
*/
449+
adjust_bucket_with_schema_updates(bucket) {
450+
if (!bucket) return;
451+
// system_owner is deprecated since version 5.18
452+
if (bucket.system_owner !== undefined) {
453+
delete bucket.system_owner;
454+
}
455+
}
443456
}
444457

445458
// EXPORTS

src/sdk/object_sdk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class ObjectSDK {
194194
const { bucket } = await bucket_namespace_cache.get_with_cache({ sdk: this, name });
195195
const policy_info = {
196196
s3_policy: bucket.s3_policy,
197-
system_owner: bucket.system_owner,
197+
system_owner: bucket.system_owner, // note that bucketspace_fs currently doesn't return system_owner
198198
bucket_owner: bucket.bucket_owner,
199199
owner_account: bucket.owner_account, // in NC NSFS this is the account id that owns the bucket
200200
};

src/server/system_services/schemas/nsfs_bucket_schema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
required: [
88
'_id',
99
'name',
10-
'system_owner',
1110
'bucket_owner',
1211
'owner_account',
1312
'versioning',
@@ -30,6 +29,10 @@ module.exports = {
3029
name: {
3130
type: 'string',
3231
},
32+
/**
33+
* @deprecated system_owner is kept for backward compatibility,
34+
* but will no longer be included in new / updated bucket json.
35+
*/
3336
system_owner: {
3437
type: 'string',
3538
},

src/test/unit_tests/jest_tests/test_accountspace_fs.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,6 @@ function _new_bucket_defaults(account, bucket_name, bucket_storage_path) {
18721872
_id: '65a8edc9bc5d5bbf9db71c75',
18731873
name: bucket_name,
18741874
owner_account: account._id,
1875-
system_owner: new SensitiveString(account.name),
18761875
bucket_owner: new SensitiveString(account.name),
18771876
creation_date: new Date().toISOString(),
18781877
path: bucket_storage_path,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (C) 2024 NooBaa */
2+
'use strict';
3+
4+
const path = require('path');
5+
const config = require('../../../../config');
6+
const { TMP_PATH } = require('../../system_tests/test_utils');
7+
const { get_process_fs_context } = require('../../../util/native_fs_utils');
8+
const { ConfigFS } = require('../../../sdk/config_fs');
9+
10+
const tmp_fs_path = path.join(TMP_PATH, 'test_config_fs');
11+
const config_root = path.join(tmp_fs_path, 'config_root');
12+
const config_root_backend = config.NSFS_NC_CONFIG_DIR_BACKEND;
13+
const fs_context = get_process_fs_context(config_root_backend);
14+
15+
const config_fs = new ConfigFS(config_root, config_root_backend, fs_context);
16+
17+
describe('adjust_bucket_with_schema_updates', () => {
18+
it('should return undefined on undefined bucket', () => {
19+
const bucket = undefined;
20+
config_fs.adjust_bucket_with_schema_updates(bucket);
21+
expect(bucket).toBeUndefined();
22+
});
23+
24+
it('should return bucket without deprecated properties (system_owner)', () => {
25+
const bucket = {name: 'bucket1', system_owner: 'account1-system-owner'};
26+
config_fs.adjust_bucket_with_schema_updates(bucket);
27+
expect(bucket).toBeDefined();
28+
expect(bucket).not.toHaveProperty('system_owner');
29+
});
30+
});

0 commit comments

Comments
 (0)