-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support client verify for derp (add integration tests) (#2046)
* feat: support client verify for derp * docs: fix doc for integration test * tests: add integration test for DERP verify endpoint * tests: use `tailcfg.DERPMap` instead of `[]byte` * refactor: introduce func `ContainsNodeKey` * tests(dsic): use string builder for cmd args * ci: fix tests order * tests: fix derper failure * chore: cleanup * tests(verify-client): perfer to use `CreateHeadscaleEnv` * refactor(verify-client): simplify error handling * tests: fix `TestDERPVerifyEndpoint` * refactor: make `doVerify` a seperated func --------- Co-authored-by: 117503445 <[email protected]>
- Loading branch information
1 parent
c6336ad
commit edf9e25
Showing
14 changed files
with
735 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# For testing purposes only | ||
|
||
FROM golang:alpine AS build-env | ||
|
||
WORKDIR /go/src | ||
|
||
RUN apk add --no-cache git | ||
ARG VERSION_BRANCH=main | ||
RUN git clone https://github.com/tailscale/tailscale.git --branch=$VERSION_BRANCH --depth=1 | ||
WORKDIR /go/src/tailscale | ||
|
||
ARG TARGETARCH | ||
RUN GOARCH=$TARGETARCH go install -v ./cmd/derper | ||
|
||
FROM alpine:3.18 | ||
RUN apk add --no-cache ca-certificates iptables iproute2 ip6tables curl | ||
|
||
COPY --from=build-env /go/bin/* /usr/local/bin/ | ||
ENTRYPOINT [ "/usr/local/bin/derper" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package integration | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/juanfont/headscale/hscontrol/util" | ||
"github.com/juanfont/headscale/integration/dsic" | ||
"github.com/juanfont/headscale/integration/hsic" | ||
"github.com/juanfont/headscale/integration/integrationutil" | ||
"github.com/juanfont/headscale/integration/tsic" | ||
"tailscale.com/tailcfg" | ||
) | ||
|
||
func TestDERPVerifyEndpoint(t *testing.T) { | ||
IntegrationSkip(t) | ||
|
||
// Generate random hostname for the headscale instance | ||
hash, err := util.GenerateRandomStringDNSSafe(6) | ||
assertNoErr(t, err) | ||
testName := "derpverify" | ||
hostname := fmt.Sprintf("hs-%s-%s", testName, hash) | ||
|
||
headscalePort := 8080 | ||
|
||
// Create cert for headscale | ||
certHeadscale, keyHeadscale, err := integrationutil.CreateCertificate(hostname) | ||
assertNoErr(t, err) | ||
|
||
scenario, err := NewScenario(dockertestMaxWait()) | ||
assertNoErr(t, err) | ||
defer scenario.ShutdownAssertNoPanics(t) | ||
|
||
spec := map[string]int{ | ||
"user1": len(MustTestVersions), | ||
} | ||
|
||
derper, err := scenario.CreateDERPServer("head", | ||
dsic.WithCACert(certHeadscale), | ||
dsic.WithVerifyClientURL(fmt.Sprintf("https://%s/verify", net.JoinHostPort(hostname, strconv.Itoa(headscalePort)))), | ||
) | ||
assertNoErr(t, err) | ||
|
||
derpMap := tailcfg.DERPMap{ | ||
Regions: map[int]*tailcfg.DERPRegion{ | ||
900: { | ||
RegionID: 900, | ||
RegionCode: "test-derpverify", | ||
RegionName: "TestDerpVerify", | ||
Nodes: []*tailcfg.DERPNode{ | ||
{ | ||
Name: "TestDerpVerify", | ||
RegionID: 900, | ||
HostName: derper.GetHostname(), | ||
STUNPort: derper.GetSTUNPort(), | ||
STUNOnly: false, | ||
DERPPort: derper.GetDERPPort(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err = scenario.CreateHeadscaleEnv(spec, []tsic.Option{tsic.WithCACert(derper.GetCert())}, | ||
hsic.WithHostname(hostname), | ||
hsic.WithPort(headscalePort), | ||
hsic.WithCustomTLS(certHeadscale, keyHeadscale), | ||
hsic.WithHostnameAsServerURL(), | ||
hsic.WithDERPConfig(derpMap)) | ||
assertNoErrHeadscaleEnv(t, err) | ||
|
||
allClients, err := scenario.ListTailscaleClients() | ||
assertNoErrListClients(t, err) | ||
|
||
for _, client := range allClients { | ||
report, err := client.DebugDERPRegion("test-derpverify") | ||
assertNoErr(t, err) | ||
successful := false | ||
for _, line := range report.Info { | ||
if strings.Contains(line, "Successfully established a DERP connection with node") { | ||
successful = true | ||
|
||
break | ||
} | ||
} | ||
if !successful { | ||
stJSON, err := json.Marshal(report) | ||
assertNoErr(t, err) | ||
t.Errorf("Client %s could not establish a DERP connection: %s", client.Hostname(), string(stJSON)) | ||
} | ||
} | ||
} |
Oops, something went wrong.