diff --git a/integration/auth_oidc_test.go b/integration/auth_oidc_test.go index d1c4087b..ded10449 100644 --- a/integration/auth_oidc_test.go +++ b/integration/auth_oidc_test.go @@ -91,7 +91,6 @@ func TestOIDCAuthenticationPingAll(t *testing.T) { hsic.WithTestName("oidcauthping"), hsic.WithConfigEnv(oidcMap), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), hsic.WithFileInContainer("/tmp/hs_client_oidc_secret", []byte(oidcConfig.ClientSecret)), ) assertNoErrHeadscaleEnv(t, err) @@ -206,7 +205,6 @@ func TestOIDCExpireNodesBasedOnTokenExpiry(t *testing.T) { spec, hsic.WithTestName("oidcexpirenodes"), hsic.WithConfigEnv(oidcMap), - hsic.WithHostnameAsServerURL(), ) assertNoErrHeadscaleEnv(t, err) @@ -497,7 +495,6 @@ func TestOIDC024UserCreation(t *testing.T) { hsic.WithTestName("oidcmigration"), hsic.WithConfigEnv(oidcMap), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), hsic.WithFileInContainer("/tmp/hs_client_oidc_secret", []byte(oidcConfig.ClientSecret)), ) assertNoErrHeadscaleEnv(t, err) @@ -576,7 +573,6 @@ func TestOIDCAuthenticationWithPKCE(t *testing.T) { hsic.WithTestName("oidcauthpkce"), hsic.WithConfigEnv(oidcMap), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), hsic.WithFileInContainer("/tmp/hs_client_oidc_secret", []byte(oidcConfig.ClientSecret)), ) assertNoErrHeadscaleEnv(t, err) diff --git a/integration/auth_web_flow_test.go b/integration/auth_web_flow_test.go index 86cc8bcd..c9dda617 100644 --- a/integration/auth_web_flow_test.go +++ b/integration/auth_web_flow_test.go @@ -43,7 +43,6 @@ func TestAuthWebFlowAuthenticationPingAll(t *testing.T) { hsic.WithTestName("webauthping"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), ) assertNoErrHeadscaleEnv(t, err) diff --git a/integration/cli_test.go b/integration/cli_test.go index 8d63809c..59d39278 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -545,7 +545,6 @@ func TestPreAuthKeyCorrectUserLoggedInCommand(t *testing.T) { hsic.WithTestName("clipak"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), ) assertNoErr(t, err) diff --git a/integration/derp_verify_endpoint_test.go b/integration/derp_verify_endpoint_test.go index adad5b6a..bc7a0a7d 100644 --- a/integration/derp_verify_endpoint_test.go +++ b/integration/derp_verify_endpoint_test.go @@ -69,7 +69,6 @@ func TestDERPVerifyEndpoint(t *testing.T) { hsic.WithHostname(hostname), hsic.WithPort(headscalePort), hsic.WithCustomTLS(certHeadscale, keyHeadscale), - hsic.WithHostnameAsServerURL(), hsic.WithDERPConfig(derpMap)) assertNoErrHeadscaleEnv(t, err) diff --git a/integration/dns_test.go b/integration/dns_test.go index d1693441..05e272f5 100644 --- a/integration/dns_test.go +++ b/integration/dns_test.go @@ -123,7 +123,6 @@ func TestResolveMagicDNSExtraRecordsPath(t *testing.T) { hsic.WithFileInContainer(erPath, b), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), ) assertNoErrHeadscaleEnv(t, err) diff --git a/integration/embedded_derp_test.go b/integration/embedded_derp_test.go index d5fdb161..e17bbacb 100644 --- a/integration/embedded_derp_test.go +++ b/integration/embedded_derp_test.go @@ -105,7 +105,6 @@ func derpServerScenario( hsic.WithEmbeddedDERPServerOnly(), hsic.WithPort(443), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), hsic.WithConfigEnv(map[string]string{ "HEADSCALE_DERP_AUTO_UPDATE_ENABLED": "true", "HEADSCALE_DERP_UPDATE_FREQUENCY": "10s", diff --git a/integration/general_test.go b/integration/general_test.go index 985c9529..085fc786 100644 --- a/integration/general_test.go +++ b/integration/general_test.go @@ -44,7 +44,6 @@ func TestPingAllByIP(t *testing.T) { hsic.WithTestName("pingallbyip"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), hsic.WithIPAllocationStrategy(types.IPAllocationStrategyRandom), ) assertNoErrHeadscaleEnv(t, err) @@ -127,7 +126,6 @@ func TestAuthKeyLogoutAndRelogin(t *testing.T) { hsic.WithTestName("pingallbyip"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), } } @@ -1050,7 +1048,6 @@ func TestPingAllByIPManyUpDown(t *testing.T) { hsic.WithTestName("pingallbyipmany"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), ) assertNoErrHeadscaleEnv(t, err) @@ -1133,7 +1130,6 @@ func Test2118DeletingOnlineNodePanics(t *testing.T) { hsic.WithTestName("deletenocrash"), hsic.WithEmbeddedDERPServerOnly(), hsic.WithTLS(), - hsic.WithHostnameAsServerURL(), ) assertNoErrHeadscaleEnv(t, err) diff --git a/integration/hsic/config.go b/integration/hsic/config.go index 509052a3..76a5176c 100644 --- a/integration/hsic/config.go +++ b/integration/hsic/config.go @@ -26,9 +26,7 @@ func DefaultConfigEnv() map[string]string { "HEADSCALE_DNS_NAMESERVERS_GLOBAL": "127.0.0.11 1.1.1.1", "HEADSCALE_PRIVATE_KEY_PATH": "/tmp/private.key", "HEADSCALE_NOISE_PRIVATE_KEY_PATH": "/tmp/noise_private.key", - "HEADSCALE_LISTEN_ADDR": "0.0.0.0:8080", "HEADSCALE_METRICS_LISTEN_ADDR": "0.0.0.0:9090", - "HEADSCALE_SERVER_URL": "http://headscale:8080", "HEADSCALE_DERP_URLS": "https://controlplane.tailscale.com/derpmap/default", "HEADSCALE_DERP_AUTO_UPDATE_ENABLED": "false", "HEADSCALE_DERP_UPDATE_FREQUENCY": "1m", diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 883fc8bc..e38abd1c 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -7,9 +7,7 @@ import ( "fmt" "io" "log" - "net" "net/http" - "net/url" "os" "path" "strconv" @@ -166,17 +164,6 @@ func WithHostname(hostname string) Option { } } -// WithHostnameAsServerURL sets the Headscale ServerURL based on -// the Hostname. -func WithHostnameAsServerURL() Option { - return func(hsic *HeadscaleInContainer) { - hsic.env["HEADSCALE_SERVER_URL"] = fmt.Sprintf("http://%s", - net.JoinHostPort(hsic.GetHostname(), - fmt.Sprintf("%d", hsic.port)), - ) - } -} - // WithFileInContainer adds a file to the container at the given path. func WithFileInContainer(path string, contents []byte) Option { return func(hsic *HeadscaleInContainer) { @@ -297,16 +284,6 @@ func New( portProto := fmt.Sprintf("%d/tcp", hsic.port) - serverURL, err := url.Parse(hsic.env["HEADSCALE_SERVER_URL"]) - if err != nil { - return nil, err - } - - if len(hsic.tlsCert) != 0 && len(hsic.tlsKey) != 0 { - serverURL.Scheme = "https" - hsic.env["HEADSCALE_SERVER_URL"] = serverURL.String() - } - headscaleBuildOptions := &dockertest.BuildOptions{ Dockerfile: IntegrationTestDockerFileName, ContextDir: dockerContextPath, @@ -352,6 +329,12 @@ func New( hsic.env["HEADSCALE_TLS_CERT_PATH"] = tlsCertPath hsic.env["HEADSCALE_TLS_KEY_PATH"] = tlsKeyPath } + + // Server URL and Listen Addr should not be overridable outside of + // the configuration passed to docker. + hsic.env["HEADSCALE_SERVER_URL"] = hsic.GetEndpoint() + hsic.env["HEADSCALE_LISTEN_ADDR"] = fmt.Sprintf("0.0.0.0:%d", hsic.port) + for key, value := range hsic.env { env = append(env, fmt.Sprintf("%s=%s", key, value)) } @@ -649,7 +632,7 @@ func (t *HeadscaleInContainer) GetHealthEndpoint() string { // GetEndpoint returns the Headscale endpoint for the HeadscaleInContainer. func (t *HeadscaleInContainer) GetEndpoint() string { hostEndpoint := fmt.Sprintf("%s:%d", - t.GetIP(), + t.GetHostname(), t.port) if t.hasTLS() {