Commit Graph

5577 Commits

Author SHA1 Message Date
yifeizhuang fe8f474055
xds: Fix AbstractXdsClient fromTypeUrl to use subscribedResources instead of hardcoded (#9607) 2022-10-07 13:33:38 -07:00
yifeizhuang 68339250e4
xds: remove ResourceType enum, use XdsResourceType instead (#9587)
Now the xds resources are dynamically managed in resourceStore in xdsClient. The types is a xdsResourceType, singleton.
There is no longer hardcoded static list of known resource types, the subscription list is the source of truth.
AbstractXdsClient that manages AdsStream will only accept the xds resource types that has already has watchers subscribed to, same behaviour as before.
2022-10-06 13:10:55 -07:00
yifeizhuang cff8bd8d87
doc: name resolver start() should not throw (#9589) 2022-10-05 16:22:30 -07:00
Terry Wilson df0a4bdc1b
Update README etc to reference 1.49.2 (#9588) 2022-10-04 15:16:09 -07:00
Terry Wilson dd35ae5206
okhttp: Add client transport proxy socket timeout (#9586)
Not having a timeout when reading the response from a proxy server can
cause a hang if network connectivity is lost at the same time.
2022-10-04 12:43:02 -07:00
sanjaypujare 6b80efcfa8
xds: security code refactoring: delete unused code and rename misc things (#9583) 2022-10-04 12:41:17 -07:00
Eric Anderson b118e00cf9
Use Protobuf 21.7 in our code generator
This aligns the C++ version we're using for gRPC-generated code with the
Java version. This should have no real impact to our users, as there
were no features added to .proto files or the like that would be visible
to users.
2022-10-04 10:22:52 -07:00
Alexander Polcyn b7363bc854 Revert "rls: use acceptResolvedAddresses() (#9569)"
This reverts commit 3b62fbe365.
2022-10-03 16:15:51 -07:00
Alexander Polcyn 114e1dfbf7 google-c2p resolver: add authority entry to bootstrap config 2022-09-30 15:25:50 -07:00
Eric Anderson 85bdca45fa Bump Protobuf to 3.21.7 2022-09-30 14:02:45 -07:00
sanjaypujare ba8cd04191
xds: rename ClientXdsClient to XdsClientImpl (#9573) 2022-09-30 09:32:52 -07:00
Terry Wilson 3b62fbe365
rls: use acceptResolvedAddresses() (#9569)
Switch over from handleResolvedAddresses as part of a LoadBalancer
public API refactoring.
2022-09-29 12:51:31 -07:00
Sergii Tkachenko eaf8b28930
netty: create adaptive cumulator (#9558)
Creates "Adaptive" cumulator: cumulate ByteBuf's by dynamically switching between merge and compose strategies.

This cumulator applies a heuristic to make a decision whether to track a reference to the buffer with bytes received from the network stack in an array ("zero-copy"), or to merge into the last component (the tail) by performing a memory copy.

It is necessary as a protection from a potential attack on the COMPOSITE_CUMULATOR. Consider a pathological case when an attacker sends TCP packages containing a single byte of data, and forcing the cumulator to track each one in a separate buffer. In this case we'll be paying a memory overhead for each buffer, as well as extra compute to read the cumulation.

Implemented heuristic establishes a minimal threshold for the total size of the tail and incoming buffer, below which they are merged. The sum of the tail and the incoming buffer is used to avoid a case where attacker alternates the size of data packets to trick the cumulator into always selecting compose strategy.

Merging strategy attempts to minimize unnecessary memory writes. When possible, it expands the tail capacity and only copies the incoming buffer into available memory. Otherwise, when both tail and the buffer must be copied, the tail is reallocated (or fully replaced) with a new buffer of exponentially increasing capacity (bounded to minComposeSize) to ensure runtime O(n^2) amortized to O(n).

Note: this reintroduces https://github.com/grpc/grpc-java/pull/7532, addressing the subtle issue (ref b/155940949) with `CompositeByteBuf.component()` indexes getting out of sync, which results in the merge operation producing broken buffers.
2022-09-27 19:21:46 -07:00
Eric Anderson 5b62d22802 Start 1.51.0 development cycle 2022-09-26 16:37:56 -07:00
Eric Anderson e998955d1d xds: Avoid NPE from update after removing subscriptions
This fixes a regression in commit e1ad984. I'd create a test, but the
NPE gets thrown away in the context of the current test setup so can't
be created as quickly as we'd like to fix this. I have manually tested
in a custom reproduction to confirm it resolves the NPE.

Seen at b/248326695

```
java.lang.AssertionError: java.lang.NullPointerException
        at io.grpc.xds.ClientXdsClient$1.uncaughtException(ClientXdsClient.java:89)
        at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:97)
        at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
        at io.grpc.xds.ClientXdsClient.cancelXdsResourceWatch(ClientXdsClient.java:327)
        at io.grpc.xds.ClusterResolverLoadBalancer$ClusterResolverLbState$EdsClusterState.shutdown(ClusterResolverLoadBalancer.java:378)
        at io.grpc.xds.ClusterResolverLoadBalancer$ClusterResolverLbState.shutdown(ClusterResolverLoadBalancer.java:206)
        at io.grpc.util.GracefulSwitchLoadBalancer.shutdown(GracefulSwitchLoadBalancer.java:195)
        at io.grpc.xds.ClusterResolverLoadBalancer.shutdown(ClusterResolverLoadBalancer.java:141)
        at io.grpc.xds.CdsLoadBalancer2$CdsLbState.shutdown(CdsLoadBalancer2.java:136)
        at io.grpc.xds.CdsLoadBalancer2.shutdown(CdsLoadBalancer2.java:110)
        at io.grpc.util.GracefulSwitchLoadBalancer.shutdown(GracefulSwitchLoadBalancer.java:195)
        at io.grpc.xds.ClusterManagerLoadBalancer$ChildLbState.shutdown(ClusterManagerLoadBalancer.java:256)
        at io.grpc.xds.ClusterManagerLoadBalancer.shutdown(ClusterManagerLoadBalancer.java:138)
        at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.shutdown(AutoConfiguredLoadBalancerFactory.java:164)
        at io.grpc.internal.ManagedChannelImpl.shutdownNameResolverAndLoadBalancer(ManagedChannelImpl.java:381)
        at io.grpc.internal.ManagedChannelImpl.access$8200(ManagedChannelImpl.java:118)
        at io.grpc.internal.ManagedChannelImpl$DelayedTransportListener.transportTerminated(ManagedChannelImpl.java:2174)
        at io.grpc.internal.DelayedClientTransport$3.run(DelayedClientTransport.java:122)
        at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:95)
        at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
        at io.grpc.internal.ManagedChannelImpl$RealChannel.shutdown(ManagedChannelImpl.java:1057)
        at io.grpc.internal.ManagedChannelImpl.shutdown(ManagedChannelImpl.java:817)
        at io.grpc.internal.ManagedChannelImpl.shutdownNow(ManagedChannelImpl.java:837)
        at io.grpc.internal.ManagedChannelImpl.shutdownNow(ManagedChannelImpl.java:117)
        at io.grpc.internal.ForwardingManagedChannel.shutdownNow(ForwardingManagedChannel.java:52)
        at io.grpc.internal.ManagedChannelOrphanWrapper.shutdownNow(ManagedChannelOrphanWrapper.java:65)
        at io.grpc.testing.integration.GrpclbFallbackTestClient.tearDown(GrpclbFallbackTestClient.java:178)
        at io.grpc.testing.integration.GrpclbFallbackTestClient.main(GrpclbFallbackTestClient.java:67)
Caused by: java.lang.NullPointerException
        at io.grpc.xds.ClientXdsClient.handleResourceResponse(ClientXdsClient.java:179)
        at io.grpc.xds.AbstractXdsClient$AbstractAdsStream.handleRpcResponse(AbstractXdsClient.java:358)
        at io.grpc.xds.AbstractXdsClient$AdsStreamV3$1$1.run(AbstractXdsClient.java:511)
        at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:95)
        ... 26 more
```
2022-09-26 16:37:37 -07:00
sanjaypujare 6f8e44a7f5
xds: security code refactoring/renaming (#9555)
* xds: security code refactoring/renaming
1) move certprovider package under security
2) refactor inner Factory into  CertProviderClientSslContextProviderFactory and CertProviderServerSslContextProviderFactory
3) Make CertProviderClientSslContextProvider and CertProviderServerSslContextProvider non-public
4) use only public (non package private) types like SslContextProvider (instead of CertProviderClientSslContextProvider etc)
2022-09-24 00:05:15 -07:00
sanjaypujare 0cda133c52
observability: replace current OpenCensus registerAllGrpcViews with only selected views for GCP observability (#9561) 2022-09-23 13:24:27 -07:00
Terry Wilson 2289956ec7
core: outlier_detection LB to use acceptResolvedAddresses() (#9557)
Switch OutlierDetectionLoadBalancer to implement
acceptResolvedAddresses() to allow for the eventual deprecation of
handleResolvedAddresses().
2022-09-19 20:20:08 -07:00
apolcyn 8925696b3e
Revert "xds: prevent concurrent priority LB picker updates (#9363)" (#9554)
This reverts commit bcf5cde7dd.
2022-09-19 08:29:41 -07:00
yifeizhuang e1ad984db3
xds: refactor xds client to make it resource agnostic (#9444)
Mainly refactor work to make type specific xds resources generic, e.g.
1. Define abstract class XdsResourceType to be extended by pluggable new resources. It mainly contains abstract method doParse() to parse unpacked proto messges and produce a ResourceUpdate. The common unpacking proto logic is in XdsResourceType default method parse()
2. Move the parsing/processing logics to specific XdsResourceType. Implementing:
XdsListenerResource for LDS
XdsRouteConfigureResource for RDS
XdsClusterResource for CDS
XdsEndpointResource for EDS
3. The XdsResourceTypes are singleton. To process for each XdsClient, context is passed in parameters, defined by XdsResourceType.Args.
4. Watchers will use generic APIs to subscribe to resource watchXdsResource(XdsResourceType, resourceName, watcher). Watcher and ResourceSubscribers becomes java generic class.
2022-09-16 10:08:16 -07:00
yifeizhuang a3c1d7711f
okhttp: add okhttpServerBuilder permitKeepAliveTime() and permitKeepAliveWithoutCalls() for server keepAlive enforcement (#9544) 2022-09-15 16:08:55 -07:00
Terry Wilson 15033caf1c
core: pick_first LB to use acceptResolvedAddresses() (#9548) 2022-09-15 14:21:10 -07:00
Terry Wilson 79c4c355ba
okhttp: Fair treatment when writing out streams (#9545)
When allocating bytes to streams within a flow control window we always
go through the streams in the same order. This can lead to large streams
hogging all the bytes and a smaller one down the list getting starved
out. This change shuffles the stream array to lower the chance of this
happening.

Fixes #9089
2022-09-15 09:35:23 -07:00
Terry Wilson 341fea8996
core: Convert inappropriate call cred errors (#9543)
If a CallCredentials implementation returns an error that is not
appropriate to propagate from the control plane to the data plane, we
convert it to an INTERNAL error. This makes the inappropriate control
plane behavior to be discoverable in the logs.

https://github.com/grpc/proposal/blob/master/A54-restrict-control-plane-status-codes.md
2022-09-13 13:36:40 -07:00
Terry Wilson 944cbf84ed
core: Comment on "inappropriate" service config errors (#9542)
https://github.com/grpc/proposal/blob/master/A54-restrict-control-plane-status-codes.md
2022-09-13 09:57:55 -07:00
Kun Zhang 38b338228a
core: add getCallOptions() to CallCredentials.RequestInfo (#9538)
This is needed internally (b/134067789#comment20).
2022-09-13 08:55:05 -07:00
Terry Wilson 9853a0c463
core: Don't delegate inappropriate ConfigSelector errors (#9536)
In case a control plane returns an "inappropriate" response code, it is converted to INTERNAL to highlight the bug in the control plane.

https://github.com/grpc/proposal/blob/master/A54-restrict-control-plane-status-codes.md
2022-09-12 13:17:16 -07:00
Terry Wilson bcf5cde7dd
xds: prevent concurrent priority LB picker updates (#9363)
If a child policy triggers an update to the parent priority policy
it will be ignored if an update is already in process.
2022-09-12 11:17:51 -07:00
Eric Anderson bacf18db8d
census: Avoid deprecated measure constants
Many of the deprecated constants are just aliases for non-deprecated
constants, so just swap which one we use.
2022-09-12 08:19:21 -07:00
yifeizhuang 42e68149a5
xds: ringhash policy in TRANSIENT_FAILURE should not attempt connecting when already in connecting (#9535) 2022-09-09 17:27:22 -07:00
Terry Wilson 84d0b0474f
core: Replace inappropriate picker result status codes (#9530)
Certain status codes are inappropriate for a control plane to be
returning and indicate a bug in the control plane. These status codes
will be replaced by INTERNAL, to make it clearer to see that the control
plane is misbehaving.
2022-09-09 15:46:28 -07:00
yifeizhuang eac4178eaa
okhttp: add max connection idle at OkHttpServer and fix test (#9533)
* Revert "Revert "okhttp: add max connection idle at OkHttpServer (#9494)" (#9528)"

This reverts commit 95b9d6db29 and fixed flaky test.
2022-09-09 12:53:47 -07:00
sanjaypujare 88a035e2c2
xds: rename package io.grpc.xds.internal.sds to io.grpc.xds.internal.security (#9532) 2022-09-09 09:21:03 -07:00
Eric Anderson 24287b0b14 binder: Fix expected result of security test
The test name includes "fails" but it asserts the result is OK. The test
was added in #9428.

The binder tests are passing on the Android CI, but for some reason the
tests with sdk >= 29 are skipped. Robolectric 4.8 claims API level 32
support and the tests are skipped even when using Java 11 and 17.
2022-09-09 09:18:43 -07:00
sanjaypujare 074e919304
xds: rename Sds to Security or Xds in various classes to eliminate references to SDS (#9529) 2022-09-08 09:35:03 -07:00
yifeizhuang 95b9d6db29
Revert "okhttp: add max connection idle at OkHttpServer (#9494)" (#9528)
This reverts commit 7291ad44c6.
2022-09-08 08:51:16 -07:00
Terry Wilson 53a2d50695
xds: always update priority LB connectivity state (#9527)
Removes the option of skipping the update of the priority LB state when
the failover timer is pending.

This consistency facilitates a future change weher we delay child LB
status updates if the priority LB is performing an update. The upcoming
priority LB policy gRFC also does not require this update to ever be
skipped.
2022-09-08 08:49:07 -07:00
Chris Povirk 6bafca93a7
core: Use real ByteBuffer instead of mock (#9523)
My motivation for making this change is that [`ByteBuffer` is becoming
`sealed`](https://download.java.net/java/early_access/loom/docs/api/java.base/java/nio/ByteBuffer.html)
in new versions of Java. This makes it impossible for Mockito's
_current_ default mockmaker to mock it.

That said, Mockito will likely [switch its default
mockmaker](https://github.com/mockito/mockito/issues/2589) to an
alternative that _is_ able to mock `sealed` classes. However, there are
downside to that, such as [slower
performance](https://github.com/mockito/mockito/issues/2589#issuecomment-1192725206),
so it's probably better to leave our options open by avoiding mocking at
all.

And in this case, it's equally easy to use real objects.

As a bonus, I think that real objects makes the code a little easier to
follow: Before, we created mocks that the code under test never
interacted with in any way. (The code just passed them through to a
delegate.) When I first read the tests, I was confused, since I assumed
that the mock we were creating was the same mock that we then passed to
`verify` at the end of the method. That turned out not to be the case.
2022-09-07 15:50:31 -07:00
Larry Safran 5946eb0d6a
style fix (#9526) 2022-09-07 14:58:42 -07:00
Prateek Karandikar 0fd5751679
Add security policies for checking device owner/profile owner. (#9428) 2022-09-06 20:31:49 -07:00
Terry Wilson bf692c04e6
Add custom_lb to the test suites. (#9502)
Co-authored-by: Sergii Tkachenko <hi@sergii.org>
2022-09-06 15:49:49 -07:00
Terry Wilson 2ee65a9c26
core: Don't forward acceptResolvedAddresses() (#9511)
Forwarding acceptResolvedAddresses() to a delegate in ForwardingLoadBalancer can cause problems if an extending class expects its handleResolvedAddresses implementation to be called even when a client calls handleResolvedAddresses(). This would not happen as ForwardingLoadBalancer would directly send the call to the delegate.
2022-09-06 13:06:48 -07:00
Sergii Tkachenko c8c3d3d6b2
xDS interop: enable pod log collection in the buildscripts (#9495)
- Enables pod log collection in all PSM interop jobs implemented
  in https://github.com/grpc/grpc/pull/30594.
- Associate test suite runs with their own log file, so it's displayed
  on the "Target Log" tab
- Updates security job to not stop after a failed suite, so that
  authz_test run even if security_test failed
- Fix run_test not returning correct exit status, causing false
  positives in some cases. See https://github.com/grpc/grpc/pull/30768
2022-09-06 11:18:27 -07:00
Larry Safran c27f2d5a57
[core,api,auth: Choose executor based on need for thread affinity (#9504)
* core,api,auth: Choose the callOptions executor when applying request metadata to credentials during newStream based upon whether AppEngineCredentials are being used as they require a specific thread to do the processing.

Add an interface to differentiate whether the specific thread is needed.

Fixes b/244209681
2022-09-02 21:55:38 -07:00
yifeizhuang 0a699ad694
netty: upgrade netty from 4.1.77.Final to 4.1.29.Final and tcnative from 2.0.53 to 2.0.54 (#9451) 2022-08-31 16:02:27 -07:00
Terry Wilson 1f33fe6383
core: Assure that context cancellationCause is set (#9501)
core: Assure that context cancellationCause is set

Makes sure that whenever a context is in a cancelled state, we also have
a cancellationCause.
2022-08-31 10:43:22 -07:00
Terry Wilson 4b4cb0bd3b
api,core: Add LoadBalancer.acceptResolvedAddresses() (#9498)
Introduces a new acceptResolvedAddresses() method in LoadBalancer that
is to ultimately replace the existing handleResolvedAddresses(). The new
method allows the LoadBalancer implementation to reject the given
addresses by returning false from the method.

The long deprecated handleResolvedAddressGroups is also removed.
2022-08-31 08:36:50 -07:00
Eric Anderson 8dbff5ba6a core: DelayedClientCall should propagate context
This was already being done for the Listener, but it was missed for the
ClientCall draining itself. That's not too surprising, since very few
things should be looking at the context in that path. We don't care too
much about this client call case, but if the context _does_ end up
mattering it could be painful to debug.

Fixes #9478
2022-08-30 16:42:46 -07:00
sanjaypujare b778947ca6
istio-interop-testing: increase deadline to 5 sec to avoid deadline issue on aarch64 (#9497) 2022-08-30 09:32:52 -07:00
yifeizhuang 7291ad44c6
okhttp: add max connection idle at OkHttpServer (#9494) 2022-08-29 16:25:58 -07:00