Skip to content

Commit f9abdc6

Browse files
committed
refactor: set Lambda and Fargate policy in same CF template for GH OIDC
1 parent 16a1370 commit f9abdc6

File tree

2 files changed

+65
-161
lines changed

2 files changed

+65
-161
lines changed

packages/artillery/lib/platform/aws/iam-cf-templates/gh-oidc-lambda.yml

-153
This file was deleted.

packages/artillery/lib/platform/aws/iam-cf-templates/gh-oidc-fargate.yml renamed to packages/artillery/lib/platform/aws/iam-cf-templates/github-oidc.yml

+65-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Description: Creates an ArtilleryGitHubOIDCForFargateRole IAM role with permissions needed to run Artillery Fargate tests from a specified GitHub repository. An OIDC identity provider for Github will also be created if it is not already present in the account.
2+
Description: Sets up IAM resources needed to trigger Artillery distributed tests (on AWS Fargate/Lambda) from a specified GitHub repository. Uses OpenID Connect (OIDC) to authenticate requests from GitHub.
33
Metadata:
44
AWS::CloudFormation::Interface:
55
ParameterGroups:
@@ -19,13 +19,13 @@ Metadata:
1919
GitHubBranch:
2020
default: "GitHub branch"
2121
GitHubOIDCProviderExists:
22-
default: "GitHub OIDC identity provider already created for the account?"
22+
default: "Is GitHub OIDC identity provider already created for the account?"
2323

2424
Parameters:
2525
GitHubRepository:
2626
Type: String
2727
Default: ""
28-
Description: The GitHub repository (orgname/reponame) to be allowed to assume the created IAM role using OIDC (e.g. "artilleryio/artillery").
28+
Description: The GitHub repository ("GitHubOrganizationOrUser/GitHubRepository") to be allowed to assume the created IAM role using OIDC (e.g. "artilleryio/artillery").
2929

3030
GitHubBranch:
3131
Type: String
@@ -38,7 +38,8 @@ Parameters:
3838
AllowedValues:
3939
- 'Yes'
4040
- 'No'
41-
Description: This will let CloudFormation know whether it needs to create the provider. (If it exists, can be found at Services -> IAM -> Identity providers as 'token.actions.githubusercontent.com').
41+
Description: This will let CloudFormation know whether it needs to create the OIDC identity provider for GitHub. (If it exists, can be found at IAM > Identity providers).
42+
4243

4344
Conditions:
4445
IsGHRepoSet:
@@ -56,12 +57,12 @@ Resources:
5657
ClientIdList:
5758
- "sts.amazonaws.com"
5859
ThumbprintList:
59-
- "6938fd4d98bab03faadb97b34396831e3780ee11"
60+
- "6938fd4d98bab03faadb97b34396831e3780aea1"
6061

61-
ArtilleryGitHubOIDCForFargateRole:
62+
ArtilleryGitHubOIDCRole:
6263
Type: "AWS::IAM::Role"
6364
Properties:
64-
RoleName: "ArtilleryGitHubOIDCForFargateRole"
65+
RoleName: "ArtilleryGitHubOIDCRole"
6566
AssumeRolePolicyDocument:
6667
Version: "2012-10-17"
6768
Statement:
@@ -228,12 +229,68 @@ Resources:
228229
- "ec2:DescribeSubnets"
229230
Resource: "*"
230231

232+
- PolicyName: ArtilleryDistributedTestingLambdaPolicy
233+
PolicyDocument:
234+
Version: "2012-10-17"
235+
Statement:
236+
- Sid: CreateOrGetLambdaRole
237+
Effect: Allow
238+
Action:
239+
- iam:CreateRole
240+
- iam:GetRole
241+
- iam:PassRole
242+
- iam:AttachRolePolicy
243+
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/artilleryio-default-lambda-role-*"
244+
- Sid: CreateLambdaPolicy
245+
Effect: Allow
246+
Action:
247+
- iam:CreatePolicy
248+
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/artilleryio-lambda-policy-*"
249+
- Sid: SQSPermissions
250+
Effect: Allow
251+
Action:
252+
- sqs:*
253+
Resource: !Sub "arn:aws:sqs:*:${AWS::AccountId}:artilleryio*"
254+
- Sid: SQSListQueues
255+
Effect: Allow
256+
Action:
257+
- sqs:ListQueues
258+
Resource: "*"
259+
- Sid: LambdaPermissions
260+
Effect: Allow
261+
Action:
262+
- lambda:InvokeFunction
263+
- lambda:CreateFunction
264+
- lambda:DeleteFunction
265+
- lambda:GetFunctionConfiguration
266+
Resource: !Sub "arn:aws:lambda:*:${AWS::AccountId}:function:artilleryio-*"
267+
- Sid: EcrPullImagePermissions
268+
Effect: Allow
269+
Action:
270+
- ecr:GetDownloadUrlForLayer
271+
- ecr:BatchGetImage
272+
Resource: "arn:aws:ecr:*:248481025674:repository/artillery-worker"
273+
- Sid: S3Permissions
274+
Effect: Allow
275+
Action:
276+
- s3:CreateBucket
277+
- s3:DeleteObject
278+
- s3:GetObject
279+
- s3:PutObject
280+
- s3:ListBucket
281+
- s3:GetLifecycleConfiguration
282+
- s3:PutLifecycleConfiguration
283+
Resource:
284+
- !Sub "arn:aws:s3:::artilleryio-test-data-*"
285+
- !Sub "arn:aws:s3:::artilleryio-test-data-*/*"
286+
287+
231288
Outputs:
232289
RoleArn:
233290
Description: "ARN of the created IAM Role"
234291
Value:
235292
Fn::GetAtt:
236-
- "ArtilleryGitHubOIDCForFargateRole"
293+
- "ArtilleryGitHubOIDCRole"
237294
- "Arn"
238295
OIDCProviderArn:
239296
Condition: CreateOIDCProvider

0 commit comments

Comments
 (0)