use of io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute in project grpc-java by grpc.
the class RbacFilterTest method overrideConfig.
@Test
@SuppressWarnings("unchecked")
public void overrideConfig() {
ServerCallHandler<Void, Void> mockHandler = mock(ServerCallHandler.class);
ServerCall<Void, Void> mockServerCall = mock(ServerCall.class);
Attributes attr = Attributes.newBuilder().set(Grpc.TRANSPORT_ATTR_LOCAL_ADDR, new InetSocketAddress("1::", 20)).build();
when(mockServerCall.getAttributes()).thenReturn(attr);
PolicyMatcher policyMatcher = PolicyMatcher.create("policy-matcher", OrMatcher.create(DestinationPortMatcher.create(99999)), OrMatcher.create(AlwaysTrueMatcher.INSTANCE));
AuthConfig authconfig = AuthConfig.create(Collections.singletonList(policyMatcher), GrpcAuthorizationEngine.Action.ALLOW);
RbacConfig original = RbacConfig.create(authconfig);
RBACPerRoute rbacPerRoute = RBACPerRoute.newBuilder().build();
RbacConfig override = new RbacFilter().parseFilterConfigOverride(Any.pack(rbacPerRoute)).config;
assertThat(override).isEqualTo(RbacConfig.create(null));
ServerInterceptor interceptor = new RbacFilter().buildServerInterceptor(original, override);
assertThat(interceptor).isNull();
policyMatcher = PolicyMatcher.create("policy-matcher-override", OrMatcher.create(DestinationPortMatcher.create(20)), OrMatcher.create(AlwaysTrueMatcher.INSTANCE));
authconfig = AuthConfig.create(Collections.singletonList(policyMatcher), GrpcAuthorizationEngine.Action.ALLOW);
override = RbacConfig.create(authconfig);
new RbacFilter().buildServerInterceptor(original, override).interceptCall(mockServerCall, new Metadata(), mockHandler);
verify(mockHandler).startCall(eq(mockServerCall), any(Metadata.class));
verify(mockServerCall).getAttributes();
verifyNoMoreInteractions(mockServerCall);
}
use of io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseOverrideRbacFilterConfig.
@Test
public void parseOverrideRbacFilterConfig() {
filterRegistry.register(RbacFilter.INSTANCE);
RBACPerRoute rbacPerRoute = RBACPerRoute.newBuilder().setRbac(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBAC.newBuilder().setRules(RBAC.newBuilder().setAction(Action.ALLOW).putPolicies("allow-all", Policy.newBuilder().addPrincipals(Principal.newBuilder().setAny(true)).addPermissions(Permission.newBuilder().setAny(true)).build()))).build();
Map<String, Any> configOverrides = ImmutableMap.of("envoy.auth", Any.pack(rbacPerRoute));
Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
assertThat(parsedConfigs).hasSize(1);
assertThat(parsedConfigs).containsKey("envoy.auth");
assertThat(parsedConfigs.get("envoy.auth")).isInstanceOf(RbacConfig.class);
}
use of io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute in project grpc-java by grpc.
the class RbacFilterTest method parseOverride.
private ConfigOrError<RbacConfig> parseOverride(List<Permission> permissionList, List<Principal> principalList) {
RBACPerRoute rbacPerRoute = RBACPerRoute.newBuilder().setRbac(buildRbac(permissionList, principalList)).build();
Any proto = Any.pack(rbacPerRoute);
return new RbacFilter().parseFilterConfigOverride(proto);
}
use of io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute in project grpc-java by grpc.
the class RbacFilter method parseFilterConfigOverride.
@Override
public ConfigOrError<RbacConfig> parseFilterConfigOverride(Message rawProtoMessage) {
RBACPerRoute rbacPerRoute;
if (!(rawProtoMessage instanceof Any)) {
return ConfigOrError.fromError("Invalid config type: " + rawProtoMessage.getClass());
}
Any anyMessage = (Any) rawProtoMessage;
try {
rbacPerRoute = anyMessage.unpack(RBACPerRoute.class);
} catch (InvalidProtocolBufferException e) {
return ConfigOrError.fromError("Invalid proto: " + e);
}
if (rbacPerRoute.hasRbac()) {
return parseRbacConfig(rbacPerRoute.getRbac());
} else {
return ConfigOrError.fromConfig(RbacConfig.create(null));
}
}
Aggregations