Skip to content

Latest commit

 

History

History
246 lines (196 loc) · 8.93 KB

security.adoc

File metadata and controls

246 lines (196 loc) · 8.93 KB

Security

Authentication

The client authenticates over SASL. These mechanisms are implemented:

  • SCRAM-SHA-256 — the default when you call setAuthentication(…​).

  • 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

Authentication is configured with a flat setter on RemoteCache, matching the existing setClientIntelligence / setProtocolVersion idiom. Call it before connect():

#include "hotrod/RemoteCache.h"
#include "hotrod/HotRodClientException.h"

using namespace hotrod;

RemoteCache cache("localhost", 11222, "my-cache");

// Username + password are all SCRAM needs. Mechanism defaults to SCRAM-SHA-256.
cache.setAuthentication("username", "password");

try {
    cache.connect();
} catch (const HotRodClientException& e) {
    // Wrong credentials, an unsupported mechanism, or a mechanism the server
    // does not offer all surface here, at connect() time.
    std::cerr << "Authentication failed: " << e.what() << '\n';
    return 1;
}

// Every operation now runs over an authenticated connection.
cache.put(ByteArray{'k'}, ByteArray{'v'}).get();

The full setter signature is:

void setAuthentication(const std::string& username,
                       const std::string& password,
                       const std::string& realm      = "default",
                       const std::string& serverName = "infinispan",
                       const std::string& mechanism  = "SCRAM-SHA-256");

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

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:

#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):

// 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

Parameter Default

mechanism

SCRAM-SHA-256

realm

default

serverName

infinispan

These match the Java client’s AuthenticationConfiguration defaults.

realm and serverName are unused by SCRAM

For the SCRAM mechanisms only username and password enter the exchange. realm and serverName are accepted and stored for parity with the Java client (and for future mechanisms that need them), but the SCRAM handshake does not use them. You can leave them at their defaults.

Credentials apply to every connection

Authentication is a property of the client, not of a single socket. When authentication is enabled, the client runs the SASL handshake (AUTH_MECH_LIST + AUTH) on every connection it opens — the seed connection you named in the constructor and every cluster member the client later discovers through topology updates — before that connection carries any operation. You configure credentials once; the client re-authenticates transparently as it pools new connections during failover and rebalancing.

How the SCRAM handshake works

Per connection, before the read loop starts:

  1. AUTH_MECH_LIST_REQUEST → the client reads the server’s offered mechanisms and verifies the configured one is present (otherwise it throws).

  2. client-first → server-first: the client sends its nonce; the server replies with the combined nonce, salt, and iteration count.

  3. client-final → server-final: the client sends its proof; the server replies with its signature, which the client verifies for mutual authentication.

SCRAM completes on the client side once it has verified the server signature (mirroring the Java client’s AuthHandler): the client sends no confirmation round and does not depend on the server’s completed flag. Infinispan/Elytron sends the server-final with completed=false; sending an extra empty confirmation triggers an Elytron error (ELY05037).

The wire layout was cross-checked against the two authoritative sources: the Java client (AuthHandler / AuthOperation) for behavior and the Kaitai schema hotrod40.ksy for byte layout.

Server configuration

The SCRAM family derives keys from the cleartext password, so the server’s security realm must store passwords in a form SCRAM can use — a properties realm with plain-text="true" is the simplest. A minimal Hot Rod endpoint offering the SCRAM family looks like this (see test-configs/infinispan-auth.xml for the full tested config):

<security-realm name="default">
   <properties-realm groups-attribute="Roles">
      <user-properties path="users.properties" plain-text="true"/>
      <group-properties path="groups.properties"/>
   </properties-realm>
</security-realm>
...
<endpoint socket-binding="default" security-realm="default">
   <hotrod-connector>
      <authentication>
         <sasl mechanisms="SCRAM-SHA-512 SCRAM-SHA-256 SCRAM-SHA-1"
               server-name="infinispan"/>
      </authentication>
   </hotrod-connector>
   <rest-connector/> <!-- single-port endpoint needs a REST route too -->
</endpoint>

TLS / mutual TLS

Transport encryption (TLS/SSL) is supported over OpenSSL. All certificate material is PEM — Java keystore formats (JKS/PKCS12) are not supported.

Enable it with the hotrods:// URI scheme or RemoteCache::setTls(…​); every connection the client opens (the seed connection and every topology-discovered cluster member) is then wrapped in a TLS session (minimum TLS 1.2).

Server-authenticated TLS verifies the server’s certificate chain (always on) and, by default, that the certificate matches the host name:

// URI form (private CA):
auto c = RemoteCache::fromUri("hotrods://cache:11222?ca_file=/etc/pki/ca.pem");

// Programmatic form (empty ca_file = system/default trust store):
RemoteCache cache("cache", 11222);
cache.setTls("/etc/pki/ca.pem");

Mutual TLS additionally presents a client certificate. Supply a PEM client cert chain and its private key (and a passphrase if the key is encrypted):

auto c = RemoteCache::fromUri(
    "hotrods://cache:11222"
    "?ca_file=/etc/pki/ca.pem"
    "&client_cert_file=/etc/pki/client.pem"
    "&client_key_file=/etc/pki/client-key.pem");

// Or programmatically:
TlsConfig tls;
tls.enabled   = true;
tls.ca_file   = "/etc/pki/ca.pem";
tls.cert_file = "/etc/pki/client.pem";
tls.key_file  = "/etc/pki/client-key.pem";
// tls.key_password = "...";  // only if the key is encrypted
cache.setTls(tls);
Table 1. TLS URI query keys
Key Meaning

ca_file

PEM CA bundle to verify the server; empty = system trust store

sni_host_name

SNI server name (skipped for literal IP addresses)

ssl_hostname_validation

true (default) / false — host-name match toggle

client_cert_file

PEM client certificate chain (mutual TLS)

client_key_file

PEM client private key matching client_cert_file

client_key_password

passphrase for an encrypted client_key_file

Note
The Java keystore keys (trust_store_file_name, key_store_file_name, *_store_type/*_store_password, key_alias) are rejected — this client uses PEM. Use ca_file for trust and client_cert_file + client_key_file for the client identity. Protocol/cipher tuning (ssl_protocol, ssl_ciphers, …) is not yet supported (issue #10). See docs/STATUS.md for the current roadmap.