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_AwsEc2Volume_associations #67

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
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
add_AwsEc2Volume_associations
  • Loading branch information
gabrielsoltz committed Dec 5, 2023
commit fa91a732f2bfa921dab4be1bfc4e02679d9a4404
25 changes: 23 additions & 2 deletions lib/context/resources/AwsEc2Volume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""ResourceType: AwsEc2Volume"""

from aws_arn import generate_arn
from botocore.exceptions import ClientError

from lib.AwsHelpers import get_boto3_client
Expand All @@ -24,7 +25,8 @@ def __init__(
self.volume = self.describe_volumes()
if not self.volume:
return False
# Associated MetaChecks
# Associations
self.instances = self._describe_volumes_instances()

def parse_finding(self, finding, drilled):
self.finding = finding
Expand Down Expand Up @@ -52,6 +54,23 @@ def describe_volumes(self):
)
return False

def _describe_volumes_instances(self):
instances = {}
if self.volume:
for ebs in self.volume:
if ebs.get("Attachments"):
for attachment in ebs.get("Attachments"):
arn = generate_arn(
attachment.get("InstanceId"),
"ec2",
"instance",
self.region,
self.account,
self.partition,
)
instances[arn] = {}
return instances

# Context Config

def encrypted(self):
Expand All @@ -78,7 +97,9 @@ def public(self):
return None

def associations(self):
associations = {}
associations = {
"instances": self.instances,
}
return associations

def checks(self):
Expand Down