Skip to content

Commit

Permalink
[logging] Log identity as part of API call logging (#14793)
Browse files Browse the repository at this point in the history
## Change Description

- Adds the username dict to requests during auth checks
- Adds logging of that username dict (if available) during call logging

## Security Assessment

- This change has a medium security impact

### Impact Description

- Makes usernames explicitly visible in the system logs, so admins are
now able to track what individual users are doing or looking at.
- The userdata in request objects should be handled carefully, though it
does not include anything secret (ie nothing which would allow
impersonation if leaked)


(Reviewers: please confirm the security impact before approving)
  • Loading branch information
cjllanwarne authored Jan 24, 2025
1 parent 79c599a commit 8ce7022
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions gear/gear/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async def wrapped(request: web.Request) -> web.StreamResponse:
if redirect or (redirect is None and '/api/' not in request.path):
raise login_redirect(request)
raise web.HTTPUnauthorized()
request['userdata'] = userdata
return await fun(request, userdata)

return wrapped
Expand Down
4 changes: 4 additions & 0 deletions hail/python/hailtop/hail_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def log(self, request, response, time):
'x_real_ip': request.headers.get("X-Real-IP"),
}

userdata_maybe = request.get('userdata', {})
userdata_keys = ['username', 'login_id', 'is_developer', 'hail_identity']
extra.update({k: userdata_maybe[k] for k in userdata_keys if k in userdata_maybe})

self.logger.info(
f'{request.scheme} {request.method} {request.path} ' f'done in {time}s: {response.status}',
extra={**extra, **request.get('batch_telemetry', {})},
Expand Down

0 comments on commit 8ce7022

Please sign in to comment.