Skip to content

Commit ad1a3dd

Browse files
committed
Log client_name and client_schachome when defined for app
1 parent 434d5f7 commit ad1a3dd

File tree

9 files changed

+45
-13
lines changed

9 files changed

+45
-13
lines changed

config/gateway.config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,18 @@ pipelines:
143143
- action:
144144
apps:
145145
fred:
146+
client_name: 'Fred Flintstone'
147+
client_schachome: 'fred.flintstone'
146148
passwordSalt: 8b52795e90b598eb022647f17c93ac2b
147149
passwordHash: e4c9628c52aead0dcf10330a6864d8bcc78a5a4a463b274bee39cee4cfc0a574
148150
barney:
151+
client_name: 'Barney Rubble'
152+
client_schachome: 'barney.rubble'
149153
passwordSalt: 5e5b3fb149fdd06ba9d18edd178d77cb
150154
passwordHash: 19d767b82ebb294e3c2008b53a0bcc59140e688baded13eea1794099c869e89f
151155
bubbles:
156+
client_name: 'Bubbles Flintstone'
157+
client_schachome: 'bubbles.flintstone'
152158
passwordSalt: 5970ad7d7501916274cf114f68d2aed0
153159
passwordHash: 5e063ba6dcff4b7bc0234be7861dac8c4dd7db573f36755e0578b2e77a5cf6bf
154160
acls:

config/gateway.config.yml.v5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,18 @@ pipelines:
148148
- action:
149149
apps:
150150
fred:
151+
client_name: 'Fred Flintstone'
152+
client_schachome: 'fred.flintstone'
151153
passwordSalt: 8b52795e90b598eb022647f17c93ac2b
152154
passwordHash: e4c9628c52aead0dcf10330a6864d8bcc78a5a4a463b274bee39cee4cfc0a574
153155
barney:
156+
client_name: 'Barney Rubble'
157+
client_schachome: 'barney.rubble'
154158
passwordSalt: 5e5b3fb149fdd06ba9d18edd178d77cb
155159
passwordHash: 19d767b82ebb294e3c2008b53a0bcc59140e688baded13eea1794099c869e89f
156160
bubbles:
161+
client_name: 'Bubbles Flintstone'
162+
client_schachome: 'bubbles.flintstone'
157163
passwordSalt: 5970ad7d7501916274cf114f68d2aed0
158164
passwordHash: 5e063ba6dcff4b7bc0234be7861dac8c4dd7db573f36755e0578b2e77a5cf6bf
159165
acls:

policies/aggregation/aggregation.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,21 @@ module.exports = (config, { gatewayConfig: { serviceEndpoints } }) => {
117117
const outgoingTraceParent = traceParent.child()
118118
const reqTimerStart = new Date()
119119
// setup logging and metrics
120-
const app = req.egContext.app
120+
const app = req.egContext.app // set by gatekeeper policy
121121
const labels = {
122122
method: req.method,
123123
path: req.route.path,
124124
endpoint: endpointId,
125-
client: app
125+
client: app.user
126126
}
127127
concurrentRequestsMetric.labels(labels).inc()
128128

129129
// log and keep metrics for request to endpoint
130130
const report = ({ statusCode, reqTimerEnd, ...rest }) => {
131131
jsonLog.info({
132-
client: app,
132+
client: app.user,
133+
client_name: app.client_name,
134+
client_schachome: app.client_schachome,
133135
side: 'backend',
134136
http_status: statusCode,
135137
endpoint: endpointId,

policies/gatekeeper/authentication.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ const appFromRequest = (req, apps) => {
6868
const pass = password || dummyPass
6969
const salt = app ? app.passwordSalt : dummySalt
7070
const hash = app ? app.passwordHash : dummyHash
71+
7172
if (timingSafeHashEqual(hashPassword(pass, salt), hash)) {
72-
return app ? user : null
73+
return { ...app, user }
7374
}
7475
}
7576

policies/gatekeeper/gatekeeper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = (params, config) => {
5555
delete req.headers.authorization
5656

5757
if (app) {
58-
const acl = acls[app]
58+
const acl = acls[app.user]
5959

6060
if (acl) {
6161
authorization.prepareRequestHeaders(acl, req)

policies/lifecycle-logger/logger.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ module.exports = () => {
3636
traceparent_trace_id: traceParent.traceId,
3737
traceparent_id: traceParent.id,
3838
traceparent_parent_id: traceParent.parent_id,
39-
client: app,
39+
client: app && app.user,
40+
client_name: app && app.client_name,
41+
client_schachome: app && app.client_schachome,
4042
route_path: req.route && req.route.path,
4143
http_status: statusCode,
4244
request_method: method,

test/config/gateway.config.v4.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,18 @@ pipelines:
145145
- action:
146146
apps:
147147
fred:
148+
client_name: 'Fred Flintstone'
149+
client_schachome: 'fred.flintstone'
148150
passwordSalt: 8b52795e90b598eb022647f17c93ac2b
149151
passwordHash: e4c9628c52aead0dcf10330a6864d8bcc78a5a4a463b274bee39cee4cfc0a574
150152
barney:
153+
client_name: 'Barney Rubble'
154+
client_schachome: 'barney.rubble'
151155
passwordSalt: 5e5b3fb149fdd06ba9d18edd178d77cb
152156
passwordHash: 19d767b82ebb294e3c2008b53a0bcc59140e688baded13eea1794099c869e89f
153157
bubbles:
158+
client_name: 'Bubbles Flintstone'
159+
client_schachome: 'bubbles.flintstone'
154160
passwordSalt: 5970ad7d7501916274cf114f68d2aed0
155161
passwordHash: 5e063ba6dcff4b7bc0234be7861dac8c4dd7db573f36755e0578b2e77a5cf6bf
156162
acls:

test/config/gateway.config.v5.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,18 @@ pipelines:
152152
- action:
153153
apps:
154154
fred:
155+
client_name: 'Fred Flintstone'
156+
client_schachome: 'fred.flintstone'
155157
passwordSalt: 8b52795e90b598eb022647f17c93ac2b
156158
passwordHash: e4c9628c52aead0dcf10330a6864d8bcc78a5a4a463b274bee39cee4cfc0a574
157159
barney:
160+
client_name: 'Bubbles Flintstone'
161+
client_schachome: 'bubbles.flintstone'
158162
passwordSalt: 5e5b3fb149fdd06ba9d18edd178d77cb
159163
passwordHash: 19d767b82ebb294e3c2008b53a0bcc59140e688baded13eea1794099c869e89f
160164
bubbles:
165+
client_name: 'Bubbles Flintstone'
166+
client_schachome: 'bubbles.flintstone'
161167
passwordSalt: 5970ad7d7501916274cf114f68d2aed0
162168
passwordHash: 5e063ba6dcff4b7bc0234be7861dac8c4dd7db573f36755e0578b2e77a5cf6bf
163169
acls:

test/gatekeeper/authentication.test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ describe('gatekeeper/authentication', () => {
6464
let salt
6565
const apps = {
6666
fred: {
67+
client_name: 'Fred Flintstone',
68+
client_schachome: 'fred.flintstone',
6769
passwordHash: authentication.hashPassword('wilma', salt = randomString()),
6870
passwordSalt: salt
6971
},
@@ -82,19 +84,20 @@ describe('gatekeeper/authentication', () => {
8284
)
8385

8486
it('should return app from basic authentication', () => {
85-
assert.equal(
86-
authentication.appFromRequest({
87-
headers: { authorization: authorizationHeader('fred', 'wilma') }
88-
}, apps),
89-
'fred'
90-
)
87+
const app = authentication.appFromRequest({
88+
headers: { authorization: authorizationHeader('fred', 'wilma') }
89+
}, apps)
90+
91+
assert.equal(app.user, 'fred')
92+
assert.equal(app.client_name, 'Fred Flintstone')
93+
assert.equal(app.client_schachome, 'fred.flintstone')
9194
})
9295

9396
it('should allow colon in password', () => {
9497
assert.equal(
9598
authentication.appFromRequest({
9699
headers: { authorization: authorizationHeader('with-colon', 'with:colon') }
97-
}, apps),
100+
}, apps).user,
98101
'with-colon'
99102
)
100103
})

0 commit comments

Comments
 (0)