Skip to content

Commit

Permalink
Configure GitHub Actions user's permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrikandersen committed Jun 27, 2024
1 parent d45e25c commit 420fc63
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions infrastructure/aws/lib/infrastructure-stack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as cdk from 'aws-cdk-lib';
import { IpAddresses, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Repository } from 'aws-cdk-lib/aws-ecr';
import { Policy, User } from 'aws-cdk-lib/aws-iam';
import { Effect, Policy, PolicyStatement, User } from 'aws-cdk-lib/aws-iam';
import { Construct } from 'constructs';

export class InfrastructureStack extends cdk.Stack {
Expand All @@ -24,17 +24,35 @@ export class InfrastructureStack extends cdk.Stack {
const deploymentPolicy = new Policy(this, 'DeploymentPolicy', {
policyName: 'DeploymentPolicy',
statements: [
// TODO: Change!
// ECR permissions
new PolicyStatement({
effect: Effect.ALLOW,
actions: [
"ecr:GetAuthorizationToken",
"ecr:PutImage",
],
resources: [
"*"
],
}),
// ECS permissions
new PolicyStatement({
effect: Effect.ALLOW,
actions: [
"ecs:Describe*",
"ecs:RegisterTaskDefinition",
"ecs:UpdateService",
],
resources: [
"*"
],
}),
],
});

const deploymentUser = new User(this, 'GitHubActionsUser', {
managedPolicies: [
{
managedPolicyArn: 'arn:aws:iam::aws:policy/AdministratorAccess', // TODO: Change!
},
],
});
const deploymentUser = new User(this, 'GitHubActionsUser');

deploymentPolicy.attachToUser(deploymentUser);

deploymentUser.attachInlinePolicy(deploymentPolicy);
}
Expand Down

0 comments on commit 420fc63

Please sign in to comment.