Skip to content

Commit 420fc63

Browse files
committed
Configure GitHub Actions user's permissions
1 parent d45e25c commit 420fc63

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

infrastructure/aws/lib/infrastructure-stack.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as cdk from 'aws-cdk-lib';
22
import { IpAddresses, Vpc } from 'aws-cdk-lib/aws-ec2';
33
import { Repository } from 'aws-cdk-lib/aws-ecr';
4-
import { Policy, User } from 'aws-cdk-lib/aws-iam';
4+
import { Effect, Policy, PolicyStatement, User } from 'aws-cdk-lib/aws-iam';
55
import { Construct } from 'constructs';
66

77
export class InfrastructureStack extends cdk.Stack {
@@ -24,17 +24,35 @@ export class InfrastructureStack extends cdk.Stack {
2424
const deploymentPolicy = new Policy(this, 'DeploymentPolicy', {
2525
policyName: 'DeploymentPolicy',
2626
statements: [
27-
// TODO: Change!
27+
// ECR permissions
28+
new PolicyStatement({
29+
effect: Effect.ALLOW,
30+
actions: [
31+
"ecr:GetAuthorizationToken",
32+
"ecr:PutImage",
33+
],
34+
resources: [
35+
"*"
36+
],
37+
}),
38+
// ECS permissions
39+
new PolicyStatement({
40+
effect: Effect.ALLOW,
41+
actions: [
42+
"ecs:Describe*",
43+
"ecs:RegisterTaskDefinition",
44+
"ecs:UpdateService",
45+
],
46+
resources: [
47+
"*"
48+
],
49+
}),
2850
],
2951
});
3052

31-
const deploymentUser = new User(this, 'GitHubActionsUser', {
32-
managedPolicies: [
33-
{
34-
managedPolicyArn: 'arn:aws:iam::aws:policy/AdministratorAccess', // TODO: Change!
35-
},
36-
],
37-
});
53+
const deploymentUser = new User(this, 'GitHubActionsUser');
54+
55+
deploymentPolicy.attachToUser(deploymentUser);
3856

3957
deploymentUser.attachInlinePolicy(deploymentPolicy);
4058
}

0 commit comments

Comments
 (0)