Skip to content

feat(c-abi): expose mTLS client identity - #289

Merged
sreekanth-db merged 3 commits into
mainfrom
feat/c-abi-mtls-client-certificate
Aug 24, 2026
Merged

sreekanth-db merged 3 commits into
mainfrom
feat/c-abi-mtls-client-certificate

Conversation

@sreekanth-db

Copy link
Copy Markdown
Contributor

Summary

  • expose the kernel's existing mTLS client certificate/private-key configuration through a paired C-ABI setter
  • reject null or empty certificate/key inputs and copy accepted buffers into Rust-owned memory
  • forward the identity into the existing TlsConfig, preserving strict server verification and private-key redaction
  • add Rust unit tests, a real C-consumer smoke test, and hermetic end-to-end mTLS handshakes

Motivation

The Rust kernel already supports mTLS through its core API, PyO3, and N-API bindings. Go and ODBC consumers use the C ABI, which currently exposes custom server trust and verification controls but has no way to provide the client identity.

This adds one atomic API:

KernelStatusCode kernel_session_config_set_tls_client_certificate(
    KernelSessionConfig* config,
    const uint8_t* cert_pem,
    size_t cert_len,
    const uint8_t* key_pem,
    size_t key_len);

Taking the certificate and key together prevents a partially configured identity at the C boundary. The certificate may contain the leaf followed by intermediates; an unencrypted PKCS#8 key is recommended for portability across the native-TLS and rustls backends.

Behavior and security

  • null or zero-length certificate/key values return InvalidArgument
  • accepted buffers are copied before the setter returns
  • parsing and certificate/key matching remain delegated to the existing kernel TLS implementation
  • the private key is never rendered by the kernel's TlsConfig debug output
  • server chain and hostname verification remain strict unless independently relaxed by existing options
  • no certificates or private keys are committed by the tests; all identities are generated at runtime

Testing

Hermetic mTLS end-to-end tests

tests/c_abi_mtls_e2e.rs starts a local rustls HTTPS server configured to require and verify client certificates. It exercises the complete path:

C ABI setter -> kernel TlsConfig -> reqwest client -> TLS handshake

Covered cases:

  • valid client certificate succeeds and the server observes the expected peer certificate
  • missing client certificate fails the handshake
  • client certificate signed by an untrusted CA fails the handshake
  • test CA, server certificate, and client certificates are generated in-process

The suite passes with both kernel TLS backends:

  • cargo test --test c_abi_mtls_e2e — 3 passed
  • cargo test --no-default-features --features tls-rustls --test c_abi_mtls_e2e — 3 passed

Unit and C-ABI coverage

  • setter stores certificate and key bytes together
  • null and zero-length values return InvalidArgument without mutating TLS state
  • session construction forwards both values into the existing mTLS identity parser
  • tests/c/session_smoke.c compiles and calls the exported symbol from a real C consumer, including success and missing-half rejection cases

Regression validation

  • cargo test — 1,040 passed, 63 ignored
  • cargo clippy --all-targets -- -D warnings — passed
  • cargo fmt --check — passed
  • git diff --check — passed
  • Isaac uncommitted review — 0 actionable findings across all 7 changed files

Follow-up

After this lands, the Go driver can pin the merged kernel revision and add its kernel-specific client-certificate option without depending on an unmerged kernel branch.

Allow Go and ODBC consumers to configure paired client certificates through the kernel C ABI, with hermetic handshake coverage across both TLS backends.

Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

Use an explicit IPv4 endpoint to avoid localhost resolution differences in CI and preserve kernel/server diagnostics when a handshake fails.

Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

Keep the hermetic mTLS test focused on server-side client identity validation so platform-specific native server trust does not mask the behavior under test.

Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

@sreekanth-db sreekanth-db added the integration-test Maintainer-only: triggers cross-repo integration tests. Auto-removed on push for re-review. label Aug 24, 2026
@github-actions

Copy link
Copy Markdown

Kernel integration tests triggered. View status. Results post back here as the "Kernel Integration Tests" check.

@sreekanth-db
sreekanth-db enabled auto-merge August 24, 2026 23:04
@sreekanth-db
sreekanth-db added this pull request to the merge queue Aug 24, 2026
Merged via the queue into main with commit e8d60c9 Aug 24, 2026
26 of 32 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — cf793d3d Deployed Aug 24, 2026 by sreekanth-db via followup #986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-test Maintainer-only: triggers cross-repo integration tests. Auto-removed on push for re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants