Skip to content

Commit 58ad973

Browse files
committed
NSFS | add configuration flag to enable dinamic supplemental groups allocation
Signed-off-by: nadav mizrahi <nadav.mizrahi16@gmail.com>
1 parent 937075f commit 58ad973

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

config.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ config.NSFS_CONTENT_DIRECTORY_VERSIONING_ENABLED = false;
823823
config.NSFS_EXIT_EVENTS_TIME_FRAME_MIN = 24 * 60; // per day
824824
config.NSFS_MAX_EXIT_EVENTS_PER_TIME_FRAME = 10; // allow max 10 failed forks per day
825825

826+
config.NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS = 'true';
827+
826828
config.NSFS_GLACIER_LOGS_DIR = '/var/run/noobaa-nsfs/wal';
827829
config.NSFS_GLACIER_LOGS_POLL_INTERVAL = 10 * 1000;
828830

@@ -1106,6 +1108,18 @@ function _get_config_root() {
11061108
return config_root;
11071109
}
11081110

1111+
/**
1112+
* go over the config object and set the relevant configurations as environment variables
1113+
*/
1114+
function _set_nc_config_to_env() {
1115+
const config_to_env = ['NOOBAA_LOG_LEVEL', 'UV_THREADPOOL_SIZE', 'GPFS_DL_PATH', 'NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS'];
1116+
Object.values(config_to_env).forEach(function(key) {
1117+
if (config[key] !== undefined) {
1118+
process.env[key] = config[key];
1119+
}
1120+
});
1121+
}
1122+
11091123
/**
11101124
* validate_nc_master_keys_config validates the following -
11111125
* 1. if type is file -
@@ -1155,11 +1169,6 @@ function load_nsfs_nc_config() {
11551169
const merged_config = _.merge(shared_config, node_config || {});
11561170

11571171
Object.keys(merged_config).forEach(function(key) {
1158-
const config_to_env = ['NOOBAA_LOG_LEVEL', 'UV_THREADPOOL_SIZE', 'GPFS_DL_PATH'];
1159-
if (config_to_env.includes(key)) {
1160-
process.env[key] = merged_config[key];
1161-
return;
1162-
}
11631172
config[key] = merged_config[key];
11641173
});
11651174
console.warn(`nsfs: config_dir_path=${config.NSFS_NC_CONF_DIR}`);
@@ -1171,6 +1180,7 @@ function load_nsfs_nc_config() {
11711180
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ENOENT') throw err;
11721181
console.warn('config.load_nsfs_nc_config could not find config.json... skipping');
11731182
}
1183+
_set_nc_config_to_env();
11741184
}
11751185
/**
11761186
* reload_nsfs_nc_config reloads on non containerized env the config.json file every 10 seconfs

docs/NooBaaNonContainerized/AccountsAndBuckets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ See all available account properties - [NC Account Schema](../../src/server/syst
3232
- `uid/gid/user` - An account's access key is mapped to a file system uid/gid (or user). Before performing any file system operation, NooBaa switches to the account's UID/GID, ensuring that accounts access to buckets and objects is enforced by the file system.
3333

3434
- `supplemental_groups` - In addition to the account main GID, an account can have supplementary group IDs that are used to determine permissions for accessing files. These GIDs are validated against a files group (GID) permissions.
35-
By default, supplemental groups are based on user's groups in the filesystem. In case this value was set in the CLI it will override the user's groups in the filesystem. In case this value was not set in account configuration (in the CLI) and failed to fetch the user's group in the filesystem (either because no record exists or because the operation failed), supplemental groups will be unset.
35+
By default, supplemental groups are based on user's groups in the filesystem. In case this value was set in the CLI it will override the user's groups in the filesystem. In case this value was not set in account configuration (in the CLI) and failed to fetch the user's group in the filesystem (either because no record exists or because the operation failed), supplemental groups will be unset. You can disable fetching groups from users record in the filesystem by setting NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS to be `false` in config.json. In this case the default would be to unset supplemental groups entirely.
3636
Note: Depending on the file system there may be 'sticky bit' enabled somewhere on the files path. 'sticky bit' is a user ownership access right flag that prevents other users than the file owner and root from deleting or moving files.
3737
In that case some actions will still get access denied regardless of group permissions enabled. sticky bit is denoted by `t` at the end of the permissions list (example: `drwxrwxrwt`). see https://en.wikipedia.org/wiki/Sticky_bit
3838

docs/NooBaaNonContainerized/ConfigFileCustomizations.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,20 @@ Warning: After setting this configuration, NooBaa will skip schema validations a
506506
3. systemctl restart noobaa
507507
```
508508
509+
### 34. Dynamic supplemental groups allocation flag -
510+
* <u>Key</u>: `NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS`
511+
* <u>Type</u>: boolean
512+
* <u>Default</u>: true
513+
* <u>Description</u>: whether to fetch supplemental groups dynamicly from FS user record.
514+
* <u>Steps</u>:
515+
```
516+
1. Open /path/to/config_dir/config.json file.
517+
2. Set the config key -
518+
Example:
519+
"NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS": false
520+
3. systemctl restart noobaa
521+
```
522+
509523
## Config.json File Examples
510524
The following is an example of a config.json file -
511525

src/native/util/os_darwin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ static void
8080
set_supplemental_groups(uid_t uid, gid_t gid, std::vector<gid_t>& groups) {
8181
//first check if groups were defined in the account configuration
8282
if (groups.empty()) {
83-
if (get_supplemental_groups_by_uid(uid, groups) < 0) {
83+
const char* is_enabled = getenv("NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS");
84+
if ((is_enabled == NULL) || (strcmp(is_enabled, "true") != 0) || get_supplemental_groups_by_uid(uid, groups) < 0) {
8485
//aready unset by _mac_thread_setugid
8586
return;
8687
}

src/native/util/os_linux.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ static void
6565
set_supplemental_groups(uid_t uid, std::vector<gid_t>& groups) {
6666
//first check if groups were defined in the account configuration
6767
if (groups.empty()) {
68-
if (get_supplemental_groups_by_uid(uid, groups) < 0) {
68+
const char* is_enabled = getenv("NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS");
69+
if ((is_enabled == NULL) || (strcmp(is_enabled, "true") != 0) || get_supplemental_groups_by_uid(uid, groups) < 0) {
6970
//couldn't get supplemental groups dynamically. set it to be an empty set
7071
MUST_SYS(syscall(SYS_setgroups, 0, NULL));
7172
return;

src/test/unit_tests/test_nsfs_access.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ mocha.describe('new tests check', async function() {
162162
assert.equal(err.code, 'EACCES');
163163
}
164164
});
165+
166+
mocha.it('NON ROOT 4 with disabled dynamicly suplemental groups - failure', async function() {
167+
try {
168+
process.env.NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS = 'false';
169+
const non_root_entries = await nb_native().fs.readdir(NON_ROOT4_FS_CONFIG, full_path_non_root1);
170+
assert.fail(`non root 4 has access to a folder with disabled supplemental groups - ${p} ${non_root_entries}`);
171+
} catch (err) {
172+
assert.equal(err.code, 'EACCES');
173+
}
174+
process.env.NSFS_ENABLE_DYNAMIC_SUPPLEMENTAL_GROUPS = 'true';
175+
});
165176
});
166177

167178

0 commit comments

Comments
 (0)