Skip to content

[management] login filter to fix multiple peers connected with the same pub key #3986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

crn4
Copy link
Contributor

@crn4 crn4 commented Jun 16, 2025

Describe your changes

We discovered that multiple machines using the same public key caused continuous reconnections. This PR introduces a login filter cache to allow only one connection per public key at a time.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@crn4 crn4 marked this pull request as ready for review June 19, 2025 15:12
@Copilot Copilot AI review requested due to automatic review settings June 19, 2025 15:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a login filter to enforce only one active connection per public key, integrates it into the account manager and gRPC server, and adds metrics and error handling for blocked requests.

  • Introduce loginFilter with in-memory cache to track and block duplicate logins
  • Wire loginFilter into DefaultAccountManager and gRPC Sync/Login handlers with metrics and logging
  • Add new blocked-request counters and ErrPeerAlreadyLoggedIn error type

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
management/server/telemetry/grpc_metrics.go Added metrics/counters and methods for blocked sync and login requests
management/server/status/error.go Replaced ErrExtraSettingsNotFound creation and added ErrPeerAlreadyLoggedIn
management/server/mock_server/account_mock.go Added AllowSyncFunc stub and default AllowSync implementation
management/server/loginfilter.go Implemented loginFilter, allowLogin, addLogin, removeLogin
management/server/loginfilter_test.go Unit tests covering filter behaviors
management/server/peer_test.go Removed unused wireGuardPubKey field in test struct
management/server/grpcserver.go Integrated filter checks into Sync and Login, with logging & metrics
management/server/account/manager.go Exposed AllowSync in Manager interface
management/server/account.go Added loginFilter field and invoked filter in SyncAndMarkPeer & OnPeerDisconnected
Comments suppressed due to low confidence (2)

management/server/grpcserver.go:472

  • [nitpick] Using AllowSync for both sync and login flows can be confusing. Consider renaming to a more generic term (e.g. AllowConnection) or splitting into AllowSync and AllowLogin for clarity.
	if !s.accountManager.AllowSync(peerKey.String(), metahashed) {

management/server/loginfilter_test.go:119

  • Add a test verifying that repeated calls to allowLogin with the same metaHash within the filterTimeout window return true as long as the peer isn’t banned.
	s.True(s.filter.allowLogin(pubKey, meta2))

pascal-fischer
pascal-fischer previously approved these changes Jun 20, 2025
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants