runbooks 0.2.5__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 +7 -7
  199. runbooks/security_baseline/report_template_jp.html +7 -7
  200. runbooks/security_baseline/report_template_kr.html +12 -12
  201. runbooks/security_baseline/report_template_vn.html +7 -7
  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.5.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.5.dist-info/METADATA +0 -439
  219. runbooks-0.2.5.dist-info/RECORD +0 -61
  220. runbooks-0.2.5.dist-info/entry_points.txt +0 -3
  221. runbooks-0.2.5.dist-info/top_level.txt +0 -1
@@ -0,0 +1,354 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ AWS Organizations User Inventory Discovery Script
5
+
6
+ This script provides comprehensive discovery and enumeration capabilities for user accounts
7
+ across AWS Organizations environments, supporting both traditional IAM users and modern
8
+ AWS Identity Center (formerly AWS SSO) user management. It's designed for enterprise
9
+ identity and access management teams who need complete visibility into user distribution,
10
+ access patterns, and identity governance across large-scale multi-account deployments.
11
+
12
+ Key Features:
13
+ - Multi-account user discovery using assume role capabilities across AWS Organizations
14
+ - Dual identity source support: IAM users and AWS Identity Center users
15
+ - Comprehensive user metadata extraction with last access tracking
16
+ - Cross-account user enumeration with organizational hierarchy mapping
17
+ - Identity Center directory deduplication for efficient discovery
18
+ - Enterprise reporting with CSV export and structured output
19
+ - Profile-based authentication with support for federated access
20
+
21
+ Enterprise Use Cases:
22
+ - Identity governance and user access auditing across organizations
23
+ - User lifecycle management and access certification processes
24
+ - Security compliance reporting for identity and access management
25
+ - Identity consolidation analysis and migration planning
26
+ - Multi-account user access patterns and behavioral analysis
27
+ - Identity Center adoption tracking and governance oversight
28
+ - User account sprawl detection and cleanup initiatives
29
+
30
+ Identity Management Features:
31
+ - IAM user discovery with comprehensive metadata extraction including:
32
+ - User creation dates and last password usage tracking
33
+ - Access key status and last activity monitoring
34
+ - Policy attachments and group membership analysis
35
+ - AWS Identity Center user enumeration with directory awareness including:
36
+ - Identity Center user profiles and attributes
37
+ - Directory instance discovery and deduplication
38
+ - User provisioning status and access tracking
39
+ - Cross-account identity correlation for governance oversight
40
+
41
+ Security Considerations:
42
+ - Uses IAM assume role capabilities for cross-account user discovery
43
+ - Implements proper error handling for authorization failures
44
+ - Supports read-only operations with no user modification capabilities
45
+ - Respects identity service permissions and regional access constraints
46
+ - Provides comprehensive audit trail through detailed logging
47
+ - Sensitive user information handling with appropriate access controls
48
+
49
+ Identity Center Integration:
50
+ - Automatic discovery of Identity Center directory instances
51
+ - Directory deduplication to prevent duplicate user enumeration
52
+ - Support for multiple Identity Center instances across organization
53
+ - Integration with Identity Center user provisioning and lifecycle management
54
+ - Identity Center user attribute and profile extraction
55
+
56
+ Performance Considerations:
57
+ - Sequential processing for reliable user discovery operations
58
+ - Progress tracking for operational visibility during large-scale enumeration
59
+ - Efficient credential management for cross-account user access
60
+ - Memory-optimized data structures for large user inventories
61
+ - Directory deduplication to optimize Identity Center discovery performance
62
+
63
+ Threading Architecture:
64
+ - Currently uses sequential processing for reliable operations
65
+ - TODO: Multi-threading enhancement planned for improved performance
66
+ - Thread-safe error handling and progress tracking architecture
67
+ - Graceful degradation for account access failures
68
+
69
+ Dependencies:
70
+ - boto3/botocore for AWS IAM and Identity Center API interactions
71
+ - ArgumentsClass for standardized CLI argument parsing
72
+ - Inventory_Modules for common utility functions and credential management
73
+ - colorama for enhanced output formatting
74
+ - tqdm for progress tracking during user discovery
75
+
76
+ Compliance and Audit Features:
77
+ - Comprehensive user discovery for identity governance auditing
78
+ - User access pattern analysis for compliance validation
79
+ - Cross-account user visibility for organizational security oversight
80
+ - Identity lifecycle tracking for governance and compliance management
81
+ - User attribute and metadata extraction for compliance reporting
82
+
83
+ Future Enhancements:
84
+ - Multi-threading for improved performance across large organizations
85
+ - User access pattern analysis and behavioral analytics
86
+ - Integration with AWS CloudTrail for user activity correlation
87
+ - User optimization recommendations for identity governance
88
+
89
+ Author: AWS CloudOps Team
90
+ Version: 2024.05.09
91
+ """
92
+
93
+ import logging
94
+ import sys
95
+ from os.path import split
96
+ from time import time
97
+
98
+ from ArgumentsClass import CommonArguments
99
+ from botocore.exceptions import ClientError
100
+ from colorama import Fore, init
101
+ from Inventory_Modules import (
102
+ display_results,
103
+ find_iam_users2,
104
+ find_idc_directory_id2,
105
+ find_idc_users2,
106
+ get_all_credentials,
107
+ )
108
+ from tqdm.auto import tqdm
109
+
110
+ init()
111
+ __version__ = "2024.05.09"
112
+ ERASE_LINE = "\x1b[2K"
113
+ begin_time = time()
114
+
115
+
116
+ ##################
117
+ # Functions
118
+ ##################
119
+ def parse_args(arguments):
120
+ """
121
+ Parse command line arguments for AWS Organizations user discovery operations.
122
+
123
+ Configures comprehensive argument parsing for multi-account, multi-region user inventory
124
+ operations. Supports enterprise identity and access management with profile management,
125
+ region targeting, organizational access controls, and identity source selection for both
126
+ traditional IAM users and modern AWS Identity Center user management.
127
+
128
+ Args:
129
+ arguments (list): Command line arguments from sys.argv[1:]
130
+
131
+ Returns:
132
+ argparse.Namespace: Parsed arguments containing:
133
+ - Profiles: List of AWS profiles to process
134
+ - Regions: Target regions for user discovery
135
+ - SkipProfiles/SkipAccounts: Exclusion filters
136
+ - RootOnly: Limit to organization root accounts
137
+ - AccessRoles: Cross-account roles for Organizations access
138
+ - Filename: Output file for CSV export
139
+ - Time: Enable performance timing metrics
140
+ - loglevel: Logging verbosity configuration
141
+ - pIdentityCenter: Enable AWS Identity Center user discovery
142
+ - pIAM: Enable IAM user discovery
143
+
144
+ Configuration Options:
145
+ - Multi-region scanning with region filters for targeted user analysis
146
+ - Multi-profile support for federated access across identity infrastructure
147
+ - Extended arguments for advanced filtering and account selection
148
+ - Root-only mode for organization-level user inventory
149
+ - Role-based access for cross-account user discovery
150
+ - File output for integration with identity management tools
151
+ - Timing metrics for performance optimization and monitoring
152
+ - Verbose logging for debugging and identity governance audit
153
+
154
+ Identity Source Selection:
155
+ - IAM flag (--iam): Enable traditional IAM user discovery and enumeration
156
+ - Identity Center flag (--idc): Enable AWS Identity Center user discovery
157
+ - Default behavior: Both identity sources enabled when neither flag specified
158
+ - Selective discovery for focused identity analysis and governance
159
+
160
+ Enterprise Identity Management:
161
+ - Multi-account user discovery across organizational boundaries
162
+ - Identity source flexibility for migration and governance planning
163
+ - Cross-account user enumeration with organizational hierarchy mapping
164
+ - Identity governance and compliance reporting capabilities
165
+ """
166
+ script_path, script_name = split(sys.argv[0])
167
+ parser = CommonArguments()
168
+ parser.my_parser.description = "Discover and enumerate both IAM users and AWS Identity Center users across AWS Organizations for enterprise identity governance and access management."
169
+ parser.multiprofile()
170
+ parser.multiregion()
171
+ parser.extendedargs()
172
+ parser.rootOnly()
173
+ parser.rolestouse()
174
+ parser.save_to_file()
175
+ parser.verbosity()
176
+ parser.timing()
177
+ parser.version(__version__)
178
+ local = parser.my_parser.add_argument_group(script_name, "Parameters specific to this script")
179
+ local.add_argument(
180
+ "--idc",
181
+ dest="pIdentityCenter",
182
+ action="store_true", # Defaults to False
183
+ help="Enable AWS Identity Center user discovery only - supports modern centralized identity management with directory integration",
184
+ )
185
+ local.add_argument(
186
+ "--iam",
187
+ dest="pIAM",
188
+ action="store_true", # Defaults to False
189
+ help="Enable traditional IAM user discovery only - supports legacy identity management and direct account access patterns",
190
+ )
191
+ return parser.my_parser.parse_args(arguments)
192
+
193
+
194
+ def find_all_org_users(f_credentials, f_IDC: bool, f_IAM: bool) -> list:
195
+ """
196
+ Discover and enumerate user accounts across AWS Organizations supporting both IAM and Identity Center.
197
+
198
+ Performs comprehensive user discovery using sequential processing to efficiently inventory
199
+ users across enterprise AWS environments. Supports dual identity sources with directory
200
+ deduplication and comprehensive metadata extraction for enterprise identity governance.
201
+
202
+ Args:
203
+ f_credentials (list): List of credential dictionaries for cross-account access containing:
204
+ - AccountId: AWS account number
205
+ - Success: Boolean indicating credential validity
206
+ - ErrorMessage: Error details for failed credential attempts
207
+ - RolesTried: List of roles attempted for access
208
+ f_IDC (bool): Enable AWS Identity Center user discovery
209
+ f_IAM (bool): Enable traditional IAM user discovery
210
+
211
+ Returns:
212
+ list: Comprehensive list of user dictionaries containing:
213
+ - MgmtAccount: Management account identifier for organizational hierarchy
214
+ - AccountId: AWS account containing the user
215
+ - Region: AWS region where user is managed
216
+ - UserName: User account name or identifier
217
+ - PasswordLastUsed: Last password usage timestamp (IAM users)
218
+ - Type: User source type (IAM or Identity Center)
219
+ - Additional metadata based on user type and source
220
+
221
+ Identity Discovery Features:
222
+ - IAM user enumeration with comprehensive metadata extraction
223
+ - Identity Center user discovery with directory awareness
224
+ - Directory instance deduplication for efficient discovery
225
+ - Cross-account user correlation for governance oversight
226
+ - User access pattern tracking for compliance analysis
227
+
228
+ Performance Considerations:
229
+ - Sequential processing for reliable user discovery operations
230
+ - Progress tracking for operational visibility during enumeration
231
+ - Directory deduplication to optimize Identity Center discovery
232
+ - Memory-optimized data structures for large user inventories
233
+ - TODO: Multi-threading enhancement planned for improved performance
234
+
235
+ Error Handling:
236
+ - Authorization failure detection with appropriate logging
237
+ - AWS API error management with graceful degradation
238
+ - Credential validation and failure tracking
239
+ - Comprehensive error reporting for troubleshooting
240
+
241
+ Identity Center Integration:
242
+ - Automatic discovery of Identity Center directory instances
243
+ - Directory deduplication to prevent duplicate user enumeration
244
+ - Support for multiple Identity Center instances across organization
245
+ - Integration with Identity Center user provisioning and lifecycle
246
+
247
+ Enterprise Identity Governance:
248
+ - Cross-account user visibility for organizational security oversight
249
+ - User lifecycle tracking for governance and compliance management
250
+ - Identity source correlation for migration and governance planning
251
+ - User attribute and metadata extraction for compliance reporting
252
+ """
253
+ User_List = []
254
+ directories_seen = set()
255
+
256
+ # TODO: Enhance with multi-threading for improved performance across large organizations
257
+ for credential in tqdm(
258
+ f_credentials, desc=f"Looking for users across {len(f_credentials)} Accounts", unit=" accounts"
259
+ ):
260
+ # Skip credentials that failed validation
261
+ if not credential["Success"]:
262
+ logging.info(f"{credential['ErrorMessage']} with roles: {credential['RolesTried']}")
263
+ continue
264
+
265
+ # Discover traditional IAM users if requested
266
+ if f_IAM:
267
+ try:
268
+ # Call inventory module to discover IAM users in this account
269
+ User_List.extend(find_iam_users2(credential))
270
+ # Optional verbose logging for user discovery progress (currently commented)
271
+ # logging.info(f"{ERASE_LINE}Account: {credential['AccountId']} Found {len(User_List)} users")
272
+ except ClientError as my_Error:
273
+ # Handle IAM API authorization failures gracefully
274
+ if "AuthFailure" in str(my_Error):
275
+ logging.error(f"{ERASE_LINE}{credential}: Authorization Failure")
276
+
277
+ # Discover AWS Identity Center users if requested
278
+ if f_IDC:
279
+ try:
280
+ # Find out if this account hosts an Identity Center with a user directory
281
+ directory_ids = find_idc_directory_id2(credential)
282
+ for directory_instance_id in directory_ids:
283
+ # Directory deduplication: if we've already interrogated this directory, skip it
284
+ if directory_instance_id in directories_seen:
285
+ continue
286
+ else:
287
+ # Mark this directory as processed and discover users
288
+ directories_seen.update(directory_ids)
289
+ User_List.extend(find_idc_users2(credential, directory_instance_id))
290
+ # Optional verbose logging for user discovery progress (currently commented)
291
+ # logging.info(f"{ERASE_LINE}Account: {credential['AccountId']} Found {len(User_List)} users")
292
+ except ClientError as my_Error:
293
+ # Handle Identity Center API authorization failures gracefully
294
+ if "AuthFailure" in str(my_Error):
295
+ logging.error(f"{ERASE_LINE}{credential}: Authorization Failure")
296
+ return User_List
297
+
298
+
299
+ ##################
300
+ # Main
301
+ ##################
302
+
303
+ if __name__ == "__main__":
304
+ args = parse_args(sys.argv[1:])
305
+ pProfiles = args.Profiles
306
+ pRegionList = args.Regions
307
+ pAccounts = args.Accounts
308
+ pSkipAccounts = args.SkipAccounts
309
+ pSkipProfiles = args.SkipProfiles
310
+ pAccessRoles = args.AccessRoles
311
+ pFilename = args.Filename
312
+ pIdentityCenter = args.pIdentityCenter
313
+ pIAM = args.pIAM
314
+ # Although I want to the flags to remain
315
+ if not pIAM and not pIdentityCenter:
316
+ pIdentityCenter = True
317
+ pIAM = True
318
+ pRootOnly = args.RootOnly
319
+ pTiming = args.Time
320
+ verbose = args.loglevel
321
+ logging.basicConfig(level=verbose, format="[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
322
+ logging.getLogger("boto3").setLevel(logging.CRITICAL)
323
+ logging.getLogger("botocore").setLevel(logging.CRITICAL)
324
+ logging.getLogger("s3transfer").setLevel(logging.CRITICAL)
325
+ logging.getLogger("urllib3").setLevel(logging.CRITICAL)
326
+
327
+ CredentialList = get_all_credentials(
328
+ pProfiles, pTiming, pSkipProfiles, pSkipAccounts, pRootOnly, pAccounts, pRegionList, pAccessRoles
329
+ )
330
+ SuccessfulAccountAccesses = [x for x in CredentialList if x["Success"]]
331
+ UserListing = find_all_org_users(CredentialList, pIdentityCenter, pIAM)
332
+ sorted_UserListing = sorted(
333
+ UserListing, key=lambda k: (k["MgmtAccount"], k["AccountId"], k["Region"], k["UserName"])
334
+ )
335
+
336
+ display_dict = {
337
+ "MgmtAccount": {"DisplayOrder": 1, "Heading": "Mgmt Acct"},
338
+ "AccountId": {"DisplayOrder": 2, "Heading": "Acct Number"},
339
+ "Region": {"DisplayOrder": 3, "Heading": "Region"},
340
+ "UserName": {"DisplayOrder": 4, "Heading": "User Name"},
341
+ "PasswordLastUsed": {"DisplayOrder": 5, "Heading": "Last Used"},
342
+ "Type": {"DisplayOrder": 6, "Heading": "Source"},
343
+ }
344
+ display_results(sorted_UserListing, display_dict, "N/A", pFilename)
345
+ if pTiming:
346
+ print(ERASE_LINE)
347
+ print(f"{Fore.GREEN}This script took {time() - begin_time:.2f} seconds{Fore.RESET}")
348
+ print(ERASE_LINE)
349
+ print(
350
+ f"Found {len(UserListing)} users across {len(SuccessfulAccountAccesses)} account{'' if len(SuccessfulAccountAccesses) == 1 else 's'}"
351
+ )
352
+ print()
353
+ print("Thank you for using this script")
354
+ print()