Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if(GTest_FOUND)
tests/unit/AuthCodecTest.cpp
tests/unit/HotRodURITest.cpp
tests/unit/SaslAuthenticatorTest.cpp
tests/unit/SaslMechanismsTest.cpp
tests/unit/TlsConnectionTest.cpp
)

Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A cross-platform C++17 implementation of the Infinispan Hot Rod protocol client.

🎉 **Smart client** - hash-aware routing, automatic failover, full CRUD +
metadata ops, typed error handling and user-decided retry (keyed & keyless),
and SASL/SCRAM authentication (SCRAM-SHA-1/256/512).
and SASL authentication (SCRAM-SHA-1/256/512, PLAIN, EXTERNAL, OAUTHBEARER).

## Quick Start

Expand Down Expand Up @@ -193,9 +193,11 @@ coverage breakdown and counts.
tried nodes) + `isTransient` / `outcomeUncertain` classification (Step 11a)
- ✅ **User-decided retry** (`cache.excluding(e)` bound view) for keyed ops and
keyless `ping`, with automatic before-send failover (Step 11b/11c)
- ✅ **SASL/SCRAM authentication** (`setAuthentication(...)`) — end-to-end for the
SCRAM family (`SCRAM-SHA-1`/`SCRAM-SHA-256`/`SCRAM-SHA-512`), applied to every
connection; see [`documentation/topics/security.adoc`](documentation/topics/security.adoc)
- ✅ **SASL authentication** (`setAuthentication(...)`) — end-to-end, applied to
every connection: SCRAM family (`SCRAM-SHA-1`/`-256`/`-512`), **PLAIN**,
**EXTERNAL** (identity from the mutual-TLS client cert), and **OAUTHBEARER**
(bearer `token`). GSSAPI/DIGEST-MD5 throw at connect(). See
[`documentation/topics/security.adoc`](documentation/topics/security.adoc)
- ✅ **Hot Rod URI** (`RemoteCache::fromUri("hotrod[s]://...")`) — build a client from
a connection string (hosts, credentials, `sasl_mechanism`/`client_intelligence`/
`protocol_version` params, and the server-auth TLS params below); timeouts and more
Expand Down Expand Up @@ -261,8 +263,9 @@ cache->connect();
// Supports hotrod:// and hotrods:// (TLS). All hosts become seed servers (issue
// #12): connect() tries each in order, and ops fall back to the seed list when the
// connected server dies or no topology is known (e.g. BASIC mode). Credentials
// enable SCRAM, and sasl_mechanism/client_intelligence/protocol_version (Java
// "4.0"/"4.1" form) are honoured. hotrods:// enables TLS (PEM material only); the
// enable SCRAM by default; sasl_mechanism (SCRAM*/PLAIN/EXTERNAL/OAUTHBEARER, with
// token for OAUTHBEARER) / client_intelligence / protocol_version (Java "4.0"/"4.1"
// form) are honoured. hotrods:// enables TLS (PEM material only); the
// ca_file (PEM CA) / sni_host_name / ssl_hostname_validation params and the mutual-
// TLS client_cert_file / client_key_file / client_key_password params map to
// setTls(...). The Java keystore keys (trust_store_file_name, key_store_*, …) are
Expand Down Expand Up @@ -296,7 +299,7 @@ cache->connect();
user-decided retry (keyed + keyless)
- ✅ **TLS, incl. mutual TLS** (shipped, issue #18): `hotrods://` + `setTls(...)`, PEM only
- **Step 12 — Bulk operations** (next): `GET_ALL`, `PUT_ALL`, `BULK_GET`
- Also: multiplexing benchmarks, non-SCRAM SASL + PKCS12/JKS keystores (issue #10)
- Also: multiplexing benchmarks, GSSAPI SASL (Kerberos) + PKCS12/JKS keystores (issue #10)

## Project Structure

Expand Down
45 changes: 45 additions & 0 deletions docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1318,3 +1318,48 @@ is now unblocked by this change but not yet implemented.
**Keys still rejected (not keystore-related):** `use_ssl`, `ssl_protocol`,
`ssl_ciphers`, `ssl_named_groups`, `ssl_provider`, `ssl_context` — protocol/cipher
tuning deferred (issue #10).

## 2026-11-12 — Non-SCRAM SASL: PLAIN, EXTERNAL, OAUTHBEARER

**What:** The SASL driver (`SaslAuthenticator`) now supports three single-message
mechanisms beyond the SCRAM family: **PLAIN** (RFC 4616), **EXTERNAL** (RFC 4422),
and **OAUTHBEARER** (RFC 7628). GSSAPI/GS2-KRB5 (Kerberos) and DIGEST-MD5 remain
unsupported and throw at connect().

- `Authentication` gains a `token` field (OAUTHBEARER bearer token). A new
`RemoteCache::setAuthentication(const Authentication&)` overload configures
mechanisms the username/password convenience setter can't (OAUTHBEARER token,
EXTERNAL cert identity).
- `HotRodURI` now parses `token` (previously an unknown-key error) and keeps
`sasl_mechanism`; `fromUri` enables auth on *any* auth signal (mechanism, creds,
or token) rather than requiring a username — EXTERNAL/OAUTHBEARER have none.
- Pure, unit-testable initial-response builders live in
`include/hotrod/SaslMechanisms.h` (header-only, like `AuthCodec.h`).

**Why it matters:** The wire layer (`AuthCodec`, `SaslTransport`) was already
mechanism-agnostic — it carries a mechanism name + opaque token bytes — so only the
driver was SCRAM-specific. Generalizing it (classify mechanism → SCRAM multi-turn
vs single-message path) kept the well-tested SCRAM flow untouched while adding the
common non-Kerberos mechanisms cheaply. EXTERNAL was unblocked by mutual TLS
(same-day #18 work): the client identity is the TLS client certificate.

**Design notes / gotchas:**
- **PLAIN** builds `authzid NUL authcid NUL passwd` as raw bytes (NULs), never a C
string; authzid empty = authorize as the authcid. Must be used over TLS (password
is effectively cleartext). Requires a username (throws otherwise, BeforeSend).
- **EXTERNAL** sends the authorization id (usually empty — identity from the cert).
Needs no credentials; pointless without a mutual-TLS client cert.
- **OAUTHBEARER** sends `n,[a=authzid],^Aauth=Bearer <token>^A^A` (^A = 0x01).
Requires a token (throws otherwise). On failure the server returns a non-completed
error challenge and expects a lone `0x01` continuation before failing the exchange
with an ERROR frame (RFC 7628) — the driver handles that extra turn.
- Mechanism names are matched case-sensitively against the server's offered list
(as on the wire): use the canonical upper-case names.

**Coverage:** unit only — pure builders + driver flows against fake servers
(success, bad credentials, missing username/token, mechanism-not-offered,
OAUTHBEARER failure continuation). End-to-end integration against a real server is
deferred (needs server realms/token issuer; see STATUS backlog), as with mutual TLS.

**Deferred:** GSSAPI/GS2-KRB5 (needs MIT krb5/Heimdal + multi-round GSS exchange),
DIGEST-MD5 (obsolete). SASL QOP/`sasl_properties.*` not wired.
43 changes: 27 additions & 16 deletions docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ _The 1–3 concrete things to do next. Keep this short and current._
(two `TODO`s in `src/operations/RemoteCache.cpp`).

_Recently shipped (detail in "Working and shipped" + [`DECISIONS.md`](DECISIONS.md)):
mutual TLS (PEM client cert/key) + PEM-honest TLS URI keys (`ca_file`,
non-SCRAM SASL (PLAIN/EXTERNAL/OAUTHBEARER) (#10, 2026-11-12), mutual TLS (PEM
client cert/key) + PEM-honest TLS URI keys (`ca_file`,
`client_cert_file`/`client_key_file`; Java keystore keys now rejected with a
redirect) (#18, 2026-11-12), server-authenticated TLS for `hotrods://` (#18,
2026-11-06), multi-server seed list + failover (#12), Hot Rod URI `fromUri` (#9),
Expand All @@ -66,16 +67,20 @@ pull from here next. Step numbers follow
Docker `TlsIntegrationTest`, which needs the Infinispan server configured to
require/verify client certs (extend `scripts/start_infinispan_tls.sh` +
`gen-test-certs.sh` already emits the unit client cert).
- [ ] **Non-SCRAM SASL integration coverage** — PLAIN/EXTERNAL/OAUTHBEARER are
unit-tested against fake servers but not end-to-end: PLAIN needs a server SASL
realm offering it; EXTERNAL needs mutual TLS + a cert→identity mapping;
OAUTHBEARER needs a token issuer/realm. `AuthIntegrationTest` covers SCRAM only.
- [ ] **Benchmark the multiplexing path** — the async rewrite targets 5–10×
concurrent throughput; unmeasured so far.
- [ ] **Code cleanup:** read header "other params" when `paramCount > 0`
(`src/operations/RemoteCache.cpp:140,182`).
- [ ] **Hot Rod URI — deferred features (issue #10):** `connect_timeout`/
`socket_timeout`, non-SCRAM SASL (PLAIN/OAUTHBEARER `token`, EXTERNAL — now
unblocked by mutual TLS), `protocol_version=AUTO`/3.x. Each drops its
"unsupported" throw from `HotRodURI::parse` once the capability lands.
(Multi-server seed list — #12 — and TLS incl. mutual TLS — #18 — are already
shipped; see "Working and shipped".)
`socket_timeout`, `protocol_version=AUTO`/3.x, and GSSAPI/GS2-KRB5 SASL (needs a
Kerberos lib). Each drops its "unsupported" throw from `HotRodURI::parse` once
the capability lands. (Multi-server seed list — #12 — TLS incl. mutual TLS — #18 —
and non-SCRAM SASL PLAIN/EXTERNAL/OAUTHBEARER are already shipped; see "Working
and shipped".)
- [ ] **TLS keystore formats + tuning (deferred part of #18/#10):** Java keystore
formats (JKS/PKCS12, `*_store_file_name`/`*_store_type`/password/`key_alias`) —
this client is PEM-only, so these URI keys are rejected with a redirect to the
Expand Down Expand Up @@ -138,11 +143,15 @@ Rod URI `fromUri` (#9), multi-server seed list + failover (#12)._
Excluding every known server still throws (no seed rescue of an excluded node)
- Wire primitives (vInt, vLong, strings, byte arrays)
- Protocol 4.0 headers (all conditional fields)
- **SASL/SCRAM authentication (end-to-end)** — `setAuthentication(...)` runs the
AUTH_MECH_LIST + two-turn SCRAM handshake on every connection (seed +
topology-discovered), for the whole family (`SCRAM-SHA-1/256/512`, RFC 5802,
OpenSSL); non-SCRAM mechanisms throw at connect(). See
`documentation/topics/security.adoc`
- **SASL authentication (end-to-end)** — `setAuthentication(...)` runs the
AUTH_MECH_LIST + AUTH handshake on every connection (seed + topology-discovered).
Mechanisms: SCRAM family (`SCRAM-SHA-1/256/512`, RFC 5802, two-turn), **PLAIN**
(RFC 4616), **EXTERNAL** (RFC 4422 — identity from the mutual-TLS client cert),
**OAUTHBEARER** (RFC 7628 — bearer `token`); single-message mechanisms share a
generalized path, pure initial-response builders in `include/hotrod/SaslMechanisms.h`.
URI selects via `sasl_mechanism` (+ `token`); the `Authentication` overload of
`setAuthentication` covers token/cert mechanisms. GSSAPI/DIGEST-MD5 throw at
connect(). All OpenSSL, no JDK SASL provider. See `documentation/topics/security.adoc`
- Cluster topology awareness (failover, load balancing)
- Consistent hashing (MurmurHash3 x64_32, seed 9001)
- Hash-aware routing → primary owner, with automatic failover
Expand Down Expand Up @@ -189,15 +198,17 @@ Rod URI `fromUri` (#9), multi-server seed list + failover (#12)._
that stalls a subprocess fails fast instead of hanging the whole CI job. See
[`DECISIONS.md`](DECISIONS.md).

**Test status:** **266 unit** (verified 2026-11-12) + **96 integration** (20
**Test status:** **284 unit** (verified 2026-11-12) + **96 integration** (20
suites, verified 2026-10-19), all passing. This is the one authoritative count —
other docs describe *what* is covered rather than repeating totals. Counts read
from the built test binaries via `--gtest_list_tests`, so they match what actually
runs. (The +16 unit tests since 2026-11-09 are the mutual-TLS handshake cases and
the PEM-honest URI-key parsing/redirect cases.)
runs. (The +34 unit tests since 2026-11-09 are the mutual-TLS handshake cases, the
PEM-honest URI-key parsing/redirect cases, and the non-SCRAM SASL mechanism cases
— pure initial-response builders + PLAIN/EXTERNAL/OAUTHBEARER driver flows.)
- Unit (`./build/unit_tests`, <1s) — wire primitives/headers, consistent hashing,
server-selection/retry helpers, the SASL/SCRAM handshake, the TLS handshake
(server-auth + mutual TLS, in-process OpenSSL server), and the Hot Rod URI parser.
server-selection/retry helpers, the SASL handshake (SCRAM family +
PLAIN/EXTERNAL/OAUTHBEARER, against fake servers), the TLS handshake (server-auth
+ mutual TLS, in-process OpenSSL server), and the Hot Rod URI parser.
- Integration (`ctest`, spins up Docker Infinispan single-server + multi-node
clusters; also green on Linux CI) — CRUD + metadata/CAS, topology & hash-aware
routing, keyed/keyless retry (`RetryView`/ping), SASL/SCRAM against a secured
Expand Down
60 changes: 50 additions & 10 deletions documentation/topics/security.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

=== Authentication

The client authenticates over SASL. The **SCRAM family** is implemented:
The client authenticates over SASL. These mechanisms are implemented:

* **SCRAM-SHA-256** -- the default when you call `setAuthentication(...)`.
* **SCRAM-SHA-1**
* **SCRAM-SHA-512**

Any other mechanism (`PLAIN`, `DIGEST-MD5`, `EXTERNAL`, `GSSAPI`,
`OAUTHBEARER`, …) throws a `HotRodClientException` at `connect()` time with a
clear "unsupported SASL mechanism" message. C++ has no JDK-style SASL provider
framework, so each mechanism is hand-rolled over OpenSSL; only the SCRAM variants
share the generalized implementation today.
* **SCRAM-SHA-1**, **SCRAM-SHA-512**
* **PLAIN** -- username + password (always use over TLS; the password is sent
effectively in the clear).
* **EXTERNAL** -- the identity comes from the mutual-TLS client certificate (no
username/password needed); requires a `hotrods://` connection presenting a
client cert (see _TLS / mutual TLS_ below).
* **OAUTHBEARER** -- a bearer `token` (e.g. an OAuth2/OIDC access token).

Any other mechanism (`DIGEST-MD5`, `GSSAPI`, …) throws a `HotRodClientException`
at `connect()` time with a clear "unsupported SASL mechanism" message. C++ has no
JDK-style SASL provider framework, so each mechanism is hand-rolled over OpenSSL.

==== Configuring authentication

Expand Down Expand Up @@ -56,12 +59,49 @@ void setAuthentication(const std::string& username,
const std::string& mechanism = "SCRAM-SHA-256");
----

To use a different SCRAM variant, pass the mechanism explicitly:
To use a different username/password mechanism (another SCRAM variant, or PLAIN),
pass the mechanism explicitly:

[source,cpp]
----
cache.setAuthentication("username", "password",
"default", "infinispan", "SCRAM-SHA-512");

cache.setAuthentication("username", "password",
"default", "infinispan", "PLAIN"); // use over TLS
----

For **EXTERNAL** (identity from the client cert) and **OAUTHBEARER** (bearer
token), build an `Authentication` and use the overload that takes it:

[source,cpp]
----
#include "hotrod/Authentication.h"

// OAUTHBEARER: authenticate with a bearer token (no username/password).
Authentication oauth;
oauth.mechanism = "OAUTHBEARER";
oauth.token = "<access-token>";
cache.setAuthentication(oauth);

// EXTERNAL: identity is the mutual-TLS client certificate (configure TLS too).
Authentication external;
external.mechanism = "EXTERNAL";
cache.setAuthentication(external);
----

From a URI, select the mechanism with `sasl_mechanism` (and `token` for
OAUTHBEARER):

[source,cpp]
----
// PLAIN over TLS:
RemoteCache::fromUri("hotrods://user:pass@host?sasl_mechanism=PLAIN&ca_file=/ca.pem");
// OAUTHBEARER:
RemoteCache::fromUri("hotrods://host?sasl_mechanism=OAUTHBEARER&token=<tok>&ca_file=/ca.pem");
// EXTERNAL (client cert):
RemoteCache::fromUri("hotrods://host?sasl_mechanism=EXTERNAL"
"&ca_file=/ca.pem&client_cert_file=/client.pem&client_key_file=/client-key.pem");
----

==== Defaults
Expand Down
17 changes: 12 additions & 5 deletions include/hotrod/Authentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ namespace hotrod {
* seed connection and every topology-discovered cluster member — before the
* connection is used for operations.
*
* Only the SCRAM family is implemented (SCRAM-SHA-1 / SCRAM-SHA-256 /
* SCRAM-SHA-512); any other configured mechanism throws a HotRodClientException
* at connect time. For the SCRAM mechanisms only `username` and `password`
* actually enter the exchange; `realm` and `serverName` are carried for parity
* with the Java client (and future mechanisms) but are unused by SCRAM.
* Supported mechanisms:
* - SCRAM family: SCRAM-SHA-1 / SCRAM-SHA-256 / SCRAM-SHA-512 — uses
* `username` + `password`.
* - PLAIN — uses `username` + `password` (send over TLS).
* - EXTERNAL — identity comes from the mutual-TLS client certificate; no
* credentials needed (`username`, if set, is sent as the authorization id).
* - OAUTHBEARER — uses `token` (a bearer token); `username`, if set, is sent as
* the authorization id.
* Any other configured mechanism throws a HotRodClientException at connect time.
* `realm` and `serverName` are carried for parity with the Java client but are
* not used on the wire by these mechanisms.
*
* Reference:
* - Java: org.infinispan.client.hotrod.configuration.AuthenticationConfiguration
Expand All @@ -26,6 +32,7 @@ struct Authentication {
bool enabled = false;
std::string username;
std::string password;
std::string token; // bearer token for OAUTHBEARER
std::string realm = "default";
std::string serverName = "infinispan";
std::string mechanism = "SCRAM-SHA-256";
Expand Down
14 changes: 11 additions & 3 deletions include/hotrod/HotRodURI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ namespace hotrod {
* them in order at connect() and falls back to the list when the learned
* topology is empty or exhausted. `seed()` is retained as the first host.
* - query parameters are a typed whitelist; an unknown key or a bad value for a
* known key throws. Deferred params (timeouts, non-SCRAM SASL) and the Java
* keystore TLS keys are therefore rejected rather than silently ignored.
* known key throws. Deferred params (timeouts) and the Java keystore TLS keys
* are therefore rejected rather than silently ignored. SASL mechanism selection
* (`sasl_mechanism`) and the OAUTHBEARER `token` are parsed here and validated
* at connect() (SCRAM family, PLAIN, EXTERNAL, OAUTHBEARER are supported).
*/
struct HotRodURI {
std::vector<ServerAddress> servers; // all parsed, in order (>=1)
std::optional<std::string> username;
std::optional<std::string> password;
std::optional<std::string> saslMechanism; // e.g. "SCRAM-SHA-256"
std::optional<std::string> token; // bearer token for OAUTHBEARER
std::optional<ClientIntelligence> clientIntelligence;
std::optional<uint8_t> protocolVersion; // Protocol::VERSION_40 / _41
std::optional<TlsConfig> tls; // set when scheme is hotrods://
Expand Down Expand Up @@ -244,8 +247,13 @@ inline HotRodURI HotRodURI::parse(const std::string& uri) {
"query parameter value");

if (key == "sasl_mechanism") {
// SCRAM-only is enforced later at connect(); pass through here.
// The mechanism is validated at connect() (SaslAuthenticator);
// pass it through here.
result.saslMechanism = value;
} else if (key == "token") {
// Bearer token for OAUTHBEARER (used only when the mechanism is
// OAUTHBEARER; validated at connect()).
result.token = value;
} else if (key == "client_intelligence") {
const std::string v = toLower(value);
if (v == "basic") {
Expand Down
Loading
Loading