mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 15:26:40 +00:00
report pat id for tokens used more than 120 times per minute
This commit is contained in:
@@ -171,10 +171,6 @@ func (m *AuthMiddleware) checkPATFromRequest(r *http.Request, authHeaderParts []
|
||||
return r, fmt.Errorf("error extracting token: %w", err)
|
||||
}
|
||||
|
||||
if m.patUsageTracker != nil {
|
||||
m.patUsageTracker.IncrementUsage(token)
|
||||
}
|
||||
|
||||
if m.rateLimiter != nil {
|
||||
if !m.rateLimiter.Allow(token) {
|
||||
return r, status.Errorf(status.TooManyRequests, "too many requests")
|
||||
@@ -186,6 +182,11 @@ func (m *AuthMiddleware) checkPATFromRequest(r *http.Request, authHeaderParts []
|
||||
if err != nil {
|
||||
return r, fmt.Errorf("invalid Token: %w", err)
|
||||
}
|
||||
|
||||
if m.patUsageTracker != nil {
|
||||
m.patUsageTracker.IncrementUsage(pat.ID)
|
||||
}
|
||||
|
||||
if time.Now().After(pat.GetExpirationDate()) {
|
||||
return r, fmt.Errorf("token expired")
|
||||
}
|
||||
|
||||
@@ -74,8 +74,11 @@ func (t *PATUsageTracker) reportUsageBuckets() {
|
||||
|
||||
totalTokens := len(snapshot)
|
||||
if totalTokens > 0 {
|
||||
for _, count := range snapshot {
|
||||
for id, count := range snapshot {
|
||||
t.histogram.Record(t.ctx, count)
|
||||
if count > 120 {
|
||||
log.Debugf("High PAT usage detected: token %s used %d times in the last minute", id, count)
|
||||
}
|
||||
}
|
||||
log.Debugf("PAT usage in last minute: %d unique tokens used", totalTokens)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user