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

Add flag to skip clean objects #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AV_SKIP_CLEAN_OBJECTS = os.getenv("AV_SKIP_CLEAN_OBJECTS", "False")
AV_SKIP_CLEAN_OBJECTS = int(os.getenv("AV_SKIP_CLEAN_OBJECTS", "0"))

"False" is truthy. This should make it more difficult to accidentally set a truthy value. I'm definitely open to other approaches though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"False" would still return 0 in this case:
image

But I have no problems with changing the env.
Just keep in mind that it would only accept numeric values, and a "False" or "True" would raise instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python, str_to_bool isn't a built-in. Where are you getting that defined?

SNS_ENDPOINT = os.getenv("SNS_ENDPOINT", None)
S3_ENDPOINT = os.getenv("S3_ENDPOINT", None)
LAMBDA_ENDPOINT = os.getenv("LAMBDA_ENDPOINT", None)
Expand Down
12 changes: 12 additions & 0 deletions scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)


cuchi marked this conversation as resolved.
Show resolved Hide resolved
def get_local_path(s3_object, local_prefix):
return os.path.join(local_prefix, s3_object.bucket_name, s3_object.key)

Expand Down Expand Up @@ -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

cuchi marked this conversation as resolved.
Show resolved Hide resolved
if str_to_bool(AV_PROCESS_ORIGINAL_VERSION_ONLY):
verify_s3_object_version(s3, s3_object)

Expand Down