Skip to content

Commit eb9c1c0

Browse files
committed
CLDSRV-896: Emit IAM ARN in access log Requester field for IAM users
When an IAM user makes a request, the Requester field in the bucket server access log was emitted as userName:accountName. AWS emits an ARN of the form arn:aws:iam::<accountId>:user/<userName>. Use the IAM ARN that Vault already provides via authInfo to match the AWS S3 server access log format. (cherry picked from commit fc18430)
1 parent e30397b commit eb9c1c0

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
@@ -331,10 +331,10 @@ function getRequester(authInfo) {
331331
} else if (arn && assumedRoleArnRegex.test(arn)) {
332332
return arn;
333333
} else if (authInfo.isRequesterAnIAMUser && authInfo.isRequesterAnIAMUser()) {
334-
// IAM user: include IAM user name and account
335-
const iamUserName = authInfo.getIAMdisplayName ? authInfo.getIAMdisplayName() : '';
336-
const accountName = authInfo.getAccountDisplayName ? authInfo.getAccountDisplayName() : '';
337-
return iamUserName && accountName ? `${iamUserName}:${accountName}` : authInfo.getCanonicalID();
334+
// IAM user: emit the IAM ARN (arn:aws:iam::<accountId>:user/<userName>)
335+
// to match the AWS S3 server access log format. Fall back to the
336+
// canonical ID if the ARN is unexpectedly absent.
337+
return arn || authInfo.getCanonicalID();
338338
} else if (authInfo.getCanonicalID) {
339339
// Regular user: canonical user ID
340340
return authInfo.getCanonicalID();

tests/unit/utils/serverAccessLogger.js

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

272-
it('should return IAM user name with account for IAM user', () => {
272+
it('should return IAM ARN for IAM user', () => {
273+
const arn = 'arn:aws:iam::123456789012:user/myuser';
273274
const authInfo = {
274275
isRequesterPublicUser: () => false,
275276
isRequesterAnIAMUser: () => true,
276-
getIAMdisplayName: () => 'iamUser',
277-
getAccountDisplayName: () => 'accountName',
277+
getArn: () => arn,
278278
getCanonicalID: () => 'canonicalID123',
279279
};
280280
const result = getRequester(authInfo);
281-
assert.strictEqual(result, 'iamUser:accountName');
281+
assert.strictEqual(result, arn);
282282
});
283283

284-
it('should return canonical ID for IAM user if display names are missing', () => {
284+
it('should fall back to canonical ID for IAM user when ARN is missing', () => {
285285
const authInfo = {
286286
isRequesterPublicUser: () => false,
287287
isRequesterAnIAMUser: () => true,
288-
getIAMdisplayName: () => '',
289-
getAccountDisplayName: () => 'accountName',
288+
getArn: () => undefined,
290289
getCanonicalID: () => 'canonicalID123',
291290
};
292291
const result = getRequester(authInfo);
@@ -305,19 +304,6 @@ describe('serverAccessLogger utility functions', () => {
305304
assert.strictEqual(result, arn);
306305
});
307306

308-
it('should fall through to IAM user path for non-assumed-role ARN', () => {
309-
const authInfo = {
310-
isRequesterPublicUser: () => false,
311-
isRequesterAnIAMUser: () => true,
312-
getArn: () => 'arn:aws:iam::123456789012:user/myuser',
313-
getIAMdisplayName: () => 'myuser',
314-
getAccountDisplayName: () => 'myaccount',
315-
getCanonicalID: () => 'canonicalID789',
316-
};
317-
const result = getRequester(authInfo);
318-
assert.strictEqual(result, 'myuser:myaccount');
319-
});
320-
321307
it('should return canonical ID for regular user', () => {
322308
const authInfo = {
323309
isRequesterPublicUser: () => false,

0 commit comments

Comments
 (0)