duo-labs / cloudmapper

CloudMapper helps you analyze your Amazon Web Services (AWS) environments.
BSD 3-Clause "New" or "Revised" License
5.97k stars 802 forks source link

timezone issue in iso_date #962

Open yasinzaehringer-paradime opened 1 month ago

yasinzaehringer-paradime commented 1 month ago

Note the Network Visualization functionality (command prepare) is no longer maintained.

Please mention the following:

Exception was:

Exception:
unconverted data remains: Z

Traceback (most recent call last):
 File "/tmp/airflow/cloudmapper/shared/audit.py", line 1195, in audit
   audit_users(findings, region)
 File "/tmp/airflow/cloudmapper/shared/audit.py", line 409, in audit_users
   user_age = days_between(collection_date, user["user_creation_time"])
 File "/tmp/airflow/cloudmapper/shared/common.py", line 348, in days_between
   d2 = iso_date(s2)
 File "/tmp/airflow/cloudmapper/shared/common.py", line 342, in iso_date
   return datetime.datetime.strptime(d.split("+")[0], time_format)
 File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
   tt, fraction, gmtoff_fraction = _strptime(data_string, format)
 File "/usr/local/lib/python3.9/_strptime.py", line 352, in _strptime
   raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: Z

The reason seems to be that these commands

aws iam generate-credential-report 
aws iam get-credential-report

return data which have timestamps which end with Z instead of +00:00 - which are both valid values. And https://github.com/duo-labs/cloudmapper/blob/main/shared/common.py#L342 assumes that it ends with +00:00.

crash7 commented 1 week ago

I fixed this by changing this to something like:

def iso_date(d):
    """Convert ISO format date string such as 2018-04-08T23:33:20+00:00"""
    time_format = "%Y-%m-%dT%H:%M:%S"
-    return datetime.datetime.strptime(d.split("+")[0], time_format)
+    return datetime.datetime.strptime(d.replace('Z', '').split("+")[0], time_format)

Probably a better fix would be to just consider dates won't have the +00:00 now, but didn't know if this was used somewhere else.

reifyhealth-caseybecking commented 4 days ago

This change also worked for me!