Skip to content

Commit 8b215d8

Browse files
IAM Roles | Store roles in accounts with type=role instead of a separate iam_roles collection
Signed-off-by: Aayush Chouhan <achouhan@redhat.com>
1 parent 783e4f2 commit 8b215d8

9 files changed

Lines changed: 199 additions & 292 deletions

File tree

src/sdk/nb.d.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,30 @@ interface Account extends Base {
9292
email: SensitiveString;
9393
next_password_change: Date;
9494
is_support?: boolean;
95+
// Optional identity kind: account | user | role. Absent on legacy docs.
96+
type?: 'account' | 'user' | 'role';
9597
access_keys: Array<{
9698
access_key: SensitiveString;
9799
secret_key: SensitiveString;
98100
}>;
99101
master_key_id: ID;
100-
}
101-
102-
interface IamRole extends Base {
103-
_id: ID;
104-
owner: ID;
105-
name: string;
106-
iam_path: string;
102+
iam_path?: string;
103+
iam_user_policies?: object[];
107104
description?: string;
108105
max_session_duration?: number;
109-
assume_role_policy_document: object;
106+
assume_role_policy_document?: object;
110107
iam_role_policies?: object[];
111-
creation_date: Date;
108+
creation_date?: Date;
112109
deleted?: Date;
113110
}
114111

112+
/** IAM role identity stored in accounts with type === 'role'. */
113+
type IamRole = Account & {
114+
type: 'role';
115+
owner: ID;
116+
assume_role_policy_document: object;
117+
};
118+
115119
interface NodeAPI extends Base {
116120
_id: ID;
117121
name: string;

src/sdk/object_sdk.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ const account_cache = new LRUCache({
6565
validate: (data, params) => _validate_account(data, params),
6666
});
6767

68-
// IAM role cache — keyed by owner + role_name (role names are unique per account, not globally)
68+
// IAM role cache — keyed by owner + role_name (unique per account; email uses lowercase name)
6969
const iam_roles_cache = new LRUCache({
7070
name: 'IamRolesCache',
7171
expiry_ms: config.IAM_ROLES_CACHE_EXPIRY_MS,
72+
// Align with bucket_namespace_cache; RolesPerAccount max is 1000
73+
max_usage: 1000,
7274
/**
7375
* Set type for the generic template
7476
* @param {{
@@ -77,7 +79,7 @@ const iam_roles_cache = new LRUCache({
7779
* bucketspace: nb.BucketSpace;
7880
* }} params
7981
*/
80-
make_key: ({ role_name, owner_account_id }) => `${owner_account_id}:${role_name}`,
82+
make_key: ({ role_name, owner_account_id }) => `${owner_account_id}:${role_name.toLowerCase()}`,
8183
load: async ({ bucketspace, role_name, owner_account_id }) =>
8284
bucketspace.read_role_by_name({ role_name, owner_account_id }),
8385
});

0 commit comments

Comments
 (0)