mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
fix(key_errors): handle Key Errors in Lambda and EMR (#1871)
Co-authored-by: sergargar <sergargar@users.noreply.github.com>
This commit is contained in:
@@ -12,31 +12,30 @@ class awslambda_function_no_secrets_in_code(Check):
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
findings = []
|
findings = []
|
||||||
for function in awslambda_client.functions.values():
|
for function in awslambda_client.functions.values():
|
||||||
report = Check_Report_AWS(self.metadata())
|
if function.code:
|
||||||
report.region = function.region
|
report = Check_Report_AWS(self.metadata())
|
||||||
report.resource_id = function.name
|
report.region = function.region
|
||||||
report.resource_arn = function.arn
|
report.resource_id = function.name
|
||||||
|
report.resource_arn = function.arn
|
||||||
|
|
||||||
report.status = "PASS"
|
report.status = "PASS"
|
||||||
report.status_extended = (
|
report.status_extended = (
|
||||||
f"No secrets found in Lambda function {function.name} code"
|
f"No secrets found in Lambda function {function.name} code"
|
||||||
)
|
)
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir_name:
|
||||||
|
function.code.code_zip.extractall(tmp_dir_name)
|
||||||
|
# List all files
|
||||||
|
files_in_zip = next(os.walk(tmp_dir_name))[2]
|
||||||
|
for file in files_in_zip:
|
||||||
|
secrets = SecretsCollection()
|
||||||
|
with default_settings():
|
||||||
|
secrets.scan_file(f"{tmp_dir_name}/{file}")
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp_dir_name:
|
if secrets.json():
|
||||||
function.code.code_zip.extractall(tmp_dir_name)
|
report.status = "FAIL"
|
||||||
# List all files
|
report.status_extended = f"Potential secret found in Lambda function {function.name} code"
|
||||||
files_in_zip = next(os.walk(tmp_dir_name))[2]
|
break
|
||||||
for file in files_in_zip:
|
|
||||||
|
|
||||||
secrets = SecretsCollection()
|
findings.append(report)
|
||||||
with default_settings():
|
|
||||||
secrets.scan_file(f"{tmp_dir_name}/{file}")
|
|
||||||
|
|
||||||
if secrets.json():
|
|
||||||
report.status = "FAIL"
|
|
||||||
report.status_extended = f"Potential secret found in Lambda function {function.name} code"
|
|
||||||
break
|
|
||||||
|
|
||||||
findings.append(report)
|
|
||||||
|
|
||||||
return findings
|
return findings
|
||||||
|
|||||||
@@ -87,12 +87,13 @@ class Lambda:
|
|||||||
function_information = regional_client.get_function(
|
function_information = regional_client.get_function(
|
||||||
FunctionName=function.name
|
FunctionName=function.name
|
||||||
)
|
)
|
||||||
code_location_uri = function_information["Code"]["Location"]
|
if "Location" in function_information["Code"]:
|
||||||
raw_code_zip = requests.get(code_location_uri).content
|
code_location_uri = function_information["Code"]["Location"]
|
||||||
self.functions[function.name].code = LambdaCode(
|
raw_code_zip = requests.get(code_location_uri).content
|
||||||
location=code_location_uri,
|
self.functions[function.name].code = LambdaCode(
|
||||||
code_zip=zipfile.ZipFile(io.BytesIO(raw_code_zip)),
|
location=code_location_uri,
|
||||||
)
|
code_zip=zipfile.ZipFile(io.BytesIO(raw_code_zip)),
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|||||||
@@ -97,9 +97,13 @@ class EMR:
|
|||||||
slave_node_security_group = cluster_info["Cluster"][
|
slave_node_security_group = cluster_info["Cluster"][
|
||||||
"Ec2InstanceAttributes"
|
"Ec2InstanceAttributes"
|
||||||
]["EmrManagedSlaveSecurityGroup"]
|
]["EmrManagedSlaveSecurityGroup"]
|
||||||
slave_node_additional_security_groups = cluster_info["Cluster"][
|
if (
|
||||||
"Ec2InstanceAttributes"
|
"AdditionalSlaveSecurityGroups"
|
||||||
]["AdditionalSlaveSecurityGroups"]
|
in cluster_info["Cluster"]["Ec2InstanceAttributes"]
|
||||||
|
):
|
||||||
|
slave_node_additional_security_groups = cluster_info["Cluster"][
|
||||||
|
"Ec2InstanceAttributes"
|
||||||
|
]["AdditionalSlaveSecurityGroups"]
|
||||||
self.clusters[cluster.id].slave = Node(
|
self.clusters[cluster.id].slave = Node(
|
||||||
security_group_id=slave_node_security_group,
|
security_group_id=slave_node_security_group,
|
||||||
additional_security_groups_id=slave_node_additional_security_groups,
|
additional_security_groups_id=slave_node_additional_security_groups,
|
||||||
|
|||||||
Reference in New Issue
Block a user