use of kafka.server.KafkaServerStartable in project ranger by apache.
the class KafkaRangerAuthorizerSASLSSLTest method setup.
@org.junit.BeforeClass
public static void setup() throws Exception {
// JAAS Config file
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
File f = new File(basedir + "/src/test/resources/kafka_plain.jaas");
System.setProperty("java.security.auth.login.config", f.getPath());
// Create keys
String serviceDN = "CN=Service,O=Apache,L=Dublin,ST=Leinster,C=IE";
String clientDN = "CN=Client,O=Apache,L=Dublin,ST=Leinster,C=IE";
// Create a truststore
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, "security".toCharArray());
serviceKeystorePath = KafkaTestUtils.createAndStoreKey(serviceDN, serviceDN, BigInteger.valueOf(30), "sspass", "myservicekey", "skpass", keystore);
clientKeystorePath = KafkaTestUtils.createAndStoreKey(clientDN, clientDN, BigInteger.valueOf(31), "cspass", "myclientkey", "ckpass", keystore);
File truststoreFile = File.createTempFile("kafkatruststore", ".jks");
try (OutputStream output = new FileOutputStream(truststoreFile)) {
keystore.store(output, "security".toCharArray());
}
truststorePath = truststoreFile.getPath();
zkServer = new TestingServer();
// Get a random port
ServerSocket serverSocket = new ServerSocket(0);
port = serverSocket.getLocalPort();
serverSocket.close();
final Properties props = new Properties();
props.put("broker.id", 1);
props.put("host.name", "localhost");
props.put("port", port);
props.put("log.dir", "/tmp/kafka");
props.put("zookeeper.connect", zkServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
// Enable SASL_SSL
props.put("listeners", "SASL_SSL://localhost:" + port);
props.put("security.inter.broker.protocol", "SASL_SSL");
props.put("sasl.enabled.mechanisms", "PLAIN");
props.put("sasl.mechanism.inter.broker.protocol", "PLAIN");
props.put("offsets.topic.replication.factor", (short) 1);
props.put("offsets.topic.num.partitions", 1);
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, serviceKeystorePath);
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "sspass");
props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, "skpass");
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, truststorePath);
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "security");
// Plug in Apache Ranger authorizer
props.put("authorizer.class.name", "org.apache.ranger.authorization.kafka.authorizer.RangerKafkaAuthorizer");
// Create users for testing
UserGroupInformation.createUserForTesting("alice", new String[] { "IT" });
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// Create some topics
final Properties adminProps = new Properties();
adminProps.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + port);
adminProps.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL");
adminProps.put(SaslConfigs.SASL_MECHANISM, "PLAIN");
// ssl
adminProps.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, serviceKeystorePath);
adminProps.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "sspass");
adminProps.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, "skpass");
adminProps.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, truststorePath);
adminProps.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "security");
KafkaTestUtils.createSomeTopics(adminProps);
}
use of kafka.server.KafkaServerStartable in project drill by axbaretto.
the class EmbeddedKafkaCluster method shutDownCluster.
public void shutDownCluster() throws IOException {
// set Kafka log level to ERROR
Level level = LogManager.getLogger(KafkaStoragePluginConfig.NAME).getLevel();
LogManager.getLogger(KafkaStoragePluginConfig.NAME).setLevel(Level.ERROR);
for (KafkaServerStartable broker : brokers) {
broker.shutdown();
}
// revert back the level
LogManager.getLogger(KafkaStoragePluginConfig.NAME).setLevel(level);
zkHelper.stopZookeeper();
}
use of kafka.server.KafkaServerStartable in project drill by axbaretto.
the class EmbeddedKafkaCluster method getKafkaBrokerList.
public String getKafkaBrokerList() {
StringBuilder sb = new StringBuilder();
for (KafkaServerStartable broker : brokers) {
KafkaConfig serverConfig = broker.serverConfig();
sb.append(serverConfig.hostName() + ":" + serverConfig.port());
sb.append(",");
}
return sb.toString().substring(0, sb.toString().length() - 1);
}
use of kafka.server.KafkaServerStartable in project testcases by coheigea.
the class KafkaAuthorizerSASLGSSTest method setup.
@org.junit.BeforeClass
public static void setup() throws Exception {
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
configureKerby(basedir);
// JAAS Config file - We need to point to the correct keytab files
Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/kafka_kerberos.jaas");
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
content = content.replaceAll("<basedir>", basedir);
Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/kafka_kerberos.jaas");
Files.write(path2, content.getBytes(StandardCharsets.UTF_8));
System.setProperty("java.security.auth.login.config", path2.toString());
// Set up Zookeeper to require SASL
Map<String, Object> zookeeperProperties = new HashMap<>();
zookeeperProperties.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
zookeeperProperties.put("requireClientAuthScheme", "sasl");
zookeeperProperties.put("jaasLoginRenew", "3600000");
InstanceSpec instanceSpec = new InstanceSpec(null, -1, -1, -1, true, 1, -1, -1, zookeeperProperties);
zkServer = new TestingServer(instanceSpec, true);
// Get a random port
ServerSocket serverSocket = new ServerSocket(0);
port = serverSocket.getLocalPort();
serverSocket.close();
final Properties props = new Properties();
props.put("broker.id", 1);
props.put("host.name", "localhost");
props.put("port", port);
props.put("log.dir", "/tmp/kafka");
props.put("zookeeper.connect", zkServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
// Enable SASL_PLAINTEXT
props.put("listeners", "SASL_PLAINTEXT://localhost:" + port);
props.put("security.inter.broker.protocol", "SASL_PLAINTEXT");
props.put("sasl.enabled.mechanisms", "GSSAPI");
props.put("sasl.mechanism.inter.broker.protocol", "GSSAPI");
props.put("sasl.kerberos.service.name", "kafka");
// Plug in custom authorizer
props.put("authorizer.class.name", "org.apache.coheigea.bigdata.kafka.CustomSASLGSSAuthorizer");
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// Create some topics
ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "dev", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
use of kafka.server.KafkaServerStartable in project testcases by coheigea.
the class KafkaRangerAuthorizerTest method setup.
@org.junit.BeforeClass
public static void setup() throws Exception {
zkServer = new TestingServer();
// Get a random port
ServerSocket serverSocket = new ServerSocket(0);
port = serverSocket.getLocalPort();
serverSocket.close();
final Properties props = new Properties();
props.put("broker.id", 1);
props.put("host.name", "localhost");
props.put("port", port);
props.put("log.dir", "/tmp/kafka");
props.put("zookeeper.connect", zkServer.getConnectString());
props.put("replica.socket.timeout.ms", "1500");
props.put("controlled.shutdown.enable", Boolean.TRUE.toString());
// Enable SSL
props.put("listeners", "SSL://localhost:" + port);
props.put("ssl.keystore.location", KafkaAuthorizerTest.class.getResource("/servicestore.jks").getPath());
props.put("ssl.keystore.password", "sspass");
props.put("ssl.key.password", "skpass");
props.put("ssl.truststore.location", KafkaAuthorizerTest.class.getResource("/truststore.jks").getPath());
props.put("ssl.truststore.password", "security");
props.put("security.inter.broker.protocol", "SSL");
props.put("ssl.client.auth", "required");
// Plug in Apache Ranger authorizer
props.put("authorizer.class.name", "org.apache.ranger.authorization.kafka.authorizer.RangerKafkaAuthorizer");
// Create users for testing
UserGroupInformation.createUserForTesting("CN=Client,O=Apache,L=Dublin,ST=Leinster,C=IE", new String[] { "public" });
UserGroupInformation.createUserForTesting("CN=Service,O=Apache,L=Dublin,ST=Leinster,C=IE", new String[] { "IT" });
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
// Create some topics
ZkClient zkClient = new ZkClient(zkServer.getConnectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkServer.getConnectString()), false);
AdminUtils.createTopic(zkUtils, "test", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "dev", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
AdminUtils.createTopic(zkUtils, "messages", 1, 1, new Properties(), RackAwareMode.Enforced$.MODULE$);
}
Aggregations