-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): add logs to routes #2697
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we create an openPaymentsServerErrorMiddleware
like we do in backend to catch all of the GNAPErrors to have a single place for a standardized log for each error? (Since most of the logs are added right before the throw).
packages/auth/src/shared/utils.ts
Outdated
requestBody: typeof ctx.request.body | ||
} { | ||
return { | ||
requestId: v4(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would show a different uuid for each log, right?
I was looking into a way to have a common request/traceId as a property on a child pino logger, but it is a bit difficult to do that with how we've set up dependency injection with adonis fold library. I'll take another attempt at addressing this in my upcoming changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it would be workable for now as the routes log once per request, but I admit it's wishful thinking
deps.logger.debug( | ||
{ | ||
...generateRouteLogs(ctx), | ||
accessToken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we be logging out tokens such as accessToken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make any difference that its a debug log? I guess we can say these can but shouldnt be logged in production. Had the same thought about grant.continueToken
elsewhere.
export function generateRouteLogs(ctx: AppContext): { | ||
route: typeof ctx.path | ||
method: typeof ctx.method | ||
params: typeof ctx.params | ||
headers: typeof ctx.headers | ||
requestBody: typeof ctx.request.body | ||
} { | ||
return { | ||
method: ctx.method, | ||
route: ctx.path, | ||
headers: ctx.headers, | ||
params: ctx.params, | ||
requestBody: ctx.request.body | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine there is probably some sensitive info in here somewhere.
for example from a POST continue/{{continueId}}
:
requestBody.continue.access_token.value
requestBody.access_token.value
And is everything in headers OK to log or should any of it be redacted?
"headers": {
"accept": "application/json",
"content-type": "application/json",
"content-digest": "sha-512=:wJHRy2GvqCYWZhLTIAdtBaDT9MRO69ldMWgdld0GO8cYVu8uop7pmilYh1xmlVDiiT8d2P1CSdyYgnbCsJIrNA==:",
"content-length": "174",
"signature": "sig1=:M5wb//IFQa43pZ6DfUrxcx7RCf3aQWXApk28TmhqgiUrzBbhlu0hs2/zVzXuiB7kEa1LZuq3taQT1XT5wuBDDg==:",
"signature-input": "sig1=(\"@method\" \"@target-uri\" \"content-digest\" \"content-length\" \"content-type\");keyid=\"keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5\";created=1715013373",
"user-agent": "axios/1.6.8",
"accept-encoding": "gzip, compress, deflate, br",
"host": "happy-life-bank-test-auth:4106",
"connection": "keep-alive"
},
If we need to configure pino to redact I imagine it might make sense to do it where we initialize the logger for some things, like the headers (if required).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good pattern btw though. Also wondering if you think it would make sense to destructure this where we init the pino logger so we dont have to do ...generateRouteLogs(ctx)
everywhere? Or if we dont want to always log context do a new loggerWithCtx
or something?
What do you think about original PR review comment?
Might be nice to match the behaviour in |
I think it's possible to have this PR also match that pattern. It'll be slightly different since it's supposed to also return GNAP error codes, but will be mostly similar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few minor comments
'invalid access token' | ||
) | ||
} | ||
|
||
if (!accessToken.grant) { | ||
const logger = await ctx.container.use('logger') | ||
logger.error( | ||
`access token with management id ${ctx.params['id']} has no grant associated with it.` | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this log worth keeping still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably...in hindsight that's a pretty severe case that shouldn't happen - we should know about if it does for some reason
@@ -3,7 +3,14 @@ import createLogger, { Logger as PinoLogger } from 'pino' | |||
import { Config } from '../config/app' | |||
|
|||
function initLogger(): PinoLogger { | |||
const logger = createLogger() | |||
const logger = createLogger({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to use this when instantiating the logger singleton in index.ts?
} | ||
} | ||
|
||
export async function gnapServerErrorMiddleware( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check for OpenAPIValidatorMiddlewareError
here as well, similar to backend
, so we get a nicely formatted error when getting validation errors as well. This means we need to update @interledger/openapi
to 2.0.1
85a7724
to
82c7135
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one comment
ctx.container = deps | ||
}) | ||
|
||
test('handles GNAPServerRouteError error', async (): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add a test for the validator middleware error
c7af5bf
to
b7d2663
Compare
Changes proposed in this pull request
Context
Closes #2577.
Checklist
fixes #number