-
Notifications
You must be signed in to change notification settings - Fork 820
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: fix appsync permission assignment from functions #5342
fix: fix appsync permission assignment from functions #5342
Conversation
PHAL @aws-amplify/amplify-cli (@kaustavghosh06 @renebrandel @UnleashedMind @yuth @attilah) |
Codecov Report
@@ Coverage Diff @@
## master #5342 +/- ##
========================================
Coverage 57.05% 57.05%
========================================
Files 468 468
Lines 21489 21490 +1
Branches 4273 4058 -215
========================================
+ Hits 12261 12262 +1
- Misses 8349 8369 +20
+ Partials 879 859 -20
Continue to review full report at Codecov.
|
hi @r0zar ! I'll try to get the team to review it on Friday. Thanks for starting this! |
@renebrandel 👋 Completed my final updates. This PR is ready for merging now AFAIK |
@attilah will test this PR and see if we need to introduce a feature flag. At this point it looks good. |
@r0zar Thanks for the PR, I went through it and I see the reason for the changes, but because of existing deployments we have to preserve the existing functionality so it needs to be put behind a feature flag that can be enabled by default for new projects and not for existing projects. I have one concern about the generated IAM policy and that is that I can't see that the policy generation code includes the schema types. If I remember correctly you have to have access to the types as well, since if I have a policy for Since this change has to go behind a feature flag we don't have to deal with the legacy permissions especially we don't have to map it. If you need further help on the above suggested changes, ping me and I we can setup a meeting to get it through the finish line. |
Thanks for the review. Yeah let's find some time next week so I get aligned on this and put together a todo list. |
@r0zar sounds good, please test out the |
Synced up offline with @r0zar will add the E2E tests and the Feature flag to preserve the existing functionality and will update the PR. |
@r0zar how you see your time working on this, do you have an ETA (no rush) ? |
I finally had some time open up this week and was going to make a start on it. Hopefully I can knock it out in a few sessions. |
@r0zar let me know if I can be any help. |
Ran a rebase to keep my changes. |
01337da
to
8810503
Compare
Ok, fixed the terrible rebase. 😅 |
packages/amplify-category-function/src/provider-utils/awscloudformation/utils/constants.ts
Outdated
Show resolved
Hide resolved
This pull request introduces 3 alerts when merging 1c4309c into a7b7a8c - view on LGTM.com new alerts:
|
🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments on the recent changes, but overall almost there!
import path from 'path'; | ||
import * as TransformPackage from 'graphql-transformer-core'; | ||
import _ from 'lodash'; | ||
import { topLevelCommentPrefix, topLevelCommentSuffix, envVarPrintoutPrefix, CRUDOperation } from '../../../constants'; | ||
import _, { get, capitalize, concat, isEmpty } from 'lodash'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use import _ from 'lodash';
and don't deconstruct its functions, it's more readable that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
@@ -60,7 +60,7 @@ export async function createWalkthrough( | |||
// list out the advanced settings before asking whether to configure them | |||
context.print.info(''); | |||
context.print.success('Available advanced settings:'); | |||
advancedSettingsList.forEach(setting => context.print.info('- '.concat(setting))); | |||
advancedSettingsList.forEach(setting => context.print.info(setting)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removed the '-' prefix? We rarely change prompts and DX without API reviews. Sync up on this with @renebrandel .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -
served as a pseudo-bullet-point in the unordered list of choices. I replaced that with the icons in the PR. It results in a more visually comprehensible list of choices that can be understood better internationally.
packages/amplify-category-function/src/provider-utils/awscloudformation/utils/constants.ts
Outdated
Show resolved
Hide resolved
import _ from 'lodash'; | ||
|
||
const featureFlagPR5342 = () => FeatureFlags.getBoolean('useAppSyncPermissionsInLambdaPolicies') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just name it normally as a variable, no need for GH reference, also FeatureFlags has a ., I'd suggest to use appSync
.generateGraphQLPermissionsForCRUD
since this feature flag is not for graphqlTransformer
. We can debate the name but this is what it does IMHO, suggest something similar if you have a better in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you feel about the category being iamPolicies
? This distinction would be helpful to make clear it's related to how the policies are generated and managed.
const permissions = _.get(permissionMap, [category, resourceName], []); | ||
// If AppSync and legacy CRUD permissions BUT they opted into the feature flag, update policy. | ||
if (serviceType == 'AppSync' && hasCRUDPermissions(permissions) && featureFlagPR5342()) { | ||
return updatePermissionsForBackwardsCompatibility(permissionMap, category, resourceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the FF branch of the if doing anything that is backward compatible? It should not, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote it so that enabling a feature flag with incorrect permissions would autocorrect their policies. I now see that the way feature flags are being used in amplify is that by turning them on early, the user may deals with the consequences. I see this results in code with less 'artifacts' so I'll update to fit this design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the FF check to line 102 of execPermissionsWalkthrough.ts
. Still exists as an artifact in the code, but there is no more autocorrecting of permissions. Is this the intention?
@@ -504,6 +504,12 @@ export class FeatureFlags { | |||
defaultValueForExistingProjects: false, | |||
defaultValueForNewProjects: false, | |||
}, | |||
{ | |||
name: 'useAppSyncPermissionsInLambdaPolicies', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As suggested above it should go into a new appSync
group.
This pull request introduces 1 alert when merging c3b406d into 206ab32 - view on LGTM.com new alerts:
|
c3b406d
to
24aa3b0
Compare
I squashed and force pushed the commit with only the relevant changes to keep the scope a little tighter. |
@@ -25,32 +26,31 @@ export const askExecRolePermissionsQuestions = async ( | |||
category?: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value seems to be coming in as undefined for most scenarios. Is it still used?
4f8ce5a
to
e8b97a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for hanging in there ;-)
Fixes test introduced by aws-amplify#5342
Fixes test introduced by aws-amplify#5342
Fixes test introduced by #5342
This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
fix #4306
Issue #, if available:
4306
Description of changes:
The current implementation of appsync permissions is using an incorrect understanding of IAM policies for AppSync. This PR updates the IAM Policy generation process for lambdas from
amplify function create/update
walkthroughs.This PR is ready for merging. 🚀
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.