feat: implement automated account enforcement service with RADIUS disconnect capabilities and add RADIUS management service
Build and Push Docker Image to Gitea Container Registry / build-and-push (push) Successful in 1m15s

This commit is contained in:
Tygozwolle
2026-07-24 20:29:11 +02:00
parent d88e03ea09
commit 87d6d7e764
2 changed files with 24 additions and 24 deletions
@@ -87,20 +87,19 @@ public class AccountEnforcementService : BackgroundService
// Disable the account // Disable the account
profile.Status = "Expired"; profile.Status = "Expired";
// Remove Cleartext-Password from radcheck so FreeRADIUS rejects future auth // Scramble the password so the device prompts for new credentials
var checks = await db.RadCheck var check = await db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Cleartext-Password", ct);
.Where(rc => rc.Username == profile.Username) if (check != null)
.ToListAsync(ct);
db.RadCheck.RemoveRange(checks);
// Insert Auth-Type := Reject to explicitly deny
db.RadCheck.Add(new RadCheck
{ {
Username = profile.Username, check.Value = "REJECT_" + Guid.NewGuid().ToString("N").Substring(0, 8);
Attribute = "Auth-Type", }
Op = ":=",
Value = "Reject" // Cleanup any old Auth-Type Reject entries
}); var rejectCheck = await db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Auth-Type", ct);
if (rejectCheck != null)
{
db.RadCheck.Remove(rejectCheck);
}
_logger.LogInformation("Account '{Username}' disabled. Reason: {Reason}", profile.Username, reason); _logger.LogInformation("Account '{Username}' disabled. Reason: {Reason}", profile.Username, reason);
+12 -11
View File
@@ -272,17 +272,18 @@ public class RadiusService : IRadiusService
profile.Status = "Revoked"; profile.Status = "Revoked";
// Remove Cleartext-Password and insert Auth-Type := Reject // Scramble the password instead of Auth-Type := Reject so devices prompt for new credentials
var checks = await _db.RadCheck.Where(rc => rc.Username == profile.Username).ToListAsync(); var check = await _db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Cleartext-Password");
_db.RadCheck.RemoveRange(checks); if (check != null)
_db.RadCheck.Add(new RadCheck
{ {
Username = profile.Username, check.Value = "REJECT_" + Guid.NewGuid().ToString("N").Substring(0, 8);
Attribute = "Auth-Type", }
Op = ":=",
Value = "Reject" var rejectCheck = await _db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Auth-Type");
}); if (rejectCheck != null)
{
_db.RadCheck.Remove(rejectCheck);
}
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();
@@ -331,7 +332,7 @@ public class RadiusService : IRadiusService
}); });
} }
if (profile.Status == "Revoked") if (profile.Status == "Revoked" || profile.Status == "Expired")
{ {
profile.Status = "Active"; profile.Status = "Active";
var rejectCheck = await _db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Auth-Type"); var rejectCheck = await _db.RadCheck.FirstOrDefaultAsync(rc => rc.Username == profile.Username && rc.Attribute == "Auth-Type");