Skip to content

Handle slow security policies without blocking gRPC threads. - #10633

Merged
markb74 merged 11 commits into
grpc:masterfrom
mateusazis:sync_to_async
Dec 6, 2023
Merged

Handle slow security policies without blocking gRPC threads.#10633
markb74 merged 11 commits into
grpc:masterfrom
mateusazis:sync_to_async

Conversation

@mateusazis

Copy link
Copy Markdown
Collaborator
  • Introduce PendingAuthListener to handle a ListenableFuture, progressing the gRPC through each stage in sequence once the future completes and is OK.
  • Move unit tests away from checkAuthorizationForService and into checkAuthorizationForServiceAsync since that should be the only method called in production now.
  • Some tests in ServerSecurityPolicyTest had their expectations updated; they previously called synchornous APIs that transformed failed ListenableFuture<Status> into one or another status. Now, we call the sync API, so those transformations do not happen anymore, thus the test needs to deal with failed futures directly.
  • I couldn't figure out if this PR needs extra tests. AFAICT BinderSecurityTest should already cover the new codepaths, but please let me know otherwise.

This should be the last PR to address #10566.

- Introduce PendingAuthListener to handle a ListenableFuture<Status>, progressing the gRPC through each stage in sequence once the future completes and is OK.
- Move unit tests away from `checkAuthorizationForService` and into `checkAuthorizationForServiceAsync` since that should be the only method called in production now.
- Some tests in `ServerSecurityPolicyTest` had their expectations updated; they previously called synchornous APIs that transformed failed `ListenableFuture<Status>` into one or another status. Now, we call the sync API, so those transformations do not happen anymore, thus the test needs to deal with failed futures directly.
- I couldn't figure out if this PR needs extra tests. AFAICT `BinderSecurityTest` should already cover the new codepaths, but please let me know otherwise.

This should be the last PR to address grpc#10566.
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
- Drop sequential executor from PendingAuthListener.
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
@mateusazis
mateusazis requested a review from jdcormie November 7, 2023 18:46
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/test/java/io/grpc/binder/ServerSecurityPolicyTest.java Outdated
- Factory method for PendingAuthListener.
- Fix leak of executor when PendingAuthListener encountered an exception while starting the call.
- Catching RuntimeException.
@mateusazis
mateusazis requested a review from jdcormie November 14, 2023 22:08
- Comment + TODO for multiple concurrent auth checks.
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/PendingAuthListener.java Outdated

@jdcormie jdcormie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
@mateusazis
mateusazis requested a review from markb74 November 16, 2023 18:52

@markb74 markb74 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Getting really close.

I'm happy with this overall, but I'd like some changes to make this easier to review more completely.

I.e. Undo changes to the struture of interceptCall per my comment there, and undo all unrelated reformatting.

Comment thread binder/src/main/java/io/grpc/binder/BinderServerBuilder.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderServer.java Outdated
Comment thread binder/src/test/java/io/grpc/binder/ServerSecurityPolicyTest.java
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderServer.java Outdated
- define BinderTransportSecurity.ShutdownListener interface
- take a non-close executor closeable in BinderServer's constructor
@mateusazis
mateusazis requested a review from markb74 November 29, 2023 23:41

@markb74 markb74 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks so much for your patience!

Just a couple of minor nits now, then we can go ahead and submit.

There's a couple more things we'll want to do in a follow up to handle nuance around policy decision caching, and server vs. transport shutdown, but this is in a good state.

Comment thread binder/src/main/java/io/grpc/binder/internal/BinderServer.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderServer.java Outdated
Comment thread binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java Outdated
* resources to be potentially cleaned up.
*/
public interface ShutdownListener {
void onShutdown();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Server shutdown is actually kind of complex, so if we're going to use the prefix "on" (which I agree makes sense in a listener), we probably want to clarify that this is the server shutdown, and rename this to onServerShutdown().

FWIW, there's actually a bit more nuance here we'll need to handle, but let's leave that for a follow up CL.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Renamed.

By "nuance", do you mean code style-wise or are we actually missing something from the implementation? Because if it's the later, I'm not aware of what that is.

@markb74 markb74 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 4, 2023
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 4, 2023
@markb74 markb74 added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 5, 2023
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 5, 2023
@markb74
markb74 merged commit a053889 into grpc:master Dec 6, 2023
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants