Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: Remove TLSContext #15030

Merged
merged 1 commit into from
Jan 16, 2025
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
3 changes: 1 addition & 2 deletions pdns/dnsdistdist/dnsdist-console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ static const std::vector<dnsdist::console::ConsoleKeyword> s_consoleKeywords
{"getTopRules", true, "[top]", "return the `top` rules"},
{"getTopSelfAnsweredResponseRules", true, "[top]", "return the `top` self-answered response rules"},
{"getTopXFRResponseRules", true, "[top]", "return the `top` XFR response rules"},
{"getTLSContext", true, "n", "returns the TLS context with index n"},
{"getTLSFrontend", true, "n", "returns the TLS frontend with index n"},
{"getTLSFrontendCount", true, "", "returns the number of DoT listeners"},
{"getVerbose", true, "", "get whether log messages at the verbose level will be logged"},
Expand Down Expand Up @@ -796,8 +795,8 @@ static const std::vector<dnsdist::console::ConsoleKeyword> s_consoleKeywords
{"showServerPolicy", true, "", "show name of currently operational server selection policy"},
{"showServers", true, "[{showUUIDs=false}]", "output all servers, optionally with their UUIDs"},
{"showTCPStats", true, "", "show some statistics regarding TCP"},
{"showTLSContexts", true, "", "list all the available TLS contexts"},
{"showTLSErrorCounters", true, "", "show metrics about TLS handshake failures"},
{"showTLSFrontends", true, "", "list all the available TLS contexts"},
{"showVersion", true, "", "show the current version"},
{"showWebserverConfig", true, "", "Show the current webserver configuration"},
{"shutdown", true, "", "shut down `dnsdist`"},
Expand Down
38 changes: 1 addition & 37 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
#endif
});

luaCtx.writeFunction("showTLSContexts", []() {
luaCtx.writeFunction("showTLSFrontends", []() {
#ifdef HAVE_DNS_OVER_TLS
setLuaNoSideEffect();
try {
Expand All @@ -3171,30 +3171,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
#endif
});

luaCtx.writeFunction("getTLSContext", [](uint64_t index) {
std::shared_ptr<TLSCtx> result = nullptr;
#ifdef HAVE_DNS_OVER_TLS
setLuaNoSideEffect();
const auto tlsFrontends = dnsdist::getDoTFrontends();
try {
if (index < tlsFrontends.size()) {
result = tlsFrontends.at(index)->getContext();
}
else {
errlog("Error: trying to get TLS context with index %d but we only have %d context(s)\n", index, tlsFrontends.size());
g_outputBuffer = "Error: trying to get TLS context with index " + std::to_string(index) + " but we only have " + std::to_string(tlsFrontends.size()) + " context(s)\n";
}
}
catch (const std::exception& e) {
g_outputBuffer = "Error while trying to get TLS context with index " + std::to_string(index) + ": " + string(e.what()) + "\n";
errlog("Error while trying to get TLS context with index %d: %s\n", index, string(e.what()));
}
#else
g_outputBuffer="DNS over TLS support is not present!\n";
#endif
return result;
});

luaCtx.writeFunction("getTLSFrontend", [](uint64_t index) {
std::shared_ptr<TLSFrontend> result = nullptr;
#ifdef HAVE_DNS_OVER_TLS
Expand Down Expand Up @@ -3224,18 +3200,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
return dnsdist::getDoTFrontends().size();
});

luaCtx.registerFunction<void (std::shared_ptr<TLSCtx>::*)()>("rotateTicketsKey", [](std::shared_ptr<TLSCtx>& ctx) {
if (ctx != nullptr) {
ctx->rotateTicketsKey(time(nullptr));
}
});

luaCtx.registerFunction<void (std::shared_ptr<TLSCtx>::*)(const std::string&)>("loadTicketsKeys", [](std::shared_ptr<TLSCtx>& ctx, const std::string& file) {
if (ctx != nullptr) {
ctx->loadTicketsKeys(file);
}
});

luaCtx.registerFunction<std::string (std::shared_ptr<TLSFrontend>::*)() const>("getAddressAndPort", [](const std::shared_ptr<TLSFrontend>& frontend) {
if (frontend == nullptr) {
return std::string();
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdistdist/docs/advanced/tls-sessions-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ By default, dnsdist will generate a new, random STEK at startup for each :func:`
When the automatic rotation mechanism kicks in a new, random key will be added to the list of keys. With the OpenSSL provider, the new key becomes active, so new tickets will be encrypted with this key, and the existing keys become passive and only be used to decrypt existing tickets. With the GnuTLS provider only one key is currently supported so the existing keys are immediately discarded.
This automatic rotation can be disabled by setting ``ticketsKeysRotationDelay`` to 0.

It is also possible to manually request a STEK rotation using the :func:`getDOHFrontend` (DoH) and :func:`getTLSContext` (DoT) functions to retrieve the bind object, and calling its ``rotateTicketsKey`` method (:meth:`DOHFrontend:rotateTicketsKey`, :meth:`TLSContext:rotateTicketsKey`).
It is also possible to manually request a STEK rotation using the :func:`getDOHFrontend` (DoH) and :func:`getTLSFrontend` (DoT) functions to retrieve the bind object, and calling its ``rotateTicketsKey`` method (:meth:`DOHFrontend:rotateTicketsKey`, :meth:`TLSFrontend:rotateTicketsKey`).

The default settings should be fine for most deployments, but generating a random key for every dnsdist instance will not allow resuming the session from a different instance in a cluster. It is also not very useful to have a different key for every :func:`addTLSLocal` and :func:`addDOHLocal` directive if you are using the same certificate and key, and it would be much better to use the same STEK to improve the session resumption ratio.

Expand All @@ -53,7 +53,7 @@ The file can then be loaded at startup by using the ``ticketKeyFile`` parameter
If the file contains several keys, so for example 240 random bytes, dnsdist will load several STEKs, using the last one for encrypting new tickets and all of them to decrypt existing tickets.

In order to rotate the keys at runtime, it is possible to instruct dnsdist to reload the content of the certificates, keys, and STEKs from the same file used at configuration time, for all DoH and DoH binds, by issuing the :func:`reloadAllCertificates` command.
It can also be done one bind at a time using the :func:`getDOHFrontend` (DoH) and :func:`getTLSContext` (DoT) functions to retrieve the bind object, and calling its ``loadTicketsKeys`` method (:meth:`DOHFrontend:loadTicketsKeys`, :meth:`TLSContext:loadTicketsKeys`).
It can also be done one bind at a time using the :func:`getDOHFrontend` (DoH) and :func:`getTLSFrontend` (DoT) functions to retrieve the bind object, and calling its ``loadTicketsKeys`` method (:meth:`DOHFrontend:loadTicketsKeys`, :meth:`TLSFrontend:loadTicketsKeys`).

One possible way of handling manual rotation of the key would be to first:

Expand Down
20 changes: 19 additions & 1 deletion pdns/dnsdistdist/docs/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,9 @@ Status, Statistics and More

.. function:: getTLSContext(idx)

.. versionchanged:: 2.0.0
This directive was removed in version 2.0.0, see :func:`getTLSFrontend` instead.

Return the TLSContext object for the context of index ``idx``.

.. function:: getTLSFrontend(idx)
Expand Down Expand Up @@ -1424,14 +1427,26 @@ Status, Statistics and More

.. function:: showTLSContexts()

Print the list of all available DNS over TLS contexts.
.. versionchanged:: 2.0.0
This function has been renamed to :func:`showTLSFrontends`.

Print the list of all available DNS over TLS frontends.

.. function:: showTLSErrorCounters()

.. versionadded:: 1.4.0

Display metrics about TLS handshake failures.

.. function:: showTLSContexts()

.. versionadded:: 2.0.0

.. note::
Before 2.0.0 this function was called ``showTLSContexts``.

Print the list of all available DNS over TLS frontends.

.. function:: showVersion()

Print the version of dnsdist
Expand Down Expand Up @@ -2509,6 +2524,9 @@ TLSContext

.. class:: TLSContext

.. versionchanged:: 2.0.0
This class has been removed in version 2.0.0.

This object represents an address and port dnsdist is listening on for DNS over TLS queries.

.. method:: TLSContext:loadTicketsKeys(ticketsKeysFile)
Expand Down
6 changes: 6 additions & 0 deletions pdns/dnsdistdist/docs/upgrade_guide.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Upgrade Guide
=============

1.9.x to 2.0.0
--------------

:func:`showTLSContexts` has been renamed to :func:`showTLSFrontends`.
:func:`getTLSContext` and the associated :class:`TLSContext` have been removed, please use :func:`getTLSFrontend` and the associated :class:`TLSFrontend` instead.

1.8.x to 1.9.0
--------------

Expand Down
22 changes: 11 additions & 11 deletions regression-tests.dnsdist/test_TLSSessionResumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@ def testSessionResumption(self):

# rotate the TLS session ticket keys several times, but keep the previously active one around so we can resume
for _ in range(self._numberOfKeys - 1):
self.sendConsoleCommand("getTLSContext(0):rotateTicketsKey()")
self.sendConsoleCommand("getTLSFrontend(0):rotateTicketsKey()")

# the session should be resumed and a new ticket, encrypted with the newly active key, should be stored
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot'))

# rotate the TLS session ticket keys several times, but keep the previously active one around so we can resume
for _ in range(self._numberOfKeys - 1):
self.sendConsoleCommand("getTLSContext(0):rotateTicketsKey()")
self.sendConsoleCommand("getTLSFrontend(0):rotateTicketsKey()")

self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot'))

# rotate the TLS session ticket keys several times, not keeping any key around this time!
for _ in range(self._numberOfKeys):
self.sendConsoleCommand("getTLSContext(0):rotateTicketsKey()")
self.sendConsoleCommand("getTLSFrontend(0):rotateTicketsKey()")

# we should not be able to resume
self.assertFalse(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot'))
Expand All @@ -252,26 +252,26 @@ def testSessionResumption(self):
self.generateTicketKeysFile(self._numberOfKeys, '/tmp/ticketKeys.1')
self.generateTicketKeysFile(self._numberOfKeys - 1, '/tmp/ticketKeys.2')
# load all ticket keys from the file
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.1')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.1')")

# create a new session, resume it
self.assertFalse(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', None))
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot', allowNoTicket=True))

# reload the same keys
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.1')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.1')")

# should still be able to resume
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot', allowNoTicket=True))

# rotate the TLS session ticket keys several times, but keep the previously active one around so we can resume
for _ in range(self._numberOfKeys - 1):
self.sendConsoleCommand("getTLSContext(0):rotateTicketsKey()")
self.sendConsoleCommand("getTLSFrontend(0):rotateTicketsKey()")
# should still be able to resume
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot'))

# reload the same keys
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.1')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.1')")
# since the last key was only present in memory, we should not be able to resume
self.assertFalse(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot'))

Expand All @@ -280,20 +280,20 @@ def testSessionResumption(self):

# generate a file with only _numberOfKeys - 1 keys, so the last active one should still be around after loading that one
self.generateTicketKeysFile(self._numberOfKeys - 1, '/tmp/ticketKeys.2')
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.2')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.2')")
# we should be able to resume, and the ticket should be re-encrypted with the new key (NOTE THAT we store into a new file!!)
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot.2', '/tmp/session.dot'))
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot.2', '/tmp/session.dot.2', allowNoTicket=True))

# rotate all keys, we should not be able to resume
for _ in range(self._numberOfKeys):
self.sendConsoleCommand("getTLSContext(0):rotateTicketsKey()")
self.sendConsoleCommand("getTLSFrontend(0):rotateTicketsKey()")
self.assertFalse(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot.3', '/tmp/session.dot.2'))

# reload from file 1, the old session should resume
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.1')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.1')")
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot', '/tmp/session.dot', allowNoTicket=True))

# reload from file 2, the latest session should resume
self.sendConsoleCommand("getTLSContext(0):loadTicketsKeys('/tmp/ticketKeys.2')")
self.sendConsoleCommand("getTLSFrontend(0):loadTicketsKeys('/tmp/ticketKeys.2')")
self.assertTrue(self.checkSessionResumed('127.0.0.1', self._tlsServerPort, self._serverName, self._caCert, '/tmp/session.dot.2', '/tmp/session.dot.2', allowNoTicket=True))
Loading