Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/api/bucket_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,9 @@ module.exports = {
bucket_owner: {
$ref: 'common_api#/definitions/email'
},
bucket_owner_id: {
type: 'string'
},
website: {
$ref: 'common_api#/definitions/bucket_website'
},
Expand Down
13 changes: 9 additions & 4 deletions src/endpoint/s3/s3_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async function authorize_request_policy(req) {
s3_policy,
system_owner,
bucket_owner,
bucket_owner_id,
owner_account,
public_access_block,
} = await req.object_sdk.read_bucket_sdk_policy_info(req.params.bucket);
Expand All @@ -253,8 +254,9 @@ async function authorize_request_policy(req) {
}

const account = req.object_sdk.requesting_account;
const account_identifier_name = req.object_sdk.nsfs_config_root ? account.name.unwrap() : account.email.unwrap();
const account_identifier_id = req.object_sdk.nsfs_config_root ? account._id : undefined;
const is_nc_deployment = req.object_sdk.nsfs_config_root;
const account_identifier_name = is_nc_deployment ? account.name.unwrap() : account.email.unwrap();
const account_identifier_id = is_nc_deployment ? account._id : undefined;
const account_identifier_arn = s3_bucket_policy_utils.get_bucket_policy_principal_arn(account);

// deny delete_bucket permissions from bucket_claim_owner accounts (accounts that were created by OBC from openshift\k8s)
Expand Down Expand Up @@ -286,8 +288,11 @@ async function authorize_request_policy(req) {
if (!s3_policy) {
// in case we do not have bucket policy
// we allow IAM account to access a bucket that is owned by their root account
const is_iam_account_and_same_root_account_owner = account.owner !== undefined &&
owner_account && account.owner === owner_account.id;
let is_iam_account_and_same_root_account_owner = false;
if (account.owner !== undefined) {
const owner_account_to_compare = is_nc_deployment ? (owner_account && owner_account.id) : bucket_owner_id;
is_iam_account_and_same_root_account_owner = account.owner === owner_account_to_compare;
}
if (is_owner || is_iam_account_and_same_root_account_owner) return;
throw new S3Error(S3Error.AccessDenied);
}
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/object_sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ class ObjectSDK {
s3_policy: bucket.s3_policy,
system_owner: bucket.system_owner, // note that bucketspace_fs currently doesn't return system_owner
bucket_owner: bucket.bucket_owner,
owner_account: bucket.owner_account, // in NC NSFS this is the account id that owns the bucket
bucket_owner_id: bucket.bucket_owner_id, // in containerized this is the account id that owns the bucket
owner_account: bucket.owner_account, // in NC NSFS this is an object of account id and name that owns the bucket
public_access_block: bucket.public_access_block,
};
return policy_info;
Expand Down
8 changes: 7 additions & 1 deletion src/server/common_services/auth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,13 @@ async function has_bucket_action_permission(bucket, account, action, req_query,
(account.bucket_claim_owner && account.bucket_claim_owner.name.unwrap() === bucket.name.unwrap());
const bucket_policy = bucket.s3_policy;

if (!bucket_policy) return is_owner;
if (!bucket_policy) {
// in case we do not have bucket policy
// we allow IAM account to access a bucket that that is owned by their root account
const is_iam_and_same_root_account_owner = account.owner !== undefined &&
account.owner._id.toString() === bucket.owner_account._id.toString();
return is_owner || is_iam_and_same_root_account_owner;
}
if (!action) {
throw new Error('has_bucket_action_permission: action is required');
}
Expand Down
1 change: 1 addition & 0 deletions src/server/system_services/bucket_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ async function read_bucket_sdk_info(req) {
s3_policy: bucket.s3_policy,
system_owner: bucket.system.owner.email,
bucket_owner: bucket.owner_account.email,
bucket_owner_id: bucket.owner_account._id.toString(),
bucket_info: await P.map_props({
bucket,
nodes_aggregate_pool: bucket.tiering && nodes_client.instance().aggregate_nodes_by_pool(pool_names, system._id),
Expand Down