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): add the default amplify policy to the auto-generated role #29076

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-amplify-alpha/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export interface AppProps {
* The IAM service role to associate with the application. The App
* implements IGrantable.
*
* @default - a new role is created
* @default - a new role is created with the AdministratorAccess-Amplify managed policy attached
*/
readonly role?: iam.IRole;

Expand Down Expand Up @@ -224,6 +224,7 @@ export class App extends Resource implements IApp, iam.IGrantable {

const role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('amplify.amazonaws.com'),
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess-Amplify')],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm down to add common sense permissions to this role, but I balk at the idea of adding this managed policy. We typically don't like adding managed policies to our roles in CDK, and instead opt for fine grained controls (so our users know exactly what policy they are adding.

As always, if you want to use AdministratorAccess-Amplify, you can easily add it in as your role. But I don't want to push that on to everyone.

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 precisely the conversation I wanted to have in the issue before creating a PR :)
I can try to develop a smaller set of permissions, i.e., the minimum required to deploy a basic app. But I might miss some key things I'm not using myself.
The main thing missing for me was permission to talk to the backend to grab the amplify configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense and I'm wary of my initial disdain towards the black box of the managed policy. Just need someone to confirm w me.

});
this.grantPrincipal = role;

Expand All @@ -239,7 +240,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
buildSpec: props.autoBranchCreation.buildSpec && props.autoBranchCreation.buildSpec.toBuildSpec(),
enableAutoBranchCreation: true,
enableAutoBuild: props.autoBranchCreation.autoBuild ?? true,
environmentVariables: Lazy.any({ produce: () => renderEnvironmentVariables(this.autoBranchEnvironmentVariables ) }, { omitEmptyArray: true }), // eslint-disable-line max-len
environmentVariables: Lazy.any({ produce: () => renderEnvironmentVariables(this.autoBranchEnvironmentVariables) }, { omitEmptyArray: true }), // eslint-disable-line max-len
enablePullRequestPreview: props.autoBranchCreation.pullRequestPreview ?? true,
pullRequestEnvironmentName: props.autoBranchCreation.pullRequestEnvironmentName,
stage: props.autoBranchCreation.stage,
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ test('create an app connected to a GitLab repository', () => {
],
Version: '2012-10-17',
},
ManagedPolicyArns: [
{
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::aws:policy/AdministratorAccess-Amplify',
],
],
},
],

});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@
}
],
"Version": "2012-10-17"
}
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/AdministratorAccess-Amplify"
]
]
}
]
}
},
"AppF1B96344": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@
}
],
"Version": "2012-10-17"
}
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/AdministratorAccess-Amplify"
]
]
}
]
}
},
"AppRoleDefaultPolicy9CADBAA1": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@
}
],
"Version": "2012-10-17"
}
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/AdministratorAccess-Amplify"
]
]
}
]
}
},
"AppAppBasicAuthE743F015": {
Expand Down Expand Up @@ -70,6 +84,7 @@
"CustomRules": [
{
"Source": "/source",
"Status": "302",
"Target": "/target"
}
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/test/integ.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class TestStack extends Stack {
amplifyApp.addCustomRule({
source: '/source',
target: '/target',
// NOTE: This is optional according to the API but Cloudformation is breaking without it
// Resource handler returned message: "Invalid request provided: Status field in rewrite custom rules should not be empty
status: amplify.RedirectStatus.TEMPORARY_REDIRECT,
});

const mainBranch = amplifyApp.addBranch('main');
Expand Down
Loading