Skip to content

Commit 6a84e73

Browse files
committed
docs: add TLS session caching documentation
Document the TLS session caching feature in the security guide: - Overview of session resumption benefits - Configuration options (enabled, size, ttl, options) - Advanced configuration with TLSSessionCacheOptions - Custom cache implementation example - Notes on TLS 1.2 vs TLS 1.3 behavior
1 parent b15b788 commit 6a84e73

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

docs/security.rst

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,115 @@ then you can do a proxy execute...
402402
s.execute('select * from k.t;', execute_as='user1') # the request will be executed as 'user1'
403403
404404
Please see the `official documentation <https://docs.datastax.com/en/latest-dse/datastax_enterprise/unifiedAuth/unifiedAuthTOC.html>`_ for more details on the feature and configuration process.
405+
406+
TLS Session Resumption
407+
----------------------
408+
409+
.. versionadded:: 3.30.0
410+
411+
The driver automatically caches TLS sessions to enable session resumption for faster reconnections.
412+
When a TLS connection is established, the session is cached and can be reused for subsequent
413+
connections to the same endpoint, reducing handshake latency and CPU usage.
414+
415+
**TLS Version Support**: Session resumption works with both TLS 1.2 and TLS 1.3. TLS 1.2 uses
416+
Session IDs and optionally Session Tickets (RFC 5077), while TLS 1.3 uses Session Tickets (RFC 8446)
417+
as the primary mechanism. Python's ``ssl.SSLSession`` API handles both versions transparently.
418+
419+
Session caching is **enabled by default** when SSL/TLS is configured and applies to the following
420+
connection classes:
421+
422+
* :class:`~cassandra.io.asyncorereactor.AsyncoreConnection` (default)
423+
* :class:`~cassandra.io.libevreactor.LibevConnection`
424+
* :class:`~cassandra.io.asyncioreactor.AsyncioConnection`
425+
* :class:`~cassandra.io.geventreactor.GeventConnection` (when not using SSL)
426+
427+
.. note::
428+
Session caching is not currently supported for PyOpenSSL-based reactors
429+
(:class:`~cassandra.io.twistedreactor.TwistedConnection`,
430+
:class:`~cassandra.io.eventletreactor.EventletConnection`) but may be added in a future release.
431+
432+
Configuration
433+
^^^^^^^^^^^^^
434+
435+
TLS session caching is controlled by three cluster-level parameters:
436+
437+
* :attr:`~.Cluster.tls_session_cache_enabled` - Enable or disable session caching (default: ``True``)
438+
* :attr:`~.Cluster.tls_session_cache_size` - Maximum number of sessions to cache (default: ``100``)
439+
* :attr:`~.Cluster.tls_session_cache_ttl` - Time-to-live for cached sessions in seconds (default: ``3600``)
440+
441+
Example with default settings (session caching enabled):
442+
443+
.. code-block:: python
444+
445+
from cassandra.cluster import Cluster
446+
import ssl
447+
448+
ssl_context = ssl.create_default_context(cafile='/path/to/ca.crt')
449+
cluster = Cluster(
450+
contact_points=['127.0.0.1'],
451+
ssl_context=ssl_context
452+
)
453+
session = cluster.connect()
454+
455+
Example with custom cache settings:
456+
457+
.. code-block:: python
458+
459+
from cassandra.cluster import Cluster
460+
import ssl
461+
462+
ssl_context = ssl.create_default_context(cafile='/path/to/ca.crt')
463+
cluster = Cluster(
464+
contact_points=['127.0.0.1'],
465+
ssl_context=ssl_context,
466+
tls_session_cache_size=200, # Cache up to 200 sessions
467+
tls_session_cache_ttl=7200 # Sessions expire after 2 hours
468+
)
469+
session = cluster.connect()
470+
471+
Example with session caching disabled:
472+
473+
.. code-block:: python
474+
475+
from cassandra.cluster import Cluster
476+
import ssl
477+
478+
ssl_context = ssl.create_default_context(cafile='/path/to/ca.crt')
479+
cluster = Cluster(
480+
contact_points=['127.0.0.1'],
481+
ssl_context=ssl_context,
482+
tls_session_cache_enabled=False
483+
)
484+
session = cluster.connect()
485+
486+
How It Works
487+
^^^^^^^^^^^^
488+
489+
When session caching is enabled:
490+
491+
1. The first connection to an endpoint establishes a new TLS session and caches it
492+
2. Subsequent connections to the same endpoint reuse the cached session
493+
3. Sessions are cached per endpoint (host:port combination)
494+
4. Sessions expire after the configured TTL
495+
5. When the cache reaches max size, the least recently used session is evicted
496+
497+
Performance Benefits
498+
^^^^^^^^^^^^^^^^^^^^
499+
500+
TLS session resumption is a standard TLS feature that provides performance benefits:
501+
502+
* **Faster reconnection times** - Reduced handshake latency by reusing cached sessions
503+
* **Lower CPU usage** - Fewer cryptographic operations during reconnection
504+
* **Better overall throughput** - Especially beneficial for workloads with frequent reconnections
505+
506+
The actual performance improvement depends on various factors including network latency,
507+
server configuration, and workload characteristics.
508+
509+
Security Considerations
510+
^^^^^^^^^^^^^^^^^^^^^^^
511+
512+
* Sessions are stored in memory only and never persisted to disk
513+
* Sessions are cached per cluster and not shared across different cluster instances
514+
* Sessions for one endpoint are never used for a different endpoint
515+
* Hostname verification still occurs on each connection, even when reusing sessions
516+
* Sessions automatically expire after the configured TTL

0 commit comments

Comments
 (0)