Skip to content

plugin/tls: Add the keylog option to configure TLSConfig.KeyLogWriter#7537

Merged
thevilledev merged 2 commits into
coredns:masterfrom
Kentzo:tls-keylog
Mar 27, 2026
Merged

plugin/tls: Add the keylog option to configure TLSConfig.KeyLogWriter#7537
thevilledev merged 2 commits into
coredns:masterfrom
Kentzo:tls-keylog

Conversation

@Kentzo

@Kentzo Kentzo commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

1. Why is this pull request needed and what does it do?

In order to debug DNS-over-TLS it's helpful to export TLS master secrets so tools like Wireshark could decrypt traffic.

This PR adds the keylog option to the tls plugin which the user can set. It behaves similarly to the SSLKEYLOGFILE environment variable in other applications.

2. Which issues (if any) are related?

None

3. Which documentation changes (if any) need to be made?

The keylog option should be added to the tls plugin description.

4. Does this introduce a backward incompatible change or deprecation?

No

Comment thread plugin/tls/tls.go Outdated
Comment thread plugin/tls/tls.go
Comment thread plugin/tls/tls.go Outdated
@Kentzo Kentzo changed the title tls: Add the keylog option to configure TLSConfig.KeyLogWriter plugin/tls: Add the keylog option to configure TLSConfig.KeyLogWriter Oct 8, 2025
@Kentzo

Kentzo commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

No interest in this one?

@thevilledev thevilledev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Kentzo, sorry for the delay. I'm catching up with open PRs now. Some comments below.

Comment thread plugin/tls/tls.go Outdated
Comment thread plugin/tls/tls_test.go Outdated
Comment thread plugin/tls/tls_test.go
Comment thread plugin/tls/tls.go Outdated
Comment thread plugin/tls/tls.go
Comment thread plugin/tls/tls.go Outdated
Comment thread plugin/tls/tls_test.go Outdated
@Kentzo Kentzo force-pushed the tls-keylog branch 2 times, most recently from e77ada3 to ed8be22 Compare March 25, 2026 18:27
@thevilledev

Copy link
Copy Markdown
Collaborator

The CircleCI test failure is weird. Can you try to rebase this branch against the latest in master?

Kentzo added 2 commits March 25, 2026 12:30
Signed-off-by: Ilya Kulakov <kulakov.ilya@gmail.com>
Signed-off-by: Ilya Kulakov <kulakov.ilya@gmail.com>
Comment thread plugin/tls/tls.go
return c.Errf("unable to write TLS Key Log to %q: %s", absKeyLog, err)
}
c.OnShutdown(func() error {
f.Close()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thevilledev

Closing the file will cause TLS handshake to fail on connections that still has this config: https://cs.opensource.google/go/go/+/refs/tags/go1.26.1:src/crypto/tls/handshake_server_tls13.go (search for writerKeyLog).

This is fine if we expect OnShutdown to get called after underlying dns.Server is closed and doesn't accept new connections.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On restart/reload, Caddy starts the new instance first (taking over the listeners), then calls Stop() on the old instance to drain, and only then calls OnShutdown.

For SIGTERM/SIGINT, the server is dying anyway. Probably fine for the handshake to fail in a debug tool?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC dns.Server should not accept new connections by the time OnShutdown is called.

OTOH one might say it's fine for an file descriptor to wait for GC event in a debug tool :)

@Kentzo

Kentzo commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

The CircleCI test failure is weird. Can you try to rebase this branch against the latest in master?

I don't have CircleCI as an authorized OAuth App on my GitHub account.

@thevilledev thevilledev merged commit a8caf4c into coredns:master Mar 27, 2026
10 of 11 checks passed
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.

2 participants