Merge branch 'release-next' of https://github.com/openziti/ziti-tunnel-win into release-next

This commit is contained in:
Jeremy Tellier - ROG
2021-04-20 12:01:06 +01:00
9 changed files with 86 additions and 29 deletions
+5 -5
View File
@@ -214,7 +214,7 @@ namespace ZitiUpdateService {
}
return zipName;
} catch (Exception ex) {
Logger.Error(ex, "Unexpected error {0}", ex.Message);
Logger.Error(ex, "Unexpected error in generating system files {0}", ex.Message);
return null;
}
}
@@ -233,7 +233,7 @@ namespace ZitiUpdateService {
process.Start();
process.WaitForExit();
} catch (Exception ex) {
Logger.Error(ex, "Unexpected error {0}", ex.Message);
Logger.Error(ex, "Unexpected error in outputIpconfigInfo {0}", ex.Message);
}
}
@@ -251,7 +251,7 @@ namespace ZitiUpdateService {
process.Start();
process.WaitForExit();
} catch (Exception ex) {
Logger.Error(ex, "Unexpected error {0}", ex.Message);
Logger.Error(ex, "Unexpected error in outputSystemInfo {0}", ex.Message);
}
}
@@ -269,7 +269,7 @@ namespace ZitiUpdateService {
process.Start();
process.WaitForExit();
} catch (Exception ex) {
Logger.Error(ex, "Unexpected error {0}", ex.Message);
Logger.Error(ex, "Unexpected error in outputDnsCache {0}", ex.Message);
}
}
@@ -283,7 +283,7 @@ namespace ZitiUpdateService {
string responseBody = resp.Content.ReadAsStringAsync().Result;
File.WriteAllText(extIpFile, responseBody);
} catch (Exception ex) {
Logger.Error(ex, "Unexpected error {0}", ex.Message);
Logger.Error(ex, "Unexpected error in outputExternalIP {0}", ex.Message);
}
}
+1
View File
@@ -8,6 +8,7 @@
## Bugs fixed:
* [#362](https://github.com/openziti/desktop-edge-win/issues/362) Update tun ip, mask and addDns flag
* [#364](https://github.com/openziti/desktop-edge-win/issues/364) Add the test nrpt policy function in the startup method
## Dependency Updates
* none
+50
View File
@@ -238,3 +238,53 @@ ForEach ($ns in $toRemove){
log.Errorf("ERROR removing nrpt rules: %v", err)
}
}
func IsNrptPoliciesEffective(dnsserver string) bool {
script := fmt.Sprintf(`Add-DnsClientNrptRule -Namespace ".ziti.test" -NameServers "%s" -Comment "Added by ziti-tunnel" -DisplayName "ziti-tunnel:.ziti.test"
Get-DnsClientNrptPolicy -Effective | Select-Object Namespace -Unique | Where-Object Namespace -Eq ".ziti.test"`, dnsserver)
log.Debugf("checking the nrpt policies with: %s", script)
cmd := exec.Command("powershell", "-Command", script)
cmd.Stderr = os.Stdout
output := new(bytes.Buffer)
cmd.Stdout = output
err := cmd.Run()
if err != nil {
log.Errorf("ERROR adding the test nrpt rules: %v", err)
return false
}
policyFound := false
for {
l, err := output.ReadString('\n')
policyOut := strings.Trim(l, "\r\n")
if err != nil {
break
}
if strings.Compare(policyOut, ".ziti.test") == 0 {
policyFound = true
log.Debug("The nrpt policies are effective in this client")
break
}
}
removeSingleNrtpRule(".ziti.test")
return policyFound
}
func removeSingleNrtpRule(nrptRule string) {
script := fmt.Sprintf(`Get-DnsClientNrptRule | where Namespace -eq "%s" | Remove-DnsClientNrptRule -Force -ErrorAction SilentlyContinue`, nrptRule)
log.Debugf("Removing the nrpt rule with: %s", script)
cmd := exec.Command("powershell", "-Command", script)
cmd.Stderr = os.Stdout
output := new(bytes.Buffer)
cmd.Stdout = output
err := cmd.Run()
if err != nil {
log.Errorf("ERROR removing the nrpt rules: %v", err)
}
}
+1 -1
View File
@@ -19,9 +19,9 @@ package cli
import (
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
"net"
"strconv"
"strings"
"net"
)
//GetIdentities is to fetch identities through cmdline
+1 -1
View File
@@ -37,7 +37,7 @@ var updateCmd = &cobra.Command{
flags := map[string]interface{}{}
flags["CIDR"] = CIDR
flags["AddDns"] = AddDns
cli.UpdateConfigIPSubnet(args,flags)
cli.UpdateConfigIPSubnet(args, flags)
},
}
+5 -5
View File
@@ -27,11 +27,11 @@ type IdentityCli struct {
}
type ServiceCli struct {
Name string
Id string
Protocols string
Ports string
Addresses string
Name string
Id string
Protocols string
Ports string
Addresses string
}
type IdentityOnOffPayload struct {
+2 -2
View File
@@ -41,8 +41,8 @@ import (
"net"
"os"
"os/signal"
"strings"
"strconv"
"strings"
"sync"
"time"
)
@@ -645,7 +645,7 @@ func updateTunIpv4(out *json.Encoder, ip string, ipMask int, addDns string) {
respondWithError(out, "Could not set Tun ip and mask", UNKNOWN_ERROR, err)
return
}
respond(out, dto.Response{Message: "TunIPv4 and mask is set, Manual Restart is required", Code: SUCCESS, Error: "", Payload: ""})
}
+19 -13
View File
@@ -20,25 +20,26 @@ package service
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"github.com/openziti/desktop-edge-win/service/cziti"
"github.com/openziti/desktop-edge-win/service/windns"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/config"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/constants"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
idcfg "github.com/openziti/sdk-golang/ziti/config"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"io"
"io/ioutil"
"net"
"os"
"path"
"strconv"
"strings"
"time"
"errors"
"strconv"
"github.com/openziti/desktop-edge-win/service/cziti"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/config"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/constants"
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
idcfg "github.com/openziti/sdk-golang/ziti/config"
"golang.org/x/sys/windows/registry"
"golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
)
type RuntimeState struct {
@@ -107,7 +108,6 @@ func backupConfig() (string, error) {
return backup, err
}
func (t *RuntimeState) ToStatus(onlyInitialized bool) dto.TunnelStatus {
var uptime int64
@@ -223,7 +223,14 @@ func (t *RuntimeState) CreateTun(ipv4 string, ipv4mask int, applyDns bool) (net.
}
log.Info("routing applied")
if applyDns {
zitiPoliciesEffective := windns.IsNrptPoliciesEffective(ipv4)
if applyDns || !zitiPoliciesEffective {
if applyDns {
log.Infof("DNS is applied to the TUN interface, because apply Dns flag in the config file is %t ", applyDns)
}
if !applyDns && !zitiPoliciesEffective {
log.Infof("DNS is applied to the TUN interface, because Ziti policies test result in this client is %t", zitiPoliciesEffective)
}
//for windows 10+, could 'domains' be able to replace NRPT? dunno - didn't test it
luid.SetDNS(windows.AF_INET, []net.IP{ip}, nil)
}
@@ -428,7 +435,6 @@ func UpdateRuntimeStateIpv4(ip string, ipv4Mask int, addDns string) error {
}
rts.SaveState()
return nil
}
+2 -2
View File
@@ -21,8 +21,8 @@ package main
const (
Version = "1.9.4"
Revision = "c5751307beae"
Revision = "24a59ec169b9"
Branch = "release-next"
BuildUser = ""
BuildDate = "2021-04-16 21:00:50"
BuildDate = "2021-04-19 15:51:04"
)