Skip to content

admin: Configurable rate-limiting #364

@shazow

Description

@shazow

Right now rate limiting is hardcoded in a few places.

Would be nice to have an admin command to change the ratelimiting configuration of the server. Ideally we wouldn't have to expose fine-grained configurations for the io ratelimiting, perhaps it can be automagically extrapolated based on "number of messages"?

Something like /ratelimit 5 per 3s

The challenge is that the inputLimiter calibration was done iteratively and it will be hard to come up with a formula that will work in all cases. Perhaps a better option would be to simply toggle all of the rate limiting mechanics? Less useful for public servers, but desirable for private servers. Or maybe disable rate limiting for whitelist-enabled servers?

Off the top of my head, these sections would need to be updated:

ratelimit := rateio.NewSimpleLimiter(3, time.Second*3)

ssh-chat/sshd/net.go

Lines 31 to 34 in 5af617f

if l.RateLimit != nil {
// TODO: Configurable Limiter?
conn = ReadLimitConn(conn, l.RateLimit())
}

// NewInputLimiter returns a rateio.Limiter with sensible defaults for
// differentiating between humans typing and bots spamming.
func NewInputLimiter() rateio.Limiter {
grace := time.Second * 3
return &inputLimiter{
Amount: 2 << 14, // ~16kb, should be plenty for a high typing rate/copypasta/large key handshakes.
Frequency: time.Minute * 1,
readCap: 128, // Allow up to 128 bytes per read (anecdotally, 1 character = 52 bytes over ssh)
numRead: -1024 * 1024, // Start with a 1mb grace
timeRead: time.Now().Add(grace),
}
}

(Prompted by #363)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions