-
Notifications
You must be signed in to change notification settings - Fork 352
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
Fix: S3 ACL analysis rule for WRITE permissions never triggers #1244
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from cartography.intel.aws.s3 import _load_s3_acls | ||
from cartography.intel.aws.s3 import load_s3_buckets | ||
from cartography.intel.aws.s3 import parse_acl | ||
from tests.data.aws.s3 import LIST_BUCKETS | ||
from tests.data.aws.s3 import OPEN_BUCKET_ACLS | ||
from tests.integration.cartography.intel.aws.iam.test_iam import _create_base_account | ||
from tests.integration.util import check_nodes | ||
|
||
TEST_ACCOUNT_ID = '000000000000' | ||
TEST_REGION = 'us-east-1' | ||
TEST_UPDATE_TAG = 123456789 | ||
|
||
|
||
def test_load_s3_acls(neo4j_session): | ||
""" | ||
Ensure that the S3 ACL that sets anonymous_access and anonymous_actions works. | ||
""" | ||
# Arrange: hackily add s3 data to the test graph | ||
_create_base_account(neo4j_session) | ||
load_s3_buckets(neo4j_session, LIST_BUCKETS, TEST_ACCOUNT_ID, TEST_UPDATE_TAG) | ||
parsed_acls = [] | ||
for bucket_name, acl in OPEN_BUCKET_ACLS.items(): | ||
acl = parse_acl(acl, bucket_name, TEST_ACCOUNT_ID) | ||
if acl: | ||
parsed_acls.extend(acl) | ||
|
||
# Act: run the analysis job | ||
_load_s3_acls(neo4j_session, parsed_acls, TEST_ACCOUNT_ID, TEST_UPDATE_TAG) | ||
|
||
# Assert that the anonymous_access field is set as expected | ||
assert check_nodes(neo4j_session, 'S3Bucket', ['name', 'anonymous_access']) == { | ||
('bucket-1', None), | ||
('bucket-3', True), | ||
('bucket-2', True), | ||
} | ||
|
||
# Assert that we properly set anonymous_actions on the S3Bucket based on the attached S3Acls | ||
# (Can't use check_nodes() here because anonymous_actions is a list and is non-hashable.) | ||
actual = neo4j_session.run( | ||
""" | ||
MATCH (r:S3Bucket) RETURN r.name, r.anonymous_actions; | ||
""", | ||
) | ||
actual_nodes = [ | ||
(n['r.name'], sorted(n['r.anonymous_actions']) if n['r.anonymous_actions'] else []) for n in actual | ||
] | ||
assert sorted(actual_nodes) == [ | ||
('bucket-1', []), | ||
('bucket-2', ['s3:GetBucketAcl', 's3:ListBucket', 's3:ListBucketMultipartUploads', 's3:ListBucketVersions']), | ||
('bucket-3', ['s3:PutBucketAcl', 's3:PutObject']), | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocker: A few weeks ago we had a _check_nodes_as_list in the semgrep test. We could refactor it into tests.integraton.util
https://github.com/lyft/cartography/blob/ef5cbcede534d91df74d2e497cc2958ae548271e/tests/integration/cartography/intel/semgrep/test_findings.py#L19