-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement different ASFF fixing mechanism and other improvements (#88)
* support-trivy-asff-output * better-error-handling-no-credentials * better-error-hanlding * check-tags-in-resource * linter * parse-region-from-resource * comment-function * linter * update-aws-arn * readme-input-asff * readme * check-resource-type * bump-aws-arn * add-Container
- Loading branch information
1 parent
9015216
commit 8509d24
Showing
13 changed files
with
297 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""ResourceType: Container""" | ||
|
||
from botocore.exceptions import ClientError | ||
|
||
from lib.AwsHelpers import get_boto3_client | ||
from lib.context.resources.Base import ContextBase | ||
|
||
|
||
class Metacheck(ContextBase): | ||
def __init__( | ||
self, | ||
logger, | ||
finding, | ||
mh_filters_config, | ||
sess, | ||
drilled=False, | ||
): | ||
self.logger = logger | ||
self.sess = sess | ||
self.mh_filters_config = mh_filters_config | ||
self.parse_finding(finding, drilled) | ||
self.client = get_boto3_client( | ||
self.logger, "ecr-public", self.region, self.sess | ||
) | ||
self.container = self.describe_container() | ||
self.resource_policy = self.get_repository_policy() | ||
|
||
def parse_finding(self, finding, drilled): | ||
self.finding = finding | ||
self.region = finding["Region"] | ||
self.account = finding["AwsAccountId"] | ||
self.partition = finding["Resources"][0]["Id"].split(":")[1] | ||
self.resource_type = finding["Resources"][0]["Type"] | ||
self.resource_arn = finding["Resources"][0]["Id"] | ||
if finding["Resources"][0]["Id"].startswith("arn:aws"): | ||
self.resource_id = finding["Resources"][0]["Id"].split(":")[-1] | ||
elif finding["Resources"][0]["Id"].startswith("public.ecr.aws"): | ||
self.resource_id = finding["Resources"][0]["Id"].split("/")[2].split(":")[0] | ||
|
||
# Describe Functions | ||
def describe_container(self): | ||
try: | ||
response = self.client.describe_repositories( | ||
repositoryNames=[self.resource_id] | ||
) | ||
return response | ||
except ClientError as err: | ||
if not err.response["Error"]["Code"] == "ResourceNotFoundException": | ||
self.logger.error( | ||
"Failed to describe_container {}, {}".format(self.resource_id, err) | ||
) | ||
return False | ||
|
||
# Resource Policy | ||
|
||
def get_repository_policy(self): | ||
if self.container: | ||
try: | ||
response = self.client.get_repository_policy( | ||
repositoryName=self.resource_id | ||
) | ||
return response | ||
except ClientError as err: | ||
if ( | ||
not err.response["Error"]["Code"] | ||
== "RepositoryPolicyNotFoundException" | ||
): | ||
self.logger.error( | ||
"Failed to get_repository_policy {}, {}".format( | ||
self.resource_id, err | ||
) | ||
) | ||
return False | ||
|
||
# Context Config | ||
|
||
def associations(self): | ||
associations = {} | ||
return associations | ||
|
||
def checks(self): | ||
checks = { | ||
"resource_policy": self.resource_policy, | ||
} | ||
return checks |
Oops, something went wrong.