Skip to content
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

Add Audit logging to CloudWatch #43

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/api/api_v1/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
# TODO: We should use maybe use middleware for this see: PDCT-410


def check_user_auth(request: Request, token: str = Depends(oauth2_scheme)) -> None:
async def check_user_auth(
request: Request, token: str = Depends(oauth2_scheme)
) -> None:
"""
Checks the current user (id'd by the token) is authorised for the request.

Expand All @@ -28,6 +30,20 @@ def check_user_auth(request: Request, token: str = Depends(oauth2_scheme)) -> No
entity = auth_service.path_to_endpoint(request.scope["path"])
operation = auth_service.http_method_to_operation(request.scope["method"])

payload = await request.json()
_LOGGER.info(
f"AUDIT: {user.email} is performing {operation} on {entity}",
extra={
"props": {
"request": request.scope["path"],
"user": user.email,
"op": operation,
"entity": entity,
"payload": payload if payload else "null",
}
},
)

try:
auth_service.is_authorised(user, entity, operation)
except AuthorisationError as e:
Expand Down
Loading