@depup/artillery 2.0.30-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +63 -0
  2. package/bin/run +29 -0
  3. package/bin/run.cmd +3 -0
  4. package/changes.json +138 -0
  5. package/console-reporter.js +1 -0
  6. package/lib/artillery-global.js +33 -0
  7. package/lib/cli/banner.js +8 -0
  8. package/lib/cli/common-flags.js +80 -0
  9. package/lib/cli/hooks/version.js +20 -0
  10. package/lib/cmds/dino.js +109 -0
  11. package/lib/cmds/quick.js +122 -0
  12. package/lib/cmds/report.js +34 -0
  13. package/lib/cmds/run-aci.js +91 -0
  14. package/lib/cmds/run-fargate.js +192 -0
  15. package/lib/cmds/run-lambda.js +96 -0
  16. package/lib/cmds/run.js +671 -0
  17. package/lib/console-capture.js +92 -0
  18. package/lib/console-reporter.js +438 -0
  19. package/lib/create-bom/built-in-plugins.js +12 -0
  20. package/lib/create-bom/create-bom.js +301 -0
  21. package/lib/dispatcher.js +9 -0
  22. package/lib/dist.js +222 -0
  23. package/lib/index.js +5 -0
  24. package/lib/launch-platform.js +439 -0
  25. package/lib/load-plugins.js +113 -0
  26. package/lib/platform/aws/aws-cloudwatch.js +106 -0
  27. package/lib/platform/aws/aws-create-sqs-queue.js +58 -0
  28. package/lib/platform/aws/aws-ensure-s3-bucket-exists.js +78 -0
  29. package/lib/platform/aws/aws-get-account-id.js +26 -0
  30. package/lib/platform/aws/aws-get-bucket-region.js +18 -0
  31. package/lib/platform/aws/aws-get-credentials.js +28 -0
  32. package/lib/platform/aws/aws-get-default-region.js +26 -0
  33. package/lib/platform/aws/aws-whoami.js +15 -0
  34. package/lib/platform/aws/constants.js +7 -0
  35. package/lib/platform/aws/iam-cf-templates/aws-iam-fargate-cf-template.yml +219 -0
  36. package/lib/platform/aws/iam-cf-templates/aws-iam-lambda-cf-template.yml +125 -0
  37. package/lib/platform/aws/iam-cf-templates/gh-oidc-fargate.yml +241 -0
  38. package/lib/platform/aws/iam-cf-templates/gh-oidc-lambda.yml +153 -0
  39. package/lib/platform/aws-ecs/ecs.js +247 -0
  40. package/lib/platform/aws-ecs/legacy/aws-util.js +134 -0
  41. package/lib/platform/aws-ecs/legacy/bom.js +528 -0
  42. package/lib/platform/aws-ecs/legacy/constants.js +27 -0
  43. package/lib/platform/aws-ecs/legacy/create-s3-client.js +24 -0
  44. package/lib/platform/aws-ecs/legacy/create-test.js +247 -0
  45. package/lib/platform/aws-ecs/legacy/errors.js +34 -0
  46. package/lib/platform/aws-ecs/legacy/find-public-subnets.js +149 -0
  47. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-inspect-script/index.js +27 -0
  48. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-sqs-reporter/azure-aqs.js +80 -0
  49. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-sqs-reporter/index.js +202 -0
  50. package/lib/platform/aws-ecs/legacy/plugins.js +16 -0
  51. package/lib/platform/aws-ecs/legacy/run-cluster.js +1994 -0
  52. package/lib/platform/aws-ecs/legacy/sqs-reporter.js +401 -0
  53. package/lib/platform/aws-ecs/legacy/tags.js +22 -0
  54. package/lib/platform/aws-ecs/legacy/test-run-status.js +9 -0
  55. package/lib/platform/aws-ecs/legacy/time.js +67 -0
  56. package/lib/platform/aws-ecs/legacy/util.js +97 -0
  57. package/lib/platform/aws-ecs/worker/Dockerfile +64 -0
  58. package/lib/platform/aws-ecs/worker/helpers.sh +80 -0
  59. package/lib/platform/aws-ecs/worker/loadgen-worker +656 -0
  60. package/lib/platform/aws-lambda/dependencies.js +130 -0
  61. package/lib/platform/aws-lambda/index.js +734 -0
  62. package/lib/platform/aws-lambda/lambda-handler/a9-handler-dependencies.js +73 -0
  63. package/lib/platform/aws-lambda/lambda-handler/a9-handler-helpers.js +43 -0
  64. package/lib/platform/aws-lambda/lambda-handler/a9-handler-index.js +235 -0
  65. package/lib/platform/aws-lambda/lambda-handler/package.json +15 -0
  66. package/lib/platform/aws-lambda/prices.js +29 -0
  67. package/lib/platform/az/aci.js +694 -0
  68. package/lib/platform/az/aqs-queue-consumer.js +88 -0
  69. package/lib/platform/az/regions.js +52 -0
  70. package/lib/platform/cloud/api.js +72 -0
  71. package/lib/platform/cloud/cloud.js +448 -0
  72. package/lib/platform/cloud/http-client.js +19 -0
  73. package/lib/platform/local/artillery-worker-local.js +154 -0
  74. package/lib/platform/local/index.js +174 -0
  75. package/lib/platform/local/worker.js +261 -0
  76. package/lib/platform/worker-states.js +13 -0
  77. package/lib/queue-consumer/index.js +56 -0
  78. package/lib/stash.js +41 -0
  79. package/lib/telemetry.js +78 -0
  80. package/lib/util/await-on-ee.js +24 -0
  81. package/lib/util/generate-id.js +9 -0
  82. package/lib/util/parse-tag-string.js +21 -0
  83. package/lib/util/prepare-test-execution-plan.js +216 -0
  84. package/lib/util/sleep.js +7 -0
  85. package/lib/util/validate-script.js +132 -0
  86. package/lib/util.js +294 -0
  87. package/lib/utils-config.js +31 -0
  88. package/package.json +323 -0
  89. package/types.d.ts +317 -0
  90. package/util.js +1 -0
@@ -0,0 +1,241 @@
1
+ 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.
3
+ Metadata:
4
+ AWS::CloudFormation::Interface:
5
+ ParameterGroups:
6
+ - Label:
7
+ default: "GitHub"
8
+ Parameters:
9
+ - GitHubRepository
10
+ - GitHubBranch
11
+ - Label:
12
+ default: "AWS IAM"
13
+ Parameters:
14
+ - GitHubOIDCProviderExists
15
+
16
+ ParameterLabels:
17
+ GitHubRepository:
18
+ default: "GitHub repository"
19
+ GitHubBranch:
20
+ default: "GitHub branch"
21
+ GitHubOIDCProviderExists:
22
+ default: "GitHub OIDC identity provider already created for the account?"
23
+
24
+ Parameters:
25
+ GitHubRepository:
26
+ Type: String
27
+ Default: ""
28
+ Description: The GitHub repository (orgname/reponame) to be allowed to assume the created IAM role using OIDC (e.g. "artilleryio/artillery").
29
+
30
+ GitHubBranch:
31
+ Type: String
32
+ Default: "*"
33
+ Description: (Optional) Use when you want to allow only a specific branch within the specified Github repository to assume this IAM role using OIDC (e.g. "main"). If not set, defaults to "*" (all branches).
34
+
35
+ GitHubOIDCProviderExists:
36
+ Type: String
37
+ Default: 'No'
38
+ AllowedValues:
39
+ - 'Yes'
40
+ - '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').
42
+
43
+ Conditions:
44
+ IsGHRepoSet:
45
+ !Not [!Equals [!Ref GitHubRepository, ""]]
46
+
47
+ CreateOIDCProvider:
48
+ !Equals [!Ref GitHubOIDCProviderExists, "No"]
49
+
50
+ Resources:
51
+ GitHubOIDCProvider:
52
+ Type: AWS::IAM::OIDCProvider
53
+ Condition: CreateOIDCProvider
54
+ Properties:
55
+ Url: "https://token.actions.githubusercontent.com"
56
+ ClientIdList:
57
+ - "sts.amazonaws.com"
58
+ ThumbprintList:
59
+ - "6938fd4d98bab03faadb97b34396831e3780ee11"
60
+
61
+ ArtilleryGitHubOIDCForFargateRole:
62
+ Type: "AWS::IAM::Role"
63
+ Properties:
64
+ RoleName: "ArtilleryGitHubOIDCForFargateRole"
65
+ AssumeRolePolicyDocument:
66
+ Version: "2012-10-17"
67
+ Statement:
68
+ - Effect: "Allow"
69
+ Principal:
70
+ Federated:
71
+ Fn::If:
72
+ - CreateOIDCProvider
73
+ - !Ref GitHubOIDCProvider
74
+ - !Sub "arn:aws:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com"
75
+ Action: "sts:AssumeRoleWithWebIdentity"
76
+ Condition: {
77
+ StringEquals:
78
+ {
79
+ "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
80
+ },
81
+ StringLike:
82
+ {
83
+ "token.actions.githubusercontent.com:sub": !Sub "repo:${GitHubRepository}:${GitHubBranch}"
84
+ }
85
+ }
86
+ Path: "/"
87
+ Policies:
88
+ - PolicyName: "ArtilleryGitHubOIDCForFargatePolicy"
89
+ PolicyDocument:
90
+ Version: "2012-10-17"
91
+ Statement:
92
+ - Sid: "CreateOrGetECSRole"
93
+ Effect: "Allow"
94
+ Action:
95
+ - "iam:CreateRole"
96
+ - "iam:GetRole"
97
+ - "iam:AttachRolePolicy"
98
+ - "iam:PassRole"
99
+ Resource:
100
+ Fn::Sub: "arn:aws:iam::${AWS::AccountId}:role/artilleryio-ecs-worker-role"
101
+ - Sid: "CreateECSPolicy"
102
+ Effect: "Allow"
103
+ Action:
104
+ - "iam:CreatePolicy"
105
+ Resource:
106
+ Fn::Sub: "arn:aws:iam::${AWS::AccountId}:policy/artilleryio-ecs-worker-policy"
107
+ - Effect: "Allow"
108
+ Action:
109
+ - "iam:CreateServiceLinkedRole"
110
+ Resource:
111
+ - "arn:aws:iam::*:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS*"
112
+ Condition:
113
+ StringLike:
114
+ iam:AWSServiceName: "ecs.amazonaws.com"
115
+ - Effect: "Allow"
116
+ Action:
117
+ - "iam:PassRole"
118
+ Resource:
119
+ - Fn::Sub: "arn:aws:iam::${AWS::AccountId}:role/artilleryio-ecs-worker-role"
120
+ - Sid: "SQSPermissions"
121
+ Effect: "Allow"
122
+ Action:
123
+ - "sqs:*"
124
+ Resource:
125
+ Fn::Sub: "arn:aws:sqs:*:${AWS::AccountId}:artilleryio*"
126
+ - Sid: "SQSListQueues"
127
+ Effect: "Allow"
128
+ Action:
129
+ - "sqs:ListQueues"
130
+ Resource: "*"
131
+ - Sid: "ECSPermissionsGeneral"
132
+ Effect: "Allow"
133
+ Action:
134
+ - "ecs:ListClusters"
135
+ - "ecs:CreateCluster"
136
+ - "ecs:RegisterTaskDefinition"
137
+ - "ecs:DeregisterTaskDefinition"
138
+ Resource: "*"
139
+ - Sid: "ECSPermissionsScopedToCluster"
140
+ Effect: "Allow"
141
+ Action:
142
+ - "ecs:DescribeClusters"
143
+ - "ecs:ListContainerInstances"
144
+ Resource:
145
+ Fn::Sub: "arn:aws:ecs:*:${AWS::AccountId}:cluster/*"
146
+ - Sid: "ECSPermissionsScopedWithCondition"
147
+ Effect: "Allow"
148
+ Action:
149
+ - "ecs:SubmitTaskStateChange"
150
+ - "ecs:DescribeTasks"
151
+ - "ecs:ListTasks"
152
+ - "ecs:ListTaskDefinitions"
153
+ - "ecs:DescribeTaskDefinition"
154
+ - "ecs:StartTask"
155
+ - "ecs:StopTask"
156
+ - "ecs:RunTask"
157
+ Condition:
158
+ ArnEquals:
159
+ ecs:cluster:
160
+ Fn::Sub: "arn:aws:ecs:*:${AWS::AccountId}:cluster/*"
161
+ Resource: "*"
162
+ - Sid: "S3Permissions"
163
+ Effect: "Allow"
164
+ Action:
165
+ - "s3:CreateBucket"
166
+ - "s3:DeleteObject"
167
+ - "s3:GetObject"
168
+ - "s3:GetObjectAcl"
169
+ - "s3:GetObjectTagging"
170
+ - "s3:GetObjectVersion"
171
+ - "s3:PutObject"
172
+ - "s3:PutObjectAcl"
173
+ - "s3:ListBucket"
174
+ - "s3:GetBucketLocation"
175
+ - "s3:GetBucketLogging"
176
+ - "s3:GetBucketPolicy"
177
+ - "s3:GetBucketTagging"
178
+ - "s3:PutBucketPolicy"
179
+ - "s3:PutBucketTagging"
180
+ - "s3:PutMetricsConfiguration"
181
+ - "s3:GetLifecycleConfiguration"
182
+ - "s3:PutLifecycleConfiguration"
183
+ Resource:
184
+ - "arn:aws:s3:::artilleryio-test-data-*"
185
+ - "arn:aws:s3:::artilleryio-test-data-*/*"
186
+ - Sid: "LogsPermissions"
187
+ Effect: "Allow"
188
+ Action:
189
+ - "logs:PutRetentionPolicy"
190
+ Resource:
191
+ - Fn::Sub: "arn:aws:logs:*:${AWS::AccountId}:log-group:artilleryio-log-group/*"
192
+ - Effect: "Allow"
193
+ Action:
194
+ - "secretsmanager:GetSecretValue"
195
+ Resource:
196
+ - Fn::Sub: "arn:aws:secretsmanager:*:${AWS::AccountId}:secret:artilleryio/*"
197
+ - Effect: "Allow"
198
+ Action:
199
+ - "ssm:PutParameter"
200
+ - "ssm:GetParameter"
201
+ - "ssm:GetParameters"
202
+ - "ssm:DeleteParameter"
203
+ - "ssm:DescribeParameters"
204
+ - "ssm:GetParametersByPath"
205
+ Resource:
206
+ - Fn::Sub: "arn:aws:ssm:us-east-1:${AWS::AccountId}:parameter/artilleryio/*"
207
+ - Fn::Sub: "arn:aws:ssm:us-east-2:${AWS::AccountId}:parameter/artilleryio/*"
208
+ - Fn::Sub: "arn:aws:ssm:us-west-1:${AWS::AccountId}:parameter/artilleryio/*"
209
+ - Fn::Sub: "arn:aws:ssm:us-west-2:${AWS::AccountId}:parameter/artilleryio/*"
210
+ - Fn::Sub: "arn:aws:ssm:ca-central-1:${AWS::AccountId}:parameter/artilleryio/*"
211
+ - Fn::Sub: "arn:aws:ssm:eu-west-1:${AWS::AccountId}:parameter/artilleryio/*"
212
+ - Fn::Sub: "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/artilleryio/*"
213
+ - Fn::Sub: "arn:aws:ssm:eu-west-3:${AWS::AccountId}:parameter/artilleryio/*"
214
+ - Fn::Sub: "arn:aws:ssm:eu-central-1:${AWS::AccountId}:parameter/artilleryio/*"
215
+ - Fn::Sub: "arn:aws:ssm:eu-north-1:${AWS::AccountId}:parameter/artilleryio/*"
216
+ - Fn::Sub: "arn:aws:ssm:ap-south-1:${AWS::AccountId}:parameter/artilleryio/*"
217
+ - Fn::Sub: "arn:aws:ssm:ap-east-1:${AWS::AccountId}:parameter/artilleryio/*"
218
+ - Fn::Sub: "arn:aws:ssm:ap-northeast-1:${AWS::AccountId}:parameter/artilleryio/*"
219
+ - Fn::Sub: "arn:aws:ssm:ap-northeast-2:${AWS::AccountId}:parameter/artilleryio/*"
220
+ - Fn::Sub: "arn:aws:ssm:ap-southeast-1:${AWS::AccountId}:parameter/artilleryio/*"
221
+ - Fn::Sub: "arn:aws:ssm:ap-southeast-2:${AWS::AccountId}:parameter/artilleryio/*"
222
+ - Fn::Sub: "arn:aws:ssm:me-south-1:${AWS::AccountId}:parameter/artilleryio/*"
223
+ - Fn::Sub: "arn:aws:ssm:sa-east-1:${AWS::AccountId}:parameter/artilleryio/*"
224
+ - Effect: "Allow"
225
+ Action:
226
+ - "ec2:DescribeRouteTables"
227
+ - "ec2:DescribeVpcs"
228
+ - "ec2:DescribeSubnets"
229
+ Resource: "*"
230
+
231
+ Outputs:
232
+ RoleArn:
233
+ Description: "ARN of the created IAM Role"
234
+ Value:
235
+ Fn::GetAtt:
236
+ - "ArtilleryGitHubOIDCForFargateRole"
237
+ - "Arn"
238
+ OIDCProviderArn:
239
+ Condition: CreateOIDCProvider
240
+ Description: "ARN of the newly created OIDC provider"
241
+ Value: !Ref GitHubOIDCProvider
@@ -0,0 +1,153 @@
1
+ AWSTemplateFormatVersion: '2010-09-09'
2
+ Description: Creates an ArtilleryGitHubOIDCForLambdaRole IAM role with permissions needed to run Artillery Lambda 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.
3
+
4
+
5
+ Metadata:
6
+ AWS::CloudFormation::Interface:
7
+ ParameterGroups:
8
+ - Label:
9
+ default: "GitHub"
10
+ Parameters:
11
+ - GitHubRepository
12
+ - GitHubBranch
13
+ - Label:
14
+ default: "AWS IAM"
15
+ Parameters:
16
+ - GitHubOIDCProviderExists
17
+
18
+ ParameterLabels:
19
+ GitHubRepository:
20
+ default: "GitHub repository"
21
+ GitHubBranch:
22
+ default: "GitHub branch"
23
+ GitHubOIDCProviderExists:
24
+ default: "GitHub OIDC identity provider already created for the account?"
25
+
26
+ Parameters:
27
+ GitHubRepository:
28
+ Type: String
29
+ Default: ""
30
+ Description: The GitHub repository (orgname/reponame) to be allowed to assume the created IAM role using OIDC (e.g. "artilleryio/artillery").
31
+
32
+ GitHubBranch:
33
+ Type: String
34
+ Default: "*"
35
+ Description: (Optional) Use when you want to allow only a specific branch within the specified Github repository to assume this IAM role using OIDC (e.g. "main"). If not set, defaults to "*" (all branches).
36
+
37
+ GitHubOIDCProviderExists:
38
+ Type: String
39
+ Default: 'No'
40
+ AllowedValues:
41
+ - 'Yes'
42
+ - 'No'
43
+ 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').
44
+
45
+ Conditions:
46
+ IsGHRepoSet:
47
+ !Not [!Equals [!Ref GitHubRepository, ""]]
48
+
49
+ CreateOIDCProvider:
50
+ !Equals [!Ref GitHubOIDCProviderExists, "No"]
51
+
52
+ Resources:
53
+ GitHubOIDCProvider:
54
+ Type: AWS::IAM::OIDCProvider
55
+ Condition: CreateOIDCProvider
56
+ Properties:
57
+ Url: "https://token.actions.githubusercontent.com"
58
+ ClientIdList:
59
+ - "sts.amazonaws.com"
60
+ ThumbprintList:
61
+ - "6938fd4d98bab03faadb97b34396831e3780ee11"
62
+
63
+
64
+ ArtilleryGitHubOIDCForLambdaRole:
65
+ Type: "AWS::IAM::Role"
66
+ Properties:
67
+ RoleName: "ArtilleryGitHubOIDCForLambdaRole"
68
+ AssumeRolePolicyDocument:
69
+ Version: "2012-10-17"
70
+ Statement:
71
+ - Effect: "Allow"
72
+ Principal:
73
+ Federated:
74
+ Fn::If:
75
+ - CreateOIDCProvider
76
+ - !Ref GitHubOIDCProvider
77
+ - !Ref GitHubOIDCProviderArn
78
+ Action: "sts:AssumeRoleWithWebIdentity"
79
+ Condition: {
80
+ StringEquals:
81
+ {
82
+ "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
83
+ },
84
+ StringLike:
85
+ {
86
+ "token.actions.githubusercontent.com:sub": !Sub "repo:${GitHubRepository}:${GitHubBranch}"
87
+ }
88
+ }
89
+ Path: "/"
90
+ Policies:
91
+ - PolicyName: ArtilleryDistributedTestingLambdaPolicy
92
+ PolicyDocument:
93
+ Version: "2012-10-17"
94
+ Statement:
95
+ - Sid: CreateOrGetLambdaRole
96
+ Effect: Allow
97
+ Action:
98
+ - iam:CreateRole
99
+ - iam:GetRole
100
+ - iam:PassRole
101
+ - iam:AttachRolePolicy
102
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/artilleryio-default-lambda-role-*"
103
+ - Sid: CreateLambdaPolicy
104
+ Effect: Allow
105
+ Action:
106
+ - iam:CreatePolicy
107
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/artilleryio-lambda-policy-*"
108
+ - Sid: SQSPermissions
109
+ Effect: Allow
110
+ Action:
111
+ - sqs:*
112
+ Resource: !Sub "arn:aws:sqs:*:${AWS::AccountId}:artilleryio*"
113
+ - Sid: SQSListQueues
114
+ Effect: Allow
115
+ Action:
116
+ - sqs:ListQueues
117
+ Resource: "*"
118
+ - Sid: LambdaPermissions
119
+ Effect: Allow
120
+ Action:
121
+ - lambda:InvokeFunction
122
+ - lambda:CreateFunction
123
+ - lambda:DeleteFunction
124
+ - lambda:GetFunctionConfiguration
125
+ Resource: !Sub "arn:aws:lambda:*:${AWS::AccountId}:function:artilleryio-*"
126
+ - Sid: EcrPullImagePermissions
127
+ Effect: Allow
128
+ Action:
129
+ - ecr:GetDownloadUrlForLayer
130
+ - ecr:BatchGetImage
131
+ Resource: "arn:aws:ecr:*:248481025674:repository/artillery-worker"
132
+ - Sid: S3Permissions
133
+ Effect: Allow
134
+ Action:
135
+ - s3:CreateBucket
136
+ - s3:DeleteObject
137
+ - s3:GetObject
138
+ - s3:PutObject
139
+ - s3:ListBucket
140
+ - s3:GetLifecycleConfiguration
141
+ - s3:PutLifecycleConfiguration
142
+ Resource:
143
+ - !Sub "arn:aws:s3:::artilleryio-test-data-*"
144
+ - !Sub "arn:aws:s3:::artilleryio-test-data-*/*"
145
+
146
+ Outputs:
147
+ RoleArn:
148
+ Description: ARN of the IAM Role for Artillery.io Lambda functions
149
+ Value: !GetAtt ArtilleryGitHubOIDCForLambdaRole.Arn
150
+ OIDCProviderArn:
151
+ Condition: CreateOIDCProvider
152
+ Description: "ARN of the newly created OIDC provider"
153
+ Value: !Ref GitHubOIDCProvider
@@ -0,0 +1,247 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ const debug = require('debug')('platform:aws-ecs');
6
+
7
+ const ensureS3BucketExists = require('../aws/aws-ensure-s3-bucket-exists');
8
+
9
+ const {
10
+ IAMClient,
11
+ GetRoleCommand,
12
+ CreateRoleCommand,
13
+ CreatePolicyCommand,
14
+ AttachRolePolicyCommand
15
+ } = require('@aws-sdk/client-iam');
16
+
17
+ const { ensureParameterExists } = require('./legacy/aws-util');
18
+
19
+ const { S3_BUCKET_NAME_PREFIX } = require('../aws/constants');
20
+
21
+ const getAccountId = require('../aws/aws-get-account-id');
22
+
23
+ const sleep = require('../../util/sleep');
24
+ const { getBucketRegion } = require('../aws/aws-get-bucket-region');
25
+ const awsGetDefaultRegion = require('../aws/aws-get-default-region');
26
+
27
+ class PlatformECS {
28
+ constructor(_script, _payload, opts, platformOpts) {
29
+ this.opts = opts;
30
+ this.platformOpts = platformOpts;
31
+
32
+ this.arnPrefx = this.platformOpts.region.startsWith('cn-')
33
+ ? 'arn:aws-cn'
34
+ : 'arn:aws';
35
+
36
+ this.testRunId = platformOpts.testRunId;
37
+ if (!this.testRunId) {
38
+ throw new Error('testRunId is required');
39
+ }
40
+
41
+ this.s3LifecycleConfigurationRules = [
42
+ {
43
+ Expiration: { Days: 2 },
44
+ Filter: { Prefix: 'tests/' },
45
+ ID: 'RemoveAdHocTestData',
46
+ Status: 'Enabled'
47
+ },
48
+ {
49
+ Expiration: { Days: 7 },
50
+ Filter: { Prefix: 'test-runs/' },
51
+ ID: 'RemoveTestRunMetadata',
52
+ Status: 'Enabled'
53
+ }
54
+ ];
55
+ }
56
+
57
+ async init() {
58
+ global.artillery.awsRegion =
59
+ (await awsGetDefaultRegion()) || this.platformOpts.region;
60
+
61
+ this.accountId = await getAccountId();
62
+
63
+ await ensureSSMParametersExist(this.platformOpts.region);
64
+ const bucketName = await ensureS3BucketExists(
65
+ this.platformOpts.region,
66
+ this.s3LifecycleConfigurationRules,
67
+ false
68
+ );
69
+
70
+ global.artillery.s3BucketRegion = await getBucketRegion(bucketName);
71
+ await this.createIAMResources(
72
+ this.accountId,
73
+ this.platformOpts.taskRoleName
74
+ );
75
+ }
76
+
77
+ async createIAMResources(accountId, taskRoleName) {
78
+ const workerRoleArn = await this.createWorkerRole(accountId, taskRoleName);
79
+
80
+ return {
81
+ workerRoleArn
82
+ };
83
+ }
84
+
85
+ async createWorkerRole(accountId, taskRoleName) {
86
+ const iam = new IAMClient({ region: global.artillery.awsRegion });
87
+
88
+ try {
89
+ const res = await iam.send(
90
+ new GetRoleCommand({ RoleName: taskRoleName })
91
+ );
92
+ return res.Role.Arn;
93
+ } catch (err) {
94
+ debug(err);
95
+ }
96
+
97
+ const createRoleResp = await iam.send(
98
+ new CreateRoleCommand({
99
+ AssumeRolePolicyDocument: JSON.stringify({
100
+ Version: '2012-10-17',
101
+ Statement: [
102
+ {
103
+ Effect: 'Allow',
104
+ Principal: {
105
+ Service: ['ecs-tasks.amazonaws.com', 'ecs.amazonaws.com']
106
+ },
107
+ Action: 'sts:AssumeRole'
108
+ }
109
+ ]
110
+ }),
111
+ Path: '/',
112
+ RoleName: taskRoleName
113
+ })
114
+ );
115
+
116
+ const policyDocument = {
117
+ Version: '2012-10-17',
118
+ Statement: [
119
+ {
120
+ Effect: 'Allow',
121
+ Action: ['ssm:DescribeParameters'],
122
+ Resource: ['*']
123
+ },
124
+ {
125
+ Effect: 'Allow',
126
+ Action: [
127
+ 'ssm:GetParameters',
128
+ 'ssm:GetParameter',
129
+ 'ssm:PutParameter',
130
+ 'ssm:DeleteParameter',
131
+ 'ssm:DescribeParameters',
132
+ 'ssm:GetParametersByPath'
133
+ ],
134
+ Resource: [
135
+ `${this.arnPrefx}:ssm:*:${accountId}:parameter/artilleryio/*`
136
+ ]
137
+ },
138
+ {
139
+ Effect: 'Allow',
140
+ Action: ['ecr:GetAuthorizationToken'],
141
+ Resource: ['*']
142
+ },
143
+ {
144
+ Effect: 'Allow',
145
+ Action: ['logs:*'],
146
+ Resource: [
147
+ `${this.arnPrefx}:logs:*:${accountId}:log-group:artilleryio-log-group*:*`
148
+ ]
149
+ },
150
+ {
151
+ Effect: 'Allow',
152
+ Action: ['sqs:*'],
153
+ Resource: [`${this.arnPrefx}:sqs:*:${accountId}:artilleryio*`]
154
+ },
155
+ {
156
+ Effect: 'Allow',
157
+ Action: ['s3:*'],
158
+ Resource: [
159
+ `${this.arnPrefx}:s3:::${S3_BUCKET_NAME_PREFIX}-${accountId}`,
160
+ `${this.arnPrefx}:s3:::${S3_BUCKET_NAME_PREFIX}-${accountId}/*`
161
+ ]
162
+ },
163
+ {
164
+ Effect: 'Allow',
165
+ Action: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
166
+ Resource: ['*']
167
+ }
168
+ ]
169
+ };
170
+
171
+ const createPolicyResp = await iam.send(
172
+ new CreatePolicyCommand({
173
+ PolicyName: 'artilleryio-ecs-worker-policy',
174
+ Path: '/',
175
+ PolicyDocument: JSON.stringify(policyDocument)
176
+ })
177
+ );
178
+
179
+ await iam.send(
180
+ new AttachRolePolicyCommand({
181
+ PolicyArn: createPolicyResp.Policy.Arn,
182
+ RoleName: taskRoleName
183
+ })
184
+ );
185
+
186
+ debug('Waiting for IAM role to be ready');
187
+ await sleep(30 * 1000);
188
+ return createRoleResp.Role.Arn;
189
+ }
190
+
191
+ async createWorker() {}
192
+
193
+ async prepareWorker() {}
194
+
195
+ async runWorker() {}
196
+
197
+ async stopWorker() {}
198
+
199
+ async shutdown() {}
200
+ }
201
+
202
+ async function ensureSSMParametersExist(region) {
203
+ await ensureParameterExists(
204
+ '/artilleryio/NPM_TOKEN',
205
+ 'null',
206
+ 'SecureString',
207
+ region
208
+ );
209
+ await ensureParameterExists(
210
+ '/artilleryio/NPM_REGISTRY',
211
+ 'null',
212
+ 'String',
213
+ region
214
+ );
215
+ await ensureParameterExists(
216
+ '/artilleryio/NPM_SCOPE',
217
+ 'null',
218
+ 'String',
219
+ region
220
+ );
221
+ await ensureParameterExists(
222
+ '/artilleryio/ARTIFACTORY_AUTH',
223
+ 'null',
224
+ 'SecureString',
225
+ region
226
+ );
227
+ await ensureParameterExists(
228
+ '/artilleryio/ARTIFACTORY_EMAIL',
229
+ 'null',
230
+ 'String',
231
+ region
232
+ );
233
+ await ensureParameterExists(
234
+ '/artilleryio/NPMRC',
235
+ 'null',
236
+ 'SecureString',
237
+ region
238
+ );
239
+ await ensureParameterExists(
240
+ '/artilleryio/NPM_SCOPE_REGISTRY',
241
+ 'null',
242
+ 'String',
243
+ region
244
+ );
245
+ }
246
+
247
+ module.exports = PlatformECS;