Add handshakes.max_rate to limit new handshakes per second - #1643
Open
jrwren wants to merge 2 commits into
Open
Conversation
Nebula is vulnerable to DoS via handshake flooding since each incoming handshake performs expensive DH operations. This adds a token bucket rate limiter to the handshake manager that caps both inbound and outbound new handshakes per second. When the limit is reached, new handshakes are silently dropped and counted via the handshake_manager.rate_limited metric. Configured via handshakes.max_rate (default 0 = unlimited). Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
jrwren
force-pushed
the
jay.wren-handshakes.max_rate
branch
from
March 30, 2026 19:45
a10ebee to
3df60ae
Compare
JackDoan
reviewed
Apr 10, 2026
| # handshakes count against this limit. Once the limit is reached, new handshakes are dropped | ||
| # until the next second. A value of 0 means unlimited (default). | ||
| # This is useful for preventing DoS attacks that attempt to exhaust CPU with handshake crypto. | ||
| # Running `openssl speed ecdhp256` on your hardware can be a good rule of thumb for choosing |
Collaborator
There was a problem hiding this comment.
might note that this is single-core, and that you may wish to scale this number per routine
JackDoan
reviewed
Apr 10, 2026
| return hh.hostinfo | ||
| } | ||
|
|
||
| // Check rate limit for new outbound handshakes |
Collaborator
There was a problem hiding this comment.
from a DOS perspective, does it make sense to rate-limit outbound handshakes?
JackDoan
reviewed
Apr 10, 2026
| hm.metricRateLimited.Inc(1) | ||
| hm.l.WithField("vpnAddr", vpnAddr).Debug("Handshake rate limit reached, dropping outbound handshake") | ||
| hm.Unlock() | ||
| return nil |
Collaborator
There was a problem hiding this comment.
historically this has always been non-nil, is there anywhere that barfs bc we changed that? If we do decide to ratelimit outbounds, I'd have a slight preference to refactor this to be (*HostInfo, error) I think
Remove rate limiting from StartHandshake (outbound) since DoS protection only needs to limit inbound handshakes. This also avoids returning nil from StartHandshake which historically always returned non-nil. Update config comment to note openssl speed is single-core and suggest scaling by routines. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nebula is vulnerable to DoS via handshake flooding since each incoming
handshake performs expensive DH operations. This adds a token bucket
rate limiter to the handshake manager that caps both inbound and
outbound new handshakes per second. When the limit is reached, new
handshakes are silently dropped and counted via the
handshake_manager.rate_limited metric.
Configured via handshakes.max_rate (default 0 = unlimited).
Co-Authored-By: Claude svc-devxp-claude@slack-corp.com