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

Log request body to audit logs #5071

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

olkkoti
Copy link

@olkkoti olkkoti commented Jan 30, 2025

Description

Currently we do not get request body to audit log, as requests are already authenticated in header verifier level, which does not have access to request body.

SecurityRestFilter has the whole RestRequest object, but it does not authenticate it again. Also, it does not authorize the request if the route is not a named one. The idea here is to do logGrantedPrivileges call even if we do not authorize. This way we will get the request body to audit log.

Issues Resolved

[BUG] audit_request_body missing for REST since 2.11

Testing

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.

@olkkoti olkkoti changed the title Log granted privileges on SecurityRestFilter even if we do not author… Log request body to audit logs Jan 30, 2025
Copy link
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

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

wdyt about adding auditLog.logSucceededLogin(user.getName(), request); before each call to delegate.handleRequest(request, channel, client);?

We could also remove these calls from the BackendRegistry and rely on them to be called within here.

To enable audit logs for this category, you would need to add then AUTHENTICATED category as one of the enabled categories.

@olkkoti
Copy link
Author

olkkoti commented Feb 1, 2025

How about like this?

@olkkoti olkkoti force-pushed the auditlog-without-rest-authorization branch 4 times, most recently from aef31e2 to c49ca35 Compare February 3, 2025 16:11
@olkkoti
Copy link
Author

olkkoti commented Feb 3, 2025

Hmm. Apparently at least in test cases user is allowed to be null here. I guess then we just dont do audit log? Or would it be better to call it with null effectiveUser?

@olkkoti olkkoti force-pushed the auditlog-without-rest-authorization branch 3 times, most recently from e837d29 to e4f6268 Compare February 8, 2025 08:11
@olkkoti olkkoti requested a review from cwperks February 8, 2025 08:11
if (effectiveUser != authenticatedUser) {
threadPool.getThreadContext()
.putTransient(ConfigConstants.OPENDISTRO_SECURITY_IMPERSONATION_INITIATING_USER, authenticatedUser.getName());
}
UserSubject subject = new UserSubjectImpl(threadPool, effectiveUser);
threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject);
Copy link
Member

Choose a reason for hiding this comment

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

Thank you @olkkoti . Apologies for not getting back sooner.

Curious, why not use the value from this persistent header?

In the case where impersonation is being used, looks like the current behavior is to audit log the authenticated user (not the user being impersonated - makes sense). In that case, maybe we can use the new header you are introducing in here and use it if the header is populated.

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure what you mean. The signature of logSucceededLogin looks like this:
public void logSucceededLogin(String effectiveUser, boolean securityAdmin, String initiatingUser, SecurityRequest request)

I understood it so that the user being impersonated should be effectiveUser and authenticated user should be initiatingUser. So I added the authenticated user to context so I can log it later in SecurityRestFilter.

Copy link
Author

Choose a reason for hiding this comment

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

Actually now when I look closer, it seems that logSucceededLogin was called with effectiveUser and initiatingUser, even if they are the same user. So, I can always add authenticated user in context even there is no impersonation going on and always log it. Tests will probably pass with this also.

@olkkoti olkkoti force-pushed the auditlog-without-rest-authorization branch from e4f6268 to 017f342 Compare February 11, 2025 16:56
…try in order to get request body.

This fixes the issue opensearch-project#4094

Signed-off-by: Timo Olkkonen <timo.olkkonen@reaktor.com>
@olkkoti olkkoti force-pushed the auditlog-without-rest-authorization branch from 017f342 to 0092ae8 Compare February 11, 2025 16:56
@olkkoti olkkoti requested a review from cwperks February 11, 2025 17:00
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