mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-08 14:39:09 +02:00
[management] Add peer expiration reason to activity meta (#6619)
This commit is contained in:
@@ -689,7 +689,7 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(ctx context.Context, acc
|
|||||||
|
|
||||||
log.WithContext(ctx).Debugf("discovered %d peers to expire for account %s", len(peerIDs), accountID)
|
log.WithContext(ctx).Debugf("discovered %d peers to expire for account %s", len(peerIDs), accountID)
|
||||||
|
|
||||||
if err := am.expireAndUpdatePeers(ctx, accountID, expiredPeers); err != nil {
|
if err := am.expireAndUpdatePeers(ctx, accountID, expiredPeers, peerExpirationSessionExpired); err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed updating account peers while expiring peers for account %s", accountID)
|
log.WithContext(ctx).Errorf("failed updating account peers while expiring peers for account %s", accountID)
|
||||||
return peerSchedulerRetryInterval, true
|
return peerSchedulerRetryInterval, true
|
||||||
}
|
}
|
||||||
@@ -724,7 +724,7 @@ func (am *DefaultAccountManager) peerInactivityExpirationJob(ctx context.Context
|
|||||||
|
|
||||||
log.Debugf("discovered %d peers to expire for account %s", len(peerIDs), accountID)
|
log.Debugf("discovered %d peers to expire for account %s", len(peerIDs), accountID)
|
||||||
|
|
||||||
if err := am.expireAndUpdatePeers(ctx, accountID, inactivePeers); err != nil {
|
if err := am.expireAndUpdatePeers(ctx, accountID, inactivePeers, peerExpirationInactivity); err != nil {
|
||||||
log.Errorf("failed updating account peers while expiring peers for account %s", accountID)
|
log.Errorf("failed updating account peers while expiring peers for account %s", accountID)
|
||||||
return peerSchedulerRetryInterval, true
|
return peerSchedulerRetryInterval, true
|
||||||
}
|
}
|
||||||
@@ -1949,7 +1949,7 @@ func (am *DefaultAccountManager) onPeersInvalidated(ctx context.Context, account
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(peers) > 0 {
|
if len(peers) > 0 {
|
||||||
err := am.expireAndUpdatePeers(ctx, accountID, peers)
|
err := am.expireAndUpdatePeers(ctx, accountID, peers, peerExpirationValidationFailed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to expire and update invalidated peers for account %s: %v", accountID, err)
|
log.WithContext(ctx).Errorf("failed to expire and update invalidated peers for account %s: %v", accountID, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -34,7 +34,16 @@ import (
|
|||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const remoteJobsMinVer = "0.64.0"
|
type peerExpirationReason string
|
||||||
|
|
||||||
|
const (
|
||||||
|
remoteJobsMinVer = "0.64.0"
|
||||||
|
|
||||||
|
peerExpirationSessionExpired peerExpirationReason = "session expiration"
|
||||||
|
peerExpirationInactivity peerExpirationReason = "inactivity timeout"
|
||||||
|
peerExpirationValidationFailed peerExpirationReason = "failed integration validation"
|
||||||
|
peerExpirationUserBlocked peerExpirationReason = "blocked owner account"
|
||||||
|
)
|
||||||
|
|
||||||
// GetPeers returns peers visible to the user within an account.
|
// GetPeers returns peers visible to the user within an account.
|
||||||
// Users with "peers:read" see all peers. Otherwise, users see only their own peers, or none if restricted by account settings.
|
// Users with "peers:read" see all peers. Otherwise, users see only their own peers, or none if restricted by account settings.
|
||||||
|
|||||||
@@ -675,7 +675,7 @@ func (am *DefaultAccountManager) SaveOrAddUsers(ctx context.Context, accountID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(peersToExpire) > 0 {
|
if len(peersToExpire) > 0 {
|
||||||
if err := am.expireAndUpdatePeers(ctx, accountID, peersToExpire); err != nil {
|
if err := am.expireAndUpdatePeers(ctx, accountID, peersToExpire, peerExpirationUserBlocked); err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed update expired peers: %s", err)
|
log.WithContext(ctx).Errorf("failed update expired peers: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1118,7 @@ func (am *DefaultAccountManager) BuildUserInfosForAccount(ctx context.Context, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
// expireAndUpdatePeers expires all peers of the given user and updates them in the account
|
// expireAndUpdatePeers expires all peers of the given user and updates them in the account
|
||||||
func (am *DefaultAccountManager) expireAndUpdatePeers(ctx context.Context, accountID string, peers []*nbpeer.Peer) error {
|
func (am *DefaultAccountManager) expireAndUpdatePeers(ctx context.Context, accountID string, peers []*nbpeer.Peer, reason peerExpirationReason) error {
|
||||||
log.WithContext(ctx).Debugf("Expiring %d peers for account %s", len(peers), accountID)
|
log.WithContext(ctx).Debugf("Expiring %d peers for account %s", len(peers), accountID)
|
||||||
settings, err := am.Store.GetAccountSettings(ctx, store.LockingStrengthNone, accountID)
|
settings, err := am.Store.GetAccountSettings(ctx, store.LockingStrengthNone, accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1145,10 +1145,12 @@ func (am *DefaultAccountManager) expireAndUpdatePeers(ctx context.Context, accou
|
|||||||
if err := am.Store.SavePeerStatus(ctx, accountID, peer.ID, *peer.Status); err != nil {
|
if err := am.Store.SavePeerStatus(ctx, accountID, peer.ID, *peer.Status); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
meta := peer.EventMeta(dnsDomain)
|
||||||
|
meta["reason"] = string(reason)
|
||||||
am.StoreEvent(
|
am.StoreEvent(
|
||||||
ctx,
|
ctx,
|
||||||
peer.UserID, peer.ID, accountID,
|
peer.UserID, peer.ID, accountID,
|
||||||
activity.PeerLoginExpired, peer.EventMeta(dnsDomain),
|
activity.PeerLoginExpired, meta,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user