netbird
netbird copied to clipboard
unify Config generation, loading and updating
Describe your changes
There are 2 primary changes:
- (misc) allows passing custom system service name (helps https://github.com/NixOS/nixpkgs/pull/287236 )
- unifies configuration loading and updating into a single
Config.apply(ConfigInput):- has better logging (informs of everything it does)
- accepts both empty
Config{}and emptyInputConfig{}filling in missing parts automatically - handling was slightly inconsistent between
createNewConfig()andupdate() - added
InterfaceBlacklistto theInputConfig
Basically when I tried to start the netbird service run with just WgIface and WgPort present in config.json it crashed, so I got to fixing stuff :)
Issue ticket number and link
- partially addresses #1562 by making incomplete configs acceptable (currently it segfaults on missing pointers/values)
- to be used in https://github.com/NixOS/nixpkgs/pull/287236
Checklist
- [x] Is it a bug fix
- [ ] Is a typo/documentation fix
- [x] Is a feature enhancement
- [x] It is a refactor
- [ ] Created tests that fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary
Note I was unable to run tests locally so didn't touch those hoping nothing will break
kdn@krul ~/d/g/n/netbird (fixups) [1]> go test -exec sudo ./...
package github.com/netbirdio/netbird/client/ui
imports fyne.io/fyne/v2/app
imports fyne.io/fyne/v2/internal/driver/glfw
imports fyne.io/fyne/v2/internal/driver/common
imports fyne.io/fyne/v2/internal/painter/gl
imports github.com/go-gl/gl/v3.2-core/gl: build constraints exclude all Go files in /home/kdn/go/pkg/mod/github.com/go-gl/[email protected]/v3.2-core/gl
this commit seems to work on a live system https://github.com/netbirdio/netbird/pull/1586/commits/dcf9b84ee3360d7d1ba81976be9956e1623d4054
before
don't mind that jq error, it was still creating a file and starting:
Feb 15 09:44:54 krul (re-start)[420986]: netbird.service: ConfigurationDirectory 'netbird' already exists but the mode is different. (File system: 755 ConfigurationDirectoryMode: 700)
Feb 15 09:44:54 krul netbird-pre-start[420986]: created empty /var/lib/netbird/config.json
Feb 15 09:44:54 krul netbird-pre-start[420999]: jq: error: syntax error, unexpected '/', expecting end of file (Unix shell quoting issues?) at <top-level>, line 1:
Feb 15 09:44:54 krul netbird-pre-start[420999]: /var/lib/netbird/config.json
Feb 15 09:44:54 krul netbird-pre-start[420999]: jq: 1 compile error
Feb 15 09:44:54 krul netbird-pre-start[421001]: 0a1,4
Feb 15 09:44:54 krul netbird-pre-start[421001]: > {
Feb 15 09:44:54 krul netbird-pre-start[421001]: > "WgIface": "wt0",
Feb 15 09:44:54 krul netbird-pre-start[421001]: > "WgPort": 51831
Feb 15 09:44:54 krul netbird-pre-start[421001]: > }
Feb 15 09:44:54 krul systemd[1]: Started A WireGuard-based mesh network that connects your devices into a single private network.
Feb 15 09:44:54 krul (bird-wt0)[421033]: netbird.service: ConfigurationDirectory 'netbird' already exists but the mode is different. (File system: 755 ConfigurationDirectoryMode: 700)
Feb 15 09:44:54 krul netbird-wt0[421033]: 2024-02-15T09:44:54+01:00 INFO client/cmd/service_controller.go:24: starting Netbird service
Feb 15 09:44:54 krul netbird-wt0[421033]: panic: runtime error: invalid memory address or nil pointer dereference
Feb 15 09:44:54 krul netbird-wt0[421033]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xf0997d]
Feb 15 09:44:54 krul netbird-wt0[421033]: goroutine 8 [running]:
Feb 15 09:44:54 krul netbird-wt0[421033]: net/url.(*URL).Hostname(...)
Feb 15 09:44:54 krul netbird-wt0[421033]: net/url/url.go:1144
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/internal.UpdateOldManagementURL({0x16b78e8, 0xc0000e65f0}, 0xc0008266e0, {0xc00004a03a, 0x1c})
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/internal/config.go:358 +0xfd
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/server.(*Server).Start(0xc000002480)
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/server/server.go:109 +0x4e5
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/cmd.(*program).Start.func1()
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/cmd/service_controller.go:59 +0x513
Feb 15 09:44:54 krul netbird-wt0[421033]: created by github.com/netbirdio/netbird/client/cmd.(*program).Start in goroutine 1
Feb 15 09:44:54 krul netbird-wt0[421033]: github.com/netbirdio/netbird/client/cmd/service_controller.go:47 +0x315
Feb 15 09:44:54 krul systemd[1]: netbird.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 15 09:44:54 krul systemd[1]: netbird.service: Failed with result 'exit-code'.
Feb 15 09:44:54 krul systemd[1]: netbird.service: Scheduled restart job, restart counter is at 1.
after
kdn@krul ~/d/g/n/nix-configs (main)> journalctl --since -5m -u netbird.service
Feb 15 12:35:10 krul systemd[1]: Stopping A WireGuard-based mesh network that connects your devices into a single private network...
Feb 15 12:35:10 krul netbird-wt0[647207]: 2024-02-15T12:35:10+01:00 INFO client/cmd/root.go:150: shutdown signal received
Feb 15 12:35:12 krul netbird-wt0[647207]: 2024-02-15T12:35:12+01:00 INFO client/cmd/service_controller.go:80: stopped Netbird service
Feb 15 12:35:12 krul systemd[1]: netbird.service: Deactivated successfully.
Feb 15 12:35:12 krul systemd[1]: Stopped A WireGuard-based mesh network that connects your devices into a single private network.
Feb 15 12:35:12 krul systemd[1]: Starting A WireGuard-based mesh network that connects your devices into a single private network...
Feb 15 12:35:12 krul netbird-pre-start[721471]: Comparing /var/lib/netbird/config.json with /var/lib/netbird/config.json.new ...
Feb 15 12:35:12 krul netbird-pre-start[721474]: 52c52
Feb 15 12:35:12 krul netbird-pre-start[721474]: < "WgPort": 51820
Feb 15 12:35:12 krul netbird-pre-start[721474]: ---
Feb 15 12:35:12 krul netbird-pre-start[721474]: > "WgPort": 51831
Feb 15 12:35:12 krul netbird-pre-start[721471]: Updating /var/lib/netbird/config.json ...
Feb 15 12:35:12 krul systemd[1]: Started A WireGuard-based mesh network that connects your devices into a single private network.
Feb 15 12:35:12 krul netbird-wt0[721477]: 2024-02-15T12:35:12+01:00 INFO client/cmd/service_controller.go:24: starting Netbird service
Feb 15 12:35:12 krul netbird-wt0[721477]: 2024-02-15T12:35:12+01:00 INFO client/cmd/service_controller.go:64: started daemon server: /var/run/netbird/sock
Feb 15 12:35:12 krul netbird-wt0[721477]: 2024-02-15T12:35:12+01:00 INFO client/internal/connect.go:95: starting NetBird client version 0.25.7
Feb 15 12:35:12 krul netbird-wt0[721477]: 2024-02-15T12:35:12+01:00 ERRO client/server/server.go:121: init connections: rpc error: code = PermissionDenied desc = no peer auth method provided, please use a setup key or interactive SSO login
moved service name flag out into https://github.com/netbirdio/netbird/pull/1691
FYI: this seems like a good standard for configurations https://uapi-group.org/specifications/specs/configuration_files_specification/