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

IT-1295 #312

Merged
merged 4 commits into from
Jul 2, 2021
Merged

IT-1295 #312

merged 4 commits into from
Jul 2, 2021

Conversation

brucehoff
Copy link
Member

@brucehoff brucehoff commented Jul 2, 2021

This PR modifies the S3 bucket template to meet the requirements listed in IT-1295, i.e.:

  • Can upload from Synapse;
  • Can upload from the S3 console, when logged in as the bucket owner;
  • Cannot upload from a different account without adding the bucket-owner-full-control ACL;
  • CAN upload from a different account with the bucket-owner-full-control ACL. Bucket owner assumes ownership;
  • A different account cannot change the ACL of an object in the bucket.

I created this policy interactively in S3, converted the JSON to YAML and mapped it back into the CFN template. It passes the CloudFormation Linter but we'll have to check it against the UAT bucket to ensure correctness.

There are six statements in the policy:
SynapseBucketAccess - gives Synapse access to the bucket
SynapseObjectAccess - gives Synapse access to objects in the bucket (R/O or R/W)
BucketAccess - gives grantees access to the bucket
ReadObjectAccess - give grantees read access to objects
InternalPutObjectAccess - gives bucket account grantees the ability to upload objects
ExternalPutObjectAccess - gives cross-account grantees the ability to upload objects

Note that the template has a boolean 'AllowWrite'. The *PutObjectAccess statements are conditioned on this boolean.

@brucehoff brucehoff requested a review from zaro0508 July 2, 2021 17:30
@brucehoff brucehoff requested a review from a team as a code owner July 2, 2021 17:30
Copy link
Member

@zaro0508 zaro0508 left a comment

Choose a reason for hiding this comment

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

The policy looks pretty insane now. Would it make sense to add comments to this template describing what the policy is doing?

Comment on lines 206 to 233
- !If
- AllowWrite
- Sid: InternalPutObjectAccess
Effect: Allow
Principal:
AWS: !Ref GrantAccess
Action:
- "s3:PutObject"
- "s3:PutObjectAcl"
Resource: !If [EnableEncryption, !Sub "${SynapseEncryptedExternalBucket.Arn}/*", !Sub "${SynapseExternalBucket.Arn}/*"]
Condition:
StringLike:
"aws:PrincipalArn":
- "arn:aws:iam::055273631518:*"
- "arn:aws:sts::055273631518:assumed-role/*"
- !If
- AllowWrite
- Sid: ExternalPutObjectAccess
Effect: Allow
Principal:
AWS: !Ref GrantAccess
Action:
- "s3:PutObject"
- "s3:PutObjectAcl"
Resource: !If [EnableEncryption, !Sub "${SynapseEncryptedExternalBucket.Arn}/*", !Sub "${SynapseExternalBucket.Arn}/*"]
Condition:
StringEquals:
s3:x-amz-acl: bucket-owner-full-control
Copy link
Member

Choose a reason for hiding this comment

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

these if conditions look wrong. The docs provide example as !If [condition_name, value_if_true, value_if_false] which implies that valid inputs to If condition are 3 strings, not lists. Also you'll need to provide a 3rd parameter to the If construct, in this case i'm thinking you'll want a AWS::NoValue, https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html

Copy link
Member Author

Choose a reason for hiding this comment

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

valid inputs to If condition are 3 strings, not lists

Here's an an example that uses lists:
https://stackoverflow.com/questions/56970457/how-to-use-fnif-with-array-values-in-cloud-formation-templates

There's an example on this page too:
aws/serverless-application-model#1218

There's an example on this page that uses a nested IF in the else clause!
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-sample-templates.html

@brucehoff
Copy link
Member Author

The policy looks pretty insane now. Would it make sense to add comments to this template describing what the policy is doing?

Done!

@brucehoff brucehoff merged commit 3a3c5dc into Sage-Bionetworks:master Jul 2, 2021
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.

2 participants