Mitigation Strategy: Enforce TLS Encryption (Sarama Configuration)
-
Mitigation Strategy: Enforce TLS Encryption for all Kafka communication using Sarama's configuration options.
-
Description:
- Obtain Certificates: Obtain valid TLS certificates (CA, client certificate, client key).
- Configure Sarama: In your Sarama configuration (
sarama.Config
):Config.Net.TLS.Enable = true
Config.Net.TLS.Config = &tls.Config{...}
: Populate this with certificate information. Load the CA certificate, client certificate, and client key.tlsConfig = &tls.Config{ Certificates: []tls.Certificate{clientCert}, // Load client cert and key RootCAs: caCertPool, // Load CA cert } config.Net.TLS.Config = tlsConfig
- Crucially: Avoid
InsecureSkipVerify = true
in production. If used during development, remove it before deployment.
-
Threats Mitigated:
- Man-in-the-Middle (MITM) Attacks: (Severity: High)
- Data Eavesdropping: (Severity: High)
- Unauthorized Access: (Severity: Medium) - Contributes to authentication.
-
Impact:
- MITM Attacks: Risk reduced to near zero with proper certificate validation.
- Data Eavesdropping: Risk reduced to near zero.
- Unauthorized Access: Risk significantly reduced (with SASL).
-
Currently Implemented:
- Partially. TLS enabled in
producer
(producer/config.go
), butInsecureSkipVerify = true
.consumer
(consumer/config.go
) has no TLS.
- Partially. TLS enabled in
-
Missing Implementation:
- Remove
InsecureSkipVerify = true
fromproducer
. - Implement TLS in
consumer
, including certificate loading.
- Remove
Mitigation Strategy: Implement SASL Authentication (Sarama Configuration)
-
Mitigation Strategy: Implement SASL Authentication using Sarama's configuration.
-
Description:
- Choose a SASL Mechanism: Select
SASL/SCRAM-SHA-256
,SASL/SCRAM-SHA-512
,SASL/PLAIN
,SASL/GSSAPI
, orSASL/OAUTHBEARER
. - Configure Sarama: In your
sarama.Config
:Config.Net.SASL.Enable = true
Config.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256
(or your choice)Config.Net.SASL.User = "your_kafka_user"
Config.Net.SASL.Password = "your_kafka_password"
(or credentials for other mechanisms)- For SCRAM, you might need
Config.Net.SASL.SCRAMClientGeneratorFunc
. - For OAUTHBEARER, you will need to set
Config.Net.SASL.TokenProvider
.
- Secure Credential Storage: Never hardcode credentials. Use environment variables or a secrets management service.
- Choose a SASL Mechanism: Select
-
Threats Mitigated:
- Unauthorized Access: (Severity: High)
- Brute-Force Attacks: (Severity: Medium) - Strong SASL mechanisms help.
- Credential Theft: (Severity: High) - Secure storage is crucial.
-
Impact:
- Unauthorized Access: Risk near zero with proper SASL and strong credentials.
- Brute-Force Attacks: Risk significantly reduced with strong SASL.
- Credential Theft: Risk significantly reduced with secure storage.
-
Currently Implemented:
- Not implemented. Neither
producer
norconsumer
have SASL configured.
- Not implemented. Neither
-
Missing Implementation:
- Implement SASL in both
producer
andconsumer
. - Implement secure credential storage.
- Implement SASL in both
Mitigation Strategy: Configure Consumer Group Settings (Sarama Configuration)
-
Mitigation Strategy: Configure Sarama's Consumer Group settings to optimize rebalancing and failure detection.
-
Description:
Session.Timeout
andHeartbeat.Interval
:Config.Consumer.Group.Session.Timeout
: Set to a reasonable value (e.g., 10-30 seconds) based on processing time and latency.Config.Consumer.Group.Heartbeat.Interval
: Should be significantly less thanSession.Timeout
(e.g., 1/3).
Rebalance.Timeout
: SetConfig.Consumer.Group.Rebalance.Timeout
.- Static Membership (Optional): If using Kafka 2.3+, consider static membership:
Config.Consumer.Group.InstanceId = "unique_id"
.
-
Threats Mitigated:
- DoS due to Frequent Rebalancing: (Severity: Medium)
- Delayed Failure Detection: (Severity: Medium)
- Data Loss/Duplication (Indirectly): (Severity: Low)
-
Impact:
- DoS (Rebalancing): Risk significantly reduced with proper timeouts and static membership.
- Delayed Failure Detection: Risk significantly reduced with proper timeouts.
- Data Loss/Duplication: Risk indirectly reduced.
-
Currently Implemented:
- Partially.
consumer
has basic settings, but not optimized. Defaults used for timeouts.
- Partially.
-
Missing Implementation:
- Tune
Session.Timeout
andHeartbeat.Interval
. - Consider static membership.
- Tune
Mitigation Strategy: Control Producer and Consumer Resource Usage (Sarama Configuration)
-
Mitigation Strategy: Control resource usage via Sarama's producer and consumer configuration.
-
Description:
- Producer:
Config.Producer.Flush
Settings:Config.Producer.Flush.Frequency
Config.Producer.Flush.Messages
Config.Producer.Flush.Bytes
- Tune these based on throughput and broker capacity.
Config.Producer.MaxMessageBytes
: Set a reasonable limit.
- Consumer:
Config.Consumer.Fetch.Default
andConfig.Consumer.Fetch.Max
:- Set these to avoid fetching excessive data.
- Producer:
-
Threats Mitigated:
- DoS (Producer): (Severity: High) - Overwhelming brokers.
- DoS (Consumer): (Severity: High) - Excessive resource consumption.
- Application Instability: (Severity: Medium)
-
Impact:
- DoS (Producer): Risk significantly reduced with proper buffer sizes and
MaxMessageBytes
. - DoS (Consumer): Risk significantly reduced with controlled fetch sizes.
- Application Instability: Risk significantly reduced.
- DoS (Producer): Risk significantly reduced with proper buffer sizes and
-
Currently Implemented:
- Partially.
producer
andconsumer
have some settings, but not fully optimized.
- Partially.
-
Missing Implementation:
- Tune
Config.Producer.Flush
settings. - Tune
Config.Consumer.Fetch
settings. - Set
Config.Producer.MaxMessageBytes
.
- Tune
Mitigation Strategy: Implement Robust Error Handling and Recovery (Sarama Usage)
-
Mitigation Strategy: Use Sarama's features and proper coding practices for robust error handling.
-
Description:
- Check All Errors: Always check errors returned by Sarama functions.
- Idempotent Producers: Use
Config.Producer.Idempotent = true
(Kafka 0.11+). - Transactional Producers: For exactly-once semantics, use Sarama's transactional API.
- Offset Management: Carefully manage consumer offsets. Choose between automatic (
Config.Consumer.Offsets.AutoCommit.Enable = true
) and manual committing. If manual, commit after successful processing.
-
Threats Mitigated:
- Data Loss: (Severity: High)
- Data Duplication: (Severity: Medium)
- Application Crashes: (Severity: High)
- Inconsistent State: (Severity: High)
-
Impact:
- Data Loss: Risk significantly reduced with error handling, retries, and potentially DLQs (DLQs themselves are not a direct Sarama feature).
- Data Duplication: Risk significantly reduced with idempotent/transactional producers and offset management.
- Application Crashes: Risk significantly reduced with error handling.
- Inconsistent State: Risk significantly reduced with transactions and offset management.
-
Currently Implemented:
- Partially. Basic error handling exists, but not comprehensive. No retries or DLQs.
-
Missing Implementation:
- Idempotent or transactional producers should be considered.
- Offset management needs review and potential improvement.