Handle non-Tailnet connections
This commit is contained in:
parent
871b191fb9
commit
d9027601f9
1 changed files with 4 additions and 0 deletions
|
@ -2,6 +2,7 @@ package caddy_tailscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -45,6 +46,9 @@ func (ta *TailscaleAuth) Authenticate(_ http.ResponseWriter, req *http.Request)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
whois, err := ta.lc.WhoIs(ctx, req.RemoteAddr)
|
whois, err := ta.lc.WhoIs(ctx, req.RemoteAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, tailscale.ErrPeerNotFound) { // happens when a non-tailnet IP is tested, eg. from the wider internet
|
||||||
|
return caddyauth.User{}, false, nil
|
||||||
|
}
|
||||||
return caddyauth.User{}, false, err
|
return caddyauth.User{}, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue