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

fix(amplify-provider-awscloudformation): consolidate REST API policies #6904

Merged
merged 11 commits into from
Apr 19, 2021
Merged

fix(amplify-provider-awscloudformation): consolidate REST API policies #6904

merged 11 commits into from
Apr 19, 2021

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Mar 18, 2021

Issue #, if available: #2084

Description of changes:
This commit updates the REST API IAM policy logic. Instead of using an inline policy per REST API, the logic now combines multiple REST API policies into managed IAM policies.

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

@cjihrig cjihrig requested a review from a team as a code owner March 18, 2021 06:03
@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #6904 (47e65c7) into master (8775152) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6904   +/-   ##
=======================================
  Coverage   56.43%   56.43%           
=======================================
  Files         445      445           
  Lines       21859    21859           
  Branches     4373     4373           
=======================================
  Hits        12336    12336           
  Misses       8745     8745           
  Partials      778      778           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8775152...47e65c7. Read the comment docs.

@cjihrig cjihrig marked this pull request as draft March 23, 2021 22:53
@cjihrig cjihrig marked this pull request as ready for review March 24, 2021 19:40
@akshbhu
Copy link
Contributor

akshbhu commented Mar 25, 2021

Discussed Offline , Some nits Otherwise LGTM!!
Nice job on tests @cjihrig !!

]);
}

function computePolicySizeIncrease(methodLength: number, pathLength: number, nameLength: number): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this compute an increase, or just the new policy size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It computes the increase, and is added to the current policy size on line 122.

// Initial size of 100 for version, statement, etc.
options.policyDocSize = 100 + policySizeIncrease;
options.roleCount++;
options.managedPolicy = createManagedPolicy(this, `${namePrefix}${options.roleCount}`, (roleName as unknown) as string);
Copy link
Contributor

Choose a reason for hiding this comment

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

won't this overwrite the previous policy on each iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only when a new policy needs to be created (either because it's the first iteration, or because the current policy is "full").

type: 'String',
});

const state: ApiGatewayPolicyCreationState = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this need to be outside of the forEach closure below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't strictly need to be. I hoisted it out of that loop to avoid creating a bunch of extra garbage objects. It could be hoisted up even further, but my thought was that the number of API gateways is probably small, but the number of paths could be a good bit larger.

':',
api,
'/',
(cdk.Fn.conditionIf('ShouldNotCreateEnvResources', 'Prod', env) as unknown) as string,
Copy link
Contributor

Choose a reason for hiding this comment

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

why is 'Prod' the default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the current behavior in packages/amplify-category-api/resources/awscloudformation/cloudformation-templates/apigw-cloudformation-template-default.json.ejs.

@cjihrig cjihrig requested a review from attilah April 5, 2021 18:30
Copy link
Contributor

@attilah attilah left a comment

Choose a reason for hiding this comment

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

It looks good in general as we discussed offline, a few points:

  • Check with @renebrandel about the necessity of feature flags based on the scenarios we talked about
  • Remove manual upload code and put the policy stack beside the root stack template, so it will be present in current cloud backend zip
  • It would be nice to only regenerate this stack during push if ANY of the apigw resources are having changes, otherwise no reason to do so

@lgtm-com
Copy link

lgtm-com bot commented Apr 8, 2021

This pull request introduces 1 alert when merging 8f02597 into 3b6298d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@cjihrig cjihrig requested a review from attilah April 12, 2021 14:46
Copy link
Contributor

@attilah attilah 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 making the changes, LGTM, a few nits added.

@edwardfoyle edwardfoyle merged commit 5cfff17 into aws-amplify:master Apr 19, 2021
@cjihrig cjihrig deleted the consolidate branch April 20, 2021 00:33
@github-actions github-actions bot added the referenced-in-release Issues referenced in a published release changelog label Apr 27, 2021
@github-actions
Copy link

👋 Hi, this pull request was referenced in the v4.50.0 release!

Check out the release notes here https://github.com/aws-amplify/amplify-cli/releases/tag/v4.50.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
referenced-in-release Issues referenced in a published release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants