FreeRADIUS, FastAPI, PostgreSQL ve Redis kullanarak geliştirilmiş PAP tabanlı Network Access Control sistemi.
Kullanıcı/NAS ↓ FreeRADIUS (1812/udp auth, 1813/udp acct) ↓ rlm_rest (HTTP JSON) FastAPI Policy Engine (8000/tcp) ↓ ↓ PostgreSQL Redis (Kullanıcılar, (Oturum cache, VLAN, Accounting) Rate limiting)
1. Repoyu klonla
git clone https://github.com/BatuhanBaskurt/nac-project.git
cd nac-project2. .env dosyasını oluştur
cp .env.example .env3. Sistemi başlat
docker compose up -d --build4. Servisleri kontrol et
docker psŞu 4 container çalışıyor olmalı:
| Container | Açıklama |
|---|---|
| nac-freeradius | RADIUS sunucusu |
| nac-api | FastAPI policy engine |
| nac-postgres | Veritabanı |
| nac-redis | Cache ve rate limiting |
| Kullanıcı | Şifre | Grup | VLAN |
|---|---|---|---|
| admin | admin123 | admin | 10 |
| employee | emp123 | employee | 20 |
| guest | guest123 | guest | 30 |
# Başarılı giriş
docker exec nac-freeradius radtest admin admin123 localhost 0 testing123
# Başarısız giriş
docker exec nac-freeradius radtest admin yanliksifre localhost 0 testing123
# Olmayan kullanıcı
docker exec nac-freeradius radtest olmayan sifre123 localhost 0 testing123# Health check
curl http://localhost:8000/health
# Kullanıcı listesi
curl http://localhost:8000/users
# Aktif oturumlar
curl http://localhost:8000/sessions/active# Oturum başlat
docker exec nac-freeradius bash -c 'echo "User-Name=admin,Acct-Status-Type=Start,Acct-Session-Id=session001,NAS-IP-Address=127.0.0.1" | radclient localhost acct testing123'
# Aktif oturumu gör
curl http://localhost:8000/sessions/active
# Oturum bitir
docker exec nac-freeradius bash -c 'echo "User-Name=admin,Acct-Status-Type=Stop,Acct-Session-Id=session001,NAS-IP-Address=127.0.0.1,Acct-Session-Time=120" | radclient localhost acct testing123'
# PostgreSQL kaydını kontrol et
docker exec nac-postgres psql -U radius -d radius -c "SELECT username, acctstarttime, acctstoptime, acctsessiontime FROM radacct;"5 başarısız denemeden sonra hesap 5 dakika bloklanır.
# Önce sayacı sıfırla
docker exec nac-redis redis-cli -a redis123 DEL ratelimit:admin
# 6 kez dene
for i in 1 2 3 4 5 6; do
echo "Deneme $i:"
curl -s -X POST http://localhost:8000/authorize \
-H "Content-Type: application/json" \
-d '{"User-Name": {"type": "string", "value": ["admin"]}, "User-Password": {"type": "string", "value": ["yanliksifre"]}}'
echo ""
doneBeklenen çıktı:
- Deneme 1-5 →
Invalid credentials - Deneme 6 →
Too many attempts
| Endpoint | Metot | Açıklama |
|---|---|---|
/health |
GET | Servis durumu |
/authorize |
POST | FreeRADIUS authorize isteği |
/auth |
POST | FreeRADIUS authenticate isteği |
/accounting |
POST | Oturum kaydı |
/users |
GET | Kullanıcı listesi |
/sessions/active |
GET | Aktif oturumlar (Redis) |
- Rate Limiting — 5 başarısız denemede 5 dakika blok (Redis)
- VLAN Segmentasyonu — Grup bazlı ağ ayrımı
- Şifre Kontrolü — API katmanında doğrulama
- İzole Docker Network — Servisler arası güvenli iletişim
- Environment Variables — Şifreler
.envdosyasında, Git'e gitmiyor
.envdosyasını asla Git'e commit etme- Üretim ortamında
testing123secret'ını değiştir docker compose up -d --buildkomutu ile tüm sistem ayağa kalkar