Search code examples
apache-kafkadocker-composedb2apache-kafka-connect

How do I configure kafka-connect w/ "securityMechanism=9, encryptionAlgorithm=2" for a db2 database connection in my docker-compose file?


QUESTION:
How do I configure "securityMechanism=9, encryptionAlgorithm=2" for a db2 database connection in my docker-compose file?

NOTE: When running my local kafka installation (kafka_2.13-2.6.0) to connect to a db2 database on the network, I only had to modify the bin/connect-standalone.sh file by modifying the existing "EXTRA_ARGS=" line like this:

(...)
EXTRA_ARGS=${EXTRA_ARGS-'-name connectStandalone -Ddb2.jcc.securityMechanism=9 -Ddb2.jcc.encryptionAlgorithm=2'}
(...)

it worked fine.

However, when I tried using the same idea for a containerized kafka/broker "service" (docker-compose.yml),
by mounting a volume with the modified "connect-standalone" file content (to replace the "/usr/bin/connect-standalone" file in the container) it did not work.

I did verify that the container's file was changed.

...I receive this exception when I attempt to use a kafka-jdbc-source-connector to connect to the database:

Caused by: com.ibm.db2.jcc.am.SqlInvalidAuthorizationSpecException: [jcc][t4][201][11237][4.25.13] Connection authorization failure occurred.  
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000
  

So, again, how do I configure the securityMechanism/encryptionAlgorithm setting in a docker-compose.yml?

Thx for any help

-sairn


here is a docker-compose.yml - you can see I've tried mounting volume with the modified "connect-standalone" file in both the broker(kafka) service and the kafka-connect service... neither achieved the desired effect

version: '3.8'
services:
    zookeeper:
        image: confluentinc/cp-zookeeper:6.0.0
        container_name: zookeeper       
        ports:
            - "2181:2181"       
        environment:
            ZOOKEEPER_CLIENT_PORT: 2181
            ZOOKEEPER_TICK_TIME: 2000

            
    kafka:
        image: confluentinc/cp-enterprise-kafka:6.0.0
        container_name: kafka
        depends_on:
            - zookeeper
        ports:
            - "9092:9092"
        environment:
            KAFKA_BROKER_ID: 1
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
            KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
            KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://kafka:9092
            KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
            KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
            KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
            KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 100
            CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: kafka:29092
            CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
            CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
            CONFLUENT_METRICS_ENABLE: 'true'
            CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'
            JVM_OPTS: "-Ddb2.jcc.securityMechanism=9 -Ddb2.jcc.encryptionAlgorithm=2"            
        volumes:       
            - ./connect-standalone:/usr/bin/connect-standalone                           

            
    schema-registry:
        image: confluentinc/cp-schema-registry:6.0.0
        container_name: schema-registry
        hostname: schema-registry
        depends_on:
            - zookeeper
            - kafka
        ports:
            - "8081:8081"
        environment:
            SCHEMA_REGISTRY_HOST_NAME: schema-registry
            SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'
            SCHEMA_REGISTRY_LISTENERS: http://schema-registry:8081

            
    kafka-connect:
        image: confluentinc/cp-kafka-connect:6.0.0
        container_name: kafka-connect       
        hostname: kafka-connect
        depends_on:
            - kafka
            - schema-registry
        ports:
            - "8083:8083"
        environment:
            CONNECT_BOOTSTRAP_SERVERS: "kafka:29092"
            CONNECT_REST_ADVERTISED_HOST_NAME: "kafka-connect"
            CONNECT_REST_PORT: 8083
            CONNECT_GROUP_ID: kafka-connect
            CONNECT_CONFIG_STORAGE_TOPIC: kafka-connect-configs
            CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
            CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000
            CONNECT_OFFSET_STORAGE_TOPIC: kafka-connect-offsets
            CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
            CONNECT_STATUS_STORAGE_TOPIC: kafka-connect-status
            CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
            CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
            CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
            CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081
            CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            CONNECT_ZOOKEEPER_CONNECT: 'zookeeper:2181'
            CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/confluent-hub-components"
            CONNECT_LOG4J_LOGGERS: org.apache.zookeeper=ERROR,org.I0Itec.zkclient=ERROR,org.reflections=ERROR
            JVM_OPTS: "-Ddb2.jcc.securityMechanism=9 -Ddb2.jcc.encryptionAlgorithm=2"
        volumes:
            - ./kafka-connect-jdbc-10.0.1.jar:/usr/share/java/kafka-connect-jdbc/kafka-connect-jdbc-10.0.1.jar    
            - ./db2jcc-db2jcc4.jar:/usr/share/java/kafka-connect-jdbc/db2jcc-db2jcc4.jar  
            - ./connect-standalone:/usr/bin/connect-standalone              

Fwiw, the connector looks similar to this...

curl -X POST http://localhost:8083/connectors -H "Content-Type: application/json" -d '{
        "name": "CONNECTOR01",
        "config": {
        "connector.class":"io.confluent.connect.jdbc.JdbcSourceConnector",
        "connection.url":"jdbc:db2://THEDBURL:50000/XXXXX",
        "connection.user":"myuserid",
        "connection.password":"mypassword",
        "poll.interval.ms":"15000",
        "table.whitelist":"YYYYY.TABLEA",
        "topic.prefix":"tbl-",
        "mode":"timestamp",
        "timestamp.initial":"-1",
        "timestamp.column.name":"TIME_UPD",
        "poll.interval.ms":"15000"
        }
    }'

Solution

  • Try to use KAFKA_OPTS instead of JVM_OPTS