Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release-1.25] Add extraArgs to tailscale #8466

Merged
merged 1 commit into from Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cli/cmds/agent.go
Expand Up @@ -157,13 +157,13 @@ var (
}
VPNAuth = &cli.StringFlag{
Name: "vpn-auth",
Usage: "(agent/networking) (experimental) Credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>]",
Usage: "(agent/networking) (experimental) Credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>][,extraArgs=<args>]",
EnvVar: version.ProgramUpper + "_VPN_AUTH",
Destination: &AgentConfig.VPNAuth,
}
VPNAuthFile = &cli.StringFlag{
Name: "vpn-auth-file",
Usage: "(agent/networking) (experimental) File containing credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>]",
Usage: "(agent/networking) (experimental) File containing credentials for the VPN provider. It must include the provider name and join key in the format name=<vpn-provider>,joinKey=<key>[,controlServerURL=<url>][,extraArgs=<args>]",
EnvVar: version.ProgramUpper + "_VPN_AUTH_FILE",
Destination: &AgentConfig.VPNAuthFile,
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/vpn/vpn.go
Expand Up @@ -35,6 +35,7 @@ type vpnCliAuthInfo struct {
Name string
JoinKey string
ControlServerURL string
ExtraCLIFlags []string
}

// StartVPN starts the VPN interface. General function in case we want to add more vpn integrations
Expand All @@ -53,6 +54,10 @@ func StartVPN(vpnAuthConfigFile string) error {
if authInfo.ControlServerURL != "" {
args = append(args, "--login-server", authInfo.ControlServerURL)
}
if len(authInfo.ExtraCLIFlags) > 0 {
args = append(args, authInfo.ExtraCLIFlags...)
}
logrus.Debugf("Flags passed to tailscale up: %v", args)
output, err := util.ExecCommand("tailscale", args)
if err != nil {
return errors.Wrap(err, "tailscale up failed: "+output)
Expand Down Expand Up @@ -80,7 +85,12 @@ func GetVPNInfo(vpnAuth string) (VPNInfo, error) {
// getVPNAuthInfo returns the required authInfo object
func getVPNAuthInfo(vpnAuth string) (vpnCliAuthInfo, error) {
var authInfo vpnCliAuthInfo
vpnParameters := strings.Split(vpnAuth, ",")

// Separate extraArgs which will be passed directly to the vpn binary command
vpnCommand, extraArgs := processCLIArgs(vpnAuth)
authInfo.ExtraCLIFlags = extraArgs

vpnParameters := strings.Split(vpnCommand, ",")
for _, vpnKeyValues := range vpnParameters {
vpnKeyValue := strings.Split(vpnKeyValues, "=")
switch vpnKeyValue[0] {
Expand Down Expand Up @@ -139,3 +149,13 @@ func getTailscaleInfo() (VPNInfo, error) {

return VPNInfo{IPv4Address: net.ParseIP(ipv4Address), IPv6Address: net.ParseIP(ipv6Address), NodeID: "", ProviderName: "tailscale", VPNInterface: tailscaleIf}, nil
}

// processCLIArgs separates the extraArgs part from the command.
// Note that tailscale flags of type list are comma separated and don't accept spaces, thus we can use strings.Fields to separate flags
func processCLIArgs(command string) (string, []string) {
subCommands := strings.Split(command, ",extraArgs=")
if len(subCommands) > 1 {
return subCommands[0], strings.Fields(subCommands[1])
}
return subCommands[0], []string{}
}