mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-30 18:41:37 -07:00
[client] Fix staticcheck findings from the updated golangci-lint (#7266)
* Fix staticcheck findings reported by the updated golangci-lint * Skip the receive error log when the local context is done
This commit is contained in:
@@ -45,8 +45,8 @@ func daemonServerOptions(network string) []grpc.ServerOption {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := ipcauth.NewTransportCredentials()
|
creds := ipcauth.NewTransportCredentials() //nolint:staticcheck
|
||||||
if creds == nil {
|
if creds == nil { //nolint:staticcheck // nil only on platforms without a peer-identity primitive
|
||||||
log.Warnf("daemon IPC has no peer-identity primitive on %s: privileged operations will be denied", runtime.GOOS)
|
log.Warnf("daemon IPC has no peer-identity primitive on %s: privileged operations will be denied", runtime.GOOS)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ func listenOnAddress(addr string) (*socketListener, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if network == "npipe" {
|
if network == "npipe" {
|
||||||
listener, path, err := listenNamedPipe(address)
|
listener, path, err := listenNamedPipe(address) //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on non-Windows builds
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &socketListener{Listener: listener, network: network, address: path}, nil
|
return &socketListener{Listener: listener, network: network, address: path}, nil
|
||||||
|
|||||||
@@ -144,13 +144,13 @@ func (d *DefaultManager) applyPeerACLs(networkMap *mgmProto.NetworkMap) {
|
|||||||
log.Warn("this peer is connected to a NetBird Management service with an older version. Allowing all traffic from connected peers")
|
log.Warn("this peer is connected to a NetBird Management service with an older version. Allowing all traffic from connected peers")
|
||||||
rules = append(rules,
|
rules = append(rules,
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "0.0.0.0",
|
PeerIP: "0.0.0.0", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_ALL,
|
Protocol: mgmProto.RuleProtocol_ALL,
|
||||||
},
|
},
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "0.0.0.0",
|
PeerIP: "0.0.0.0", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_OUT,
|
Direction: mgmProto.RuleDirection_OUT,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_ALL,
|
Protocol: mgmProto.RuleProtocol_ALL,
|
||||||
@@ -407,7 +407,6 @@ func (d *DefaultManager) getRuleGroupingSelector(rule *mgmProto.FirewallRule) st
|
|||||||
return fmt.Sprintf("%v:%v:%v:%s:%v", strconv.Itoa(int(rule.Direction)), rule.Action, rule.Protocol, rule.Port, rule.PortInfo)
|
return fmt.Sprintf("%v:%v:%v:%s:%v", strconv.Itoa(int(rule.Direction)), rule.Action, rule.Protocol, rule.Port, rule.PortInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// extractRuleIP extracts the peer IP from a firewall rule.
|
// extractRuleIP extracts the peer IP from a firewall rule.
|
||||||
// If sourcePrefixes is populated (new management), decode the first entry and use its address.
|
// If sourcePrefixes is populated (new management), decode the first entry and use its address.
|
||||||
// Otherwise fall back to the deprecated PeerIP string field (old management).
|
// Otherwise fall back to the deprecated PeerIP string field (old management).
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.uber.org/mock/gomock"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/mock/gomock"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/firewall"
|
"github.com/netbirdio/netbird/client/firewall"
|
||||||
"github.com/netbirdio/netbird/client/iface"
|
"github.com/netbirdio/netbird/client/iface"
|
||||||
@@ -87,7 +87,7 @@ func TestDefaultManager(t *testing.T) {
|
|||||||
networkMap.FirewallRules = append(
|
networkMap.FirewallRules = append(
|
||||||
networkMap.FirewallRules,
|
networkMap.FirewallRules,
|
||||||
&mgmProto.FirewallRule{
|
&mgmProto.FirewallRule{
|
||||||
PeerIP: "10.93.0.3",
|
PeerIP: "10.93.0.3", //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_DROP,
|
Action: mgmProto.RuleAction_DROP,
|
||||||
Protocol: mgmProto.RuleProtocol_ICMP,
|
Protocol: mgmProto.RuleProtocol_ICMP,
|
||||||
@@ -561,7 +561,7 @@ func buildNetworkMap(peerRules, routeRules int) *mgmProto.NetworkMap {
|
|||||||
}
|
}
|
||||||
for i := range peerRules {
|
for i := range peerRules {
|
||||||
nm.FirewallRules = append(nm.FirewallRules, &mgmProto.FirewallRule{
|
nm.FirewallRules = append(nm.FirewallRules, &mgmProto.FirewallRule{
|
||||||
PeerIP: fmt.Sprintf("10.%d.%d.%d", i>>16&0xff, i>>8&0xff, i&0xff),
|
PeerIP: fmt.Sprintf("10.%d.%d.%d", i>>16&0xff, i>>8&0xff, i&0xff), //nolint:staticcheck
|
||||||
Direction: mgmProto.RuleDirection_IN,
|
Direction: mgmProto.RuleDirection_IN,
|
||||||
Action: mgmProto.RuleAction_ACCEPT,
|
Action: mgmProto.RuleAction_ACCEPT,
|
||||||
Protocol: mgmProto.RuleProtocol_TCP,
|
Protocol: mgmProto.RuleProtocol_TCP,
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ func (r *registryConfigurator) flushDNSCache() {
|
|||||||
|
|
||||||
ret, _, err := dnsFlushResolverCacheFn.Call()
|
ret, _, err := dnsFlushResolverCacheFn.Call()
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
if err != nil && !errors.Is(err, syscall.Errno(0)) {
|
if !errors.Is(err, syscall.Errno(0)) {
|
||||||
log.Errorf("DnsFlushResolverCache failed: %v", err)
|
log.Errorf("DnsFlushResolverCache failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -627,7 +627,7 @@ func refreshGroupPolicy() error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
if err != nil && !errors.Is(err, syscall.Errno(0)) {
|
if !errors.Is(err, syscall.Errno(0)) {
|
||||||
return fmt.Errorf("RefreshPolicyEx failed: %w", err)
|
return fmt.Errorf("RefreshPolicyEx failed: %w", err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("RefreshPolicyEx failed")
|
return fmt.Errorf("RefreshPolicyEx failed")
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (m *Manager) Start(fwdEntries []*ForwarderEntry) error {
|
|||||||
m.dnsForwarder = NewDNSForwarder(listenAddress, dnsTTL, m.firewall, m.statusRecorder, m.wgIface)
|
m.dnsForwarder = NewDNSForwarder(listenAddress, dnsTTL, m.firewall, m.statusRecorder, m.wgIface)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := m.dnsForwarder.Listen(fwdEntries); err != nil {
|
if err := m.dnsForwarder.Listen(fwdEntries); err != nil { //nolint:staticcheck
|
||||||
// todo handle close error if it is exists
|
// todo handle close error if it is exists
|
||||||
log.Errorf("failed to start DNS forwarder, err: %v", err)
|
log.Errorf("failed to start DNS forwarder, err: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2572,7 +2572,7 @@ func (e *Engine) SetCapture(pc device.PacketCapture) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afc := capture.NewAFPacketCapture(intf.Name(), sess)
|
afc := capture.NewAFPacketCapture(intf.Name(), sess)
|
||||||
if err := afc.Start(); err != nil {
|
if err := afc.Start(); err != nil { //nolint:staticcheck // always errors on non-Linux builds
|
||||||
return fmt.Errorf("start AF_PACKET capture on %s: %w", intf.Name(), err)
|
return fmt.Errorf("start AF_PACKET capture on %s: %w", intf.Name(), err)
|
||||||
}
|
}
|
||||||
e.afpacketCapture = afc
|
e.afpacketCapture = afc
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ type Service struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Service, error) {
|
func New() (*Service, error) {
|
||||||
d, err := NewDetector()
|
d, err := NewDetector() //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on platforms without a sleep detector
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ func (m *Manager) install(ctx context.Context, pendingVersion *v.Version) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
inst := installer.New()
|
inst := installer.New()
|
||||||
if err := inst.RunInstallation(ctx, pendingVersion.String()); err != nil {
|
if err := inst.RunInstallation(ctx, pendingVersion.String()); err != nil { //nolint:staticcheck // always errors on platforms without an installer
|
||||||
log.Errorf("error triggering update: %v", err)
|
log.Errorf("error triggering update: %v", err)
|
||||||
m.statusRecorder.PublishEvent(
|
m.statusRecorder.PublishEvent(
|
||||||
cProto.SystemEvent_ERROR,
|
cProto.SystemEvent_ERROR,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -69,7 +70,7 @@ func setStdHandle(f *os.File) error {
|
|||||||
handle := f.Fd()
|
handle := f.Fd()
|
||||||
r0, _, e1 := setStdHandleFn.Call(stdErrorHandle, handle)
|
r0, _, e1 := setStdHandleFn.Call(stdErrorHandle, handle)
|
||||||
if r0 == 0 {
|
if r0 == 0 {
|
||||||
if e1 != nil {
|
if !errors.Is(e1, syscall.Errno(0)) {
|
||||||
return e1
|
return e1
|
||||||
}
|
}
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ func (s *Server) createCommand(logger *log.Entry, privilegeResult PrivilegeCheck
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try su first for system integration (PAM/audit) when privileged
|
// Try su first for system integration (PAM/audit) when privileged
|
||||||
cmd, err := s.createSuCommand(logger, session, localUser, hasPty)
|
cmd, err := s.createSuCommand(logger, session, localUser, hasPty) //nolint:staticcheck
|
||||||
if err != nil || privilegeResult.UsedFallback {
|
if err != nil || privilegeResult.UsedFallback { //nolint:staticcheck // always errors on platforms without su
|
||||||
logger.Debugf("su command failed, falling back to executor: %v", err)
|
logger.Debugf("su command failed, falling back to executor: %v", err)
|
||||||
cmd, cleanup, err := s.createExecutorCommand(logger, session, localUser, hasPty)
|
cmd, cleanup, err := s.createExecutorCommand(logger, session, localUser, hasPty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -146,11 +146,14 @@ func (c *GRPCClient) Receive(ctx context.Context, interval time.Duration, msgHan
|
|||||||
|
|
||||||
streamStart := time.Now()
|
streamStart := time.Now()
|
||||||
|
|
||||||
if err := c.receive(stream, msgHandler); err != nil {
|
// receive always returns a non-nil error once the stream breaks;
|
||||||
|
// handleRetryableError decides between reconnecting and exiting
|
||||||
|
// permanently on local context cancellation
|
||||||
|
err = c.receive(stream, msgHandler)
|
||||||
|
if !isContextDone(err) {
|
||||||
log.Errorf("receive failed: %v", err)
|
log.Errorf("receive failed: %v", err)
|
||||||
return c.handleRetryableError(err, streamStart, backOff)
|
|
||||||
}
|
}
|
||||||
return nil
|
return c.handleRetryableError(err, streamStart, backOff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := backoff.Retry(operation, backOff); err != nil {
|
if err := backoff.Retry(operation, backOff); err != nil {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
port := 51820
|
port := 51820
|
||||||
rawSock, err := sharedsock.Listen(port, sharedsock.NewIncomingSTUNFilter(), iface.DefaultMTU)
|
rawSock, err := sharedsock.Listen(port, sharedsock.NewIncomingSTUNFilter(), iface.DefaultMTU) //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint:staticcheck // always errors on non-Linux builds
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func WriteBytesWithRestrictedPermission(ctx context.Context, file string, bs []b
|
|||||||
return fmt.Errorf("enforce permission: %w", err)
|
return fmt.Errorf("enforce permission: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeBytes(ctx, file, err, configDir, configFileName, bs)
|
return writeBytes(ctx, file, configDir, configFileName, bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJsonWithRestrictedPermission writes JSON config object to a file. Enforces permission on the parent directory
|
// WriteJsonWithRestrictedPermission writes JSON config object to a file. Enforces permission on the parent directory
|
||||||
@@ -106,10 +106,10 @@ func writeJson(ctx context.Context, file string, obj interface{}, configDir stri
|
|||||||
return fmt.Errorf("marshal: %w", err)
|
return fmt.Errorf("marshal: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeBytes(ctx, file, err, configDir, configFileName, bs)
|
return writeBytes(ctx, file, configDir, configFileName, bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBytes(ctx context.Context, file string, err error, configDir string, configFileName string, bs []byte) error {
|
func writeBytes(ctx context.Context, file string, configDir string, configFileName string, bs []byte) error {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return fmt.Errorf("write bytes start: %w", ctx.Err())
|
return fmt.Errorf("write bytes start: %w", ctx.Err())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user