Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions xds/src/main/java/io/grpc/xds/RbacFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ private static AuthHeaderMatcher parseHeaderMatcher(

private static AuthenticatedMatcher parseAuthenticatedMatcher(
Principal.Authenticated proto) {
// An unset principal_name matches any authenticated (TLS) connection.
if (!proto.hasPrincipalName()) {
return AuthenticatedMatcher.create(null);
}
Matchers.StringMatcher matcher = MatcherParser.parseStringMatcher(proto.getPrincipalName());
return AuthenticatedMatcher.create(matcher);
}
Expand Down
26 changes: 26 additions & 0 deletions xds/src/test/java/io/grpc/xds/RbacFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ public void authenticatedParser() throws Exception {
assertThat(decision.decision()).isEqualTo(GrpcAuthorizationEngine.Action.DENY);
}

@Test
@SuppressWarnings("unchecked")
public void authenticatedParser_noPrincipalName_matchesAnyTlsConnection() {
List<Permission> permissionList = Arrays.asList(
Permission.newBuilder().setAny(true).build());
List<Principal> principalList = Arrays.asList(
Principal.newBuilder().setAuthenticated(Authenticated.getDefaultInstance()).build());
ConfigOrError<RbacConfig> result = parse(permissionList, principalList);
assertThat(result.errorDetail).isNull();
GrpcAuthorizationEngine engine = new GrpcAuthorizationEngine(result.config.authConfig());

// TLS connection without a client certificate.
Attributes tlsAttributes = Attributes.newBuilder()
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION, mock(SSLSession.class))
.build();
ServerCall<Void,Void> tlsCall = mock(ServerCall.class);
when(tlsCall.getAttributes()).thenReturn(tlsAttributes);
assertThat(engine.evaluate(new Metadata(), tlsCall).decision())
.isEqualTo(GrpcAuthorizationEngine.Action.DENY);

ServerCall<Void,Void> plaintextCall = mock(ServerCall.class);
when(plaintextCall.getAttributes()).thenReturn(Attributes.EMPTY);
assertThat(engine.evaluate(new Metadata(), plaintextCall).decision())
.isEqualTo(GrpcAuthorizationEngine.Action.ALLOW);
}

@Test
@SuppressWarnings({"unchecked", "deprecation"})
public void headerParser() {
Expand Down
Loading