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: Add Fastly Logs IAM and related constructs #761

Merged
merged 26 commits into from
Jan 10, 2022
Merged

Conversation

frankie297
Copy link
Contributor

What does this change?

Adds an s3 put object construct, and creates a Fastly Logs IAM pattern. This is specifically to allow Fastly to log directly to s3 rather than using keys and having to keep them rotated. See documentation: https://docs.fastly.com/en/guides/creating-an-aws-iam-role-for-fastly-logging

Does this change require changes to existing projects or CDK CLI?

No

Does this change require changes to the library documentation?

Yes

How to test

Snapshot test added

How can we measure success?

Manual key rotation is no longer needed, so less security issues.

Paired with @jfsoul

@frankie297 frankie297 requested a review from a team August 26, 2021 08:53
Copy link
Member

@akash1810 akash1810 left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for the contribution!

I'm not sure how semantic-release will parse these commits as they're not following the angular commit message conventions, I suspect you'll end up needing to squash and merge. There is a beta release channel available if needed.

I'd recommend configuring your IDE to format on save to avoid CI failing on linting errors; you can run npm run lint --fix to fix them.

src/patterns/fastly-logs-iam.ts Outdated Show resolved Hide resolved
src/constructs/core/parameters/fastly.ts Outdated Show resolved Hide resolved
src/patterns/fastly-logs-iam.ts Outdated Show resolved Hide resolved
@jfsoul
Copy link
Contributor

jfsoul commented Sep 3, 2021

@akash1810 we missed the requirement for angular commit messages - have we considered adding a commit hook if that's a pretty strict expectation for contributors?

@akash1810
Copy link
Member

akash1810 commented Sep 6, 2021

@akash1810 we missed the requirement for angular commit messages - have we considered adding a commit hook if that's a pretty strict expectation for contributors?

IIRC we discussed commit hooks in the early days and opted against after experience on other repositories (they're more restrictive than helpful); keen to hear from @jacobwinch and @sihil to see if this still holds.

I'm not too sure how semantic-release will parse this PR, either:

  • It will parse the feat part of the merge commit and release to npm
  • Or it will parse each commit and not deem the change as not needing a release

I'm really interested to find out! Happy to merge as is and we can update any docs to reflect our new learning.

I think a sure fire way to make semantic-release happy is to squash and merge.

akash1810
akash1810 previously approved these changes Sep 6, 2021
Copy link
Member

@akash1810 akash1810 left a comment

Choose a reason for hiding this comment

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

🎉

@jfsoul
Copy link
Contributor

jfsoul commented Sep 6, 2021

I'm really interested to find out! Happy to merge as is and we can update any docs to reflect our new learning.

It's a tempting option to experiment, but I think our commits are not ideal for the history in this case so I was always assuming it'd be a squash and merge for this PR!

@akash1810 akash1810 dismissed their stale review November 10, 2021 08:28

This branch needs rebasing now.

@akash1810
Copy link
Member

A new required status check has been added to this repository, this branch now needs rebasing against main as a result. See #998 (comment).

@jfsoul jfsoul force-pushed the fh-js-cdk-fastly-logs-s3 branch from efb82ed to c493d61 Compare January 7, 2022 10:12
@@ -1,6 +1,7 @@
export interface SsmParameterPath {
path: string;
description: string;
optional?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

The account-readiness CLI command currently expects all these parameters to be required, but actually we're introducing an optional, account-wide parameter here (account-wide because you might have multiple instances of the fastly IAM logging construct in a single account)

| /account/services/artifact.bucket | DistributionBucketName | String | GuGetDistributablePolicy |
| /account/services/logging.stream.name | LoggingStreamName | String | GuLogShippingPolicy |
| /account/services/anghammarad.topic.arn | AnghammaradSnsArn | String | AnghammaradSenderPolicy |
| /account/external/fastly/customer.id | GuFastlyCustomerIdParameter | String | GuFastlyLogsIam |
Copy link
Member

Choose a reason for hiding this comment

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

We should really auto-generate this list!

src/constants/ssm-parameter-paths.ts Outdated Show resolved Hide resolved
const stack = simpleGuStackForTesting();
new GuFastlyLogsIam(stack, "FastlyS3LoggingIam", {
bucketName: "test",
path: "",
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid the empty string at all?

*
* See https://docs.fastly.com/en/guides/creating-an-aws-iam-role-for-fastly-logging
*/
export class GuFastlyLogsIam {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be extend GuRole rather than being a plain class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've made that change, although it doesn't make a whole lot of sense now because I have a policy being created inside a role constructor. I think semantically it was correct before - a construct formed of 2 resources (policy + role) which both used Gu constructs themselves (but the containing construct was its own entity).

Tempted to revert to previous implementation now!

Copy link
Member

Choose a reason for hiding this comment

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

Extending GuRole follows the current convention of the repo, for example the GuInstanceRole. This also makes me realise that this should probably be called GuFastlyLogRole too!

To nitpick a little:

I think semantically it was correct before - a construct formed of 2 resources

This isn't correct as before we had a vanilla class formed of two resources. In CDK there is a Construct class which almost everything extends from 🤯 .

I think generally we'd only create vanilla classes for patterns, rather than constructs - but even then, I think patterns could extend Construct (see this example of a pattern from AWS).

One of the benefits from using the Construct type is you can hook into validate more easily. Additionally any exceptions that you might throw in the constructor of a Construct get pretty printed with a breadcrumb so it's a little easier to debug.

Copy link
Member

@akash1810 akash1810 left a comment

Choose a reason for hiding this comment

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

🎉

});
const policy = new GuPutS3ObjectsPolicy(scope, "GuFastlyLogsIamRolePolicy", {
bucketName: props.bucketName,
paths: props.path ? [props.path] : undefined,
Copy link
Member

@akash1810 akash1810 Jan 7, 2022

Choose a reason for hiding this comment

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

minor: I've recently started to set defaults via destructuring and find it more explicit and easier to follow, e.g.

const { path = "*" } = props;

Not massive, but this method would make the description of path above more true, specifically @default - '*' as at the moment it defaults to undefined, and its GuPutS3ObjectsPolicy that is setting it to * (obviously you can use * in the ternary too).

@jfsoul jfsoul changed the title feat: Add Fastly Logs IAM pattern, and s3 put object construct feat: Add Fastly Logs IAM and related constructs Jan 10, 2022
@jfsoul jfsoul merged commit 5ff8648 into main Jan 10, 2022
@jfsoul jfsoul deleted the fh-js-cdk-fastly-logs-s3 branch January 10, 2022 10:23
@github-actions
Copy link
Contributor

🎉 This PR is included in version 33.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants