Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/api/account_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,10 @@ module.exports = {
nsfs_account_config: {
$ref: 'common_api#/definitions/nsfs_account_config'
},
iam_user_policies: {
iam_inline_policies: {
type: 'array',
items: {
$ref: 'common_api#/definitions/iam_user_policy',
$ref: 'common_api#/definitions/iam_inline_policy',
}
},
owner: {
Expand Down Expand Up @@ -1644,10 +1644,10 @@ module.exports = {
owner_access_key: {
$ref: 'common_api#/definitions/access_key'
},
iam_role_policies: {
iam_inline_policies: {
type: 'array',
items: {
$ref: 'common_api#/definitions/iam_user_policy',
$ref: 'common_api#/definitions/iam_inline_policy',
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/api/common_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ module.exports = {
enum: ['DISABLED', 'SUSPENDED', 'ENABLED']
},

identity_type: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will make this field name consistent in NC. I had used 'type', will rename to 'identity_type'

type: 'string',
enum: ['ACCOUNT', 'USER', 'ROLE']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we planning to add type for users too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we set it for all three: create_account writes ACCOUNT/USER based on owner, and create_role (plus the upgrade script) writes ROLE.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current accounts saved in the DB don't have this enum (['ACCOUNT', 'USER', 'ROLE']) and the existing code also assumes that if we have owner defined it is a user - what is tha plan for what we had?
Are you sure you need this? I think @sakshimunjal mentioned that didn't use it.

},

assume_role_policy: {
type: 'object',
required: ['statement'],
Expand Down Expand Up @@ -586,7 +591,7 @@ module.exports = {
}
},

iam_user_policy: {
iam_inline_policy: {
type: 'object',
required: ['policy_name', 'policy_document'],
properties: {
Expand All @@ -596,7 +601,10 @@ module.exports = {
}
}
},

// TODO: NC compatibility alias, remove after NC migrates to iam_inline_policy
iam_user_policy: {
$ref: '#/definitions/iam_inline_policy',
},
// IAM role trust policy (who can assume this role)
iam_trust_policy_principal: {
allOf: [{
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint/iam/iam_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,11 +1360,11 @@ function _get_assumed_role_session_info(req) {
*/
async function _get_identity_policies(account, is_iam_user, assumed_role_arn, bucketspace) {
if (is_iam_user) {
return account.iam_user_policies || [];
return account.iam_inline_policies || [];
}
const resolved_role = await resolve_iam_role_by_arn(assumed_role_arn, bucketspace);
if (!resolved_role?.iam_role) return null;
return resolved_role.iam_role.iam_role_policies || [];
return resolved_role.iam_role.iam_inline_policies || [];
}

/**
Expand Down
22 changes: 13 additions & 9 deletions src/sdk/nb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type ID = mongodb.ObjectID;
type DBBuffer = mongodb.Binary | Buffer;

type LockType = "EXCLUSIVE" | "SHARED" | undefined;
type IdentityType = 'ACCOUNT' | 'USER' | 'ROLE';

interface System extends Base {
_id: ID;
Expand All @@ -92,25 +93,28 @@ interface Account extends Base {
email: SensitiveString;
next_password_change: Date;
is_support?: boolean;
identity_type?: IdentityType;
access_keys: Array<{
access_key: SensitiveString;
secret_key: SensitiveString;
}>;
master_key_id: ID;
iam_path?: string;
iam_inline_policies?: object[];
description?: string;
max_session_duration?: number;
assume_role_policy_document?: object;
Comment on lines +104 to +106

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment so it would be clear that those fields are only relevant for roles?

creation_date?: Date;
Comment thread
shirady marked this conversation as resolved.
deleted?: Date;
}

interface IamRole extends Base {
_id: ID;
/** IAM role identity stored in accounts with identity_type === 'ROLE' */
type IamRole = Account & {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use it?
If so, it means that we miss IamUser?

identity_type: 'ROLE';
owner: ID;
name: string;
iam_path: string;
description?: string;
max_session_duration?: number;
assume_role_policy_document: object;
iam_role_policies?: object[];
creation_date: Date;
deleted?: Date;
}
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you use those type IamUser and type IamRole?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used type IamRole in some function jsdoc.
Removed IamUser for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need to remove, we just need to understand where it is used.

interface NodeAPI extends Base {
_id: ID;
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 @@ -69,6 +69,7 @@ const account_cache = new LRUCache({
const iam_roles_cache = new LRUCache({
name: 'IamRolesCache',
expiry_ms: config.IAM_ROLES_CACHE_EXPIRY_MS,
max_usage: 1000,
/**
* Set type for the generic template
* @param {{
Expand All @@ -77,7 +78,7 @@ const iam_roles_cache = new LRUCache({
* bucketspace: nb.BucketSpace;
* }} params
*/
make_key: ({ role_name, owner_account_id }) => `${owner_account_id}:${role_name}`,
make_key: ({ role_name, owner_account_id }) => `${owner_account_id}:${role_name.toLowerCase()}`,
load: async ({ bucketspace, role_name, owner_account_id }) =>
bucketspace.read_role_by_name({ role_name, owner_account_id }),
});
Expand Down
Loading