How kdhungel/ml-api-threat-detection works
The product detects model-extraction behavior by observing prediction requests over time: callers submit patient measurements to the API, which authenticates them, predicts, and logs each patient; BigQuery-backed detection evaluates caller-level behavioral signals and creates alerts. Synthetic and live traffic, plus the Python prototype, support validation. The cloud workflow and major capabilities are documented in the README; some cloud implementation details are unsampled, so those relationships are cited to the README rather than inferred from source.
Main entry points: app/main.py Prediction endpoint · function/main.py Scheduled detector · generate.py Synthetic traffic · requests_live.sql Request views
Components 21
Prediction API
- Prediction endpoint
api/app/main.py - Key authentication
api/app/auth.py - Breast cancer model
api/app/model.py - Request log writers
api/app/logs.py
Log Pipeline
- Cloud Logging
- BigQuery request logs
infra/bigquery/sql/request_logs.sql - Request views
infra/bigquery/sql/requests_live.sql
Detection and Alerts
- BigQuery signal queries
detection/queries - Scheduled detector
detection/function/main.py - Cloud Scheduler
- BigQuery alerts
infra/bigquery/sql/alerts.sql - Log alerting
infra/monitoring - Email notifications
- Looker Studio dashboard
docs/dashboard.md
Traffic and Validation
- Synthetic traffic
traffic/generate.py - Live traffic callers
traffic/live/callers.py - Local log adapter
traffic/live/logs_to_csv.py - Signal calculations
detection/prototype/signals.py - Prototype evaluator
detection/prototype/evaluate.py - Threshold study
detection/prototype/thresholds.py
Other components
- Hospitals and callers
Connections 23
- Hospitals and callers → Prediction endpoint: submit predictions
README.md - Prediction endpoint → Key authentication: checks key
api/app/main.py - Prediction endpoint → Breast cancer model: predicts
api/app/main.py - Prediction endpoint → Request log writers: writes rows
api/app/main.py - Request log writers → Cloud Logging: emits entries
api/app/logs.py - Cloud Logging → BigQuery request logs: sink writes
README.md - BigQuery request logs → Request views: feeds views
README.md - Synthetic traffic → Request views: supplies generated data
README.md - Live traffic callers → Prediction endpoint: calls API
README.md - Live traffic callers → Breast cancer model: uses model answers
traffic/live/callers.py - Local log adapter → Signal calculations: imports features
traffic/live/logs_to_csv.py - Synthetic traffic → Prototype evaluator: provides test data
detection/prototype/evaluate.py - Prototype evaluator → Signal calculations: scores signals
detection/prototype/evaluate.py - Threshold study → Synthetic traffic: simulates callers
detection/prototype/thresholds.py - Threshold study → Signal calculations: tests thresholds
detection/prototype/thresholds.py - Request views → BigQuery signal queries: provides requests
README.md - Cloud Scheduler → Scheduled detector: invokes daily
README.md - Scheduled detector → BigQuery signal queries: computes signals
README.md - Scheduled detector → BigQuery alerts: merges alerts
README.md - Scheduled detector → Cloud Logging: logs alert events
README.md - Cloud Logging → Log alerting: drives metrics
README.md - Log alerting → Email notifications: notifies
README.md - BigQuery alerts → Looker Studio dashboard: feeds dashboard
README.md