Skip to content

Commit 5b07689

Browse files
authored
Merge pull request #8312 from shirady/nsfs-nc-config-dir-restructure-users-dir
NC | NSFS | Config Dir Restructure - Add `users/` Dir
2 parents c9876e6 + 98598e7 commit 5b07689

File tree

10 files changed

+844
-348
lines changed

10 files changed

+844
-348
lines changed

docs/NooBaaNonContainerized/Configuration.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ For Developers - Use `--config_root` flag for specifying a custom configuration
4949

5050
### Configuration files permissions
5151
Mode
52-
* Configuration files generated under the `accounts/` or `buckets/` directories will have 600 permissions, granting read and write access exclusively to the owner of each configuration file.
52+
* Configuration files generated under the `identities/` or `buckets/` directories will have 600 permissions, granting read and write access exclusively to the owner of each configuration file.
5353

5454
Ownership
5555
* Configuration file created by the NooBaa CLI tool will be owned by the user who ran the NooBaa CLI command.
@@ -62,8 +62,9 @@ The default config directory structure contains the following files/directories
6262
> sudo ls /etc/noobaa.conf.d/
6363
system.json // Required
6464
access_keys/ // Required
65-
accounts/ // Required
65+
accounts_by_name/ // Required
6666
buckets/ // Required
67+
identities/ // Required
6768
config.json // Optional
6869
master_keys.json // Optional
6970
certificates/ // Optional
@@ -81,8 +82,9 @@ config_dir_redirect // Required
8182
> sudo ls /path/to/custom/config/dir/
8283
system.json // Required
8384
access_keys/ // Required
84-
accounts/ // Required
85+
accounts_by_name/ // Required
8586
buckets/ // Required
87+
identities/ // Required
8688
config.json // Optional
8789
master_keys.json // Optional
8890
certificates/ // Optional
@@ -113,29 +115,33 @@ certificates/ // Optional
113115
}
114116
}
115117
```
116-
`accounts/` -
118+
119+
`accounts_by_name/`
117120
* <u>Type</u>: Directory.
118121
* <u>Required</u>: Yes.
119-
* <u>Description</u>: A directory that contains configuration files for individual accounts, each account configuration file is named {account_name}.json and adheres to the [account schema](../../src/server/system_services/schemas/nsfs_account_schema.js).
122+
* <u>Description</u>: A directory that contains symlinks to accounts configurations, each symlink named
123+
{account_name}.symlink, linking to the account config within `identities/<account-id>` directory,
124+
configuration file is named identity.json and adheres to the [account schema](../../src/server/system_services/schemas/nsfs_account_schema.js). The account name symlink points to a relative path of the account rather than an absolute path, for example: `../identities/1111/identity.json`.
120125
* <u>Example</u>:
121126
```sh
122-
> ls /etc/noobaa.conf.d/accounts/
123-
alice.json
124-
bob.json
125-
charlie.json
127+
> ls /etc/noobaa.conf.d/accounts_by_name/
128+
alice.symlink -> ../identities/1111/identity.json
129+
bob.symlink -> ../identities/2222/identity.json
130+
charlie.symlink -> ../identities/333/identity.json
126131
```
127132

128133
`access_keys/`
129134
* <u>Type</u>: Directory.
130135
* <u>Required</u>: Yes.
131-
* <u>Description</u>: A directory that contains symlinks to accounts configurations, each symlink named {access_key}.symlink, linking to an account within `accounts/` directory. The access key symlink points to a relative path of the account rather than an absolute path, for example: `../accounts/alice.json`.
136+
* <u>Description</u>: A directory that contains symlinks to accounts configurations, each symlink named {access_key}.symlink, linking to an account within `identities/<account-id>/` directory. The access key symlink points to a relative path of the account rather than an absolute path, for example: `../identities/3333/identity.json`.
132137
* <u>Example</u>:
133138
```sh
134139
> ls -la /etc/noobaa.conf.d/access_keys/
135-
0kbUZlNM9k4SCvrw1pftEXAMPLE.symlink -> ../accounts/alice.json
136-
1kbUTlNM9k4SCvrw2pfxEXAMPLE.symlink -> ../accounts/bob.json
137-
2kbUMlNM9k4SCvrw3pfyEXAMPLE.symlink -> ../accounts/charlie.json
140+
0kbUZlNM9k4SCvrw1pftEXAMPLE.symlink -> ../identities/3333/identity.json
141+
1kbUTlNM9k4SCvrw2pfxEXAMPLE.symlink -> ../identities/1111/identity.json
142+
2kbUMlNM9k4SCvrw3pfyEXAMPLE.symlink -> ../identities/2222/identity.json
138143
```
144+
139145
`buckets/`
140146
* <u>Type</u>: Directory.
141147
* <u>Required</u>: Yes.
@@ -147,6 +153,23 @@ certificates/ // Optional
147153
bucket2.json
148154
bucket3.json
149155
```
156+
157+
`identities/`
158+
* <u>Type</u>: Directory.
159+
* <u>Required</u>: Yes.
160+
* <u>Description</u>: A directory that contains configuration files for individual identities, each identity configuration file is named {identity}.json. In case the identity is an account it adheres to the [account schema](../../src/server/system_services/schemas/nsfs_account_schema.js).
161+
* <u>Example</u>:
162+
```sh
163+
> tree /etc/noobaa.conf.d/identities/
164+
/etc/noobaa.conf.d/identities
165+
├── 1111
166+
│   └── identity.json
167+
└── 2222
168+
└── identity.json
169+
└── 3333
170+
└── identity.json
171+
```
172+
150173
`config.json`
151174
* <u>Type</u>: File.
152175
* <u>Required</u>: No.

docs/NooBaaNonContainerized/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NooBaa Non Containerized solution includes the following components -
3131
5. [Storage File System](#create-storage-file-system-paths) - A File system for storing objects.
3232

3333
### NooBaa High Level Diagram
34-
![NooBaa Non Containerized Components Diagram](https://github.com/noobaa/noobaa-core/assets/35330373/8d6cce71-e9e8-4e6a-ad88-5c65255bacc7)
34+
![NooBaa Non Containerized Components Diagram](https://github.com/user-attachments/assets/dad9ecc8-7d8f-46cb-a832-4fc7e40a640d)
3535

3636

3737
## Build NooBaa RPM

docs/design/iam.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,76 @@ Here attached a diagram with all the accounts that we have in our system:
127127
- IAM DeleteAccessKey: AccessKeyId, UserName
128128
- IAM ListAccessKeys: UserName (not supported: Marker, MaxItems)
129129

130+
### Configuration Directory Components With users
131+
If account creates a user its config file will be created under identities/<user-id>.identity.json and under the account will be created `users/` directory and inside it it will link to the config.
132+
Example:
133+
Note: In this example, we didn't use `system.json`, `config.json`, and `certificates/`.
134+
1. Configuration directory with 1 account (name: alice, ID: 1111):
135+
136+
```sh
137+
> tree /etc/noobaa.conf.d/
138+
├── access_keys
139+
│   └── Zzto3OwtGflQrqD41h3SEXAMPLE.symlink -> ../identities/1111/identity.json
140+
├── accounts_by_name
141+
│   └── alice.symlink -> ../identities/1111/identity.json
142+
├── buckets
143+
├── identities
144+
│   └── 1111
145+
│   └── identity.json
146+
└── master_keys.json
147+
```
148+
149+
2. Configuration directory with 1 account (name: alice, ID: 1111) and 1 user (name: Robert, ID: 9999, without access key) -
150+
Notice the `users/` directory with a symlink of the username to its config file
151+
152+
```sh
153+
├── access_keys
154+
│   └── Zzto3OwtGflQrqD41h3SEXAMPLE.symlink -> ../identities/1111/identity.json
155+
├── accounts_by_name
156+
│   └── alice.symlink -> ../identities/1111/identity.json
157+
├── buckets
158+
├── identities
159+
│   ├── 1111
160+
│   │   ├── identity.json
161+
│   │   └── users
162+
│   │   └── Robert.symlink -> ../../9999/identity.json
163+
│   └── 9999
164+
│   └── identity.json
165+
├── master_keys.json
166+
└── system.json
167+
```
168+
169+
#### Naming Scope
170+
- Account names are unique between the accounts, for example, if we have account with name John, you cannot create a new account with the name John (and also cannot update the name of an existing account to John).
171+
- Usernames are unique only inside the account, for example: username Robert can be under account-1, and another user with username Robert can be under account-2.
172+
Note: The username cannot be the same as the account, for example: under account John we cannot create a username John (and also cannot update the name of an existing username to John). The reason for limiting it is that in the IAM API of Access Key (for example ListAccessKeys) it can be done by account on himself or on another user, and it passes the `--user-name` flag.
173+
174+
Example: 2 accounts (alice and bob) both of them have user with username Robert (notice the different ID number).
175+
```sh
176+
├── access_keys
177+
│   ├── Zzto3OwtGflQrqD41h3SEXAMPLE.symlink -> ../identities/66d81ec79eac82ed43cdee73/identity.json
178+
│   └── Yser45gyHaghebY62wsUEXAMPLE.symlink -> ../identities/66d8351a92b8dd91b550aa71/identity.json
179+
├── accounts_by_name
180+
│   ├── alice.symlink -> ../identities/66d81ec79eac82ed43cdee73/identity.json
181+
│   └── bob.symlink -> ../identities/66d8351a92b8dd91b550aa71/identity.json
182+
├── buckets
183+
├── identities
184+
│   ├── 66d81ec79eac82ed43cdee73
185+
│   │   ├── identity.json
186+
│   │   └── users
187+
│   │   └── Robert.symlink -> ../../66d834df78e973023abd80cb/identity.json
188+
│   ├── 66d834df78e973023abd80cb
189+
│   │   └── identity.json
190+
│   ├── 66d8351a92b8dd91b550aa71
191+
│   │   ├── identity.json
192+
│   │   └── users
193+
│   │   └── Robert.symlink -> ../../66d83529e09267f53e705373/identity.json
194+
│   └── 66d83529e09267f53e705373
195+
│   └── identity.json
196+
├── master_keys.json
197+
└── system.json
198+
```
199+
130200
## Other
131201
### Terminology - AWS vs NooBaa
132202
| | AWS | NooBaa |

src/endpoint/iam/iam_utils.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@ function format_iam_xml_date(input) {
1919
}
2020

2121
/**
22-
* create_arn creates the AWS ARN for user
22+
* create_arn_for_root creates the AWS ARN for root account user
23+
* see: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns
24+
* @param {string} account_id (the root user account id)
25+
*/
26+
function create_arn_for_root(account_id) {
27+
return `arn:aws:iam::${account_id}:root`;
28+
29+
}
30+
31+
/**
32+
* create_arn_for_user creates the AWS ARN for user
2333
* see: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns
2434
* @param {string} account_id (the root user account id)
2535
* @param {string} username
2636
* @param {string} iam_path
2737
*/
28-
function create_arn(account_id, username, iam_path) {
38+
function create_arn_for_user(account_id, username, iam_path) {
2939
const basic_structure = `arn:aws:iam::${account_id}:user`;
3040
if (username === undefined) return `${basic_structure}/`;
3141
if (check_iam_path_was_set(iam_path)) {
@@ -508,7 +518,8 @@ function validate_status(input_status) {
508518

509519
// EXPORTS
510520
exports.format_iam_xml_date = format_iam_xml_date;
511-
exports.create_arn = create_arn;
521+
exports.create_arn_for_user = create_arn_for_user;
522+
exports.create_arn_for_root = create_arn_for_root;
512523
exports.get_action_message_title = get_action_message_title;
513524
exports.check_iam_path_was_set = check_iam_path_was_set;
514525
exports.parse_max_items = parse_max_items;

src/endpoint/s3/s3_rest.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,17 @@ async function authorize_request_policy(req) {
243243
if (is_system_owner) return;
244244

245245
const is_owner = (function() {
246+
// Containerized condition for bucket ownership
247+
// 1. by bucket_claim_owner
248+
// 2. by email
246249
if (account.bucket_claim_owner && account.bucket_claim_owner.unwrap() === req.params.bucket) return true;
250+
// NC conditions for bucket ownership
251+
// 1. by ID (when creating the bucket the owner is always an account) - comparison to ID which is unique
252+
// 2. by name - account_identifier can be username which is not unique
253+
// to make sure it is only on accounts (account names are unique) we check there's no account's ownership
247254
if (owner_account && owner_account.id === account._id) return true;
248-
if (account_identifier_name === bucket_owner.unwrap()) return true; // TODO: change it to root accounts after we will have the /users structure
255+
// checked last on purpose (NC first checks the ID and then name for backward computability)
256+
if (account.owner === undefined && account_identifier_name === bucket_owner.unwrap()) return true; // mutual check
249257
return false;
250258
}());
251259

@@ -267,7 +275,7 @@ async function authorize_request_policy(req) {
267275
s3_policy, account_identifier_id, method, arn_path, req);
268276
}
269277

270-
if (!account_identifier_id || permission === "IMPLICIT_DENY") {
278+
if ((!account_identifier_id || permission === "IMPLICIT_DENY") && account.owner === undefined) {
271279
permission = await s3_bucket_policy_utils.has_bucket_policy_permission(
272280
s3_policy, account_identifier_name, method, arn_path, req);
273281
}

0 commit comments

Comments
 (0)