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

feat: add auto-tls service #2798

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: add auto-tls service #2798

wants to merge 5 commits into from

Conversation

achingbrain
Copy link
Member

Adds an optional service that requests a Let's Encrypt-style TLS certificate when publicly dialable addresses are detected.

This will allow transports such as WebSockets to upgrade themselves to be the secure version.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Adds an optional service that requests a Let's Encrypt-style TLS
certificate when publicly dialable addresses are detected.

This will allow transports such as WebSockets to upgrade themselves
to be the secure version.
@achingbrain achingbrain mentioned this pull request Nov 3, 2024
3 tasks
yamux()
],
services: {
autoTLS: autoTLS(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to add identify as per instructions

this.privateKey = components.privateKey
this.peerId = components.peerId
this.events = components.events
this.forgeEndpoint = init.forgeEndpoint ?? 'registration.libp2p.direct'
Copy link
Contributor

@2color 2color Nov 4, 2024

Choose a reason for hiding this comment

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

Endpoint implies a URL with path, no?

Also I'd suggest moving these defaults into a constants file.

Copy link
Member Author

Choose a reason for hiding this comment

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

The path is /v1/_acme-challenge - I omitted the path here to prevent people specifying /v2/_acme-challenge and expecting it to work.

We could make them add https:// on the front if you think it's more intuitive, otherwise I guess we should add a note that the /v1/.. bit will be appended?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah note also works.

const domain = `${base36EncodedPeer}.${this.forgeDomain}`

// Create CSR
const [certificatePrivateKey, csr] = await acmeClient.forge.createCsr({
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for using the legacy forge interface which is deprecated?

Copy link
Member Author

Choose a reason for hiding this comment

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

No reason, just stopped at the first thing that worked. TBH I wanted to use @peculiar/acme-client as we have other @peculiar/... deps in the tree but couldn't get it to work in the time I was looking at it.

altNames: []
})

const accountPrivateKey = await acmeClient.forge.createPrivateKey()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to store the private keys and certificate in the store for renewals and persistence after restarts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't see a "renew"-type operation in the API so I guess not, unless I've missed something.

I do want to add storing the cert/key in the datastore so we can re-use it after a restart as they are quite long-lived.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, there's isn't a a renew operation. It's the same process, except that you can reuse the CSR and account key (IIUC).

// TODO: handle rate limit errors like "too many new registrations (10) from this IP address in the last 3h0m0s, retry after 2024-11-01 09:22:38 UTC: see https://letsencrypt.org/docs/rate-limits/#new-registrations-per-ip-address"

const base36EncodedPeer = base36.encode(this.peerId.toCID().bytes)
const domain = `${base36EncodedPeer}.${this.forgeDomain}`
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to be a wildcard:

Suggested change
const domain = `${base36EncodedPeer}.${this.forgeDomain}`
const domain = `*.${base36EncodedPeer}.${this.forgeDomain}`

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