mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-25 04:01:29 +02:00
Log remote address when not registered (#445)
This commit is contained in:
parent
c13f0b9f07
commit
586c0f5c3d
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/netbirdio/netbird/route"
|
"github.com/netbirdio/netbird/route"
|
||||||
|
gPeer "google.golang.org/grpc/peer"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -88,17 +89,24 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
|
|
||||||
peer, err := s.accountManager.GetPeer(peerKey.String())
|
peer, err := s.accountManager.GetPeer(peerKey.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return status.Errorf(codes.PermissionDenied, "provided peer with the key wgPubKey %s is not registered", peerKey.String())
|
p, _ := gPeer.FromContext(srv.Context())
|
||||||
|
msg := status.Errorf(codes.PermissionDenied, "provided peer with the key wgPubKey %s is not registered, remote addr is %s", peerKey.String(), p.Addr.String())
|
||||||
|
log.Debug(msg)
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
syncReq := &proto.SyncRequest{}
|
syncReq := &proto.SyncRequest{}
|
||||||
err = encryption.DecryptMessage(peerKey, s.wgKey, req.Body, syncReq)
|
err = encryption.DecryptMessage(peerKey, s.wgKey, req.Body, syncReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return status.Errorf(codes.InvalidArgument, "invalid request message")
|
p, _ := gPeer.FromContext(srv.Context())
|
||||||
|
msg := status.Errorf(codes.InvalidArgument, "invalid request message from %s,remote addr is %s", peerKey.String(), p.Addr.String())
|
||||||
|
log.Debug(msg)
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.sendInitialSync(peerKey, peer, srv)
|
err = s.sendInitialSync(peerKey, peer, srv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debugf("error while sending initial sync for %s: %v", peerKey.String(), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +125,7 @@ func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementServi
|
|||||||
// condition when there are some updates
|
// condition when there are some updates
|
||||||
case update, open := <-updates:
|
case update, open := <-updates:
|
||||||
if !open {
|
if !open {
|
||||||
// updates channel has been closed
|
log.Debugf("updates channel for peer %s was closed", peerKey.String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Debugf("recevied an update for peer %s", peerKey.String())
|
log.Debugf("recevied an update for peer %s", peerKey.String())
|
||||||
@ -266,8 +274,13 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p
|
|||||||
if errStatus, ok := status.FromError(err); ok && errStatus.Code() == codes.NotFound {
|
if errStatus, ok := status.FromError(err); ok && errStatus.Code() == codes.NotFound {
|
||||||
// peer doesn't exist -> check if setup key was provided
|
// peer doesn't exist -> check if setup key was provided
|
||||||
if loginReq.GetJwtToken() == "" && loginReq.GetSetupKey() == "" {
|
if loginReq.GetJwtToken() == "" && loginReq.GetSetupKey() == "" {
|
||||||
// absent setup key -> permission denied
|
// absent setup key or jwt -> permission denied
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "provided peer with the key wgPubKey %s is not registered and no setup key or jwt was provided", peerKey.String())
|
p, _ := gPeer.FromContext(ctx)
|
||||||
|
msg := status.Errorf(codes.PermissionDenied,
|
||||||
|
"provided peer with the key wgPubKey %s is not registered and no setup key or jwt was provided,"+
|
||||||
|
" remote addr is %s", peerKey.String(), p.Addr.String())
|
||||||
|
log.Debug(msg)
|
||||||
|
return nil, msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup key or jwt is present -> try normal registration flow
|
// setup key or jwt is present -> try normal registration flow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user