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

[aws-s3] Bucket.fromBucketArn does not behave as expected #10638

Closed
jpSimkins opened this issue Oct 1, 2020 · 3 comments
Closed

[aws-s3] Bucket.fromBucketArn does not behave as expected #10638

jpSimkins opened this issue Oct 1, 2020 · 3 comments
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@jpSimkins
Copy link

jpSimkins commented Oct 1, 2020

❓ General Issue

The Question

I am working on a construct, I want to allow a bucket ARN to be used if they prefer. I thought simple enough, we have this:

this.bucket = Bucket.fromBucketArn(this, 'S3ReplicationBucket', props.destionationBucketArn);

The issue I am experiencing is that I want to add a policy to the bucket.

    // Add policy to allow replication to be received
    this.bucket.addToResourcePolicy(
      new PolicyStatement({
        actions: [
          's3:GetBucketVersioning',
          's3:PutBucketVersioning',
          's3:ReplicateObject',
          's3:ReplicateDelete',
          's3:ObjectOwnerOverrideToBucketOwner',
        ],
        principals: [new AccountPrincipal(props.sourceAWSAccountID)],
        resources: [this.bucket.bucketArn, this.bucket.bucketArn + '/*'],
      }),
    );

When I create the bucket, this works as expected. When I am using an ARN, I have an empty template.

This leads me to believe that:
a. Bucket.fromBucketArn cannot be used like a bucket, then what's the point of it?
b. This is a bug

Before I attempt to go the policy route and attach to a bucket (if even possible), e.g.:

Type: AWS::S3::BucketPolicy
Properties: 
  Bucket: String
  PolicyDocument: Json

I wanted to see if this is expected behavior. I for one, find this to be very limiting as this severely limits what I can do with existing resources.

Is it not possible to attach bucket policies this way? If not, is there a concern for policies being removed this way? Just trying to understand why this doesn't work and what the correct approach would be.

My only other option would be to remove support for bucketArn but this has me worried about other constructs I plan to write as this is something I can see being necessary.

Environment

@jpSimkins jpSimkins added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Oct 1, 2020
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Oct 1, 2020
@iliapolo
Copy link
Contributor

iliapolo commented Oct 8, 2020

Hi @jpSimkins - Indeed this is a bug. See #6548 for more details.

Bucket.fromBucketArn cannot be used like a bucket, then what's the point of it?

IBucket has a few additional API's that can take affect on imported buckets (grant* methods). It also has a few utility functions and can be used as a type safe reference for other API's that work with buckets.

@iliapolo iliapolo added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 8, 2020
@jpSimkins
Copy link
Author

Thank you @iliapolo, I will close this ticket and +1 that ticket.

@github-actions
Copy link

github-actions bot commented Oct 9, 2020

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants