feat(Production): Complete production deployment infrastructure

- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
This commit is contained in:
2025-10-25 19:18:37 +02:00
parent caa85db796
commit fc3d7e6357
83016 changed files with 378904 additions and 20919 deletions

View File

@@ -5,15 +5,25 @@ declare(strict_types=1);
namespace App\Framework\Waf\MachineLearning\Extractors;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\MachineLearning\Core\FeatureExtractorMetadata;
use App\Framework\MachineLearning\Core\FeatureExtractorPerformance;
use App\Framework\MachineLearning\ValueObjects\Feature;
use App\Framework\MachineLearning\ValueObjects\FeatureType;
use App\Framework\Waf\Analysis\ValueObjects\RequestAnalysisData;
use App\Framework\Waf\MachineLearning\BehaviorType;
use App\Framework\Waf\MachineLearning\FeatureExtractorInterface;
use App\Framework\Waf\MachineLearning\ValueObjects\BehaviorFeature;
use App\Framework\Waf\MachineLearning\WafFeatureExtractor;
/**
* Extracts request frequency and rate-based behavioral features
*
* Uses atomic interface composition pattern (NO extends):
* - WafFeatureExtractor: Domain-specific feature extraction
* - FeatureExtractorMetadata: Metadata and configuration
* - FeatureExtractorPerformance: Performance characteristics
*/
final class FrequencyFeatureExtractor implements FeatureExtractorInterface
final class FrequencyFeatureExtractor implements
WafFeatureExtractor,
FeatureExtractorMetadata,
FeatureExtractorPerformance
{
public function __construct(
private readonly bool $enabled = true,
@@ -24,9 +34,9 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
) {
}
public function getBehaviorType(): BehaviorType
public function getFeatureType(): FeatureType
{
return BehaviorType::REQUEST_FREQUENCY;
return FeatureType::FREQUENCY;
}
public function canExtract(RequestAnalysisData $requestData): bool
@@ -78,12 +88,12 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract basic request rate
*/
private function extractRequestRate(array $requests, int $windowSeconds): BehaviorFeature
private function extractRequestRate(array $requests, int $windowSeconds): Feature
{
$count = count($requests);
$rate = $windowSeconds > 0 ? $count / $windowSeconds : 0.0;
return BehaviorFeature::frequency(
return Feature::frequency(
name: "request_rate_{$windowSeconds}s",
count: $count,
timeWindow: $windowSeconds
@@ -93,11 +103,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract burst detection rate
*/
private function extractBurstRate(array $requests, int $windowSeconds): BehaviorFeature
private function extractBurstRate(array $requests, int $windowSeconds): Feature
{
if (count($requests) < 2) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: "burst_rate_{$windowSeconds}s",
value: 0.0,
unit: 'requests/second'
@@ -124,8 +134,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$maxRate = max($maxRate, $rate);
}
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: "burst_rate_{$windowSeconds}s",
value: $maxRate,
unit: 'requests/second'
@@ -135,7 +145,7 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract sustained rate (longer window)
*/
private function extractSustainedRate(array $requests, int $windowSeconds): BehaviorFeature
private function extractSustainedRate(array $requests, int $windowSeconds): Feature
{
$count = count($requests);
@@ -149,8 +159,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$sustainedCount = count($sustainedRequests);
$rate = $windowSeconds > 0 ? $sustainedCount / $windowSeconds : 0.0;
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: "sustained_rate_{$windowSeconds}s",
value: $rate,
unit: 'requests/second'
@@ -160,11 +170,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract inter-arrival time variance
*/
private function extractInterArrivalVariance(array $requests): BehaviorFeature
private function extractInterArrivalVariance(array $requests): Feature
{
if (count($requests) < 3) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'inter_arrival_variance',
value: 0.0,
unit: 'seconds²'
@@ -180,8 +190,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$interArrivals[] = $requests[$i] - $requests[$i - 1];
}
return BehaviorFeature::statistical(
type: $this->getBehaviorType(),
return Feature::statistical(
type: $this->getFeatureType(),
name: 'inter_arrival_variance',
values: $interArrivals,
statistic: 'variance'
@@ -191,11 +201,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract request spacing regularity
*/
private function extractRequestSpacing(array $requests): BehaviorFeature
private function extractRequestSpacing(array $requests): Feature
{
if (count($requests) < 3) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'request_spacing_regularity',
value: 0.0,
unit: 'coefficient'
@@ -211,8 +221,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
}
$mean = array_sum($interArrivals) / count($interArrivals);
$variance = BehaviorFeature::statistical(
type: $this->getBehaviorType(),
$variance = Feature::statistical(
type: $this->getFeatureType(),
name: 'temp_variance',
values: $interArrivals,
statistic: 'variance'
@@ -221,8 +231,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
// Coefficient of variation (lower = more regular)
$regularity = $mean > 0 ? sqrt($variance) / $mean : 1.0;
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'request_spacing_regularity',
value: 1.0 / (1.0 + $regularity), // Normalize: 1 = perfectly regular, 0 = very irregular
unit: 'regularity_score'
@@ -232,11 +242,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract periodicity score using autocorrelation
*/
private function extractPeriodicityScore(array $requests): BehaviorFeature
private function extractPeriodicityScore(array $requests): Feature
{
if (count($requests) < 10) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'periodicity_score',
value: 0.0,
unit: 'correlation'
@@ -251,8 +261,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$duration = $maxTime - $minTime;
if ($duration <= 0) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'periodicity_score',
value: 0.0,
unit: 'correlation'
@@ -279,8 +289,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$maxCorrelation = max($maxCorrelation, abs($correlation));
}
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'periodicity_score',
value: $maxCorrelation,
unit: 'correlation'
@@ -290,11 +300,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract time of day pattern
*/
private function extractTimeOfDayPattern(array $requests): BehaviorFeature
private function extractTimeOfDayPattern(array $requests): Feature
{
if (empty($requests)) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'time_of_day_entropy',
value: 0.0,
unit: 'bits'
@@ -309,8 +319,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$hourDistribution[$hour]++;
}
return BehaviorFeature::entropy(
type: $this->getBehaviorType(),
return Feature::entropy(
type: $this->getFeatureType(),
name: 'time_of_day_entropy',
distribution: $hourDistribution
);
@@ -319,11 +329,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract weekday pattern
*/
private function extractWeekdayPattern(array $requests): BehaviorFeature
private function extractWeekdayPattern(array $requests): Feature
{
if (empty($requests)) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'weekday_entropy',
value: 0.0,
unit: 'bits'
@@ -338,8 +348,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$dayDistribution[$day]++;
}
return BehaviorFeature::entropy(
type: $this->getBehaviorType(),
return Feature::entropy(
type: $this->getFeatureType(),
name: 'weekday_entropy',
distribution: $dayDistribution
);
@@ -348,11 +358,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract frequency distribution entropy
*/
private function extractFrequencyEntropy(array $requests): BehaviorFeature
private function extractFrequencyEntropy(array $requests): Feature
{
if (count($requests) < 5) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'frequency_entropy',
value: 0.0,
unit: 'bits'
@@ -369,8 +379,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$buckets[$bucket] = ($buckets[$bucket] ?? 0) + 1;
}
return BehaviorFeature::entropy(
type: $this->getBehaviorType(),
return Feature::entropy(
type: $this->getFeatureType(),
name: 'frequency_entropy',
distribution: array_values($buckets)
);
@@ -379,11 +389,11 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
/**
* Extract burstiness measure
*/
private function extractBurstiness(array $requests): BehaviorFeature
private function extractBurstiness(array $requests): Feature
{
if (count($requests) < 5) {
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'burstiness',
value: 0.0,
unit: 'burstiness_coefficient'
@@ -399,8 +409,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
}
$mean = array_sum($interArrivals) / count($interArrivals);
$variance = BehaviorFeature::statistical(
type: $this->getBehaviorType(),
$variance = Feature::statistical(
type: $this->getFeatureType(),
name: 'temp_variance',
values: $interArrivals,
statistic: 'variance'
@@ -411,8 +421,8 @@ final class FrequencyFeatureExtractor implements FeatureExtractorInterface
$stdDev = sqrt($variance);
$burstiness = ($stdDev + $mean) > 0 ? ($stdDev - $mean) / ($stdDev + $mean) : 0.0;
return BehaviorFeature::create(
type: $this->getBehaviorType(),
return Feature::create(
type: $this->getFeatureType(),
name: 'burstiness',
value: $burstiness,
unit: 'burstiness_coefficient'