Giter Site home page Giter Site logo

Comments (11)

Zaba avatar Zaba commented on May 20, 2024 4

I've had to update both the Caddy and the Tailscale dependencies to get this to build and to work (somehow with the old Tailscale version the node would seemingly be connected to the tailnet but no traffic would actually go through).

--- a/go.mod
+++ b/go.mod
@@ -3,8 +3,8 @@ module github.com/tailscale/caddy-tailscale
 go 1.19
 
 require (
-       github.com/caddyserver/caddy/v2 v2.5.3-0.20220831215348-67098e5cbd68
-       tailscale.com v1.1.1-0.20220902232949-3344c3b89bd1
+       github.com/caddyserver/caddy/v2 v2.6.4
+       tailscale.com v1.36.2
 )
 
 require (

(+ many more changes after running go mod tidy)

I've also had to patch the module slightly because the newer version of tsnet verifies the network parameter in Listen. I just hardcoded "tcp", not sure if that's strictly correct but it seemed to work.

--- a/module.go
+++ b/module.go
@@ -46,7 +46,7 @@ func getPlainListener(_ context.Context, network string, addr string, _ net.List
                return nil, err
        }
 
-       return s.Listen(network, ":"+port)
+       return s.Listen("tcp", ":"+port)
 }
 
 func getTLSListener(_ context.Context, network string, addr string, _ net.ListenConfig) (any, error) {
@@ -60,7 +60,7 @@ func getTLSListener(_ context.Context, network string, addr string, _ net.Listen
                return nil, err
        }
 
-       ln, err := s.Listen(network, ":"+port)
+       ln, err := s.Listen("tcp", ":"+port)
        if err != nil {
                return nil, err
        }

Edit: And just for posterity, here's the terrible, no good, very hacky workaround for tailscale/tailscale#6973 that I've added to this module to make it work across restarts of Caddy on Windows:

--- a/module.go
+++ b/module.go
@@ -20,6 +20,10 @@ import (
 	"tailscale.com/client/tailscale"
 	"tailscale.com/tsnet"
 	"tailscale.com/util/strs"
+
+	"path/filepath"
+	"tailscale.com/ipn"
+	"tailscale.com/ipn/store"
 )
 
 var (
@@ -121,6 +125,22 @@ func getServer(_, addr string) (*tsnet.Server, error) {
 			if err := os.MkdirAll(s.Dir, 0700); err != nil {
 				return nil, err
 			}
+
+			stateFile := filepath.Join(s.Dir, "tailscaled.state")
+			log.Printf("attempting to fix state file %s", stateFile)
+			tmpStore, err := store.New(log.Printf, stateFile)
+			if err != nil {
+				log.Printf("could not open store: %v", err)
+			} else {
+				value, err := tmpStore.ReadState(ipn.CurrentProfileStateKey)
+				if err == nil {
+					err := tmpStore.WriteState(ipn.ServerModeStartKey, value)
+					if err != nil {
+						log.Printf("could not fix state file: %v", err)
+					}
+				}
+			}
+
 		}
 
 		servers[host] = s

from caddy-tailscale.

Zaba avatar Zaba commented on May 20, 2024 3

The change to hardcode "tcp" was necessary because the newer versions of tsnet validate the network argument to Listen (see https://github.com/tailscale/tailscale/blob/main/tsnet/tsnet.go#L982), so just passing through "tailscale" or "tailscale+tls" as the original code does no longer works.

Technically it doesn't have to be "tcp" but could also be an empty string or any of the other accepted options, but I have no idea whether and how this value affects anything inside of tsnet and how this does or does not interact with UDP/HTTP3 usage for example, nor do I have time to investigate this in detail, hence I cannot put any of this into a pull request in good faith.

from caddy-tailscale.

willnorris avatar willnorris commented on May 20, 2024 3

#13 has been merged, which I believe addresses most (or all?) of the issues mentioned here. This bumps us to caddy v2.6.4, which @mholt noted fixes the original problem discussed. #13 also includes some other changes which I believe takes care of needing to hardcard a network value of "tcp" as well as the tailscale.com/util/strs issue.

If any of these problems remain after updating to the latest version of caddy-tailscale, feel free to reply here or open a new issue.

from caddy-tailscale.

ericswpark avatar ericswpark commented on May 20, 2024 1

@Zaba if you have the time, could you please submit your code as a pull request? Currently running into the same issue.

from caddy-tailscale.

gbraad avatar gbraad commented on May 20, 2024 1

I applied the changes as originally I also ran into compiling issues with the old dependencies (ref: #9). I have a repo, that works with gitpod at: https://gitpod.io/#https://github.com/spotsnel/caddy-tailscale

the changes in module.go are needed, otherwise it fails to start with:
Error: loading initial config: loading new config: http app module: start: listening on tailscale/caddy:80: unsupported network type

Besides this, it works... although it might be that the templates didn't render correctly?

Any suggestions to remove the hard-coded tcp part? Although, this might well be obsolete from an older version of tailscale. @Zaba Have you tried running with bind tailscale+tls/caddy ?

from caddy-tailscale.

mholt avatar mholt commented on May 20, 2024

It is super cool!

But alas, you have hit a known bug in the go command.

We've figured out, that with Caddy, specifying the version of v2.6.3 or higher (v2.6.4 is current) fixes it. The plugin can do that in its go.mod or you can manually create a replacement in your own go.mod.

from caddy-tailscale.

kernelb00t avatar kernelb00t commented on May 20, 2024

Hey ! Running into same issue here !
Here are some logs, if they are some kind of useful :

2023/06/15 21:00:24 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v
2023/06/15 21:00:28 [INFO] Build environment ready
2023/06/15 21:00:28 [INFO] Building Caddy
2023/06/15 21:00:28 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod tidy -e
go: finding module for package golang.org/x/crypto/internal/subtle
caddy imports
        github.com/tailscale/caddy-tailscale imports
        tailscale.com/tsnet imports
        tailscale.com/ipn/ipnlocal imports
        github.com/tailscale/golang-x-crypto/ssh imports
        github.com/tailscale/golang-x-crypto/chacha20 imports
        github.com/tailscale/golang-x-crypto/internal/subtle tested by
        github.com/tailscale/golang-x-crypto/internal/subtle.test imports
        golang.org/x/crypto/internal/subtle: module golang.org/x/crypto@latest found (v0.10.0), but does not contain package golang.org/x/crypto/internal/subtle
2023/06/15 21:00:28 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go build -o /home/pi/temp/caddy -ldflags -w -s -trimpath
package caddy
        imports github.com/tailscale/caddy-tailscale
        imports tailscale.com/tsnet
        imports tailscale.com/ipn/ipnlocal
        imports tailscale.com/net/dns
        imports tailscale.com/net/tstun
        imports gvisor.dev/gvisor/pkg/tcpip
        imports gvisor.dev/gvisor/pkg/atomicbitops
        imports gvisor.dev/gvisor/pkg/cpuid
        imports gvisor.dev/gvisor/pkg/state
        imports gvisor.dev/gvisor/pkg/state/wire
        imports gvisor.dev/gvisor/pkg/gohacks: build constraints exclude all Go files in /home/pi/go/pkg/mod/gvisor.dev/[email protected]/pkg/gohacks
2023/06/15 21:00:29 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-06-15-2100.2723375457
2023/06/15 21:00:29 [FATAL] exit status 1
pi@john:~/temp $ go version
go version go1.20.5 linux/arm64

I'm on Raspberry Pi 4GB, running latest Go and xcaddy, Raspberry Pi OS based on Debian 11.
Caddy itself is building correctly, but not with this module.

from caddy-tailscale.

kernelb00t avatar kernelb00t commented on May 20, 2024

Oh, I didn't realised it wasn't the same issue
But it did happen the first time I tried to build

EDIT : OP's issue happened for me the first 2 times I tried to build, nothing changed between retrys (no updates, etc...). Then it showed me the error of my previous comment.

from caddy-tailscale.

vamega avatar vamega commented on May 20, 2024

@fr3nchalp4a I ran into that issue as well.
Manually patched the value in go.mod to use the value from tailscale/tailscale#6168

I'm still running into some issues, but am getting closer.

caddy imports
        github.com/tailscale/caddy-tailscale imports
        tailscale.com/util/strs: cannot find module providing package tailscale.com/util/strs
caddy imports
        github.com/caddyserver/caddy/v2/modules/standard imports
        github.com/caddyserver/caddy/v2/modules/caddypki/acmeserver imports
        github.com/smallstep/certificates/acme imports
        github.com/smallstep/go-attestation/attest imports
        github.com/google/go-tpm/tpm2/credactivation: cannot find module providing package github.com/google/go-tpm/tpm2/credactivation

The first error is due to this commit.

I'm going to need to learn some go to tackle this, it seems like mashing commands I don't understand isn't going to get me to power through the dependency hell that my chosen set of plugins seems to create.

xcaddy does panic with the exception that started this thread.

> xcaddy version
v0.3.4

> xcaddy build --with github.com/tailscale/caddy-tailscale --with github.com/caddyserver/caddy/v2/modules/standard --with github.com/caddy-dns/cloudflare --with github.com/lum8rjack/caddy-maxmind-geolocation

[ Snipped ]go: downloading github.com/jackc/pgproto3/v2 v2.3.1
go: downloading github.com/golang/glog v1.0.0
panic: internal error: can't find reason for requirement on github.com/google/[email protected]

goroutine 1 [running]:
cmd/go/internal/modget.(*resolver).updateBuildList.func1({{0xc001605e90, 0x17}, {0xc000034660, 0x22}})
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/internal/modget/get.go:1760 +0xd4
cmd/go/internal/modget.(*resolver).updateBuildList(0xc00013e000, {0xb45e38, 0xc000032240}, {0x0, 0x0, 0x0})
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/internal/modget/get.go:1765 +0x54c
cmd/go/internal/modget.(*resolver).applyUpgrades(0xc00013e000, {0xb45e38, 0xc000032240}, {0x0?, 0x0, 0xc0000bfd70?})
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/internal/modget/get.go:1312 +0x465
cmd/go/internal/modget.runGet({0xb45e38, 0xc000032240}, 0xc00002e660?, {0xc000024220, 0x2, 0x2})
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/internal/modget/get.go:351 +0x458
main.invoke(0xe67340, {0xc0000241f0, 0x5, 0x5})
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/main.go:225 +0x3d9
main.main()
        /nix/store/i3ab37h47xmd0zh75708gj57hah7v7f4-go-1.20.5/share/go/src/cmd/go/main.go:179 +0x7ce
2023/07/14 19:53:48 [FATAL] exit status 2

from caddy-tailscale.

vamega avatar vamega commented on May 20, 2024

I was able to get this to build by replacing the the tailscale-caddy module with the contents on #13.

 go mod edit --replace github.com/tailscale/caddy-tailscale=github.com/trea/caddy-tailscale@network-listener-changes

from caddy-tailscale.

mholt avatar mholt commented on May 20, 2024

Yayyyy thanks Will!

from caddy-tailscale.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.