Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6c44b06e
Unverified
Commit
6c44b06e
authored
Jul 06, 2023
by
Manuel Buil
Committed by
GitHub
Jul 06, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7838 from manuelbuil/ipv4ipv6tailscale
Check if we are on ipv4, ipv6 or dualStack when doing tailscale
parents
9e334153
f21a0147
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
21 deletions
+44
-21
config.go
pkg/agent/config/config.go
+12
-3
server.go
pkg/cli/server/server.go
+20
-5
net.go
pkg/util/net.go
+6
-7
vpn.go
pkg/vpn/vpn.go
+6
-6
No files found.
pkg/agent/config/config.go
View file @
6c44b06e
...
...
@@ -404,15 +404,24 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
vpnInfo
.
IPs
)
!=
0
{
logrus
.
Infof
(
"Node-ip changed to %v due to VPN"
,
vpnInfo
.
IPs
)
var
vpnIPs
[]
net
.
IP
if
vpnInfo
.
IPv4Address
!=
nil
{
vpnIPs
=
append
(
vpnIPs
,
vpnInfo
.
IPv4Address
)
}
if
vpnInfo
.
IPv6Address
!=
nil
{
vpnIPs
=
append
(
vpnIPs
,
vpnInfo
.
IPv6Address
)
}
if
len
(
vpnIPs
)
!=
0
{
logrus
.
Infof
(
"Node-ip changed to %v due to VPN"
,
vpnIPs
)
if
len
(
envInfo
.
NodeIP
)
!=
0
{
logrus
.
Warn
(
"VPN provider overrides configured node-ip parameter"
)
}
if
len
(
envInfo
.
NodeExternalIP
)
!=
0
{
logrus
.
Warn
(
"VPN provider overrides node-external-ip parameter"
)
}
nodeIPs
=
vpnI
nfo
.
I
Ps
nodeIPs
=
vpnIPs
flannelIface
,
err
=
net
.
InterfaceByName
(
vpnInfo
.
VPNInterface
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"unable to find vpn interface: %s"
,
vpnInfo
.
VPNInterface
)
...
...
pkg/cli/server/server.go
View file @
6c44b06e
...
...
@@ -229,12 +229,27 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
if
err
!=
nil
{
return
err
}
if
len
(
vpnInfo
.
IPs
)
!=
0
{
logrus
.
Infof
(
"Advertise-address changed to %v due to VPN"
,
vpnInfo
.
IPs
)
if
serverConfig
.
ControlConfig
.
AdvertiseIP
!=
""
{
logrus
.
Warn
(
"Conflict in the config detected. VPN integration overwrites advertise-address but the config is setting the advertise-address parameter"
)
// If we are in ipv6-only mode, we should pass the ipv6 address. Otherwise, ipv4
if
utilsnet
.
IsIPv6CIDRString
(
util
.
JoinIPNets
(
serverConfig
.
ControlConfig
.
ClusterIPRanges
))
{
if
vpnInfo
.
IPv6Address
!=
nil
{
logrus
.
Infof
(
"Advertise-address changed to %v due to VPN"
,
vpnInfo
.
IPv6Address
)
if
serverConfig
.
ControlConfig
.
AdvertiseIP
!=
""
{
logrus
.
Warn
(
"Conflict in the config detected. VPN integration overwrites advertise-address but the config is setting the advertise-address parameter"
)
}
serverConfig
.
ControlConfig
.
AdvertiseIP
=
vpnInfo
.
IPv6Address
.
String
()
}
else
{
return
errors
.
New
(
"tailscale does not provide an ipv6 address"
)
}
}
else
{
if
vpnInfo
.
IPv4Address
!=
nil
{
logrus
.
Infof
(
"Advertise-address changed to %v due to VPN"
,
vpnInfo
.
IPv4Address
)
if
serverConfig
.
ControlConfig
.
AdvertiseIP
!=
""
{
logrus
.
Warn
(
"Conflict in the config detected. VPN integration overwrites advertise-address but the config is setting the advertise-address parameter"
)
}
serverConfig
.
ControlConfig
.
AdvertiseIP
=
vpnInfo
.
IPv4Address
.
String
()
}
else
{
return
errors
.
New
(
"tailscale does not provide an ipv4 address"
)
}
serverConfig
.
ControlConfig
.
AdvertiseIP
=
vpnInfo
.
IPs
[
0
]
.
String
()
}
logrus
.
Warn
(
"Etcd IP (PrivateIP) remains the local IP. Running etcd traffic over VPN is not recommended due to performance issues"
)
}
else
{
...
...
pkg/util/net.go
View file @
6c44b06e
...
...
@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
apinet
"k8s.io/apimachinery/pkg/util/net"
netutils
"k8s.io/utils/net"
)
// JoinIPs stringifies and joins a list of IP addresses with commas.
...
...
@@ -85,10 +86,9 @@ func JoinIP4Nets(elems []*net.IPNet) string {
// If no IPv6 addresses are found, an error is raised.
func
GetFirst6
(
elems
[]
net
.
IP
)
(
net
.
IP
,
error
)
{
for
_
,
elem
:=
range
elems
{
if
elem
==
nil
||
elem
.
To16
()
==
nil
{
continue
if
elem
!=
nil
&&
netutils
.
IsIPv6
(
elem
)
{
return
elem
,
nil
}
return
elem
,
nil
}
return
nil
,
errors
.
New
(
"no IPv6 address found"
)
}
...
...
@@ -97,10 +97,9 @@ func GetFirst6(elems []net.IP) (net.IP, error) {
// If no IPv6 addresses are found, an error is raised.
func
GetFirst6Net
(
elems
[]
*
net
.
IPNet
)
(
*
net
.
IPNet
,
error
)
{
for
_
,
elem
:=
range
elems
{
if
elem
==
nil
||
elem
.
IP
.
To16
()
==
nil
{
continue
if
elem
!=
nil
&&
netutils
.
IsIPv6
(
elem
.
IP
)
{
return
elem
,
nil
}
return
elem
,
nil
}
return
nil
,
errors
.
New
(
"no IPv6 CIDRs found"
)
}
...
...
@@ -125,7 +124,7 @@ func GetFirst6String(elems []string) (string, error) {
func
JoinIP6Nets
(
elems
[]
*
net
.
IPNet
)
string
{
var
strs
[]
string
for
_
,
elem
:=
range
elems
{
if
elem
!=
nil
&&
elem
.
IP
.
To4
()
==
nil
{
if
elem
!=
nil
&&
netutils
.
IsIPv6
(
elem
.
IP
)
{
strs
=
append
(
strs
,
elem
.
String
())
}
}
...
...
pkg/vpn/vpn.go
View file @
6c44b06e
...
...
@@ -22,7 +22,8 @@ type TailscaleOutput struct {
// VPNInfo includes node information of the VPN. It is a general struct in case we want to add more vpn integrations
type
VPNInfo
struct
{
IPs
[]
net
.
IP
IPv4Address
net
.
IP
IPv6Address
net
.
IP
NodeID
string
ProviderName
string
VPNInterface
string
...
...
@@ -112,15 +113,14 @@ func getTailscaleInfo() (VPNInfo, error) {
logrus
.
Debugf
(
"Output from tailscale status --json: %v"
,
output
)
var
tailscaleOutput
TailscaleOutput
var
internalIPs
[]
net
.
IP
err
=
json
.
Unmarshal
([]
byte
(
output
),
&
tailscaleOutput
)
if
err
!=
nil
{
return
VPNInfo
{},
fmt
.
Errorf
(
"failed to unmarshal tailscale output: %v"
,
err
)
}
for
_
,
address
:=
range
tailscaleOutput
.
TailscaleIPs
{
internalIPs
=
append
(
internalIPs
,
net
.
ParseIP
(
address
)
)
}
// Errors are ignored because the interface might not have ipv4 or ipv6 addresses (that's the only possible error)
ipv4Address
,
_
:=
util
.
GetFirst4String
(
tailscaleOutput
.
TailscaleIPs
)
ipv6Address
,
_
:=
util
.
GetFirst6String
(
tailscaleOutput
.
TailscaleIPs
)
return
VPNInfo
{
IP
s
:
internalIPs
,
NodeID
:
""
,
ProviderName
:
"tailscale"
,
VPNInterface
:
tailscaleIf
},
nil
return
VPNInfo
{
IP
v4Address
:
net
.
ParseIP
(
ipv4Address
),
IPv6Address
:
net
.
ParseIP
(
ipv6Address
)
,
NodeID
:
""
,
ProviderName
:
"tailscale"
,
VPNInterface
:
tailscaleIf
},
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment