Skip to main content

Message layer security/crypto for Kafka

Project description

kafkacrypto

Message Layer Encryption for Kafka

Available on PyPI at https://pypi.org/project/kafkacrypto/
Available on Github at https://github.com/tmcqueen-materials/kafkacrypto

Quick Start

On every kafka consumer or producer node, do:

  1. pip3 install kafkacrypto
  2. Download simple-provision.py
  3. Run: ./simple-provision.py and follow the instructions. Use the same root of trust password on all nodes.

In your producer/consumer code:

from kafkacrypto import KafkaCrypto
nodeId = 'my-node-ID'

# setup separate consumer/producers for the crypto key passing messages. DO NOT use these for
# other messages.
kcc = KafkaConsumer(...your server params...)
kcp = KafkaProducer(...your server params...)
kc = KafkaCrypto(nodeId,kcp,kcc)

... Your code here ...

# Here is how you configure your producer/consumer objects to use the crypto (de)serializers
producer = KafkaProducer(...,key_serializer=kc.getKeySerializer(), value_serializer=kc.getValueSerializer())
consumer = KafkaConsumer(...,key_deserializer=kc.getKeyDeserializer(), value_deserializer=kc.getValueDeserializer())

... Your code here ...

And that's it! Your producers and consumers should function as normal, but all traffic within Kafka is encrypted.

If automatic topic creation is disabled, then one more action is needed. For each "root topic" you must create the requisite key-passing topics. By default these are root.reqs and root.keys, where root is replaced with the root topic name.

Root Topics

kafkacrypto uses unique keys on a per-"root topic" basis. A root topic is defined as the topic name before the first user-defined separator. The default separator is ".". Thus all of these:
example001
example001.foo.bar.baz
example001.foo.bar
example001.foo
have the same root topic of example001, whereas example001_baz.bar.foo has the root topic example001_baz. Since kafka does not recommend using both "." and "_" in topic names, if you wish every topic to use a unique set of keys, use "_" (and not ".") in names, or change the defined topic separator.

Troubleshooting

If something is not working, enable logging to get detailed information:

import logging

logging.basicConfig(level=logging.WARNING)
logging.getLogger("kafkacrypto").setLevel(level=logging.INFO) # set to logging.DEBUG for more verbosity

Advanced Usage

kafkacrypto has been designed to seamlessly support a range of key exchange authorization and delegation mechanisms beyond the simple single-password root of trust. An example of a simple "controller-based" intermediary is included in the main package. The requisite controller can be setup as:

#!/usr/bin/python3
from kafka import KafkaConsumer, KafkaProducer
from kafkacrypto import KafkaCryptoController

nodeId = 'controller-name'

# use your normal server parameters in place of the ...
kcc = KafkaConsumer(..., enable_auto_commit=False, group_id=nodeId)
kcp = KafkaProducer(...)
controller = KafkaCryptoController(nodeId,kcp,kcc)
controller._mgmt_thread.join()

The configuration parameters inside the provision script should be adjusted so that the "subscribe" and "key request" suffixes are distinct (see comment in simple-provision.py). If automatic topic creation is disabled, then the topic root.subs must also be created.

Design, Specification, and Security Analysis

kafkacrypto is already in limited production use, and should be stable enough for broad adoption. However, a detailed security analysis of the kafkacrypto framework is still in progress, and use of this code should be considered experimental.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for kafkacrypto, version 0.9.1rc1
Filename, size File type Python version Upload date Hashes
Filename, size kafkacrypto-0.9.1rc1-py3-none-any.whl (26.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size kafkacrypto-0.9.1rc1.tar.gz (13.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page