@pipeline-builder/pipeline-manager 6.5.5 → 6.5.7
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.
- package/README.md +11 -3
- package/dist/agent/post-steps.d.ts +1 -1
- package/dist/agent/post-steps.d.ts.map +1 -1
- package/dist/agent/post-steps.js +27 -31
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -9
- package/dist/commands/audit-stacks.d.ts +2 -1
- package/dist/commands/audit-stacks.d.ts.map +1 -1
- package/dist/commands/audit-stacks.js +12 -2
- package/dist/commands/provision-steps.d.ts +1 -1
- package/dist/commands/provision-steps.js +2 -2
- package/dist/commands/provision.js +2 -2
- package/dist/commands/redrive-events.d.ts +4 -3
- package/dist/commands/redrive-events.d.ts.map +1 -1
- package/dist/commands/redrive-events.js +51 -18
- package/dist/commands/runner-signing-key.js +2 -2
- package/dist/commands/{setup-runner.d.ts → setup-account.d.ts} +133 -71
- package/dist/commands/setup-account.d.ts.map +1 -0
- package/dist/commands/setup-account.js +1366 -0
- package/dist/commands/store-token.d.ts +6 -28
- package/dist/commands/store-token.d.ts.map +1 -1
- package/dist/commands/store-token.js +12 -139
- package/dist/config/cli.constants.d.ts +0 -8
- package/dist/config/cli.constants.d.ts.map +1 -1
- package/dist/config/cli.constants.js +1 -9
- package/dist/lambda/events-handler.js +1558 -0
- package/dist/lambda/runner-handler.d.ts +27 -1
- package/dist/lambda/runner-handler.d.ts.map +1 -1
- package/dist/lambda/runner-handler.js +428 -71
- package/dist/lambda/runner-inspect-connection.d.ts +45 -0
- package/dist/lambda/runner-inspect-connection.d.ts.map +1 -0
- package/dist/lambda/runner-inspect-connection.js +157 -0
- package/dist/lambda/runner-jws.d.ts.map +1 -1
- package/dist/lambda/runner-jws.js +64 -6
- package/dist/lambda/runner-sources.d.ts +12 -0
- package/dist/lambda/runner-sources.d.ts.map +1 -1
- package/dist/lambda/runner-sources.js +25 -16
- package/dist/lambda/token-renew-handler.d.ts +3 -2
- package/dist/lambda/token-renew-handler.d.ts.map +1 -1
- package/dist/lambda/token-renew-handler.js +17 -5
- package/dist/templates/account-stack.json +2060 -0
- package/dist/templates/forwarder-stack.json +133 -0
- package/dist/utils/{runner-template.d.ts → account-template.d.ts} +83 -18
- package/dist/utils/account-template.d.ts.map +1 -0
- package/dist/utils/account-template.js +340 -0
- package/dist/utils/inspect-buildspec.d.ts +9 -0
- package/dist/utils/inspect-buildspec.d.ts.map +1 -0
- package/dist/utils/inspect-buildspec.js +209 -0
- package/dist/utils/service-account.d.ts +10 -2
- package/dist/utils/service-account.d.ts.map +1 -1
- package/dist/utils/service-account.js +10 -4
- package/package.json +5 -4
- package/dist/commands/setup-events.d.ts +0 -15
- package/dist/commands/setup-events.d.ts.map +0 -1
- package/dist/commands/setup-events.js +0 -182
- package/dist/commands/setup-runner.d.ts.map +0 -1
- package/dist/commands/setup-runner.js +0 -1132
- package/dist/templates/events-stack.json +0 -192
- package/dist/templates/runner-stack.json +0 -960
- package/dist/templates/token-renew-stack.json +0 -115
- package/dist/utils/cron.d.ts +0 -28
- package/dist/utils/cron.d.ts.map +0 -1
- package/dist/utils/cron.js +0 -119
- package/dist/utils/runner-template.d.ts.map +0 -1
- package/dist/utils/runner-template.js +0 -238
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
} from "@aws-sdk/client-codepipeline";
|
|
10
10
|
import { KMSClient } from "@aws-sdk/client-kms";
|
|
11
11
|
import { GetResourcesCommand, ResourceGroupsTaggingAPIClient } from "@aws-sdk/client-resource-groups-tagging-api";
|
|
12
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
12
13
|
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
14
|
+
import { GetQueueAttributesCommand, SQSClient } from "@aws-sdk/client-sqs";
|
|
15
|
+
import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
13
16
|
|
|
14
17
|
// ../api-core/lib/types/pipeline-runners.js
|
|
15
18
|
var PIPELINE_ID_TAG = "pb.pipeline-id";
|
|
@@ -30,26 +33,53 @@ var RUNNER_ACTIONS = [
|
|
|
30
33
|
"list_sources",
|
|
31
34
|
"check_source",
|
|
32
35
|
// Reading a private GitHub repository for Generate from Git with the stored token, inside the account.
|
|
33
|
-
"inspect_repository"
|
|
36
|
+
"inspect_repository",
|
|
37
|
+
// Reading any private repository for Generate from Git through a CodeConnections connection: a short
|
|
38
|
+
// CodeBuild job in the account clones it and leaves a bounded snapshot the platform reads back;
|
|
39
|
+
// _stop ends that job early when the platform gives up on it (deadline, cancel, failure).
|
|
40
|
+
"inspect_connection_start",
|
|
41
|
+
"inspect_connection_status",
|
|
42
|
+
"inspect_connection_stop"
|
|
34
43
|
];
|
|
35
44
|
var DEPLOY_CAPABILITY = "deploy:1";
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
var EVENTS_CAPABILITY = "events:1";
|
|
46
|
+
var RUNNER_ACTION_SPECS = {
|
|
47
|
+
start: { outcomes: ["started"], runRequest: true },
|
|
48
|
+
stop: { outcomes: ["stopped"], runRequest: true },
|
|
49
|
+
probe: { outcomes: ["match", "no_match"], runRequest: true },
|
|
50
|
+
ping: { outcomes: ["pong"] },
|
|
51
|
+
status: { outcomes: ["status"] },
|
|
52
|
+
deploy: { outcomes: ["deploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
|
|
53
|
+
deploy_status: { outcomes: ["deploy_status"], capability: DEPLOY_CAPABILITY },
|
|
54
|
+
deploy_cancel: { outcomes: ["deploy_cancelled"], capability: DEPLOY_CAPABILITY },
|
|
55
|
+
undeploy: { outcomes: ["undeploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
|
|
56
|
+
list_sources: { outcomes: ["sources"] },
|
|
57
|
+
check_source: { outcomes: ["source_ok"] },
|
|
58
|
+
inspect_repository: { outcomes: ["repository_reads"] },
|
|
59
|
+
inspect_connection_start: { outcomes: ["inspection_started"] },
|
|
60
|
+
inspect_connection_status: { outcomes: ["inspection_status"] },
|
|
61
|
+
inspect_connection_stop: { outcomes: ["inspection_stopped"] }
|
|
43
62
|
};
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var
|
|
63
|
+
var RUN_REQUEST_ACTIONS = RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].runRequest === true);
|
|
64
|
+
var EXPECTED_OUTCOMES = Object.fromEntries(RUNNER_ACTIONS.map((a) => [a, RUNNER_ACTION_SPECS[a].outcomes]));
|
|
65
|
+
function actionsGatedBy(capability) {
|
|
66
|
+
return Object.freeze(Object.fromEntries(RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].capability === capability).map((a) => [a, capability])));
|
|
67
|
+
}
|
|
68
|
+
var DEPLOY_ACTION_CAPABILITY = actionsGatedBy(DEPLOY_CAPABILITY);
|
|
69
|
+
var SOURCE_ACTIONS = ["list_sources", "check_source"];
|
|
70
|
+
var INSPECT_CONNECTION_ACTIONS = ["inspect_connection_start", "inspect_connection_status", "inspect_connection_stop"];
|
|
52
71
|
var AWS_REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
|
|
72
|
+
var RUNNER_LABEL_MAX_LENGTH = 64;
|
|
73
|
+
var CONTROL_CHARS_G = /[\p{Cc}\p{Cf}\u2028\u2029]/gu;
|
|
74
|
+
function displayRunnerName(raw) {
|
|
75
|
+
if (typeof raw !== "string")
|
|
76
|
+
return void 0;
|
|
77
|
+
const v = [...raw.replace(CONTROL_CHARS_G, " ").replace(/\s+/g, " ").trim()].slice(0, RUNNER_LABEL_MAX_LENGTH).join("").trim();
|
|
78
|
+
return v || void 0;
|
|
79
|
+
}
|
|
80
|
+
function claimRegion(c) {
|
|
81
|
+
return c.sources?.region ?? c.inspect?.region ?? c.inspectConnection?.region ?? c.deploy?.region;
|
|
82
|
+
}
|
|
53
83
|
var RUNNER_ERRORS = {
|
|
54
84
|
// -- The pipeline service's answers --
|
|
55
85
|
RUNNERS_UNAVAILABLE: { httpStatus: 409, retryable: false, category: "platform" },
|
|
@@ -62,9 +92,14 @@ var RUNNER_ERRORS = {
|
|
|
62
92
|
RUNNER_LIMIT: { httpStatus: 409, retryable: false, category: "platform" },
|
|
63
93
|
/** Another non-revoked runner of the org already has this label (labels are how the CLI finds a runner). */
|
|
64
94
|
RUNNER_LABEL_TAKEN: { httpStatus: 409, retryable: false, category: "platform" },
|
|
95
|
+
/**
|
|
96
|
+
* The connector answered from a different AWS account than the one it was
|
|
97
|
+
* pinned to: nothing is delivered to it until an admin confirms the new
|
|
98
|
+
* account (POST …/runners/:id/confirm-account).
|
|
99
|
+
*/
|
|
100
|
+
RUNNER_ACCOUNT_CHANGED: { httpStatus: 409, retryable: false, category: "platform" },
|
|
65
101
|
RUN_REQUEST_RATE_LIMITED: { httpStatus: 429, retryable: false, category: "platform" },
|
|
66
102
|
TOO_MANY_PENDING: { httpStatus: 429, retryable: false, category: "platform" },
|
|
67
|
-
RUNNER_UPDATE_REQUIRED: { httpStatus: 409, retryable: false, category: "platform" },
|
|
68
103
|
RUNNER_PENDING: { httpStatus: 409, retryable: false, category: "platform" },
|
|
69
104
|
/** The org's effective signing key exists but cannot be decrypted (wrong master, rotated KMS key). That org only. */
|
|
70
105
|
RUNNER_KEY_UNREADABLE: { httpStatus: 409, retryable: false, category: "platform" },
|
|
@@ -85,7 +120,7 @@ var RUNNER_ERRORS = {
|
|
|
85
120
|
/** Revoke: the typed confirmation is not the last {@link RUNNER_KEY_REVOKE_CONFIRM_CHARS} characters of the active kid. */
|
|
86
121
|
RUNNER_KEY_CONFIRMATION_MISMATCH: { httpStatus: 400, retryable: false, category: "platform" },
|
|
87
122
|
// -- Deploys through a runner (the pipeline service's answers) --
|
|
88
|
-
/** The runner does not list the `deploy:1` capability (an old bundle, or a stack without --
|
|
123
|
+
/** The runner does not list the `deploy:1` capability (an old bundle, or a stack without --deploy): update it with {@link DEPLOY_SETUP_COMMAND}. */
|
|
89
124
|
RUNNER_DEPLOY_UNSUPPORTED: { httpStatus: 409, retryable: false, category: "platform" },
|
|
90
125
|
/** Several runners can deploy this pipeline and none was named (`details.runners`: the deployable ones). */
|
|
91
126
|
DEPLOY_RUNNER_REQUIRED: { httpStatus: 409, retryable: false, category: "platform" },
|
|
@@ -132,7 +167,7 @@ var RUNNER_ERRORS = {
|
|
|
132
167
|
*/
|
|
133
168
|
RUNNER_ERROR: { httpStatus: 500, retryable: false, category: "runner" },
|
|
134
169
|
// -- A runner's answers to the deploy actions --
|
|
135
|
-
/** The stack was not set up with --
|
|
170
|
+
/** The stack was not set up with --deploy (the platform clears the runner's stored capabilities). */
|
|
136
171
|
DEPLOY_NOT_ENABLED: { httpStatus: 403, retryable: false, category: "runner" },
|
|
137
172
|
/** A pipeline tagged with this pipeline id already exists in the account (the platform links it instead). */
|
|
138
173
|
PIPELINE_ALREADY_DEPLOYED: { httpStatus: 409, retryable: false, category: "runner" },
|
|
@@ -155,8 +190,17 @@ var RUNNER_ERRORS = {
|
|
|
155
190
|
SOURCE_CONNECTION_WRONG_PROVIDER: { httpStatus: 409, retryable: false, category: "runner" },
|
|
156
191
|
/** A token-less GitHub source, and neither the owner's nor the org's GitHub token secret exists in the region. */
|
|
157
192
|
GITHUB_TOKEN_MISSING: { httpStatus: 409, retryable: false, category: "runner" },
|
|
193
|
+
// -- A runner's answers to the connection inspection (its start also answers the source refusals above) --
|
|
194
|
+
/** inspect_connection_status: no such build in the runner's own inspect project. */
|
|
195
|
+
INSPECT_BUILD_NOT_FOUND: { httpStatus: 404, retryable: false, category: "runner" },
|
|
196
|
+
/** The inspect project lives in the runner stack's own region; the connection must be there too. */
|
|
197
|
+
INSPECT_REGION_UNSUPPORTED: { httpStatus: 409, retryable: false, category: "runner" },
|
|
198
|
+
/** The inspect project is at its concurrent build limit. */
|
|
199
|
+
INSPECT_BUSY: { httpStatus: 409, retryable: false, category: "runner" },
|
|
158
200
|
// -- Recorded by the platform --
|
|
159
201
|
/** Not delivered within the request's lifetime. */
|
|
202
|
+
/** A reply whose echoed connector id, request id or region is not the request's, or a success without the echo. */
|
|
203
|
+
RUNNER_IDENTITY_MISMATCH: { httpStatus: null, retryable: false, category: "recorded" },
|
|
160
204
|
RUN_REQUEST_EXPIRED: { httpStatus: null, retryable: false, category: "recorded" },
|
|
161
205
|
/** A discovery probe that found nothing (probe rows only). */
|
|
162
206
|
NO_MATCH: { httpStatus: null, retryable: false, category: "recorded" },
|
|
@@ -189,6 +233,26 @@ var INSPECT_MAX_READ_BYTES = 128 * 1024;
|
|
|
189
233
|
var INSPECT_MAX_REPLY_BYTES = 1024 * 1024;
|
|
190
234
|
var INSPECT_MAX_LISTING_ENTRIES = 1e3;
|
|
191
235
|
var INSPECT_REPO_PATTERN = /^[A-Za-z0-9._-]{1,100}$/;
|
|
236
|
+
var INSPECT_CONNECTION_MAX_SEGMENTS = 10;
|
|
237
|
+
function inspectConnectionRepositoryProblem(raw) {
|
|
238
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
239
|
+
return "not a repository";
|
|
240
|
+
const r = raw;
|
|
241
|
+
if (Object.keys(r).some((k) => k !== "host" && k !== "path"))
|
|
242
|
+
return "unexpected fields";
|
|
243
|
+
if (typeof r.host !== "string" || !SOURCE_HOST_PATTERN.test(r.host))
|
|
244
|
+
return "malformed host";
|
|
245
|
+
if (typeof r.path !== "string")
|
|
246
|
+
return "malformed path";
|
|
247
|
+
const segments = r.path.split("/");
|
|
248
|
+
if (segments.length < 2 || segments.length > INSPECT_CONNECTION_MAX_SEGMENTS)
|
|
249
|
+
return "malformed path";
|
|
250
|
+
if (segments.some((seg) => seg === "." || seg === ".." || !SOURCE_OWNER_PATTERN.test(seg)))
|
|
251
|
+
return "malformed path";
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
var INSPECT_CONNECTION_DEADLINE_MS = 6 * 6e4;
|
|
255
|
+
var INSPECT_BUILD_ID_PATTERN = /^pipeline-builder-inspect[A-Za-z0-9_-]{0,200}:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
192
256
|
var RUNNER_KEY_ACTIVATION_DELAY_MS = 10 * 6e4;
|
|
193
257
|
var RUNNER_KEY_RETIRE_WINDOW_MS = 60 * 6e4;
|
|
194
258
|
var RUNNER_TUNABLE_DEFAULTS = {
|
|
@@ -479,8 +543,9 @@ async function runDeployAction(ctx, claims) {
|
|
|
479
543
|
}
|
|
480
544
|
}
|
|
481
545
|
|
|
482
|
-
// src/lambda/runner-inspect.ts
|
|
483
|
-
import {
|
|
546
|
+
// src/lambda/runner-inspect-connection.ts
|
|
547
|
+
import { BatchGetBuildsCommand as BatchGetBuildsCommand2, StartBuildCommand as StartBuildCommand2, StopBuildCommand as StopBuildCommand2 } from "@aws-sdk/client-codebuild";
|
|
548
|
+
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
484
549
|
|
|
485
550
|
// ../api-core/lib/types/pipeline-source.js
|
|
486
551
|
var CONNECTION_ARN_PATTERN = /^arn:aws(?:-[a-z]+)*:(?:codeconnections|codestar-connections):[a-z0-9-]+:\d{12}:connection\/[A-Za-z0-9-]+$/;
|
|
@@ -502,6 +567,31 @@ function githubTokenStoreCommand(owner, region = "<region>") {
|
|
|
502
567
|
return `pipeline-manager infra store-github-token --region ${region}${owner ? ` --owner ${owner.toLowerCase()}` : ""}`;
|
|
503
568
|
}
|
|
504
569
|
var GITHUB_TOKEN_STORE_COMMAND = githubTokenStoreCommand();
|
|
570
|
+
var GIT_REF_MAX_LENGTH = 200;
|
|
571
|
+
function gitBranchProblem(branch) {
|
|
572
|
+
if (!branch)
|
|
573
|
+
return "Enter a branch name.";
|
|
574
|
+
if (branch.length > GIT_REF_MAX_LENGTH)
|
|
575
|
+
return `A branch name is at most ${GIT_REF_MAX_LENGTH} characters.`;
|
|
576
|
+
if (!/^[A-Za-z0-9._/-]+$/.test(branch))
|
|
577
|
+
return 'A branch name uses only letters, digits, ".", "_", "-" and "/".';
|
|
578
|
+
if (branch.startsWith("/") || branch.endsWith("/") || branch.includes("//"))
|
|
579
|
+
return 'A branch name cannot start or end with "/" or contain "//".';
|
|
580
|
+
if (branch.startsWith("-") || branch.includes("..") || branch.endsWith(".lock") || branch.endsWith("."))
|
|
581
|
+
return "That is not a valid branch name.";
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
function subdirectoryProblem(subdirectory) {
|
|
585
|
+
if (subdirectory === "")
|
|
586
|
+
return null;
|
|
587
|
+
if (subdirectory.length > GIT_REF_MAX_LENGTH)
|
|
588
|
+
return `A subdirectory is at most ${GIT_REF_MAX_LENGTH} characters.`;
|
|
589
|
+
const segments = subdirectory.split("/");
|
|
590
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || !/^[A-Za-z0-9._-]+$/.test(s))) {
|
|
591
|
+
return 'A subdirectory is a path inside the repository, like "services/api" (letters, digits, ".", "_", "-"; no "..").';
|
|
592
|
+
}
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
505
595
|
var GIT_PROVIDERS = {
|
|
506
596
|
github: { host: "github.com", browse: "tree" },
|
|
507
597
|
gitlab: { host: "gitlab.com", browse: "-/tree" },
|
|
@@ -509,17 +599,19 @@ var GIT_PROVIDERS = {
|
|
|
509
599
|
unknown: { host: null, browse: "tree" }
|
|
510
600
|
};
|
|
511
601
|
function providerForHost(host) {
|
|
512
|
-
const
|
|
602
|
+
const name = host.trim().toLowerCase().replace(/^www\./, "");
|
|
603
|
+
const hit = Object.keys(GIT_PROVIDERS).find((id) => GIT_PROVIDERS[id].host === name);
|
|
513
604
|
return hit ?? "unknown";
|
|
514
605
|
}
|
|
515
606
|
var SOURCE_CONNECTION_PROVIDER_TYPES = ["GitHub", "GitHubEnterpriseServer", "GitLab", "GitLabSelfManaged", "Bitbucket"];
|
|
516
607
|
var SOURCE_CONNECTION_STATUSES = ["PENDING", "AVAILABLE", "ERROR"];
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
608
|
+
var SOURCE_CONNECTION_PROVIDERS = {
|
|
609
|
+
GitHub: { label: "GitHub", codebuildSourceType: "GITHUB", publicProvider: "github" },
|
|
610
|
+
GitHubEnterpriseServer: { label: "GitHub Enterprise Server", codebuildSourceType: "GITHUB_ENTERPRISE", publicProvider: null },
|
|
611
|
+
GitLab: { label: "GitLab", codebuildSourceType: "GITLAB", publicProvider: "gitlab" },
|
|
612
|
+
GitLabSelfManaged: { label: "GitLab self-managed", codebuildSourceType: "GITLAB_SELF_MANAGED", publicProvider: null },
|
|
613
|
+
Bitbucket: { label: "Bitbucket", codebuildSourceType: "BITBUCKET", publicProvider: "bitbucket" }
|
|
521
614
|
};
|
|
522
|
-
var SELF_MANAGED_PROVIDER_TYPES = ["GitHubEnterpriseServer", "GitLabSelfManaged"];
|
|
523
615
|
function connectionArnParts(arn) {
|
|
524
616
|
const value = arn.trim();
|
|
525
617
|
if (!CONNECTION_ARN_PATTERN.test(value))
|
|
@@ -530,9 +622,10 @@ function connectionArnParts(arn) {
|
|
|
530
622
|
function connectionMatchesRepository(connection, repoHost) {
|
|
531
623
|
const host = repoHost.trim().toLowerCase();
|
|
532
624
|
const provider = providerForHost(host);
|
|
625
|
+
const served = SOURCE_CONNECTION_PROVIDERS[connection.providerType]?.publicProvider;
|
|
533
626
|
if (provider !== "unknown")
|
|
534
|
-
return
|
|
535
|
-
if (
|
|
627
|
+
return served === provider;
|
|
628
|
+
if (served !== null || !connection.hostEndpoint)
|
|
536
629
|
return false;
|
|
537
630
|
try {
|
|
538
631
|
return new URL(connection.hostEndpoint).hostname.toLowerCase() === host;
|
|
@@ -586,6 +679,8 @@ var MAX_TOPICS = 50;
|
|
|
586
679
|
var MAX_LANGUAGES = 100;
|
|
587
680
|
var MAX_BASE64_CHARS = 2e5;
|
|
588
681
|
var optionalString = (v, max) => v === void 0 || v === null || typeof v === "string" && v.length <= max;
|
|
682
|
+
var listingNameOk = (name) => name !== "." && name !== ".." && !name.includes("/") && READ_SEGMENT_PATTERN.test(name);
|
|
683
|
+
var languageEntryOk = (name, bytes) => name.length <= 100 && typeof bytes === "number" && Number.isFinite(bytes) && bytes >= 0;
|
|
589
684
|
function parseRepositoryReadBody(read, body) {
|
|
590
685
|
if (read.kind === "repo") {
|
|
591
686
|
if (!isRecord(body))
|
|
@@ -611,14 +706,14 @@ function parseRepositoryReadBody(read, body) {
|
|
|
611
706
|
if (!isRecord(body))
|
|
612
707
|
return null;
|
|
613
708
|
const entries = Object.entries(body);
|
|
614
|
-
if (entries.length > MAX_LANGUAGES || entries.some(([k, v]) => k
|
|
709
|
+
if (entries.length > MAX_LANGUAGES || entries.some(([k, v]) => !languageEntryOk(k, v)))
|
|
615
710
|
return null;
|
|
616
711
|
return Object.fromEntries(entries);
|
|
617
712
|
}
|
|
618
713
|
if (Array.isArray(body)) {
|
|
619
714
|
if (body.length > INSPECT_MAX_LISTING_ENTRIES)
|
|
620
715
|
return null;
|
|
621
|
-
return body.filter((e) => isRecord(e) && typeof e.name === "string" && e.name
|
|
716
|
+
return body.filter((e) => isRecord(e) && typeof e.name === "string" && listingNameOk(e.name) && (e.type === "file" || e.type === "dir")).map((e) => ({ name: e.name, type: e.type }));
|
|
622
717
|
}
|
|
623
718
|
if (!isRecord(body))
|
|
624
719
|
return null;
|
|
@@ -627,6 +722,53 @@ function parseRepositoryReadBody(read, body) {
|
|
|
627
722
|
return null;
|
|
628
723
|
return { name, type, encoding, content };
|
|
629
724
|
}
|
|
725
|
+
var MAX_SNAPSHOT_LISTINGS = 4;
|
|
726
|
+
var MAX_SNAPSHOT_FILES = 20;
|
|
727
|
+
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
728
|
+
function snapshotPathOk(path) {
|
|
729
|
+
if (path === "")
|
|
730
|
+
return true;
|
|
731
|
+
if (path.length > MAX_READ_PATH)
|
|
732
|
+
return false;
|
|
733
|
+
return path.split("/").every((seg) => seg !== "." && seg !== ".." && READ_SEGMENT_PATTERN.test(seg));
|
|
734
|
+
}
|
|
735
|
+
function parseRepositorySnapshot(raw) {
|
|
736
|
+
if (!isRecord(raw))
|
|
737
|
+
return null;
|
|
738
|
+
if (Object.keys(raw).some((k) => !["branch", "listings", "files", "languages"].includes(k)))
|
|
739
|
+
return null;
|
|
740
|
+
const { branch, listings, files, languages } = raw;
|
|
741
|
+
if (branch !== null && (typeof branch !== "string" || !READ_REF_PATTERN.test(branch)))
|
|
742
|
+
return null;
|
|
743
|
+
if (!isRecord(listings) || !isRecord(files) || !isRecord(languages))
|
|
744
|
+
return null;
|
|
745
|
+
const listingEntries = Object.entries(listings);
|
|
746
|
+
if (listingEntries.length > MAX_SNAPSHOT_LISTINGS)
|
|
747
|
+
return null;
|
|
748
|
+
const outListings = {};
|
|
749
|
+
for (const [path, entries] of listingEntries) {
|
|
750
|
+
if (!snapshotPathOk(path) || !Array.isArray(entries) || entries.length > INSPECT_MAX_LISTING_ENTRIES)
|
|
751
|
+
return null;
|
|
752
|
+
const kept = [];
|
|
753
|
+
for (const e of entries) {
|
|
754
|
+
if (!isRecord(e) || typeof e.name !== "string" || !listingNameOk(e.name) || e.type !== "file" && e.type !== "dir")
|
|
755
|
+
return null;
|
|
756
|
+
kept.push({ name: e.name, type: e.type });
|
|
757
|
+
}
|
|
758
|
+
outListings[path] = kept;
|
|
759
|
+
}
|
|
760
|
+
const fileEntries = Object.entries(files);
|
|
761
|
+
if (fileEntries.length > MAX_SNAPSHOT_FILES)
|
|
762
|
+
return null;
|
|
763
|
+
for (const [path, content] of fileEntries) {
|
|
764
|
+
if (path === "" || !snapshotPathOk(path) || typeof content !== "string" || content.length > MAX_BASE64_CHARS || !BASE64_PATTERN.test(content))
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
const langEntries = Object.entries(languages);
|
|
768
|
+
if (langEntries.length > MAX_LANGUAGES || langEntries.some(([k, v]) => !languageEntryOk(k, v)))
|
|
769
|
+
return null;
|
|
770
|
+
return { branch, listings: outListings, files: Object.fromEntries(fileEntries), languages: Object.fromEntries(langEntries) };
|
|
771
|
+
}
|
|
630
772
|
|
|
631
773
|
// src/lambda/runner-sources.ts
|
|
632
774
|
import { GetConnectionCommand, GetHostCommand, ListConnectionsCommand, ListHostsCommand } from "@aws-sdk/client-codeconnections";
|
|
@@ -698,18 +840,13 @@ async function listSources(claim, accountId, deps) {
|
|
|
698
840
|
truncated: more || matching.length > MAX_SOURCE_CONNECTIONS
|
|
699
841
|
};
|
|
700
842
|
}
|
|
701
|
-
async function
|
|
702
|
-
const
|
|
703
|
-
if (
|
|
704
|
-
|
|
705
|
-
return await githubTokenFor(claim, deps) ? null : "GITHUB_TOKEN_MISSING";
|
|
706
|
-
}
|
|
707
|
-
const parts = connectionArnParts(source.connectionArn);
|
|
708
|
-
if (!parts || parts.accountId !== accountId) return "SOURCE_CONNECTION_WRONG_ACCOUNT";
|
|
709
|
-
if (parts.region !== claim.region) return "SOURCE_CONNECTION_WRONG_REGION";
|
|
843
|
+
async function checkConnection(deps, q) {
|
|
844
|
+
const parts = connectionArnParts(q.connectionArn);
|
|
845
|
+
if (!parts || parts.accountId !== q.accountId) return "SOURCE_CONNECTION_WRONG_ACCOUNT";
|
|
846
|
+
if (parts.region !== q.region) return "SOURCE_CONNECTION_WRONG_REGION";
|
|
710
847
|
let connection;
|
|
711
848
|
try {
|
|
712
|
-
const out = await deps.codeconnections(
|
|
849
|
+
const out = await deps.codeconnections(q.region).send(new GetConnectionCommand({ ConnectionArn: q.connectionArn }));
|
|
713
850
|
connection = out.Connection;
|
|
714
851
|
} catch (err) {
|
|
715
852
|
if (isNotFound(err)) return "SOURCE_CONNECTION_NOT_FOUND";
|
|
@@ -720,7 +857,7 @@ async function checkSource(claim, accountId, deps) {
|
|
|
720
857
|
let hostEndpoint;
|
|
721
858
|
if (connection.HostArn) {
|
|
722
859
|
try {
|
|
723
|
-
const host = await deps.codeconnections(
|
|
860
|
+
const host = await deps.codeconnections(q.region).send(new GetHostCommand({ HostArn: connection.HostArn }));
|
|
724
861
|
hostEndpoint = host.ProviderEndpoint;
|
|
725
862
|
} catch (err) {
|
|
726
863
|
if (!isNotFound(err)) throw err;
|
|
@@ -728,10 +865,110 @@ async function checkSource(claim, accountId, deps) {
|
|
|
728
865
|
}
|
|
729
866
|
const dto = toDto(connection, hostEndpoint);
|
|
730
867
|
if (!dto) return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
731
|
-
return !
|
|
868
|
+
return !q.repoHost || connectionMatchesRepository(dto, q.repoHost) ? dto : "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
869
|
+
}
|
|
870
|
+
async function checkSource(claim, accountId, deps) {
|
|
871
|
+
const source = claim.source;
|
|
872
|
+
if (source.type === "github") {
|
|
873
|
+
if (!claim.repository || providerForHost(claim.repository.host) !== "github") return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
874
|
+
return await githubTokenFor(claim, deps) ? null : "GITHUB_TOKEN_MISSING";
|
|
875
|
+
}
|
|
876
|
+
const checked = await checkConnection(deps, { connectionArn: source.connectionArn, region: claim.region, accountId, repoHost: claim.repository?.host });
|
|
877
|
+
return typeof checked === "string" ? checked : null;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/lambda/runner-inspect-connection.ts
|
|
881
|
+
var errName3 = (err) => String(err?.name ?? "");
|
|
882
|
+
function resultKey(buildId) {
|
|
883
|
+
return `${buildId.slice(buildId.indexOf(":") + 1)}.json`;
|
|
884
|
+
}
|
|
885
|
+
async function startInspection(claim, accountId, config, deps) {
|
|
886
|
+
if (claim.region !== config.region) return "INSPECT_REGION_UNSUPPORTED";
|
|
887
|
+
const connection = await checkConnection(deps, { connectionArn: claim.connectionArn, region: claim.region, accountId, repoHost: claim.repository.host });
|
|
888
|
+
if (typeof connection === "string") return connection;
|
|
889
|
+
const location = `https://${claim.repository.host}/${claim.repository.path.split("/").map(encodeURIComponent).join("/")}.git`;
|
|
890
|
+
try {
|
|
891
|
+
const out = await deps.codebuild().send(new StartBuildCommand2({
|
|
892
|
+
projectName: config.projectName,
|
|
893
|
+
sourceTypeOverride: SOURCE_CONNECTION_PROVIDERS[connection.providerType].codebuildSourceType,
|
|
894
|
+
sourceLocationOverride: location,
|
|
895
|
+
...claim.branch ? { sourceVersion: claim.branch } : {},
|
|
896
|
+
gitCloneDepthOverride: 1,
|
|
897
|
+
sourceAuthOverride: { type: "CODECONNECTIONS", resource: claim.connectionArn },
|
|
898
|
+
environmentVariablesOverride: [
|
|
899
|
+
{ name: "INSPECT_BRANCH", value: claim.branch, type: "PLAINTEXT" },
|
|
900
|
+
{ name: "INSPECT_SUBDIRECTORY", value: claim.subdirectory, type: "PLAINTEXT" }
|
|
901
|
+
]
|
|
902
|
+
}));
|
|
903
|
+
const buildId = out.build?.id;
|
|
904
|
+
if (!buildId) throw new Error("StartBuild answered no build id");
|
|
905
|
+
return { buildId };
|
|
906
|
+
} catch (err) {
|
|
907
|
+
if (errName3(err) === "AccountLimitExceededException") return "INSPECT_BUSY";
|
|
908
|
+
throw err;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
var WAITING_PHASES = /* @__PURE__ */ new Set(["SUBMITTED", "QUEUED", "PROVISIONING"]);
|
|
912
|
+
var SOURCE_PHASES = /* @__PURE__ */ new Set(["DOWNLOAD_SOURCE"]);
|
|
913
|
+
function failedPhase(build) {
|
|
914
|
+
if (build.buildStatus !== "FAILED") return "other";
|
|
915
|
+
const failed = (build.phases ?? []).find((p) => p.phaseStatus === "FAILED" || p.phaseStatus === "FAULT");
|
|
916
|
+
if (!failed?.phaseType) return "other";
|
|
917
|
+
return SOURCE_PHASES.has(failed.phaseType) ? "source" : "build";
|
|
918
|
+
}
|
|
919
|
+
async function readSnapshot(buildId, config, deps) {
|
|
920
|
+
const key = resultKey(buildId);
|
|
921
|
+
let text = null;
|
|
922
|
+
try {
|
|
923
|
+
const out = await deps.s3().send(new GetObjectCommand({ Bucket: config.bucket, Key: key }));
|
|
924
|
+
if (out.Body && typeof out.ContentLength === "number" && out.ContentLength <= INSPECT_MAX_REPLY_BYTES) {
|
|
925
|
+
const bytes = await out.Body.transformToByteArray();
|
|
926
|
+
if (bytes.byteLength <= INSPECT_MAX_REPLY_BYTES) text = Buffer.from(bytes).toString("utf8");
|
|
927
|
+
}
|
|
928
|
+
} catch (err) {
|
|
929
|
+
if (errName3(err) === "NoSuchKey" || errName3(err) === "NotFound") return null;
|
|
930
|
+
throw err;
|
|
931
|
+
}
|
|
932
|
+
if (text === null) return null;
|
|
933
|
+
let json;
|
|
934
|
+
try {
|
|
935
|
+
json = JSON.parse(text);
|
|
936
|
+
} catch {
|
|
937
|
+
return null;
|
|
938
|
+
}
|
|
939
|
+
const snapshot = parseRepositorySnapshot(json);
|
|
940
|
+
return snapshot ? { state: "succeeded", snapshot } : null;
|
|
941
|
+
}
|
|
942
|
+
async function inspectionStatus(claim, config, deps) {
|
|
943
|
+
if (!claim.buildId.startsWith(`${config.projectName}:`)) return "INSPECT_BUILD_NOT_FOUND";
|
|
944
|
+
const out = await deps.codebuild().send(new BatchGetBuildsCommand2({ ids: [claim.buildId] }));
|
|
945
|
+
const build = (out.builds ?? []).find((b) => b.id === claim.buildId);
|
|
946
|
+
if (!build) return "INSPECT_BUILD_NOT_FOUND";
|
|
947
|
+
switch (build.buildStatus) {
|
|
948
|
+
case "IN_PROGRESS":
|
|
949
|
+
return { state: build.currentPhase && WAITING_PHASES.has(build.currentPhase) ? "queued" : "running" };
|
|
950
|
+
case "SUCCEEDED":
|
|
951
|
+
return await readSnapshot(claim.buildId, config, deps) ?? { state: "failed", failedPhase: "build" };
|
|
952
|
+
case "TIMED_OUT":
|
|
953
|
+
return { state: "timed_out" };
|
|
954
|
+
default:
|
|
955
|
+
return { state: "failed", failedPhase: failedPhase(build) };
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
async function stopInspection(claim, config, deps) {
|
|
959
|
+
if (!claim.buildId.startsWith(`${config.projectName}:`)) return "INSPECT_BUILD_NOT_FOUND";
|
|
960
|
+
try {
|
|
961
|
+
await deps.codebuild().send(new StopBuildCommand2({ id: claim.buildId }));
|
|
962
|
+
return { stopped: true };
|
|
963
|
+
} catch (err) {
|
|
964
|
+
if (errName3(err) === "InvalidInputException") return { stopped: false };
|
|
965
|
+
if (errName3(err) === "ResourceNotFoundException") return "INSPECT_BUILD_NOT_FOUND";
|
|
966
|
+
throw err;
|
|
967
|
+
}
|
|
732
968
|
}
|
|
733
969
|
|
|
734
970
|
// src/lambda/runner-inspect.ts
|
|
971
|
+
import { GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
|
|
735
972
|
var GITHUB_API = "https://api.github.com";
|
|
736
973
|
var GITHUB_TIMEOUT_MS = 6e3;
|
|
737
974
|
async function readCapped(res, cap) {
|
|
@@ -940,9 +1177,10 @@ async function verifyRunRequest(jws, opts) {
|
|
|
940
1177
|
const action = c.action;
|
|
941
1178
|
if (!opts.runnerId) throw new SignatureError("runner has no RUNNER_ID");
|
|
942
1179
|
if (c.aud !== opts.runnerId) throw new SignatureError("wrong aud");
|
|
943
|
-
const isSourceAction =
|
|
1180
|
+
const isSourceAction = SOURCE_ACTIONS.includes(action);
|
|
944
1181
|
const isInspect = action === "inspect_repository";
|
|
945
|
-
|
|
1182
|
+
const isInspectConnection = INSPECT_CONNECTION_ACTIONS.includes(action);
|
|
1183
|
+
if (action !== "ping" && !isSourceAction && !isInspect && !isInspectConnection && !isNonEmptyString(c.pipelineId)) throw new SignatureError("missing pipelineId");
|
|
946
1184
|
if ((action === "stop" || action === "status") && !isNonEmptyString(c.executionId)) throw new SignatureError("missing executionId");
|
|
947
1185
|
let hint;
|
|
948
1186
|
if (c.hint !== void 0 && c.hint !== null) {
|
|
@@ -962,6 +1200,8 @@ async function verifyRunRequest(jws, opts) {
|
|
|
962
1200
|
const sources = isSourceAction ? parseSourcesClaim(c.sources, action === "check_source") : void 0;
|
|
963
1201
|
if (!isInspect && c.inspect !== void 0) throw new SignatureError("unexpected inspect claim");
|
|
964
1202
|
const inspect = isInspect ? parseInspectClaim(c.inspect) : void 0;
|
|
1203
|
+
if (!isInspectConnection && c.inspectConnection !== void 0) throw new SignatureError("unexpected inspectConnection claim");
|
|
1204
|
+
const inspectConnection = isInspectConnection ? parseInspectConnectionClaim(c.inspectConnection, INSPECT_CONNECTION_CLAIM_KIND[action]) : void 0;
|
|
965
1205
|
if (takesBuild) {
|
|
966
1206
|
if (!isNonEmptyString(c.deployRequestId) || c.deployRequestId.length > 128) throw new SignatureError("missing deployRequestId");
|
|
967
1207
|
if (typeof c.buildId !== "string" || !BUILD_ID_PATTERN.test(c.buildId)) throw new SignatureError("malformed buildId");
|
|
@@ -980,6 +1220,9 @@ async function verifyRunRequest(jws, opts) {
|
|
|
980
1220
|
...takesBuild ? { deployRequestId: c.deployRequestId, buildId: c.buildId } : {},
|
|
981
1221
|
...sources ? { sources } : {},
|
|
982
1222
|
...inspect ? { inspect } : {},
|
|
1223
|
+
...inspectConnection ? { inspectConnection } : {},
|
|
1224
|
+
// Informational only (logged, echoed after cleaning): never checked, never a reason to refuse.
|
|
1225
|
+
...typeof c.name === "string" ? { name: c.name } : {},
|
|
983
1226
|
requestedBy: c.requestedBy
|
|
984
1227
|
};
|
|
985
1228
|
}
|
|
@@ -1060,6 +1303,41 @@ function parseInspectClaim(raw) {
|
|
|
1060
1303
|
});
|
|
1061
1304
|
return { orgId: b.orgId, region: b.region, repository: { owner: repo.owner, repo: repo.repo }, reads };
|
|
1062
1305
|
}
|
|
1306
|
+
var INSPECT_CONNECTION_CLAIM_KIND = {
|
|
1307
|
+
inspect_connection_start: "start",
|
|
1308
|
+
inspect_connection_status: "status",
|
|
1309
|
+
inspect_connection_stop: "stop"
|
|
1310
|
+
};
|
|
1311
|
+
function parseInspectConnectionClaim(raw, kind) {
|
|
1312
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new SignatureError("missing inspectConnection claim");
|
|
1313
|
+
const b = raw;
|
|
1314
|
+
if (b.kind !== kind) throw new SignatureError("inspectConnection kind is not the action");
|
|
1315
|
+
if (typeof b.region !== "string" || !AWS_REGION_PATTERN.test(b.region)) throw new SignatureError("malformed inspectConnection region");
|
|
1316
|
+
if (kind !== "start") {
|
|
1317
|
+
if (Object.keys(b).some((k) => !["kind", "region", "buildId"].includes(k))) throw new SignatureError("unexpected inspectConnection field");
|
|
1318
|
+
if (typeof b.buildId !== "string" || !INSPECT_BUILD_ID_PATTERN.test(b.buildId)) throw new SignatureError("malformed inspectConnection buildId");
|
|
1319
|
+
return { kind, region: b.region, buildId: b.buildId };
|
|
1320
|
+
}
|
|
1321
|
+
if (Object.keys(b).some((k) => !["kind", "region", "connectionArn", "repository", "branch", "subdirectory"].includes(k))) {
|
|
1322
|
+
throw new SignatureError("unexpected inspectConnection field");
|
|
1323
|
+
}
|
|
1324
|
+
if (typeof b.connectionArn !== "string" || !CONNECTION_ARN_PATTERN.test(b.connectionArn)) throw new SignatureError("malformed inspectConnection connectionArn");
|
|
1325
|
+
const problem = inspectConnectionRepositoryProblem(b.repository);
|
|
1326
|
+
if (problem) throw new SignatureError(`malformed inspectConnection repository: ${problem}`);
|
|
1327
|
+
if (typeof b.branch !== "string" || b.branch !== "" && gitBranchProblem(b.branch) !== null) throw new SignatureError("malformed inspectConnection branch");
|
|
1328
|
+
if (typeof b.subdirectory !== "string" || b.subdirectory !== "" && subdirectoryProblem(b.subdirectory) !== null) {
|
|
1329
|
+
throw new SignatureError("malformed inspectConnection subdirectory");
|
|
1330
|
+
}
|
|
1331
|
+
const repository = b.repository;
|
|
1332
|
+
return {
|
|
1333
|
+
kind: "start",
|
|
1334
|
+
region: b.region,
|
|
1335
|
+
connectionArn: b.connectionArn,
|
|
1336
|
+
repository: { host: repository.host, path: repository.path },
|
|
1337
|
+
branch: b.branch,
|
|
1338
|
+
subdirectory: b.subdirectory
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1063
1341
|
var ReplayCache = class {
|
|
1064
1342
|
constructor(now) {
|
|
1065
1343
|
this.now = now;
|
|
@@ -1106,9 +1384,23 @@ function configFromEnv(env = process.env) {
|
|
|
1106
1384
|
allowedRegions,
|
|
1107
1385
|
allowedPrefixes,
|
|
1108
1386
|
version: env.RUNNER_VERSION?.trim() || "0.0.0",
|
|
1109
|
-
deploy: deployConfigFromEnv(env)
|
|
1387
|
+
deploy: deployConfigFromEnv(env),
|
|
1388
|
+
inspectConnection: inspectConnectionFromEnv(env),
|
|
1389
|
+
...reportingFromEnv(env)
|
|
1110
1390
|
};
|
|
1111
1391
|
}
|
|
1392
|
+
function reportingFromEnv(env) {
|
|
1393
|
+
const deadLetterQueueUrl = env.REPORTING_DLQ_URL?.trim();
|
|
1394
|
+
const lastEventParameter = env.REPORTING_LAST_EVENT_PARAMETER?.trim();
|
|
1395
|
+
return deadLetterQueueUrl && lastEventParameter ? { reporting: { deadLetterQueueUrl, lastEventParameter } } : {};
|
|
1396
|
+
}
|
|
1397
|
+
function inspectConnectionFromEnv(env) {
|
|
1398
|
+
const projectName = env.INSPECT_PROJECT_NAME?.trim();
|
|
1399
|
+
const bucket = env.INSPECT_RESULTS_BUCKET?.trim();
|
|
1400
|
+
const region = env.AWS_REGION?.trim();
|
|
1401
|
+
if (!projectName || !bucket || !region) throw new Error("INSPECT_PROJECT_NAME, INSPECT_RESULTS_BUCKET and AWS_REGION environment variables are required");
|
|
1402
|
+
return { projectName, bucket, region };
|
|
1403
|
+
}
|
|
1112
1404
|
function defaultLog(level, msg, data) {
|
|
1113
1405
|
const line = JSON.stringify({ level, msg, ...data });
|
|
1114
1406
|
if (level === "ERROR") console.error(line);
|
|
@@ -1119,6 +1411,9 @@ function defaultDeps() {
|
|
|
1119
1411
|
const cp = /* @__PURE__ */ new Map();
|
|
1120
1412
|
let codebuild;
|
|
1121
1413
|
let kms;
|
|
1414
|
+
let s3;
|
|
1415
|
+
let sqs;
|
|
1416
|
+
let ssm;
|
|
1122
1417
|
const cc = /* @__PURE__ */ new Map();
|
|
1123
1418
|
const sm = /* @__PURE__ */ new Map();
|
|
1124
1419
|
return {
|
|
@@ -1134,6 +1429,7 @@ function defaultDeps() {
|
|
|
1134
1429
|
},
|
|
1135
1430
|
codebuild: () => codebuild ??= new CodeBuildClient({}),
|
|
1136
1431
|
kms: () => kms ??= new KMSClient({}),
|
|
1432
|
+
s3: () => s3 ??= new S3Client({}),
|
|
1137
1433
|
codeconnections: (region) => {
|
|
1138
1434
|
if (!cc.has(region)) cc.set(region, new CodeConnectionsClient({ region }));
|
|
1139
1435
|
return cc.get(region);
|
|
@@ -1142,6 +1438,8 @@ function defaultDeps() {
|
|
|
1142
1438
|
if (!sm.has(region)) sm.set(region, new SecretsManagerClient({ region }));
|
|
1143
1439
|
return sm.get(region);
|
|
1144
1440
|
},
|
|
1441
|
+
sqs: () => sqs ??= new SQSClient({}),
|
|
1442
|
+
ssm: () => ssm ??= new SSMClient({}),
|
|
1145
1443
|
github: githubGet,
|
|
1146
1444
|
log: defaultLog
|
|
1147
1445
|
};
|
|
@@ -1161,10 +1459,10 @@ function isAllowed(config, region, name) {
|
|
|
1161
1459
|
if (!config.allowedRegions.includes(region)) return false;
|
|
1162
1460
|
return config.allowedPrefixes.some((p) => p === "*" || name.startsWith(p));
|
|
1163
1461
|
}
|
|
1164
|
-
var
|
|
1462
|
+
var errName4 = (err) => String(err?.name ?? "");
|
|
1165
1463
|
var errStatus = (err) => err?.$metadata?.httpStatusCode;
|
|
1166
1464
|
function isAccessDenied(err) {
|
|
1167
|
-
const n =
|
|
1465
|
+
const n = errName4(err);
|
|
1168
1466
|
return n === "AccessDeniedException" || n === "AccessDenied" || n === "UnauthorizedOperation" || n === "AuthorizationErrorException" || errStatus(err) === 403 && !/Throttl/.test(n);
|
|
1169
1467
|
}
|
|
1170
1468
|
var NOT_FOUND_ERRORS = /* @__PURE__ */ new Set(["ResourceNotFoundException", "PipelineNotFoundException", "InvalidArnException"]);
|
|
@@ -1195,7 +1493,7 @@ async function hintedTag(deps, account, hint) {
|
|
|
1195
1493
|
try {
|
|
1196
1494
|
return await readPipelineIdTag(deps.codepipeline(hint.region), resourceArn) ?? null;
|
|
1197
1495
|
} catch (err) {
|
|
1198
|
-
if (NOT_FOUND_ERRORS.has(
|
|
1496
|
+
if (NOT_FOUND_ERRORS.has(errName4(err))) return void 0;
|
|
1199
1497
|
throw err;
|
|
1200
1498
|
}
|
|
1201
1499
|
}
|
|
@@ -1240,8 +1538,8 @@ function createRunner(config, deps) {
|
|
|
1240
1538
|
if (e?.pipelineName !== void 0 && e.pipelineName !== pipelineName) return fail("RUNNER_REFUSED");
|
|
1241
1539
|
return { ...e?.status ? { executionStatus: e.status } : {} };
|
|
1242
1540
|
} catch (err) {
|
|
1243
|
-
if (
|
|
1244
|
-
if (
|
|
1541
|
+
if (errName4(err) === "PipelineNotFoundException") return fail("PIPELINE_NOT_FOUND");
|
|
1542
|
+
if (errName4(err) === "PipelineExecutionNotFoundException") return fail("RUNNER_REFUSED");
|
|
1245
1543
|
throw err;
|
|
1246
1544
|
}
|
|
1247
1545
|
}
|
|
@@ -1255,7 +1553,7 @@ function createRunner(config, deps) {
|
|
|
1255
1553
|
}));
|
|
1256
1554
|
return ok("started", out.pipelineExecutionId ? { executionId: out.pipelineExecutionId } : {});
|
|
1257
1555
|
} catch (err) {
|
|
1258
|
-
if (
|
|
1556
|
+
if (errName4(err) === "PipelineNotFoundException") return fail("PIPELINE_NOT_FOUND");
|
|
1259
1557
|
throw err;
|
|
1260
1558
|
}
|
|
1261
1559
|
}
|
|
@@ -1272,7 +1570,7 @@ function createRunner(config, deps) {
|
|
|
1272
1570
|
reason: `Stopped by pipeline-builder request ${claims.jti}`.slice(0, 200)
|
|
1273
1571
|
}));
|
|
1274
1572
|
} catch (err) {
|
|
1275
|
-
const n =
|
|
1573
|
+
const n = errName4(err);
|
|
1276
1574
|
if (n === "DuplicatedStopRequestException") return ok("stopped", { executionId });
|
|
1277
1575
|
if (n === "PipelineNotFoundException") return fail("PIPELINE_NOT_FOUND");
|
|
1278
1576
|
if (n === "PipelineExecutionNotStoppableException" || n === "PipelineExecutionNotFoundException") return fail("RUNNER_REFUSED");
|
|
@@ -1312,16 +1610,54 @@ function createRunner(config, deps) {
|
|
|
1312
1610
|
const answer2 = await inspectRepository(inspect, deps);
|
|
1313
1611
|
return answer2 === "GITHUB_TOKEN_MISSING" ? fail(answer2) : ok("repository_reads", { results: answer2.results });
|
|
1314
1612
|
}
|
|
1613
|
+
async function inspectConnectionAction(claims, account) {
|
|
1614
|
+
const claim = claims.inspectConnection;
|
|
1615
|
+
if (!config.allowedRegions.includes(claim.region)) return fail("SOURCE_REGION_NOT_ALLOWED");
|
|
1616
|
+
const inspect = config.inspectConnection;
|
|
1617
|
+
if (claim.kind === "start") {
|
|
1618
|
+
if (!account) return internal();
|
|
1619
|
+
const started = await startInspection(claim, account.accountId, inspect, deps);
|
|
1620
|
+
return typeof started === "string" ? fail(started) : ok("inspection_started", { buildId: started.buildId });
|
|
1621
|
+
}
|
|
1622
|
+
if (claim.kind === "stop") {
|
|
1623
|
+
const stopped = await stopInspection(claim, inspect, deps);
|
|
1624
|
+
return typeof stopped === "string" ? fail(stopped) : ok("inspection_stopped", { stopped: stopped.stopped });
|
|
1625
|
+
}
|
|
1626
|
+
const status = await inspectionStatus(claim, inspect, deps);
|
|
1627
|
+
return typeof status === "string" ? fail(status) : ok("inspection_status", { ...status });
|
|
1628
|
+
}
|
|
1629
|
+
async function reportingHealth() {
|
|
1630
|
+
const r = config.reporting;
|
|
1631
|
+
if (!r) return void 0;
|
|
1632
|
+
try {
|
|
1633
|
+
const q = await deps.sqs().send(new GetQueueAttributesCommand({ QueueUrl: r.deadLetterQueueUrl, AttributeNames: ["ApproximateNumberOfMessages"] }));
|
|
1634
|
+
const failedEvents = Number.parseInt(q.Attributes?.ApproximateNumberOfMessages ?? "0", 10);
|
|
1635
|
+
let lastEventAt = null;
|
|
1636
|
+
try {
|
|
1637
|
+
const p = await deps.ssm().send(new GetParameterCommand({ Name: r.lastEventParameter }));
|
|
1638
|
+
const v = p.Parameter?.Value;
|
|
1639
|
+
lastEventAt = v && !Number.isNaN(Date.parse(v)) ? new Date(v).toISOString() : null;
|
|
1640
|
+
} catch (err) {
|
|
1641
|
+
if (errName4(err) !== "ParameterNotFound") throw err;
|
|
1642
|
+
}
|
|
1643
|
+
return { failedEvents: Number.isSafeInteger(failedEvents) && failedEvents >= 0 ? failedEvents : 0, lastEventAt };
|
|
1644
|
+
} catch (err) {
|
|
1645
|
+
deps.log("WARN", "Could not read the reporting health", { error: errName4(err) || "Error" });
|
|
1646
|
+
return void 0;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1315
1649
|
async function act(claims, account) {
|
|
1316
1650
|
if (claims.action === "ping") {
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1651
|
+
const capabilities = [
|
|
1652
|
+
...config.deploy.enabled ? [DEPLOY_CAPABILITY] : [],
|
|
1653
|
+
...config.reporting ? [EVENTS_CAPABILITY] : []
|
|
1654
|
+
];
|
|
1655
|
+
const reporting = await reportingHealth();
|
|
1656
|
+
return ok("pong", { regions: [...config.allowedRegions], capabilities, pipelinePrefixes: [...config.allowedPrefixes], ...reporting ? { reporting } : {} });
|
|
1322
1657
|
}
|
|
1658
|
+
if (INSPECT_CONNECTION_ACTIONS.includes(claims.action)) return inspectConnectionAction(claims, account);
|
|
1323
1659
|
if (Object.hasOwn(DEPLOY_ACTION_CAPABILITY, claims.action)) return deployAction(claims);
|
|
1324
|
-
if (
|
|
1660
|
+
if (SOURCE_ACTIONS.includes(claims.action)) return sourceAction(claims, account);
|
|
1325
1661
|
if (claims.action === "inspect_repository") return inspectAction(claims);
|
|
1326
1662
|
const found = await findPipeline(config, deps, account, claims.pipelineId, claims.hint);
|
|
1327
1663
|
if (claims.action === "probe") {
|
|
@@ -1336,36 +1672,56 @@ function createRunner(config, deps) {
|
|
|
1336
1672
|
return executionStatus(cp, found.name, claims);
|
|
1337
1673
|
}
|
|
1338
1674
|
async function handleRequest(jws, opts = {}) {
|
|
1675
|
+
return (await handle(jws, opts)).result;
|
|
1676
|
+
}
|
|
1677
|
+
async function handle(jws, opts = {}) {
|
|
1339
1678
|
let claims;
|
|
1340
1679
|
try {
|
|
1341
1680
|
claims = await verifyRunRequest(jws, { jwks, runnerId: config.runnerId, now: deps.now });
|
|
1342
1681
|
} catch (err) {
|
|
1343
1682
|
if (err instanceof SignatureError) {
|
|
1344
1683
|
deps.log("WARN", "Rejected a request that is not validly signed for this runner", { reason: err.message });
|
|
1345
|
-
return fail("SIGNATURE_INVALID");
|
|
1684
|
+
return { result: fail("SIGNATURE_INVALID") };
|
|
1346
1685
|
}
|
|
1347
1686
|
if (err instanceof JwksUnavailableError) {
|
|
1348
1687
|
deps.log("ERROR", "Could not fetch the platform signing keys", { reason: err.message });
|
|
1349
|
-
return internal();
|
|
1688
|
+
return { result: internal() };
|
|
1350
1689
|
}
|
|
1351
|
-
deps.log("ERROR", "Unexpected verification failure", { error:
|
|
1352
|
-
return internal();
|
|
1690
|
+
deps.log("ERROR", "Unexpected verification failure", { error: errName4(err) || "Error" });
|
|
1691
|
+
return { result: internal() };
|
|
1353
1692
|
}
|
|
1693
|
+
const connectorName = displayRunnerName(claims.name);
|
|
1694
|
+
const region = claimRegion(claims);
|
|
1695
|
+
const homeRegion = process.env.AWS_REGION?.trim();
|
|
1696
|
+
const identity = {
|
|
1697
|
+
runnerId: config.runnerId,
|
|
1698
|
+
requestId: claims.jti,
|
|
1699
|
+
...opts.account ? { accountId: opts.account.accountId } : {},
|
|
1700
|
+
...homeRegion ? { homeRegion } : {},
|
|
1701
|
+
...region ? { region } : {},
|
|
1702
|
+
...connectorName ? { name: connectorName } : {}
|
|
1703
|
+
};
|
|
1354
1704
|
const prior = replay.claim(claims.jti);
|
|
1355
1705
|
if (prior) {
|
|
1356
1706
|
deps.log("INFO", "Repeated request", { requestId: claims.jti, replayed: !!prior.result });
|
|
1357
|
-
return prior.result ?? fail("DUPLICATE");
|
|
1707
|
+
return { result: prior.result ?? fail("DUPLICATE"), identity };
|
|
1358
1708
|
}
|
|
1359
|
-
const logCtx = {
|
|
1709
|
+
const logCtx = {
|
|
1710
|
+
requestId: claims.jti,
|
|
1711
|
+
requestedBy: claims.requestedBy,
|
|
1712
|
+
action: claims.action,
|
|
1713
|
+
...claims.pipelineId ? { pipelineId: claims.pipelineId } : {},
|
|
1714
|
+
...connectorName ? { connectorName } : {}
|
|
1715
|
+
};
|
|
1360
1716
|
let result;
|
|
1361
1717
|
try {
|
|
1362
1718
|
result = await act(claims, opts.account);
|
|
1363
1719
|
} catch (err) {
|
|
1364
1720
|
if (isAccessDenied(err)) {
|
|
1365
|
-
deps.log("ERROR", "The runner role was refused by AWS \u2014 redeploy the runner stack or fix its role", { ...logCtx, error:
|
|
1721
|
+
deps.log("ERROR", "The runner role was refused by AWS \u2014 redeploy the runner stack or fix its role", { ...logCtx, error: errName4(err) });
|
|
1366
1722
|
result = fail("RUNNER_PERMISSION_DENIED");
|
|
1367
1723
|
} else {
|
|
1368
|
-
deps.log("ERROR", "Request failed", { ...logCtx, error:
|
|
1724
|
+
deps.log("ERROR", "Request failed", { ...logCtx, error: errName4(err) || "Error" });
|
|
1369
1725
|
result = internal();
|
|
1370
1726
|
}
|
|
1371
1727
|
}
|
|
@@ -1380,13 +1736,13 @@ function createRunner(config, deps) {
|
|
|
1380
1736
|
// `<project>:<uuid>` — no account id. The grant and its ciphertext are never logged.
|
|
1381
1737
|
...b.buildId ? { buildId: b.buildId } : {}
|
|
1382
1738
|
});
|
|
1383
|
-
return result;
|
|
1739
|
+
return { result, identity };
|
|
1384
1740
|
}
|
|
1385
1741
|
async function handleHttp(event, account) {
|
|
1386
|
-
const respond = (r) => ({
|
|
1742
|
+
const respond = (r, identity) => ({
|
|
1387
1743
|
statusCode: r.status,
|
|
1388
1744
|
headers: { "content-type": "application/json", "cache-control": "no-store" },
|
|
1389
|
-
body: JSON.stringify(r.body)
|
|
1745
|
+
body: JSON.stringify(identity ? { ...r.body, identity } : r.body)
|
|
1390
1746
|
});
|
|
1391
1747
|
const method = event.requestContext?.http?.method ?? event.httpMethod;
|
|
1392
1748
|
const contentType = Object.entries(event.headers ?? {}).find(([k]) => k.toLowerCase() === "content-type")?.[1] ?? "";
|
|
@@ -1395,7 +1751,8 @@ function createRunner(config, deps) {
|
|
|
1395
1751
|
if (method !== "POST" || !/^application\/jwt\s*(;|$)/i.test(contentType) || !body || Buffer.byteLength(body) > MAX_BODY_BYTES) {
|
|
1396
1752
|
return respond(fail("SIGNATURE_INVALID"));
|
|
1397
1753
|
}
|
|
1398
|
-
|
|
1754
|
+
const handled = await handle(body, { account });
|
|
1755
|
+
return respond(handled.result, handled.identity);
|
|
1399
1756
|
}
|
|
1400
1757
|
return {
|
|
1401
1758
|
process: handleRequest,
|