runbooks 1.1.4__py3-none-any.whl → 1.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- runbooks/__init__.py +31 -2
- runbooks/__init___optimized.py +18 -4
- runbooks/_platform/__init__.py +1 -5
- runbooks/_platform/core/runbooks_wrapper.py +141 -138
- runbooks/aws2/accuracy_validator.py +812 -0
- runbooks/base.py +7 -0
- runbooks/cfat/assessment/compliance.py +1 -1
- runbooks/cfat/assessment/runner.py +1 -0
- runbooks/cfat/cloud_foundations_assessment.py +227 -239
- runbooks/cli/__init__.py +1 -1
- runbooks/cli/commands/cfat.py +64 -23
- runbooks/cli/commands/finops.py +1005 -54
- runbooks/cli/commands/inventory.py +138 -35
- runbooks/cli/commands/operate.py +9 -36
- runbooks/cli/commands/security.py +42 -18
- runbooks/cli/commands/validation.py +432 -18
- runbooks/cli/commands/vpc.py +81 -17
- runbooks/cli/registry.py +22 -10
- runbooks/cloudops/__init__.py +20 -27
- runbooks/cloudops/base.py +96 -107
- runbooks/cloudops/cost_optimizer.py +544 -542
- runbooks/cloudops/infrastructure_optimizer.py +5 -4
- runbooks/cloudops/interfaces.py +224 -225
- runbooks/cloudops/lifecycle_manager.py +5 -4
- runbooks/cloudops/mcp_cost_validation.py +252 -235
- runbooks/cloudops/models.py +78 -53
- runbooks/cloudops/monitoring_automation.py +5 -4
- runbooks/cloudops/notebook_framework.py +177 -213
- runbooks/cloudops/security_enforcer.py +125 -159
- runbooks/common/accuracy_validator.py +11 -0
- runbooks/common/aws_pricing.py +349 -326
- runbooks/common/aws_pricing_api.py +211 -212
- runbooks/common/aws_profile_manager.py +40 -36
- runbooks/common/aws_utils.py +74 -79
- runbooks/common/business_logic.py +126 -104
- runbooks/common/cli_decorators.py +36 -60
- runbooks/common/comprehensive_cost_explorer_integration.py +455 -463
- runbooks/common/cross_account_manager.py +197 -204
- runbooks/common/date_utils.py +27 -39
- runbooks/common/decorators.py +29 -19
- runbooks/common/dry_run_examples.py +173 -208
- runbooks/common/dry_run_framework.py +157 -155
- runbooks/common/enhanced_exception_handler.py +15 -4
- runbooks/common/enhanced_logging_example.py +50 -64
- runbooks/common/enhanced_logging_integration_example.py +65 -37
- runbooks/common/env_utils.py +16 -16
- runbooks/common/error_handling.py +40 -38
- runbooks/common/lazy_loader.py +41 -23
- runbooks/common/logging_integration_helper.py +79 -86
- runbooks/common/mcp_cost_explorer_integration.py +476 -493
- runbooks/common/mcp_integration.py +63 -74
- runbooks/common/memory_optimization.py +140 -118
- runbooks/common/module_cli_base.py +37 -58
- runbooks/common/organizations_client.py +175 -193
- runbooks/common/patterns.py +23 -25
- runbooks/common/performance_monitoring.py +67 -71
- runbooks/common/performance_optimization_engine.py +283 -274
- runbooks/common/profile_utils.py +111 -37
- runbooks/common/rich_utils.py +201 -141
- runbooks/common/sre_performance_suite.py +177 -186
- runbooks/enterprise/__init__.py +1 -1
- runbooks/enterprise/logging.py +144 -106
- runbooks/enterprise/security.py +187 -204
- runbooks/enterprise/validation.py +43 -56
- runbooks/finops/__init__.py +26 -30
- runbooks/finops/account_resolver.py +1 -1
- runbooks/finops/advanced_optimization_engine.py +980 -0
- runbooks/finops/automation_core.py +268 -231
- runbooks/finops/business_case_config.py +184 -179
- runbooks/finops/cli.py +660 -139
- runbooks/finops/commvault_ec2_analysis.py +157 -164
- runbooks/finops/compute_cost_optimizer.py +336 -320
- runbooks/finops/config.py +20 -20
- runbooks/finops/cost_optimizer.py +484 -618
- runbooks/finops/cost_processor.py +332 -214
- runbooks/finops/dashboard_runner.py +1006 -172
- runbooks/finops/ebs_cost_optimizer.py +991 -657
- runbooks/finops/elastic_ip_optimizer.py +317 -257
- runbooks/finops/enhanced_mcp_integration.py +340 -0
- runbooks/finops/enhanced_progress.py +32 -29
- runbooks/finops/enhanced_trend_visualization.py +3 -2
- runbooks/finops/enterprise_wrappers.py +223 -285
- runbooks/finops/executive_export.py +203 -160
- runbooks/finops/helpers.py +130 -288
- runbooks/finops/iam_guidance.py +1 -1
- runbooks/finops/infrastructure/__init__.py +80 -0
- runbooks/finops/infrastructure/commands.py +506 -0
- runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
- runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
- runbooks/finops/markdown_exporter.py +337 -174
- runbooks/finops/mcp_validator.py +1952 -0
- runbooks/finops/nat_gateway_optimizer.py +1512 -481
- runbooks/finops/network_cost_optimizer.py +657 -587
- runbooks/finops/notebook_utils.py +226 -188
- runbooks/finops/optimization_engine.py +1136 -0
- runbooks/finops/optimizer.py +19 -23
- runbooks/finops/rds_snapshot_optimizer.py +367 -411
- runbooks/finops/reservation_optimizer.py +427 -363
- runbooks/finops/scenario_cli_integration.py +64 -65
- runbooks/finops/scenarios.py +1277 -438
- runbooks/finops/schemas.py +218 -182
- runbooks/finops/snapshot_manager.py +2289 -0
- runbooks/finops/types.py +3 -3
- runbooks/finops/validation_framework.py +259 -265
- runbooks/finops/vpc_cleanup_exporter.py +189 -144
- runbooks/finops/vpc_cleanup_optimizer.py +591 -573
- runbooks/finops/workspaces_analyzer.py +171 -182
- runbooks/integration/__init__.py +89 -0
- runbooks/integration/mcp_integration.py +1920 -0
- runbooks/inventory/CLAUDE.md +816 -0
- runbooks/inventory/__init__.py +2 -2
- runbooks/inventory/cloud_foundations_integration.py +144 -149
- runbooks/inventory/collectors/aws_comprehensive.py +1 -1
- runbooks/inventory/collectors/aws_networking.py +109 -99
- runbooks/inventory/collectors/base.py +4 -0
- runbooks/inventory/core/collector.py +495 -313
- runbooks/inventory/drift_detection_cli.py +69 -96
- runbooks/inventory/inventory_mcp_cli.py +48 -46
- runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
- runbooks/inventory/mcp_inventory_validator.py +549 -465
- runbooks/inventory/mcp_vpc_validator.py +359 -442
- runbooks/inventory/organizations_discovery.py +55 -51
- runbooks/inventory/rich_inventory_display.py +33 -32
- runbooks/inventory/unified_validation_engine.py +278 -251
- runbooks/inventory/vpc_analyzer.py +732 -695
- runbooks/inventory/vpc_architecture_validator.py +293 -348
- runbooks/inventory/vpc_dependency_analyzer.py +382 -378
- runbooks/inventory/vpc_flow_analyzer.py +1 -1
- runbooks/main.py +49 -34
- runbooks/main_final.py +91 -60
- runbooks/main_minimal.py +22 -10
- runbooks/main_optimized.py +131 -100
- runbooks/main_ultra_minimal.py +7 -2
- runbooks/mcp/__init__.py +36 -0
- runbooks/mcp/integration.py +679 -0
- runbooks/monitoring/performance_monitor.py +9 -4
- runbooks/operate/dynamodb_operations.py +3 -1
- runbooks/operate/ec2_operations.py +145 -137
- runbooks/operate/iam_operations.py +146 -152
- runbooks/operate/networking_cost_heatmap.py +29 -8
- runbooks/operate/rds_operations.py +223 -254
- runbooks/operate/s3_operations.py +107 -118
- runbooks/operate/vpc_operations.py +646 -616
- runbooks/remediation/base.py +1 -1
- runbooks/remediation/commons.py +10 -7
- runbooks/remediation/commvault_ec2_analysis.py +70 -66
- runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
- runbooks/remediation/multi_account.py +24 -21
- runbooks/remediation/rds_snapshot_list.py +86 -60
- runbooks/remediation/remediation_cli.py +92 -146
- runbooks/remediation/universal_account_discovery.py +83 -79
- runbooks/remediation/workspaces_list.py +46 -41
- runbooks/security/__init__.py +19 -0
- runbooks/security/assessment_runner.py +1150 -0
- runbooks/security/baseline_checker.py +812 -0
- runbooks/security/cloudops_automation_security_validator.py +509 -535
- runbooks/security/compliance_automation_engine.py +17 -17
- runbooks/security/config/__init__.py +2 -2
- runbooks/security/config/compliance_config.py +50 -50
- runbooks/security/config_template_generator.py +63 -76
- runbooks/security/enterprise_security_framework.py +1 -1
- runbooks/security/executive_security_dashboard.py +519 -508
- runbooks/security/multi_account_security_controls.py +959 -1210
- runbooks/security/real_time_security_monitor.py +422 -444
- runbooks/security/security_baseline_tester.py +1 -1
- runbooks/security/security_cli.py +143 -112
- runbooks/security/test_2way_validation.py +439 -0
- runbooks/security/two_way_validation_framework.py +852 -0
- runbooks/sre/production_monitoring_framework.py +167 -177
- runbooks/tdd/__init__.py +15 -0
- runbooks/tdd/cli.py +1071 -0
- runbooks/utils/__init__.py +14 -17
- runbooks/utils/logger.py +7 -2
- runbooks/utils/version_validator.py +50 -47
- runbooks/validation/__init__.py +6 -6
- runbooks/validation/cli.py +9 -3
- runbooks/validation/comprehensive_2way_validator.py +745 -704
- runbooks/validation/mcp_validator.py +906 -228
- runbooks/validation/terraform_citations_validator.py +104 -115
- runbooks/validation/terraform_drift_detector.py +447 -451
- runbooks/vpc/README.md +617 -0
- runbooks/vpc/__init__.py +8 -1
- runbooks/vpc/analyzer.py +577 -0
- runbooks/vpc/cleanup_wrapper.py +476 -413
- runbooks/vpc/cli_cloudtrail_commands.py +339 -0
- runbooks/vpc/cli_mcp_validation_commands.py +480 -0
- runbooks/vpc/cloudtrail_audit_integration.py +717 -0
- runbooks/vpc/config.py +92 -97
- runbooks/vpc/cost_engine.py +411 -148
- runbooks/vpc/cost_explorer_integration.py +553 -0
- runbooks/vpc/cross_account_session.py +101 -106
- runbooks/vpc/enhanced_mcp_validation.py +917 -0
- runbooks/vpc/eni_gate_validator.py +961 -0
- runbooks/vpc/heatmap_engine.py +185 -160
- runbooks/vpc/mcp_no_eni_validator.py +680 -639
- runbooks/vpc/nat_gateway_optimizer.py +358 -0
- runbooks/vpc/networking_wrapper.py +15 -8
- runbooks/vpc/pdca_remediation_planner.py +528 -0
- runbooks/vpc/performance_optimized_analyzer.py +219 -231
- runbooks/vpc/runbooks_adapter.py +1167 -241
- runbooks/vpc/tdd_red_phase_stubs.py +601 -0
- runbooks/vpc/test_data_loader.py +358 -0
- runbooks/vpc/tests/conftest.py +314 -4
- runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
- runbooks/vpc/tests/test_cost_engine.py +0 -2
- runbooks/vpc/topology_generator.py +326 -0
- runbooks/vpc/unified_scenarios.py +1297 -1124
- runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
- runbooks-1.1.5.dist-info/METADATA +328 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/RECORD +214 -193
- runbooks/finops/README.md +0 -414
- runbooks/finops/accuracy_cross_validator.py +0 -647
- runbooks/finops/business_cases.py +0 -950
- runbooks/finops/dashboard_router.py +0 -922
- runbooks/finops/ebs_optimizer.py +0 -973
- runbooks/finops/embedded_mcp_validator.py +0 -1629
- runbooks/finops/enhanced_dashboard_runner.py +0 -527
- runbooks/finops/finops_dashboard.py +0 -584
- runbooks/finops/finops_scenarios.py +0 -1218
- runbooks/finops/legacy_migration.py +0 -730
- runbooks/finops/multi_dashboard.py +0 -1519
- runbooks/finops/single_dashboard.py +0 -1113
- runbooks/finops/unlimited_scenarios.py +0 -393
- runbooks-1.1.4.dist-info/METADATA +0 -800
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,7 @@ Supports automated compliance enforcement, security policy implementation, and a
|
|
6
6
|
|
7
7
|
Business Scenarios:
|
8
8
|
- Security Incident Response: Automated remediation for compliance violations
|
9
|
-
- S3 Encryption Enforcement: Compliance with SOC2, PCI-DSS, HIPAA requirements
|
9
|
+
- S3 Encryption Enforcement: Compliance with SOC2, PCI-DSS, HIPAA requirements
|
10
10
|
- IAM Security Optimization: Least privilege principle enforcement
|
11
11
|
- RDS Security Hardening: Database security and compliance
|
12
12
|
- Multi-Account Security Governance: Organization-wide security policy enforcement
|
@@ -27,19 +27,33 @@ from botocore.exceptions import ClientError
|
|
27
27
|
from datetime import datetime, timedelta
|
28
28
|
|
29
29
|
from runbooks.common.rich_utils import (
|
30
|
-
console,
|
31
|
-
|
30
|
+
console,
|
31
|
+
print_header,
|
32
|
+
print_success,
|
33
|
+
print_error,
|
34
|
+
print_warning,
|
35
|
+
print_info,
|
36
|
+
create_table,
|
37
|
+
create_progress_bar,
|
38
|
+
format_cost,
|
39
|
+
create_panel,
|
32
40
|
)
|
33
41
|
from .base import CloudOpsBase
|
34
42
|
from .models import (
|
35
|
-
SecurityEnforcementResult,
|
36
|
-
|
43
|
+
SecurityEnforcementResult,
|
44
|
+
BusinessScenario,
|
45
|
+
ExecutionMode,
|
46
|
+
RiskLevel,
|
47
|
+
ResourceImpact,
|
48
|
+
BusinessMetrics,
|
49
|
+
ComplianceMetrics,
|
37
50
|
)
|
38
51
|
|
52
|
+
|
39
53
|
class SecurityEnforcer(CloudOpsBase):
|
40
54
|
"""
|
41
55
|
Security enforcement scenarios for automated compliance and risk reduction.
|
42
|
-
|
56
|
+
|
43
57
|
Business Use Cases:
|
44
58
|
1. Security incident response and automated remediation
|
45
59
|
2. Compliance framework enforcement (SOC2, PCI-DSS, HIPAA)
|
@@ -47,122 +61,115 @@ class SecurityEnforcer(CloudOpsBase):
|
|
47
61
|
4. Security baseline implementation and monitoring
|
48
62
|
5. Executive security reporting and audit preparation
|
49
63
|
"""
|
50
|
-
|
64
|
+
|
51
65
|
def __init__(
|
52
|
-
self,
|
53
|
-
profile: str = "default",
|
54
|
-
dry_run: bool = True,
|
55
|
-
execution_mode: ExecutionMode = ExecutionMode.DRY_RUN
|
66
|
+
self, profile: str = "default", dry_run: bool = True, execution_mode: ExecutionMode = ExecutionMode.DRY_RUN
|
56
67
|
):
|
57
68
|
"""
|
58
69
|
Initialize Security Enforcer with enterprise patterns.
|
59
|
-
|
70
|
+
|
60
71
|
Args:
|
61
72
|
profile: AWS profile (typically management profile for cross-account access)
|
62
73
|
dry_run: Enable safe analysis mode (default True)
|
63
74
|
execution_mode: Execution mode for operations
|
64
75
|
"""
|
65
76
|
super().__init__(profile, dry_run, execution_mode)
|
66
|
-
|
77
|
+
|
67
78
|
print_header("CloudOps Security Enforcer", "1.0.0")
|
68
79
|
print_info(f"Execution mode: {execution_mode.value}")
|
69
80
|
print_info(f"Profile: {profile}")
|
70
|
-
|
81
|
+
|
71
82
|
if dry_run:
|
72
83
|
print_warning("🛡️ DRY RUN MODE: No security policies will be enforced")
|
73
|
-
|
84
|
+
|
74
85
|
async def enforce_s3_encryption(
|
75
|
-
self,
|
76
|
-
regions: Optional[List[str]] = None,
|
77
|
-
encryption_type: str = "AES256"
|
86
|
+
self, regions: Optional[List[str]] = None, encryption_type: str = "AES256"
|
78
87
|
) -> SecurityEnforcementResult:
|
79
88
|
"""
|
80
89
|
Business Scenario: Enforce S3 bucket encryption for compliance
|
81
90
|
Source: AWS_encrypt_unencrypted_S3_buckets.ipynb
|
82
|
-
|
91
|
+
|
83
92
|
Typical Business Impact:
|
84
93
|
- Compliance improvement: SOC2, PCI-DSS, HIPAA requirements
|
85
94
|
- Risk reduction: Data protection and regulatory compliance
|
86
95
|
- Implementation time: 10-20 minutes
|
87
|
-
|
96
|
+
|
88
97
|
Args:
|
89
|
-
regions: Target regions (default: all available)
|
98
|
+
regions: Target regions (default: all available)
|
90
99
|
encryption_type: Encryption type (AES256 or aws:kms)
|
91
|
-
|
100
|
+
|
92
101
|
Returns:
|
93
102
|
SecurityEnforcementResult with detailed compliance improvements
|
94
103
|
"""
|
95
104
|
operation_name = "S3 Encryption Enforcement"
|
96
105
|
print_header(f"🔒 {operation_name}")
|
97
|
-
|
106
|
+
|
98
107
|
# Initialize result tracking
|
99
108
|
unencrypted_buckets = []
|
100
109
|
encrypted_buckets = []
|
101
110
|
total_violations = 0
|
102
111
|
violations_fixed = 0
|
103
|
-
|
112
|
+
|
104
113
|
# Get target regions
|
105
|
-
target_regions = regions or self._get_available_regions(
|
106
|
-
|
114
|
+
target_regions = regions or self._get_available_regions("s3")[:3] # S3 is global, limit regions
|
115
|
+
|
107
116
|
print_info(f"Scanning S3 buckets for encryption compliance")
|
108
117
|
print_info(f"Required encryption: {encryption_type}")
|
109
118
|
print_info(f"Target regions: {len(target_regions)}")
|
110
|
-
|
119
|
+
|
111
120
|
# Progress tracking
|
112
121
|
with create_progress_bar() as progress:
|
113
122
|
task = progress.add_task("[cyan]Scanning S3 buckets...", total=len(target_regions))
|
114
|
-
|
123
|
+
|
115
124
|
for region in target_regions:
|
116
125
|
try:
|
117
|
-
region_results = await self._analyze_s3_encryption_in_region(
|
118
|
-
|
119
|
-
)
|
120
|
-
|
121
|
-
encrypted_buckets.extend(region_results['encrypted'])
|
122
|
-
|
126
|
+
region_results = await self._analyze_s3_encryption_in_region(region, encryption_type)
|
127
|
+
unencrypted_buckets.extend(region_results["unencrypted"])
|
128
|
+
encrypted_buckets.extend(region_results["encrypted"])
|
129
|
+
|
123
130
|
progress.update(task, advance=1)
|
124
|
-
|
131
|
+
|
125
132
|
except Exception as e:
|
126
133
|
print_warning(f"Could not analyze region {region}: {str(e)}")
|
127
134
|
continue
|
128
|
-
|
135
|
+
|
129
136
|
total_violations = len(unencrypted_buckets)
|
130
|
-
|
137
|
+
|
131
138
|
# Create resource impacts for unencrypted buckets
|
132
139
|
resource_impacts = []
|
133
140
|
for bucket_info in unencrypted_buckets:
|
134
141
|
impact = self.create_resource_impact(
|
135
142
|
resource_type="s3-bucket",
|
136
|
-
resource_id=bucket_info[
|
137
|
-
region=bucket_info[
|
143
|
+
resource_id=bucket_info["bucket_name"],
|
144
|
+
region=bucket_info["region"],
|
138
145
|
estimated_cost=0.0, # No direct cost for encryption
|
139
146
|
projected_savings=0.0, # Compliance value, not cost savings
|
140
147
|
risk_level=RiskLevel.HIGH, # Unencrypted data is high risk
|
141
148
|
modification_required=True,
|
142
149
|
resource_name=f"S3 Bucket {bucket_info['bucket_name']}",
|
143
150
|
business_criticality="high", # Data protection is critical
|
144
|
-
estimated_downtime=0.0 # S3 encryption enablement has no downtime
|
151
|
+
estimated_downtime=0.0, # S3 encryption enablement has no downtime
|
145
152
|
)
|
146
153
|
resource_impacts.append(impact)
|
147
|
-
|
154
|
+
|
148
155
|
# Execute enforcement if not dry run
|
149
156
|
if not self.dry_run and self.execution_mode == ExecutionMode.EXECUTE:
|
150
157
|
print_info("🔧 Executing S3 encryption enforcement...")
|
151
158
|
violations_fixed = await self._apply_s3_encryption(unencrypted_buckets, encryption_type)
|
152
|
-
|
159
|
+
|
153
160
|
# Calculate compliance scores
|
154
161
|
total_buckets = len(encrypted_buckets) + len(unencrypted_buckets)
|
155
162
|
security_score_before = (len(encrypted_buckets) / total_buckets * 100) if total_buckets > 0 else 100.0
|
156
|
-
|
163
|
+
|
157
164
|
if violations_fixed > 0:
|
158
|
-
security_score_after = (
|
165
|
+
security_score_after = (len(encrypted_buckets) + violations_fixed) / total_buckets * 100
|
159
166
|
else:
|
160
167
|
security_score_after = security_score_before
|
161
|
-
|
168
|
+
|
162
169
|
# Display results
|
163
170
|
if unencrypted_buckets:
|
164
171
|
print_warning(f"⚠️ Found {len(unencrypted_buckets)} unencrypted S3 buckets")
|
165
|
-
|
172
|
+
|
166
173
|
# Detailed table
|
167
174
|
s3_table = create_table(
|
168
175
|
title="S3 Encryption Compliance Analysis",
|
@@ -171,26 +178,20 @@ class SecurityEnforcer(CloudOpsBase):
|
|
171
178
|
{"name": "Region", "style": "green"},
|
172
179
|
{"name": "Current Encryption", "style": "red"},
|
173
180
|
{"name": "Required Action", "style": "yellow"},
|
174
|
-
{"name": "Compliance Risk", "style": "blue"}
|
175
|
-
]
|
181
|
+
{"name": "Compliance Risk", "style": "blue"},
|
182
|
+
],
|
176
183
|
)
|
177
|
-
|
184
|
+
|
178
185
|
for bucket in unencrypted_buckets[:10]: # Show top 10
|
179
|
-
s3_table.add_row(
|
180
|
-
|
181
|
-
bucket['region'],
|
182
|
-
"None",
|
183
|
-
f"Apply {encryption_type}",
|
184
|
-
"High"
|
185
|
-
)
|
186
|
-
|
186
|
+
s3_table.add_row(bucket["bucket_name"], bucket["region"], "None", f"Apply {encryption_type}", "High")
|
187
|
+
|
187
188
|
console.print(s3_table)
|
188
|
-
|
189
|
+
|
189
190
|
if violations_fixed > 0:
|
190
191
|
print_success(f"🔐 Successfully encrypted {violations_fixed} buckets")
|
191
192
|
else:
|
192
193
|
print_success("✅ All S3 buckets are properly encrypted")
|
193
|
-
|
194
|
+
|
194
195
|
# Create compliance metrics
|
195
196
|
compliance_metrics = [
|
196
197
|
ComplianceMetrics(
|
@@ -198,26 +199,26 @@ class SecurityEnforcer(CloudOpsBase):
|
|
198
199
|
current_score=security_score_after,
|
199
200
|
target_score=100.0,
|
200
201
|
violations_found=total_violations,
|
201
|
-
violations_fixed=violations_fixed
|
202
|
+
violations_fixed=violations_fixed,
|
202
203
|
),
|
203
204
|
ComplianceMetrics(
|
204
205
|
framework="PCI-DSS",
|
205
206
|
current_score=security_score_after,
|
206
207
|
target_score=100.0,
|
207
208
|
violations_found=total_violations,
|
208
|
-
violations_fixed=violations_fixed
|
209
|
-
)
|
209
|
+
violations_fixed=violations_fixed,
|
210
|
+
),
|
210
211
|
]
|
211
|
-
|
212
|
+
|
212
213
|
# Business metrics
|
213
214
|
business_metrics = self.create_business_metrics(
|
214
215
|
total_savings=0.0, # Security compliance doesn't directly save costs
|
215
216
|
implementation_cost=0.0, # No cost for S3 encryption
|
216
|
-
overall_risk=RiskLevel.LOW if total_violations == 0 else RiskLevel.MEDIUM
|
217
|
+
overall_risk=RiskLevel.LOW if total_violations == 0 else RiskLevel.MEDIUM,
|
217
218
|
)
|
218
219
|
business_metrics.operational_efficiency_gain = 90.0 # High automation value
|
219
220
|
business_metrics.business_continuity_impact = "positive" # Improves security posture
|
220
|
-
|
221
|
+
|
221
222
|
# Create comprehensive result
|
222
223
|
result = SecurityEnforcementResult(
|
223
224
|
scenario=BusinessScenario.SECURITY_ENFORCEMENT,
|
@@ -235,12 +236,11 @@ class SecurityEnforcer(CloudOpsBase):
|
|
235
236
|
"Implement bucket policy to require encryption for new objects",
|
236
237
|
"Set up CloudTrail logging for S3 encryption compliance monitoring",
|
237
238
|
"Consider AWS Config rules for continuous compliance validation",
|
238
|
-
"Review and update data classification policies"
|
239
|
+
"Review and update data classification policies",
|
239
240
|
],
|
240
241
|
aws_profile_used=self.profile,
|
241
242
|
regions_analyzed=target_regions,
|
242
243
|
services_analyzed=["s3"],
|
243
|
-
|
244
244
|
# Security-specific metrics
|
245
245
|
security_score_before=security_score_before,
|
246
246
|
security_score_after=security_score_after,
|
@@ -250,171 +250,137 @@ class SecurityEnforcer(CloudOpsBase):
|
|
250
250
|
medium_findings=0,
|
251
251
|
low_findings=0,
|
252
252
|
auto_remediated=violations_fixed,
|
253
|
-
manual_remediation_required=max(0, total_violations - violations_fixed)
|
253
|
+
manual_remediation_required=max(0, total_violations - violations_fixed),
|
254
254
|
)
|
255
|
-
|
255
|
+
|
256
256
|
self.display_execution_summary(result)
|
257
257
|
return result
|
258
|
-
|
258
|
+
|
259
259
|
async def _analyze_s3_encryption_in_region(
|
260
|
-
self,
|
261
|
-
region: str,
|
262
|
-
required_encryption: str
|
260
|
+
self, region: str, required_encryption: str
|
263
261
|
) -> Dict[str, List[Dict[str, str]]]:
|
264
262
|
"""
|
265
263
|
Analyze S3 buckets in a specific region for encryption compliance.
|
266
|
-
|
264
|
+
|
267
265
|
Args:
|
268
266
|
region: AWS region to analyze
|
269
267
|
required_encryption: Required encryption type
|
270
|
-
|
268
|
+
|
271
269
|
Returns:
|
272
270
|
Dictionary with encrypted and unencrypted bucket lists
|
273
271
|
"""
|
274
272
|
encrypted_buckets = []
|
275
273
|
unencrypted_buckets = []
|
276
|
-
|
274
|
+
|
277
275
|
try:
|
278
|
-
s3 = self.session.client(
|
279
|
-
|
276
|
+
s3 = self.session.client("s3", region_name=region)
|
277
|
+
|
280
278
|
# List all buckets (S3 buckets are global, but we check from each region)
|
281
|
-
if region ==
|
279
|
+
if region == "us-east-1": # Only check from one region to avoid duplicates
|
282
280
|
response = s3.list_buckets()
|
283
|
-
|
284
|
-
for bucket in response.get(
|
285
|
-
bucket_name = bucket[
|
286
|
-
|
281
|
+
|
282
|
+
for bucket in response.get("Buckets", []):
|
283
|
+
bucket_name = bucket["Name"]
|
284
|
+
|
287
285
|
try:
|
288
286
|
# Check bucket encryption
|
289
287
|
encryption_response = s3.get_bucket_encryption(Bucket=bucket_name)
|
290
|
-
|
288
|
+
|
291
289
|
# Bucket has encryption configured
|
292
|
-
encrypted_buckets.append(
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
})
|
297
|
-
|
290
|
+
encrypted_buckets.append(
|
291
|
+
{"bucket_name": bucket_name, "region": region, "encryption_type": "Configured"}
|
292
|
+
)
|
293
|
+
|
298
294
|
except ClientError as e:
|
299
|
-
if e.response[
|
295
|
+
if e.response["Error"]["Code"] == "ServerSideEncryptionConfigurationNotFoundError":
|
300
296
|
# Bucket has no encryption
|
301
|
-
unencrypted_buckets.append(
|
302
|
-
|
303
|
-
|
304
|
-
'encryption_type': 'None'
|
305
|
-
})
|
297
|
+
unencrypted_buckets.append(
|
298
|
+
{"bucket_name": bucket_name, "region": region, "encryption_type": "None"}
|
299
|
+
)
|
306
300
|
else:
|
307
301
|
print_warning(f"Could not check encryption for bucket {bucket_name}: {str(e)}")
|
308
|
-
|
302
|
+
|
309
303
|
except ClientError as e:
|
310
304
|
print_warning(f"Could not analyze S3 buckets in {region}: {str(e)}")
|
311
|
-
|
312
|
-
return {
|
313
|
-
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
async def _apply_s3_encryption(
|
318
|
-
self,
|
319
|
-
unencrypted_buckets: List[Dict[str, str]],
|
320
|
-
encryption_type: str
|
321
|
-
) -> int:
|
305
|
+
|
306
|
+
return {"encrypted": encrypted_buckets, "unencrypted": unencrypted_buckets}
|
307
|
+
|
308
|
+
async def _apply_s3_encryption(self, unencrypted_buckets: List[Dict[str, str]], encryption_type: str) -> int:
|
322
309
|
"""
|
323
310
|
Apply encryption to unencrypted S3 buckets.
|
324
|
-
|
311
|
+
|
325
312
|
Args:
|
326
313
|
unencrypted_buckets: List of buckets requiring encryption
|
327
314
|
encryption_type: Encryption type to apply
|
328
|
-
|
315
|
+
|
329
316
|
Returns:
|
330
317
|
Number of buckets successfully encrypted
|
331
318
|
"""
|
332
319
|
if self.dry_run:
|
333
320
|
print_info("DRY RUN: Would apply S3 encryption")
|
334
321
|
return 0
|
335
|
-
|
322
|
+
|
336
323
|
violations_fixed = 0
|
337
324
|
print_warning("🚨 EXECUTING S3 encryption enforcement - this will modify bucket policies!")
|
338
|
-
|
325
|
+
|
339
326
|
for bucket_info in unencrypted_buckets:
|
340
|
-
bucket_name = bucket_info[
|
341
|
-
|
327
|
+
bucket_name = bucket_info["bucket_name"]
|
328
|
+
|
342
329
|
try:
|
343
|
-
s3 = self.session.client(
|
344
|
-
|
330
|
+
s3 = self.session.client("s3", region_name="us-east-1")
|
331
|
+
|
345
332
|
# Apply server-side encryption configuration
|
346
333
|
if encryption_type == "AES256":
|
347
|
-
encryption_config = {
|
348
|
-
'Rules': [
|
349
|
-
{
|
350
|
-
'ApplyServerSideEncryptionByDefault': {
|
351
|
-
'SSEAlgorithm': 'AES256'
|
352
|
-
}
|
353
|
-
}
|
354
|
-
]
|
355
|
-
}
|
334
|
+
encryption_config = {"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}
|
356
335
|
else: # aws:kms
|
357
|
-
encryption_config = {
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
'SSEAlgorithm': 'aws:kms'
|
362
|
-
}
|
363
|
-
}
|
364
|
-
]
|
365
|
-
}
|
366
|
-
|
367
|
-
s3.put_bucket_encryption(
|
368
|
-
Bucket=bucket_name,
|
369
|
-
ServerSideEncryptionConfiguration=encryption_config
|
370
|
-
)
|
371
|
-
|
336
|
+
encryption_config = {"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "aws:kms"}}]}
|
337
|
+
|
338
|
+
s3.put_bucket_encryption(Bucket=bucket_name, ServerSideEncryptionConfiguration=encryption_config)
|
339
|
+
|
372
340
|
print_success(f"✅ Applied {encryption_type} encryption to bucket {bucket_name}")
|
373
341
|
violations_fixed += 1
|
374
|
-
|
342
|
+
|
375
343
|
except ClientError as e:
|
376
344
|
print_error(f"❌ Failed to encrypt bucket {bucket_name}: {str(e)}")
|
377
|
-
|
345
|
+
|
378
346
|
return violations_fixed
|
379
|
-
|
347
|
+
|
380
348
|
async def security_incident_response(
|
381
|
-
self,
|
382
|
-
incident_type: str = "compliance_violation",
|
383
|
-
severity: str = "high"
|
349
|
+
self, incident_type: str = "compliance_violation", severity: str = "high"
|
384
350
|
) -> SecurityEnforcementResult:
|
385
351
|
"""
|
386
352
|
Business Scenario: Automated security incident response
|
387
|
-
|
353
|
+
|
388
354
|
Designed for: CISO escalations, compliance violations, security alerts
|
389
355
|
Response time: <15 minutes for initial remediation
|
390
|
-
|
356
|
+
|
391
357
|
Args:
|
392
358
|
incident_type: Type of security incident
|
393
359
|
severity: Incident severity level
|
394
|
-
|
360
|
+
|
395
361
|
Returns:
|
396
362
|
SecurityEnforcementResult with incident response analysis
|
397
363
|
"""
|
398
364
|
operation_name = "Security Incident Response"
|
399
365
|
print_header(f"🚨 {operation_name}")
|
400
|
-
|
366
|
+
|
401
367
|
print_warning(f"Security incident detected: {incident_type}")
|
402
368
|
print_warning(f"Severity level: {severity}")
|
403
|
-
|
369
|
+
|
404
370
|
# This would integrate multiple security enforcement scenarios
|
405
371
|
# for rapid security response in incident situations
|
406
|
-
|
372
|
+
|
407
373
|
response_actions = [
|
408
374
|
"Immediate security assessment and vulnerability scanning",
|
409
375
|
"Automated policy enforcement and compliance validation",
|
410
376
|
"Security posture analysis and risk assessment",
|
411
|
-
"Incident documentation and audit trail generation"
|
377
|
+
"Incident documentation and audit trail generation",
|
412
378
|
]
|
413
|
-
|
379
|
+
|
414
380
|
print_info("Security incident response actions:")
|
415
381
|
for action in response_actions:
|
416
382
|
print_info(f" • {action}")
|
417
|
-
|
383
|
+
|
418
384
|
return SecurityEnforcementResult(
|
419
385
|
scenario=BusinessScenario.SECURITY_ENFORCEMENT,
|
420
386
|
scenario_name="Security Incident Response",
|
@@ -427,12 +393,12 @@ class SecurityEnforcer(CloudOpsBase):
|
|
427
393
|
resources_impacted=[],
|
428
394
|
business_metrics=self.create_business_metrics(
|
429
395
|
total_savings=0.0, # Security response doesn't directly save costs
|
430
|
-
overall_risk=RiskLevel.HIGH if severity == "critical" else RiskLevel.MEDIUM
|
396
|
+
overall_risk=RiskLevel.HIGH if severity == "critical" else RiskLevel.MEDIUM,
|
431
397
|
),
|
432
398
|
recommendations=[
|
433
399
|
"Implement continuous security monitoring and alerting",
|
434
400
|
"Establish security incident response playbooks",
|
435
|
-
"Regular security posture assessments and compliance validation"
|
401
|
+
"Regular security posture assessments and compliance validation",
|
436
402
|
],
|
437
403
|
aws_profile_used=self.profile,
|
438
404
|
regions_analyzed=[],
|
@@ -445,5 +411,5 @@ class SecurityEnforcer(CloudOpsBase):
|
|
445
411
|
medium_findings=1 if severity == "medium" else 0,
|
446
412
|
low_findings=0,
|
447
413
|
auto_remediated=1,
|
448
|
-
manual_remediation_required=0
|
449
|
-
)
|
414
|
+
manual_remediation_required=0,
|
415
|
+
)
|
@@ -59,6 +59,17 @@ from ..common.rich_utils import (
|
|
59
59
|
print_warning,
|
60
60
|
)
|
61
61
|
|
62
|
+
|
63
|
+
# Define common enums that are needed regardless of FinOps availability
|
64
|
+
class ErrorCategory(Enum):
|
65
|
+
AWS_CREDENTIALS = "AWS_CREDENTIALS"
|
66
|
+
AWS_THROTTLING = "AWS_THROTTLING"
|
67
|
+
NETWORK = "NETWORK"
|
68
|
+
PERMISSION = "PERMISSION"
|
69
|
+
DATA_VALIDATION = "DATA_VALIDATION"
|
70
|
+
CONFIGURATION = "CONFIGURATION"
|
71
|
+
|
72
|
+
|
62
73
|
# Import the proven FinOps accuracy patterns
|
63
74
|
try:
|
64
75
|
from ..finops.accuracy_cross_validator import (
|