runbooks 1.1.3__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.
Files changed (247) hide show
  1. runbooks/__init__.py +31 -2
  2. runbooks/__init___optimized.py +18 -4
  3. runbooks/_platform/__init__.py +1 -5
  4. runbooks/_platform/core/runbooks_wrapper.py +141 -138
  5. runbooks/aws2/accuracy_validator.py +812 -0
  6. runbooks/base.py +7 -0
  7. runbooks/cfat/WEIGHT_CONFIG_README.md +1 -1
  8. runbooks/cfat/assessment/compliance.py +8 -8
  9. runbooks/cfat/assessment/runner.py +1 -0
  10. runbooks/cfat/cloud_foundations_assessment.py +227 -239
  11. runbooks/cfat/models.py +6 -2
  12. runbooks/cfat/tests/__init__.py +6 -1
  13. runbooks/cli/__init__.py +13 -0
  14. runbooks/cli/commands/cfat.py +274 -0
  15. runbooks/cli/commands/finops.py +1164 -0
  16. runbooks/cli/commands/inventory.py +379 -0
  17. runbooks/cli/commands/operate.py +239 -0
  18. runbooks/cli/commands/security.py +248 -0
  19. runbooks/cli/commands/validation.py +825 -0
  20. runbooks/cli/commands/vpc.py +310 -0
  21. runbooks/cli/registry.py +107 -0
  22. runbooks/cloudops/__init__.py +23 -30
  23. runbooks/cloudops/base.py +96 -107
  24. runbooks/cloudops/cost_optimizer.py +549 -547
  25. runbooks/cloudops/infrastructure_optimizer.py +5 -4
  26. runbooks/cloudops/interfaces.py +226 -227
  27. runbooks/cloudops/lifecycle_manager.py +5 -4
  28. runbooks/cloudops/mcp_cost_validation.py +252 -235
  29. runbooks/cloudops/models.py +78 -53
  30. runbooks/cloudops/monitoring_automation.py +5 -4
  31. runbooks/cloudops/notebook_framework.py +179 -215
  32. runbooks/cloudops/security_enforcer.py +125 -159
  33. runbooks/common/accuracy_validator.py +11 -0
  34. runbooks/common/aws_pricing.py +349 -326
  35. runbooks/common/aws_pricing_api.py +211 -212
  36. runbooks/common/aws_profile_manager.py +341 -0
  37. runbooks/common/aws_utils.py +75 -80
  38. runbooks/common/business_logic.py +127 -105
  39. runbooks/common/cli_decorators.py +36 -60
  40. runbooks/common/comprehensive_cost_explorer_integration.py +456 -464
  41. runbooks/common/cross_account_manager.py +198 -205
  42. runbooks/common/date_utils.py +27 -39
  43. runbooks/common/decorators.py +235 -0
  44. runbooks/common/dry_run_examples.py +173 -208
  45. runbooks/common/dry_run_framework.py +157 -155
  46. runbooks/common/enhanced_exception_handler.py +15 -4
  47. runbooks/common/enhanced_logging_example.py +50 -64
  48. runbooks/common/enhanced_logging_integration_example.py +65 -37
  49. runbooks/common/env_utils.py +16 -16
  50. runbooks/common/error_handling.py +40 -38
  51. runbooks/common/lazy_loader.py +41 -23
  52. runbooks/common/logging_integration_helper.py +79 -86
  53. runbooks/common/mcp_cost_explorer_integration.py +478 -495
  54. runbooks/common/mcp_integration.py +63 -74
  55. runbooks/common/memory_optimization.py +140 -118
  56. runbooks/common/module_cli_base.py +37 -58
  57. runbooks/common/organizations_client.py +176 -194
  58. runbooks/common/patterns.py +204 -0
  59. runbooks/common/performance_monitoring.py +67 -71
  60. runbooks/common/performance_optimization_engine.py +283 -274
  61. runbooks/common/profile_utils.py +248 -39
  62. runbooks/common/rich_utils.py +643 -92
  63. runbooks/common/sre_performance_suite.py +177 -186
  64. runbooks/enterprise/__init__.py +1 -1
  65. runbooks/enterprise/logging.py +144 -106
  66. runbooks/enterprise/security.py +187 -204
  67. runbooks/enterprise/validation.py +43 -56
  68. runbooks/finops/__init__.py +29 -33
  69. runbooks/finops/account_resolver.py +1 -1
  70. runbooks/finops/advanced_optimization_engine.py +980 -0
  71. runbooks/finops/automation_core.py +268 -231
  72. runbooks/finops/business_case_config.py +184 -179
  73. runbooks/finops/cli.py +660 -139
  74. runbooks/finops/commvault_ec2_analysis.py +157 -164
  75. runbooks/finops/compute_cost_optimizer.py +336 -320
  76. runbooks/finops/config.py +20 -20
  77. runbooks/finops/cost_optimizer.py +488 -622
  78. runbooks/finops/cost_processor.py +332 -214
  79. runbooks/finops/dashboard_runner.py +1006 -172
  80. runbooks/finops/ebs_cost_optimizer.py +991 -657
  81. runbooks/finops/elastic_ip_optimizer.py +317 -257
  82. runbooks/finops/enhanced_mcp_integration.py +340 -0
  83. runbooks/finops/enhanced_progress.py +40 -37
  84. runbooks/finops/enhanced_trend_visualization.py +3 -2
  85. runbooks/finops/enterprise_wrappers.py +230 -292
  86. runbooks/finops/executive_export.py +203 -160
  87. runbooks/finops/helpers.py +130 -288
  88. runbooks/finops/iam_guidance.py +1 -1
  89. runbooks/finops/infrastructure/__init__.py +80 -0
  90. runbooks/finops/infrastructure/commands.py +506 -0
  91. runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
  92. runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
  93. runbooks/finops/markdown_exporter.py +338 -175
  94. runbooks/finops/mcp_validator.py +1952 -0
  95. runbooks/finops/nat_gateway_optimizer.py +1513 -482
  96. runbooks/finops/network_cost_optimizer.py +657 -587
  97. runbooks/finops/notebook_utils.py +226 -188
  98. runbooks/finops/optimization_engine.py +1136 -0
  99. runbooks/finops/optimizer.py +25 -29
  100. runbooks/finops/rds_snapshot_optimizer.py +367 -411
  101. runbooks/finops/reservation_optimizer.py +427 -363
  102. runbooks/finops/scenario_cli_integration.py +77 -78
  103. runbooks/finops/scenarios.py +1278 -439
  104. runbooks/finops/schemas.py +218 -182
  105. runbooks/finops/snapshot_manager.py +2289 -0
  106. runbooks/finops/tests/test_finops_dashboard.py +3 -3
  107. runbooks/finops/tests/test_reference_images_validation.py +2 -2
  108. runbooks/finops/tests/test_single_account_features.py +17 -17
  109. runbooks/finops/tests/validate_test_suite.py +1 -1
  110. runbooks/finops/types.py +3 -3
  111. runbooks/finops/validation_framework.py +263 -269
  112. runbooks/finops/vpc_cleanup_exporter.py +191 -146
  113. runbooks/finops/vpc_cleanup_optimizer.py +593 -575
  114. runbooks/finops/workspaces_analyzer.py +171 -182
  115. runbooks/hitl/enhanced_workflow_engine.py +1 -1
  116. runbooks/integration/__init__.py +89 -0
  117. runbooks/integration/mcp_integration.py +1920 -0
  118. runbooks/inventory/CLAUDE.md +816 -0
  119. runbooks/inventory/README.md +3 -3
  120. runbooks/inventory/Tests/common_test_data.py +30 -30
  121. runbooks/inventory/__init__.py +2 -2
  122. runbooks/inventory/cloud_foundations_integration.py +144 -149
  123. runbooks/inventory/collectors/aws_comprehensive.py +28 -11
  124. runbooks/inventory/collectors/aws_networking.py +111 -101
  125. runbooks/inventory/collectors/base.py +4 -0
  126. runbooks/inventory/core/collector.py +495 -313
  127. runbooks/inventory/discovery.md +2 -2
  128. runbooks/inventory/drift_detection_cli.py +69 -96
  129. runbooks/inventory/find_ec2_security_groups.py +1 -1
  130. runbooks/inventory/inventory_mcp_cli.py +48 -46
  131. runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
  132. runbooks/inventory/mcp_inventory_validator.py +549 -465
  133. runbooks/inventory/mcp_vpc_validator.py +359 -442
  134. runbooks/inventory/organizations_discovery.py +56 -52
  135. runbooks/inventory/rich_inventory_display.py +33 -32
  136. runbooks/inventory/unified_validation_engine.py +278 -251
  137. runbooks/inventory/vpc_analyzer.py +733 -696
  138. runbooks/inventory/vpc_architecture_validator.py +293 -348
  139. runbooks/inventory/vpc_dependency_analyzer.py +382 -378
  140. runbooks/inventory/vpc_flow_analyzer.py +3 -3
  141. runbooks/main.py +152 -9147
  142. runbooks/main_final.py +91 -60
  143. runbooks/main_minimal.py +22 -10
  144. runbooks/main_optimized.py +131 -100
  145. runbooks/main_ultra_minimal.py +7 -2
  146. runbooks/mcp/__init__.py +36 -0
  147. runbooks/mcp/integration.py +679 -0
  148. runbooks/metrics/dora_metrics_engine.py +2 -2
  149. runbooks/monitoring/performance_monitor.py +9 -4
  150. runbooks/operate/dynamodb_operations.py +3 -1
  151. runbooks/operate/ec2_operations.py +145 -137
  152. runbooks/operate/iam_operations.py +146 -152
  153. runbooks/operate/mcp_integration.py +1 -1
  154. runbooks/operate/networking_cost_heatmap.py +33 -10
  155. runbooks/operate/privatelink_operations.py +1 -1
  156. runbooks/operate/rds_operations.py +223 -254
  157. runbooks/operate/s3_operations.py +107 -118
  158. runbooks/operate/vpc_endpoints.py +1 -1
  159. runbooks/operate/vpc_operations.py +648 -618
  160. runbooks/remediation/base.py +1 -1
  161. runbooks/remediation/commons.py +10 -7
  162. runbooks/remediation/commvault_ec2_analysis.py +71 -67
  163. runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
  164. runbooks/remediation/multi_account.py +24 -21
  165. runbooks/remediation/rds_snapshot_list.py +91 -65
  166. runbooks/remediation/remediation_cli.py +92 -146
  167. runbooks/remediation/universal_account_discovery.py +83 -79
  168. runbooks/remediation/workspaces_list.py +49 -44
  169. runbooks/security/__init__.py +19 -0
  170. runbooks/security/assessment_runner.py +1150 -0
  171. runbooks/security/baseline_checker.py +812 -0
  172. runbooks/security/cloudops_automation_security_validator.py +509 -535
  173. runbooks/security/compliance_automation_engine.py +17 -17
  174. runbooks/security/config/__init__.py +2 -2
  175. runbooks/security/config/compliance_config.py +50 -50
  176. runbooks/security/config_template_generator.py +63 -76
  177. runbooks/security/enterprise_security_framework.py +1 -1
  178. runbooks/security/executive_security_dashboard.py +519 -508
  179. runbooks/security/integration_test_enterprise_security.py +5 -3
  180. runbooks/security/multi_account_security_controls.py +959 -1210
  181. runbooks/security/real_time_security_monitor.py +422 -444
  182. runbooks/security/run_script.py +1 -1
  183. runbooks/security/security_baseline_tester.py +1 -1
  184. runbooks/security/security_cli.py +143 -112
  185. runbooks/security/test_2way_validation.py +439 -0
  186. runbooks/security/two_way_validation_framework.py +852 -0
  187. runbooks/sre/mcp_reliability_engine.py +6 -6
  188. runbooks/sre/production_monitoring_framework.py +167 -177
  189. runbooks/tdd/__init__.py +15 -0
  190. runbooks/tdd/cli.py +1071 -0
  191. runbooks/utils/__init__.py +14 -17
  192. runbooks/utils/logger.py +7 -2
  193. runbooks/utils/version_validator.py +51 -48
  194. runbooks/validation/__init__.py +6 -6
  195. runbooks/validation/cli.py +9 -3
  196. runbooks/validation/comprehensive_2way_validator.py +754 -708
  197. runbooks/validation/mcp_validator.py +906 -228
  198. runbooks/validation/terraform_citations_validator.py +104 -115
  199. runbooks/validation/terraform_drift_detector.py +447 -451
  200. runbooks/vpc/README.md +617 -0
  201. runbooks/vpc/__init__.py +8 -1
  202. runbooks/vpc/analyzer.py +577 -0
  203. runbooks/vpc/cleanup_wrapper.py +476 -413
  204. runbooks/vpc/cli_cloudtrail_commands.py +339 -0
  205. runbooks/vpc/cli_mcp_validation_commands.py +480 -0
  206. runbooks/vpc/cloudtrail_audit_integration.py +717 -0
  207. runbooks/vpc/config.py +92 -97
  208. runbooks/vpc/cost_engine.py +411 -148
  209. runbooks/vpc/cost_explorer_integration.py +553 -0
  210. runbooks/vpc/cross_account_session.py +101 -106
  211. runbooks/vpc/enhanced_mcp_validation.py +917 -0
  212. runbooks/vpc/eni_gate_validator.py +961 -0
  213. runbooks/vpc/heatmap_engine.py +190 -162
  214. runbooks/vpc/mcp_no_eni_validator.py +681 -640
  215. runbooks/vpc/nat_gateway_optimizer.py +358 -0
  216. runbooks/vpc/networking_wrapper.py +15 -8
  217. runbooks/vpc/pdca_remediation_planner.py +528 -0
  218. runbooks/vpc/performance_optimized_analyzer.py +219 -231
  219. runbooks/vpc/runbooks_adapter.py +1167 -241
  220. runbooks/vpc/tdd_red_phase_stubs.py +601 -0
  221. runbooks/vpc/test_data_loader.py +358 -0
  222. runbooks/vpc/tests/conftest.py +314 -4
  223. runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
  224. runbooks/vpc/tests/test_cost_engine.py +0 -2
  225. runbooks/vpc/topology_generator.py +326 -0
  226. runbooks/vpc/unified_scenarios.py +1302 -1129
  227. runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
  228. runbooks-1.1.5.dist-info/METADATA +328 -0
  229. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/RECORD +233 -200
  230. runbooks/finops/README.md +0 -414
  231. runbooks/finops/accuracy_cross_validator.py +0 -647
  232. runbooks/finops/business_cases.py +0 -950
  233. runbooks/finops/dashboard_router.py +0 -922
  234. runbooks/finops/ebs_optimizer.py +0 -956
  235. runbooks/finops/embedded_mcp_validator.py +0 -1629
  236. runbooks/finops/enhanced_dashboard_runner.py +0 -527
  237. runbooks/finops/finops_dashboard.py +0 -584
  238. runbooks/finops/finops_scenarios.py +0 -1218
  239. runbooks/finops/legacy_migration.py +0 -730
  240. runbooks/finops/multi_dashboard.py +0 -1519
  241. runbooks/finops/single_dashboard.py +0 -1113
  242. runbooks/finops/unlimited_scenarios.py +0 -393
  243. runbooks-1.1.3.dist-info/METADATA +0 -799
  244. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
  245. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
  246. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
  247. {runbooks-1.1.3.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, print_header, print_success, print_error, print_warning, print_info,
31
- create_table, create_progress_bar, format_cost, create_panel
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, BusinessScenario, ExecutionMode, RiskLevel,
36
- ResourceImpact, BusinessMetrics, ComplianceMetrics
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('s3')[:3] # S3 is global, limit 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
- region, encryption_type
119
- )
120
- unencrypted_buckets.extend(region_results['unencrypted'])
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['bucket_name'],
137
- region=bucket_info['region'],
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 = ((len(encrypted_buckets) + violations_fixed) / total_buckets * 100)
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
- bucket['bucket_name'],
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('s3', region_name=region)
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 == 'us-east-1': # Only check from one region to avoid duplicates
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('Buckets', []):
285
- bucket_name = bucket['Name']
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
- 'bucket_name': bucket_name,
294
- 'region': region,
295
- 'encryption_type': 'Configured'
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['Error']['Code'] == 'ServerSideEncryptionConfigurationNotFoundError':
295
+ if e.response["Error"]["Code"] == "ServerSideEncryptionConfigurationNotFoundError":
300
296
  # Bucket has no encryption
301
- unencrypted_buckets.append({
302
- 'bucket_name': bucket_name,
303
- 'region': region,
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
- 'encrypted': encrypted_buckets,
314
- 'unencrypted': unencrypted_buckets
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['bucket_name']
341
-
327
+ bucket_name = bucket_info["bucket_name"]
328
+
342
329
  try:
343
- s3 = self.session.client('s3', region_name='us-east-1')
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
- 'Rules': [
359
- {
360
- 'ApplyServerSideEncryptionByDefault': {
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 (