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

Honor log_request_body setting in compliance audit log #4832

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Oct 21, 2024

Description

This PR ensures that the value of log_request_body is honored for the compliance logging. When using the compliance config, this PR will ensure that the document's source is audit logged in the audit_request_body when a document is first created, but otherwise it will not. When write_log_diffs is enabled, you can trace the full history of changes to documents on the tracked indices by looking for all events on the target index.

By default, the security index gets events audit logged so Compliant logging is a good feature to use to trace changes to the security configuration.

  • Category (Enhancement, New feature, Bug fix, Test fix, Refactoring, Maintenance, Documentation)

Enhancement

Issues Resolved

#4534

Check List

  • New functionality includes testing
  • New functionality has been documented
  • New Roles/Permissions have a corresponding security dashboards plugin PR
  • API changes companion pull request created
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 70.76%. Comparing base (703d40f) to head (3ed22ae).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...earch/security/auditlog/impl/AbstractAuditLog.java 55.55% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4832      +/-   ##
==========================================
- Coverage   70.99%   70.76%   -0.23%     
==========================================
  Files         310      310              
  Lines       20938    20952      +14     
  Branches     3326     3333       +7     
==========================================
- Hits        14865    14827      -38     
- Misses       4325     4376      +51     
- Partials     1748     1749       +1     
Files with missing lines Coverage Δ
...earch/security/auditlog/impl/AbstractAuditLog.java 76.51% <55.55%> (-0.12%) ⬇️

... and 17 files with indirect coverage changes

Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Craig Perkins <[email protected]>
@cwperks cwperks changed the title Honor log_request_body setiing in compliance audit log Honor log_request_body setting in compliance audit log Oct 22, 2024
@@ -628,7 +633,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
}
}

if (!complianceConfig.shouldLogWriteMetadataOnly()) {
if (!complianceConfig.shouldLogWriteMetadataOnly() && !complianceConfig.shouldLogDiffsForWrite()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Add this condition in so that the full request body is only logged if both compliance.write_metadata_only and compliance.write_log_diffs are both false. These settings seems to be in conflict:

Documentation: https://opensearch.org/docs/latest/security/access-control/api/

compliance.write_log_diffs	Boolean	Logs only diffs for document updates. Default is false.

compliance.write_metadata_only	Boolean	Log only metadata of the document for write events. Default is true.

The full body should only get audit logged if both compliance.write_metadata_only and compliance.write_log_diffs are false.

new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()),
id
);
}
}
} catch (Exception e) {
log.error(e.toString());
Copy link

Choose a reason for hiding this comment

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

should we return here?

new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()),
id
);
if (auditConfigFilter.shouldLogRequestBody() || originalResult == null) {
Copy link

Choose a reason for hiding this comment

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

Overall LGTM. I am not following why we need the originalResult == null check..

Copy link

Choose a reason for hiding this comment

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

is there a rule that "first" doc insert will have all possible audits published?

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.

2 participants