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 new audit handler method for action responses #63708

Merged

Conversation

albertzaharovits
Copy link
Contributor

@albertzaharovits albertzaharovits commented Oct 14, 2020

This adds a new method to the AuditTrail that intercepts the responses of transport actions. This new method is unlike all the other existing audit methods because it is called after the action has been run (so that it has access to the response).

In order to facilitate the "linking" of the new audit event with the other existing events, the audit method receives the requestId and the authentication as arguments (in addition to the request itself and the response).

This is labeled non-issue because it is only the foundation upon which later features that actually print out (some) responses can be built upon.

Related #63221

@@ -47,6 +48,10 @@ void accessGranted(String requestId, Authentication authentication, String actio
void accessDenied(String requestId, Authentication authentication, String action, TransportRequest transportRequest,
AuthorizationInfo authorizationInfo);

// this is the only audit method that is called *after* the action executed, when the response is available
void actionResponse(String requestId, Authentication authentication, String action, TransportRequest transportRequest,
TransportResponse transportResponse);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the new audit method.

Authentication authentication = securityContext.getAuthentication();
auditTrailService.get().actionResponse(requestId, authentication, action, request, response);
contextPreservingListener.onResponse(response);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This intercepts the response for the action that is executed inside the rest handler (that do NOT go to other cluster nodes).

public void sendResponse(Exception exception) throws IOException {
channel.sendResponse(exception);
}
}, task);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This intercepts the response for actions executed on other cluster nodes (when an action on the coordinating node submits requests to other nodes - or even the same node)

// it is however *only called for coordinating actions*, which are the actions that a client invokes as opposed to
// the actions that a node invokes in order to service a client request
void coordinatingActionResponse(String requestId, Authentication authentication, String action, TransportRequest transportRequest,
TransportResponse transportResponse);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not technically true, some actions' (TransportMasterNodeAction) responses are intercepted on the coordinating node, as well as on the master node.

The naming and descriptions are difficult to write to convey the subset of actions that are covered.
We could also bleed some internals in here and mention the SecurityActionFilter.

Open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

I think we could keep the previous name, i.e. actionResponse. Please let me explain: When I suggested pulling out the code from SecurityServerTransportInterceptor, it was in the context of getting auditing for API key ID in for v7.11.0. The reasons are:

  • The response in SecurityServerTransportInterceptor is a fairly low level indexing response and does not really provide extra valuable information than the one in the coordinating node. Therefore auditing on just the coordinating node is sufficient.
  • Creating API key is underlyingly a TransportReplicationAction. Unlike TransportMasterNodeAction, it does not go through the SecurityActionFilter (on the remote node). This means: on the remote node, we will not get another auditing entry from SecurityActionFilter, i.e. there will only be a single auditing entry about API key creation and it is on the coordinating node.

So my motivation was rather narrowly focused on the particular use case. The agreement, as I understand it, is to defer the auditing code in SecurityServerTransportInterceptor until the next release. Because it is not necessary for API key auditing in this release and if it is not in use, it's better to be left out. But we also agreed that it could still be useful when we expand the usage scenario and this is subject to further discussion.

IIUC, your intention of changing the method name is for the possibility to have two different audit event types. I should have been clear that it was not my proposal. I consider whether auditing inside SecurityServerTransportInterceptor an implementation detail, which we chose to opt out for initial release, but could choose to add it later as an enhancement. For verbosity and duplication control, I'd prefer to solve it in a different way other than splitting it into different audit event types. I hope this makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the detailed explanation Yang, but I would like to focus the conversation on the scope of this PR only. We should consider the broader picture, as you describe, but ultimately this PR is what gets merged as a unit, and what we merge in the future is subject to debate still.

If we merge this PR, which adds the audit hook for the responses of actions intercepted by the SecurityActionFilter only, we add to the interface of the LoggingAuditTrail .
When we later merge the code to allow intercepting the responses of the other actions, we have the options to:

  • reuse the same LoggingAuditTrail hook method
  • rename the existing hook method, or
  • add a new audit response hook method.
    (or any mix of them, really, if we feel wild)

Because this is a private interface, I don't believe we have to name it in anticipation of its use. We should name it for the purpose that it serves right now, as we can always tinker with it later. For this reason, I would not favor the actionResponse name.

Copy link
Member

Choose a reason for hiding this comment

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

Just trying to brainstorm here: How about calling this one actionResponse and the other one transportResponse?
As you said, this is a private interface, so we don't have to struggle too much with its name now. So please feel free to use whatever works for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this could work. I'll keep this in mind when we'll iterate on the interface.

@albertzaharovits
Copy link
Contributor Author

@ywangd As convened, I have chopped this PR to insert the new audit hook method only on the responses of actions intercepted by the SecurityActionFilter.

Ready for feedback.

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the iterations!

Other than the following few minor comment. I also commented on the method name of the new audit method. The changes to AuthenticationServiceTests are quite noisy, but I cannot think of a better way of doing it without major revamping. I think I won’t bother with it given the changes do the right job and they are test only code.

@albertzaharovits
Copy link
Contributor Author

@tvernum are you planning on reviewing as well?

…ecurity/action/filter/SecurityActionFilter.java

Co-authored-by: Tim Vernum <[email protected]>
@albertzaharovits
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/bwc

@albertzaharovits
Copy link
Contributor Author

@elasticmachine update branch

@albertzaharovits albertzaharovits merged commit d967c75 into elastic:master Dec 17, 2020
@albertzaharovits albertzaharovits deleted the post_authz_audit_event branch December 17, 2020 19:52
@albertzaharovits albertzaharovits restored the post_authz_audit_event branch December 17, 2020 19:52
@albertzaharovits albertzaharovits deleted the post_authz_audit_event branch December 17, 2020 19:52
@albertzaharovits albertzaharovits restored the post_authz_audit_event branch December 17, 2020 19:53
@albertzaharovits albertzaharovits changed the title Add new audit event for action responses Add new audit method for action responses Dec 17, 2020
albertzaharovits added a commit to albertzaharovits/elasticsearch that referenced this pull request Dec 17, 2020
This adds a new method to the AuditTrail that intercepts the
responses of transport-level actions. This new method is unlike all
the other existing audit methods because it is called after the
action has been run (so that it has access to the response).
After careful deliberation, the new method is called for the
responses of actions that are intercepted by the
`SecurityActionFilter` only, and not by the transport filter.

In order to facilitate the "linking" of the new audit event with the
other existing events, the audit method receives the requestId
as well as the authentication as arguments (in addition to the
request itself and the response).

This is labeled non-issue because it is only the foundation
upon which later features that actually print out (some) responses
can be built upon.

Related elastic#63221
@albertzaharovits albertzaharovits changed the title Add new audit method for action responses Add new audit handler method for action responses Dec 17, 2020
albertzaharovits added a commit that referenced this pull request Dec 17, 2020
This adds a new method to the AuditTrail that intercepts the
responses of transport-level actions. This new method is unlike all
the other existing audit methods because it is called after the
action has been run (so that it has access to the response).
After careful deliberation, the new method is called for the
responses of actions that are intercepted by the
`SecurityActionFilter` only, and not by the transport filter.

In order to facilitate the "linking" of the new audit event with the
other existing events, the audit method receives the requestId
as well as the authentication as arguments (in addition to the
request itself and the response).

This is labeled non-issue because it is only the foundation
upon which later features that actually print out (some) responses
can be built upon.

Related #63221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Security/Audit X-Pack Audit logging Team:Security Meta label for security team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants