Skip to content

Commit

Permalink
fix(iam): handle non existing MFA devices (#6396)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCloudSec authored Jan 9, 2025
1 parent 901bc69 commit 4bcf036
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions prowler/providers/aws/services/iam/iam_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,38 @@ def _list_mfa_devices(self):
logger.info("IAM - List MFA Devices...")
try:
for user in self.users:
list_mfa_devices_paginator = self.client.get_paginator(
"list_mfa_devices"
)
mfa_devices = []
for page in list_mfa_devices_paginator.paginate(UserName=user.name):
for mfa_device in page["MFADevices"]:
mfa_serial_number = mfa_device["SerialNumber"]
try:
mfa_type = mfa_serial_number.split(":")[5].split("/")[0]
except IndexError:
mfa_type = "hardware"
mfa_devices.append(
MFADevice(serial_number=mfa_serial_number, type=mfa_type)
try:
list_mfa_devices_paginator = self.client.get_paginator(
"list_mfa_devices"
)
mfa_devices = []
for page in list_mfa_devices_paginator.paginate(UserName=user.name):
for mfa_device in page["MFADevices"]:
mfa_serial_number = mfa_device["SerialNumber"]
try:
mfa_type = mfa_serial_number.split(":")[5].split("/")[0]
except IndexError:
mfa_type = "hardware"
mfa_devices.append(
MFADevice(
serial_number=mfa_serial_number, type=mfa_type
)
)
user.mfa_devices = mfa_devices
except ClientError as error:
if error.response["Error"]["Code"] == "NoSuchEntity":
logger.warning(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
else:
logger.error(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
user.mfa_devices = mfa_devices

except Exception as error:
logger.error(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
except Exception as error:
logger.error(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
Expand Down

0 comments on commit 4bcf036

Please sign in to comment.