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

write Caddy module for getting TLS certs from tailscaled #3096

Closed
bradfitz opened this issue Oct 15, 2021 · 3 comments
Closed

write Caddy module for getting TLS certs from tailscaled #3096

bradfitz opened this issue Oct 15, 2021 · 3 comments
Labels
fr Feature request L2 Few Likelihood P1 Nuisance Priority level T0 New feature Issue type

Comments

@bradfitz
Copy link
Member

Tracking bug for writing a Caddy module to get TLS certs from the machine's tailscaled via the localapi. (using https://pkg.go.dev/tailscale.com/client/tailscale#GetCertificate)

@mholt, any pointers on what type of module we'd need to be? Got an example of a similar one?

Grepping around backwards from tls.Config.GetCertificate ....

ConnectionPolicy ...https://caddyserver.com/docs/json/apps/http/servers/tls_connection_policies/

AutomationPolicy .... https://caddyserver.com/docs/json/apps/tls/automation/policies/

"Fulfilled by modules in namespace: tls.issuance"

I guess we want to be one of these? https://caddyserver.com/docs/json/apps/tls/automation/policies/issuers/

So e.g.
https://github.com/caddyserver/caddy/blob/master/modules/caddytls/acmeissuer.go
https://github.com/caddyserver/caddy/blob/master/modules/caddytls/internalissuer.go

Do we really have to do all the CSR stuff? https://pkg.go.dev/github.com/caddyserver/certmagic#Issuer

We already do that, and handle caching for certs that are still valid.

The hook I really want is given the SNI name, choose to give you a cert pair or not.

@DentonGentry DentonGentry added L2 Few Likelihood P1 Nuisance Priority level T0 New feature Issue type fr Feature request labels Oct 15, 2021
@mholt
Copy link

mholt commented Oct 15, 2021

Great questions -- and nice work following the code.

I guess we want to be one of these? https://caddyserver.com/docs/json/apps/tls/automation/policies/issuers/

Yes, exactly!

So yeah, using the ACMEIssuer or InternalIssuer for boilerplate are great starting points.

Do we really have to do all the CSR stuff? https://pkg.go.dev/github.com/caddyserver/certmagic#Issuer

No, the CSR is generated for you. You can just extract whatever info you need to get a cert.

The hook I really want is given the SNI name, choose to give you a cert pair or not.

Yep, so all your issuer module needs to do is look at the Subjects in the CSR and you can decide whether to return a cert or not.


When Caddy is asked to manage a certificate for a domain (or IP address), it will call Issue() on the configured Issuer to get the certificate, which it then saves to storage and loads into its in-memory cache. That in-memory cache is where it draws from to serve certificates during TLS handshakes. Managed certs, which are all the ones that come from an Issuer, are tracked for expiration and Caddy will call Issue() again when time is running out. If Issue() returns certificates that still expire soon, Caddy will just keep trying over time until it gets a certificate that isn't expiring soon.

There is one other module type called a CertificateLoader which simply loads certificates into that in-memory cache, but these are not considered "managed" so the user would have to reload the config in order to re-load them into the cache: https://pkg.go.dev/github.com/caddyserver/caddy/v2/modules/caddytls#CertificateLoader -- but I think Issuer is what you want.

@bradfitz
Copy link
Member Author

Thanks for the tips!

I'm taking next week off but I'll try to get to this whenever I have some "fun" time free. (unless somebody wants to beat me to it! :))

@DentonGentry
Copy link
Contributor

I think this is being done in caddyserver/caddy#4541
Interested parties should subscribe to that issue instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fr Feature request L2 Few Likelihood P1 Nuisance Priority level T0 New feature Issue type
Projects
None yet
Development

No branches or pull requests

3 participants