Dork Atolyesi, Go ile gelistirilmis basit bir web uygulamasidir. Kullanici bir domain girer, uygulama hedef domain icin Google Dork sorgulari uretir, hedefin HTTP/HTTPS durumunu kontrol eder ve arama gecmisini PostgreSQL uzerinde saklar.
Bu repo; Docker imaji, Kubernetes manifestleri, Persistent Volume/PVC, NetworkPolicy, HorizontalPodAutoscaler ve Jenkins tabanli CI/CD pipeline dosyalarini icerir. Kubernetes ortami olarak Google Kubernetes Engine (GKE), imaj deposu olarak Google Artifact Registry hedeflenmistir.
Uygulama iki ana parcadan olusur:
- Go backend: HTTP server, API endpointleri, health/readiness endpointleri ve PostgreSQL baglantisini yonetir.
- HTML frontend: Kullanici formu, dork sonuclari ve gecmis sorgu ekranlarini sunar.
Temel endpointler:
| Endpoint | Gorev |
|---|---|
/ |
Web arayuzu |
/api/dorks?domain=example.com |
JSON formatinda dork uretimi |
/history |
Kayitli sorgu gecmisi |
/health |
Liveness probe |
/ready |
Readiness probe, veritabani hazirligini kontrol eder |
PostgreSQL, tarama gecmisini kalici olarak saklamak icin kullanilir. Uygulama Kubernetes icinde DATABASE_URL degerini postgres-secret Secret nesnesinden alir.
Sistemin bulut ortami su sekildedir:
Kullanici
|
v
GKE LoadBalancer Service
|
v
dork-backend Deployment (Go web uygulamasi, 2+ pod)
|
v
postgres-service (ClusterIP)
|
v
postgres-db Deployment
|
v
postgres-pvc (kalici disk)
Dis dunyaya yalnizca dork-backend-service acilir. PostgreSQL servisi ClusterIP oldugu icin cluster disindan erisilemez.
Kubernetes kaynaklari k8s/ dizinindedir:
| Kaynak | Aciklama |
|---|---|
backend-deployment.yaml |
Go uygulamasini calistiran Deployment. RollingUpdate stratejisi, readiness/liveness probe ve resource limitleri icerir. |
backend-service.yaml |
Uygulamayi GKE LoadBalancer ile internete acar. |
postgres-deployment.yaml |
PostgreSQL containerini calistirir. |
postgres-service.yaml |
PostgreSQL icin sadece cluster ici erisim saglar. |
postgres-pvc.yaml |
PostgreSQL verilerini kalici disk uzerinde saklar. |
postgres-secret.example.yaml |
Ornek PostgreSQL Secret dosyasi. Gercek sifreler repo icine yazilmaz. |
admin-secret.example.yaml |
Ornek admin token Secret dosyasi. Gecmis silme islemleri icin kullanilir. |
hpa.yaml |
Backend podlarini CPU kullanimina gore otomatik olceklendirir. |
network-policy.yaml |
PostgreSQL'e sadece backend podlarindan erisim verir; backend icin gerekli ingress/egress trafigini tanimlar. |
Imaj cok asamali build ile uretilir:
golang:1.26.2-alpineimaji icinde Go binary derlenir.alpine:latestruntime imajina yalnizca binary ve frontend dosyalari kopyalanir.- Uygulama container icinde
9867portundan calisir.
Yerel build:
docker build -t projectofdork-local:latest .Yerel calistirma:
docker run --rm -p 9867:9867 \
-e DATABASE_URL="postgres://dorkuser:password@host.docker.internal:5432/dorkdb?sslmode=disable" \
projectofdork-local:latestVeritabani olmadan sadece UI/API kontrolu icin DATABASE_URL verilmeden de calistirilabilir. Kubernetes ortaminda DB_REQUIRED=true oldugu icin veritabani hazir degilse pod ready olmaz.
CI/CD icin Jenkins kullanilir. Jenkinsfile su asamalari calistirir:
- Repository checkout edilir.
- Commit SHA ve Jenkins build numarasindan imaj tag'i uretilir.
go test ./...calistirilir.- Docker imaji build edilir.
- Jenkins makinesindeki aktif
gcloudoturumu ile Google Cloud projesi secilir ve Docker auth yapilir. - Imaj Google Artifact Registry'ye push edilir.
- GKE cluster credentials alinir.
- Secret, PVC, Deployment, Service, HPA ve NetworkPolicy manifestleri uygulanir.
- Deployment imaji yeni tag ile guncellenir.
kubectl rollout statusile rolling update sonucu beklenir.kubectl get service dork-backend-serviceile public IP Jenkins loguna yazdirilir.
Jenkinsfile'in repoda bulunmasi tek basina otomasyonun aktif oldugu anlamina gelmez. Otomasyonun gercekten calismasi icin Jenkins tarafinda su kurulumlar yapilmis olmalidir:
- Jenkins job tipi
Pipeline from SCMolmali. - Repository URL bu GitHub reposunu gostermeli.
- Script Path
Jenkinsfileolmali. - Jenkins credential kayitlari olusturulmali.
- Jenkins'i calistiran kullanici daha once
gcloud auth loginile Google Cloud'a giris yapmis olmali. JenkinsfileicindekipollSCM('H/2 * * * *')tetikleyicisi ilk build sonrasinda yaklasik 2 dakikada bir GitHub'i kontrol eder ve yeni commit varsa build baslatir.
Jenkins sunucusu internetten erisilebiliyorsa GitHub webhook daha hizli tetikleme saglar. Lokal Jenkins icin SCM polling daha pratiktir.
Jenkins > Manage Credentials altinda su credential ID'leri beklenir:
postgres-user Secret text
postgres-password Secret text
postgres-db Secret text
Bu projede servis hesabi JSON key kullanilmamaktadir. Google Cloud organizasyon politikasinda iam.disableServiceAccountKeyCreation aktif oldugu icin Jenkins, makinedeki aktif gcloud kullanici oturumuyla calisir.
Jenkins'i calistiran Google kullanicisinda en az su yetkiler bulunmalidir:
- Artifact Registry Writer
- Kubernetes Engine Developer
- Service Account User
Detayli Jenkins kurulumu icin: docs/jenkins-gke.md
Bu projede public IP, dork-backend-service LoadBalancer servisinden gelir.
Cloud Shell veya gcloud/kubectl kurulu bir makinede:
gcloud container clusters get-credentials dork-cluster \
--location europe-west1-b \
--project project-444d504d-38fb-4e0d-83e
kubectl get service dork-backend-serviceSadece IP'yi almak icin:
kubectl get service dork-backend-service \
-o jsonpath='{.status.loadBalancer.ingress[0].ip}'Eger EXTERNAL-IP kisminda <pending> gorunuyorsa LoadBalancer henuz IP almamistir. Biraz bekleyip tekrar kontrol edilmelidir.
Ilk deploy icin Secret olusturulur:
kubectl create secret generic postgres-secret \
--from-literal=POSTGRES_USER=dorkuser \
--from-literal=POSTGRES_PASSWORD='guclu-bir-sifre' \
--from-literal=POSTGRES_DB=dorkdb \
--from-literal=DATABASE_URL='postgres://dorkuser:guclu-bir-sifre@postgres-service:5432/dorkdb?sslmode=disable'Normal kullanicilar yalnizca kendi tarayici cookie oturumlarina ait gecmisi gorur ve silebilir. Adminin tum kullanici gecmisini gorebilmesi ve toplu yonetebilmesi icin admin token Secret'i olusturulur. Bu Secret yoksa uygulama calismaya devam eder, ancak admin modu kapali kalir:
kubectl create secret generic admin-secret \
--from-literal=ADMIN_TOKEN='uzun-rastgele-bir-token'Manifestleri uygulama:
kubectl apply -f k8s/postgres-pvc.yaml
kubectl apply -f k8s/postgres-deployment.yaml
kubectl apply -f k8s/postgres-service.yaml
kubectl apply -f k8s/backend-deployment.yaml
kubectl apply -f k8s/backend-service.yaml
kubectl apply -f k8s/hpa.yaml
kubectl apply -f k8s/network-policy.yamlDurum kontrolu:
kubectl get pods
kubectl get services
kubectl get pvc
kubectl get hpa
kubectl get networkpolicyBackend Deployment, Go uygulamasini birden fazla pod olarak calistirir. Readiness probe /ready endpointini kullanir; veritabani hazir degilse pod trafige alinmaz. Liveness probe /health endpointini kullanir; uygulama cevap vermezse Kubernetes podu yeniden baslatir.
Backend Service LoadBalancer tipindedir. Bu servis GKE uzerinden public IP alir ve kullanicidan gelen HTTP trafigini backend podlarina dagitir.
PostgreSQL Service ClusterIP tipindedir. Bu nedenle veritabani internete acilmaz; sadece cluster icinden erisilebilir.
postgres-pvc.yaml, PostgreSQL verileri icin 5Gi kalici depolama ister. postgres-deployment.yaml bu PVC'yi /var/lib/postgresql/data dizinine mount eder. Boylece PostgreSQL podu silinse bile veriler Persistent Volume uzerinde kalir.
Kontrol:
kubectl get pvc postgres-pvc
kubectl describe pvc postgres-pvcnetwork-policy.yaml iki temel kural tanimlar:
- PostgreSQL podlarina sadece
app=dork-backendetiketli backend podlari TCP 5432 portundan erisebilir. - Backend podlari 9867 portundan trafik alabilir; PostgreSQL, DNS, HTTP ve HTTPS cikis trafigine izinlidir.
Kontrol:
kubectl get networkpolicy
kubectl describe networkpolicy postgres-allow-backend-only
kubectl describe networkpolicy backend-network-policyNot: GKE'de NetworkPolicy etkisinin uygulanmasi icin cluster tarafinda NetworkPolicy destegi aktif olmalidir. GKE Dataplane V2 veya NetworkPolicy etkin bir cluster bu kurallari uygular.
Rolling update, yeni imaj tag'i Deployment'a verildiginde Kubernetes'in podlari sirayla yenilemesidir. Bu projede backend-deployment.yaml icinde RollingUpdate stratejisi tanimlidir.
Manuel rolling update ornegi:
kubectl set image deployment/dork-backend \
dork-backend-container=europe-west1-docker.pkg.dev/project-444d504d-38fb-4e0d-83e/dork-repo/projectofdork-app:NEW_TAG
kubectl rollout status deployment/dork-backend
kubectl rollout history deployment/dork-backendJenkins pipeline da deploy sirasinda ayni mantikla kubectl set image calistirir.
Son deploy sorunluysa once rollout history incelenir:
kubectl rollout history deployment/dork-backendBir onceki surume donmek icin:
kubectl rollout undo deployment/dork-backend
kubectl rollout status deployment/dork-backendBelirli bir revision'a donmek icin:
kubectl rollout undo deployment/dork-backend --to-revision=2Otomatik olcekleme HPA ile yapilir:
kubectl get hpa
kubectl describe hpa dork-backend-hpaBu projede backend podlari CPU kullanimina gore en az 1, en fazla 5 replika olacak sekilde olceklenir.
Manuel olcekleme demosu:
kubectl scale deployment dork-backend --replicas=3
kubectl get pods -l app=dork-backendHPA aktifken uzun vadeli replika sayisini HPA tekrar kendi hedeflerine gore ayarlayabilir.
Backend'i yerelde calistirma:
cd src/backend
go mod download
go run main.goTest:
cd src/backend
go test ./...API ornegi:
curl "http://localhost:9867/api/dorks?domain=example.com"Admin gecmis islemleri icin /history sayfasinda admin token girilerek admin modu acilir. Admin modu tum oturumlarin gecmisini listeler; normal mod yalnizca mevcut tarayici cookie oturumuna ait gecmisi gosterir. Komut satirindan tum gecmisi silmek icin:
curl -X POST "http://localhost:9867/" \
-H "X-Admin-Token: uzun-rastgele-bir-token" \
-d "action=clear_history" \
-d "history_scope=all".
├── Dockerfile
├── Jenkinsfile
├── README.md
├── docs
│ └── jenkins-gke.md
├── k8s
│ ├── backend-deployment.yaml
│ ├── backend-service.yaml
│ ├── admin-secret.example.yaml
│ ├── hpa.yaml
│ ├── network-policy.yaml
│ ├── postgres-deployment.yaml
│ ├── postgres-pvc.yaml
│ ├── postgres-secret.example.yaml
│ └── postgres-service.yaml
└── src
├── backend
│ ├── database
│ ├── handlers
│ ├── models
│ ├── go.mod
│ └── main.go
└── frontend
├── history.html
└── index.html
Bu arac yalnizca egitim ve yetkili guvenlik testi amaciyla kullanilmalidir. Hedef sistemlerde izinsiz test yapmak hukuki ve etik sorunlara yol acabilir. Kullanim sorumlulugu tamamen kullaniciya aittir.