From 8e33ec6f04a28691166e7f55175145d119267c36 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Cuchi Date: Fri, 23 Jun 2023 10:42:50 -0300 Subject: [PATCH 1/2] Add flag to skip clean objects --- common.py | 1 + scan.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/common.py b/common.py index bb953fca..e82e5700 100644 --- a/common.py +++ b/common.py @@ -43,6 +43,7 @@ AV_DEFINITION_FILE_PREFIXES = ["main", "daily", "bytecode"] AV_DEFINITION_FILE_SUFFIXES = ["cld", "cvd"] +AV_SKIP_CLEAN_OBJECTS = os.getenv("AV_SKIP_CLEAN_OBJECTS", "False") SNS_ENDPOINT = os.getenv("SNS_ENDPOINT", None) S3_ENDPOINT = os.getenv("S3_ENDPOINT", None) LAMBDA_ENDPOINT = os.getenv("LAMBDA_ENDPOINT", None) diff --git a/scan.py b/scan.py index a28a6e34..3c683d9c 100644 --- a/scan.py +++ b/scan.py @@ -37,6 +37,7 @@ from common import AV_STATUS_SNS_PUBLISH_CLEAN from common import AV_STATUS_SNS_PUBLISH_INFECTED from common import AV_TIMESTAMP_METADATA +from common import AV_SKIP_CLEAN_OBJECTS from common import SNS_ENDPOINT from common import S3_ENDPOINT from common import create_dir @@ -99,6 +100,13 @@ def verify_s3_object_version(s3, s3_object): ) +def is_clean(s3_object): + return ( + str_to_bool(AV_SKIP_CLEAN_OBJECTS) + and s3_object.metadata.get(AV_STATUS_METADATA, None) == AV_STATUS_CLEAN + ) + + def get_local_path(s3_object, local_prefix): return os.path.join(local_prefix, s3_object.bucket_name, s3_object.key) @@ -211,6 +219,10 @@ def lambda_handler(event, context): print("Script starting at %s\n" % (start_time)) s3_object = event_object(event, event_source=EVENT_SOURCE) + if is_clean(s3_object): + print("Object is clean, skipping...") + return + if str_to_bool(AV_PROCESS_ORIGINAL_VERSION_ONLY): verify_s3_object_version(s3, s3_object) From 1a58240d9bc1ff7c812250e958d8cc2955983b21 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Cuchi Date: Wed, 19 Jul 2023 09:44:44 -0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Ryan Delaney <1139517+rpdelaney@users.noreply.github.com> --- common.py | 2 +- scan.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/common.py b/common.py index e82e5700..a762c080 100644 --- a/common.py +++ b/common.py @@ -43,7 +43,7 @@ AV_DEFINITION_FILE_PREFIXES = ["main", "daily", "bytecode"] AV_DEFINITION_FILE_SUFFIXES = ["cld", "cvd"] -AV_SKIP_CLEAN_OBJECTS = os.getenv("AV_SKIP_CLEAN_OBJECTS", "False") +AV_SKIP_CLEAN_OBJECTS = int(os.getenv("AV_SKIP_CLEAN_OBJECTS", "0")) SNS_ENDPOINT = os.getenv("SNS_ENDPOINT", None) S3_ENDPOINT = os.getenv("S3_ENDPOINT", None) LAMBDA_ENDPOINT = os.getenv("LAMBDA_ENDPOINT", None) diff --git a/scan.py b/scan.py index 3c683d9c..518db682 100644 --- a/scan.py +++ b/scan.py @@ -100,13 +100,6 @@ def verify_s3_object_version(s3, s3_object): ) -def is_clean(s3_object): - return ( - str_to_bool(AV_SKIP_CLEAN_OBJECTS) - and s3_object.metadata.get(AV_STATUS_METADATA, None) == AV_STATUS_CLEAN - ) - - def get_local_path(s3_object, local_prefix): return os.path.join(local_prefix, s3_object.bucket_name, s3_object.key) @@ -219,7 +212,10 @@ def lambda_handler(event, context): print("Script starting at %s\n" % (start_time)) s3_object = event_object(event, event_source=EVENT_SOURCE) - if is_clean(s3_object): + if ( + AV_SKIP_CLEAN_OBJECTS + and s3_object.metadata.get(AV_STATUS_METADATA, None) == AV_STATUS_CLEAN + ): print("Object is clean, skipping...") return