Skip to content

Commit 033bcf1

Browse files
committed
test case fix
1 parent 1a1ff98 commit 033bcf1

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/endpoint/s3/s3_rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async function authorize_request_policy(req) {
307307
}
308308
if (permission_by_id === "DENY") throw new S3Error(S3Error.AccessDenied);
309309

310-
if (!account_identifier_id || permission_by_id !== "DENY") {
310+
if ((!account_identifier_id || permission_by_id !== "DENY") && !req.object_sdk.nsfs_config_root) {
311311
permission_by_name = await s3_bucket_policy_utils.has_bucket_policy_permission(
312312
s3_policy, arn, method, arn_path, req, public_access_block?.restrict_public_buckets
313313
);

src/server/system_services/bucket_server.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const bucket_semaphore = new KeysSemaphore(1);
4040
const Quota = require('../system_services/objects/quota');
4141
const { STORAGE_CLASS_GLACIER_IR } = require('../../endpoint/s3/s3_utils');
4242
const noobaa_s3_client = require('../../sdk/noobaa_s3_client/noobaa_s3_client');
43+
const string_utils = require('../../util/string_utils');
4344

4445
const VALID_BUCKET_NAME_REGEXP =
4546
/^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$/;
@@ -516,26 +517,25 @@ async function get_bucket_policy(req) {
516517
/*
517518
validate ARN principle
518519
1. validate basic ARN, like arn prefix `arn:aws:iam::`
519-
2. If principal ARN end with `root sufix its a account and get account with id eg : aws:arn:${account_id}:root
520+
2. If principal ARN end with `root sufix its a account and get account with id eg : arn:aws:iam::${account_id}:root
520521
3. if principle ARN contains `user` its a IAM user and get account with username and id
521-
eg : aws:arn:${account_id}:user/${iam_path}/${use_name}
522+
eg : arn:aws:iam::${account_id}:user/${iam_path}/${use_name}
522523
account email = ${iam_user_name}:${account_id}
523524
*/
524525
async function principal_validation_handler(principal) {
525526
const principal_as_string = principal instanceof SensitiveString ? principal.unwrap() : principal;
526-
const arn_prefix = 'arn:aws:iam::';
527527
const root_sufix = 'root';
528528
const user_sufix = 'user';
529529
const arn_parts = principal_as_string.split(':');
530-
if (!principal_as_string.startsWith(arn_prefix) || arn_parts.length < 6) {
530+
if (!string_utils.AWS_ARN_REGEXP.test(principal_as_string)) {
531531
return;
532532
}
533533
const account_id = arn_parts[4];
534534
if (principal_as_string.endsWith(root_sufix)) {
535535
return system_store.data.accounts.find(account => account._id.toString() === account_id);
536-
} else if (principal_as_string.includes(user_sufix)) {
536+
} else if (arn_parts[5] && arn_parts[5].startsWith(user_sufix)) {
537537
const arn_path_parts = principal_as_string.split('/');
538-
const iam_user_name = arn_path_parts[arn_path_parts.length - 1];
538+
const iam_user_name = arn_path_parts[arn_path_parts.length - 1].trim();
539539
return system_store.get_account_by_email(new SensitiveString(`${iam_user_name}:${account_id}`));
540540
}
541541
}

src/test/integration_tests/nsfs/test_nsfs_integration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ mocha.describe('bucket operations - namespace_fs', function() {
205205
mocha.it('list buckets without uid, gid', async function() {
206206
this.timeout(600000); // eslint-disable-line no-invalid-this
207207
// Give s3_owner access to the required buckets
208-
const generated = generate_s3_policy(EMAIL, first_bucket, ['s3:*']);
208+
const account_info_admin = await rpc_client.account.read_account({ email: EMAIL });
209+
const generated = generate_s3_policy(`arn:aws:iam::${account_info_admin._id.toString()}:root`, first_bucket, ['s3:*']);
209210
await rpc_client.bucket.put_bucket_policy({ name: first_bucket, policy: generated.policy });
210211

211212
const res = await s3_owner.listBuckets({});

src/util/string_utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const AWS_IAM_ACCESS_KEY_INPUT_REGEXP = /^[\w]+$/;
1818
const AWS_IAM_TAG_KEY_AND_VALUE_REGEXP = /^[\p{L}\p{Z}\p{N}_.:/=+\-@]+$/u;
1919
const AWS_POLICY_NAME_REGEXP = /^[\w+=,.@-]+$/;
2020
const AWS_POLICY_DOCUMENT_REGEXP = /^[\u0009\u000A\u000D\u0020-\u00FF]+$/;
21+
const AWS_ARN_REGEXP = /^arn:aws:iam::\w{10,}:(?:user|root)(?:\/[\w\d\-\_\.\/]+$)?/;
2122

2223
function crypto_random_string(len, charset = ALPHA_NUMERIC_CHARSET) {
2324
// In order to not favor any specific chars over others we limit the maximum random value
@@ -171,3 +172,4 @@ exports.AWS_IAM_ACCESS_KEY_INPUT_REGEXP = AWS_IAM_ACCESS_KEY_INPUT_REGEXP;
171172
exports.AWS_IAM_TAG_KEY_AND_VALUE_REGEXP = AWS_IAM_TAG_KEY_AND_VALUE_REGEXP;
172173
exports.AWS_POLICY_NAME_REGEXP = AWS_POLICY_NAME_REGEXP;
173174
exports.AWS_POLICY_DOCUMENT_REGEXP = AWS_POLICY_DOCUMENT_REGEXP;
175+
exports.AWS_ARN_REGEXP = AWS_ARN_REGEXP;

0 commit comments

Comments
 (0)