Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: Return empty access_keys object when access keys do not exist #1309

Merged

Conversation

austincomstockzoom
Copy link
Contributor

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.

@ryandiamond23
Copy link

LGTM

@achantavy
Copy link
Contributor

Hi @austincomstockzoom, thank you for the fix! Can you please sign the CLA?

@austincomstockzoom
Copy link
Contributor Author

Check again, thanks

@achantavy achantavy merged commit b9116ed into cartography-cncf:master Jun 17, 2024
5 checks passed
chandanchowdhury pushed a commit to juju4/cartography that referenced this pull request Jun 26, 2024
cartography-cncf#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]>
SecPrez pushed a commit to SecPrez/cartography that referenced this pull request Nov 10, 2024
cartography-cncf#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]>
chandanchowdhury pushed a commit to chandanchowdhury/cartography that referenced this pull request Nov 27, 2024
cartography-cncf#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]>
Signed-off-by: chandanchowdhury <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants