Skip to content

Commit 34891ef

Browse files
authored
Merge pull request #28 from telefonicaid/activate-securiry
Add support and documentation for Kafka with security
2 parents de8aec0 + e96cea0 commit 34891ef

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

doc/technical_configuration.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,39 @@ KAFNUS_TESTS_MONGO_PORT: "27017"
9494

9595
> ✅ These environment variables are available to all sink connectors via `${env:...}` references thanks to the `config.providers=env` setting in the Kafnus Connect distributed configuration.
9696

97+
### 🔐 Security Configuration
98+
99+
Kafnus Connect supports Kafka authentication via SASL. You can configure security by setting the following environment variables in your Docker Compose file:
100+
101+
```yaml
102+
# Security for Connect worker
103+
CONNECT_SECURITY_PROTOCOL: SASL_PLAINTEXT
104+
CONNECT_SASL_MECHANISM: PLAIN
105+
CONNECT_SASL_JAAS_CONFIG: >
106+
org.apache.kafka.common.security.plain.PlainLoginModule required
107+
username="connect-user"
108+
password="connect-pass";
109+
110+
# Security for producers and consumers
111+
CONNECT_PRODUCER_SECURITY_PROTOCOL: SASL_PLAINTEXT
112+
CONNECT_PRODUCER_SASL_MECHANISM: PLAIN
113+
CONNECT_PRODUCER_SASL_JAAS_CONFIG: >
114+
org.apache.kafka.common.security.plain.PlainLoginModule required
115+
username="connect-user"
116+
password="connect-pass";
117+
118+
CONNECT_CONSUMER_SECURITY_PROTOCOL: SASL_PLAINTEXT
119+
CONNECT_CONSUMER_SASL_MECHANISM: PLAIN
120+
CONNECT_CONSUMER_SASL_JAAS_CONFIG: >
121+
org.apache.kafka.common.security.plain.PlainLoginModule required
122+
username="connect-user"
123+
password="connect-pass";
124+
```
125+
126+
These variables are automatically applied by the `docker-entrypoint.sh` script when starting Kafka Connect in distributed mode. If `CONNECT_SECURITY_PROTOCOL` is defined, the script appends the corresponding security and SASL configuration to `connect-distributed.properties` for the worker, producer, and consumer.
127+
128+
This ensures that all Kafka connections (incoming and outgoing) respect the authentication settings without modifying connector definitions directly.
129+
97130
---
98131

99132
## 🧩 Kafnus Connect Plugins
@@ -709,3 +742,11 @@ docker exec -it kafka /opt/kafka/bin/kafka-console-consumer.sh
709742
```
710743

711744
Check tables in PostGIS or MongoDB after running the corresponding test input.
745+
746+
---
747+
748+
## 📚 Operational & Advanced Topics
749+
750+
For complete operational guidance, multi-tenant management, and security best practices, please refer to the **Kafnus main repository**:
751+
752+
- [Advanced Topics](https://github.com/telefonicaid/kafnus/blob/main/doc/03_advanced_topics.md) – security and operational guide.

docker-entrypoint.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with kafnus. If not, see http://www.gnu.org/licenses/.
1919

20+
#!/bin/bash
2021
set -e
2122

2223
CONFIG_FILE="/home/appuser/config/connect-distributed.properties"
2324

24-
cat > "${CONFIG_FILE}" <<EOF
25+
> "${CONFIG_FILE}"
26+
27+
cat >> "${CONFIG_FILE}" <<EOF
2528
bootstrap.servers=${CONNECT_BOOTSTRAP_SERVERS:-kafka:9092}
2629
group.id=${CONNECT_GROUP_ID:-connect-cluster}
2730
@@ -46,6 +49,24 @@ config.providers=env
4649
config.providers.env.class=org.apache.kafka.common.config.provider.EnvVarConfigProvider
4750
EOF
4851

52+
# Security (optional)
53+
if [ -n "${CONNECT_SECURITY_PROTOCOL}" ]; then
54+
cat >> "${CONFIG_FILE}" <<EOF
55+
56+
security.protocol=${CONNECT_SECURITY_PROTOCOL}
57+
sasl.mechanism=${CONNECT_SASL_MECHANISM}
58+
sasl.jaas.config=${CONNECT_SASL_JAAS_CONFIG}
59+
60+
producer.security.protocol=${CONNECT_PRODUCER_SECURITY_PROTOCOL:-${CONNECT_SECURITY_PROTOCOL}}
61+
producer.sasl.mechanism=${CONNECT_PRODUCER_SASL_MECHANISM:-${CONNECT_SASL_MECHANISM}}
62+
producer.sasl.jaas.config=${CONNECT_PRODUCER_SASL_JAAS_CONFIG:-${CONNECT_SASL_JAAS_CONFIG}}
63+
64+
consumer.security.protocol=${CONNECT_CONSUMER_SECURITY_PROTOCOL:-${CONNECT_SECURITY_PROTOCOL}}
65+
consumer.sasl.mechanism=${CONNECT_CONSUMER_SASL_MECHANISM:-${CONNECT_SASL_MECHANISM}}
66+
consumer.sasl.jaas.config=${CONNECT_CONSUMER_SASL_JAAS_CONFIG:-${CONNECT_SASL_JAAS_CONFIG}}
67+
EOF
68+
fi
69+
4970
echo ">> Starting Kafka Connect with config:"
5071
cat "${CONFIG_FILE}"
5172

0 commit comments

Comments
 (0)