runbooks 0.9.9__py3-none-any.whl → 1.0.1__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 +1 -1
- runbooks/cfat/WEIGHT_CONFIG_README.md +368 -0
- runbooks/cfat/app.ts +27 -19
- runbooks/cfat/assessment/runner.py +6 -5
- runbooks/cfat/cloud_foundations_assessment.py +626 -0
- runbooks/cfat/tests/test_weight_configuration.ts +449 -0
- runbooks/cfat/weight_config.ts +574 -0
- runbooks/cloudops/cost_optimizer.py +95 -33
- runbooks/common/__init__.py +26 -9
- runbooks/common/aws_pricing.py +1353 -0
- runbooks/common/aws_pricing_api.py +205 -0
- runbooks/common/aws_utils.py +2 -2
- runbooks/common/comprehensive_cost_explorer_integration.py +979 -0
- runbooks/common/cross_account_manager.py +606 -0
- runbooks/common/date_utils.py +115 -0
- runbooks/common/enhanced_exception_handler.py +14 -7
- runbooks/common/env_utils.py +96 -0
- runbooks/common/mcp_cost_explorer_integration.py +5 -4
- runbooks/common/mcp_integration.py +49 -2
- runbooks/common/organizations_client.py +579 -0
- runbooks/common/profile_utils.py +127 -72
- runbooks/common/rich_utils.py +3 -3
- runbooks/finops/cost_optimizer.py +2 -1
- runbooks/finops/dashboard_runner.py +47 -28
- runbooks/finops/ebs_optimizer.py +56 -9
- runbooks/finops/elastic_ip_optimizer.py +13 -9
- runbooks/finops/embedded_mcp_validator.py +31 -0
- runbooks/finops/enhanced_trend_visualization.py +10 -4
- runbooks/finops/finops_dashboard.py +6 -5
- runbooks/finops/iam_guidance.py +6 -1
- runbooks/finops/markdown_exporter.py +217 -2
- runbooks/finops/nat_gateway_optimizer.py +76 -20
- runbooks/finops/tests/test_integration.py +3 -1
- runbooks/finops/vpc_cleanup_exporter.py +28 -26
- runbooks/finops/vpc_cleanup_optimizer.py +363 -16
- runbooks/inventory/__init__.py +10 -1
- runbooks/inventory/cloud_foundations_integration.py +409 -0
- runbooks/inventory/core/collector.py +1177 -94
- runbooks/inventory/discovery.md +339 -0
- runbooks/inventory/drift_detection_cli.py +327 -0
- runbooks/inventory/inventory_mcp_cli.py +171 -0
- runbooks/inventory/inventory_modules.py +6 -9
- runbooks/inventory/list_ec2_instances.py +3 -3
- runbooks/inventory/mcp_inventory_validator.py +2149 -0
- runbooks/inventory/mcp_vpc_validator.py +23 -6
- runbooks/inventory/organizations_discovery.py +104 -9
- runbooks/inventory/rich_inventory_display.py +129 -1
- runbooks/inventory/unified_validation_engine.py +1279 -0
- runbooks/inventory/verify_ec2_security_groups.py +3 -1
- runbooks/inventory/vpc_analyzer.py +825 -7
- runbooks/inventory/vpc_flow_analyzer.py +36 -42
- runbooks/main.py +708 -47
- runbooks/monitoring/performance_monitor.py +11 -7
- runbooks/operate/base.py +9 -6
- runbooks/operate/deployment_framework.py +5 -4
- runbooks/operate/deployment_validator.py +6 -5
- runbooks/operate/dynamodb_operations.py +6 -5
- runbooks/operate/ec2_operations.py +3 -2
- runbooks/operate/mcp_integration.py +6 -5
- runbooks/operate/networking_cost_heatmap.py +21 -16
- runbooks/operate/s3_operations.py +13 -12
- runbooks/operate/vpc_operations.py +100 -12
- runbooks/remediation/base.py +4 -2
- runbooks/remediation/commons.py +5 -5
- runbooks/remediation/commvault_ec2_analysis.py +68 -15
- runbooks/remediation/config/accounts_example.json +31 -0
- runbooks/remediation/ec2_unattached_ebs_volumes.py +6 -3
- runbooks/remediation/multi_account.py +120 -7
- runbooks/remediation/rds_snapshot_list.py +5 -3
- runbooks/remediation/remediation_cli.py +710 -0
- runbooks/remediation/universal_account_discovery.py +377 -0
- runbooks/security/compliance_automation_engine.py +99 -20
- runbooks/security/config/__init__.py +24 -0
- runbooks/security/config/compliance_config.py +255 -0
- runbooks/security/config/compliance_weights_example.json +22 -0
- runbooks/security/config_template_generator.py +500 -0
- runbooks/security/security_cli.py +377 -0
- runbooks/validation/__init__.py +21 -1
- runbooks/validation/cli.py +8 -7
- runbooks/validation/comprehensive_2way_validator.py +2007 -0
- runbooks/validation/mcp_validator.py +965 -101
- runbooks/validation/terraform_citations_validator.py +363 -0
- runbooks/validation/terraform_drift_detector.py +1098 -0
- runbooks/vpc/cleanup_wrapper.py +231 -10
- runbooks/vpc/config.py +346 -73
- runbooks/vpc/cross_account_session.py +312 -0
- runbooks/vpc/heatmap_engine.py +115 -41
- runbooks/vpc/manager_interface.py +9 -9
- runbooks/vpc/mcp_no_eni_validator.py +1630 -0
- runbooks/vpc/networking_wrapper.py +14 -8
- runbooks/vpc/runbooks_adapter.py +33 -12
- runbooks/vpc/tests/conftest.py +4 -2
- runbooks/vpc/tests/test_cost_engine.py +4 -2
- runbooks/vpc/unified_scenarios.py +73 -3
- runbooks/vpc/vpc_cleanup_integration.py +512 -78
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/METADATA +94 -52
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/RECORD +101 -81
- runbooks/finops/runbooks.inventory.organizations_discovery.log +0 -0
- runbooks/finops/runbooks.security.report_generator.log +0 -0
- runbooks/finops/runbooks.security.run_script.log +0 -0
- runbooks/finops/runbooks.security.security_export.log +0 -0
- runbooks/finops/tests/results_test_finops_dashboard.xml +0 -1
- runbooks/inventory/artifacts/scale-optimize-status.txt +0 -12
- runbooks/inventory/runbooks.inventory.organizations_discovery.log +0 -0
- runbooks/inventory/runbooks.security.report_generator.log +0 -0
- runbooks/inventory/runbooks.security.run_script.log +0 -0
- runbooks/inventory/runbooks.security.security_export.log +0 -0
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/WHEEL +0 -0
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/entry_points.txt +0 -0
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/licenses/LICENSE +0 -0
- {runbooks-0.9.9.dist-info → runbooks-1.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,574 @@
|
|
1
|
+
/**
|
2
|
+
* Dynamic Weight Configuration System for CFAT Assessment
|
3
|
+
*
|
4
|
+
* Replaces 30+ hardcoded weight values with flexible, environment-aware
|
5
|
+
* configuration system supporting multiple compliance frameworks.
|
6
|
+
*
|
7
|
+
* Enterprise Features:
|
8
|
+
* - Framework-specific weight profiles (AWS Well-Architected, SOC2, etc.)
|
9
|
+
* - Environment-based weight adjustments (dev, staging, prod)
|
10
|
+
* - Dynamic weight calculation based on organization size
|
11
|
+
* - Override capabilities for specific requirements
|
12
|
+
*/
|
13
|
+
|
14
|
+
export interface WeightConfig {
|
15
|
+
// Core organizational checks
|
16
|
+
organization_created: number;
|
17
|
+
management_account_created: number;
|
18
|
+
|
19
|
+
// Identity and access management
|
20
|
+
iam_users_removed: number;
|
21
|
+
iam_idc_org_service_enabled: number;
|
22
|
+
iam_idc_configured: number;
|
23
|
+
|
24
|
+
// Resource management (Security best practices)
|
25
|
+
ec2_instances_removed: number;
|
26
|
+
vpc_removed: number;
|
27
|
+
|
28
|
+
// Logging and monitoring (Critical for compliance)
|
29
|
+
cloudtrail_created: number;
|
30
|
+
cloudtrail_org_service_enabled: number;
|
31
|
+
cloudtrail_org_trail_deployed: number;
|
32
|
+
config_recorder_management: number;
|
33
|
+
config_delivery_channel_management: number;
|
34
|
+
|
35
|
+
// Service integrations (Operational excellence)
|
36
|
+
cloudformation_stacksets_activated: number;
|
37
|
+
cloudformation_org_service_enabled: number;
|
38
|
+
guardduty_org_service_enabled: number;
|
39
|
+
ram_org_service_enabled: number;
|
40
|
+
securityhub_org_service_enabled: number;
|
41
|
+
iam_access_analyzer_org_service_enabled: number;
|
42
|
+
config_org_service_enabled: number;
|
43
|
+
backup_org_service_enabled: number;
|
44
|
+
|
45
|
+
// Organizational structure
|
46
|
+
infrastructure_ou_deployed: number;
|
47
|
+
security_ou_deployed: number;
|
48
|
+
workloads_ou_deployed: number;
|
49
|
+
|
50
|
+
// Governance and policies
|
51
|
+
scp_enabled: number;
|
52
|
+
tag_policy_enabled: number;
|
53
|
+
backup_policy_enabled: number;
|
54
|
+
|
55
|
+
// Control Tower (Landing Zone foundation)
|
56
|
+
control_tower_deployed: number;
|
57
|
+
control_tower_latest_version: number;
|
58
|
+
control_tower_not_drifted: number;
|
59
|
+
|
60
|
+
// Core accounts
|
61
|
+
log_archive_account_deployed: number;
|
62
|
+
audit_account_deployed: number;
|
63
|
+
|
64
|
+
// Legacy compliance
|
65
|
+
legacy_cur_setup: number;
|
66
|
+
}
|
67
|
+
|
68
|
+
export enum ComplianceFramework {
|
69
|
+
AWS_WELL_ARCHITECTED = 'aws-well-architected',
|
70
|
+
SOC2 = 'soc2',
|
71
|
+
PCI_DSS = 'pci-dss',
|
72
|
+
HIPAA = 'hipaa',
|
73
|
+
NIST = 'nist',
|
74
|
+
ISO_27001 = 'iso-27001',
|
75
|
+
CIS_BENCHMARKS = 'cis',
|
76
|
+
CUSTOM = 'custom'
|
77
|
+
}
|
78
|
+
|
79
|
+
export enum EnvironmentType {
|
80
|
+
DEVELOPMENT = 'development',
|
81
|
+
STAGING = 'staging',
|
82
|
+
PRODUCTION = 'production',
|
83
|
+
SANDBOX = 'sandbox'
|
84
|
+
}
|
85
|
+
|
86
|
+
export enum OrganizationSize {
|
87
|
+
SMALL = 'small', // < 10 accounts
|
88
|
+
MEDIUM = 'medium', // 10-100 accounts
|
89
|
+
LARGE = 'large', // 100-1000 accounts
|
90
|
+
ENTERPRISE = 'enterprise' // > 1000 accounts
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Default weight configurations for different compliance frameworks
|
95
|
+
*/
|
96
|
+
export const FRAMEWORK_WEIGHTS: Record<ComplianceFramework, WeightConfig> = {
|
97
|
+
[ComplianceFramework.AWS_WELL_ARCHITECTED]: {
|
98
|
+
// Foundational requirements (Critical - Weight 6)
|
99
|
+
organization_created: 6,
|
100
|
+
management_account_created: 6,
|
101
|
+
cloudtrail_created: 6,
|
102
|
+
cloudtrail_org_service_enabled: 6,
|
103
|
+
cloudtrail_org_trail_deployed: 6,
|
104
|
+
config_recorder_management: 6,
|
105
|
+
config_delivery_channel_management: 6,
|
106
|
+
iam_idc_org_service_enabled: 6,
|
107
|
+
iam_idc_configured: 6,
|
108
|
+
scp_enabled: 6,
|
109
|
+
tag_policy_enabled: 6,
|
110
|
+
control_tower_deployed: 6,
|
111
|
+
control_tower_not_drifted: 6,
|
112
|
+
security_ou_deployed: 6,
|
113
|
+
log_archive_account_deployed: 6,
|
114
|
+
audit_account_deployed: 6,
|
115
|
+
|
116
|
+
// Important but not critical (Weight 5)
|
117
|
+
cloudformation_stacksets_activated: 5,
|
118
|
+
cloudformation_org_service_enabled: 5,
|
119
|
+
infrastructure_ou_deployed: 5,
|
120
|
+
workloads_ou_deployed: 5,
|
121
|
+
backup_policy_enabled: 5,
|
122
|
+
control_tower_latest_version: 5,
|
123
|
+
|
124
|
+
// Best practices (Weight 4)
|
125
|
+
iam_users_removed: 4,
|
126
|
+
ec2_instances_removed: 4,
|
127
|
+
vpc_removed: 4,
|
128
|
+
legacy_cur_setup: 4,
|
129
|
+
guardduty_org_service_enabled: 4,
|
130
|
+
ram_org_service_enabled: 4,
|
131
|
+
securityhub_org_service_enabled: 4,
|
132
|
+
iam_access_analyzer_org_service_enabled: 4,
|
133
|
+
config_org_service_enabled: 4,
|
134
|
+
backup_org_service_enabled: 4
|
135
|
+
},
|
136
|
+
|
137
|
+
[ComplianceFramework.SOC2]: {
|
138
|
+
// SOC2 emphasizes security and availability (Higher security weights)
|
139
|
+
organization_created: 6,
|
140
|
+
management_account_created: 6,
|
141
|
+
cloudtrail_created: 6,
|
142
|
+
cloudtrail_org_service_enabled: 6,
|
143
|
+
cloudtrail_org_trail_deployed: 6,
|
144
|
+
config_recorder_management: 6,
|
145
|
+
config_delivery_channel_management: 6,
|
146
|
+
iam_idc_org_service_enabled: 6,
|
147
|
+
iam_idc_configured: 6,
|
148
|
+
scp_enabled: 6,
|
149
|
+
tag_policy_enabled: 5,
|
150
|
+
control_tower_deployed: 6,
|
151
|
+
control_tower_not_drifted: 6,
|
152
|
+
security_ou_deployed: 6,
|
153
|
+
log_archive_account_deployed: 6,
|
154
|
+
audit_account_deployed: 6,
|
155
|
+
securityhub_org_service_enabled: 6, // Higher weight for SOC2
|
156
|
+
iam_access_analyzer_org_service_enabled: 6, // Higher weight for SOC2
|
157
|
+
|
158
|
+
// Enhanced security monitoring
|
159
|
+
cloudformation_stacksets_activated: 5,
|
160
|
+
cloudformation_org_service_enabled: 5,
|
161
|
+
infrastructure_ou_deployed: 5,
|
162
|
+
workloads_ou_deployed: 5,
|
163
|
+
backup_policy_enabled: 6, // Higher for data protection
|
164
|
+
control_tower_latest_version: 5,
|
165
|
+
guardduty_org_service_enabled: 6, // Higher for threat detection
|
166
|
+
|
167
|
+
// Management account hygiene (Important for SOC2)
|
168
|
+
iam_users_removed: 5, // Higher weight for SOC2
|
169
|
+
ec2_instances_removed: 5, // Higher weight for SOC2
|
170
|
+
vpc_removed: 5, // Higher weight for SOC2
|
171
|
+
legacy_cur_setup: 4,
|
172
|
+
ram_org_service_enabled: 4,
|
173
|
+
config_org_service_enabled: 5,
|
174
|
+
backup_org_service_enabled: 6
|
175
|
+
},
|
176
|
+
|
177
|
+
[ComplianceFramework.PCI_DSS]: {
|
178
|
+
// PCI-DSS focuses on data protection and network security
|
179
|
+
organization_created: 6,
|
180
|
+
management_account_created: 6,
|
181
|
+
cloudtrail_created: 6,
|
182
|
+
cloudtrail_org_service_enabled: 6,
|
183
|
+
cloudtrail_org_trail_deployed: 6,
|
184
|
+
config_recorder_management: 6,
|
185
|
+
config_delivery_channel_management: 6,
|
186
|
+
iam_idc_org_service_enabled: 6,
|
187
|
+
iam_idc_configured: 6,
|
188
|
+
scp_enabled: 6,
|
189
|
+
tag_policy_enabled: 6,
|
190
|
+
control_tower_deployed: 6,
|
191
|
+
control_tower_not_drifted: 6,
|
192
|
+
security_ou_deployed: 6,
|
193
|
+
log_archive_account_deployed: 6,
|
194
|
+
audit_account_deployed: 6,
|
195
|
+
|
196
|
+
// Enhanced for PCI-DSS network and data requirements
|
197
|
+
securityhub_org_service_enabled: 6,
|
198
|
+
iam_access_analyzer_org_service_enabled: 6,
|
199
|
+
guardduty_org_service_enabled: 6,
|
200
|
+
backup_policy_enabled: 6,
|
201
|
+
backup_org_service_enabled: 6,
|
202
|
+
|
203
|
+
// Network isolation requirements
|
204
|
+
iam_users_removed: 6, // Critical for PCI-DSS
|
205
|
+
ec2_instances_removed: 6, // Critical for network isolation
|
206
|
+
vpc_removed: 6, // Critical for network isolation
|
207
|
+
|
208
|
+
cloudformation_stacksets_activated: 5,
|
209
|
+
cloudformation_org_service_enabled: 5,
|
210
|
+
infrastructure_ou_deployed: 5,
|
211
|
+
workloads_ou_deployed: 5,
|
212
|
+
control_tower_latest_version: 5,
|
213
|
+
legacy_cur_setup: 4,
|
214
|
+
ram_org_service_enabled: 4,
|
215
|
+
config_org_service_enabled: 5
|
216
|
+
},
|
217
|
+
|
218
|
+
[ComplianceFramework.HIPAA]: {
|
219
|
+
// HIPAA emphasizes data protection and audit trails
|
220
|
+
organization_created: 6,
|
221
|
+
management_account_created: 6,
|
222
|
+
cloudtrail_created: 6,
|
223
|
+
cloudtrail_org_service_enabled: 6,
|
224
|
+
cloudtrail_org_trail_deployed: 6,
|
225
|
+
config_recorder_management: 6,
|
226
|
+
config_delivery_channel_management: 6,
|
227
|
+
iam_idc_org_service_enabled: 6,
|
228
|
+
iam_idc_configured: 6,
|
229
|
+
scp_enabled: 6,
|
230
|
+
tag_policy_enabled: 6,
|
231
|
+
control_tower_deployed: 6,
|
232
|
+
control_tower_not_drifted: 6,
|
233
|
+
security_ou_deployed: 6,
|
234
|
+
log_archive_account_deployed: 6,
|
235
|
+
audit_account_deployed: 6,
|
236
|
+
|
237
|
+
// Data protection and monitoring
|
238
|
+
securityhub_org_service_enabled: 6,
|
239
|
+
iam_access_analyzer_org_service_enabled: 6,
|
240
|
+
backup_policy_enabled: 6,
|
241
|
+
backup_org_service_enabled: 6,
|
242
|
+
config_org_service_enabled: 6,
|
243
|
+
|
244
|
+
// Audit and compliance
|
245
|
+
cloudformation_stacksets_activated: 5,
|
246
|
+
cloudformation_org_service_enabled: 5,
|
247
|
+
infrastructure_ou_deployed: 5,
|
248
|
+
workloads_ou_deployed: 5,
|
249
|
+
control_tower_latest_version: 5,
|
250
|
+
guardduty_org_service_enabled: 5,
|
251
|
+
|
252
|
+
// Access controls
|
253
|
+
iam_users_removed: 5,
|
254
|
+
ec2_instances_removed: 4,
|
255
|
+
vpc_removed: 4,
|
256
|
+
legacy_cur_setup: 4,
|
257
|
+
ram_org_service_enabled: 4
|
258
|
+
},
|
259
|
+
|
260
|
+
[ComplianceFramework.NIST]: {
|
261
|
+
// NIST Cybersecurity Framework alignment
|
262
|
+
organization_created: 6,
|
263
|
+
management_account_created: 6,
|
264
|
+
cloudtrail_created: 6,
|
265
|
+
cloudtrail_org_service_enabled: 6,
|
266
|
+
cloudtrail_org_trail_deployed: 6,
|
267
|
+
config_recorder_management: 6,
|
268
|
+
config_delivery_channel_management: 6,
|
269
|
+
iam_idc_org_service_enabled: 6,
|
270
|
+
iam_idc_configured: 6,
|
271
|
+
scp_enabled: 6,
|
272
|
+
tag_policy_enabled: 5,
|
273
|
+
control_tower_deployed: 6,
|
274
|
+
control_tower_not_drifted: 6,
|
275
|
+
security_ou_deployed: 6,
|
276
|
+
log_archive_account_deployed: 6,
|
277
|
+
audit_account_deployed: 6,
|
278
|
+
|
279
|
+
// Identify, Protect, Detect framework
|
280
|
+
securityhub_org_service_enabled: 6,
|
281
|
+
iam_access_analyzer_org_service_enabled: 6,
|
282
|
+
guardduty_org_service_enabled: 6,
|
283
|
+
backup_policy_enabled: 5,
|
284
|
+
backup_org_service_enabled: 5,
|
285
|
+
|
286
|
+
cloudformation_stacksets_activated: 5,
|
287
|
+
cloudformation_org_service_enabled: 5,
|
288
|
+
infrastructure_ou_deployed: 5,
|
289
|
+
workloads_ou_deployed: 5,
|
290
|
+
control_tower_latest_version: 5,
|
291
|
+
config_org_service_enabled: 5,
|
292
|
+
|
293
|
+
iam_users_removed: 4,
|
294
|
+
ec2_instances_removed: 4,
|
295
|
+
vpc_removed: 4,
|
296
|
+
legacy_cur_setup: 4,
|
297
|
+
ram_org_service_enabled: 4
|
298
|
+
},
|
299
|
+
|
300
|
+
[ComplianceFramework.ISO_27001]: {
|
301
|
+
// ISO 27001 Information Security Management
|
302
|
+
organization_created: 6,
|
303
|
+
management_account_created: 6,
|
304
|
+
cloudtrail_created: 6,
|
305
|
+
cloudtrail_org_service_enabled: 6,
|
306
|
+
cloudtrail_org_trail_deployed: 6,
|
307
|
+
config_recorder_management: 6,
|
308
|
+
config_delivery_channel_management: 6,
|
309
|
+
iam_idc_org_service_enabled: 6,
|
310
|
+
iam_idc_configured: 6,
|
311
|
+
scp_enabled: 6,
|
312
|
+
tag_policy_enabled: 6,
|
313
|
+
control_tower_deployed: 6,
|
314
|
+
control_tower_not_drifted: 6,
|
315
|
+
security_ou_deployed: 6,
|
316
|
+
log_archive_account_deployed: 6,
|
317
|
+
audit_account_deployed: 6,
|
318
|
+
|
319
|
+
// Information security controls
|
320
|
+
securityhub_org_service_enabled: 6,
|
321
|
+
iam_access_analyzer_org_service_enabled: 6,
|
322
|
+
backup_policy_enabled: 6,
|
323
|
+
backup_org_service_enabled: 6,
|
324
|
+
config_org_service_enabled: 6,
|
325
|
+
guardduty_org_service_enabled: 5,
|
326
|
+
|
327
|
+
cloudformation_stacksets_activated: 5,
|
328
|
+
cloudformation_org_service_enabled: 5,
|
329
|
+
infrastructure_ou_deployed: 5,
|
330
|
+
workloads_ou_deployed: 5,
|
331
|
+
control_tower_latest_version: 5,
|
332
|
+
|
333
|
+
iam_users_removed: 5,
|
334
|
+
ec2_instances_removed: 4,
|
335
|
+
vpc_removed: 4,
|
336
|
+
legacy_cur_setup: 4,
|
337
|
+
ram_org_service_enabled: 4
|
338
|
+
},
|
339
|
+
|
340
|
+
[ComplianceFramework.CIS_BENCHMARKS]: {
|
341
|
+
// CIS Controls alignment
|
342
|
+
organization_created: 6,
|
343
|
+
management_account_created: 6,
|
344
|
+
cloudtrail_created: 6,
|
345
|
+
cloudtrail_org_service_enabled: 6,
|
346
|
+
cloudtrail_org_trail_deployed: 6,
|
347
|
+
config_recorder_management: 6,
|
348
|
+
config_delivery_channel_management: 6,
|
349
|
+
iam_idc_org_service_enabled: 6,
|
350
|
+
iam_idc_configured: 6,
|
351
|
+
scp_enabled: 6,
|
352
|
+
tag_policy_enabled: 5,
|
353
|
+
control_tower_deployed: 6,
|
354
|
+
control_tower_not_drifted: 6,
|
355
|
+
security_ou_deployed: 6,
|
356
|
+
log_archive_account_deployed: 6,
|
357
|
+
audit_account_deployed: 6,
|
358
|
+
|
359
|
+
// CIS Controls emphasis
|
360
|
+
securityhub_org_service_enabled: 6,
|
361
|
+
iam_access_analyzer_org_service_enabled: 6,
|
362
|
+
guardduty_org_service_enabled: 6,
|
363
|
+
backup_policy_enabled: 5,
|
364
|
+
backup_org_service_enabled: 5,
|
365
|
+
config_org_service_enabled: 6,
|
366
|
+
|
367
|
+
cloudformation_stacksets_activated: 5,
|
368
|
+
cloudformation_org_service_enabled: 5,
|
369
|
+
infrastructure_ou_deployed: 5,
|
370
|
+
workloads_ou_deployed: 5,
|
371
|
+
control_tower_latest_version: 5,
|
372
|
+
|
373
|
+
// Asset and access management
|
374
|
+
iam_users_removed: 5,
|
375
|
+
ec2_instances_removed: 5,
|
376
|
+
vpc_removed: 5,
|
377
|
+
legacy_cur_setup: 4,
|
378
|
+
ram_org_service_enabled: 4
|
379
|
+
},
|
380
|
+
|
381
|
+
[ComplianceFramework.CUSTOM]: {
|
382
|
+
// Balanced default weights (original hardcoded values preserved)
|
383
|
+
organization_created: 6,
|
384
|
+
management_account_created: 6,
|
385
|
+
iam_users_removed: 4,
|
386
|
+
ec2_instances_removed: 4,
|
387
|
+
vpc_removed: 4,
|
388
|
+
legacy_cur_setup: 4,
|
389
|
+
cloudtrail_created: 6,
|
390
|
+
cloudtrail_org_service_enabled: 6,
|
391
|
+
cloudtrail_org_trail_deployed: 6,
|
392
|
+
config_recorder_management: 6,
|
393
|
+
config_delivery_channel_management: 6,
|
394
|
+
cloudformation_stacksets_activated: 5,
|
395
|
+
guardduty_org_service_enabled: 4,
|
396
|
+
ram_org_service_enabled: 4,
|
397
|
+
securityhub_org_service_enabled: 4,
|
398
|
+
iam_access_analyzer_org_service_enabled: 4,
|
399
|
+
config_org_service_enabled: 4,
|
400
|
+
cloudformation_org_service_enabled: 5,
|
401
|
+
backup_org_service_enabled: 4,
|
402
|
+
infrastructure_ou_deployed: 5,
|
403
|
+
security_ou_deployed: 6,
|
404
|
+
workloads_ou_deployed: 5,
|
405
|
+
iam_idc_org_service_enabled: 6,
|
406
|
+
iam_idc_configured: 6,
|
407
|
+
scp_enabled: 6,
|
408
|
+
tag_policy_enabled: 6,
|
409
|
+
backup_policy_enabled: 5,
|
410
|
+
control_tower_deployed: 6,
|
411
|
+
control_tower_latest_version: 5,
|
412
|
+
control_tower_not_drifted: 6,
|
413
|
+
log_archive_account_deployed: 6,
|
414
|
+
audit_account_deployed: 6
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
/**
|
419
|
+
* Environment-based weight modifiers
|
420
|
+
*/
|
421
|
+
export const ENVIRONMENT_MODIFIERS: Record<EnvironmentType, number> = {
|
422
|
+
[EnvironmentType.DEVELOPMENT]: 0.8, // 20% reduction for dev environments
|
423
|
+
[EnvironmentType.STAGING]: 0.9, // 10% reduction for staging
|
424
|
+
[EnvironmentType.PRODUCTION]: 1.0, // Full weight for production
|
425
|
+
[EnvironmentType.SANDBOX]: 0.6 // 40% reduction for sandbox
|
426
|
+
};
|
427
|
+
|
428
|
+
/**
|
429
|
+
* Organization size-based weight adjustments
|
430
|
+
*/
|
431
|
+
export const SIZE_MODIFIERS: Record<OrganizationSize, Partial<WeightConfig>> = {
|
432
|
+
[OrganizationSize.SMALL]: {
|
433
|
+
// Small orgs might not need all enterprise features
|
434
|
+
infrastructure_ou_deployed: -1,
|
435
|
+
workloads_ou_deployed: -1,
|
436
|
+
backup_policy_enabled: -1
|
437
|
+
},
|
438
|
+
[OrganizationSize.MEDIUM]: {
|
439
|
+
// Medium orgs benefit from all features
|
440
|
+
},
|
441
|
+
[OrganizationSize.LARGE]: {
|
442
|
+
// Large orgs need enhanced governance
|
443
|
+
scp_enabled: +1,
|
444
|
+
tag_policy_enabled: +1,
|
445
|
+
backup_policy_enabled: +1
|
446
|
+
},
|
447
|
+
[OrganizationSize.ENTERPRISE]: {
|
448
|
+
// Enterprise requires maximum governance
|
449
|
+
scp_enabled: +1,
|
450
|
+
tag_policy_enabled: +1,
|
451
|
+
backup_policy_enabled: +1,
|
452
|
+
control_tower_deployed: +1,
|
453
|
+
security_ou_deployed: +1
|
454
|
+
}
|
455
|
+
};
|
456
|
+
|
457
|
+
/**
|
458
|
+
* Get dynamic weight configuration based on environment context
|
459
|
+
*/
|
460
|
+
export function getWeightConfig(
|
461
|
+
framework: ComplianceFramework = ComplianceFramework.AWS_WELL_ARCHITECTED,
|
462
|
+
environment: EnvironmentType = EnvironmentType.PRODUCTION,
|
463
|
+
orgSize: OrganizationSize = OrganizationSize.MEDIUM,
|
464
|
+
customOverrides: Partial<WeightConfig> = {}
|
465
|
+
): WeightConfig {
|
466
|
+
// Start with framework-specific weights
|
467
|
+
const baseWeights = { ...FRAMEWORK_WEIGHTS[framework] };
|
468
|
+
|
469
|
+
// Apply environment modifier
|
470
|
+
const envModifier = ENVIRONMENT_MODIFIERS[environment];
|
471
|
+
|
472
|
+
// Apply size-based adjustments
|
473
|
+
const sizeAdjustments = SIZE_MODIFIERS[orgSize] || {};
|
474
|
+
|
475
|
+
// Calculate final weights
|
476
|
+
const finalWeights: WeightConfig = { ...baseWeights };
|
477
|
+
|
478
|
+
// Apply environment modifier (multiply by modifier, round to nearest integer)
|
479
|
+
Object.keys(finalWeights).forEach(key => {
|
480
|
+
const typedKey = key as keyof WeightConfig;
|
481
|
+
finalWeights[typedKey] = Math.round(baseWeights[typedKey] * envModifier);
|
482
|
+
});
|
483
|
+
|
484
|
+
// Apply size adjustments (add/subtract values)
|
485
|
+
Object.keys(sizeAdjustments).forEach(key => {
|
486
|
+
const typedKey = key as keyof WeightConfig;
|
487
|
+
if (finalWeights[typedKey] !== undefined && sizeAdjustments[typedKey] !== undefined) {
|
488
|
+
finalWeights[typedKey] = Math.max(1, finalWeights[typedKey] + sizeAdjustments[typedKey]!);
|
489
|
+
}
|
490
|
+
});
|
491
|
+
|
492
|
+
// Apply custom overrides
|
493
|
+
Object.keys(customOverrides).forEach(key => {
|
494
|
+
const typedKey = key as keyof WeightConfig;
|
495
|
+
if (customOverrides[typedKey] !== undefined) {
|
496
|
+
finalWeights[typedKey] = customOverrides[typedKey]!;
|
497
|
+
}
|
498
|
+
});
|
499
|
+
|
500
|
+
return finalWeights;
|
501
|
+
}
|
502
|
+
|
503
|
+
/**
|
504
|
+
* Validate weight configuration values
|
505
|
+
*/
|
506
|
+
export function validateWeightConfig(config: WeightConfig): { valid: boolean; errors: string[] } {
|
507
|
+
const errors: string[] = [];
|
508
|
+
|
509
|
+
Object.entries(config).forEach(([key, value]) => {
|
510
|
+
if (typeof value !== 'number') {
|
511
|
+
errors.push(`Weight for ${key} must be a number, got ${typeof value}`);
|
512
|
+
} else if (value < 1 || value > 10) {
|
513
|
+
errors.push(`Weight for ${key} must be between 1 and 10, got ${value}`);
|
514
|
+
} else if (!Number.isInteger(value)) {
|
515
|
+
errors.push(`Weight for ${key} must be an integer, got ${value}`);
|
516
|
+
}
|
517
|
+
});
|
518
|
+
|
519
|
+
return {
|
520
|
+
valid: errors.length === 0,
|
521
|
+
errors
|
522
|
+
};
|
523
|
+
}
|
524
|
+
|
525
|
+
/**
|
526
|
+
* Load weight configuration from environment variables or defaults
|
527
|
+
*/
|
528
|
+
export function loadWeightConfigFromEnv(): {
|
529
|
+
framework: ComplianceFramework;
|
530
|
+
environment: EnvironmentType;
|
531
|
+
orgSize: OrganizationSize;
|
532
|
+
customOverrides: Partial<WeightConfig>;
|
533
|
+
} {
|
534
|
+
// Load from environment variables with sensible defaults
|
535
|
+
const framework = (process.env.CFAT_COMPLIANCE_FRAMEWORK as ComplianceFramework)
|
536
|
+
|| ComplianceFramework.AWS_WELL_ARCHITECTED;
|
537
|
+
|
538
|
+
const environment = (process.env.CFAT_ENVIRONMENT_TYPE as EnvironmentType)
|
539
|
+
|| EnvironmentType.PRODUCTION;
|
540
|
+
|
541
|
+
const orgSize = (process.env.CFAT_ORG_SIZE as OrganizationSize)
|
542
|
+
|| OrganizationSize.MEDIUM;
|
543
|
+
|
544
|
+
// Load custom overrides from environment (JSON format)
|
545
|
+
let customOverrides: Partial<WeightConfig> = {};
|
546
|
+
const customOverridesEnv = process.env.CFAT_WEIGHT_OVERRIDES;
|
547
|
+
if (customOverridesEnv) {
|
548
|
+
try {
|
549
|
+
customOverrides = JSON.parse(customOverridesEnv);
|
550
|
+
} catch (error) {
|
551
|
+
console.warn('Invalid JSON in CFAT_WEIGHT_OVERRIDES, using defaults:', error);
|
552
|
+
}
|
553
|
+
}
|
554
|
+
|
555
|
+
return {
|
556
|
+
framework,
|
557
|
+
environment,
|
558
|
+
orgSize,
|
559
|
+
customOverrides
|
560
|
+
};
|
561
|
+
}
|
562
|
+
|
563
|
+
/**
|
564
|
+
* Export default configuration for easy importing
|
565
|
+
*/
|
566
|
+
export function getDefaultWeightConfig(): WeightConfig {
|
567
|
+
const envConfig = loadWeightConfigFromEnv();
|
568
|
+
return getWeightConfig(
|
569
|
+
envConfig.framework,
|
570
|
+
envConfig.environment,
|
571
|
+
envConfig.orgSize,
|
572
|
+
envConfig.customOverrides
|
573
|
+
);
|
574
|
+
}
|