add whitelisted ips to secret key auth handler

This commit is contained in:
Stanley Dimant
2022-10-02 16:57:31 +02:00
parent 8236d355a2
commit d866223069

View File

@@ -25,6 +25,7 @@ public class SecretKeyAuthenticationHandler
private readonly object failedAuthLock = new();
private readonly int _failedAttemptsForTempBan;
private readonly int _tempBanMinutes;
private List<string> _whitelistedIps = new();
public void ClearUnauthorizedUsers()
{
@@ -135,6 +136,8 @@ public class SecretKeyAuthenticationHandler
logger.LogWarning("Failed authorization from {ip}", ip);
lock (failedAuthLock)
{
if (!_whitelistedIps.Any(w => ip.Contains(w)))
{
if (failedAuthorizations.TryGetValue(ip, out var auth))
{
@@ -146,6 +149,8 @@ public class SecretKeyAuthenticationHandler
}
}
}
metrics.IncCounter(MetricsAPI.CounterAuthenticationFailures);
return new AuthReply() { Success = false, Uid = string.Empty };
}
@@ -168,5 +173,6 @@ public class SecretKeyAuthenticationHandler
var config = configuration.GetRequiredSection("MareSynchronos");
_failedAttemptsForTempBan = config.GetValue<int>("FailedAuthForTempBan", 5);
_tempBanMinutes = config.GetValue<int>("TempBanDurationInMinutes", 30);
_whitelistedIps = config.GetValue<List<string>>("WhitelistedIps", new List<string>());
}
}