Merge remote-tracking branch 'origin/main' into braginini/wasm

# Conflicts:
#	signal/client/client.go
This commit is contained in:
braginini
2021-11-15 15:45:37 +01:00
15 changed files with 133 additions and 27 deletions

View File

@@ -85,6 +85,52 @@ nfpms:
postinstall: "release_files/post_install.sh" postinstall: "release_files/post_install.sh"
preremove: "release_files/pre_remove.sh" preremove: "release_files/pre_remove.sh"
dockers: dockers:
- image_templates:
- wiretrustee/wiretrustee:{{ .Version }}-amd64
ids:
- wiretrustee
goarch: amd64
use: buildx
dockerfile: client/Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- image_templates:
- wiretrustee/wiretrustee:{{ .Version }}-arm64v8
ids:
- wiretrustee
goarch: arm64
use: buildx
dockerfile: client/Dockerfile
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- image_templates:
- wiretrustee/wiretrustee:{{ .Version }}-arm
ids:
- wiretrustee
goarch: arm
goarm: 6
use: buildx
dockerfile: client/Dockerfile
build_flag_templates:
- "--platform=linux/arm"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- image_templates: - image_templates:
- wiretrustee/signal:{{ .Version }}-amd64 - wiretrustee/signal:{{ .Version }}-amd64
ids: ids:
@@ -225,6 +271,18 @@ dockers:
- "--label=org.opencontainers.image.version={{.Version}}" - "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com" - "--label=maintainer=wiretrustee@wiretrustee.com"
docker_manifests: docker_manifests:
- name_template: wiretrustee/wiretrustee:{{ .Version }}
image_templates:
- wiretrustee/wiretrustee:{{ .Version }}-arm64v8
- wiretrustee/wiretrustee:{{ .Version }}-arm
- wiretrustee/wiretrustee:{{ .Version }}-amd64
- name_template: wiretrustee/wiretrustee:latest
image_templates:
- wiretrustee/wiretrustee:{{ .Version }}-arm64v8
- wiretrustee/wiretrustee:{{ .Version }}-arm
- wiretrustee/wiretrustee:{{ .Version }}-amd64
- name_template: wiretrustee/signal:{{ .Version }} - name_template: wiretrustee/signal:{{ .Version }}
image_templates: image_templates:
- wiretrustee/signal:{{ .Version }}-arm64v8 - wiretrustee/signal:{{ .Version }}-arm64v8

View File

@@ -145,6 +145,11 @@ For **Windows** systems, start powershell as administrator and:
```shell ```shell
wiretrustee up --setup-key <SETUP KEY> wiretrustee up --setup-key <SETUP KEY>
``` ```
For **Docker**, you can run with the following command:
```shell
docker run --network host --privileged --rm -d -e WT_SETUP_KEY=<SETUP KEY> -v wiretrustee-client:/etc/wiretrustee wiretrustee/wiretrustee:<TAG>
```
> TAG > 0.3.0 version
Alternatively, if you are hosting your own Management Service provide `--management-url` property pointing to your Management Service: Alternatively, if you are hosting your own Management Service provide `--management-url` property pointing to your Management Service:
```shell ```shell

4
client/Dockerfile Normal file
View File

@@ -0,0 +1,4 @@
FROM gcr.io/distroless/base:debug
ENV WT_LOG_FILE=console
ENTRYPOINT [ "/go/bin/wiretrustee","up"]
COPY wiretrustee /go/bin/wiretrustee

View File

@@ -18,12 +18,12 @@ import (
) )
var ( var (
setupKey string
loginCmd = &cobra.Command{ loginCmd = &cobra.Command{
Use: "login", Use: "login",
Short: "login to the Wiretrustee Management Service (first run)", Short: "login to the Wiretrustee Management Service (first run)",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars()
err := util.InitLog(logLevel, logFile) err := util.InitLog(logLevel, logFile)
if err != nil { if err != nil {
log.Errorf("failed initializing log %v", err) log.Errorf("failed initializing log %v", err)
@@ -151,6 +151,3 @@ func promptPeerSetupKey() (string, error) {
return "", s.Err() return "", s.Err()
} }
//func init() {
//}

View File

@@ -4,19 +4,15 @@ import (
"fmt" "fmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/wiretrustee/wiretrustee/client/internal" "github.com/wiretrustee/wiretrustee/client/internal"
"os" "os"
"os/signal" "os/signal"
"runtime" "runtime"
"strings"
"syscall" "syscall"
) )
const (
// ExitSetupFailed defines exit code
ExitSetupFailed = 1
DefaultConfigPath = ""
)
var ( var (
configPath string configPath string
defaultConfigPath string defaultConfigPath string
@@ -24,6 +20,7 @@ var (
defaultLogFile string defaultLogFile string
logFile string logFile string
managementURL string managementURL string
setupKey string
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
Use: "wiretrustee", Use: "wiretrustee",
Short: "", Short: "",
@@ -75,3 +72,28 @@ func SetupCloseHandler() {
} }
}() }()
} }
// SetFlagsFromEnvVars reads and updates flag values from environment variables with prefix WT_
func SetFlagsFromEnvVars() {
flags := rootCmd.PersistentFlags()
flags.VisitAll(func(f *pflag.Flag) {
envVar := FlagNameToEnvVar(f.Name)
if value, present := os.LookupEnv(envVar); present {
err := flags.Set(f.Name, value)
if err != nil {
log.Infof("unable to configure flag %s using variable %s, err: %v", f.Name, envVar, err)
}
}
})
}
// FlagNameToEnvVar converts flag name to environment var name adding a prefix,
// replacing dashes and making all uppercase (e.g. setup-keys is converted to WT_SETUP_KEYS)
func FlagNameToEnvVar(f string) string {
prefix := "WT_"
parsed := strings.ReplaceAll(f, "-", "_")
upper := strings.ToUpper(parsed)
return prefix + upper
}

View File

@@ -34,6 +34,3 @@ var (
Short: "manages wiretrustee service", Short: "manages wiretrustee service",
} }
) )
func init() {
}

View File

@@ -8,7 +8,7 @@ import (
"time" "time"
) )
func (p *program) Start(s service.Service) error { func (p *program) Start(service.Service) error {
// Start should not block. Do the actual work async. // Start should not block. Do the actual work async.
log.Info("starting service") //nolint log.Info("starting service") //nolint
@@ -22,7 +22,7 @@ func (p *program) Start(s service.Service) error {
return nil return nil
} }
func (p *program) Stop(s service.Service) error { func (p *program) Stop(service.Service) error {
go func() { go func() {
stopCh <- 1 stopCh <- 1
}() }()
@@ -41,6 +41,7 @@ var (
Use: "run", Use: "run",
Short: "runs wiretrustee as service", Short: "runs wiretrustee as service",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
SetFlagsFromEnvVars()
err := util.InitLog(logLevel, logFile) err := util.InitLog(logLevel, logFile)
if err != nil { if err != nil {
@@ -75,6 +76,8 @@ var (
Use: "start", Use: "start",
Short: "starts wiretrustee service", Short: "starts wiretrustee service",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars()
err := util.InitLog(logLevel, logFile) err := util.InitLog(logLevel, logFile)
if err != nil { if err != nil {
log.Errorf("failed initializing log %v", err) log.Errorf("failed initializing log %v", err)
@@ -101,6 +104,8 @@ var (
Use: "stop", Use: "stop",
Short: "stops wiretrustee service", Short: "stops wiretrustee service",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
SetFlagsFromEnvVars()
err := util.InitLog(logLevel, logFile) err := util.InitLog(logLevel, logFile)
if err != nil { if err != nil {
log.Errorf("failed initializing log %v", err) log.Errorf("failed initializing log %v", err)
@@ -125,6 +130,8 @@ var (
Use: "restart", Use: "restart",
Short: "restarts wiretrustee service", Short: "restarts wiretrustee service",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
SetFlagsFromEnvVars()
err := util.InitLog(logLevel, logFile) err := util.InitLog(logLevel, logFile)
if err != nil { if err != nil {
log.Errorf("failed initializing log %v", err) log.Errorf("failed initializing log %v", err)
@@ -143,6 +150,3 @@ var (
}, },
} }
) )
func init() {
}

View File

@@ -10,6 +10,7 @@ var (
Use: "install", Use: "install",
Short: "installs wiretrustee service", Short: "installs wiretrustee service",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars()
svcConfig := newSVCConfig() svcConfig := newSVCConfig()
@@ -49,6 +50,7 @@ var (
Use: "uninstall", Use: "uninstall",
Short: "uninstalls wiretrustee service from system", Short: "uninstalls wiretrustee service from system",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
SetFlagsFromEnvVars()
s, err := newSVC(&program{}, newSVCConfig()) s, err := newSVC(&program{}, newSVCConfig())
if err != nil { if err != nil {
@@ -65,6 +67,3 @@ var (
}, },
} }
) )
func init() {
}

View File

@@ -21,7 +21,7 @@ var (
Use: "up", Use: "up",
Short: "install, login and start wiretrustee client", Short: "install, login and start wiretrustee client",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars()
err := loginCmd.RunE(cmd, args) err := loginCmd.RunE(cmd, args)
if err != nil { if err != nil {
return err return err

View File

@@ -106,6 +106,7 @@ SectionEnd
Section Uninstall Section Uninstall
${INSTALL_TYPE} ${INSTALL_TYPE}
Exec '"$INSTDIR\${MAIN_APP_EXE}" service stop'
Exec '"$INSTDIR\${MAIN_APP_EXE}" service uninstall' Exec '"$INSTDIR\${MAIN_APP_EXE}" service uninstall'
# wait the service uninstall take unblock the executable # wait the service uninstall take unblock the executable
Sleep 3000 Sleep 3000

View File

@@ -138,12 +138,18 @@ func (conn *Connection) Open(timeout time.Duration) error {
return !ok return !ok
}, },
}) })
conn.agent = a
if err != nil { if err != nil {
return err return err
} }
conn.agent = a
defer func() {
err := conn.agent.Close()
if err != nil {
return
}
}()
err = conn.listenOnLocalCandidates() err = conn.listenOnLocalCandidates()
if err != nil { if err != nil {
return err return err

View File

@@ -148,6 +148,11 @@ func (e *Engine) initializePeer(peer Peer) {
}, e.ctx) }, e.ctx)
operation := func() error { operation := func() error {
if e.signal.GetStatus() != signal.StreamConnected {
return fmt.Errorf("not opening connection to peer because Signal is unavailable")
}
_, err := e.openPeerConnection(e.wgPort, e.config.WgPrivateKey, peer) _, err := e.openPeerConnection(e.wgPort, e.config.WgPrivateKey, peer)
e.peerMux.Lock() e.peerMux.Lock()
defer e.peerMux.Unlock() defer e.peerMux.Unlock()
@@ -157,7 +162,7 @@ func (e *Engine) initializePeer(peer Peer) {
} }
if err != nil { if err != nil {
log.Infof("retrying connection because of error: %s", err.Error()) log.Debugf("retrying connection because of error: %s", err.Error())
return err return err
} }
return nil return nil

1
go.mod
View File

@@ -17,6 +17,7 @@ require (
github.com/rs/cors v1.8.0 github.com/rs/cors v1.8.0
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.3 github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/vishvananda/netlink v1.1.0 github.com/vishvananda/netlink v1.1.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359

View File

@@ -10,6 +10,12 @@ import (
// A set of tools to exchange connection details (Wireguard endpoints) with the remote peer. // A set of tools to exchange connection details (Wireguard endpoints) with the remote peer.
// Status is the status of the client
type Status string
const StreamConnected Status = "Connected"
const StreamDisconnected Status = "Disconnected"
// Client is an interface describing Signal client // Client is an interface describing Signal client
type Client interface { type Client interface {
// Receive handles incoming messages from the Signal service // Receive handles incoming messages from the Signal service
@@ -21,6 +27,7 @@ type Client interface {
SendToStream(msg *proto.EncryptedMessage) error SendToStream(msg *proto.EncryptedMessage) error
// WaitStreamConnected blocks until client is connected to the Signal stream // WaitStreamConnected blocks until client is connected to the Signal stream
WaitStreamConnected() WaitStreamConnected()
GetStatus() Status
} }
// decryptMessage decrypts the body of the msg using Wireguard private key and Remote peer's public key // decryptMessage decrypts the body of the msg using Wireguard private key and Remote peer's public key

View File

@@ -37,7 +37,7 @@ var _ = Describe("Client", func() {
}) })
Describe("Exchanging messages", func() { Describe("Exchanging messages", func() {
Context("between streamConnected peers", func() { Context("between connected peers", func() {
It("should be successful", func() { It("should be successful", func() {
var msgReceived sync.WaitGroup var msgReceived sync.WaitGroup