Skip to content

Feature Enhancement#1

Merged
davidlu1001 merged 7 commits intomainfrom
claude/sovereign-engineer-protocol-heq2N
Jan 9, 2026
Merged

Feature Enhancement#1
davidlu1001 merged 7 commits intomainfrom
claude/sovereign-engineer-protocol-heq2N

Conversation

@davidlu1001
Copy link
Owner

P0 - Critical Priority

  • P0-1: Cloud-Native Storage Backends - Added DynamoDB and S3 storage backends with the StorageBackend abstraction
  • P0-2: Enhanced Exception Handling - Implemented circuit breakers, retry logic with exponential backoff

P1 - Important

  • P1-1: IPv6 Support - Added dual-stack blocking with separate rule ranges for IPv6
  • P1-2: Incremental Log Processing - Added file caching with ETag tracking and --force-reprocess option

P2 - Enhancement

  • P2-1: AWS WAF IP Set Integration - Full WAF IP Set lifecycle management with optimistic locking
  • P2-2: Structured Logging & CloudWatch Metrics - JsonFormatter for CloudWatch Logs, CloudWatchMetrics class

P3 - Enhancement

  • P3-1: Multi-Signal Detection - ThreatSignals class with weighted scoring for false positive reduction

P4 - Nice to Have

  • P4-1: Enhanced Slack Notifications - Severity-based colors, incident threading, Block Kit formatting
  • P4-2: Athena Integration - Large-scale log analysis via SQL queries on ALB logs

Key Metrics

  • 159 tests passing (all tests)

New CLI Arguments Added

--enhanced-slack - Enable rich Slack notifications
--athena - Enable Athena for large-scale analysis
--athena-database - Custom Athena database name
--athena-output-location - S3 path for Athena results

claude added 7 commits January 9, 2026 08:14
… Block Kit

P4-1 Implementation:
- Add SlackSeverity enum for color-coded notifications (info, warning, low, medium, high, critical)
- Add TIER_TO_SEVERITY mapping for threat tier to color conversion
- Enhance SlackBlock with add_header, add_context, add_fields, and add_actions methods
- Add SlackClient.post_rich_message for formatted messages with attachments
- Add SlackClient.post_incident_notification for structured incident alerts
- Implement thread tracking for incident grouping (_active_threads)
- Add --enhanced-slack CLI flag to enable enhanced notifications
- Add _send_enhanced_slack_notification method with:
  - Severity-based color coding based on highest threat tier
  - Formatted fields with region, pattern, tier breakdown
  - Top offenders grouped by tier with country codes
  - Informational action buttons
- Add helper methods: _get_tier_emoji, _format_duration
- Add 12 new tests for enhanced Slack functionality

Also includes fixes from previous sessions:
- Fix test_timestamp_fix.py to handle new tuple return format
- Fix test_integration.py missing aws_ip_ranges_file parameter
- All 153 tests passing
Athena Integration:
- Add _init_athena() for lazy Athena client initialization
- Add _setup_athena_table() to create/verify ALB log table in Athena
- Add _execute_athena_query() with wait/poll support and timeout
- Add _wait_for_athena_query() with exponential backoff polling
- Add _query_athena_for_attackers() to find IPs matching attack patterns
- Add _get_athena_results_as_counter() to convert Athena results
- Add _process_logs_via_athena() as alternative to S3 GetObject processing
- Add CLI arguments: --athena, --athena-database, --athena-output-location
- Add parameter validation (requires output-location when enabled)
- Add 6 new tests for Athena integration

This completes the full enhancement roadmap:
- P0-1: Cloud-native storage backends (DynamoDB, S3) [DONE]
- P0-2: Enhanced exception handling with circuit breakers [DONE]
- P1-1: IPv6 dual-stack blocking support [DONE]
- P1-2: Incremental log processing with caching [DONE]
- P2-1: AWS WAF IP Set integration [DONE]
- P2-2: Structured logging & CloudWatch metrics [DONE]
- P3-1: Multi-signal threat detection [DONE]
- P4-1: Enhanced Slack notifications with Block Kit [DONE]
- P4-2: Athena integration for large-scale analysis [DONE]

All 159 tests passing.
- Create docs/TECHNICAL_DESIGN.md with full architecture details
- Create docs/CLI_GUIDE.md with complete command reference
- Update README.md with v2.0 changelog and feature overview

Documentation covers:
- Cloud-native storage backends (DynamoDB, S3)
- IPv6 dual-stack blocking
- AWS WAF IP Set integration
- Multi-signal threat detection
- Athena integration for large-scale analysis
- Enhanced Slack notifications
- CloudWatch metrics publishing
… enhanced observability

This commit implements five observability and UX improvements:

1. Auto-download AWS IP ranges
   - Automatically fetch ip-ranges.json from AWS if missing or stale
   - Uses requests library for HTTP downloads
   - Falls back to stale cache on network failure (fail-closed)
   - CLI flag --no-auto-download-ip-ranges for air-gapped environments

2. O(log N) IP range lookups with AWSIPRangeIndex
   - Binary search (bisect) for fast lookups (~13 comparisons for 10K ranges)
   - Service-specific mapping (ROUTE53_HEALTHCHECKS, CLOUDFRONT, ELB, etc.)
   - Replaces O(n) iteration over ~10,000 networks
   - Lookup statistics tracking (hits, misses, hit rate)

3. Enhanced threat score logging
   - Detailed breakdown of why IPs were blocked/skipped
   - Shows pattern score, UA score, status score, service adjustment
   - Borderline cases (within 20 points of threshold) always show details
   - WARNING for high-hit IPs (>=100) that were skipped

4. Secure legitimate service verification
   - Dynamic AWS service mapping (no hardcoded IPs)
   - Route53 Health Checks: UA + IP in ROUTE53_HEALTHCHECKS range
   - ELB HealthChecker: UA + IP in ELB range
   - CloudFront: UA + IP in CLOUDFRONT range
   - Non-AWS services (Datadog, NewRelic, etc.): UA + path matching
   - Spoofing detection: UA claims service but IP doesn't match
   - Fail-closed: No negative score without verification

5. Accurate dry-run summary table
   - Shows expected state changes: "→ WILL BE BLOCKED", "→ WILL BE UNBLOCKED"
   - Distinguishes from current state: "NO CHANGE (blocked)"
   - Shows skipped IPs with their threat scores
   - Block times in local timezone with TZ indicator
   - Legend explaining status meanings

Tests: 195 tests passing (36 new tests for observability features)

Breaking changes: None (backward compatible)
… logging

- Fix _update_nacl_rules_with_registry() to return (ips_to_add, ips_to_remove)
- Pass actual IP sets to _generate_report() for accurate dry-run summary
- Enhance _log_threat_score_details() with tiered logging strategy:
  - BLOCKED IPs: Always INFO with full details
  - High-traffic skipped (>=100 hits or >=2x threshold): INFO + WARNING
  - Borderline skipped (within ±20 of threshold): INFO
  - Other skipped: DEBUG only
- Show verified service name in status (e.g., "SKIPPED (score=33, Route53-Health-Check)")
- Add tests for service name display in dry-run status
AWS IP ranges contain overlapping CIDRs (e.g., a /16 may contain smaller
/26 subnets). The bisect lookup was incorrectly stopping when it found
a /26 that didn't contain the target IP, even though an earlier /16 did.

Fix:
- Search backwards from bisect position up to 100 ranges
- Remove incorrect early exit condition (end_int < ip_int check)
- Apply same fix to is_from_service() and get_service_for_ip()

This fixes the issue where 54.252.193.112 showed "NOT BLOCKED" instead
of "AWS IP (excluded)" because the /26 54.252.79.128/26 was found before
the containing /16 54.252.0.0/16.

Add tests:
- test_overlapping_ranges: Verify IP in /16 but not /26 is found
- test_overlapping_ranges_service_lookup: Verify service lookup works
README.md:
- Update test count badge from 159 to 197
- Add O(log N) AWS IP lookup feature to What's New section

CLI_GUIDE.md:
- Document --no-auto-download-ip-ranges option
- Update --aws-ip-ranges-file section with auto-download behavior
- Document Lambda environment path (/tmp/ip-ranges.json)
- Document 7-day cache expiry and stale fallback
@davidlu1001 davidlu1001 merged commit 1f595cf into main Jan 9, 2026
@davidlu1001 davidlu1001 deleted the claude/sovereign-engineer-protocol-heq2N branch January 9, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants