Skip to content

Commit 33e323f

Browse files
committed
Merge remote-tracking branch 'origin/bugfix/CLDSRV-896-access-log-requester-arn-format' into w/9.3/bugfix/CLDSRV-896-access-log-requester-arn-format
# Conflicts: # package.json
2 parents 8021753 + c1d3d6a commit 33e323f

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

lib/utilities/serverAccessLogger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ function getRequester(authInfo) {
335335
} else if (arn && assumedRoleArnRegex.test(arn)) {
336336
return arn;
337337
} else if (authInfo.isRequesterAnIAMUser && authInfo.isRequesterAnIAMUser()) {
338-
// IAM user: include IAM user name and account
339-
const iamUserName = authInfo.getIAMdisplayName ? authInfo.getIAMdisplayName() : '';
340-
const accountName = authInfo.getAccountDisplayName ? authInfo.getAccountDisplayName() : '';
341-
return iamUserName && accountName ? `${iamUserName}:${accountName}` : authInfo.getCanonicalID();
338+
// IAM user: emit the IAM ARN (arn:aws:iam::<accountId>:user/<userName>)
339+
// to match the AWS S3 server access log format. Fall back to the
340+
// canonical ID if the ARN is unexpectedly absent.
341+
return arn || authInfo.getCanonicalID();
342342
} else if (authInfo.getCanonicalID) {
343343
// Regular user: canonical user ID
344344
return authInfo.getCanonicalID();

tests/unit/utils/serverAccessLogger.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,23 @@ describe('serverAccessLogger utility functions', () => {
287287
assert.strictEqual(result, null);
288288
});
289289

290-
it('should return IAM user name with account for IAM user', () => {
290+
it('should return IAM ARN for IAM user', () => {
291+
const arn = 'arn:aws:iam::123456789012:user/myuser';
291292
const authInfo = {
292293
isRequesterPublicUser: () => false,
293294
isRequesterAnIAMUser: () => true,
294-
getIAMdisplayName: () => 'iamUser',
295-
getAccountDisplayName: () => 'accountName',
295+
getArn: () => arn,
296296
getCanonicalID: () => 'canonicalID123',
297297
};
298298
const result = getRequester(authInfo);
299-
assert.strictEqual(result, 'iamUser:accountName');
299+
assert.strictEqual(result, arn);
300300
});
301301

302-
it('should return canonical ID for IAM user if display names are missing', () => {
302+
it('should fall back to canonical ID for IAM user when ARN is missing', () => {
303303
const authInfo = {
304304
isRequesterPublicUser: () => false,
305305
isRequesterAnIAMUser: () => true,
306-
getIAMdisplayName: () => '',
307-
getAccountDisplayName: () => 'accountName',
306+
getArn: () => undefined,
308307
getCanonicalID: () => 'canonicalID123',
309308
};
310309
const result = getRequester(authInfo);
@@ -323,19 +322,6 @@ describe('serverAccessLogger utility functions', () => {
323322
assert.strictEqual(result, arn);
324323
});
325324

326-
it('should fall through to IAM user path for non-assumed-role ARN', () => {
327-
const authInfo = {
328-
isRequesterPublicUser: () => false,
329-
isRequesterAnIAMUser: () => true,
330-
getArn: () => 'arn:aws:iam::123456789012:user/myuser',
331-
getIAMdisplayName: () => 'myuser',
332-
getAccountDisplayName: () => 'myaccount',
333-
getCanonicalID: () => 'canonicalID789',
334-
};
335-
const result = getRequester(authInfo);
336-
assert.strictEqual(result, 'myuser:myaccount');
337-
});
338-
339325
it('should return canonical ID for regular user', () => {
340326
const authInfo = {
341327
isRequesterPublicUser: () => false,

0 commit comments

Comments
 (0)