← Back to Pull requests

Support static Linux (musl) builds via CNIOBoringSSL; make GSSAPI opt-in #263

Closed
unknown closed this pull request without merging on Oct 03, 2026 01:03 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 19:32 UTC
Author

Motivation

swift-kafka-client wraps the librdkafka C library, which links the system OpenSSL for TLS/crypto and the system libsasl2 (Cyrus SASL) for GSSAPI/Kerberos. A fully-static Linux binary built with the Swift static Linux (musl) SDK can't use those system libraries — the SDK ships its own (non‑prefixed) BoringSSL and no libsasl2 — so the package didn't build for musl.

This is a constraint fairly specific to this package: unlike a pure‑Swift library, we carry a large C dependency that hard‑links OpenSSL across several files and pulls in libsasl2 for one optional auth mechanism.

Approach

Route librdkafka's <openssl/.h> usage onto swift-nio-ssl's vendored BoringSSL (CNIOBoringSSL) on all platforms via a small header shim, depending on the public NIOSSL product so CNIOBoringSSL is pulled into the link transitively. librdkafka needs two functions BoringSSL doesn't export (RAND_priv_bytes, SSL_CTX_use_cert_and_key); these are provided as thin shims. TLS/crypto is now self‑contained on every platform (no system OpenSSL), and the package builds with the static musl SDK.

Alternatives considered

  • Vendor a full copy of BoringSSL into this repo — rejected. It means importing and maintaining hundreds of generated C/asm files plus a symbol‑prefixing/vendoring script — duplicating something the Swift ecosystem already ships and keeps patched. That's a large, ongoing maintenance and security‑update burden for no functional gain over reusing the already‑vendored, already‑audited BoringSSL distributed by swift-nio-ssl.
  • Gate the static build behind an environment variable / build flag — rejected as the primary mechanism. It only makes musl work while glibc/macOS keep the system OpenSSL, so the default build stays non‑self‑contained, the two configurations diverge, and it's easy to misconfigure. Reusing the vendored BoringSSL uniformly* removes the need for a special build mode at all.
  • Reusing the ecosystem's vendored BoringSSL through its public product is the least‑maintenance option, keeps a single uniform build across platforms, and follows a pattern already used by other C‑wrapping Swift libraries.

    GSSAPI/Kerberos is now opt‑in (off by default) — behavior change

    GSSAPI (Cyrus SASL) is the only SASL mechanism that needs the external system libsasl2, which a static build can't provide, so it's now opt‑in and off by default. SCRAM, PLAIN, and TLS/mTLS are unaffected and always available.

  • Default build: fully self‑contained; works with the static musl SDK out of the box.

  • To enable GSSAPI: build with SWIFT_KAFKA_ENABLE_GSSAPI=1 (compiles the Cyrus provider and links libsasl2; requires the libsasl2 dev headers).
  • This matches the librdkafka‑wrapper ecosystem, where GSSAPI is consistently opt‑in rather than on by default. This is change from the current behavior, where the default build provides GSSAPI.

    Verification

  • Unit tests (KafkaSSLCertLoadingTests) exercise CNIOBoringSSL certificate loading at client creation — PEM (CA/cert/key) and PKCS#12 (which routes through the SSL_CTX_use_cert_and_key shim) — with negative controls proving the parse paths actually run.

  • Gated integration tests (KafkaSecurityIntegrationTests) cover TLS transport, mTLS authentication, SASL/SCRAM authentication over TLS, and ACL authorization (allow + deny) against a real broker with SSL/SASL_SSL listeners. They're gated on KAFKA_SSL_PORT and skip when no secure broker is present, so plaintext/CI runs are unaffected.

  • Full suite (142 tests) passes against the CNIOBoringSSL build with no regression on macOS and Linux (glibc); the GSSAPI opt‑in build compiles and links (Cyrus + libsasl2 + CNIOBoringSSL).
  • Follow‑ups

  • A dedicated CI job that builds against the static musl SDK.

  • The integration test broker's PKI is generated at container startup (no keys committed).
  • Diff: 493 lines (+369 / -124) across 6 files Reviewer: FranzBusch Review duration: 3211m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 493 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.371
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #263"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.7% · Safe to merge
    18.7%