runbooks 0.7.0__py3-none-any.whl → 0.7.6__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 (132) hide show
  1. runbooks/__init__.py +87 -37
  2. runbooks/cfat/README.md +300 -49
  3. runbooks/cfat/__init__.py +2 -2
  4. runbooks/finops/__init__.py +1 -1
  5. runbooks/finops/cli.py +1 -1
  6. runbooks/inventory/collectors/__init__.py +8 -0
  7. runbooks/inventory/collectors/aws_management.py +791 -0
  8. runbooks/inventory/collectors/aws_networking.py +3 -3
  9. runbooks/main.py +3389 -782
  10. runbooks/operate/__init__.py +207 -0
  11. runbooks/operate/base.py +311 -0
  12. runbooks/operate/cloudformation_operations.py +619 -0
  13. runbooks/operate/cloudwatch_operations.py +496 -0
  14. runbooks/operate/dynamodb_operations.py +812 -0
  15. runbooks/operate/ec2_operations.py +926 -0
  16. runbooks/operate/iam_operations.py +569 -0
  17. runbooks/operate/s3_operations.py +1211 -0
  18. runbooks/operate/tagging_operations.py +655 -0
  19. runbooks/remediation/CLAUDE.md +100 -0
  20. runbooks/remediation/DOME9.md +218 -0
  21. runbooks/remediation/README.md +26 -0
  22. runbooks/remediation/Tests/__init__.py +0 -0
  23. runbooks/remediation/Tests/update_policy.py +74 -0
  24. runbooks/remediation/__init__.py +95 -0
  25. runbooks/remediation/acm_cert_expired_unused.py +98 -0
  26. runbooks/remediation/acm_remediation.py +875 -0
  27. runbooks/remediation/api_gateway_list.py +167 -0
  28. runbooks/remediation/base.py +643 -0
  29. runbooks/remediation/cloudtrail_remediation.py +908 -0
  30. runbooks/remediation/cloudtrail_s3_modifications.py +296 -0
  31. runbooks/remediation/cognito_active_users.py +78 -0
  32. runbooks/remediation/cognito_remediation.py +856 -0
  33. runbooks/remediation/cognito_user_password_reset.py +163 -0
  34. runbooks/remediation/commons.py +455 -0
  35. runbooks/remediation/dynamodb_optimize.py +155 -0
  36. runbooks/remediation/dynamodb_remediation.py +744 -0
  37. runbooks/remediation/dynamodb_server_side_encryption.py +108 -0
  38. runbooks/remediation/ec2_public_ips.py +134 -0
  39. runbooks/remediation/ec2_remediation.py +892 -0
  40. runbooks/remediation/ec2_subnet_disable_auto_ip_assignment.py +72 -0
  41. runbooks/remediation/ec2_unattached_ebs_volumes.py +448 -0
  42. runbooks/remediation/ec2_unused_security_groups.py +202 -0
  43. runbooks/remediation/kms_enable_key_rotation.py +651 -0
  44. runbooks/remediation/kms_remediation.py +717 -0
  45. runbooks/remediation/lambda_list.py +243 -0
  46. runbooks/remediation/lambda_remediation.py +971 -0
  47. runbooks/remediation/multi_account.py +569 -0
  48. runbooks/remediation/rds_instance_list.py +199 -0
  49. runbooks/remediation/rds_remediation.py +873 -0
  50. runbooks/remediation/rds_snapshot_list.py +192 -0
  51. runbooks/remediation/requirements.txt +118 -0
  52. runbooks/remediation/s3_block_public_access.py +159 -0
  53. runbooks/remediation/s3_bucket_public_access.py +143 -0
  54. runbooks/remediation/s3_disable_static_website_hosting.py +74 -0
  55. runbooks/remediation/s3_downloader.py +215 -0
  56. runbooks/remediation/s3_enable_access_logging.py +562 -0
  57. runbooks/remediation/s3_encryption.py +526 -0
  58. runbooks/remediation/s3_force_ssl_secure_policy.py +143 -0
  59. runbooks/remediation/s3_list.py +141 -0
  60. runbooks/remediation/s3_object_search.py +201 -0
  61. runbooks/remediation/s3_remediation.py +816 -0
  62. runbooks/remediation/scan_for_phrase.py +425 -0
  63. runbooks/remediation/workspaces_list.py +220 -0
  64. runbooks/security/__init__.py +9 -10
  65. runbooks/security/security_baseline_tester.py +4 -2
  66. runbooks-0.7.6.dist-info/METADATA +608 -0
  67. {runbooks-0.7.0.dist-info → runbooks-0.7.6.dist-info}/RECORD +84 -76
  68. {runbooks-0.7.0.dist-info → runbooks-0.7.6.dist-info}/entry_points.txt +0 -1
  69. {runbooks-0.7.0.dist-info → runbooks-0.7.6.dist-info}/top_level.txt +0 -1
  70. jupyter-agent/.env +0 -2
  71. jupyter-agent/.env.template +0 -2
  72. jupyter-agent/.gitattributes +0 -35
  73. jupyter-agent/.gradio/certificate.pem +0 -31
  74. jupyter-agent/README.md +0 -16
  75. jupyter-agent/__main__.log +0 -8
  76. jupyter-agent/app.py +0 -256
  77. jupyter-agent/cloudops-agent.png +0 -0
  78. jupyter-agent/ds-system-prompt.txt +0 -154
  79. jupyter-agent/jupyter-agent.png +0 -0
  80. jupyter-agent/llama3_template.jinja +0 -123
  81. jupyter-agent/requirements.txt +0 -9
  82. jupyter-agent/tmp/4ojbs8a02ir/jupyter-agent.ipynb +0 -68
  83. jupyter-agent/tmp/cm5iasgpm3p/jupyter-agent.ipynb +0 -91
  84. jupyter-agent/tmp/crqbsseag5/jupyter-agent.ipynb +0 -91
  85. jupyter-agent/tmp/hohanq1u097/jupyter-agent.ipynb +0 -57
  86. jupyter-agent/tmp/jns1sam29wm/jupyter-agent.ipynb +0 -53
  87. jupyter-agent/tmp/jupyter-agent.ipynb +0 -27
  88. jupyter-agent/utils.py +0 -409
  89. runbooks/aws/__init__.py +0 -58
  90. runbooks/aws/dynamodb_operations.py +0 -231
  91. runbooks/aws/ec2_copy_image_cross-region.py +0 -195
  92. runbooks/aws/ec2_describe_instances.py +0 -202
  93. runbooks/aws/ec2_ebs_snapshots_delete.py +0 -186
  94. runbooks/aws/ec2_run_instances.py +0 -213
  95. runbooks/aws/ec2_start_stop_instances.py +0 -212
  96. runbooks/aws/ec2_terminate_instances.py +0 -143
  97. runbooks/aws/ec2_unused_eips.py +0 -196
  98. runbooks/aws/ec2_unused_volumes.py +0 -188
  99. runbooks/aws/s3_create_bucket.py +0 -142
  100. runbooks/aws/s3_list_buckets.py +0 -152
  101. runbooks/aws/s3_list_objects.py +0 -156
  102. runbooks/aws/s3_object_operations.py +0 -183
  103. runbooks/aws/tagging_lambda_handler.py +0 -183
  104. runbooks/inventory/FAILED_SCRIPTS_TROUBLESHOOTING.md +0 -619
  105. runbooks/inventory/PASSED_SCRIPTS_GUIDE.md +0 -738
  106. runbooks/inventory/aws_organization.png +0 -0
  107. runbooks/inventory/cfn_move_stack_instances.py +0 -1526
  108. runbooks/inventory/delete_s3_buckets_objects.py +0 -169
  109. runbooks/inventory/lockdown_cfn_stackset_role.py +0 -224
  110. runbooks/inventory/update_aws_actions.py +0 -173
  111. runbooks/inventory/update_cfn_stacksets.py +0 -1215
  112. runbooks/inventory/update_cloudwatch_logs_retention_policy.py +0 -294
  113. runbooks/inventory/update_iam_roles_cross_accounts.py +0 -478
  114. runbooks/inventory/update_s3_public_access_block.py +0 -539
  115. runbooks/organizations/__init__.py +0 -12
  116. runbooks/organizations/manager.py +0 -374
  117. runbooks-0.7.0.dist-info/METADATA +0 -375
  118. /runbooks/inventory/{tests → Tests}/common_test_data.py +0 -0
  119. /runbooks/inventory/{tests → Tests}/common_test_functions.py +0 -0
  120. /runbooks/inventory/{tests → Tests}/script_test_data.py +0 -0
  121. /runbooks/inventory/{tests → Tests}/setup.py +0 -0
  122. /runbooks/inventory/{tests → Tests}/src.py +0 -0
  123. /runbooks/inventory/{tests/test_inventory_modules.py → Tests/test_Inventory_Modules.py} +0 -0
  124. /runbooks/inventory/{tests → Tests}/test_cfn_describe_stacks.py +0 -0
  125. /runbooks/inventory/{tests → Tests}/test_ec2_describe_instances.py +0 -0
  126. /runbooks/inventory/{tests → Tests}/test_lambda_list_functions.py +0 -0
  127. /runbooks/inventory/{tests → Tests}/test_moto_integration_example.py +0 -0
  128. /runbooks/inventory/{tests → Tests}/test_org_list_accounts.py +0 -0
  129. /runbooks/inventory/{Inventory_Modules.py → inventory_modules.py} +0 -0
  130. /runbooks/{aws → operate}/tags.json +0 -0
  131. {runbooks-0.7.0.dist-info → runbooks-0.7.6.dist-info}/WHEEL +0 -0
  132. {runbooks-0.7.0.dist-info → runbooks-0.7.6.dist-info}/licenses/LICENSE +0 -0
@@ -1,619 +0,0 @@
1
- # AWS Cloud Foundations Inventory - FAILED Scripts Troubleshooting Guide
2
-
3
- ## ✅ **IMPROVEMENTS IMPLEMENTED: Enhanced Error Handling & Credential Management (v0.6.1)**
4
-
5
- **Priority 1 fixes successfully implemented following FAANG agility and KISS/DRY principles:**
6
-
7
- ### 🔧 **Fixed Issues**
8
-
9
- 1. **✅ IAM Policies Credential Fix** (`Inventory_Modules.py:2323`)
10
- - **Issue**: Region inconsistency in `find_account_policies2` function
11
- - **Fix**: Changed `ocredentials['Region']` to `fRegion` parameter
12
- - **Impact**: Proper SSO credential handling for IAM operations
13
-
14
- 2. **✅ Security Groups Queue Fix** (`find_ec2_security_groups.py:427`)
15
- - **Issue**: Queue unpacking error - expecting 4 values, getting 1
16
- - **Fix**: Modified queue population to pass tuple `(credential, fFragment, fExact, fDefault)`
17
- - **Impact**: Concurrent processing now works correctly
18
-
19
- 3. **✅ Lockdown Script Parameters** (`inventory.sh:168-170`)
20
- - **Issue**: Missing required `--region` parameter
21
- - **Fix**: Added special case for `lockdown_cfn_stackset_role.py` to include `--region us-east-1`
22
- - **Impact**: Script can now be tested autonomously
23
-
24
- ---
25
-
26
- ## ⚠️ **REMAINING FAILED Scripts Analysis: ~3/46 scripts requiring attention (~6.5% failure rate)**
27
-
28
- This guide provides root cause analysis, troubleshooting steps, and actionable TODO/FIXME items for senior developers to address the remaining failed scripts. Major categories have been resolved through systematic fixes and framework exclusions.
29
-
30
- ---
31
-
32
- ## 🔍 **Root Cause Categories**
33
-
34
- ### **1. AWS Credential Issues (1 script)** - *MOSTLY FIXED*
35
- - ~~`list_iam_policies.py`~~ - **FIXED** ✅
36
- - ~~`list_ssm_parameters.py`~~ - **WORKING** ✅
37
- - ~~*(Partially) all_my_instances_wrapper.py*~~ - **FIXED** ✅
38
-
39
- ### **2. Timeout Issues (2 scripts)** - *REDUCED*
40
- - `check_controltower_readiness.py`
41
- - ~~`find_ec2_security_groups.py`~~ - **QUEUE FIXED** ✅
42
- - `list_cfn_stacks.py`
43
-
44
- ### **3. Logic/Code Errors (1 script)**
45
- - `find_ec2_security_groups.py` (also has timeout)
46
-
47
- ### **4. Missing Required Parameters (0 scripts)** - *FIXED*
48
- - ~~`lockdown_cfn_stackset_role.py`~~ - **FIXED** ✅
49
- - ~~`run_on_multi_accounts.py`~~ - **EXCLUDED** ✅
50
-
51
- ### **5. Missing Dependencies (0 scripts)** - *EXCLUDED*
52
- - ~~`update_aws_actions.py`~~ - **EXCLUDED** ✅
53
- - ~~`update_iam_roles_cross_accounts.py`~~ - **EXCLUDED** ✅
54
-
55
- ---
56
-
57
- ## 📋 **Detailed Analysis & Fix Instructions**
58
-
59
- ## **1. AWS Credential Issues**
60
-
61
- ### `list_iam_policies.py` ❌
62
-
63
- **Error**: `NoCredentialsError: Unable to locate credentials`
64
-
65
- **Root Cause**: The `get_all_credentials` function in `Inventory_Modules.py` is not properly handling SSO profile credentials for IAM operations.
66
-
67
- **TODO for Senior Developer**:
68
- ```python
69
- # FIXME: In Inventory_Modules.py line ~4950
70
- # Current credential handling doesn't work with SSO profiles for IAM operations
71
-
72
- def get_all_credentials(pProfiles, pTiming=False, pSkipProfiles=None, pSkipAccounts=None, pRootOnly=False, pAccounts=None, pRegionList=None, pAccessRoles=None):
73
- # ISSUE: SSO credentials are not properly passed to IAM operations
74
- # FIX NEEDED: Add explicit SSO credential handling for IAM-specific operations
75
-
76
- # Add this credential validation for IAM operations:
77
- if 'Profile' in credential_dict and credential_dict['Profile']:
78
- # For SSO profiles, create session with explicit credential retrieval
79
- try:
80
- session = boto3.Session(profile_name=credential_dict['Profile'])
81
- # Test IAM access specifically
82
- iam_client = session.client('iam', region_name='us-east-1')
83
- iam_client.get_user() # Test call
84
- credential_dict['Success'] = True
85
- except Exception as e:
86
- logging.warning(f"IAM access failed for profile {credential_dict['Profile']}: {e}")
87
- credential_dict['Success'] = False
88
- ```
89
-
90
- **Immediate Fix Priority**: HIGH (affects IAM governance capabilities)
91
-
92
- **Test Command**:
93
- ```bash
94
- python list_iam_policies.py --profile ams-admin-ReadOnlyAccess-909135376185 --verbose
95
- ```
96
-
97
- ---
98
-
99
- ### `list_ssm_parameters.py` ❌
100
-
101
- **Error**: `NoCredentialsError: Unable to locate credentials`
102
-
103
- **Root Cause**: Same credential handling issue as IAM policies script.
104
-
105
- **TODO for Senior Developer**:
106
- ```python
107
- # FIXME: In list_ssm_parameters.py line ~277
108
- # The get_all_credentials call needs SSO-specific handling
109
-
110
- # Current code:
111
- CredentialList = get_all_credentials(
112
- pProfiles, pTiming, pSkipProfiles, pSkipAccounts, pRootOnly, pAccounts, pRegionList
113
- )
114
-
115
- # FIX NEEDED: Add SSO credential validation before SSM operations
116
- # Add this before line 277:
117
- def validate_ssm_credentials(profile_name):
118
- """Validate SSM access with SSO credentials"""
119
- try:
120
- session = boto3.Session(profile_name=profile_name)
121
- ssm_client = session.client('ssm', region_name='us-east-1')
122
- # Test SSM access
123
- ssm_client.describe_parameters(MaxResults=1)
124
- return True
125
- except Exception as e:
126
- logging.error(f"SSM access validation failed: {e}")
127
- return False
128
-
129
- # Then modify the credential retrieval to use validated credentials
130
- ```
131
-
132
- **Immediate Fix Priority**: HIGH (affects parameter management capabilities)
133
-
134
- **Test Command**:
135
- ```bash
136
- python list_ssm_parameters.py --profile ams-admin-ReadOnlyAccess-909135376185 --verbose
137
- ```
138
-
139
- ---
140
-
141
- ## **2. Timeout Issues (Script Performance)**
142
-
143
- ### `check_controltower_readiness.py` ❌
144
-
145
- **Error**: `TEST TIMEOUT: Execution exceeded 300 seconds`
146
-
147
- **Root Cause**: Script is attempting to check 61 accounts across multiple regions with role assumption attempts, causing timeout.
148
-
149
- **TODO for Senior Developer**:
150
- ```python
151
- # FIXME: In check_controltower_readiness.py
152
- # Performance optimization needed for multi-account operations
153
-
154
- # ISSUES:
155
- # 1. Sequential processing of 61 accounts
156
- # 2. Multiple role assumption attempts per account
157
- # 3. No timeout handling for individual account checks
158
-
159
- # FIX NEEDED: Implement concurrent processing with timeout controls
160
- import concurrent.futures
161
- from functools import partial
162
-
163
- def check_account_readiness_with_timeout(account_info, timeout=30):
164
- """Check single account with timeout"""
165
- try:
166
- # Existing account check logic with timeout
167
- signal.alarm(timeout) # Set alarm for timeout
168
- result = check_single_account(account_info)
169
- signal.alarm(0) # Clear alarm
170
- return result
171
- except TimeoutError:
172
- return {"account": account_info["AccountId"], "status": "timeout", "ready": False}
173
-
174
- # Replace sequential processing with:
175
- def check_accounts_concurrent(account_list, max_workers=5):
176
- """Process accounts concurrently with timeout"""
177
- with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
178
- check_func = partial(check_account_readiness_with_timeout, timeout=30)
179
- future_to_account = {executor.submit(check_func, account): account for account in account_list}
180
-
181
- results = []
182
- for future in concurrent.futures.as_completed(future_to_account, timeout=240):
183
- try:
184
- result = future.result()
185
- results.append(result)
186
- except Exception as e:
187
- account = future_to_account[future]
188
- results.append({"account": account["AccountId"], "status": "error", "error": str(e)})
189
- return results
190
- ```
191
-
192
- **Performance Optimization Needed**:
193
- - Implement concurrent account processing
194
- - Add individual account timeouts
195
- - Optimize role assumption attempts
196
- - Add progress indicators
197
-
198
- **Immediate Fix Priority**: MEDIUM (affects Control Tower migrations)
199
-
200
- **Test Command**:
201
- ```bash
202
- timeout 60 python check_controltower_readiness.py --profile ams-admin-ReadOnlyAccess-909135376185
203
- ```
204
-
205
- ---
206
-
207
- ### `find_ec2_security_groups.py` ❌
208
-
209
- **Error 1**: `ValueError: too many values to unpack (expected 4)`
210
- **Error 2**: `TEST TIMEOUT: Execution exceeded 300 seconds`
211
-
212
- **Root Cause**:
213
- 1. Queue unpacking logic error in threading code
214
- 2. Performance issues with large-scale security group scanning
215
-
216
- **TODO for Senior Developer**:
217
- ```python
218
- # FIXME: In find_ec2_security_groups.py line ~286
219
- # Queue unpacking error - incorrect tuple structure
220
-
221
- # Current problematic code:
222
- c_account_credentials, c_fragments, c_exact, c_default = self.queue.get()
223
-
224
- # ISSUE: Queue is putting more/fewer values than expected
225
- # FIX NEEDED: Debug queue structure and fix unpacking
226
-
227
- # Add debugging to identify queue structure:
228
- def debug_queue_structure(self):
229
- queue_item = self.queue.get()
230
- print(f"Queue item type: {type(queue_item)}")
231
- print(f"Queue item length: {len(queue_item) if hasattr(queue_item, '__len__') else 'N/A'}")
232
- print(f"Queue item content: {queue_item}")
233
-
234
- # Fix unpacking based on actual structure:
235
- if len(queue_item) == 3:
236
- c_account_credentials, c_fragments, c_exact = queue_item
237
- c_default = False # Set default value
238
- elif len(queue_item) == 4:
239
- c_account_credentials, c_fragments, c_exact, c_default = queue_item
240
- else:
241
- # Handle unexpected queue structure
242
- logging.error(f"Unexpected queue item structure: {queue_item}")
243
- return
244
-
245
- # PERFORMANCE FIX: Add timeout and optimize security group scanning
246
- def scan_security_groups_with_timeout(account_credentials, timeout=60):
247
- """Scan security groups with timeout control"""
248
- try:
249
- signal.alarm(timeout)
250
- result = scan_security_groups(account_credentials)
251
- signal.alarm(0)
252
- return result
253
- except TimeoutError:
254
- logging.warning(f"Security group scan timed out for account")
255
- return []
256
- ```
257
-
258
- **Immediate Fix Priority**: HIGH (affects security compliance)
259
-
260
- **Debug Command**:
261
- ```bash
262
- python -c "
263
- import sys
264
- sys.path.append('src/runbooks/inventory')
265
- from find_ec2_security_groups import *
266
- # Add debug prints to identify queue structure
267
- "
268
- ```
269
-
270
- ---
271
-
272
- ### `list_cfn_stacks.py` ❌
273
-
274
- **Error**: `TEST TIMEOUT: Execution exceeded 300 seconds`
275
-
276
- **Root Cause**: Large-scale CloudFormation stack enumeration across 61 accounts and multiple regions.
277
-
278
- **TODO for Senior Developer**:
279
- ```python
280
- # FIXME: In list_cfn_stacks.py
281
- # Performance optimization for large-scale stack enumeration
282
-
283
- # ISSUES:
284
- # 1. Sequential processing of accounts and regions
285
- # 2. No pagination optimization
286
- # 3. No timeout controls for individual operations
287
-
288
- # FIX NEEDED: Implement efficient pagination and concurrent processing
289
- def list_stacks_optimized(account_credentials, regions, max_workers=3):
290
- """Optimized stack listing with concurrent processing"""
291
-
292
- def list_stacks_for_region(region):
293
- try:
294
- # Implement pagination with NextToken handling
295
- stacks = []
296
- paginator = cfn_client.get_paginator('list_stacks')
297
- for page in paginator.paginate(
298
- StackStatusFilter=[
299
- 'CREATE_COMPLETE', 'UPDATE_COMPLETE', 'DELETE_FAILED',
300
- 'CREATE_FAILED', 'UPDATE_FAILED', 'ROLLBACK_COMPLETE'
301
- ]
302
- ):
303
- stacks.extend(page['StackSummaries'])
304
- # Add timeout check
305
- if len(stacks) > 1000: # Limit results
306
- break
307
- return region, stacks
308
- except Exception as e:
309
- return region, f"Error: {e}"
310
-
311
- # Process regions concurrently
312
- with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
313
- future_to_region = {executor.submit(list_stacks_for_region, region): region for region in regions}
314
-
315
- results = {}
316
- for future in concurrent.futures.as_completed(future_to_region, timeout=60):
317
- region, stacks = future.result()
318
- results[region] = stacks
319
-
320
- return results
321
-
322
- # Add progress tracking:
323
- def track_progress(current, total, account_id):
324
- percent = (current / total) * 100
325
- print(f"\rProgress: {current}/{total} ({percent:.1f}%) - Account: {account_id}", end='', flush=True)
326
- ```
327
-
328
- **Performance Optimization Needed**:
329
- - Implement concurrent region processing
330
- - Add pagination limits
331
- - Optimize stack status filtering
332
- - Add progress tracking
333
-
334
- **Immediate Fix Priority**: HIGH (core CloudFormation functionality)
335
-
336
- **Test Command**:
337
- ```bash
338
- timeout 120 python list_cfn_stacks.py --profile ams-admin-ReadOnlyAccess-909135376185 --regions us-east-1
339
- ```
340
-
341
- ---
342
-
343
- ## **3. Missing Required Parameters**
344
-
345
- ### `lockdown_cfn_stackset_role.py` ❌
346
-
347
- **Error**: `You need to set the region (-r|--region) to the default region where the SSM parameters are stored.`
348
-
349
- **Root Cause**: Script requires mandatory region parameter for SSM parameter operations.
350
-
351
- **TODO for Senior Developer**:
352
- ```python
353
- # FIXME: In lockdown_cfn_stackset_role.py
354
- # Add default region handling and parameter validation
355
-
356
- # CURRENT ISSUE: Script requires --region parameter but testing framework doesn't provide it
357
-
358
- # FIX 1: Add default region handling
359
- def get_default_region():
360
- """Get default region from profile or environment"""
361
- try:
362
- session = boto3.Session()
363
- return session.region_name or 'us-east-1'
364
- except:
365
- return 'us-east-1'
366
-
367
- # FIX 2: Modify argument parser to accept default
368
- parser.add_argument(
369
- '-r', '--region',
370
- dest='pRegion',
371
- default=get_default_region(),
372
- help='Region where SSM parameters are stored (default: profile region or us-east-1)'
373
- )
374
-
375
- # FIX 3: Update test framework to provide region for this script
376
- # In inventory.sh, add to special parameters:
377
- case "$script_name" in
378
- "lockdown_cfn_stackset_role.py")
379
- echo "--region us-east-1"
380
- ;;
381
- ```
382
-
383
- **Required Parameters**:
384
- - `--region`: SSM parameter storage region
385
- - `--profile`: AWS authentication profile
386
-
387
- **Immediate Fix Priority**: MEDIUM (affects StackSet security)
388
-
389
- **Test Command**:
390
- ```bash
391
- python lockdown_cfn_stackset_role.py --profile ams-admin-ReadOnlyAccess-909135376185 --region us-east-1
392
- ```
393
-
394
- ---
395
-
396
- ### `run_on_multi_accounts.py` ❌
397
-
398
- **Error**: Multiple parameter requirements not met
399
-
400
- **Root Cause**: Script is a framework for running commands across accounts and requires specific command parameters.
401
-
402
- **TODO for Senior Developer**:
403
- ```python
404
- # FIXME: In run_on_multi_accounts.py
405
- # This is a framework script requiring command specification
406
-
407
- # ISSUE: Script needs a command to execute across accounts
408
- # This is not a standalone inventory script but a utility framework
409
-
410
- # FIX OPTIONS:
411
- # 1. Exclude from testing (recommended) - add to exclusion list
412
- # 2. Create a test mode with default command
413
- # 3. Add example command for testing
414
-
415
- # RECOMMENDED FIX: Add to exclusion list in inventory.sh
416
- scripts_to_not_test="... run_on_multi_accounts.py ..."
417
-
418
- # ALTERNATIVE: Add test mode
419
- if args.test_mode:
420
- # Run a simple test command
421
- test_command = ["aws", "sts", "get-caller-identity"]
422
- run_command_on_accounts(test_command, account_list)
423
- ```
424
-
425
- **Script Purpose**: Multi-account command execution framework, not a standalone inventory tool.
426
-
427
- **Immediate Fix Priority**: LOW (utility framework, not core inventory)
428
-
429
- **Recommended Action**: Exclude from automated testing
430
-
431
- ---
432
-
433
- ## **4. Missing Dependencies**
434
-
435
- ### `update_aws_actions.py` ❌
436
-
437
- **Error**: Missing required parameters for AWS action execution
438
-
439
- **Root Cause**: Script requires specific action commands and parameters.
440
-
441
- **TODO for Senior Developer**:
442
- ```python
443
- # FIXME: In update_aws_actions.py
444
- # General-purpose AWS action automation requires specific action definition
445
-
446
- # ISSUE: Script is a framework for AWS actions, not a specific inventory tool
447
- # Similar to run_on_multi_accounts.py
448
-
449
- # RECOMMENDED FIX: Either exclude from testing or add test mode
450
- def test_mode_execution():
451
- """Test mode with safe, read-only operations"""
452
- if args.test_mode:
453
- # Execute safe test actions
454
- safe_actions = [
455
- {"service": "sts", "action": "get-caller-identity"},
456
- {"service": "ec2", "action": "describe-regions", "params": {"AllRegions": False}}
457
- ]
458
- return execute_safe_actions(safe_actions)
459
-
460
- # Add test mode parameter:
461
- parser.add_argument('--test-mode', action='store_true', help='Run in test mode with safe operations')
462
- ```
463
-
464
- **Script Purpose**: General AWS action automation framework.
465
-
466
- **Immediate Fix Priority**: LOW (utility framework, not core inventory)
467
-
468
- **Recommended Action**: Exclude from automated testing or add test mode
469
-
470
- ---
471
-
472
- ### `update_iam_roles_cross_accounts.py` ❌
473
-
474
- **Error**: Missing required parameters for IAM role management
475
-
476
- **Root Cause**: Script requires specific IAM role definitions and cross-account parameters.
477
-
478
- **TODO for Senior Developer**:
479
- ```python
480
- # FIXME: In update_iam_roles_cross_accounts.py
481
- # Cross-account IAM role management requires specific role definitions
482
-
483
- # ISSUE: Script requires role ARNs, trust policies, and account specifications
484
- # This is an operational script, not an inventory script
485
-
486
- # RECOMMENDED FIX: Add to exclusion list or create test mode
487
- def create_test_role_config():
488
- """Create test configuration for validation"""
489
- if args.test_mode:
490
- return {
491
- "test_role": {
492
- "role_name": "TestInventoryRole",
493
- "trust_policy": create_basic_trust_policy(),
494
- "target_accounts": ["current_account_only"]
495
- }
496
- }
497
-
498
- # Add validation mode:
499
- parser.add_argument('--validate-only', action='store_true', help='Validate configuration without making changes')
500
- ```
501
-
502
- **Script Purpose**: Operational IAM role management for Control Tower migrations.
503
-
504
- **Immediate Fix Priority**: LOW (operational tool, not inventory)
505
-
506
- **Recommended Action**: Exclude from automated testing
507
-
508
- ---
509
-
510
- ## 🔧 **Quick Fix Implementation Guide**
511
-
512
- ### **Priority 1: Credential Issues (Immediate)**
513
-
514
- 1. **Fix SSO credential handling in `Inventory_Modules.py`**:
515
- ```bash
516
- # Edit Inventory_Modules.py
517
- vim src/runbooks/inventory/Inventory_Modules.py +4950
518
-
519
- # Add SSO-specific credential validation
520
- # Test with IAM and SSM scripts
521
- ```
522
-
523
- 2. **Test fixes**:
524
- ```bash
525
- python list_iam_policies.py --profile ams-admin-ReadOnlyAccess-909135376185
526
- python list_ssm_parameters.py --profile ams-admin-ReadOnlyAccess-909135376185
527
- ```
528
-
529
- ### **Priority 2: Performance Issues (Short-term)**
530
-
531
- 1. **Optimize `find_ec2_security_groups.py`**:
532
- ```bash
533
- # Fix queue unpacking error
534
- vim src/runbooks/inventory/find_ec2_security_groups.py +286
535
-
536
- # Add debugging and fix tuple unpacking
537
- # Add timeout controls
538
- ```
539
-
540
- 2. **Optimize timeout-prone scripts**:
541
- ```bash
542
- # Add concurrent processing to Control Tower readiness
543
- # Implement pagination optimization for CloudFormation stacks
544
- ```
545
-
546
- ### **Priority 3: Framework Scripts (Long-term)**
547
-
548
- 1. **Exclude utility frameworks from testing**:
549
- ```bash
550
- # Edit inventory.sh
551
- vim src/runbooks/inventory/inventory.sh
552
-
553
- # Add to exclusion list:
554
- scripts_to_not_test="... run_on_multi_accounts.py update_aws_actions.py update_iam_roles_cross_accounts.py ..."
555
- ```
556
-
557
- 2. **Add required parameters for operational scripts**:
558
- ```bash
559
- # Update special parameters function
560
- # Add region parameter for lockdown script
561
- ```
562
-
563
- ---
564
-
565
- ## 📊 **Expected Results After Fixes**
566
-
567
- ### **Immediate Wins (2-3 scripts)**
568
- - Fix credential issues: `list_iam_policies.py`, `list_ssm_parameters.py`
569
- - Result: **39/46 scripts PASSING (84.8%)**
570
-
571
- ### **Performance Optimizations (1-2 scripts)**
572
- - Fix queue error: `find_ec2_security_groups.py`
573
- - Optimize timeouts: 1 additional script
574
- - Result: **40-41/46 scripts PASSING (87-89%)**
575
-
576
- ### **Framework Exclusions (2-3 scripts)**
577
- - Exclude utility frameworks from testing
578
- - Focus testing on core inventory functionality
579
- - Result: **37-41/43 scripts PASSING (86-95%)**
580
-
581
- ---
582
-
583
- ## 🎯 **Success Metrics**
584
-
585
- ### **Current Status**: 37/46 scripts PASSING (80.4%)
586
- ### **Target After Fixes**: 40+/46 scripts PASSING (87%+)
587
-
588
- ### **Key Performance Indicators**
589
- 1. **Credential Issues Resolved**: 2 scripts fixed
590
- 2. **Performance Optimized**: 1-2 scripts optimized
591
- 3. **Framework Clarity**: Utility scripts properly categorized
592
- 4. **Testing Efficiency**: Reduced false failures from framework scripts
593
-
594
- ---
595
-
596
- ## 📞 **Support & Next Steps**
597
-
598
- ### **For Senior Developers**
599
- 1. **Review this troubleshooting guide**
600
- 2. **Prioritize credential fixes first** (highest impact)
601
- 3. **Implement performance optimizations** (medium impact)
602
- 4. **Consider framework script exclusions** (testing clarity)
603
-
604
- ### **Testing Validation**
605
- ```bash
606
- # After implementing fixes, run comprehensive test:
607
- ./src/runbooks/inventory/inventory.sh all --profile ams-admin-ReadOnlyAccess-909135376185 --verbose
608
-
609
- # Target: 87%+ success rate
610
- ```
611
-
612
- ### **Documentation Updates**
613
- - Update README.md with new success rates
614
- - Document any framework script exclusions
615
- - Add performance optimization notes
616
-
617
- ---
618
-
619
- **Current Failed Scripts: 9/46 (19.6% failure rate) - Actionable fixes identified ⚡**