Skip to content

Commit 29dd70d

Browse files
authored
Merge pull request #65 from privacyint/v6_only
Add an IPv6-only mode, defaulted off
2 parents 66d9efd + 94dfdd9 commit 29dd70d

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

scripts/container-entrypoint.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ validate_extra_records() {
160160
fi
161161
}
162162

163+
#######################################
164+
# Validate IP address settings
165+
#######################################
166+
check_ip_address_settings() {
167+
check_env_var_or_set_default "IP_ALLOCATION" "${headscale_ip_allocation_default}" "^(sequential|random)$" "Invalid 'IP_ALLOCATION'. Must be either 'sequential' (default) or 'random'."
168+
check_env_var_or_set_default "IPV6_ONLY" "${headscale_ipv6_only_default}" "^(true|false)$" "Invalid 'IPV6_ONLY'. Must be 'true' or 'false'."
169+
check_env_var_or_set_default "IPV4_PREFIX" "${headscale_ipv4_prefix_default}"
170+
check_env_var_or_set_default "IPV6_PREFIX" "${headscale_ipv6_prefix_default}"
171+
172+
if [[ "${IPV6_ONLY}" == "true" ]]; then
173+
export IP_PREFIXES="v6: ${IPV6_PREFIX}"
174+
else
175+
export IP_PREFIXES="v4: ${IPV4_PREFIX}
176+
v6: ${IPV6_PREFIX}"
177+
fi
178+
}
179+
163180
#######################################
164181
# Perform all Headscale environment variable checks
165182
#######################################
@@ -170,10 +187,8 @@ check_headscale_environment_vars() {
170187
check_litestream_replica_url
171188
validate_oidc_settings
172189
validate_extra_records
190+
check_ip_address_settings
173191
check_env_var_or_set_default "HEADSCALE_OVERRIDE_LOCAL_DNS" "true" "^(true|false)$" "Invalid 'HEADSCALE_OVERRIDE_LOCAL_DNS'. Must be 'true' (default) or 'false'."
174-
check_env_var_or_set_default "IP_ALLOCATION" "${headscale_ip_allocation_default}" "^(sequential|random)$" "Invalid 'IP_ALLOCATION'. Must be either 'sequential' (default) or 'random'."
175-
check_env_var_or_set_default "IPV4_PREFIX" "${headscale_ipv4_prefix_default}"
176-
check_env_var_or_set_default "IPV6_PREFIX" "${headscale_ipv6_prefix_default}"
177192
check_env_var_or_set_default "MAGIC_DNS" "${headscale_magic_dns_default}" "^(true|false)$" "Invalid 'MAGIC_DNS'. Must be 'true' or 'false'."
178193
require_env_var "PUBLIC_SERVER_URL"
179194
require_env_var "HEADSCALE_DNS_BASE_DOMAIN"
@@ -193,8 +208,7 @@ create_headscale_config() {
193208
"HEADSCALE_DNS_BASE_DOMAIN"
194209
"HEADSCALE_OVERRIDE_LOCAL_DNS"
195210
"MAGIC_DNS"
196-
"IPV6_PREFIX"
197-
"IPV4_PREFIX"
211+
"IP_PREFIXES"
198212
"IP_ALLOCATION"
199213
"HEADSCALE_EXTRA_RECORDS_PATH"
200214
)
@@ -437,7 +451,11 @@ display_configuration_summary() {
437451
log_feature_status "Magic DNS" "${MAGIC_DNS}"
438452

439453
log_info "IP Allocation: ${IP_ALLOCATION}"
440-
log_info "IPv4 Prefix: ${IPV4_PREFIX}"
454+
if [[ "${IPV6_ONLY}" == "true" ]]; then
455+
log_feature_status "IPv6 Only" true ""
456+
else
457+
log_info "IPv4 Prefix: ${IPV4_PREFIX}"
458+
fi
441459
log_info "IPv6 Prefix: ${IPV6_PREFIX}"
442460

443461
if env_var_is_defined "HEADSCALE_OIDC_ISSUER"; then

scripts/defaults.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public_listen_port_default=443
44

55
headscale_extra_records_path_default="/data/headscale/extra-records.json"
66
headscale_magic_dns_default="true"
7+
headscale_ipv6_only_default="false"
78
headscale_ipv6_prefix_default="fd7a:115c:a1e0::/48"
89
headscale_ipv4_prefix_default="100.64.0.0/10"
910
headscale_ip_allocation_default="sequential"

templates/headscale.template.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ noise:
5656
# IPv4: https://github.com/tailscale/tailscale/blob/22ebb25e833264f58d7c3f534a8b166894a89536/net/tsaddr/tsaddr.go#L33
5757
# Any other range is NOT supported, and it will cause unexpected issues.
5858
prefixes:
59-
v6: $IPV6_PREFIX
60-
v4: $IPV4_PREFIX
59+
$IP_PREFIXES
6160

62-
# Strategy used for allocation of IPs to nodes, available options:
63-
# - sequential (default): assigns the next free IP from the previous given IP.
64-
# - random: assigns the next free IP from a pseudo-random IP generator (crypto/rand).
65-
allocation: $IP_ALLOCATION
61+
# Strategy used for allocation of IPs to nodes, available options:
62+
# - sequential (default): assigns the next free IP from the previous given IP.
63+
# - random: assigns the next free IP from a pseudo-random IP generator (crypto/rand).
64+
allocation: $IP_ALLOCATION
6665

6766
# DERP is a relay system that Tailscale uses when a direct
6867
# connection cannot be established.

templates/secrets.template.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ HEADSCALE_DNS_BASE_DOMAIN=CHANGEME
2424
# IPV6_PREFIX="fd7a:115c:a1e0::/48"
2525
# IPV4_PREFIX="100.64.0.0/10"
2626

27+
# Enable IPv6-only mode (disables IPv4 prefix allocation)
28+
# IPV6_ONLY=false
29+
2730
# The following one can be set after first deployment
2831
# If not, it will require all Tailscale clients to restart on every deploy
2932
# HEADSCALE_NOISE_PRIVATE_KEY=CHANGEME

0 commit comments

Comments
 (0)