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

feat(cloudtrail): accept existing S3 bucket #3680

Merged
merged 18 commits into from
Aug 22, 2019

Conversation

slipdexic
Copy link
Contributor

@slipdexic slipdexic commented Aug 16, 2019

Make CloudTrail accept existing S3 bucket to write to.

Fixes #3651.


Please read the contribution guidelines and follow the pull-request checklist.

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

@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

@aws aws deleted a comment from mergify bot Aug 17, 2019
@aws aws deleted a comment from mergify bot Aug 17, 2019
chore: fixes mergify commenting on check failures (aws#3693)
@rix0rrr rix0rrr self-assigned this Aug 19, 2019
packages/@aws-cdk/aws-cloudtrail/lib/index.ts Outdated Show resolved Hide resolved
StringEquals: {'s3:x-amz-acl': "bucket-owner-full-control"}
}
}));
if (props.s3Bucket === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be made simpler by writing something like:

this.s3bucket = props.bucket || new s3.Bucket(...);

Same as we do for roles all over the place.

Copy link
Contributor Author

@slipdexic slipdexic Aug 20, 2019

Choose a reason for hiding this comment

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

This would then cause the policy to be applied to the bucket , the intent was to not apply the policy . As the bucket is pre-defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rix0rrr I have applied the change as suggested.


this.s3bucket = new s3.Bucket(this, 'S3', {encryption: s3.BucketEncryption.UNENCRYPTED});

this.s3bucket.addToResourcePolicy(new iam.PolicyStatement({
Copy link
Contributor

Choose a reason for hiding this comment

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

To match the behavior of roles, I think we should add to the resource policy, even if a literal bucket is given.

If that is undesired, an adapter for IBucket which drops calls to addToResourcePolicy() can always be written.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of this PR is to allow a bucket with pre-defined policies to be passed in.
I work in sectors that only a the security team can create Policies.

One current use cases for this , is a company may use a central logging bucket or send CT logs to a SOC bucket owned by another company , in these two cases, CDK would not have permissions to apply any policies.

If that is undesired, an adapter for IBucket which drops calls to addToResourcePolicy() can always be written.

I would not know where to start

Copy link
Contributor

Choose a reason for hiding this comment

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

I work in sectors that only a the security team can create Policies.

Yep, and we need a way to address that use case across the entire CDK. You'll have noticed this is not the only situation in which the CDK tries to do "too much" for users in locked-down IAM environments.

In the mean time, I don't think we should have inconsistent behavior across the CDK because the feature author happens to work or not work in a locked-down environment.

I would not know where to start

A rough sketch of it would be something like:

class BucketWrapper implements IBucket {
  constructor(private readonly inner: IBucket) { 
  }

  public get bucketArn()  {
    return this.inner.bucketArn;
  } 

  public urlForObject(key?: string) {
    return this.inner.urlForObject(key);
  }
  
  // ...

  public addToResourcePolicy(statement: iam.PolicyStatement) {
    // Intentionally do nothing
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I will implement your suggestion, I was not aware of using the above suggest pattern to override addToResourcePolicy. We need to make everyone aware in document about this way of handling this type of issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, and we should probably provide a set of these classes out of the box.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wrote up an issue here: #3753

Merge base into fork
Pull latest master info branch
@mergify mergify bot dismissed rix0rrr’s stale review August 20, 2019 16:01

Pull request has been modified.

@slipdexic
Copy link
Contributor Author

@rix0rrr please review again.

@rix0rrr rix0rrr changed the title feat(ec2): cloudtrail accepts existing s3bucket (#3651) feat(cloudtrail): accept existing S3 bucket (#3651) Aug 22, 2019
@rix0rrr rix0rrr changed the title feat(cloudtrail): accept existing S3 bucket (#3651) feat(cloudtrail): accept existing S3 bucket Aug 22, 2019
@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Aug 22, 2019
@rix0rrr rix0rrr merged commit c2d6847 into aws:master Aug 22, 2019
@slipdexic slipdexic deleted the slipdexic/cloudtrail-s3-bucket branch September 9, 2019 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/do-not-merge This PR should not be merged at this time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CloudTrail: Allow external/existing Bucket to be supplied
2 participants