diff --git a/cmd/auth-server/go.mod b/cmd/auth-server/go.mod deleted file mode 100644 index b6cc8a8b..00000000 --- a/cmd/auth-server/go.mod +++ /dev/null @@ -1,17 +0,0 @@ -module github.com/nais/device/cmd/auth-server - -go 1.22 - -require ( - github.com/kelseyhightower/envconfig v1.4.0 - github.com/nais/device v0.0.0-20231116080500-e5ff68885f35 - github.com/sirupsen/logrus v1.9.3 - golang.org/x/oauth2 v0.13.0 -) - -require ( - github.com/golang/protobuf v1.5.3 // indirect - golang.org/x/sys v0.13.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/protobuf v1.33.0 // indirect -) diff --git a/cmd/auth-server/go.sum b/cmd/auth-server/go.sum deleted file mode 100644 index b25b9e94..00000000 --- a/cmd/auth-server/go.sum +++ /dev/null @@ -1,64 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= -github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= -github.com/nais/device v0.0.0-20231116080500-e5ff68885f35 h1:n28lQVv0Vvg9c7on9FG2YbOzazNhV/qLs883I2ZT+Lo= -github.com/nais/device v0.0.0-20231116080500-e5ff68885f35/go.mod h1:KkdXzU7X/OZT6TG6BLZHsBPQHspj1XPeYjzX2smbFzo= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= -golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..f2658c14 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1714635257, + "narHash": "sha256-4cPymbty65RvF1DWQfc+Bc8B233A1BWxJnNULJKQ1EY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63c3a29ca82437c87573e4c6919b09a24ea61b0f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..cf0c8a7f --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "A simple Go package"; + + # Nixpkgs / NixOS version to use. + inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; + + outputs = { + self, + nixpkgs, + }: let + # to work with older version of flakes + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + + # Generate a user-friendly version number. + version = builtins.substring 0 8 lastModifiedDate; + + # System types to support. + supportedSystems = ["x86_64-linux"]; # "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); + in { + # Provide some binary packages for selected system types. + packages = forAllSystems (system: let + pkgs = nixpkgsFor.${system}; + in { + device-agent = pkgs.buildGoModule { + pname = "device-agent"; + inherit version; + # In 'nix develop', we don't need a copy of the source tree + # in the Nix store. + src = ./.; + + # This hash locks the dependencies of this package. It is + # necessary because of how Go requires network access to resolve + # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for + # details. Normally one can build with a fake hash and rely on native Go + # mechanisms to tell you what the hash should be or determine what + # it should be "out-of-band" with other tooling (eg. gomod2nix). + # To begin with it is recommended to set this, but one must + # remember to bump this hash when your dependencies change. + # vendorHash = pkgs.lib.fakeHash; + + vendorHash = "sha256-AgRQO3h7Atq4lnieTBohzrwrw0lRcbQi2cvpeol3owM="; + }; + }); + + # Add dependencies that are only needed for development + devShells = forAllSystems (system: let + pkgs = nixpkgsFor.${system}; + in { + default = pkgs.mkShell { + buildInputs = with pkgs; [go gopls gotools go-tools]; + }; + }); + + # The default package for 'nix build'. This makes sense if the + # flake provides only one package or there is a clear "main" + # package. + defaultPackage = forAllSystems (system: self.packages.${system}.device-agent); + }; +} diff --git a/internal/device-agent/config/config.go b/internal/device-agent/config/config.go index 1d4ee8a8..e9a7f2d1 100644 --- a/internal/device-agent/config/config.go +++ b/internal/device-agent/config/config.go @@ -33,16 +33,14 @@ type Config struct { GoogleOAuth2Config oauth2.Config Platform string PrivateKeyPath string - WireGuardBinary string WireGuardConfigPath string - WireGuardGoBinary string EnrollProjectID string EnrollTopicName string } func (c *Config) SetDefaults() { c.Platform = Platform - c.SetPlatformDefaults() + c.Interface = "utun69" c.PrivateKeyPath = filepath.Join(c.ConfigDir, "private.key") c.WireGuardConfigPath = filepath.Join(c.ConfigDir, c.Interface+".conf") } @@ -60,8 +58,12 @@ func DefaultConfig() (*Config, error) { DeviceAgentHelperAddress: filepath.Join(config2.RuntimeDir, "helper.sock"), GoogleAuthServerAddress: "https://naisdevice-auth-server-h2pjqrstja-lz.a.run.app", AzureOAuth2Config: oauth2.Config{ - ClientID: "8086d321-c6d3-4398-87da-0d54e3d93967", - Scopes: []string{"openid", "6e45010d-2637-4a40-b91d-d4cbb451fb57/.default", "offline_access"}, + ClientID: "8086d321-c6d3-4398-87da-0d54e3d93967", + Scopes: []string{ + "openid", + "6e45010d-2637-4a40-b91d-d4cbb451fb57/.default", + "offline_access", + }, Endpoint: endpoints.AzureAD("62366534-1ec3-4962-8869-9b5535279d0b"), RedirectURL: "http://localhost:PORT/", }, diff --git a/internal/device-agent/config/config_darwin.go b/internal/device-agent/config/config_darwin.go deleted file mode 100644 index 56cd2b47..00000000 --- a/internal/device-agent/config/config_darwin.go +++ /dev/null @@ -1,15 +0,0 @@ -package config - -import ( - "path/filepath" -) - -const ( - BinaryDir = "/Applications/naisdevice.app/Contents/MacOS" -) - -func (c *Config) SetPlatformDefaults() { - c.WireGuardBinary = filepath.Join(BinaryDir, "wg") - c.WireGuardGoBinary = filepath.Join(BinaryDir, "wireguard-go") - c.Interface = "utun69" -} diff --git a/internal/device-agent/config/config_linux.go b/internal/device-agent/config/config_linux.go deleted file mode 100644 index cbe5192e..00000000 --- a/internal/device-agent/config/config_linux.go +++ /dev/null @@ -1,14 +0,0 @@ -package config - -import ( - "path/filepath" -) - -const ( - BinaryDir = "/usr/bin/" -) - -func (c *Config) SetPlatformDefaults() { - c.WireGuardBinary = filepath.Join(BinaryDir, "wg") - c.Interface = "utun69" -} diff --git a/internal/device-agent/config/config_windows.go b/internal/device-agent/config/config_windows.go deleted file mode 100644 index 35b538ad..00000000 --- a/internal/device-agent/config/config_windows.go +++ /dev/null @@ -1,15 +0,0 @@ -package config - -import ( - "os" - "path/filepath" -) - -func (c *Config) SetPlatformDefaults() { - programFiles := os.Getenv("%programfiles%") - if programFiles == "" { - programFiles = `c:\Program Files` - } - c.WireGuardBinary = filepath.Join(programFiles, "WireGuard", "wireguard.exe") - c.Interface = "utun69" -} diff --git a/internal/device-agent/filesystem/filesystem.go b/internal/device-agent/filesystem/filesystem.go index a89bea96..356270bc 100644 --- a/internal/device-agent/filesystem/filesystem.go +++ b/internal/device-agent/filesystem/filesystem.go @@ -8,15 +8,11 @@ import ( ) func EnsurePrerequisites(c *config.Config) error { - if err := filesExist(c.WireGuardBinary); err != nil { - return fmt.Errorf("verifying if file exists: %v", err) - } - if err := ensureDirectories(c.ConfigDir); err != nil { return fmt.Errorf("ensuring directory exists: %v", err) } - return ensurePlatformPrerequisites(c) + return nil } func FileMustExist(filepath string) error { diff --git a/internal/device-agent/filesystem/filesystem_darwin.go b/internal/device-agent/filesystem/filesystem_darwin.go deleted file mode 100644 index e582a145..00000000 --- a/internal/device-agent/filesystem/filesystem_darwin.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build linux || darwin -// +build linux darwin - -package filesystem - -import ( - "fmt" - - "github.com/nais/device/internal/device-agent/config" -) - -func ensurePlatformPrerequisites(c *config.Config) error { - if err := filesExist(c.WireGuardGoBinary); err != nil { - return fmt.Errorf("verifying if file exists: %w", err) - } - - return nil -} diff --git a/internal/device-agent/filesystem/filesystem_linux.go b/internal/device-agent/filesystem/filesystem_linux.go deleted file mode 100644 index 943646eb..00000000 --- a/internal/device-agent/filesystem/filesystem_linux.go +++ /dev/null @@ -1,9 +0,0 @@ -package filesystem - -import ( - "github.com/nais/device/internal/device-agent/config" -) - -func ensurePlatformPrerequisites(c *config.Config) error { - return nil -} diff --git a/internal/device-agent/filesystem/filesystem_windows.go b/internal/device-agent/filesystem/filesystem_windows.go deleted file mode 100644 index 943646eb..00000000 --- a/internal/device-agent/filesystem/filesystem_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -package filesystem - -import ( - "github.com/nais/device/internal/device-agent/config" -) - -func ensurePlatformPrerequisites(c *config.Config) error { - return nil -} diff --git a/internal/helper/helper.go b/internal/helper/helper.go index abf90752..c1fccb35 100644 --- a/internal/helper/helper.go +++ b/internal/helper/helper.go @@ -37,7 +37,11 @@ type DeviceHelperServer struct { log *logrus.Entry } -func NewDeviceHelperServer(log *logrus.Entry, config Config, osConfigurator OSConfigurator) *DeviceHelperServer { +func NewDeviceHelperServer( + log *logrus.Entry, + config Config, + osConfigurator OSConfigurator, +) *DeviceHelperServer { return &DeviceHelperServer{ log: log, config: config, @@ -45,7 +49,10 @@ func NewDeviceHelperServer(log *logrus.Entry, config Config, osConfigurator OSCo } } -func (dhs *DeviceHelperServer) Teardown(ctx context.Context, req *pb.TeardownRequest) (*pb.TeardownResponse, error) { +func (dhs *DeviceHelperServer) Teardown( + ctx context.Context, + req *pb.TeardownRequest, +) (*pb.TeardownResponse, error) { dhs.log.Infof("Removing network interface '%s' and all routes", dhs.config.Interface) err := dhs.osConfigurator.TeardownInterface(ctx) if err != nil { @@ -64,7 +71,10 @@ func (dhs *DeviceHelperServer) Teardown(ctx context.Context, req *pb.TeardownReq return &pb.TeardownResponse{}, nil } -func (dhs *DeviceHelperServer) Configure(ctx context.Context, cfg *pb.Configuration) (*pb.ConfigureResponse, error) { +func (dhs *DeviceHelperServer) Configure( + ctx context.Context, + cfg *pb.Configuration, +) (*pb.ConfigureResponse, error) { dhs.log.Infof("New configuration received from device-agent") err := dhs.writeConfigFile(cfg) @@ -85,14 +95,22 @@ func (dhs *DeviceHelperServer) Configure(ctx context.Context, cfg *pb.Configurat if loopErr != nil { backoff := time.Duration(attempt) * time.Second dhs.log.Errorf("synchronize WireGuard configuration: %s", loopErr) - dhs.log.Infof("attempt %d at configuring failed, sleeping %v before retrying", attempt+1, backoff) + dhs.log.Infof( + "attempt %d at configuring failed, sleeping %v before retrying", + attempt+1, + backoff, + ) time.Sleep(backoff) continue } break } if loopErr != nil { - return nil, status.Errorf(codes.FailedPrecondition, "synchronize WireGuard configuration: %s", loopErr) + return nil, status.Errorf( + codes.FailedPrecondition, + "synchronize WireGuard configuration: %s", + loopErr, + ) } err = dhs.osConfigurator.SetupRoutes(ctx, cfg.GetGateways()) @@ -129,7 +147,10 @@ func (dhs *DeviceHelperServer) writeConfigFile(cfg *pb.Configuration) error { return nil } -func (dhs *DeviceHelperServer) GetSerial(context.Context, *pb.GetSerialRequest) (*pb.GetSerialResponse, error) { +func (dhs *DeviceHelperServer) GetSerial( + context.Context, + *pb.GetSerialRequest, +) (*pb.GetSerialResponse, error) { device_serial, err := serial.GetDeviceSerial() if err != nil { return nil, err @@ -137,6 +158,9 @@ func (dhs *DeviceHelperServer) GetSerial(context.Context, *pb.GetSerialRequest) return &pb.GetSerialResponse{Serial: device_serial}, nil } -func (dhs *DeviceHelperServer) Upgrade(context.Context, *pb.UpgradeRequest) (*pb.UpgradeResponse, error) { +func (dhs *DeviceHelperServer) Upgrade( + context.Context, + *pb.UpgradeRequest, +) (*pb.UpgradeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Upgrade not implemented") } diff --git a/internal/helper/helper_linux.go b/internal/helper/helper_linux.go index 7fa2a517..48a33a64 100644 --- a/internal/helper/helper_linux.go +++ b/internal/helper/helper_linux.go @@ -9,9 +9,7 @@ import ( "github.com/nais/device/internal/pb" ) -const ( - wireguardBinary = "/usr/bin/wg" -) +var wireguardBinary = "" func New(helperConfig Config) *LinuxConfigurator { return &LinuxConfigurator{ @@ -26,15 +24,26 @@ type LinuxConfigurator struct { var _ OSConfigurator = &LinuxConfigurator{} func (c *LinuxConfigurator) Prerequisites() error { - if err := filesExist(wireguardBinary); err != nil { - return fmt.Errorf("verifying if file exists: %w", err) + var err error + wireguardBinary, err = exec.LookPath("wg") + if err != nil { + return fmt.Errorf("unable to find wg binary: %w", err) + } + if wireguardBinary == "" { + return fmt.Errorf("wg path is empty string") } return nil } func (c *LinuxConfigurator) SyncConf(ctx context.Context, cfg *pb.Configuration) error { - cmd := exec.CommandContext(ctx, wireguardBinary, "syncconf", c.helperConfig.Interface, c.helperConfig.WireGuardConfigPath) + cmd := exec.CommandContext( + ctx, + wireguardBinary, + "syncconf", + c.helperConfig.Interface, + c.helperConfig.WireGuardConfigPath, + ) if b, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("running syncconf: %w: %v", err, string(b)) } @@ -53,7 +62,15 @@ func (c *LinuxConfigurator) SetupRoutes(ctx context.Context, gateways []*pb.Gate cidr = strings.TrimSpace(cidr) - cmd := exec.CommandContext(ctx, "ip", "route", "add", cidr, "dev", c.helperConfig.Interface) + cmd := exec.CommandContext( + ctx, + "ip", + "route", + "add", + cidr, + "dev", + c.helperConfig.Interface, + ) output, err := cmd.CombinedOutput() if exitErr, ok := err.(*exec.ExitError); ok { if exitErr.ExitCode() == 2 && strings.Contains(string(output), "File exists") {