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

Fixes #799: AWS: filter ebs snapshots to just the current account and used snapshots (#793) #799

Merged
merged 9 commits into from
Apr 15, 2022

Conversation

amlweems
Copy link

@amlweems amlweems commented Apr 6, 2022

The describe_snapshots call returns approximately 40k public snapshots which creates extra nodes / relationships and generally causes performances issues with the graph. This PR filters snapshots by OwnerId `"self". This parameter is documented here and returns snapshots owned or explicitly granted to the caller's account.

Co-authored-by: Dallas Kaman <dallas.kaman@praetorian.com>
@ryan-lane
Copy link
Collaborator

I agree with this. It may be good as a followup later to also inspect the graph for EBS snapshots that aren't owned by the account, but are in use, to have fuller coverage.

@ramonpetgrave64
Copy link
Contributor

ramonpetgrave64 commented Apr 7, 2022

@amlweems Thank you!

@ryan-lane Yes, it may be a better idea to filter to also include EBSVolumes -> EBSSnapshots in use by owned EC2Instances
https://github.com/lyft/cartography/blame/21af12527c70c1467cba56d3b44448ff277fd82f/cartography/intel/aws/ec2/instances.py#L380

@kedarghule

@kedarghule
Copy link
Collaborator

@amlweems Thank you!

@ryan-lane Yes, it may be a better idea to filter to also include EBSVolumes -> EBSSnapshots in use by owned EC2Instances https://github.com/lyft/cartography/blame/21af12527c70c1467cba56d3b44448ff277fd82f/cartography/intel/aws/ec2/instances.py#L380

@kedarghule

Yes, this looks good! I agree with @ryan-lane that we could also have a future PR in which we can populate EBS Snapshots not owned by the account but in use.

I'd like @mpurusottamc to take a look at this as well since I had opened the PR for EBS Snapshots during my time at Cloudanix.

Once the CLA check is okay, we can merge!

@ramonpetgrave64
Copy link
Contributor

@kedarghule I disagree, in that this PR should include both owned snapshots and snapshots in use by owned instances. This PR with just the filter for owned snapshots, I think, would be too much of a regression.

@kedarghule
Copy link
Collaborator

@kedarghule I disagree, in that this PR should include both owned snapshots and snapshots in use by owned instances. This PR with just the filter for owned snapshots, I think, would be too much of a regression.

Oh okay. I see your reasoning and I am inclined to agree. I do agree that we should show the snapshots in use by owned instances too.

@mpurusottamc
Copy link
Contributor

@kedarghule This change makes a lot of sense. It was a miss on our side during the initial checkin. Thanks @amlweems for correcting this.

@ramonpetgrave64
Copy link
Contributor

@amlweems Are you able to update this PR to include both owned snapshots and snapshots in use by owned instances?

@amlweems
Copy link
Author

@ramonpetgrave64 Sure thing! I've just pushed a commit that adds a check for snapshots in use and fetches those in addition to any self owned snapshots.

@ramonpetgrave64
Copy link
Contributor

@ramonpetgrave64 Sure thing! I've just pushed a commit that adds a check for snapshots in use and fetches those in addition to any self owned snapshots.

Thank you!
Just a small change needed, since it seems your current fix would fetch the same snapshots twice.
Also, please sign the CLA.

@amlweems
Copy link
Author

@ramonpetgrave64 Thanks for the review! I've made both changes and signed the CLA.

Copy link
Contributor

@ramonpetgrave64 ramonpetgrave64 left a comment

Choose a reason for hiding this comment

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

Looks good. A few smaller comments, but nothing to block. I'll approve for now. Do you want to address my comments before I merge?

cartography/intel/aws/ec2/snapshots.py Outdated Show resolved Hide resolved
@ramonpetgrave64 ramonpetgrave64 removed the request for review from kedarghule April 15, 2022 15:44
@ramonpetgrave64
Copy link
Contributor

Also please update your branch with the latest from the main branch.

@amlweems
Copy link
Author

@ramonpetgrave64 👍 fixed the non-blockers and updated with main

Anthony Weems and others added 2 commits April 15, 2022 11:28
Co-authored-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
@ramonpetgrave64 ramonpetgrave64 merged commit 60ca041 into lyft:master Apr 15, 2022
@ramonpetgrave64 ramonpetgrave64 changed the title filter ebs snapshots to just the current account (#793) Fixes #799: filter ebs snapshots to just the current account (#793) Apr 15, 2022
@ramonpetgrave64 ramonpetgrave64 changed the title Fixes #799: filter ebs snapshots to just the current account (#793) Fixes #799: AWS: filter ebs snapshots to just the current account and used snapshots (#793) Apr 15, 2022
@ramonpetgrave64
Copy link
Contributor

@amlweems Thank you again! Ideas, suggestions, and contributions are always welcome.

@amlweems amlweems deleted the ebs-snapshot-filter branch April 15, 2022 17:05
shinya-murakami-paypay pushed a commit to paypay/cartography that referenced this pull request May 23, 2022
* filter ebs snapshots to just the current account (lyft#793)

Co-authored-by: Dallas Kaman <dallas.kaman@praetorian.com>

* add snapshots_in_use to get_snapshots

* filter duplicate snapshots in get_snapshots

* add integration test for get_snapshots_in_use

* small var name/comment updates

* Update tests/integration/cartography/intel/aws/ec2/test_ec2_snapshots.py

Co-authored-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>

* update from linter

Co-authored-by: Dallas Kaman <dallas.kaman@praetorian.com>
Co-authored-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants