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
2 changes: 1 addition & 1 deletion src/cmd/nsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async function main(argv = minimist(process.argv.slice(2))) {
const sts_bucketspace = nsfs_config_root ?
new BucketSpaceFS({ config_root: nsfs_config_root }, endpoint_stats_collector.instance()) :
new BucketSpaceSimpleFS({ fs_root });
req.sts_sdk = new StsSDK(null, null, sts_bucketspace);
req.sts_sdk = new StsSDK(null, null, sts_bucketspace, req.object_sdk.accountspace);
}
});
if (config.ALLOW_HTTP) {
Expand Down
11 changes: 9 additions & 2 deletions src/endpoint/iam/iam_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ async function _get_identity_policies(account, is_iam_user, assumed_role_arn, bu
return account.iam_user_policies || [];
}
const resolved_role = await resolve_iam_role_by_arn(assumed_role_arn, bucketspace);
if (!resolved_role.iam_role) return null;
if (!resolved_role?.iam_role) return null;
return resolved_role.iam_role.iam_role_policies || [];
}

Expand Down Expand Up @@ -1398,12 +1398,19 @@ async function authorize_request_iam_policy_impl(req, method, bucket_name, servi
};

const iam_policies = await _get_identity_policies(
account, is_iam_user, assumed_role_arn, req.object_sdk?._get_bucketspace());
account,
is_iam_user,
assumed_role_arn,
req.object_sdk?._get_bucketspace(),
Comment thread
sakshimunjal marked this conversation as resolved.
);
if (iam_policies === null) {
dbg.error('authorize_request_iam_policy: failed to resolve IAM role for assumed session token');
return deny_result;
}
if (iam_policies.length === 0) {
// TODO: remove NC empty-policy allow when PutRolePolicy (Phase 2) is implemented
// NC: IAM user / role inline policies are Phase 2; allow until PutRolePolicy exists
Comment thread
sakshimunjal marked this conversation as resolved.
if (req.object_sdk.nsfs_config_root && (is_iam_user || is_assumed_role_session)) return true;
dbg.error('authorize_request_iam_policy:', iam_identity, 'has no inline policies configured');
return deny_result;
}
Expand Down
9 changes: 9 additions & 0 deletions src/manage_nsfs/manage_nsfs_cli_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ ManageCLIError.AccountDeleteForbiddenHasIAMAccounts = Object.freeze({
http_code: 403,
});

ManageCLIError.AccountDeleteForbiddenHasIAMRoles = Object.freeze({
code: 'AccountDeleteForbiddenHasIAMRoles',
message: 'Cannot delete account that is owner of IAM roles. ' +
'You must delete all IAM roles before deleting the account',
http_code: 403,
});

ManageCLIError.AccountCannotCreateRootAccountsRequesterIAMUser = Object.freeze({
code: 'AccountCannotCreateRootAccounts',
message: 'Cannot update account to have iam_operate_on_root_account. ' +
Expand Down Expand Up @@ -591,6 +598,8 @@ const NSFS_CLI_ERROR_EVENT_MAP = {
AccountAccessKeyAlreadyExists: NoobaaEvent.ACCOUNT_ALREADY_EXISTS,
AccountNameAlreadyExists: NoobaaEvent.ACCOUNT_ALREADY_EXISTS,
AccountDeleteForbiddenHasBuckets: NoobaaEvent.ACCOUNT_DELETE_FORBIDDEN,
AccountDeleteForbiddenHasIAMAccounts: NoobaaEvent.ACCOUNT_DELETE_FORBIDDEN,
Comment thread
shirady marked this conversation as resolved.
AccountDeleteForbiddenHasIAMRoles: NoobaaEvent.ACCOUNT_DELETE_FORBIDDEN,
Comment thread
sakshimunjal marked this conversation as resolved.
BucketAlreadyExists: NoobaaEvent.BUCKET_ALREADY_EXISTS,
BucketSetForbiddenBucketOwnerNotExists: NoobaaEvent.BUCKET_OWNER_NOT_EXISTS,
BucketSetForbiddenBucketOwnerIsIAMAccount: NoobaaEvent.BUCKET_OWNER_IS_IAM_ACCOUNT,
Expand Down
16 changes: 16 additions & 0 deletions src/manage_nsfs/manage_nsfs_validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ async function validate_account_args(config_fs, data, action, is_flag_iam_operat
* doesn't have resources related to it
* 1 - buckets that it owns
* 2 - accounts that it owns
* 3 - IAM roles that it owns (under identities/<account_id>/roles)
* @param {import('../sdk/config_fs').ConfigFS} config_fs
* @param {object} data
*/
Expand All @@ -661,6 +662,21 @@ async function validate_account_resources_before_deletion(config_fs, data) {
// If it is root account (not owned by other account) then we check that it doesn't owns IAM accounts
if (data.owner === undefined) {
await check_if_root_account_does_not_have_IAM_users(config_fs, data, ACTIONS.DELETE);
await validate_account_not_owns_roles(config_fs, data);
}
}

/**
* validate_account_not_owns_roles blocks account deletion when
* identities/<account_id>/roles contains any role entries.
* @param {import('../sdk/config_fs').ConfigFS} config_fs
* @param {Object} account_data
*/
async function validate_account_not_owns_roles(config_fs, account_data) {
const role_names = await config_fs.list_roles_under_account(account_data._id);
if (role_names.length > 0) {
const detail_msg = `Account ${account_data.name} has IAM roles: ${role_names.join(', ')}`;
throw_cli_error(ManageCLIError.AccountDeleteForbiddenHasIAMRoles, detail_msg);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/manage_nsfs/nsfs_schema_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const validate_logging = ajv.compile(log_schema);

/**
* validate_account_schema validates an account object against the NC NSFS account schema
* Same schema used for account (root account), IAM user and IAM role
* @param {object} account
*/
function validate_account_schema(account) {
Expand Down
Loading