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

caddytls: set SNI server name in context #6324

Merged
merged 1 commit into from
May 18, 2024

Conversation

willnorris
Copy link
Contributor

@willnorris willnorris commented May 17, 2024

Set the requested server name in a context value for certmagic.Manager implementations to use. Pass ctx to tscert.GetCertificateWithContext.

This relies on tailscale/tscert#9 to be merged first, which adds the new tscert.GetCertificateWithContext method. This will enable tailscale/caddy-tailscale#53, which enables the use of auto_https with tsnet servers running inside of caddy.

This PR only attaches the server name inside the Tailscale certmagic.Manager. I tried to find the right place to attach it for all managers, but couldn't seem to find it. I'd love some pointers for where to put this.

/cc @mholt

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Looks pretty straightforward -- how about this for a name instead?

Then I think we can merge.

@@ -22,6 +22,9 @@ func init() {
caddy.RegisterModule(HTTPCertGetter{})
}

// For referencing the requested SNI server name.
var SNIServerNameCtxKey caddy.CtxKey = "sni_server_name"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var SNIServerNameCtxKey caddy.CtxKey = "sni_server_name"
const ClientHelloSNICtxKey caddy.CtxKey = "client_hello_sni"

This is potentially bikeshedding but hear me out

Copy link
Member

Choose a reason for hiding this comment

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

I agree; SNIServerName is basically "server name indication server name" 😅 https://en.m.wikipedia.org/wiki/Server_Name_Indication

Copy link
Contributor Author

@willnorris willnorris May 18, 2024

Choose a reason for hiding this comment

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

lol, I didn't even think about what the expanded name would be. Indeed, that sounds pretty silly :) Updated name coming up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Set the requested server name in a context value for CertGetter
implementations to use. Pass ctx to tscert.GetCertificateWithContext.

Signed-off-by: Will Norris <will@tailscale.com>
@francislavoie francislavoie added the feature ⚙️ New feature or request label May 18, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone May 18, 2024
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks!

@mholt mholt merged commit e66040a into caddyserver:master May 18, 2024
23 checks passed
willnorris added a commit to willnorris/caddy that referenced this pull request May 19, 2024
This reverts commit e66040a.

The additional context value is unnecessary because certmagic already
sets certmagic.ClientHelloInfoCtxKey on the same context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants