Repository navigation
fix(wireguard): remove the peer when a user loses WireGuard access - #99
ImMohammad20000 merged 2 commits into
Conversation
A partial sync (SyncUser / UpdateUsers / chunked updates) only marked as "touched" the users that survived normalizeUsers, which drops users with empty peer_ips or no WireGuard credentials. The panel sends exactly that shape when it releases a user's WireGuard IPs (for example after the user left every WireGuard group), so the user's existing peer was never removed and kept working until the next Start or full sync. The freed IP could also be handed to another user while the old peer still held it in the peer store. Every user with an email in the request now counts as touched; only the normalized users become desired peers, so the stale peer is diffed out and removed from the device and the peer store.
…es access
The stale peer's stats entry must be marked deleted, and a key can move from a user sent with empty peer_ips to another user in the same batch. The handover test fails without the previous commit ("already assigned to user").
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. WalkthroughPartial user reconciliation now tracks nonempty emails from every requested user before normalization. Tests cover removal of stale peers when users lack peer IPs or WireGuard credentials, and transfer of a key to another user in the same batch. ChangesPartial User Sync
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue remains; the change is mergeable after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks the users in a row, Comment |
Problem
When a user loses WireGuard access but stays active (e.g. their groups no longer include any WireGuard inbound), the panel does two things:
peer_ips = [], keeping the public key.peer_ips.In a partial sync (
SyncUser,UpdateUsers, chunked updates),syncUsersPartialReconcilebuilt the set of touched emails only from the users that survivednormalizeUsers.normalizeUsersdrops users with emptypeer_ipsor no WireGuard credentials. So this user was never touched, and their existing peer was never removed. As a result:PeerStore.Disable and delete were not affected, because the panel still sends the stored
peer_ips(without inbounds) in those cases.Change
PeerStore, and its stats entry is marked deleted.peer_ipsto another user in the same batch. Previously that was rejected with "already assigned to user ...".syncUsersFullis unchanged.Tests
backend/wireguard/user_sync_test.go, each test failing without the change:TestUpdateUsersRemovesPeerWhenUserLosesWireguardAccess: two cases (emptypeer_ips, and nowireguardproxy at all). Exactly one Remove is applied, the peer leaves thePeerStore, and the stats entry is marked deleted.TestUpdateUsersAllowsKeyHandoverFromUserWhoLostAccess: the key handover in one batch.go test ./backend/wireguard/ ./config/ ./controller/ -p 1passes, andgo vet/gofmt -lare clean.Summary by CodeRabbit