Generate audit log entries on unauthorized access attempts #375
+203
−170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the middleware used to perform permissions checks on API endpoints to generate an audit log record if a user attempts to access an endpoint they do not have permission to access. There are a few different middleware functions that perform authorization checks, so a helper method was added to DRY up the code for a consistent experience.
The audit log entry generated will capture the name, IP address, and email address of the unauthorized user as those are standard fields for an audit log. The API endpoint the user was attempting to access will also be logged in the
fields
section.A few things to note:
POST /api/v2/bloodhound-users
would be logged,GET /api/v2/bloodhound-users
would not be loggedMotivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: