Skip to main content
Quick navigation

Field level encryption

Let's demonstrate field level encryption

View the full demo in realtime

You can either follow all the steps manually, or watch the recording

Review the docker compose environment

As can be seen from docker-compose.yaml the demo environment consists of the following services:

  • gateway1
  • gateway2
  • kafka-client
  • kafka1
  • kafka2
  • kafka3
  • schema-registry
  • zookeeper
cat docker-compose.yaml

Starting the docker environment

Start all your docker processes, wait for them to be up and ready, then run in background

  • --wait: Wait for services to be running|healthy. Implies detached mode.
  • --detach: Detached mode: Run containers in the background
docker compose up --detach --wait

Creating virtual cluster teamA

Creating virtual cluster teamA on gateway gateway1 and reviewing the configuration file to access it

# Generate virtual cluster teamA with service account sa
token=$(curl \
--request POST "http://localhost:8888/admin/vclusters/v1/vcluster/teamA/username/sa" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data-raw '{"lifeTimeSeconds": 7776000}' | jq -r ".token")

# Create access file
echo """
bootstrap.servers=localhost:6969
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='sa' password='$token';
""" > teamA-sa.properties

# Review file
cat teamA-sa.properties

Creating topic customers on teamA

Creating on teamA:

  • Topic customers with partitions:1 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--create --if-not-exists \
--topic customers

Adding interceptor encrypt

We want to encrypt only two fields, with an in memory KMS.

cat step-07-encrypt.json | jq

curl \
--request POST "http://localhost:8888/admin/interceptors/v1/vcluster/teamA/interceptor/encrypt" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data @step-07-encrypt.json | jq

Listing interceptors for teamA

Listing interceptors on gateway1 for virtual cluster teamA

curl \
--request GET 'http://localhost:8888/admin/interceptors/v1/vcluster/teamA' \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent | jq

Let's send unencrypted json

We are using regular kafka tools

Sending 2 events

{
"name" : "tom",
"username" : "tom@conduktor.io",
"password" : "motorhead",
"visa" : "#abc123",
"address" : "Chancery lane, London"
}
{
"name" : "laura",
"username" : "laura@conduktor.io",
"password" : "kitesurf",
"visa" : "#888999XZ;",
"address" : "Dubai, UAE"
}

with

echo '{"name":"tom","username":"tom@conduktor.io","password":"motorhead","visa":"#abc123","address":"Chancery lane, London"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--producer.config teamA-sa.properties \
--topic customers

echo '{"name":"laura","username":"laura@conduktor.io","password":"kitesurf","visa":"#888999XZ;","address":"Dubai, UAE"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--producer.config teamA-sa.properties \
--topic customers

Let's consume the message, and confirm tom and laura data is encrypted

Let's consume the message, and confirm tom and laura data is encrypted in cluster teamA

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic customers \
--from-beginning \
--timeout-ms 10000 | jq

returns 2 events

{
"name" : "tom",
"username" : "tom@conduktor.io",
"password" : "AAAABQAAAAEAAAAzAZyTL3LF2+p1EdfKvrIs626109f3iFgWhIkgmfH325481NBa88owQs6zyeoGKnR0p/H5GwifpQjJuRoxJ08WK9Vo5SLFLaLstd7w1COt7KPAUWoAdm/zqi6sjHn9++c=",
"visa" : "AAAABQAAAAEAAAAzAUSMa/tvk0HqciPJdw5K87jVyK8qWShUJohIt72igXEB9zNotloi3AzZ7t5zuTHb2bbmEMLQldYbYahPPiFLz87TL4qFatjqtJ2J9SpdZ8DHClID377ZOCwpHgjq",
"address" : "Chancery lane, London"
}
{
"name" : "laura",
"username" : "laura@conduktor.io",
"password" : "AAAABQAAAAEAAAAzAZyTL3LF2+p1EdfKvrIs626109f3iFgWhIkgmfH325481NBa88owQs6zyeoGKnR0p/H5VsWxypZMpcSVPKWRNn/WGoNGYCTv7L8SIlLvr7vYf6E6Ct0xCeV8yNafCw==",
"visa" : "AAAABQAAAAEAAAAzAUSMa/tvk0HqciPJdw5K87jVyK8qWShUJohIt72igXEB9zNotloi3AzZ7t5zuTHb2bbmbmZwAx2sq0DrS2DDPgnDF61OxpEdHF2w6V+qmRmFuZhwBz47doX6iVnWdjaB",
"address" : "Dubai, UAE"
}

Adding interceptor decrypt

Let's add the decrypt interceptor to decipher messages, but decrypt only a visa

cat step-11-decrypt.json | jq

curl \
--request POST "http://localhost:8888/admin/interceptors/v1/vcluster/teamA/interceptor/decrypt" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data @step-11-decrypt.json | jq

Listing interceptors for teamA

Listing interceptors on gateway1 for virtual cluster teamA

curl \
--request GET 'http://localhost:8888/admin/interceptors/v1/vcluster/teamA' \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent | jq

Confirm message from tom and laura are partially decrypted

Confirm message from tom and laura are partially decrypted in cluster teamA

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic customers \
--from-beginning \
--timeout-ms 10000 | jq

returns 2 events

{
"name" : "tom",
"username" : "tom@conduktor.io",
"password" : "AAAABQAAAAEAAAAzAZyTL3LF2+p1EdfKvrIs626109f3iFgWhIkgmfH325481NBa88owQs6zyeoGKnR0p/H5GwifpQjJuRoxJ08WK9Vo5SLFLaLstd7w1COt7KPAUWoAdm/zqi6sjHn9++c=",
"visa" : "#abc123",
"address" : "Chancery lane, London"
}
{
"name" : "laura",
"username" : "laura@conduktor.io",
"password" : "AAAABQAAAAEAAAAzAZyTL3LF2+p1EdfKvrIs626109f3iFgWhIkgmfH325481NBa88owQs6zyeoGKnR0p/H5VsWxypZMpcSVPKWRNn/WGoNGYCTv7L8SIlLvr7vYf6E6Ct0xCeV8yNafCw==",
"visa" : "#888999XZ;",
"address" : "Dubai, UAE"
}

Tearing down the docker environment

Remove all your docker processes and associated volumes

  • --volumes: Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers.
docker compose down --volumes

Conclusion

Yes, encryption in the Kafka world can be simple!