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

fix(client): wait for public reachability before registering #4

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions client/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"github.com/libp2p/go-libp2p/core/network"
"io"
"net/http"
"strings"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/caddyserver/certmagic"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p/config"
"github.com/libp2p/go-libp2p/core/event"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/mholt/acmez/v2"
Expand Down Expand Up @@ -407,6 +409,25 @@ func (d *dns01P2PForgeSolver) Wait(ctx context.Context, challenge acme.Challenge
func (d *dns01P2PForgeSolver) Present(ctx context.Context, challenge acme.Challenge) error {
h := d.hostFn()
addrs := h.Addrs()

if !d.allowPrivateForgeAddresses {
Copy link
Contributor

@lidel lidel Nov 5, 2024

Choose a reason for hiding this comment

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

@aschmahmann doing this in Present is too late, it is called in the middle of the ACME dance, and we want to avoid the entire ACME flow if we are not publicly reachable.

Pushed 5157ed9 which is tackling problem at a higher level: it is delaying calling ManageAsync for respective domain/cert in the top level func (m *P2PForgeCertMgr) Start() error, and the delay occurs only when necessary (no cert cached), and does not occur when you already have a cert.

It seems to do the trick for my Kubo setup (ipv4-only, NAT + port forwarding with uPnP) and also gives us framework for plugging up more nuanced checks if needed (right now it just waits for network.ReachabilityPublic).

Thoughts? Ok to remove this check from Present? (feels too late / redundant)

Copy link
Contributor

@lidel lidel Nov 5, 2024

Choose a reason for hiding this comment

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

Pushed further refactor in d638643 which extracts connectivity checks to separate reusable func withHostConnectivity.

Also filled #7 to tackle IPv6 separately.

sub, err := h.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged))
if err != nil {
return err
}

defer sub.Close()
select {
case e := <-sub.Out():
evt := e.(event.EvtLocalReachabilityChanged) // guaranteed safe
if evt.Reachability != network.ReachabilityPublic {
return fmt.Errorf("reachability status is not yet public, but is %s", evt.Reachability)
}
case <-ctx.Done():
return fmt.Errorf("reachability status has not yet been discovered: %w", ctx.Err())
}
}

var advertisedAddrs []multiaddr.Multiaddr

if !d.allowPrivateForgeAddresses {
Expand Down
Loading