Search in sources :

Example 11 with HttpConnectionManager

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_validateRdsConfigSource.

@Test
public void parseHttpConnectionManager_validateRdsConfigSource() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    Set<String> rdsResources = new HashSet<>();
    HttpConnectionManager hcm1 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))).build();
    ClientXdsClient.parseHttpConnectionManager(hcm1, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
    HttpConnectionManager hcm2 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setSelf(SelfConfigSource.getDefaultInstance()))).build();
    ClientXdsClient.parseHttpConnectionManager(hcm2, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
    HttpConnectionManager hcm3 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setPath("foo-path"))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
    ClientXdsClient.parseHttpConnectionManager(hcm3, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with HttpConnectionManager

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_duplicateHttpFilters.

@Test
public void parseHttpConnectionManager_duplicateHttpFilters() throws ResourceInvalidException {
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true)).addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true)).addHttpFilters(HttpFilter.newBuilder().setName("terminal").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true)).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager contains duplicate HttpFilter: envoy.filter.foo");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, true, /* parseHttpFilter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) Test(org.junit.Test)

Example 13 with HttpConnectionManager

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_terminalNotLast.

@Test
public void parseHttpConnectionManager_terminalNotLast() throws ResourceInvalidException {
    filterRegistry.register(RouterFilter.INSTANCE);
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().addHttpFilters(HttpFilter.newBuilder().setName("terminal").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true)).addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true)).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("A terminal HttpFilter must be the last filter: terminal");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, true, /* parseHttpFilter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) Test(org.junit.Test)

Example 14 with HttpConnectionManager

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_missingRdsAndInlinedRouteConfiguration.

@Test
public void parseHttpConnectionManager_missingRdsAndInlinedRouteConfiguration() throws ResourceInvalidException {
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setCommonHttpProtocolOptions(HttpProtocolOptions.newBuilder().setMaxStreamDuration(Durations.fromNanos(1000L))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager neither has inlined route_config nor RDS");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* does not matter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) Test(org.junit.Test)

Example 15 with HttpConnectionManager

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager in project grpc-java by grpc.

the class ClientXdsClient method parseFilterChain.

@VisibleForTesting
static FilterChain parseFilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain proto, Set<String> rdsResources, TlsContextManager tlsContextManager, FilterRegistry filterRegistry, Set<FilterChainMatch> uniqueSet, Set<String> certProviderInstances, boolean parseHttpFilters) throws ResourceInvalidException {
    if (proto.getFiltersCount() != 1) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " should contain exact one HttpConnectionManager filter");
    }
    io.envoyproxy.envoy.config.listener.v3.Filter filter = proto.getFiltersList().get(0);
    if (!filter.hasTypedConfig()) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " contains filter " + filter.getName() + " without typed_config");
    }
    Any any = filter.getTypedConfig();
    // HttpConnectionManager is the only supported network filter at the moment.
    if (!any.getTypeUrl().equals(TYPE_URL_HTTP_CONNECTION_MANAGER)) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " contains filter " + filter.getName() + " with unsupported typed_config type " + any.getTypeUrl());
    }
    HttpConnectionManager hcmProto;
    try {
        hcmProto = any.unpack(HttpConnectionManager.class);
    } catch (InvalidProtocolBufferException e) {
        throw new ResourceInvalidException("FilterChain " + proto.getName() + " with filter " + filter.getName() + " failed to unpack message", e);
    }
    io.grpc.xds.HttpConnectionManager httpConnectionManager = parseHttpConnectionManager(hcmProto, rdsResources, filterRegistry, parseHttpFilters, false);
    EnvoyServerProtoData.DownstreamTlsContext downstreamTlsContext = null;
    if (proto.hasTransportSocket()) {
        if (!TRANSPORT_SOCKET_NAME_TLS.equals(proto.getTransportSocket().getName())) {
            throw new ResourceInvalidException("transport-socket with name " + proto.getTransportSocket().getName() + " not supported.");
        }
        DownstreamTlsContext downstreamTlsContextProto;
        try {
            downstreamTlsContextProto = proto.getTransportSocket().getTypedConfig().unpack(DownstreamTlsContext.class);
        } catch (InvalidProtocolBufferException e) {
            throw new ResourceInvalidException("FilterChain " + proto.getName() + " failed to unpack message", e);
        }
        downstreamTlsContext = EnvoyServerProtoData.DownstreamTlsContext.fromEnvoyProtoDownstreamTlsContext(validateDownstreamTlsContext(downstreamTlsContextProto, certProviderInstances));
    }
    FilterChainMatch filterChainMatch = parseFilterChainMatch(proto.getFilterChainMatch());
    checkForUniqueness(uniqueSet, filterChainMatch);
    return FilterChain.create(proto.getName(), filterChainMatch, httpConnectionManager, downstreamTlsContext, tlsContextManager);
}
Also used : DownstreamTlsContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any) FilterChainMatch(io.grpc.xds.EnvoyServerProtoData.FilterChainMatch) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HttpConnectionManager (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager)13 Test (org.junit.Test)13 TypedExtensionConfig (io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig)3 RouteLookupClusterSpecifier (io.grpc.lookup.v1.RouteLookupClusterSpecifier)3 RouteLookupConfig (io.grpc.lookup.v1.RouteLookupConfig)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HashSet (java.util.HashSet)2 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 HttpProtocolOptions (io.envoyproxy.envoy.config.core.v3.HttpProtocolOptions)1 Filter (io.envoyproxy.envoy.config.listener.v3.Filter)1 FilterChain (io.envoyproxy.envoy.config.listener.v3.FilterChain)1 ListenerFilter (io.envoyproxy.envoy.config.listener.v3.ListenerFilter)1 RBACPerRoute (io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute)1 HttpFilter (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter)1 Rds (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds)1 DownstreamTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext)1 NamedPluginConfig (io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 FilterChainMatch (io.grpc.xds.EnvoyServerProtoData.FilterChainMatch)1