From e3d3ab0214eaeab89723595296b175e0d113c945 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 4 Oct 2024 11:02:29 +0200 Subject: [PATCH 1/4] add user name to access log --- lib/constants.js | 3 ++- lib/middleware/proxy.js | 1 + lib/services/keystoneAuth.js | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 83f7107..d955013 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -32,7 +32,8 @@ var constants = { X_REAL_IP_HEADER: 'x-real-ip', CORRELATOR_HEADER: 'fiware-correlator', - GET_ROLES_PATH: '/user' + GET_ROLES_PATH: '/user', + NA: 'N/A' }; diff --git a/lib/middleware/proxy.js b/lib/middleware/proxy.js index 86878da..a2f0dd2 100644 --- a/lib/middleware/proxy.js +++ b/lib/middleware/proxy.js @@ -201,6 +201,7 @@ function accountInfo(req, res, next) { ' | Token=' + req.headers['x-auth-token'] + ' | Origin=' + req.connection.remoteAddress + ' | UserId=' + req.userId + + ' | UserName=' + req.userName + ' | ServiceId=' + req.serviceId + ' | Service=' + req.service + ' | SubServiceId=' + req.subserviceId + diff --git a/lib/services/keystoneAuth.js b/lib/services/keystoneAuth.js index a695d67..4ffacee 100644 --- a/lib/services/keystoneAuth.js +++ b/lib/services/keystoneAuth.js @@ -191,6 +191,7 @@ function retrieveUser(req, callback) { req.serviceId = cachedValue.serviceId; req.domainName = cachedValue.domainName; req.userId = cachedValue.userId; + req.userName = cachedValue.userName; logger.debug('User value processed with value: %j', cachedValue); @@ -245,7 +246,8 @@ function retrieveUser(req, callback) { cachedValue = { domainName: body.token.project.domain.name, serviceId: body.token.project.domain.id, - userId: body.token['OS-TRUST:trust'].trustor_user.id + userId: body.token['OS-TRUST:trust'].trustor_user.id, + userName: constants.NA }; innerCb(null, cachedValue); @@ -256,7 +258,8 @@ function retrieveUser(req, callback) { cachedValue = { domainName: body.token.user.domain.name, serviceId: body.token.user.domain.id, - userId: body.token.user.id + userId: body.token.user.id, + userName: body.token.user.name }; req.userData = cachedValue; From 632cfb9cff6f7df5ef7f8c11424f102c88608c80 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 4 Oct 2024 11:12:31 +0200 Subject: [PATCH 2/4] fix userName when token is from Trust --- lib/services/keystoneAuth.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/services/keystoneAuth.js b/lib/services/keystoneAuth.js index 4ffacee..a47aa6b 100644 --- a/lib/services/keystoneAuth.js +++ b/lib/services/keystoneAuth.js @@ -249,7 +249,9 @@ function retrieveUser(req, callback) { userId: body.token['OS-TRUST:trust'].trustor_user.id, userName: constants.NA }; - + if (body.token.user) { + cachedValue['userName'] = body.token.user.name; + } innerCb(null, cachedValue); } else if (body.token && body.token.user && body.token.user.domain && From 9b5d7502b2a5a9d7a52d56336f0ef4036f8ccb57 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 4 Oct 2024 11:16:14 +0200 Subject: [PATCH 3/4] fix linter --- lib/services/keystoneAuth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/keystoneAuth.js b/lib/services/keystoneAuth.js index a47aa6b..f95f813 100644 --- a/lib/services/keystoneAuth.js +++ b/lib/services/keystoneAuth.js @@ -250,7 +250,7 @@ function retrieveUser(req, callback) { userName: constants.NA }; if (body.token.user) { - cachedValue['userName'] = body.token.user.name; + cachedValue.userName = body.token.user.name; } innerCb(null, cachedValue); From 5f12d00925da38a046a143c0a29ba757891f45b3 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 4 Oct 2024 11:23:14 +0200 Subject: [PATCH 4/4] add userName to account InfoError --- lib/fiware-pep-steelskin.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fiware-pep-steelskin.js b/lib/fiware-pep-steelskin.js index 6be28ed..3b1946f 100644 --- a/lib/fiware-pep-steelskin.js +++ b/lib/fiware-pep-steelskin.js @@ -79,7 +79,10 @@ function accountInfoError(error, req, res, next) { ' | Token=' + req.headers['x-auth-token'] + ' | Origin=' + req.connection.remoteAddress + ' | UserId=' + req.userId + + ' | ServiceId=' + req.serviceId + + ' | UserName=' + req.userName + ' | Service=' + req.service + + ' | SubServiceId=' + req.subserviceId + ' | SubService=' + req.subService + ' | Action=' + req.action + ' | Date=' + new Date().toJSON());