Search in sources :

Example 1 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 parseHttpConnectionManager.

@VisibleForTesting
static io.grpc.xds.HttpConnectionManager parseHttpConnectionManager(HttpConnectionManager proto, Set<String> rdsResources, FilterRegistry filterRegistry, boolean parseHttpFilter, boolean isForClient) throws ResourceInvalidException {
    if (enableRbac && proto.getXffNumTrustedHops() != 0) {
        throw new ResourceInvalidException("HttpConnectionManager with xff_num_trusted_hops unsupported");
    }
    if (enableRbac && !proto.getOriginalIpDetectionExtensionsList().isEmpty()) {
        throw new ResourceInvalidException("HttpConnectionManager with " + "original_ip_detection_extensions unsupported");
    }
    // Obtain max_stream_duration from Http Protocol Options.
    long maxStreamDuration = 0;
    if (proto.hasCommonHttpProtocolOptions()) {
        HttpProtocolOptions options = proto.getCommonHttpProtocolOptions();
        if (options.hasMaxStreamDuration()) {
            maxStreamDuration = Durations.toNanos(options.getMaxStreamDuration());
        }
    }
    // Parse http filters.
    List<NamedFilterConfig> filterConfigs = null;
    if (parseHttpFilter) {
        if (proto.getHttpFiltersList().isEmpty()) {
            throw new ResourceInvalidException("Missing HttpFilter in HttpConnectionManager.");
        }
        filterConfigs = new ArrayList<>();
        Set<String> names = new HashSet<>();
        for (int i = 0; i < proto.getHttpFiltersCount(); i++) {
            io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter httpFilter = proto.getHttpFiltersList().get(i);
            String filterName = httpFilter.getName();
            if (!names.add(filterName)) {
                throw new ResourceInvalidException("HttpConnectionManager contains duplicate HttpFilter: " + filterName);
            }
            StructOrError<FilterConfig> filterConfig = parseHttpFilter(httpFilter, filterRegistry, isForClient);
            if ((i == proto.getHttpFiltersCount() - 1) && (filterConfig == null || !isTerminalFilter(filterConfig.struct))) {
                throw new ResourceInvalidException("The last HttpFilter must be a terminal filter: " + filterName);
            }
            if (filterConfig == null) {
                continue;
            }
            if (filterConfig.getErrorDetail() != null) {
                throw new ResourceInvalidException("HttpConnectionManager contains invalid HttpFilter: " + filterConfig.getErrorDetail());
            }
            if ((i < proto.getHttpFiltersCount() - 1) && isTerminalFilter(filterConfig.getStruct())) {
                throw new ResourceInvalidException("A terminal HttpFilter must be the last filter: " + filterName);
            }
            filterConfigs.add(new NamedFilterConfig(filterName, filterConfig.struct));
        }
    }
    // Parse inlined RouteConfiguration or RDS.
    if (proto.hasRouteConfig()) {
        List<VirtualHost> virtualHosts = extractVirtualHosts(proto.getRouteConfig(), filterRegistry, parseHttpFilter);
        return io.grpc.xds.HttpConnectionManager.forVirtualHosts(maxStreamDuration, virtualHosts, filterConfigs);
    }
    if (proto.hasRds()) {
        Rds rds = proto.getRds();
        if (!rds.hasConfigSource()) {
            throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: missing config_source");
        }
        if (!rds.getConfigSource().hasAds() && !rds.getConfigSource().hasSelf()) {
            throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
        }
        // Collect the RDS resource referenced by this HttpConnectionManager.
        rdsResources.add(rds.getRouteConfigName());
        return io.grpc.xds.HttpConnectionManager.forRdsName(maxStreamDuration, rds.getRouteConfigName(), filterConfigs);
    }
    throw new ResourceInvalidException("HttpConnectionManager neither has inlined route_config nor RDS");
}
Also used : Rds(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) HttpProtocolOptions(io.envoyproxy.envoy.config.core.v3.HttpProtocolOptions) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterConfig(io.grpc.xds.Filter.FilterConfig) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 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_pluginNameNotFound.

@Test
public void parseHttpConnectionManager_pluginNameNotFound() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build();
    TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier)).build();
    io.envoyproxy.envoy.config.route.v3.Route route = io.envoyproxy.envoy.config.route.v3.Route.newBuilder().setName("route-1").setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")).setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder().setClusterSpecifierPlugin("invalid-plugin-name")).build();
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setRouteConfig(RouteConfiguration.newBuilder().addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig).build()).addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-1").addRoutes(route))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("ClusterSpecifierPlugin for [invalid-plugin-name] not found");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) TypedExtensionConfig(io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig) Test(org.junit.Test)

Example 3 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_duplicatePluginName.

@Test
public void parseHttpConnectionManager_duplicatePluginName() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    RouteLookupConfig routeLookupConfig1 = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier1 = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig1).build();
    RouteLookupConfig routeLookupConfig2 = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service3")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier2 = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig2).build();
    TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier1)).build();
    TypedExtensionConfig typedExtensionConfig2 = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier2)).build();
    io.envoyproxy.envoy.config.route.v3.Route route = io.envoyproxy.envoy.config.route.v3.Route.newBuilder().setName("route-1").setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")).setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder().setClusterSpecifierPlugin("rls-plugin-1")).build();
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setRouteConfig(RouteConfiguration.newBuilder().addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig).build()).addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig2).build()).addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-1").addRoutes(route))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("Multiple ClusterSpecifierPlugins with the same name: rls-plugin-1");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) TypedExtensionConfig(io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig) Test(org.junit.Test)

Example 4 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_xffNumTrustedHopsUnsupported.

@Test
public void parseHttpConnectionManager_xffNumTrustedHopsUnsupported() throws ResourceInvalidException {
    @SuppressWarnings("deprecation") HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setXffNumTrustedHops(2).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager with xff_num_trusted_hops unsupported");
    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 5 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_lastNotTerminal.

@Test
public void parseHttpConnectionManager_lastNotTerminal() throws ResourceInvalidException {
    filterRegistry.register(FaultFilter.INSTANCE);
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true)).addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.bar").setIsOptional(true).setTypedConfig(Any.pack(HTTPFault.newBuilder().build()))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("The last HttpFilter must be a terminal filter: envoy.filter.bar");
    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)

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