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
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,30 @@ if(GTest_FOUND)
# Note: NOT gtest_main - we provide our own main()
)

# Mutual TLS integration tests (client cert required, no SASL; #10 coverage)
add_executable(mutual_tls_integration_tests
tests/integration/MutualTlsIntegrationTest.cpp
)

target_link_libraries(mutual_tls_integration_tests
PRIVATE
hotrod-client
GTest::gtest
# Note: NOT gtest_main - we provide our own main()
)

# SASL EXTERNAL over mutual TLS integration tests (cert identity; #10 coverage)
add_executable(external_auth_integration_tests
tests/integration/ExternalAuthIntegrationTest.cpp
)

target_link_libraries(external_auth_integration_tests
PRIVATE
hotrod-client
GTest::gtest
# Note: NOT gtest_main - we provide our own main()
)

target_link_libraries(fromuri_integration_tests
PRIVATE
hotrod-client
Expand Down Expand Up @@ -391,6 +415,8 @@ if(GTest_FOUND)
add_test(NAME MultiSeedIntegrationTests COMMAND multiseed_integration_tests)
add_test(NAME AuthIntegrationTests COMMAND auth_integration_tests)
add_test(NAME TlsIntegrationTests COMMAND tls_integration_tests)
add_test(NAME MutualTlsIntegrationTests COMMAND mutual_tls_integration_tests)
add_test(NAME ExternalAuthIntegrationTests COMMAND external_auth_integration_tests)

# Set working directory so scripts can be found
set_tests_properties(PingIntegrationTests PROPERTIES
Expand Down Expand Up @@ -477,6 +503,14 @@ if(GTest_FOUND)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker;tls"
)
set_tests_properties(MutualTlsIntegrationTests PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker;tls;mutual-tls"
)
set_tests_properties(ExternalAuthIntegrationTests PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker;auth;tls;mutual-tls"
)

# Fail fast if a suite hangs (e.g. a server/CLI-version regression stalls a
# subprocess) instead of letting one stuck test burn the whole CI job budget.
Expand All @@ -489,6 +523,7 @@ if(GTest_FOUND)
ConcurrentClientsTests HashAwareRoutingIntegrationTests ConcurrentMultiServerTests
RetryViewIntegrationTests PingRetryIntegrationTests MultiSeedIntegrationTests
AuthIntegrationTests TlsIntegrationTests
MutualTlsIntegrationTests ExternalAuthIntegrationTests
PROPERTIES TIMEOUT 300
)
endif() # NOT WIN32 (integration tests)
Expand Down
60 changes: 60 additions & 0 deletions docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1363,3 +1363,63 @@ deferred (needs server realms/token issuer; see STATUS backlog), as with mutual

**Deferred:** GSSAPI/GS2-KRB5 (needs MIT krb5/Heimdal + multi-round GSS exchange),
DIGEST-MD5 (obsolete). SASL QOP/`sasl_properties.*` not wired.

## 2026-11-13 — Integration coverage: mutual TLS, SASL PLAIN, SASL EXTERNAL

**What:** Added Docker-backed, end-to-end integration tests for three features
that previously had unit coverage only, closing two STATUS backlog items (mutual
TLS, non-SCRAM SASL — all but OAUTHBEARER). One integration-coverage change set:
- **PLAIN** — no new infra. `infinispan-auth.xml` already offers PLAIN alongside
the SCRAM family and uses the same plain-text realm, so PLAIN reuses the existing
`AuthMechanismRoundTrip` fixture via a second `INSTANTIATE_TEST_SUITE_P` (now 7
`AuthIntegrationTests`).
- **Mutual TLS** — new `MutualTlsIntegrationTest` (suite
`MutualTlsIntegrationTests`) against `test-configs/infinispan-mtls.xml`
(require-ssl-client-auth, client-CA truststore, **no SASL**). Cases: programmatic
`setTls(cert/key)` round-trip, `hotrods://` URI with `client_cert_file`/
`client_key_file` round-trip, and a no-client-cert rejection.
- **EXTERNAL** — new `ExternalAuthIntegrationTest` (suite
`ExternalAuthIntegrationTests`) against `test-configs/infinispan-external.xml`
(the mutual-TLS realm + `<truststore-realm/>` + SASL EXTERNAL). Cases:
programmatic `setAuthentication({mechanism="EXTERNAL"})` + mutual TLS round-trip,
and the same via a `hotrods://` URI with `sasl_mechanism=EXTERNAL`.

One parameterized start script (`scripts/start_infinispan_mtls.sh [config]`) serves
both TLS configs; `scripts/gen-test-certs.sh` now also emits the integration client
identity (`client.pem`/`client.key`) and the server truststore bundle
(`client-truststore.pem`). Fixtures are committed. New ctest labels:
`mutual-tls` (both new suites), plus `auth`+`tls` on the EXTERNAL suite.

**Why it matters / gotchas discovered while wiring the server side:**

1. **`<truststore-realm/>` trusts *specific client certificates*, not just the
CA.** With a CA-only PEM truststore the pure-mTLS endpoint (no realm) accepted
our client cert fine, but the EXTERNAL endpoint rejected the TLS handshake with
`tlsv1.3 alert certificate unknown` (OpenSSL `0A000416`, SSL alert 46). Root
cause confirmed against Infinispan's own harness: `CertificateAuthority.export
Certificates` stores each **leaf** cert (`getCertificateChain()[0]`) as a
truststore entry, not the issuing CA. Fix: the committed server truststore is a
**bundle of the client leaf cert + its CA** (`client-truststore.pem`) — the leaf
entry satisfies the truststore-realm's exact-cert trust, and the CA lets the
pure-mTLS trust manager validate the chain too. One bundle serves both configs.

2. **TLS 1.3 reports a required-but-missing client cert *after* the handshake,
not at connect().** With `require-ssl-client-auth`, a client that presents no
cert still sees `SSL_connect()` succeed under TLS 1.3 — the server's
`certificate required` alert arrives post-handshake, surfacing on the first
read/op. So the no-client-cert test asserts an exception across connect()+op
(the `AuthIntegrationTest.NoCredentialsFails` pattern), not `EXPECT_THROW(connect)`.
(`openssl s_client ... <<< Q` masks this: it verifies only the *server* cert and
quits before reading the alert, so it looks like success.)

3. **`require-ssl-client-auth` is valid on the single-port `<endpoint>`** (it is a
`protocol-connector` base attribute in the 16.0 server schema), and Infinispan
**auto-detects a PEM truststore** (`password=""` per the schema) — no PKCS12
needed for the client-trust material.

**Authoritative references used (per AGENTS.md):** Infinispan server tests
`AuthenticationCertIT` + `security/trustrealm.xml` + `endpoints/auth-tls-external.xml`
(realm/endpoint shape), and the 16.0 server XSD (attribute placement, PEM detection).

**Deferred:** OAUTHBEARER integration (needs a token issuer/realm — Keycloak or a
static-JWT public key + pre-minted token); it remains unit-only. See STATUS backlog.
45 changes: 24 additions & 21 deletions docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
> If any other doc disagrees with this file, this file wins. Point-in-time
> snapshots live in [`archive/`](archive/) and are historical only.
>
> **Last updated:** 2026-11-12
> **Last updated:** 2026-11-13

---

Expand Down 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)):
non-SCRAM SASL (PLAIN/EXTERNAL/OAUTHBEARER) (#10, 2026-11-12), mutual TLS (PEM
Docker integration coverage for mutual TLS + SASL PLAIN + SASL EXTERNAL
(2026-11-13), 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,
Expand All @@ -62,15 +63,11 @@ pull from here next. Step numbers follow
`BULK_GET` (0x1F, iterator-style).

**Other known work (not roadmap steps):**
- [ ] **Mutual-TLS integration coverage** — client cert/key is unit-tested
(in-process OpenSSL server requiring a client cert) but not yet covered by the
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.
- [ ] **OAUTHBEARER integration coverage** — the last non-SCRAM SASL mechanism
without an end-to-end Docker test. Needs real token infra (a token-realm backed
by Keycloak, or a static-JWT public key + a pre-minted token). PLAIN, EXTERNAL,
and mutual TLS integration coverage shipped 2026-11-13 (see "Working and
shipped"); OAUTHBEARER is still unit-tested against a fake server 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`
Expand Down Expand Up @@ -198,24 +195,30 @@ 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:** **284 unit** (verified 2026-11-12) + **96 integration** (20
suites, verified 2026-10-19), all passing. This is the one authoritative count —
**Test status:** **284 unit** (verified 2026-11-12) + **107 integration** (23
suites, verified 2026-11-13), 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 +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.)
runs. (The +6 integration tests on 2026-11-13 are the mutual-TLS round-trip/URI/
no-cert-rejected cases — `MutualTlsIntegrationTests` — the SASL EXTERNAL
cert-identity round-trip + URI cases — `ExternalAuthIntegrationTests` — and a PLAIN
case added to `AuthIntegrationTests`.)
- Unit (`./build/unit_tests`, <1s) — wire primitives/headers, consistent hashing,
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
server, Hot Rod URI `fromUri`, and multi-server seed failover.
- Full run: `ctest --test-dir build --output-on-failure` → **100% pass, 21/21**
(1 unit + 20 integration suites) — last full end-to-end run 2026-10-19; unit
suite re-verified 2026-11-12 (266 pass) after the mutual-TLS/URI changes.
routing, keyed/keyless retry (`RetryView`/ping), SASL against a secured server
(SCRAM family + PLAIN via `AuthIntegrationTests`; EXTERNAL over mutual TLS via
`ExternalAuthIntegrationTests`), server-authenticated TLS (`TlsIntegrationTests`)
and mutual TLS (`MutualTlsIntegrationTests`), Hot Rod URI `fromUri`, and
multi-server seed failover.
- Full run: `ctest --test-dir build --output-on-failure` covers **24 suites**
(1 unit + 23 integration). Last full end-to-end run 2026-10-19 (100% pass at the
then-current 21 suites); unit suite re-verified 2026-11-12 (284 pass), and the
`Auth`/`Tls`/`MutualTls`/`ExternalAuth` integration suites verified 2026-11-13
(7 + 5 + 3 + 2 pass) after the integration-coverage changes.
- **Concurrency validated (2026-09-25):** the concurrent suites pass 8/8
(incl. `ConcurrentWithFailover`), and a ThreadSanitizer run (`build-tsan/`)
reports **no races in production code** — slice-4's `stateMutex_`/`shared_ptr`
Expand Down
19 changes: 19 additions & 0 deletions scripts/gen-test-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ openssl pkcs12 -export -out "$INT_DIR/server.p12" \
-inkey "$TMP/int-server.key" -in "$TMP/int-server.pem" \
-name server -passout "pass:$P12_PASS" 2>/dev/null

# Client identity for the mutual-TLS / EXTERNAL integration tests (MutualTls*,
# ExternalAuth* suites). A client CA signs a client leaf (client.pem + client.key,
# PEM) — what the client presents. The server's PEM truststore
# (client-truststore.pem) is a bundle of the client LEAF cert followed by its CA:
# - the leaf entry is what Infinispan's <truststore-realm/> (EXTERNAL) matches to
# derive the identity — the realm trusts specific client certificates, exactly as
# Infinispan's own test harness does (CertificateAuthority.exportCertificates
# stores each leaf, getCertificateChain()[0], not the CA);
# - the CA lets the pure-mTLS endpoint (no realm) validate the chain as well.
# Infinispan auto-detects the PEM truststore (password=""). The client CA *private*
# key is discarded, like the other CAs; the CA cert itself is not committed on its
# own — it lives only inside the committed truststore bundle.
make_ca "$TMP/int-clientca.pem" "$TMP/int-clientca.key" "Integration Client CA"
make_leaf "$TMP/int-clientca.pem" "$TMP/int-clientca.key" \
"$INT_DIR/client.key" "$INT_DIR/client.pem" \
"test-client" "DNS:test-client"
chmod 600 "$INT_DIR/client.key"
cat "$INT_DIR/client.pem" "$TMP/int-clientca.pem" > "$INT_DIR/client-truststore.pem"

echo ">> done."
echo " Regenerated fixtures are NOT byte-identical to the committed ones (fresh"
echo " random keys/serials). 'git add' them only if you mean to replace the set."
79 changes: 79 additions & 0 deletions scripts/start_infinispan_mtls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Start Infinispan with mutual TLS on the Hot Rod endpoint (issue #10 integration
# coverage). The endpoint requires a client certificate (require-ssl-client-auth),
# verified against a PEM truststore (test-configs/tls/client-ca.pem).
#
# One script serves two configs, selected by the first argument:
# infinispan-mtls.xml (default) — mutual TLS, NO SASL (MutualTlsIntegrationTest)
# infinispan-external.xml — mutual TLS + SASL EXTERNAL (ExternalAuthIntegrationTest)
#
# Mounts the server PKCS12 identity (server.p12), the client CA PEM truststore
# (client-ca.pem), and the chosen config. Exports the server trust anchor the
# client needs (ca.pem) plus the client cert/key it must present.

set -e

CONFIG_NAME="${1:-infinispan-mtls.xml}"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_DIR="$SCRIPT_DIR/../test-configs"
CONFIG_FILE="$CONFIG_DIR/$CONFIG_NAME"
KEYSTORE_FILE="$CONFIG_DIR/tls/server.p12"
TRUSTSTORE_FILE="$CONFIG_DIR/tls/client-truststore.pem"
CA_FILE="$CONFIG_DIR/tls/ca.pem"
CLIENT_CERT_FILE="$CONFIG_DIR/tls/client.pem"
CLIENT_KEY_FILE="$CONFIG_DIR/tls/client.key"

for f in "$CONFIG_FILE" "$KEYSTORE_FILE" "$TRUSTSTORE_FILE" "$CA_FILE" \
"$CLIENT_CERT_FILE" "$CLIENT_KEY_FILE"; do
if [ ! -f "$f" ]; then
echo "ERROR: Config file not found: $f" >&2
exit 1
fi
done

CONF=/opt/infinispan/server/conf

# Start container with the mutual-TLS config + server keystore + client-CA truststore
# mounted into the conf dir.
# --pull always: :latest is unpinned; refresh so a stale local cache can't run an old server.
CONTAINER_ID=$(docker run -d --pull always \
-p 0:11222 \
-v "$CONFIG_FILE:$CONF/infinispan.xml:ro" \
-v "$KEYSTORE_FILE:$CONF/server.p12:ro" \
-v "$TRUSTSTORE_FILE:$CONF/client-truststore.pem:ro" \
quay.io/infinispan/server:latest)

# Wait for server ready (ISPN080001 = "Infinispan Server started")
echo "Waiting for Infinispan server to start (mutual TLS, config: $CONFIG_NAME)..." >&2
timeout 120 bash -c "
while ! docker logs $CONTAINER_ID 2>&1 | grep -q 'ISPN080001'; do
sleep 1
done
" || {
echo "ERROR: Server failed to start within 120 seconds" >&2
docker logs $CONTAINER_ID >&2
docker rm -f $CONTAINER_ID >&2
exit 1
}

# Get mapped port
HOST=localhost
PORT=$(docker port $CONTAINER_ID 11222 | cut -d: -f2)

if [ -z "$PORT" ]; then
echo "ERROR: Failed to get mapped port" >&2
docker rm -f $CONTAINER_ID >&2
exit 1
fi

# Export for C++ tests (stdout only - for parsing)
echo "export ISPN_CONTAINER_ID=$CONTAINER_ID"
echo "export ISPN_HOST=$HOST"
echo "export ISPN_PORT=$PORT"
echo "export ISPN_TLS=true"
echo "export ISPN_CA_FILE=$CA_FILE"
echo "export ISPN_CLIENT_CERT_FILE=$CLIENT_CERT_FILE"
echo "export ISPN_CLIENT_KEY_FILE=$CLIENT_KEY_FILE"

echo "Server started: $HOST:$PORT (container: $CONTAINER_ID, mutual TLS, config: $CONFIG_NAME)" >&2
Loading
Loading