mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 08:53:05 +00:00
Compare commits
4 commits
8666c4ba77
...
6d82e8b702
Author | SHA1 | Date | |
---|---|---|---|
|
6d82e8b702 | ||
|
c0c383359f | ||
|
ddb1370c73 | ||
|
e834017314 |
2 changed files with 13 additions and 8 deletions
|
@ -30,7 +30,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errOidcMutuallyExclusive = errors.New("oidc_client_secret and oidc_client_secret_path are mutually exclusive")
|
errOidcMutuallyExclusive = errors.New("oidc_client_secret and oidc_client_secret_path are mutually exclusive")
|
||||||
errServerURLSuffix = errors.New("server_url cannot be a suffix of the base_domain, this will cause the headscale server and embedded DERP to become unreachable from the Tailscale node.")
|
errServerURLSuffix = errors.New("server_url cannot be part of base_domain in a way that could make the DERP and headscale server unreachable")
|
||||||
)
|
)
|
||||||
|
|
||||||
type IPAllocationStrategy string
|
type IPAllocationStrategy string
|
||||||
|
@ -928,9 +928,9 @@ func LoadServerConfig() (*Config, error) {
|
||||||
// This is because Tailscale takes over the domain in BaseDomain,
|
// This is because Tailscale takes over the domain in BaseDomain,
|
||||||
// causing the headscale server and DERP to be unreachable.
|
// causing the headscale server and DERP to be unreachable.
|
||||||
// For Tailscale upstream, the following is true:
|
// For Tailscale upstream, the following is true:
|
||||||
// - DERP run on their own domains
|
// - DERP run on their own domains.
|
||||||
// - Control plane runs on login.tailscale.com/controlplane.tailscale.com
|
// - Control plane runs on login.tailscale.com/controlplane.tailscale.com.
|
||||||
// - MagicDNS (BaseDomain) for users is on a *.ts.net domain per tailnet (e.g. tail-scale.ts.net)
|
// - MagicDNS (BaseDomain) for users is on a *.ts.net domain per tailnet (e.g. tail-scale.ts.net).
|
||||||
func isSafeServerURL(serverURL, baseDomain string) error {
|
func isSafeServerURL(serverURL, baseDomain string) error {
|
||||||
server, err := url.Parse(serverURL)
|
server, err := url.Parse(serverURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -946,8 +946,8 @@ func isSafeServerURL(serverURL, baseDomain string) error {
|
||||||
|
|
||||||
s := len(serverDomainParts)
|
s := len(serverDomainParts)
|
||||||
b := len(baseDomainParts)
|
b := len(baseDomainParts)
|
||||||
for i := 1; i < len(baseDomainParts)-1; i++ {
|
for i := range len(baseDomainParts) {
|
||||||
if serverDomainParts[s-i] != baseDomainParts[b-i] {
|
if serverDomainParts[s-i-1] != baseDomainParts[b-i-1] {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ func TestReadConfig(t *testing.T) {
|
||||||
return LoadServerConfig()
|
return LoadServerConfig()
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: "server_url cannot be a suffix of the base_domain, this will cause the headscale server and embedded DERP to become unreachable from the Tailscale node.",
|
wantErr: errServerURLSuffix.Error(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "base-domain-not-in-server-url",
|
name: "base-domain-not-in-server-url",
|
||||||
|
@ -340,7 +340,7 @@ tls_letsencrypt_challenge_type: TLS-ALPN-01
|
||||||
// server_url: headscale.com, base: headscale.net
|
// server_url: headscale.com, base: headscale.net
|
||||||
//
|
//
|
||||||
// NOT OK
|
// NOT OK
|
||||||
// server_url: server.headscale.com, base: headscale.com
|
// server_url: server.headscale.com, base: headscale.com.
|
||||||
func TestSafeServerURL(t *testing.T) {
|
func TestSafeServerURL(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
serverURL, baseDomain,
|
serverURL, baseDomain,
|
||||||
|
@ -362,6 +362,10 @@ func TestSafeServerURL(t *testing.T) {
|
||||||
serverURL: "https://headscale.com",
|
serverURL: "https://headscale.com",
|
||||||
baseDomain: "clients.subdomain.headscale.com",
|
baseDomain: "clients.subdomain.headscale.com",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
serverURL: "https://headscale.kristoffer.com",
|
||||||
|
baseDomain: "mybase",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
serverURL: "https://server.headscale.com",
|
serverURL: "https://server.headscale.com",
|
||||||
baseDomain: "headscale.com",
|
baseDomain: "headscale.com",
|
||||||
|
@ -384,6 +388,7 @@ func TestSafeServerURL(t *testing.T) {
|
||||||
err := isSafeServerURL(tt.serverURL, tt.baseDomain)
|
err := isSafeServerURL(tt.serverURL, tt.baseDomain)
|
||||||
if tt.wantErr != "" {
|
if tt.wantErr != "" {
|
||||||
assert.EqualError(t, err, tt.wantErr)
|
assert.EqualError(t, err, tt.wantErr)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue