krabka-security 0.8.0

TLS, SASL, SCRAM, OAuth, and Kerberos security utilities for Krabka
Documentation

krabka-security

Crates.io Docs.rs CI

TLS, SASL, SCRAM, OAuth, Kerberos, and certificate utilities for Krabka.

Part of Krabka, a Rust implementation of Apache Kafka-compatible infrastructure and clients.

Overview

krabka-security collects the reusable security primitives that Krabka brokers, clients, operators, and tests share. It builds rustls configs, implements SASL mechanism helpers, and runs SCRAM exchanges. It also validates OAuth bearer tokens, extracts Kafka principals from certificates, and issues local test/cluster certificates.

The crate supplies security building blocks. It does not open network sockets and it does not own OAuth/JWKS refresh loops. Callers integrate these primitives with their own transport and runtime.

Capabilities

  • SASL mechanism names and auth method types for PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, OAUTHBEARER, and GSSAPI.
  • PLAIN verification helpers.
  • SCRAM credential hashing and client/server exchange state machines.
  • OAuth bearer initial-response parsing, unsecured JWS validation, signed JWS validation through JWKS, and introspection traits.
  • TLS client/server config builders and dynamic server config reload support.
  • mTLS principal extraction from X.509 subject distinguished names.
  • Cluster and client CA generation plus broker/user certificate issuance.
  • Delegation-token HMAC helpers and redacted secret wrappers.
  • Kerberos/GSSAPI trait surfaces, keytab parsing, and provider scaffolding, behind the gssapi feature.

Kafka Security Scope

SASL mechanism wire names match Kafka mechanism strings. SCRAM follows RFC 5802 and includes KIP-554-style broker credential derivation. OAuth bearer parsing matches the RFC 7628/KIP-255 client initial response shape. mTLS principal extraction follows Kafka's default subject-DN principal style.

GSSAPI support is a de-risking surface. Review it before you use it in production.

Cargo features

Feature Default What it adds
gssapi off SASL/GSSAPI (Kerberos): the gssapi module, its keytab parser and the sspi-backed acceptor and initiator. Native targets only.

gssapi is off by default because its Kerberos stack, krabka-sspi, depends on rsa 0.10. That crate carries RUSTSEC-2023-0071, the Marvin timing attack, and has no patched release. Without the feature, a build compiles no rsa code. With it, Krabka's GSSAPI code uses only AES keytab keys and never runs an RSA private-key operation; docs/rustsec-2023-0071.md has the analysis.

Turn it on only in a crate that serves or initiates GSSAPI:

krabka-security = { version = "0.7", features = ["gssapi"] }

Without it, SaslMechanism::Gssapi still parses, but SaslMechanism::is_available returns false for it, and SaslMechanism::require_available returns AuthError::UnsupportedMechanism. A broker answers that with Kafka's UNSUPPORTED_SASL_MECHANISM.

Install

cargo add krabka-security

For workspace development, use the path dependency from this repository.

Usage

Build the client-first message for a SCRAM-SHA-256 exchange:

use krabka_security::{SaslMechanism, ScramClientExchange};

let exchange = ScramClientExchange::new(
    "alice".to_string(),
    b"correct horse battery staple".to_vec(),
    SaslMechanism::ScramSha256,
);

let (client_first, _exchange) = exchange.client_first()?;
println!("send SCRAM client-first-message: {}", String::from_utf8_lossy(&client_first));
# Ok::<(), krabka_security::AuthError>(())

Documentation

License

Apache-2.0. Derivative work of Apache Kafka; see NOTICE.