Skip to content

Commit

Permalink
Don't use the custom dialer as non-root (netbirdio#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal authored Apr 11, 2024
1 parent 225be98 commit 77313df
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions util/grpc/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package grpc
import (
"context"
"net"
"os/user"
"runtime"

log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand All @@ -12,6 +14,20 @@ import (

func WithCustomDialer() grpc.DialOption {
return grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
if runtime.GOOS == "linux" {
currentUser, err := user.Current()
if err != nil {
log.Fatalf("failed to get current user: %v", err)
}

// the custom dialer requires root permissions which are not required for use cases run as non-root
if currentUser.Uid != "0" {
dialer := &net.Dialer{}
return dialer.DialContext(ctx, "tcp", addr)
}
}


conn, err := nbnet.NewDialer().DialContext(ctx, "tcp", addr)
if err != nil {
log.Errorf("Failed to dial: %s", err)
Expand Down

0 comments on commit 77313df

Please sign in to comment.