Skip to content

Commit 0f4ce2a

Browse files
Merge pull request #9290 from aayushchouhan09/sec-key
Added support for second access key s3 access
2 parents 252f602 + 8a7f955 commit 0f4ce2a

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/server/common_services/auth_server.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,25 @@ function unauthorized_error(reason) {
178178
*
179179
*/
180180
function create_access_key_auth(req) {
181-
const access_key = req.rpc_params.access_key.unwrap();
181+
const access_key = req.rpc_params.access_key;
182182
const string_to_sign = req.rpc_params.string_to_sign;
183183
const signature = req.rpc_params.signature;
184184

185185
if (_.isUndefined(string_to_sign) || _.isUndefined(signature)) {
186186
throw new RpcError('UNAUTHORIZED', 'signature error');
187187
}
188188

189-
const account = _.find(system_store.data.accounts, function(acc) {
190-
if (acc.access_keys) {
191-
return acc.access_keys[0].access_key.unwrap().toString() === access_key.toString();
192-
} else {
193-
return false;
194-
}
195-
});
189+
const account = system_store.get_account_by_access_key(access_key);
196190

197191
if (!account || account.deleted) {
198192
throw new RpcError('UNAUTHORIZED', 'account not found');
199193
}
200194

201-
const secret = account.access_keys[0].secret_key.unwrap().toString();
195+
const key_pair = account.access_keys.find(key =>
196+
key.access_key.unwrap() === access_key.unwrap()
197+
);
198+
199+
const secret = key_pair.secret_key.unwrap();
202200
const signature_test = signature_utils.get_signature_from_auth_token({ string_to_sign: string_to_sign }, secret);
203201
if (signature_test !== signature) {
204202
throw new RpcError('UNAUTHORIZED', 'signature error');
@@ -315,15 +313,16 @@ function _authorize_jwt_token(req) {
315313
function _authorize_signature_token(req) {
316314
const auth_token_obj = req.auth_token;
317315

318-
const account = _.find(system_store.data.accounts, function(acc) {
319-
return acc.access_keys && acc.access_keys.length > 0 &&
320-
acc.access_keys[0].access_key.unwrap() ===
321-
auth_token_obj.access_key;
322-
});
316+
const account = system_store.get_account_by_access_key(new SensitiveString(auth_token_obj.access_key));
323317
if (!account || account.deleted) {
324318
throw new RpcError('UNAUTHORIZED', 'account not found');
325319
}
326-
const secret_key = account.access_keys[0].secret_key;
320+
321+
const key_pair = account.access_keys.find(key =>
322+
key.access_key.unwrap() === auth_token_obj.access_key
323+
);
324+
325+
const secret_key = key_pair.secret_key;
327326

328327
const role = _.find(system_store.data.roles, function(r) {
329328
return r.account._id.toString() === account._id.toString();

src/server/system_services/account_server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ function read_account(req) {
132132

133133
function read_account_by_access_key(req) {
134134
const { access_key } = req.rpc_params;
135-
const account = _.find(system_store.data.accounts, acc =>
136-
acc.access_keys && acc.access_keys.length > 0 && acc.access_keys[0].access_key.unwrap() === access_key.unwrap()
137-
);
135+
136+
const account = system_store.get_account_by_access_key(access_key);
138137

139138
if (!account) throw new RpcError('NO_SUCH_ACCOUNT', 'No such account with credentials: ' + access_key);
140139

0 commit comments

Comments
 (0)