Skip to main content
Quick navigation

Field level encryption

Let's demonstrate full payload 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
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 topic customers on gateway1

Creating on gateway1:

  • Topic customers with partitions:1 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--replication-factor 1 \
--partitions 1 \
--create --if-not-exists \
--topic customers

Adding interceptor encrypt-full-payload

We want to encrypt the full payload with an in memory KMS.

step-06-encrypt-full-payload-interceptor.json:

{
"kind" : "Interceptor",
"apiVersion" : "gateway/v2",
"metadata" : {
"name" : "encrypt-full-payload"
},
"spec" : {
"comment" : "Adding interceptor: encrypt-full-payload",
"pluginClass" : "io.conduktor.gateway.interceptor.EncryptPlugin",
"priority" : 100,
"config" : {
"payload" : {
"keySecretId" : "full-payload-secret",
"algorithm" : "AES128_GCM"
}
}
}
}
curl \
--silent \
--request PUT "http://localhost:8888/gateway/v2/interceptor" \
--header "Content-Type: application/json" \
--user "admin:conduktor" \
--data @step-06-encrypt-full-payload-interceptor.json | jq

Listing interceptors

Listing interceptors on gateway1

curl \
--silent \
--request GET "http://localhost:8888/gateway/v2/interceptor" \
--user "admin:conduktor" | 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"
}
echo '{"name":"tom","username":"tom@conduktor.io","password":"motorhead","visa":"#abc123","address":"Chancery lane, London"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--topic customers

echo '{"name":"laura","username":"laura@conduktor.io","password":"kitesurf","visa":"#888999XZ;","address":"Dubai, UAE"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--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 gateway1

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--topic customers \
--from-beginning \
--max-messages 3 \
--timeout-ms 3000

returns 2 events


�j|��q�f�1�α�W���H� ����Jg#�b�H������~�!�-l��� �b�i�p`
x��
�����?в)�2��Գ�C�w͔,!�K���ﳐ

�j|��q�f�1�α�W���H� ����Jg#�b�H������~틂�@-W�B7| �44

Adding interceptor decrypt-full-payload

Let's add the decrypt interceptor to decipher messages

step-10-decrypt-full-payload-interceptor.json:

{
"kind" : "Interceptor",
"apiVersion" : "gateway/v2",
"metadata" : {
"name" : "decrypt-full-payload"
},
"spec" : {
"comment" : "Adding interceptor: decrypt-full-payload",
"pluginClass" : "io.conduktor.gateway.interceptor.DecryptPlugin",
"priority" : 100,
"config" : {
"topic" : "customers",
"kmsConfig" : {
"vault" : {
"uri" : "http://vault:8200",
"token" : "vault-plaintext-root-token",
"version" : 1
}
}
}
}
}
curl \
--silent \
--request PUT "http://localhost:8888/gateway/v2/interceptor" \
--header "Content-Type: application/json" \
--user "admin:conduktor" \
--data @step-10-decrypt-full-payload-interceptor.json | jq

Listing interceptors

Listing interceptors on gateway1

curl \
--silent \
--request GET "http://localhost:8888/gateway/v2/interceptor" \
--user "admin:conduktor" | jq

Confirm message from tom and laura are decrypted

Confirm message from tom and laura are decrypted in cluster gateway1

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--topic customers \
--from-beginning \
--max-messages 3 \
--timeout-ms 3000 | jq

returns 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"
}

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!