Skip to content

Commit cd19105

Browse files
committed
CR changes
Signed-off-by: shirady <[email protected]>
1 parent 48d50d3 commit cd19105

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/endpoint/s3/s3_bucket_policy_utils.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,28 @@ async function _is_object_version_fit(req, predicate, value) {
149149
return res;
150150
}
151151

152-
async function has_bucket_policy_permission(policy, account, method, arn_path, req, disallow_public_access = false,
153-
should_pass_principal = true) {
152+
async function has_bucket_policy_permission(policy, account, method, arn_path, req,
153+
{ disallow_public_access = false, should_pass_principal = true } = {}) {
154154
const [allow_statements, deny_statements] = _.partition(policy.Statement, statement => statement.Effect === 'Allow');
155155

156156
// the case where the permission is an array started in op get_object_attributes
157157
const method_arr = Array.isArray(method) ? method : [method];
158158

159159
// look for explicit denies
160160
const res_arr_deny = await is_statement_fit_of_method_array(
161-
deny_statements, account, method_arr, arn_path, req, undefined, should_pass_principal); // No need to disallow in "DENY"
161+
deny_statements, account, method_arr, arn_path, req, {
162+
disallow_public_access: false, // No need to disallow in "DENY"
163+
should_pass_principal
164+
}
165+
);
162166
if (res_arr_deny.every(item => item)) return 'DENY';
163167

164168
// look for explicit allows
165169
const res_arr_allow = await is_statement_fit_of_method_array(
166-
allow_statements, account, method_arr, arn_path, req, disallow_public_access, should_pass_principal);
170+
allow_statements, account, method_arr, arn_path, req, {
171+
disallow_public_access,
172+
should_pass_principal
173+
});
167174
if (res_arr_allow.every(item => item)) return 'ALLOW';
168175

169176
// implicit deny
@@ -219,13 +226,13 @@ function _is_resource_fit(arn_path, statement) {
219226
}
220227

221228
async function is_statement_fit_of_method_array(statements, account, method_arr, arn_path, req,
222-
disallow_public_access = false, should_pass_principal = true) {
229+
{ disallow_public_access = false, should_pass_principal = true } = {}) {
223230
return Promise.all(method_arr.map(method_permission =>
224-
_is_statements_fit(statements, account, method_permission, arn_path, req, disallow_public_access, should_pass_principal)));
231+
_is_statements_fit(statements, account, method_permission, arn_path, req, { disallow_public_access, should_pass_principal })));
225232
}
226233

227-
async function _is_statements_fit(statements, account, method, arn_path, req, disallow_public_access = false,
228-
should_pass_principal = true) {
234+
async function _is_statements_fit(statements, account, method, arn_path, req,
235+
{ disallow_public_access = false, should_pass_principal = true} = {}) {
229236
for (const statement of statements) {
230237
const action_fit = _is_action_fit(method, statement);
231238
const principal_fit = should_pass_principal ? _is_principal_fit(account, statement, disallow_public_access) : true;

src/endpoint/s3/s3_rest.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,17 @@ async function authorize_request_policy(req) {
301301
// we start the permission check on account identifier intentionally
302302
if (account_identifier_id) {
303303
permission_by_id = await s3_bucket_policy_utils.has_bucket_policy_permission(
304-
s3_policy, account_identifier_id, method, arn_path, req, public_access_block?.restrict_public_buckets);
304+
s3_policy, account_identifier_id, method, arn_path, req,
305+
{ disallow_public_access: public_access_block?.restrict_public_buckets }
306+
);
305307
dbg.log3('authorize_request_policy: permission_by_id', permission_by_id);
306308
}
307309
if (permission_by_id === "DENY") throw new S3Error(S3Error.AccessDenied);
308310

309311
if ((!account_identifier_id || permission_by_id !== "DENY") && account.owner === undefined) {
310312
permission_by_name = await s3_bucket_policy_utils.has_bucket_policy_permission(
311-
s3_policy, account_identifier_name, method, arn_path, req, public_access_block?.restrict_public_buckets
313+
s3_policy, account_identifier_name, method, arn_path, req,
314+
{ disallow_public_access: public_access_block?.restrict_public_buckets }
312315
);
313316
dbg.log3('authorize_request_policy: permission_by_name', permission_by_name);
314317
}
@@ -320,12 +323,12 @@ async function authorize_request_policy(req) {
320323

321324
async function authorize_request_iam_policy(req) {
322325
const auth_token = req.object_sdk.get_auth_token();
323-
const is_anon = !(auth_token && auth_token.access_key);
324-
if (is_anon) return;
326+
const is_anonymous = !(auth_token && auth_token.access_key);
327+
if (is_anonymous) return;
325328

326329
const account = req.object_sdk.requesting_account;
327330
const is_iam_user = account.owner !== undefined;
328-
if (!is_iam_user) return;
331+
if (!is_iam_user) return; // IAM policy is only on IAM users (account root user is authorized here)
329332

330333
const resource_arn = _get_arn_from_req_path(req);
331334
const method = _get_method_from_req(req);
@@ -337,7 +340,8 @@ async function authorize_request_iam_policy(req) {
337340
for (const iam_policy of iam_policies) {
338341
// We reusing the bucket policy util function as it is checks the policy document
339342
const promise = s3_bucket_policy_utils.has_bucket_policy_permission(
340-
iam_policy.policy_document, undefined, method, resource_arn, req, undefined, false
343+
iam_policy.policy_document, undefined, method, resource_arn, req,
344+
{ should_pass_principal: false }
341345
);
342346
promises.push(promise);
343347
}
@@ -358,7 +362,9 @@ async function authorize_anonymous_access(s3_policy, method, arn_path, req, publ
358362
if (!s3_policy) throw new S3Error(S3Error.AccessDenied);
359363

360364
const permission = await s3_bucket_policy_utils.has_bucket_policy_permission(
361-
s3_policy, undefined, method, arn_path, req, public_access_block?.restrict_public_buckets);
365+
s3_policy, undefined, method, arn_path, req,
366+
{ disallow_public_access: public_access_block?.restrict_public_buckets }
367+
);
362368
if (permission === "ALLOW") return;
363369

364370
throw new S3Error(S3Error.AccessDenied);

src/sdk/bucketspace_fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
951951
action,
952952
`arn:aws:s3:::${bucket.name.unwrap()}${bucket_path}`,
953953
undefined,
954-
bucket.public_access_block?.restrict_public_buckets,
954+
{ disallow_public_access: bucket.public_access_block?.restrict_public_buckets }
955955
);
956956
if (permission_by_id === "DENY") return false;
957957
// we (currently) allow account identified to be both id and name,
@@ -963,7 +963,7 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
963963
action,
964964
`arn:aws:s3:::${bucket.name.unwrap()}${bucket_path}`,
965965
undefined,
966-
bucket.public_access_block?.restrict_public_buckets,
966+
{ disallow_public_access: bucket.public_access_block?.restrict_public_buckets }
967967
);
968968
}
969969
if (permission_by_name === 'DENY') return false;

0 commit comments

Comments
 (0)