Encrypting messages
Since 4.9.0 jEAP Messaging can encrypt messages using the jEAP-Crypto library.
jeap-messaging-infrastructure-kafka automatically configures encryption in the Kafka
serializer/deserializer if a KeyIdCryptoService Spring bean is available — for example provided by
the jeap-crypto-vault-starter together with the jeap-spring-boot-vault-starter. The wrapping keys
declared in the jEAP Vault crypto configuration are then used to encrypt and decrypt messages.
jEAP Messaging is KMS-agnostic: anything jeap-crypto supports works.
Declare the wrapping key
The wrapping keys are declared in the jEAP Vault crypto configuration under jeap.crypto.vault,
each under a key id (here messagingKey):
jeap:
crypto:
vault:
default-secret-engine-path: transit
keys:
messagingKey:
key-name: messaging-key
Encrypt a message type
To send a message type encrypted, reference the wrapping key by its key id in the producer
contract via the encryptionKeyId field on @JeapMessageProducerContract:
@JeapMessageProducerContract(value = SomeEvent.TypeRef.class, encryptionKeyId = "messagingKey")
Only one message contract per event can exist per encryption key, so projects sometimes adjust
topic/appName per Maven profile.
Disable encryption in tests
jeap.messaging.kafka.messageTypeEncryptionDisabled=true lets tests run without a jEAP-Crypto
instance. It is forbidden on the acceptance and production environments (see
Configuration reference).
jeap:
messaging:
kafka:
messageTypeEncryptionDisabled: true
Check that messages are encrypted
Every message whose value was encrypted carries the Kafka record header jeap_encrypted_value (value 0x01).
Messages without this header were sent in plaintext. Only message values are encrypted, never keys.
The jeap_messaging_total counter has an encrypted tag (1 = encrypted, 0 = plaintext) next to signed:
type="producer": whether the published message will be encrypted, decided from the same producer contracts the serializer uses. WithmessageTypeEncryptionDisabled=trueall messages count asencrypted="0".type="consumer": whether the received message carried thejeap_encrypted_valueheader. Messages decrypted with the legacy NiFi-compatible mechanism carry no such header and count asencrypted="0".
To find message types that are published unencrypted:
sum by (application, message, topic) (increase(jeap_messaging_total{type="producer", encrypted="0"}[1d]))