Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug: Return empty access_keys object when access keys do not exist (
#1309) While running the AWS sync in Cartography, the following error occurs, causing the sync process to fail: ``` ERROR:cartography.sync:Unhandled exception during sync stage 'aws' Traceback (most recent call last): File "/home/REDACTED/cartography/cartography/sync.py", line 113, in run stage_func(neo4j_session, config) File "/home/REDACTED/cartography/cartography/util.py", line 197, in timed return method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/intel/aws/__init__.py", line 298, in start_aws_ingestion sync_successful = _sync_multiple_accounts( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/intel/aws/__init__.py", line 169, in _sync_multiple_accounts _sync_one_account( File "/home/REDACTED/cartography/cartography/intel/aws/__init__.py", line 64, in _sync_one_account RESOURCE_FUNCTIONS[func_name](**sync_args) File "/home/REDACTED/cartography/cartography/util.py", line 197, in timed return method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/intel/aws/iam.py", line 819, in sync sync_user_access_keys(neo4j_session, boto3_session, current_aws_account_id, update_tag, common_job_parameters) File "/home/REDACTED/cartography/cartography/util.py", line 197, in timed return method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/intel/aws/iam.py", line 795, in sync_user_access_keys access_keys = get_account_access_key_data(boto3_session, user["name"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/util.py", line 197, in timed return method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/REDACTED/cartography/cartography/intel/aws/iam.py", line 230, in get_account_access_key_data for access_key in access_keys['AccessKeyMetadata']: ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ KeyError: 'AccessKeyMetadata' ERROR:__main__:Error in AWS account sync REDACTED: 'AccessKeyMetadata' ``` The fix involves returning the access_keys object directly from the get_account_access_key_data function. This ensures that the function returns the correct data structure, even if the AccessKeyMetadata key is missing. The function was tested with various AWS accounts to ensure it correctly handles cases where the AccessKeyMetadata key is present and when it is missing. Verified that the sync process was completed successfully without any errors. Co-authored-by: Alex Chantavy <[email protected]>
- Loading branch information