Skip to content

feat(ssl): take over the session ticket keys of marked servers - #133

Draft
membphis wants to merge 1 commit into
mainfrom
feat/ssl-session-ticket-takeover
Draft

membphis wants to merge 1 commit into
mainfrom
feat/ssl-session-ticket-takeover

Conversation

@membphis

@membphis membphis commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

A server marked with the new apisix_ssl_session_ticket_takeover directive, in http or in stream, hands the TLS session ticket keys of its SSL_CTX over to Lua. The context then encrypts and decrypts tickets with a complete, ordered set of keys installed through the new resty.apisix.ssl_session_ticket module: the first key issues tickets, every key decrypts. Servers of several nodes that install the same set resume each other's sessions, over TLSv1.2 and TLSv1.3.

Servers that are not marked keep the native behavior, including the keys nginx rotates in an ssl_session_cache they share with a marked server (the Admin API shares shared:SSL with the data plane in APISIX).

resty.apisix.process also gets the configuration generation of the process and an identity with a slot bounded per generation, so per-process records can be keyed across reloads without the pid.

How

  • Patch patch/1.31.1.1/nginx-ssl_session_ticket_takeover.patch: both the http and the stream SSL merge paths bind the server's mark to the SSL_CTX they just created, right before ngx_ssl_session_ticket_keys(); that function registers the module's callback for a marked context before the return it takes when there is neither ssl_session_ticket_key nor a shared session cache, which is the stream default. Unmarked contexts keep the native path untouched.
  • Directive: only allowed in server{}, so a mark is never inherited from http{} / stream{}; each stream server is marked on its own. It cannot be combined with ssl_session_ticket_key.
  • Starts off: a marked context gets SSL_OP_NO_TICKET whatever ssl_session_tickets says. Tickets only go on through the API, with a complete set installed; a failed registration keeps the context off. The callback refuses the keys whenever the context is off or has none (decrypt returns 0: a full handshake; encrypt returns 0: an empty ticket in TLSv1.2, none in TLSv1.3), so it never falls back to keys OpenSSL makes up. Renewal follows nginx: always in TLSv1.3, else for a non-default key. The return values were checked against the OpenSSL 3.5.9 sources.
  • Registration check: OpenSSL has no getter for the ticket callback, so the successful registration leaves a record of the context and of the configuration generation in the module's own SSL_CTX ex_data; contexts() reports whether it verifies, and keys cannot be installed nor tickets turned on otherwise.
  • Key sets are replaced as a whole (the callback only ever sees the old or the new complete set), wiped when replaced or revoked, 1 to 256 keys of 80 bytes in the nginx layout, unique names.
  • Connection options: SSL_new() copies the options of the context at accept, so sync_connection() aligns SSL_OP_NO_TICKET of the current connection with its context, meant for ssl_client_hello_by_lua*.
  • Safe order: on = set_keys() then enable_tickets(); off = disable_tickets() then revoke_keys(). Nothing closes a connection, and num_tickets is never touched: when off, TLSv1.3 still sends its stateful tickets.
  • Version lock: with the patch applied on any nginx but 1.31.1, the module fails to compile (#error), rather than relying on the patch failing to apply. Other bundles, such as the api7ee-runtime one, build as before: the directive only warns and the API reports not_supported.

The directive and both Lua APIs are documented in the README.

Tests

New Test::Nginx files, which only run on OpenResty 1.31.1 (the only bundle with the patch) and skip elsewhere:

  • t/ssl-session-ticket.t (http) and t/stream/ssl-session-ticket.t (stream, servers without a session cache): real resumption between two contexts standing for two nodes, checked with $ssl_session_reused and the key name in the client's ticket; first key issues, older keys decrypt, reorder, removal; 0 -> n -> 0 with an open connection; callback results 1, renew, 0 and negative; a context turned off mid-handshake; connection alignment when the client hello is delayed; unmarked servers keep the native keys; off semantics per protocol; directive placement and API errors.
  • t/ssl-session-ticket-unregistered.t: a failed callback registration is visible and keeps the context off.
  • t/ssl-session-ticket-reload.t: the generation moves on with a reload, with the registrations; worker and privileged agent identities.
  • t/process.t: generation and identity of a single process.

The negative callback results and the failed registration cannot be caused from outside: builds --with-debug (as in CI) let the tests provoke them through environment variables; other builds do not contain that code.

Local verification: an apisix-runtime built with this branch and the CI compiler flags (-fsanitize=address -Werror, OpenResty 1.31.1.1, OpenSSL 3.5.9) passes every t/ file run by the apisix-runtime CI jobs, t/gm.t skipping without Tongsuo as in CI. OpenResty 1.21.4.4 with this branch (no takeover patch) also builds with the same flags and reports the takeover as not supported. luacheck was not run locally.

Draft: the Lua API is still being reviewed before this is marked ready.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

A server marked with apisix_ssl_session_ticket_takeover, in http or in
stream, hands the session ticket keys of its SSL_CTX over to Lua: the
context encrypts and decrypts tickets with a complete, ordered set of
keys installed through resty.apisix.ssl_session_ticket, the first key
issuing and every key decrypting, so that the servers of several nodes
that install the same set resume each other's sessions. Servers that are
not marked, the Admin API among them, keep the native keys, including
those nginx rotates in a session cache they share with a marked server.

- patch/1.31.1.1: both SSL merge paths bind the mark to the new SSL_CTX,
  and ngx_ssl_session_ticket_keys() registers the module's callback for a
  marked context before the return it takes without a shared session
  cache, the stream default
- a marked context starts with SSL_OP_NO_TICKET whatever
  ssl_session_tickets says, tickets only go on with a complete set, and
  the callback refuses the keys once the context is off or has none:
  never a fallback to keys of OpenSSL's own
- the registration leaves a record of the context and of the
  configuration generation in the SSL_CTX ex_data, which the FFI checks,
  as OpenSSL has no getter for the callback
- sync_connection() aligns the options a connection copied at accept
  with its context, from ssl_client_hello_by_lua*
- resty.apisix.process gets the configuration generation of the process
  and an identity with a slot bounded per generation, to key per-process
  records across reloads without the pid
- the takeover is locked to nginx 1.31.1 at compile time; the other
  bundles build without it and report it as not supported

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant