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

Enable versioning and server access logging for ArtifactBucket #396

Merged
merged 1 commit into from
Mar 13, 2020

Conversation

knassef
Copy link
Contributor

@knassef knassef commented Feb 19, 2020

Description of changes: For security reasons;

  • Created new bucket AccessLogsBucket to store s3 server access logs of ArtifactBucket
  • Enabled versioning in both buckets (ArtifactBucket and AccessLogsBucket)
  • Set LifecycleConfiguration to maximum value

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

@rjlohan
Copy link
Contributor

rjlohan commented Feb 25, 2020

Thanks for this contribution, this is a nice improvement. 👍

@benbridts
Copy link
Contributor

@knassef I promise I didn't set out to nitpick every line of this. There's nothing wrong with the template in general, but I have a tendency to keep asking questions

@knassef
Copy link
Contributor Author

knassef commented Feb 25, 2020

@ikben ah no worries at all, we are having a reasonable conversation here, trying to understand pros and cons of different approaches. so all good :)

@rjlohan rjlohan self-requested a review February 25, 2020 16:22
@knassef
Copy link
Contributor Author

knassef commented Feb 26, 2020

@jotompki yes, my team is using this approach with all S3 bucket as we have a hard security requirement to log all s3 buckets (with no exceptions). AFAIK CloudTrail also dumps logs into an s3 bucket so we will face the same issue with that approach as well. I have addressed the other comments and now DestinationBucketName is an optional parameter and logging will only be enabled if it was passed. Do you think we can come to an agreement on this?

@knassef
Copy link
Contributor Author

knassef commented Mar 3, 2020

would appreciate any response regarding my last comment :)

Condition: CreateLogBucket
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref DestinationBucketName
Copy link
Contributor

Choose a reason for hiding this comment

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

so if we create the bucket, we set a bucket name of "" that logs to ""? That will throw some validation errors on the CloudFormation end.

I'm all for adding an access logs bucket just don't think it is necessary for the logs bucket to log to itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

AccessLogsBucket | CREATE_FAILED | Property BucketName cannot be empty if specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check #396 (comment)

Copy link
Contributor

@PatMyron PatMyron left a comment

Choose a reason for hiding this comment

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

This fails to successfully create any CloudFormation stack regardless if the DestinationBucketName parameter is specified or not. Even after negating the CreateLogBucket condition, this template still fails to successfully create a CloudFormation stack if the DestinationBucketName parameter is not specified

@knassef please test not only that these CloudFormation stacks successfully deploy but also the desired behavior of both specifying DestinationBucketName and not specifying DestinationBucketName

This bucket should also enforce secure transport: #389

Type: String
Default: ""
Conditions:
CreateLogBucket: !Equals [!Ref DestinationBucketName, ""]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CreateLogBucket: !Equals [!Ref DestinationBucketName, ""]
CreateLogBucket: !Not [!Equals [!Ref DestinationBucketName, ""]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check #396 (comment)

Comment on lines 32 to 26
LoggingConfiguration:
DestinationBucketName: !If [CreateLogBucket, !Ref AccessLogsBucket, !Ref DestinationBucketName]
LogFilePrefix: ArtifactBucket
Copy link
Contributor

Choose a reason for hiding this comment

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

ArtifactBucket | CREATE_FAILED | The target bucket for logging does not exist (Service: Amazon S3; Status Code: 400; Error Code: InvalidTargetBucketForLogging)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check #396 (comment)

Condition: CreateLogBucket
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref DestinationBucketName
Copy link
Contributor

Choose a reason for hiding this comment

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

AccessLogsBucket | CREATE_FAILED | Property BucketName cannot be empty if specified.

Comment on lines 7 to 10
DestinationBucketName:
Description: Set this if you want to write access logs to a bucket you manage
Type: String
Default: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DestinationBucketName:
Description: Set this if you want to write access logs to a bucket you manage
Type: String
Default: ""
DestinationBucketName:
Description: Set this if you want to write access logs to a bucket you manage
Type: String
Default: ""
AllowedPattern: "^[a-z0-9.-]*$"

We can't be as strict as the AWS::S3::Bucket.BucketName AllowedPattern because of the empty default, but we can at least constrain with some AllowedPattern to prevent invalid S3 bucket name characters

Copy link
Contributor

Choose a reason for hiding this comment

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

Quick AllowedPattern note:^[a-z0-9][a-z0-9.-]*[a-z0-9]$|^$ should catch both cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check #396 (comment)

@knassef
Copy link
Contributor Author

knassef commented Mar 13, 2020

To unblock this, I have removed the self logging of the logs bucket to keep things simple for this PR as I see its not the general use case and I will try to think of another way to keep it optional without complicating the template.

Copy link
Contributor

@rjlohan rjlohan left a comment

Choose a reason for hiding this comment

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

Thanks for taking the effort on this, especially with all the rework you did!

@johnttompkins johnttompkins requested a review from PatMyron March 13, 2020 16:53
@rjlohan rjlohan merged commit e98d730 into aws-cloudformation:master Mar 13, 2020
@knassef
Copy link
Contributor Author

knassef commented Mar 16, 2020

Thank you as well everyone! 🙏

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.

5 participants