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

Introduce check for IAM actions in share_verify bucket and access points + reapply with list of allowed actions #1407

Merged
merged 6 commits into from
Jul 12, 2024

Conversation

SofiaSazonova
Copy link
Contributor

Feature or Bugfix

  • Bugfix

Detail

  • Share verifier now detects "s3:*" permission as an error
  • Share reapplied with enforced valid actions

Relates

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

  • Does this PR introduce or modify any input fields or queries - this includes
    fetching data from storage outside the application (e.g. a database, an S3 bucket)?
    • Is the input sanitized?
    • What precautions are you taking before deserializing the data you consume?
    • Is injection prevented by parametrizing queries?
    • Have you ensured no eval or similar functions are used?
  • Does this PR introduce any functionality or component that requires authorization?
    • How have you ensured it respects the existing AuthN/AuthZ mechanisms?
    • Are you logging failed auth attempts?
  • Are you using or adding any cryptographic features?
    • Do you use a standard proven implementations?
    • Are the used keys controlled by the customer? Where are they stored?
  • Are you introducing any new policies/roles/users?
    • Have you used the least-privilege principle? How?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@SofiaSazonova SofiaSazonova marked this pull request as ready for review July 11, 2024 16:24
@@ -118,7 +118,7 @@ def check_s3_iam_access(self) -> None:
existing_policy_statement=policy_document['Statement'][s3_statement_index],
):
logger.info(
f'IAM Policy Statement {IAM_S3_BUCKETS_STATEMENT_SID}KMS does not contain resources {s3_target_resources}'
f'IAM Policy Statement {IAM_S3_BUCKETS_STATEMENT_SID}S3 does not contain resources {s3_target_resources}'
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch

Comment on lines 132 to 148
else:
policy_check, missing_policies, extra_policies = share_policy_service.check_s3_actions(
existing_policy_statement=policy_document['Statement'][s3_statement_index]
)
if not policy_check:
logger.info(f'IAM Policy Statement {IAM_S3_BUCKETS_STATEMENT_SID}S3 has invalid actions')
self.bucket_errors.append(
ShareErrorFormatter.invalid_policy_error_msg(
self.target_requester_IAMRoleName,
'IAM Policy Resource',
f'{IAM_S3_BUCKETS_STATEMENT_SID}S3',
'S3 Bucket',
f'{self.bucket_name}',
missing_actions=missing_policies,
extra_actions=extra_policies,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

need to check_s3_actions(...) for folder shares as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Such as with backend/dataall/modules/s3_datasets_shares/services/share_managers/s3_access_point_share_manager.py file in https://github.com/data-dot-all/dataall/pull/1406/files#diff-1d48910db676c4a11b5ff22dcb45a55eb6c31ebd2d9aa1313f90ce4e13b8ecfc

@noah-paige
Copy link
Contributor

noah-paige commented Jul 11, 2024

Test:

  • Verify Share Items from UI --> Shows missing permission and Unhealthy Item if s3:* (For Bucket Only - TODO for Folder!!)
  • Reapply Share Items from UI --> Fixes and removes s3:* for Unhealthy Share Items
  • ECS Verify ALL Share Item Task --> Shows missing permission and Unhealthy Item if s3:* (For Bucket Only - TODO for Folder!!)
  • ECS Reapply ALL Share Item Task --> Fixes and removes s3:* for Unhealthy Share Items

Example Verify Task Detecting s3:* Permissions:
Screenshot 2024-07-11 at 3 08 30 PM

@dlpzx dlpzx changed the title Verify reapply s3 access Introduce check for IAM actions in share_verify bucket and access points + reapply we force only the list of allowed actions Jul 12, 2024
@dlpzx dlpzx changed the title Introduce check for IAM actions in share_verify bucket and access points + reapply we force only the list of allowed actions Introduce check for IAM actions in share_verify bucket and access points + reapply with list of allowed actions Jul 12, 2024
Copy link
Contributor

@petrkalos petrkalos left a comment

Choose a reason for hiding this comment

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

lgtm, I tested it by manually setting s3:* on a folder/share policy and then run the check and the fix and worked fine

Copy link
Contributor

@dlpzx dlpzx 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

@dlpzx dlpzx merged commit 19f7981 into data-dot-all:main Jul 12, 2024
9 checks passed
@SofiaSazonova SofiaSazonova deleted the verify-reapply-s3-access branch September 30, 2024 12:45
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.

4 participants