runbooks 0.2.3__py3-none-any.whl → 0.6.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.
Files changed (221) hide show
  1. conftest.py +26 -0
  2. jupyter-agent/.env.template +2 -0
  3. jupyter-agent/.gitattributes +35 -0
  4. jupyter-agent/README.md +16 -0
  5. jupyter-agent/app.py +256 -0
  6. jupyter-agent/cloudops-agent.png +0 -0
  7. jupyter-agent/ds-system-prompt.txt +154 -0
  8. jupyter-agent/jupyter-agent.png +0 -0
  9. jupyter-agent/llama3_template.jinja +123 -0
  10. jupyter-agent/requirements.txt +9 -0
  11. jupyter-agent/utils.py +409 -0
  12. runbooks/__init__.py +71 -3
  13. runbooks/__main__.py +13 -0
  14. runbooks/aws/ec2_describe_instances.py +1 -1
  15. runbooks/aws/ec2_run_instances.py +8 -2
  16. runbooks/aws/ec2_start_stop_instances.py +17 -4
  17. runbooks/aws/ec2_unused_volumes.py +5 -1
  18. runbooks/aws/s3_create_bucket.py +4 -2
  19. runbooks/aws/s3_list_objects.py +6 -1
  20. runbooks/aws/tagging_lambda_handler.py +13 -2
  21. runbooks/aws/tags.json +12 -0
  22. runbooks/base.py +353 -0
  23. runbooks/cfat/README.md +49 -0
  24. runbooks/cfat/__init__.py +74 -0
  25. runbooks/cfat/app.ts +644 -0
  26. runbooks/cfat/assessment/__init__.py +40 -0
  27. runbooks/cfat/assessment/asana-import.csv +39 -0
  28. runbooks/cfat/assessment/cfat-checks.csv +31 -0
  29. runbooks/cfat/assessment/cfat.txt +520 -0
  30. runbooks/cfat/assessment/collectors.py +200 -0
  31. runbooks/cfat/assessment/jira-import.csv +39 -0
  32. runbooks/cfat/assessment/runner.py +387 -0
  33. runbooks/cfat/assessment/validators.py +290 -0
  34. runbooks/cfat/cli.py +103 -0
  35. runbooks/cfat/docs/asana-import.csv +24 -0
  36. runbooks/cfat/docs/cfat-checks.csv +31 -0
  37. runbooks/cfat/docs/cfat.txt +335 -0
  38. runbooks/cfat/docs/checks-output.png +0 -0
  39. runbooks/cfat/docs/cloudshell-console-run.png +0 -0
  40. runbooks/cfat/docs/cloudshell-download.png +0 -0
  41. runbooks/cfat/docs/cloudshell-output.png +0 -0
  42. runbooks/cfat/docs/downloadfile.png +0 -0
  43. runbooks/cfat/docs/jira-import.csv +24 -0
  44. runbooks/cfat/docs/open-cloudshell.png +0 -0
  45. runbooks/cfat/docs/report-header.png +0 -0
  46. runbooks/cfat/models.py +1026 -0
  47. runbooks/cfat/package-lock.json +5116 -0
  48. runbooks/cfat/package.json +38 -0
  49. runbooks/cfat/report.py +496 -0
  50. runbooks/cfat/reporting/__init__.py +46 -0
  51. runbooks/cfat/reporting/exporters.py +337 -0
  52. runbooks/cfat/reporting/formatters.py +496 -0
  53. runbooks/cfat/reporting/templates.py +135 -0
  54. runbooks/cfat/run-assessment.sh +23 -0
  55. runbooks/cfat/runner.py +69 -0
  56. runbooks/cfat/src/actions/check-cloudtrail-existence.ts +43 -0
  57. runbooks/cfat/src/actions/check-config-existence.ts +37 -0
  58. runbooks/cfat/src/actions/check-control-tower.ts +37 -0
  59. runbooks/cfat/src/actions/check-ec2-existence.ts +46 -0
  60. runbooks/cfat/src/actions/check-iam-users.ts +50 -0
  61. runbooks/cfat/src/actions/check-legacy-cur.ts +30 -0
  62. runbooks/cfat/src/actions/check-org-cloudformation.ts +30 -0
  63. runbooks/cfat/src/actions/check-vpc-existence.ts +43 -0
  64. runbooks/cfat/src/actions/create-asanaimport.ts +14 -0
  65. runbooks/cfat/src/actions/create-backlog.ts +372 -0
  66. runbooks/cfat/src/actions/create-jiraimport.ts +15 -0
  67. runbooks/cfat/src/actions/create-report.ts +616 -0
  68. runbooks/cfat/src/actions/define-account-type.ts +51 -0
  69. runbooks/cfat/src/actions/get-enabled-org-policy-types.ts +40 -0
  70. runbooks/cfat/src/actions/get-enabled-org-services.ts +26 -0
  71. runbooks/cfat/src/actions/get-idc-info.ts +34 -0
  72. runbooks/cfat/src/actions/get-org-da-accounts.ts +34 -0
  73. runbooks/cfat/src/actions/get-org-details.ts +35 -0
  74. runbooks/cfat/src/actions/get-org-member-accounts.ts +44 -0
  75. runbooks/cfat/src/actions/get-org-ous.ts +35 -0
  76. runbooks/cfat/src/actions/get-regions.ts +22 -0
  77. runbooks/cfat/src/actions/zip-assessment.ts +27 -0
  78. runbooks/cfat/src/types/index.d.ts +147 -0
  79. runbooks/cfat/tests/__init__.py +141 -0
  80. runbooks/cfat/tests/test_cli.py +340 -0
  81. runbooks/cfat/tests/test_integration.py +290 -0
  82. runbooks/cfat/tests/test_models.py +505 -0
  83. runbooks/cfat/tests/test_reporting.py +354 -0
  84. runbooks/cfat/tsconfig.json +16 -0
  85. runbooks/cfat/webpack.config.cjs +27 -0
  86. runbooks/config.py +260 -0
  87. runbooks/finops/__init__.py +88 -0
  88. runbooks/finops/aws_client.py +245 -0
  89. runbooks/finops/cli.py +151 -0
  90. runbooks/finops/cost_processor.py +410 -0
  91. runbooks/finops/dashboard_runner.py +448 -0
  92. runbooks/finops/helpers.py +355 -0
  93. runbooks/finops/main.py +14 -0
  94. runbooks/finops/profile_processor.py +174 -0
  95. runbooks/finops/types.py +66 -0
  96. runbooks/finops/visualisations.py +80 -0
  97. runbooks/inventory/.gitignore +354 -0
  98. runbooks/inventory/ArgumentsClass.py +261 -0
  99. runbooks/inventory/Inventory_Modules.py +6130 -0
  100. runbooks/inventory/LandingZone/delete_lz.py +1075 -0
  101. runbooks/inventory/README.md +1320 -0
  102. runbooks/inventory/__init__.py +62 -0
  103. runbooks/inventory/account_class.py +532 -0
  104. runbooks/inventory/all_my_instances_wrapper.py +123 -0
  105. runbooks/inventory/aws_decorators.py +201 -0
  106. runbooks/inventory/cfn_move_stack_instances.py +1526 -0
  107. runbooks/inventory/check_cloudtrail_compliance.py +614 -0
  108. runbooks/inventory/check_controltower_readiness.py +1107 -0
  109. runbooks/inventory/check_landingzone_readiness.py +711 -0
  110. runbooks/inventory/cloudtrail.md +727 -0
  111. runbooks/inventory/collectors/__init__.py +20 -0
  112. runbooks/inventory/collectors/aws_compute.py +518 -0
  113. runbooks/inventory/collectors/aws_networking.py +275 -0
  114. runbooks/inventory/collectors/base.py +222 -0
  115. runbooks/inventory/core/__init__.py +19 -0
  116. runbooks/inventory/core/collector.py +303 -0
  117. runbooks/inventory/core/formatter.py +296 -0
  118. runbooks/inventory/delete_s3_buckets_objects.py +169 -0
  119. runbooks/inventory/discovery.md +81 -0
  120. runbooks/inventory/draw_org_structure.py +748 -0
  121. runbooks/inventory/ec2_vpc_utils.py +341 -0
  122. runbooks/inventory/find_cfn_drift_detection.py +272 -0
  123. runbooks/inventory/find_cfn_orphaned_stacks.py +719 -0
  124. runbooks/inventory/find_cfn_stackset_drift.py +733 -0
  125. runbooks/inventory/find_ec2_security_groups.py +669 -0
  126. runbooks/inventory/find_landingzone_versions.py +201 -0
  127. runbooks/inventory/find_vpc_flow_logs.py +1221 -0
  128. runbooks/inventory/inventory.sh +659 -0
  129. runbooks/inventory/list_cfn_stacks.py +558 -0
  130. runbooks/inventory/list_cfn_stackset_operation_results.py +252 -0
  131. runbooks/inventory/list_cfn_stackset_operations.py +734 -0
  132. runbooks/inventory/list_cfn_stacksets.py +453 -0
  133. runbooks/inventory/list_config_recorders_delivery_channels.py +681 -0
  134. runbooks/inventory/list_ds_directories.py +354 -0
  135. runbooks/inventory/list_ec2_availability_zones.py +286 -0
  136. runbooks/inventory/list_ec2_ebs_volumes.py +244 -0
  137. runbooks/inventory/list_ec2_instances.py +425 -0
  138. runbooks/inventory/list_ecs_clusters_and_tasks.py +562 -0
  139. runbooks/inventory/list_elbs_load_balancers.py +411 -0
  140. runbooks/inventory/list_enis_network_interfaces.py +526 -0
  141. runbooks/inventory/list_guardduty_detectors.py +568 -0
  142. runbooks/inventory/list_iam_policies.py +404 -0
  143. runbooks/inventory/list_iam_roles.py +518 -0
  144. runbooks/inventory/list_iam_saml_providers.py +359 -0
  145. runbooks/inventory/list_lambda_functions.py +882 -0
  146. runbooks/inventory/list_org_accounts.py +446 -0
  147. runbooks/inventory/list_org_accounts_users.py +354 -0
  148. runbooks/inventory/list_rds_db_instances.py +406 -0
  149. runbooks/inventory/list_route53_hosted_zones.py +318 -0
  150. runbooks/inventory/list_servicecatalog_provisioned_products.py +575 -0
  151. runbooks/inventory/list_sns_topics.py +360 -0
  152. runbooks/inventory/list_ssm_parameters.py +402 -0
  153. runbooks/inventory/list_vpc_subnets.py +433 -0
  154. runbooks/inventory/list_vpcs.py +422 -0
  155. runbooks/inventory/lockdown_cfn_stackset_role.py +224 -0
  156. runbooks/inventory/models/__init__.py +24 -0
  157. runbooks/inventory/models/account.py +192 -0
  158. runbooks/inventory/models/inventory.py +309 -0
  159. runbooks/inventory/models/resource.py +247 -0
  160. runbooks/inventory/recover_cfn_stack_ids.py +205 -0
  161. runbooks/inventory/requirements.txt +12 -0
  162. runbooks/inventory/run_on_multi_accounts.py +211 -0
  163. runbooks/inventory/tests/common_test_data.py +3661 -0
  164. runbooks/inventory/tests/common_test_functions.py +204 -0
  165. runbooks/inventory/tests/script_test_data.py +0 -0
  166. runbooks/inventory/tests/setup.py +24 -0
  167. runbooks/inventory/tests/src.py +18 -0
  168. runbooks/inventory/tests/test_cfn_describe_stacks.py +208 -0
  169. runbooks/inventory/tests/test_ec2_describe_instances.py +162 -0
  170. runbooks/inventory/tests/test_inventory_modules.py +55 -0
  171. runbooks/inventory/tests/test_lambda_list_functions.py +86 -0
  172. runbooks/inventory/tests/test_moto_integration_example.py +273 -0
  173. runbooks/inventory/tests/test_org_list_accounts.py +49 -0
  174. runbooks/inventory/update_aws_actions.py +173 -0
  175. runbooks/inventory/update_cfn_stacksets.py +1215 -0
  176. runbooks/inventory/update_cloudwatch_logs_retention_policy.py +294 -0
  177. runbooks/inventory/update_iam_roles_cross_accounts.py +478 -0
  178. runbooks/inventory/update_s3_public_access_block.py +539 -0
  179. runbooks/inventory/utils/__init__.py +23 -0
  180. runbooks/inventory/utils/aws_helpers.py +510 -0
  181. runbooks/inventory/utils/threading_utils.py +493 -0
  182. runbooks/inventory/utils/validation.py +682 -0
  183. runbooks/inventory/verify_ec2_security_groups.py +1430 -0
  184. runbooks/main.py +785 -0
  185. runbooks/organizations/__init__.py +12 -0
  186. runbooks/organizations/manager.py +374 -0
  187. runbooks/security_baseline/README.md +324 -0
  188. runbooks/security_baseline/checklist/alternate_contacts.py +8 -1
  189. runbooks/security_baseline/checklist/bucket_public_access.py +4 -1
  190. runbooks/security_baseline/checklist/cloudwatch_alarm_configuration.py +9 -2
  191. runbooks/security_baseline/checklist/guardduty_enabled.py +9 -2
  192. runbooks/security_baseline/checklist/multi_region_instance_usage.py +5 -1
  193. runbooks/security_baseline/checklist/root_access_key.py +6 -1
  194. runbooks/security_baseline/config-origin.json +1 -1
  195. runbooks/security_baseline/config.json +1 -1
  196. runbooks/security_baseline/permission.json +1 -1
  197. runbooks/security_baseline/report_generator.py +10 -2
  198. runbooks/security_baseline/report_template_en.html +8 -8
  199. runbooks/security_baseline/report_template_jp.html +8 -8
  200. runbooks/security_baseline/report_template_kr.html +13 -13
  201. runbooks/security_baseline/report_template_vn.html +8 -8
  202. runbooks/security_baseline/requirements.txt +7 -0
  203. runbooks/security_baseline/run_script.py +8 -2
  204. runbooks/security_baseline/security_baseline_tester.py +10 -2
  205. runbooks/security_baseline/utils/common.py +5 -1
  206. runbooks/utils/__init__.py +204 -0
  207. runbooks-0.6.1.dist-info/METADATA +373 -0
  208. runbooks-0.6.1.dist-info/RECORD +237 -0
  209. {runbooks-0.2.3.dist-info → runbooks-0.6.1.dist-info}/WHEEL +1 -1
  210. runbooks-0.6.1.dist-info/entry_points.txt +7 -0
  211. runbooks-0.6.1.dist-info/licenses/LICENSE +201 -0
  212. runbooks-0.6.1.dist-info/top_level.txt +3 -0
  213. runbooks/python101/calculator.py +0 -34
  214. runbooks/python101/config.py +0 -1
  215. runbooks/python101/exceptions.py +0 -16
  216. runbooks/python101/file_manager.py +0 -218
  217. runbooks/python101/toolkit.py +0 -153
  218. runbooks-0.2.3.dist-info/METADATA +0 -435
  219. runbooks-0.2.3.dist-info/RECORD +0 -61
  220. runbooks-0.2.3.dist-info/entry_points.txt +0 -3
  221. runbooks-0.2.3.dist-info/top_level.txt +0 -1
@@ -0,0 +1,681 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ AWS Config Service Configuration Recorders and Delivery Channels Discovery and Management Script
5
+
6
+ This enterprise-grade inventory and management script provides comprehensive discovery, analysis,
7
+ and optional cleanup of AWS Config service configuration recorders and delivery channels across
8
+ multi-account AWS Organizations environments. Designed for infrastructure teams, DevOps engineers,
9
+ and cloud architects managing AWS Config service deployment and compliance across large-scale
10
+ enterprise environments.
11
+
12
+ Key Features:
13
+ - Configuration recorder discovery and inventory across organizational accounts
14
+ - Delivery channel enumeration with S3 bucket and SNS topic configuration analysis
15
+ - Fragment-based filtering for targeted Config service component discovery
16
+ - Optional deletion capabilities with safety controls and confirmation prompts
17
+ - Multi-threaded discovery for efficient large-scale Config service inventory
18
+ - Comprehensive error handling for authorization, throttling, and connectivity issues
19
+ - Progress tracking with real-time operational feedback and performance metrics
20
+ - Flexible output formatting with CSV export for reporting and integration
21
+
22
+ Configuration Discovery Features:
23
+ - Configuration recorder enumeration with recording scope and status analysis
24
+ - Delivery channel discovery with destination bucket and notification configuration
25
+ - Cross-account Config service visibility for organizational compliance oversight
26
+ - Fragment-based search for targeted Config component identification and filtering
27
+ - Regional Config service availability validation and access control
28
+
29
+ Management and Cleanup:
30
+ - Safe deletion workflows with explicit confirmation prompts and force flags
31
+ - Batch deletion capabilities for efficient Config service cleanup operations
32
+ - Pre-deletion validation and dependency checking for operational safety
33
+ - Comprehensive audit logging for compliance and operational tracking
34
+ - Rollback-safe operations with detailed status tracking and error handling
35
+
36
+ Authentication and Access:
37
+ - Multi-profile authentication for comprehensive organizational Config discovery
38
+ - Cross-account role-based access patterns supporting AWS Organizations structure
39
+ - Multi-region support with Config service availability validation
40
+ - Root account filtering and inclusion controls for targeted discovery
41
+ - Comprehensive error handling for authentication and authorization failures
42
+
43
+ Enterprise Use Cases:
44
+ - Config service governance and compliance tracking for organizational oversight
45
+ - Centralized Config service inventory for infrastructure management and planning
46
+ - Config service cleanup and decommissioning for cost optimization
47
+ - Compliance framework validation ensuring consistent Config deployment
48
+ - Operational maintenance identification for Config service health monitoring
49
+
50
+ Performance and Scalability:
51
+ - Multi-threaded architecture for efficient Config service discovery operations
52
+ - Queue-based worker pattern for concurrent Config component enumeration
53
+ - Optimized AWS API usage with progress tracking and performance timing
54
+ - Configurable concurrency limits for API rate limiting and throttling management
55
+ - Efficient credential management for cross-account Config service access
56
+
57
+ Security Considerations:
58
+ - Read-only discovery operations ensuring no accidental Config modifications
59
+ - Explicit deletion controls with confirmation prompts and force flag requirements
60
+ - Comprehensive audit logging for compliance and operational tracking
61
+ - Secure credential handling with profile-based authentication patterns
62
+ - Access validation and error handling for enterprise security requirements
63
+
64
+ Dependencies:
65
+ - boto3: AWS SDK for Config service operations and cross-account access
66
+ - colorama: Enhanced terminal output with color coding for operational visibility
67
+ - tqdm: Progress bars for long-running discovery and management operations
68
+ - Inventory_Modules: Custom AWS inventory and discovery utilities
69
+ - ArgumentsClass: Standardized CLI argument parsing and validation
70
+
71
+ Example Usage:
72
+ # Basic Config service discovery
73
+ python list_config_recorders_delivery_channels.py --profiles production
74
+
75
+ # Fragment-based Config component search
76
+ python list_config_recorders_delivery_channels.py --fragment SecurityBaseline
77
+
78
+ # Config service cleanup with confirmation
79
+ python list_config_recorders_delivery_channels.py +delete --force
80
+
81
+ Output:
82
+ Displays discovered Config recorders and delivery channels with account, region,
83
+ type, and configuration details for infrastructure management and compliance tracking.
84
+ """
85
+
86
+ import logging
87
+ import sys
88
+ from os.path import split
89
+ from queue import Queue
90
+ from threading import Thread
91
+ from time import time
92
+
93
+ import Inventory_Modules
94
+ from ArgumentsClass import CommonArguments
95
+ from botocore.exceptions import ClientError
96
+ from colorama import Fore, init
97
+ from Inventory_Modules import del_config_recorder_or_delivery_channel2, display_results, get_all_credentials
98
+ from tqdm.auto import tqdm
99
+
100
+ init()
101
+ __version__ = "2024.05.31"
102
+
103
+
104
+ ##################
105
+ # Functions
106
+ ##################
107
+
108
+
109
+ # TODO: Enable the deletion of the config recorders / delivery channels from specific accounts (or all?) at the end.
110
+ def parse_args(f_arguments):
111
+ """
112
+ Parse and validate CLI arguments for Config service discovery and management operations.
113
+
114
+ Configures comprehensive argument parsing for AWS Config service configuration recorders
115
+ and delivery channels inventory across AWS Organizations with support for fragment-based
116
+ filtering, deletion operations, and cross-account discovery. Provides enterprise-grade
117
+ CLI interface for infrastructure teams managing Config service deployment and compliance.
118
+
119
+ Args:
120
+ f_arguments (object): Command-line arguments list for parsing and validation
121
+
122
+ Returns:
123
+ argparse.Namespace: Parsed arguments object containing:
124
+ - Profiles: List of AWS profiles for multi-account Config discovery
125
+ - Regions: Target AWS regions for Config service enumeration
126
+ - Accounts: Specific account IDs for targeted Config discovery
127
+ - Fragments: Config component name fragments for targeted search and filtering
128
+ - SkipAccounts: Account IDs to exclude from Config discovery operations
129
+ - SkipProfiles: Profile names to exclude from Config service inventory
130
+ - RootOnly: Boolean flag to limit discovery to root account only
131
+ - Filename: Optional output file path for CSV export and reporting
132
+ - AccessRole: Cross-account access role for Config service operations
133
+ - Time: Boolean flag to enable performance timing and metrics
134
+ - loglevel: Logging verbosity level for operational visibility and debugging
135
+ - flagDelete: Boolean flag to enable Config component deletion operations
136
+ - Force: Boolean flag to bypass confirmation prompts for deletion
137
+
138
+ CLI Arguments:
139
+ Multi-Account Authentication:
140
+ - --profiles: AWS profiles for comprehensive organizational Config discovery
141
+ - --skip-profiles: Profile exclusion for targeted Config inventory
142
+ - Multi-profile mode for extensive Config service visibility
143
+
144
+ Regional Configuration:
145
+ - --regions: Target AWS regions for Config service discovery
146
+ - Multi-region support for comprehensive Config deployment analysis
147
+
148
+ Account Filtering:
149
+ - --accounts: Specific account IDs for targeted Config discovery
150
+ - --skip-accounts: Account exclusion for focused Config inventory
151
+ - --root-only: Limit discovery to root account Config components
152
+
153
+ Config Component Filtering:
154
+ - --fragment: Config recorder/delivery channel name fragments for targeted search
155
+ - Fragment-based search for precise Config component identification
156
+ - Supports substring matching for flexible Config discovery
157
+
158
+ Management Operations:
159
+ - +delete: Enable Config component deletion with safety controls
160
+ - --force: Bypass confirmation prompts for automated deletion workflows
161
+ - Deletion safety features with explicit confirmation requirements
162
+
163
+ Operational Controls:
164
+ - --access-role: Cross-account access role for Config operations
165
+ - --timing: Enable performance timing for operational metrics
166
+ - --save-to-file: Export results to CSV for reporting and integration
167
+ - --verbose: Control logging verbosity for debugging and audit trails
168
+
169
+ Enterprise Features:
170
+ - Standardized CLI interface consistent with inventory tooling
171
+ - Fragment-based search for targeted Config component discovery
172
+ - Multi-account and multi-region support for organizational Config visibility
173
+ - Safe deletion workflows with confirmation and force controls
174
+ - Output formatting with CSV export for enterprise reporting
175
+
176
+ Validation and Error Handling:
177
+ - Argument validation with informative error messages
178
+ - Help text generation for operational documentation
179
+ - Version information for tooling compatibility tracking
180
+ - Default value configuration for operational convenience
181
+ """
182
+ script_path, script_name = split(sys.argv[0])
183
+ parser = CommonArguments()
184
+
185
+ # Configure standardized CLI arguments for enterprise Config service operations
186
+ parser.multiprofile() # Multi-profile authentication for organizational Config discovery
187
+ parser.multiregion() # Multi-region support for comprehensive Config deployment analysis
188
+ parser.extendedargs() # Extended argument support for advanced filtering capabilities
189
+ parser.deletion() # Standard deletion controls with safety and confirmation features
190
+ parser.rootOnly() # Root account only mode for targeted Config discovery
191
+ parser.roletouse() # Cross-account access role configuration for Config operations
192
+ parser.timing() # Performance timing metrics for operational analysis
193
+ parser.save_to_file() # CSV export functionality for enterprise reporting and integration
194
+ parser.fragment() # Fragment-based filtering for targeted Config component discovery
195
+ parser.verbosity() # Configurable logging verbosity for debugging and audit trails
196
+ parser.version(__version__) # Version information for tooling compatibility tracking
197
+
198
+ # Add script-specific arguments for Config service management operations
199
+ local = parser.my_parser.add_argument_group(script_name, "Parameters specific to this script")
200
+ local.add_argument(
201
+ "+delete",
202
+ "+forreal",
203
+ dest="flagDelete",
204
+ action="store_true", # Enable deletion mode when parameter is supplied
205
+ help="Enable deletion of discovered configuration recorders and delivery channels with safety controls",
206
+ )
207
+ return parser.my_parser.parse_args(f_arguments)
208
+
209
+
210
+ def check_accounts_for_delivery_channels_and_config_recorders(CredentialList, fFragments=None, fFixRun=False):
211
+ """
212
+ Discover and enumerate AWS Config service components across multiple accounts and regions.
213
+
214
+ Performs comprehensive Config service discovery using multi-threaded processing to efficiently
215
+ inventory configuration recorders and delivery channels across large-scale AWS Organizations
216
+ environments. Supports fragment-based filtering for targeted Config component discovery and
217
+ provides detailed metadata extraction for enterprise infrastructure governance and compliance.
218
+
219
+ Args:
220
+ CredentialList (list): List of credential dictionaries for cross-account Config discovery containing:
221
+ - AccountId: AWS account number for Config service access
222
+ - Region: Target AWS region for Config component enumeration
223
+ - Success: Boolean indicating credential validity and access status
224
+ - AccessError: Error details for failed credential attempts
225
+ fFragments (list): Config component name fragments for targeted search and filtering
226
+ Defaults to None for comprehensive Config discovery
227
+ fFixRun (bool): Deletion mode flag for Config component cleanup operations
228
+ Default False for read-only discovery mode
229
+
230
+ Returns:
231
+ list: Comprehensive list of Config component dictionaries containing:
232
+ - Type: Config component type (Config Recorder or Delivery Channel)
233
+ - AccountId: AWS account containing the Config component
234
+ - Region: AWS region where Config component is deployed
235
+ - name: Config component name identifier
236
+ - ParentProfile: AWS profile used for Config component access
237
+ - MgmtAccount: Management account for organizational Config oversight
238
+ - Deleted: Boolean flag indicating deletion status for cleanup operations
239
+
240
+ Config Discovery Features:
241
+ - Configuration recorder enumeration with recording scope and status analysis
242
+ - Delivery channel discovery with S3 bucket and SNS topic configuration
243
+ - Fragment-based filtering for targeted Config component identification
244
+ - Cross-account Config service visibility for organizational compliance oversight
245
+ - Regional Config service availability validation and access control
246
+
247
+ Multi-threaded Architecture:
248
+ - Queue-based worker pattern for concurrent Config component discovery
249
+ - Configurable worker thread pool for performance optimization
250
+ - Progress tracking with real-time operational feedback
251
+ - Graceful error handling for authorization and throttling issues
252
+
253
+ Performance Optimization:
254
+ - Concurrent processing for efficient large-scale Config discovery
255
+ - Progress bars for operational visibility during long-running operations
256
+ - Worker thread scaling based on credential count for optimal performance
257
+ - Queue management for efficient work distribution and completion tracking
258
+
259
+ Enterprise Infrastructure Governance:
260
+ - Organizational Config service visibility across accounts and regions
261
+ - Config component metadata extraction for compliance and audit tracking
262
+ - Fragment-based search for targeted Config component management
263
+ - Comprehensive error handling for operational resilience and troubleshooting
264
+
265
+ Error Handling:
266
+ - Authorization failure detection with graceful degradation
267
+ - AWS API error management with comprehensive logging
268
+ - Credential validation and failure tracking
269
+ - Profile-specific error handling for multi-account Config discovery
270
+ """
271
+
272
+ class Find_Config_Recorders_and_Delivery_Channels(Thread):
273
+ """
274
+ Multi-threaded worker class for concurrent Config service component discovery and enumeration.
275
+
276
+ Implements thread-safe Config service discovery using queue-based work distribution for
277
+ efficient processing of configuration recorders and delivery channels across organizational
278
+ accounts and regions.
279
+ """
280
+
281
+ def __init__(self, queue):
282
+ Thread.__init__(self)
283
+ self.queue = queue
284
+
285
+ def run(self):
286
+ while True:
287
+ # Extract work item from queue with account credentials and processing context
288
+ c_account_credentials, c_fixrun, c_fragments, c_PlacesToLook, c_PlaceCount = self.queue.get()
289
+ logging.info(
290
+ f"De-queued info for account {c_account_credentials['AccountId']} in region {c_account_credentials['Region']}"
291
+ )
292
+
293
+ try:
294
+ # Begin Config service discovery for the current account and region
295
+ logging.info(
296
+ f"Checking for config recorders and delivery channels in account {c_account_credentials['AccountId']} in region {c_account_credentials['Region']}"
297
+ )
298
+
299
+ # Discover and process Config delivery channels with fragment-based filtering
300
+ capture_this_delivery_channel = False
301
+ account_dcs = Inventory_Modules.find_delivery_channels2(
302
+ c_account_credentials, c_account_credentials["Region"]
303
+ )
304
+
305
+ # Process discovered delivery channels with fragment matching logic
306
+ if len(account_dcs["DeliveryChannels"]) > 0:
307
+ # Apply fragment filtering for targeted delivery channel discovery
308
+ if c_fragments is None or "all" in c_fragments:
309
+ # Include all delivery channels when no fragment filter specified
310
+ capture_this_delivery_channel = True
311
+ logging.info(f"No fragment provided. Found {account_dcs['DeliveryChannels'][0]['name']}")
312
+ else:
313
+ # Apply fragment-based filtering for targeted discovery
314
+ for fragment in c_fragments:
315
+ if fragment in account_dcs["DeliveryChannels"][0]["name"]:
316
+ capture_this_delivery_channel = True
317
+ logging.info(
318
+ f"Found {account_dcs['DeliveryChannels'][0]['name']} which contains {fragment}"
319
+ )
320
+ break
321
+ else:
322
+ capture_this_delivery_channel = False
323
+ logging.info(
324
+ f"Looking for {fragment}. Found {account_dcs['DeliveryChannels'][0]['name']}, so skipping..."
325
+ )
326
+
327
+ # Aggregate delivery channel metadata for enterprise reporting
328
+ if capture_this_delivery_channel:
329
+ account_dcs["DeliveryChannels"][0].update(
330
+ {
331
+ "Type": "Delivery Channel", # Component type for categorization
332
+ "AccountId": c_account_credentials["AccountNumber"], # Account identifier
333
+ "AccessKeyId": c_account_credentials["AccessKeyId"], # Access credentials
334
+ "SecretAccessKey": c_account_credentials["SecretAccessKey"], # Secret credentials
335
+ "SessionToken": c_account_credentials["SessionToken"], # Session token
336
+ "Region": c_account_credentials["Region"], # Regional deployment
337
+ "MgmtAccount": c_account_credentials["MgmtAccount"], # Management account
338
+ "ParentProfile": c_account_credentials["ParentProfile"], # Profile context
339
+ "Deleted": False, # Deletion status tracking
340
+ }
341
+ )
342
+ account_crs_and_dcs.extend(account_dcs["DeliveryChannels"])
343
+
344
+ # Discover and process Config configuration recorders with fragment-based filtering
345
+ account_crs = Inventory_Modules.find_config_recorders2(
346
+ c_account_credentials, c_account_credentials["Region"]
347
+ )
348
+ capture_this_config_recorder = False
349
+
350
+ # Process discovered configuration recorders with fragment matching logic
351
+ if len(account_crs["ConfigurationRecorders"]) > 0:
352
+ # Apply fragment filtering for targeted configuration recorder discovery
353
+ if c_fragments is None or "all" in c_fragments:
354
+ # Include all configuration recorders when no fragment filter specified
355
+ capture_this_config_recorder = True
356
+ logging.info(
357
+ f"No fragment provided. Found {account_crs['ConfigurationRecorders'][0]['name']}"
358
+ )
359
+ else:
360
+ # Apply fragment-based filtering for targeted discovery
361
+ for fragment in c_fragments:
362
+ if fragment in account_crs["ConfigurationRecorders"][0]["name"]:
363
+ capture_this_config_recorder = True
364
+ logging.info(
365
+ f"Found {account_crs['ConfigurationRecorders'][0]['name']} which contains {fragment}"
366
+ )
367
+ break
368
+ else:
369
+ capture_this_config_recorder = False
370
+ logging.info(
371
+ f"Looking for {fragment}. Found {account_crs['ConfigurationRecorders'][0]['name']}, so skipping..."
372
+ )
373
+
374
+ # Aggregate configuration recorder metadata for enterprise reporting
375
+ if capture_this_config_recorder:
376
+ account_crs["ConfigurationRecorders"][0].update(
377
+ {
378
+ "Type": "Config Recorder", # Component type for categorization
379
+ "AccountId": c_account_credentials["AccountNumber"], # Account identifier
380
+ "AccessKeyId": c_account_credentials["AccessKeyId"], # Access credentials
381
+ "SecretAccessKey": c_account_credentials["SecretAccessKey"], # Secret credentials
382
+ "SessionToken": c_account_credentials["SessionToken"], # Session token
383
+ "Region": c_account_credentials["Region"], # Regional deployment
384
+ "MgmtAccount": c_account_credentials["MgmtAccount"], # Management account
385
+ "ParentProfile": c_account_credentials["ParentProfile"], # Profile context
386
+ "Deleted": False, # Deletion status tracking
387
+ }
388
+ )
389
+ account_crs_and_dcs.extend(account_crs["ConfigurationRecorders"])
390
+
391
+ # Log successful account and region processing for audit trail
392
+ logging.info(
393
+ f"Successfully connected to account {c_account_credentials['AccountId']} in region {c_account_credentials['Region']}"
394
+ )
395
+ except KeyError as my_Error:
396
+ # Handle missing key errors during Config component metadata extraction
397
+ logging.error(
398
+ f"Account Access failed - trying to access {c_account_credentials['AccountId']} in region {c_account_credentials['Region']}"
399
+ )
400
+ logging.info(f"Actual Error: {my_Error}")
401
+ pass
402
+ except AttributeError as my_Error:
403
+ # Handle attribute errors likely caused by incorrect profile configuration
404
+ logging.error(f"Error: Likely that one of the supplied profiles {pProfiles} was wrong")
405
+ logging.warning(my_Error)
406
+ continue
407
+ finally:
408
+ # Complete processing and update progress tracking
409
+ logging.info(
410
+ f"{ERASE_LINE}Finished finding items in account {c_account_credentials['AccountId']} in region {c_account_credentials['Region']} - {c_PlaceCount} / {c_PlacesToLook}"
411
+ )
412
+ pbar.update() # Update progress bar for operational visibility
413
+ self.queue.task_done() # Mark queue item as completed
414
+
415
+ # Initialize processing context and data structures for Config discovery
416
+ account_crs_and_dcs = [] # Aggregated results list for all discovered Config components
417
+ PlaceCount = 1 # Progress counter for operational visibility
418
+
419
+ # Configure optimal worker thread count based on credential count and system limits
420
+ WorkerThreads = min(len(CredentialList), 40)
421
+
422
+ checkqueue = Queue() # Queue for work distribution across worker threads
423
+
424
+ # Initialize progress tracking for operational visibility during Config discovery
425
+ pbar = tqdm(
426
+ desc=f"Finding config recorders / delivery channels from {len(AllCredentials)} accounts and regions",
427
+ total=len(AllCredentials),
428
+ unit=" accounts & regions",
429
+ )
430
+
431
+ # Create and start worker thread pool for concurrent Config component discovery
432
+ for x in range(WorkerThreads):
433
+ worker = Find_Config_Recorders_and_Delivery_Channels(checkqueue)
434
+ # Daemon threads allow main thread exit even if workers are still processing
435
+ worker.daemon = True
436
+ worker.start()
437
+
438
+ # Queue Config discovery work items for worker thread processing
439
+ # Note: Credential list already includes regional context, eliminating need for nested region iteration
440
+ for credential in CredentialList:
441
+ logging.info(f"Connecting to account {credential['AccountId']} in region {credential['Region']}")
442
+ try:
443
+ # Queue account and region combination for worker thread processing
444
+ # Note: Tuple structure is critical for proper parameter expansion in worker threads
445
+ checkqueue.put((credential, fFixRun, fFragments, len(CredentialList), PlaceCount))
446
+ except ClientError as my_Error:
447
+ # Handle authorization failures with informative error messaging
448
+ if "AuthFailure" in str(my_Error):
449
+ logging.error(
450
+ f"Authorization Failure accessing account {credential['AccountId']} in {credential['Region']} region"
451
+ )
452
+ logging.warning(f"It's possible that the region {credential['Region']} hasn't been opted-into")
453
+ pass
454
+
455
+ # Wait for all worker threads to complete processing
456
+ checkqueue.join()
457
+ pbar.close() # Close progress bar after completion
458
+ return account_crs_and_dcs
459
+
460
+
461
+ def _delete_config_recorders_and_delivery_channels(f_config_recorders_and_delivery_channels_to_delete, f_timing):
462
+ """
463
+ Execute safe deletion of AWS Config service configuration recorders and delivery channels.
464
+
465
+ Performs batch deletion operations for Config service components with comprehensive error
466
+ handling, progress tracking, and status validation. Designed for enterprise Config service
467
+ cleanup operations with safety controls and operational visibility for infrastructure teams
468
+ managing Config service decommissioning and optimization.
469
+
470
+ Args:
471
+ f_config_recorders_and_delivery_channels_to_delete (list): List of Config component
472
+ dictionaries containing deletion targets with:
473
+ - Type: Config component type (Config Recorder or Delivery Channel)
474
+ - AccountId: Target AWS account for deletion operation
475
+ - Region: Target AWS region for Config component removal
476
+ - name: Config component name identifier
477
+ - Access credentials and metadata for deletion operations
478
+ f_timing (bool): Performance timing flag for operational metrics and milestone tracking
479
+
480
+ Returns:
481
+ list: Updated Config component list with deletion status tracking containing:
482
+ - Original component metadata preserved for audit trails
483
+ - Deleted: Boolean flag indicating successful deletion completion
484
+ - Deletion operation results and error details for troubleshooting
485
+
486
+ Deletion Process:
487
+ - Sequential processing for reliable Config component deletion
488
+ - Pre-deletion validation ensuring component exists and is accessible
489
+ - Comprehensive error handling for authorization and dependency issues
490
+ - Status tracking with detailed logging for operational audit trails
491
+
492
+ Safety Features:
493
+ - Deletion confirmation and validation before component removal
494
+ - Comprehensive error handling preventing partial deletion states
495
+ - Detailed logging for compliance and audit trail requirements
496
+ - Rollback-safe operations with status tracking and error reporting
497
+
498
+ Performance Monitoring:
499
+ - Optional timing metrics for deletion operation analysis
500
+ - Progress tracking for operational visibility during batch deletions
501
+ - Performance milestone reporting for optimization and planning
502
+ - Efficient deletion sequencing for minimal operational impact
503
+
504
+ Enterprise Operations:
505
+ - Batch deletion capabilities for efficient Config service cleanup
506
+ - Comprehensive audit logging for compliance and operational tracking
507
+ - Error handling and recovery for enterprise operational requirements
508
+ - Status validation and confirmation for deletion verification
509
+
510
+ Error Handling:
511
+ - AWS API error management with graceful degradation
512
+ - Authorization failure detection with appropriate logging
513
+ - Dependency validation preventing orphaned resource creation
514
+ - Comprehensive error reporting for troubleshooting and audit trails
515
+ """
516
+ # Begin Config service component deletion with operational logging
517
+ logging.warning("Deleting all Config Recorders")
518
+ for deletion_item in f_config_recorders_and_delivery_channels_to_delete:
519
+ try:
520
+ # Display deletion progress for operational visibility
521
+ print(
522
+ ERASE_LINE,
523
+ f"Deleting {deletion_item['Type']} from Account {deletion_item['AccountId']} in region {deletion_item['Region']}",
524
+ end="\r",
525
+ )
526
+
527
+ # Process Config Recorder deletion with AWS API validation
528
+ if deletion_item["Type"] == "Config Recorder":
529
+ # Establish Config service client for configuration recorder deletion
530
+ config_client = Inventory_Modules.get_child_access2(
531
+ profile=deletion_item, region=deletion_item["Region"], service="config"
532
+ )
533
+ # Execute configuration recorder deletion with AWS Config API
534
+ deleteit = config_client.delete_configuration_recorder(ConfigurationRecorderName=deletion_item["name"])
535
+ # Display timing metrics for performance monitoring if requested
536
+ if f_timing:
537
+ print(
538
+ f"{ERASE_LINE}Deleted {deletion_item['Type']} in {deleteit['ResponseMetadata']['HTTPStatusCode']} ms"
539
+ )
540
+ deletion_item["Deleted"] = True # Mark deletion as successful
541
+ logging.warning(f"Deleted {deletion_item['Type']} {deletion_item['name']}")
542
+
543
+ # Process Delivery Channel deletion with AWS API validation
544
+ elif deletion_item["Type"] == "Delivery Channel":
545
+ # Establish Config service client for delivery channel deletion
546
+ config_client = Inventory_Modules.get_child_access2(
547
+ profile=deletion_item, region=deletion_item["Region"], service="config"
548
+ )
549
+ # Execute delivery channel deletion with AWS Config API
550
+ deleteit = config_client.delete_delivery_channel(DeliveryChannelName=deletion_item["name"])
551
+ # Display timing metrics for performance monitoring if requested
552
+ if f_timing:
553
+ print(
554
+ f"{ERASE_LINE}Deleted {deletion_item['Type']} in {deleteit['ResponseMetadata']['HTTPStatusCode']} ms"
555
+ )
556
+ deletion_item["Deleted"] = True # Mark deletion as successful
557
+ logging.warning(f"Deleted {deletion_item['Type']} {deletion_item['name']}")
558
+
559
+ except Exception as my_Error:
560
+ # Handle deletion failures with comprehensive error logging
561
+ deletion_item["Deleted"] = False # Mark deletion as failed
562
+ print(f"Error: {my_Error}")
563
+
564
+ return f_config_recorders_and_delivery_channels_to_delete
565
+
566
+
567
+ ##################
568
+ # Main
569
+ ##################
570
+
571
+
572
+ if __name__ == "__main__":
573
+ args = parse_args(sys.argv[1:])
574
+ pProfiles = args.Profiles
575
+ pRegionList = args.Regions
576
+ pAccounts = args.Accounts
577
+ pFragments = args.Fragments
578
+ pSkipAccounts = args.SkipAccounts
579
+ pSkipProfiles = args.SkipProfiles
580
+ pRootOnly = args.RootOnly
581
+ pFilename = args.Filename
582
+ pChildAccessRole = args.AccessRole
583
+ pTiming = args.Time
584
+ verbose = args.loglevel
585
+ DeletionRun = args.flagDelete
586
+ ForceDelete = args.Force
587
+ logging.basicConfig(level=verbose, format="[%(filename)s:%(lineno)s - %(funcName)30s() ] %(message)s")
588
+ logging.getLogger("boto3").setLevel(logging.CRITICAL)
589
+ logging.getLogger("botocore").setLevel(logging.CRITICAL)
590
+ logging.getLogger("s3transfer").setLevel(logging.CRITICAL)
591
+ logging.getLogger("urllib3").setLevel(logging.CRITICAL)
592
+ logging.getLogger("botocore").setLevel(logging.CRITICAL)
593
+
594
+ ERASE_LINE = "\x1b[2K"
595
+ begin_time = time()
596
+
597
+ display_dict = {
598
+ "ParentProfile": {"DisplayOrder": 1, "Heading": "Parent Profile"},
599
+ "MgmtAccount": {"DisplayOrder": 2, "Heading": "Mgmt Acct"},
600
+ "AccountId": {"DisplayOrder": 3, "Heading": "Acct Number"},
601
+ "Region": {"DisplayOrder": 4, "Heading": "Region"},
602
+ "Type": {"DisplayOrder": 5, "Heading": "Type"},
603
+ "name": {"DisplayOrder": 6, "Heading": "Name"},
604
+ }
605
+
606
+ NumObjectsFound = 0
607
+ NumAccountsInvestigated = 0
608
+
609
+ AllCredentials = get_all_credentials(
610
+ pProfiles, pTiming, pSkipProfiles, pSkipAccounts, pRootOnly, pAccounts, pRegionList
611
+ )
612
+ RegionList = list(set([x["Region"] for x in AllCredentials]))
613
+ AccountNum = len(set([acct["AccountId"] for acct in AllCredentials]))
614
+
615
+ cf_regions = Inventory_Modules.get_service_regions("config", RegionList)
616
+ print()
617
+ print(f"Searching total of {AccountNum} accounts and {len(cf_regions)} regions")
618
+ if pTiming:
619
+ print()
620
+ milestone_time1 = time()
621
+ print(
622
+ f"{Fore.GREEN}\t\tFiguring out what regions are available to your accounts, and capturing credentials for all accounts in those regions took: {(milestone_time1 - begin_time):.3f} seconds{Fore.RESET}"
623
+ )
624
+ print()
625
+ print(f"Now running through all accounts and regions identified to find resources...")
626
+ all_config_recorders_and_delivery_channels = check_accounts_for_delivery_channels_and_config_recorders(
627
+ AllCredentials, pFragments, DeletionRun
628
+ )
629
+
630
+ if pTiming:
631
+ print()
632
+ milestone_time2 = time()
633
+ print(
634
+ f"{Fore.GREEN}\t\tChecking {len(AllCredentials)} places took: {(milestone_time2 - milestone_time1):.3f} seconds{Fore.RESET}"
635
+ )
636
+ print()
637
+ cr = 0
638
+ dc = 0
639
+ for item in all_config_recorders_and_delivery_channels:
640
+ if item["Type"] == "Delivery Channel":
641
+ dc += 1
642
+ elif item["Type"] == "Config Recorder":
643
+ cr += 1
644
+
645
+ all_sorted_config_recorders_and_delivery_channels = sorted(
646
+ all_config_recorders_and_delivery_channels,
647
+ key=lambda d: (d["ParentProfile"], d["MgmtAccount"], d["AccountId"], d["Region"], d["Type"]),
648
+ )
649
+ if pTiming:
650
+ print()
651
+ milestone_time3 = time()
652
+ print(
653
+ f"{Fore.GREEN}\t\tSorting the list of places took: {(milestone_time3 - milestone_time2):.3f} seconds{Fore.RESET}"
654
+ )
655
+ print()
656
+ display_results(all_sorted_config_recorders_and_delivery_channels, display_dict, None, pFilename)
657
+
658
+ print(ERASE_LINE)
659
+ print(f"We scanned {AccountNum} accounts and {len(RegionList)} regions...")
660
+ print(f"We Found {cr} Configuration Recorders and {dc} Delivery Channels")
661
+ print()
662
+
663
+ if DeletionRun and not ForceDelete:
664
+ ReallyDelete = (
665
+ input("Deletion of Config Recorders and Delivery Channels has been requested. Are you still sure? (y/n): ")
666
+ == "y"
667
+ )
668
+ else:
669
+ ReallyDelete = False
670
+
671
+ if DeletionRun and (ReallyDelete or ForceDelete):
672
+ deleted_config_recorders_and_delivery_channels = _delete_config_recorders_and_delivery_channels(
673
+ all_sorted_config_recorders_and_delivery_channels, pTiming
674
+ )
675
+
676
+ if pTiming:
677
+ print(ERASE_LINE)
678
+ print(f"{Fore.GREEN}This whole script took {time() - begin_time:.3f} seconds{Fore.RESET}")
679
+ print()
680
+ print("Thank you for using this tool")
681
+ print()