eolivelli commented on a change in pull request #2355: URL: https://github.com/apache/bookkeeper/pull/2355#discussion_r435018656
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/BookieAuthZFactory.java ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bookkeeper.tls; + +import com.google.common.base.Strings; + +import java.io.IOException; +import java.security.cert.X509Certificate; +import java.util.Collection; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.bookkeeper.auth.AuthCallbacks; +import org.apache.bookkeeper.auth.AuthToken; +import org.apache.bookkeeper.auth.BookKeeperPrincipal; +import org.apache.bookkeeper.auth.BookieAuthProvider; +import org.apache.bookkeeper.client.BKException; +import org.apache.bookkeeper.conf.ServerConfiguration; +import org.apache.bookkeeper.proto.BookieConnectionPeer; +import org.apache.bookkeeper.util.CertUtils; + + +/** + * Authorization factory class. + */ +@Slf4j +public class BookieAuthZFactory implements BookieAuthProvider.Factory { Review comment: what about BookieX509CertificateAuthZFactory ? ########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/util/CertUtils.java ########## @@ -0,0 +1,117 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bookkeeper.util; + +import java.io.IOException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.naming.InvalidNameException; +import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Certificate parsing utilities. + */ +public class CertUtils { Review comment: abstract ? with a private default constructor ########## File path: conf/bk_server.conf ########## @@ -226,6 +226,15 @@ httpServerClass=org.apache.bookkeeper.http.vertx.VertxHttpServer # # permittedStartupUsers= +# Certificate role based authorization for Bookie +# To enable this option, bookieAuthProviderFactoryClass should be set to org.apache.bookkeeper.tls.BookieAuthZFactory +# comma separated values of roles from the certificates OU field which we want to authorize for access +# +# Example settings: +# authorizedRoles=apache-pulsar-cluster-12,apache-kafka-cluster-2 Review comment: looks like 'kafka' is not useful in BK context :-) ########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/BookieAuthZFactory.java ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bookkeeper.tls; + +import com.google.common.base.Strings; + +import java.io.IOException; +import java.security.cert.X509Certificate; +import java.util.Collection; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.bookkeeper.auth.AuthCallbacks; +import org.apache.bookkeeper.auth.AuthToken; +import org.apache.bookkeeper.auth.BookKeeperPrincipal; +import org.apache.bookkeeper.auth.BookieAuthProvider; +import org.apache.bookkeeper.client.BKException; +import org.apache.bookkeeper.conf.ServerConfiguration; +import org.apache.bookkeeper.proto.BookieConnectionPeer; +import org.apache.bookkeeper.util.CertUtils; + + +/** + * Authorization factory class. + */ +@Slf4j +public class BookieAuthZFactory implements BookieAuthProvider.Factory { + + public String[] allowedRoles; + + @Override + public String getPluginName() { + return "BookieAuthZFactory"; + } + + @Override + public void init(ServerConfiguration conf) throws IOException { + // Read from config + allowedRoles = conf.getAuthorizedRoles(); + + if (allowedRoles == null || allowedRoles.length == 0) { + throw new RuntimeException("Configuration option \'bookieAuthProviderFactoryClass\' is set to" + + " \'BookieAuthZFactory\' but no roles set for configuration field \'authorizedRoles\'."); Review comment: what about usiing this.class.getName() instead of an hardcoded "BookieAuthZFactory" ? ########## File path: bookkeeper-server/src/test/java/org/apache/bookkeeper/tls/TestTLS.java ########## @@ -635,6 +635,47 @@ public void testBookieAuthPluginRequireClientTLSAuthenticationLocal() throws Exc assertTrue(cert instanceof X509Certificate); } + /** + * Verify that given role in client certificate is checked when BookieAuthZFactory is set. + * Positive test case where all given roles are present. Review comment: this test does look like a "Positive test" you are asserting that the client is not able to work ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
