Search in sources :

Example 46 with SecurityProtocol

use of org.apache.kafka.common.security.auth.SecurityProtocol in project apache-kafka-on-k8s by banzaicloud.

the class ClientUtils method createChannelBuilder.

/**
 * @param config client configs
 * @return configured ChannelBuilder based on the configs.
 */
public static ChannelBuilder createChannelBuilder(AbstractConfig config) {
    SecurityProtocol securityProtocol = SecurityProtocol.forName(config.getString(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
    String clientSaslMechanism = config.getString(SaslConfigs.SASL_MECHANISM);
    return ChannelBuilders.clientChannelBuilder(securityProtocol, JaasContext.Type.CLIENT, config, null, clientSaslMechanism, true);
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol)

Example 47 with SecurityProtocol

use of org.apache.kafka.common.security.auth.SecurityProtocol in project cruise-control by linkedin.

the class CCEmbeddedBroker method parseConfigs.

private void parseConfigs(Map<Object, Object> config) {
    _id = Integer.parseInt((String) config.get(KafkaConfig.BrokerIdProp()));
    _logDir = new File((String) config.get(KafkaConfig.LogDirProp()));
    // Bind addresses
    String listenersString = (String) config.get(KafkaConfig.ListenersProp());
    for (String protocolAddr : listenersString.split("\\s*,\\s*")) {
        try {
            URI uri = new URI(protocolAddr.trim());
            SecurityProtocol protocol = SecurityProtocol.forName(uri.getScheme());
            _hosts.put(protocol, uri.getHost());
            // We get the value after boot
            _ports.put(protocol, null);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) File(java.io.File) URI(java.net.URI)

Example 48 with SecurityProtocol

use of org.apache.kafka.common.security.auth.SecurityProtocol in project cruise-control by linkedin.

the class CCKafkaClientsIntegrationTestHarness method setSecurityConfigs.

protected void setSecurityConfigs(Properties clientProps, String certAlias) {
    SecurityProtocol protocol = securityProtocol();
    if (protocol == SecurityProtocol.SSL) {
        File trustStoreFile = trustStoreFile();
        if (trustStoreFile == null) {
            throw new AssertionError("ssl set but no trust store provided");
        }
        clientProps.setProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, protocol.name);
        clientProps.setProperty(KafkaConfig.SslEndpointIdentificationAlgorithmProp(), "");
        try {
            clientProps.putAll(TestSslUtils.createSslConfig(true, true, Mode.CLIENT, trustStoreFile, certAlias));
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) File(java.io.File)

Example 49 with SecurityProtocol

use of org.apache.kafka.common.security.auth.SecurityProtocol in project kcache by rayokota.

the class SASLClusterTestHarness method getKafkaConfig.

@Override
protected KafkaConfig getKafkaConfig(int brokerId) {
    final Option<File> trustStoreFileOption = Option.apply(null);
    final Option<SecurityProtocol> saslInterBrokerSecurityProtocol = Option.apply(SecurityProtocol.SASL_PLAINTEXT);
    Properties props = TestUtils.createBrokerConfig(brokerId, zkConnect, false, false, TestUtils.RandomPort(), saslInterBrokerSecurityProtocol, trustStoreFileOption, EMPTY_SASL_PROPERTIES, false, true, TestUtils.RandomPort(), false, TestUtils.RandomPort(), false, TestUtils.RandomPort(), Option.<String>empty(), 1, false, 1, (short) 1);
    injectProperties(props);
    props.setProperty("zookeeper.connection.timeout.ms", "30000");
    props.setProperty("sasl.mechanism.inter.broker.protocol", "GSSAPI");
    props.setProperty(BrokerSecurityConfigs.SASL_ENABLED_MECHANISMS_CONFIG, "GSSAPI");
    return KafkaConfig.fromProps(props);
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) Properties(java.util.Properties) File(java.io.File)

Example 50 with SecurityProtocol

use of org.apache.kafka.common.security.auth.SecurityProtocol in project kcache by rayokota.

the class SSLClusterTestHarness method getKafkaConfig.

@Override
protected KafkaConfig getKafkaConfig(int brokerId) {
    File trustStoreFile;
    try {
        trustStoreFile = File.createTempFile("SSLClusterTestHarness-truststore", ".jks");
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to create temporary file for the truststore.");
    }
    final Option<File> trustStoreFileOption = Option.apply(trustStoreFile);
    final Option<SecurityProtocol> sslInterBrokerSecurityProtocol = Option.apply(SecurityProtocol.SSL);
    Properties props = TestUtils.createBrokerConfig(brokerId, zkConnect, false, false, TestUtils.RandomPort(), sslInterBrokerSecurityProtocol, trustStoreFileOption, EMPTY_SASL_PROPERTIES, false, false, TestUtils.RandomPort(), true, TestUtils.RandomPort(), false, TestUtils.RandomPort(), Option.<String>empty(), 1, false, 1, (short) 1);
    // setup client SSL. Needs to happen before the broker is initialized, because the client's cert
    // needs to be added to the broker's trust store.
    Map<String, Object> sslConfigs;
    try {
        this.clientSslConfigs = TestSslUtils.createSslConfig(true, true, Mode.CLIENT, trustStoreFile, "client", "localhost");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    injectProperties(props);
    if (requireSSLClientAuth()) {
        props.setProperty("ssl.client.auth", "required");
    }
    return KafkaConfig.fromProps(props);
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException)

Aggregations

SecurityProtocol (org.apache.kafka.common.security.auth.SecurityProtocol)106 Test (org.junit.jupiter.api.Test)50 Test (org.junit.Test)29 HashMap (java.util.HashMap)22 InetSocketAddress (java.net.InetSocketAddress)14 NetworkSend (org.apache.kafka.common.network.NetworkSend)11 RequestHeader (org.apache.kafka.common.requests.RequestHeader)11 IOException (java.io.IOException)10 PlainLoginModule (org.apache.kafka.common.security.plain.PlainLoginModule)10 TestSecurityConfig (org.apache.kafka.common.security.TestSecurityConfig)9 ScramLoginModule (org.apache.kafka.common.security.scram.ScramLoginModule)9 File (java.io.File)8 ByteBuffer (java.nio.ByteBuffer)8 Properties (java.util.Properties)8 ApiVersionsRequest (org.apache.kafka.common.requests.ApiVersionsRequest)7 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)7 LogContext (org.apache.kafka.common.utils.LogContext)6 Random (java.util.Random)5 Password (org.apache.kafka.common.config.types.Password)5 ListenerName (org.apache.kafka.common.network.ListenerName)5