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

Audit logging #440

Merged
merged 33 commits into from
Dec 23, 2024
Merged

Audit logging #440

merged 33 commits into from
Dec 23, 2024

Conversation

nikomakela
Copy link
Contributor

@nikomakela nikomakela commented Dec 4, 2024

Kukkuu audit logging

Audit logging is implemented with django-auditlog, but it has some extended features applied with hel_django_auditlog_extra -app.

Audit log extension

This pull request introduces hel_django_auditlog_extra, a Django application that enhances django-auditlog with the following features:

  • Fixes set_actor context manager: The original set_actor in django-auditlog is designed to extract user and IP address information from the request and log it. However, it has issues with Graphene and its authentication mechanisms. This has been corrected.
  • New context manager for request path logging: Adds a new context manager to include request.path in the logs. This information is added to the additional_data field of LogEntry.
  • Middleware for context managers: Provides middleware that utilizes both of the aforementioned context managers.
  • Graphene decorator for access logging: Includes a Graphene decorator that logs access information every time the get_node method of a Graphene object is called.
  • Admin view mixin for audit logging: Offers an admin view mixin that enables audit logging for admin view requests.
  • Optional configuration tool: Introduces an optional configuration tool that monitors and enforces audit logging for all models, either through an inclusive or exclusive approach.

This PR is splitted so that it would contain only the new hel_django_auditlog_extra -app. The Kukkuu configuration is added in another PR: #441.

@karisal-anders karisal-anders self-requested a review December 5, 2024 17:15
Copy link
Contributor

@karisal-anders karisal-anders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good job! I left some comments, please take a look at them.

@nikomakela
Copy link
Contributor Author

NOTE: Django-auditlog provides a generic view access log mixin out of the box: https://django-auditlog.readthedocs.io/en/latest/usage.html#automatically-logging-changes. This should be usable with DRF.

KK-1113.

Use Python context manager to set a request path to the LogEntry
instance's additional data field when it's available, the same way as
the `set_actor` of the `django-auditlog` sets the ip address and user to
the LogEntry instance.
@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@nikomakela
Copy link
Contributor Author

  • The ContextVar stuff related to get_object would be good to test that it works

Okay, I finally had time to test this and it the test result is that the contextvar works wrong: it persists through multiple requests. I need to find a proper fix for that or manipulate the request object instead.

@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

KK-1113.

Replace the contextvar usage with a request object manipulation, since
the contextvar was not reinitialized for every Django request.
@terovirtanen
Copy link
Contributor

KUKKUU-API branch is deployed to platta: https://kukkuu-pr440.api.dev.hel.ninja 🚀🚀🚀

@terovirtanen
Copy link
Contributor

TestCafe result is success for https://kukkuu-pr440.api.dev.hel.ninja 😆🎉🎉🎉

@nikomakela nikomakela merged commit a427992 into master Dec 23, 2024
24 checks passed
@nikomakela nikomakela deleted the KK-1113-audit-log branch December 23, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants