@intentius/chant 0.124.86 → 0.124.88
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/dist/action-pins.d.ts +1 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +2 -0
- package/dist/actor.d.ts +12 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +18 -0
- package/dist/bundle-check.d.ts +20 -5
- package/dist/bundle-check.d.ts.map +1 -1
- package/dist/bundle-check.js +20 -5
- package/dist/chant-install.d.ts +98 -0
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +204 -2
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +1 -2
- package/dist/ci-control.d.ts +1 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +1 -1
- package/dist/ci-evidence-claims.d.ts +59 -0
- package/dist/ci-evidence-claims.d.ts.map +1 -0
- package/dist/ci-evidence-claims.js +87 -0
- package/dist/ci-evidence-from-job.d.ts +103 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -0
- package/dist/ci-evidence-from-job.js +162 -0
- package/dist/ci-evidence-jobs.d.ts +69 -10
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +72 -8
- package/dist/ci-handover.d.ts +12 -0
- package/dist/ci-handover.d.ts.map +1 -1
- package/dist/ci-handover.js +15 -3
- package/dist/ci-identity.d.ts +32 -6
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +40 -8
- package/dist/ci-image.d.ts +47 -9
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +45 -18
- package/dist/ci-jobs.d.ts +1 -1
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -2
- package/dist/ci-login.d.ts +75 -13
- package/dist/ci-login.d.ts.map +1 -1
- package/dist/ci-login.js +89 -37
- package/dist/ci-product-words.d.ts +20 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +27 -1
- package/dist/ci-product.d.ts +20 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +21 -2
- package/dist/cli/handlers/approve-confirm.d.ts +14 -0
- package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
- package/dist/cli/handlers/approve-confirm.js +46 -0
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +38 -14
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +238 -26
- package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-forge-check.js +34 -17
- package/dist/cli/handlers/generated-check.d.ts +3 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -0
- package/dist/cli/handlers/generated-check.js +41 -0
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +3 -0
- package/dist/cli/handlers/local-chant.d.ts +13 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -1
- package/dist/cli/handlers/local-chant.js +42 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +42 -5
- package/dist/cli/handlers/run-wave.js +8 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -4
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +66 -0
- package/dist/cli/registry.d.ts +24 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +10 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +21 -3
- package/dist/components/check-steps.js +1 -1
- package/dist/components/pr-checks.d.ts +105 -0
- package/dist/components/pr-checks.d.ts.map +1 -0
- package/dist/components/pr-checks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +34 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +14 -1
- package/dist/components/product-pipeline.d.ts +16 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +17 -2
- package/dist/components/product-plan.d.ts +262 -3
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +243 -11
- package/dist/config.d.ts +10 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -6
- package/dist/control/consumers.d.ts +6 -0
- package/dist/control/consumers.d.ts.map +1 -1
- package/dist/control/consumers.js +6 -0
- package/dist/dead-guards.d.ts.map +1 -1
- package/dist/dead-guards.js +9 -6
- package/dist/discovery/files.d.ts +1 -1
- package/dist/discovery/files.js +1 -1
- package/dist/drift-issue.d.ts +20 -3
- package/dist/drift-issue.d.ts.map +1 -1
- package/dist/drift-issue.js +16 -0
- package/dist/drift-record.d.ts +45 -5
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +27 -6
- package/dist/floor-table.d.ts +6 -6
- package/dist/floor-table.d.ts.map +1 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +58 -20
- package/dist/floor-table.js +10 -7
- package/dist/forge-check/contract.d.ts +8 -0
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/forge-flags.d.ts +10 -0
- package/dist/forge-flags.d.ts.map +1 -1
- package/dist/forge-flags.js +31 -0
- package/dist/forge-remote.d.ts +47 -0
- package/dist/forge-remote.d.ts.map +1 -0
- package/dist/forge-remote.js +69 -0
- package/dist/generated-check.d.ts +74 -0
- package/dist/generated-check.d.ts.map +1 -0
- package/dist/generated-check.js +216 -0
- package/dist/lexicon.d.ts +16 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +49 -3
- package/dist/lifecycle/release-images.d.ts +22 -1
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +27 -3
- package/dist/lifecycle/release-ledger.d.ts +4 -3
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +3 -2
- package/dist/local-chant.d.ts +57 -3
- package/dist/local-chant.d.ts.map +1 -1
- package/dist/local-chant.js +122 -13
- package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-jobs.js +112 -0
- package/dist/op/op-waves-evidence.d.ts +17 -4
- package/dist/op/op-waves-evidence.d.ts.map +1 -1
- package/dist/op/op-waves-evidence.js +32 -10
- package/dist/op/op-waves-run.d.ts +12 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +54 -3
- package/dist/op/op-waves.d.ts +8 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +10 -0
- package/dist/op/schedule-overdue.d.ts +39 -2
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +89 -7
- package/dist/pr-forge-reads.d.ts +21 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +19 -1
- package/dist/pr-forge.d.ts +7 -1
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +7 -2
- package/dist/pr-plan-note.d.ts +24 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +11 -1
- package/dist/pr-plan-record.d.ts +47 -0
- package/dist/pr-plan-record.d.ts.map +1 -0
- package/dist/pr-plan-record.js +89 -0
- package/dist/pr-post.d.ts +40 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +79 -6
- package/dist/pr-requires.d.ts +8 -0
- package/dist/pr-requires.d.ts.map +1 -1
- package/dist/pr-requires.js +3 -1
- package/dist/ref-gate-init.d.ts +76 -0
- package/dist/ref-gate-init.d.ts.map +1 -0
- package/dist/ref-gate-init.js +144 -0
- package/dist/ref-gate-rules.d.ts +19 -0
- package/dist/ref-gate-rules.d.ts.map +1 -0
- package/dist/ref-gate-rules.js +17 -0
- package/dist/release-floors.d.ts +51 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +66 -16
- package/dist/state-migration.d.ts +23 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +39 -3
- package/dist/state-unlock.d.ts +32 -1
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +31 -0
- package/dist/wave-runtime.mjs +310 -303
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +13 -7
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -3
- package/dist/workspace/drift-cli.d.ts +1 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +5 -12
- package/dist/workspace/forge-work.d.ts +3 -2
- package/dist/workspace/forge-work.d.ts.map +1 -1
- package/dist/workspace/forge-work.js +7 -17
- package/dist/workspace/lexicon-outputs.js +2 -2
- package/dist/workspace/release-workflow.d.ts +26 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +48 -6
- package/dist/workspace/trust/check-evidence-report.d.ts +25 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +20 -0
- package/dist/workspace/trust/check-evidence.d.ts +59 -13
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence.js +101 -24
- package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
- package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.d.ts +40 -2
- package/dist/workspace/trust/dsse.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.js +34 -2
- package/dist/workspace/trust/evidence.d.ts +7 -2
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/evidence.js +5 -0
- package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
- package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/keyless-fixture.js +161 -0
- package/dist/workspace/trust/keyless.d.ts +202 -0
- package/dist/workspace/trust/keyless.d.ts.map +1 -0
- package/dist/workspace/trust/keyless.js +488 -0
- package/dist/workspace/trust/local-evidence.d.ts +3 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/op-run-statement.d.ts +2 -2
- package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/open-evidence.d.ts +67 -0
- package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/open-evidence.js +92 -0
- package/dist/workspace/trust/policy.d.ts +56 -1
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +103 -2
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +65 -3
- package/dist/workspace/trust/ref-gate.d.ts +62 -3
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate.js +75 -8
- package/dist/workspace/trust/run-statement.d.ts +3 -3
- package/dist/workspace/trust/run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/runner-identity.d.ts +56 -0
- package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
- package/dist/workspace/trust/runner-identity.js +65 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +8 -1
- package/package.json +1 -1
- package/src/action-pins.ts +2 -0
- package/src/actor.test.ts +12 -0
- package/src/actor.ts +19 -0
- package/src/bundle-check.test.ts +22 -0
- package/src/bundle-check.ts +33 -5
- package/src/chant-install.test.ts +109 -1
- package/src/chant-install.ts +243 -2
- package/src/ci-commit.test.ts +51 -5
- package/src/ci-commit.ts +1 -2
- package/src/ci-control.ts +1 -0
- package/src/ci-evidence-claims.ts +102 -0
- package/src/ci-evidence-from-job.test.ts +147 -0
- package/src/ci-evidence-from-job.ts +195 -0
- package/src/ci-evidence-jobs.ts +85 -10
- package/src/ci-handover.ts +16 -3
- package/src/ci-identity.test.ts +3 -3
- package/src/ci-identity.ts +51 -11
- package/src/ci-image.test.ts +60 -10
- package/src/ci-image.ts +78 -19
- package/src/ci-jobs.ts +7 -2
- package/src/ci-login.test.ts +131 -3
- package/src/ci-login.token-drop.test.ts +204 -0
- package/src/ci-login.ts +137 -39
- package/src/ci-product-words.ts +30 -0
- package/src/ci-product.ts +26 -1
- package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
- package/src/cli/handlers/approve-confirm.test.ts +35 -0
- package/src/cli/handlers/approve-confirm.ts +44 -0
- package/src/cli/handlers/build-source-dir.test.ts +4 -0
- package/src/cli/handlers/build.ts +20 -2
- package/src/cli/handlers/ci-check.ts +35 -13
- package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
- package/src/cli/handlers/ci-evidence.ts +223 -24
- package/src/cli/handlers/ci-forge-check.ts +22 -9
- package/src/cli/handlers/generated-check.ts +39 -0
- package/src/cli/handlers/lifecycle.test.ts +20 -0
- package/src/cli/handlers/lifecycle.ts +4 -0
- package/src/cli/handlers/local-chant.ts +39 -1
- package/src/cli/handlers/pr.ts +43 -5
- package/src/cli/handlers/run-wave.ts +7 -0
- package/src/cli/main.ts +38 -4
- package/src/cli/parse-args.ts +46 -0
- package/src/cli/registry.ts +24 -0
- package/src/components/check-hooks.ts +25 -3
- package/src/components/check-report-summary.test.ts +78 -0
- package/src/components/check-steps.ts +1 -1
- package/src/components/pr-checks.ts +159 -0
- package/src/components/pr-pipeline.ts +41 -1
- package/src/components/product-pipeline.ts +25 -3
- package/src/components/product-plan.test.ts +102 -1
- package/src/components/product-plan.ts +419 -14
- package/src/config.ts +13 -8
- package/src/control/consumers.ts +7 -0
- package/src/dead-guards.test.ts +27 -5
- package/src/dead-guards.ts +9 -6
- package/src/discovery/files.ts +1 -1
- package/src/drift-issue.test.ts +29 -1
- package/src/drift-issue.ts +28 -3
- package/src/drift-record.test.ts +25 -0
- package/src/drift-record.ts +55 -6
- package/src/floor-table.data.ts +58 -20
- package/src/floor-table.ts +12 -9
- package/src/forge-check/contract.ts +11 -1
- package/src/forge-check/forge-check.test.ts +8 -0
- package/src/forge-check/index.ts +2 -0
- package/src/forge-flags.test.ts +25 -1
- package/src/forge-flags.ts +34 -0
- package/src/forge-remote.test.ts +37 -0
- package/src/forge-remote.ts +79 -0
- package/src/generated-check.e2e.test.ts +98 -0
- package/src/generated-check.test.ts +104 -0
- package/src/generated-check.ts +269 -0
- package/src/lexicon.ts +17 -0
- package/src/lifecycle/publish-npm.ts +56 -3
- package/src/lifecycle/release-catalog.test.ts +2 -2
- package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
- package/src/lifecycle/release-images.test.ts +44 -0
- package/src/lifecycle/release-images.ts +39 -3
- package/src/lifecycle/release-ledger.ts +4 -3
- package/src/local-chant.e2e.test.ts +81 -6
- package/src/local-chant.test.ts +22 -3
- package/src/local-chant.ts +130 -13
- package/src/op/op-waves-evidence-jobs.ts +134 -0
- package/src/op/op-waves-evidence.test.ts +37 -4
- package/src/op/op-waves-evidence.ts +32 -11
- package/src/op/op-waves-run.ts +57 -2
- package/src/op/op-waves.ts +11 -0
- package/src/op/schedule-overdue.test.ts +83 -1
- package/src/op/schedule-overdue.ts +107 -9
- package/src/pr-forge-reads-compare.test.ts +2 -1
- package/src/pr-forge-reads.ts +37 -1
- package/src/pr-forge.ts +14 -3
- package/src/pr-plan-note.ts +32 -3
- package/src/pr-plan-record.test.ts +75 -0
- package/src/pr-plan-record.ts +101 -0
- package/src/pr-post-plan-note.test.ts +60 -0
- package/src/pr-post.test.ts +30 -0
- package/src/pr-post.ts +110 -6
- package/src/pr-requires.test.ts +20 -0
- package/src/pr-requires.ts +10 -1
- package/src/ref-gate-init.ts +189 -0
- package/src/ref-gate-rules.ts +26 -0
- package/src/release-floors.ts +88 -16
- package/src/state-migration-record.test.ts +90 -0
- package/src/state-migration.test.ts +1 -1
- package/src/state-migration.ts +52 -3
- package/src/state-unlock.test.ts +33 -1
- package/src/state-unlock.ts +49 -1
- package/src/workspace/ci-green-cli.ts +12 -6
- package/src/workspace/ci-green.ts +4 -3
- package/src/workspace/drift-cli.ts +6 -18
- package/src/workspace/forge-work.ts +7 -14
- package/src/workspace/lexicon-outputs.ts +2 -2
- package/src/workspace/release-workflow.test.ts +70 -0
- package/src/workspace/release-workflow.ts +56 -8
- package/src/workspace/trust/check-evidence-report.ts +33 -0
- package/src/workspace/trust/check-evidence.test.ts +3 -3
- package/src/workspace/trust/check-evidence.ts +110 -28
- package/src/workspace/trust/ci-tag-statement.ts +2 -2
- package/src/workspace/trust/dsse.ts +48 -4
- package/src/workspace/trust/evidence.ts +7 -2
- package/src/workspace/trust/keyless-fixture.ts +214 -0
- package/src/workspace/trust/keyless.test.ts +220 -0
- package/src/workspace/trust/keyless.ts +557 -0
- package/src/workspace/trust/local-evidence.ts +3 -1
- package/src/workspace/trust/op-run-statement.ts +2 -2
- package/src/workspace/trust/open-evidence.ts +129 -0
- package/src/workspace/trust/policy.ts +129 -2
- package/src/workspace/trust/ref-gate-cli.ts +59 -3
- package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
- package/src/workspace/trust/ref-gate.ts +90 -8
- package/src/workspace/trust/run-statement.ts +3 -3
- package/src/workspace/trust/runner-identity.ts +92 -0
- package/src/workspace/trust/trust-files.test.ts +6 -0
- package/src/workspace/trust/trust-files.ts +14 -1
package/src/ci-image.ts
CHANGED
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
* product records others in its own config and passes them as `sha256`.
|
|
17
17
|
* - {@link ciToolFetchScript} is the shell that downloads one release and
|
|
18
18
|
* checks it, for an image's fetch stage; {@link ciToolInstallLine} is the
|
|
19
|
-
* job line that runs it unless the binary is there
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* job line that runs it unless the binary is there (with `sudo`, or under
|
|
20
|
+
* a root such as `$RUNNER_TEMP/chant-tools`, for a job that is not root,
|
|
21
|
+
* #4908); {@link installCiTool} does the same from Node, for a product
|
|
22
|
+
* that installs a pinned release at run time.
|
|
22
23
|
* - {@link productImageStages} is a product's image as stages a Dockerfile
|
|
23
24
|
* takes (the docker lexicon's `new Dockerfile({ stages })`), and
|
|
24
25
|
* {@link productImageDockerfile} is the same as text. The product passes
|
|
@@ -46,9 +47,9 @@ import { tmpdir } from "node:os";
|
|
|
46
47
|
import { join } from "node:path";
|
|
47
48
|
import { gunzipSync, inflateRawSync } from "node:zlib";
|
|
48
49
|
import { tarEntry } from "./policy-engine";
|
|
49
|
-
import { CI_IMAGE_FLOOR } from "./release-floors";
|
|
50
|
+
import { CI_IMAGE_DOCKER_STAGES_FLOOR, CI_IMAGE_FLOOR, CI_IMAGE_NON_ROOT_FLOOR } from "./release-floors";
|
|
50
51
|
|
|
51
|
-
export { CI_IMAGE_FLOOR };
|
|
52
|
+
export { CI_IMAGE_DOCKER_STAGES_FLOOR, CI_IMAGE_FLOOR, CI_IMAGE_NON_ROOT_FLOOR };
|
|
52
53
|
|
|
53
54
|
// ---------------------------------------------------------------------------
|
|
54
55
|
// Engine releases
|
|
@@ -230,6 +231,14 @@ export const CI_TOOL_SHA256: Readonly<Record<string, string>> = {
|
|
|
230
231
|
"plunge-0.2.0-linux-arm64": "c176a82f038164085aa19c8ad6530d6022e560e124050e535dbe364ae0473357",
|
|
231
232
|
"aws-cli-2.22.0-linux-amd64": "f315aa564190a12ae05a05bd8ab7b0645dd4a1ad71ce9e47dae4ff3dfeee8ceb",
|
|
232
233
|
"aws-cli-2.22.0-linux-arm64": "c932ac00901ea3c430f3829140b8dc00fa6e9b8b99d6891929a4795947de7f3e",
|
|
234
|
+
// #4908: terragucci's image pins (its TOOL_SHA256, from terraform_1.14.9_SHA256SUMS and terragrunt v1.2.0's SHA256SUMS)
|
|
235
|
+
// and the AWS CLI its drift job installs (its AWS_CLI), so a product's image and job lines need no sums of their own.
|
|
236
|
+
"terraform-1.14.9-linux-amd64": "2e5cffc20a0b48a67a76268723bd5a10b8666f69b2aa4f04906e206726bedd63",
|
|
237
|
+
"terraform-1.14.9-linux-arm64": "863002085b886453795d9ff4b8989b8468784478150b70ba8a1df3e3ad66da99",
|
|
238
|
+
"terragrunt-1.2.0-linux-amd64": "45b6df8a8494c8cfe34b4abf919e894709557163e4d3b5704d11083002ab787a",
|
|
239
|
+
"terragrunt-1.2.0-linux-arm64": "b069ce4310572bc46ee6f057057acc4bc6a9077ef8687e157a64b0551290a371",
|
|
240
|
+
"aws-cli-2.37.9-linux-amd64": "6b3a6a3d7bb3997928f0bdf7b866914224abf242c2e54e1dcebbe84bee64f356",
|
|
241
|
+
"aws-cli-2.37.9-linux-arm64": "e7d2cca3622af4765871fe9ce7eeed03acd09dca10a99ebc46e92f79d78765c0",
|
|
233
242
|
};
|
|
234
243
|
|
|
235
244
|
/** One release file of one tool for one architecture. */
|
|
@@ -256,6 +265,13 @@ export interface CiToolRelease {
|
|
|
256
265
|
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/;
|
|
257
266
|
const SHA256 = /^[0-9a-f]{64}$/;
|
|
258
267
|
const DIR = /^\/[A-Za-z0-9._/-]*$/;
|
|
268
|
+
/**
|
|
269
|
+
* A directory a job line may name (#4908): an absolute path, or one under a
|
|
270
|
+
* variable the job's shell expands, such as `$RUNNER_TEMP/chant-tools` or
|
|
271
|
+
* `$HOME/.local/bin`, so a job that is not root installs where it can write.
|
|
272
|
+
* Every line writes it inside double quotes.
|
|
273
|
+
*/
|
|
274
|
+
const SHELL_DIR = /^(?:\/|\$[A-Za-z_][A-Za-z0-9_]*(?=\/|$)|\$\{[A-Za-z_][A-Za-z0-9_]*\})[A-Za-z0-9._/-]*$/;
|
|
259
275
|
|
|
260
276
|
function spec(tool: CiTool): ToolSpec {
|
|
261
277
|
const s = TOOLS[tool];
|
|
@@ -304,10 +320,10 @@ export function ciToolSha256(tool: CiTool, version: string, given?: Partial<Reco
|
|
|
304
320
|
return out;
|
|
305
321
|
}
|
|
306
322
|
|
|
307
|
-
/** Where a tool lives once installed: `<root>/<tool>-<version>`. */
|
|
323
|
+
/** Where a tool lives once installed: `<root>/<tool>-<version>`. A job line's root may start with a shell variable (#4908). */
|
|
308
324
|
export function ciToolDir(tool: CiTool, version: string, root: string): string {
|
|
309
325
|
checkVersion(tool, version);
|
|
310
|
-
if (!
|
|
326
|
+
if (!SHELL_DIR.test(root)) throw new Error(`a tool root is an absolute path of letters, digits and ._/-, or one under a variable such as $RUNNER_TEMP, not ${JSON.stringify(root)}`);
|
|
311
327
|
return `${root.replace(/\/+$/, "")}/${tool}-${version}`;
|
|
312
328
|
}
|
|
313
329
|
|
|
@@ -340,6 +356,12 @@ export interface CiToolFetchOptions extends CiToolCheckOptions {
|
|
|
340
356
|
arch?: string;
|
|
341
357
|
/** A shell word for the checksums file's URL, such as `"$CHECKSUMS_URL"`. Default the release's own. */
|
|
342
358
|
checksumsUrl?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Write into `dir` with `sudo` (#4908), for a job that runs as a user who
|
|
361
|
+
* cannot write the tool root, such as GitHub's hosted runners under
|
|
362
|
+
* /opt. The download and the check run as the job's user. Default false.
|
|
363
|
+
*/
|
|
364
|
+
sudo?: boolean;
|
|
343
365
|
}
|
|
344
366
|
|
|
345
367
|
function needPins(tool: CiTool, version: string, sums: Partial<Record<CiToolArch, string>>, requirePin: boolean): void {
|
|
@@ -358,7 +380,8 @@ function needPins(tool: CiTool, version: string, sums: Partial<Record<CiToolArch
|
|
|
358
380
|
* release needs a recorded sha256 it lacks.
|
|
359
381
|
*/
|
|
360
382
|
export function ciToolFetchScript(tool: CiTool, version: string, options: CiToolFetchOptions): string {
|
|
361
|
-
if (!
|
|
383
|
+
if (!SHELL_DIR.test(options.dir)) throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, or one under a variable such as $RUNNER_TEMP, not ${JSON.stringify(options.dir)}`);
|
|
384
|
+
const su = options.sudo ? "sudo " : "";
|
|
362
385
|
const s = spec(tool);
|
|
363
386
|
const sums = ciToolSha256(tool, version, options.sha256);
|
|
364
387
|
needPins(tool, version, sums, options.requirePin === true);
|
|
@@ -387,33 +410,49 @@ export function ciToolFetchScript(tool: CiTool, version: string, options: CiTool
|
|
|
387
410
|
} else {
|
|
388
411
|
lines.push(`{ [ -n "$want" ] || { echo "${name}: no sha256 is recorded for $f" >&2; exit 1; }; }`);
|
|
389
412
|
}
|
|
390
|
-
lines.push(`echo "$want $t/$f" | sha256sum -c - >/dev/null`,
|
|
413
|
+
lines.push(`echo "$want $t/$f" | sha256sum -c - >/dev/null`, `${su}mkdir -p "${dir}"`);
|
|
391
414
|
const member = s.member?.("$w") ?? s.bin;
|
|
392
415
|
switch (s.layout) {
|
|
393
416
|
case "binary":
|
|
394
|
-
lines.push(
|
|
417
|
+
lines.push(`${su}install -m 0755 "$t/$f" "${dir}/${s.bin}"`);
|
|
395
418
|
break;
|
|
396
419
|
case "tar.gz":
|
|
397
|
-
lines.push(`tar -xzf "$t/$f" -C "$t" "${member}"`,
|
|
420
|
+
lines.push(`tar -xzf "$t/$f" -C "$t" "${member}"`, `${su}install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
|
|
398
421
|
break;
|
|
399
422
|
case "zip":
|
|
400
|
-
lines.push(`unzip -q -o "$t/$f" "${member}" -d "$t"`,
|
|
423
|
+
lines.push(`unzip -q -o "$t/$f" "${member}" -d "$t"`, `${su}install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
|
|
401
424
|
break;
|
|
402
425
|
case "tree":
|
|
403
|
-
lines.push(
|
|
426
|
+
lines.push(`${su}tar -xzf "$t/$f" -C "${dir}" --strip-components=1`);
|
|
404
427
|
break;
|
|
405
428
|
case "aws-cli":
|
|
406
|
-
lines.push(`unzip -q "$t/$f" -d "$t"`,
|
|
429
|
+
lines.push(`unzip -q "$t/$f" -d "$t"`, `${su}"$t/aws/install" -i "${dir}" -b "${dir}/bin"`);
|
|
407
430
|
break;
|
|
408
431
|
}
|
|
409
432
|
return lines.join(" && ");
|
|
410
433
|
}
|
|
411
434
|
|
|
412
435
|
export interface CiToolInstallOptions extends CiToolCheckOptions {
|
|
413
|
-
/**
|
|
436
|
+
/**
|
|
437
|
+
* Where the versioned directories live. Default {@link CI_TOOL_ROOT}. It
|
|
438
|
+
* may start with a variable the job's shell expands (#4908), such as
|
|
439
|
+
* `$RUNNER_TEMP/chant-tools`, for a job that is not root.
|
|
440
|
+
*/
|
|
414
441
|
root?: string;
|
|
415
|
-
/** Link the binary into
|
|
442
|
+
/** Link the binary into `binDir` (default true). `false` leaves PATH alone, for a pin a step runs by its path. */
|
|
416
443
|
link?: boolean;
|
|
444
|
+
/**
|
|
445
|
+
* Where the link goes. Default /usr/local/bin. Like `root` it may start
|
|
446
|
+
* with a variable (#4908), such as `$HOME/.local/bin`; the job puts it on
|
|
447
|
+
* PATH.
|
|
448
|
+
*/
|
|
449
|
+
binDir?: string;
|
|
450
|
+
/**
|
|
451
|
+
* Install into `root` and link into `binDir` with `sudo` (#4908), for a
|
|
452
|
+
* job that runs as a user who cannot write them, as on GitHub's hosted
|
|
453
|
+
* runners. The download and the check run as the job's user. Default false.
|
|
454
|
+
*/
|
|
455
|
+
sudo?: boolean;
|
|
417
456
|
/** Skip the install when any `<bin>` is on PATH, whatever its version. Default false: only the versioned directory counts. */
|
|
418
457
|
onPath?: boolean;
|
|
419
458
|
}
|
|
@@ -433,9 +472,15 @@ export function ciToolInstallLine(tool: CiTool, version: string, options: CiTool
|
|
|
433
472
|
const dir = ciToolDir(tool, version, root);
|
|
434
473
|
const bin = ciToolBin(tool, version, root);
|
|
435
474
|
const s = spec(tool);
|
|
436
|
-
const
|
|
475
|
+
const binDir = (options.binDir ?? "/usr/local/bin").replace(/(.)\/+$/, "$1");
|
|
476
|
+
if (!SHELL_DIR.test(binDir)) throw new Error(`binDir is an absolute path of letters, digits and ._/-, or one under a variable such as $HOME, not ${JSON.stringify(options.binDir)}`);
|
|
477
|
+
const su = options.sudo ? "sudo " : "";
|
|
478
|
+
const install = `(set -e; ${ciToolFetchScript(tool, version, { dir, sha256: options.sha256, requirePin: options.requirePin, sudo: options.sudo })})`;
|
|
437
479
|
const inDir = `[ -x "${bin}" ]`;
|
|
438
|
-
|
|
480
|
+
// A plain path is written as it always was; one under a variable is quoted, so the shell expands it as one word.
|
|
481
|
+
const target = DIR.test(binDir) ? `${binDir}/${s.bin}` : `"${binDir}/${s.bin}"`;
|
|
482
|
+
const link = `${su}${options.binDir !== undefined ? `mkdir -p "${binDir}" && ${su}` : ""}ln -sf "${bin}" ${target}`;
|
|
483
|
+
const line = options.link === false ? `${inDir} || ${install}` : `{ ${inDir} || ${install}; } && ${link}`;
|
|
439
484
|
return options.onPath ? `command -v ${s.bin} >/dev/null 2>&1 || { ${line}; }` : line;
|
|
440
485
|
}
|
|
441
486
|
|
|
@@ -582,7 +627,19 @@ export const CI_BASE_IMAGES = {
|
|
|
582
627
|
export const CI_IMAGE_LABEL_ARG = "CHANT_RELEASE_LABEL";
|
|
583
628
|
|
|
584
629
|
/** One Dockerfile instruction, as the docker lexicon's stage `steps` take it: `{ run: "..." }`. */
|
|
585
|
-
|
|
630
|
+
/** The Dockerfile instructions a {@link CiImageStep} names. */
|
|
631
|
+
export type CiImageInstruction = "arg" | "env" | "run" | "copy" | "label" | "cmd" | "user" | "workdir" | "expose" | "entrypoint";
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* One Dockerfile instruction, as the docker lexicon's stage `steps` take it:
|
|
635
|
+
* `{ run: "..." }`. One key each, the others `never`, the shape of the
|
|
636
|
+
* lexicon's `DockerfileStep`, so `new Dockerfile({ stages:
|
|
637
|
+
* productImageStages(spec) })` compiles under `exactOptionalPropertyTypes`
|
|
638
|
+
* (#4932).
|
|
639
|
+
*/
|
|
640
|
+
export type CiImageStep = {
|
|
641
|
+
[K in CiImageInstruction]: { readonly [P in K]: string } & { readonly [P in Exclude<CiImageInstruction, K>]?: never };
|
|
642
|
+
}[CiImageInstruction];
|
|
586
643
|
|
|
587
644
|
/** One stage, as the docker lexicon's `new Dockerfile({ stages })` takes it. */
|
|
588
645
|
export interface CiImageStage {
|
|
@@ -736,6 +793,8 @@ export function productImageStages(spec: ProductImageSpec): CiImageStage[] {
|
|
|
736
793
|
for (const p of spec.npm ?? []) if (!PKG.test(p)) throw new Error(`npm package ${JSON.stringify(p)} is not a name at an exact version`);
|
|
737
794
|
if (spec.chant !== undefined && !VERSION.test(spec.chant)) throw new Error(`chant ${JSON.stringify(spec.chant)} is not a release version`);
|
|
738
795
|
const root = spec.toolRoot ?? `/opt/${spec.product}`;
|
|
796
|
+
// An image's COPY takes no shell variable, so the tool root is a plain path here.
|
|
797
|
+
if (!DIR.test(root)) throw new Error(`toolRoot ${JSON.stringify(root)} is not an absolute path of letters, digits and ._/-`);
|
|
739
798
|
const tools = spec.tools ?? [];
|
|
740
799
|
const seen = new Set<string>();
|
|
741
800
|
for (const t of tools) {
|
package/src/ci-jobs.ts
CHANGED
|
@@ -339,6 +339,9 @@ const USES_PATTERN = /^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)((?:\/[A-Za-z0-9_.-]+
|
|
|
339
339
|
export function assertSetupSteps(name: string, setup: OpSetupStep[]): void {
|
|
340
340
|
setup.forEach((step, index) => {
|
|
341
341
|
const where = `Scheduled Op "${name}" setup step ${index + 1}`;
|
|
342
|
+
if (step.name !== undefined && (step.name.trim() === "" || /[\r\n]/.test(step.name))) {
|
|
343
|
+
throw new Error(`${where} has a blank or multi-line \`name\`. Give the step a one-line name, or leave it out.`);
|
|
344
|
+
}
|
|
342
345
|
if ("uses" in step) {
|
|
343
346
|
const ref = step.uses.trim();
|
|
344
347
|
const match = USES_PATTERN.exec(ref);
|
|
@@ -368,16 +371,18 @@ export function assertSetupSteps(name: string, setup: OpSetupStep[]): void {
|
|
|
368
371
|
});
|
|
369
372
|
}
|
|
370
373
|
|
|
371
|
-
/** One setup entry as a GitHub Actions step: `with:` and `env:` only when they hold something. */
|
|
374
|
+
/** One setup entry as a GitHub Actions step: its `name` when it has one (#4932), `with:` and `env:` only when they hold something. */
|
|
372
375
|
export function setupStepDoc(step: OpSetupStep): Record<string, unknown> {
|
|
376
|
+
const name = step.name !== undefined ? { name: step.name } : {};
|
|
373
377
|
if ("uses" in step) {
|
|
374
378
|
return {
|
|
379
|
+
...name,
|
|
375
380
|
uses: step.uses,
|
|
376
381
|
...nonEmpty("with", step.with),
|
|
377
382
|
...nonEmpty("env", step.env),
|
|
378
383
|
};
|
|
379
384
|
}
|
|
380
|
-
return { run: step.run, ...nonEmpty("env", step.env) };
|
|
385
|
+
return { ...name, run: step.run, ...nonEmpty("env", step.env) };
|
|
381
386
|
}
|
|
382
387
|
|
|
383
388
|
/**
|
package/src/ci-login.test.ts
CHANGED
|
@@ -13,8 +13,8 @@ import { tmpdir } from "node:os";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { promisify } from "node:util";
|
|
15
15
|
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
16
|
-
import { cloudLogin, forgejoCloudLogin, githubCloudLogin, gitlabCloudLogin, LOGIN_JS, LOGIN_SPEC_ENV, type CloudLoginSpec, type LoginForge } from "./ci-login";
|
|
17
|
-
import { CLOUD_TARGETS_ENV, resolveCloudIdentity, targetCloudEnv, type CloudIdentityDeclaration } from "./ci-identity";
|
|
16
|
+
import { cloudLogin, cloudLoginSpec, forgejoCloudLogin, githubCloudLogin, GITLAB_LOGIN_VARS, gitlabCloudLogin, LOGIN_JS, LOGIN_SPEC_ENV, type CloudLoginSpec, type LoginForge } from "./ci-login";
|
|
17
|
+
import { CLOUD_TARGETS_ENV, CLOUD_TRADED_ENV, cloudsTraded, resolveCloudIdentity, targetCloudEnv, TRADE_SPEC_ENV, tradeLine, type CloudIdentityDeclaration, type CloudTradeSpec } from "./ci-identity";
|
|
18
18
|
import { EMULATED_JWT_PREFIX, startOidcEmulator, type OidcEmulator } from "./__fixtures__/oidc-emulator";
|
|
19
19
|
|
|
20
20
|
const run = promisify(execFile);
|
|
@@ -78,7 +78,7 @@ describe("the rendered login (#4788)", () => {
|
|
|
78
78
|
expect(() => githubCloudLogin({ pulumi: { organization: "o", audience: "a", token: "team:x" } } as unknown as CloudLoginSpec)).toThrow(/Pulumi Cloud\) is traded/);
|
|
79
79
|
expect(() => githubCloudLogin({ azure: { ...SPEC.azure!, database: true } } as unknown as CloudLoginSpec)).toThrow(/no database token/);
|
|
80
80
|
expect(() => githubCloudLogin({ aws: { role: "arn:aws:iam::1:role/a b" } })).toThrow(/role is .*printable ASCII with no space/);
|
|
81
|
-
expect(() => githubCloudLogin({
|
|
81
|
+
expect(() => githubCloudLogin({ azure: { tenantId: TENANT } })).toThrow(/names no identity/);
|
|
82
82
|
expect(() => githubCloudLogin({ aws: { role: "r", sessionName: "x" } })).toThrow(/sessionName/);
|
|
83
83
|
expect(() => githubCloudLogin({ aws: { role: "r", tokenFile: "$(id)" } })).toThrow(/tokenFile/);
|
|
84
84
|
expect(() => githubCloudLogin({ azure: { tenantId: TENANT, targets: [{ targets: ["a"], clientId: "c" }], cli: true } })).toThrow(/needs clientId/);
|
|
@@ -233,3 +233,131 @@ describe("the login, run (#4788)", () => {
|
|
|
233
233
|
expect(lines[1]).toBe(`account set --subscription ${SPEC.azure!.subscriptionId}`);
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
|
+
|
|
237
|
+
describe("the gaps terragucci's login needs closed (#4930)", () => {
|
|
238
|
+
let emu: OidcEmulator;
|
|
239
|
+
beforeAll(async () => {
|
|
240
|
+
emu = await startOidcEmulator();
|
|
241
|
+
});
|
|
242
|
+
afterAll(async () => {
|
|
243
|
+
await emu.close();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const parseEnv = (text: string): Record<string, string> => Object.fromEntries(text.trim().split("\n").filter(Boolean).map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)]));
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Runs a login and then `env` in one shell with -e off, as terragucci's
|
|
250
|
+
* steps run (they read each stage's exit code): the variables the same
|
|
251
|
+
* step sees, and what `$GITHUB_ENV` got.
|
|
252
|
+
*/
|
|
253
|
+
async function oneStep(forge: LoginForge, spec: CloudLoginSpec, sameStep: boolean, env: Record<string, string> = {}) {
|
|
254
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4930-"));
|
|
255
|
+
const githubEnv = join(dir, "github-env");
|
|
256
|
+
writeFileSync(githubEnv, "");
|
|
257
|
+
const { steps, idTokens } = cloudLogin(forge, spec, { sameStep });
|
|
258
|
+
const tokens = forge === "gitlab" ? Object.fromEntries(Object.keys(idTokens).map((k) => [k, `eyJgitlab.${k}.1`])) : emu.requestEnv;
|
|
259
|
+
const script = ["set +e", ...steps[0]!.run, "env"].join("\n");
|
|
260
|
+
const r = await run("bash", ["-c", script], { env: { PATH: process.env.PATH!, GITHUB_ENV: githubEnv, RUNNER_TEMP: dir, TMPDIR: dir, ...tokens, ...env } }).catch((e: { stdout: string; stderr: string; code: number }) => ({ stdout: e.stdout, stderr: e.stderr, failed: e.code }));
|
|
261
|
+
return { dir, step: parseEnv(r.stdout), githubEnv: parseEnv(readFileSync(githubEnv, "utf-8")), run: r };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
test.each(FORGES)("%s: a spec with no region leaves the job's region, and one that names it sets it as before", async (forge) => {
|
|
265
|
+
const none = await oneStep(forge, { aws: { role: "arn:aws:iam::1:role/p" } }, true, { AWS_REGION: "ap-south-1", AWS_DEFAULT_REGION: "ap-south-1" });
|
|
266
|
+
expect(none.step).toMatchObject({ AWS_ROLE_ARN: "arn:aws:iam::1:role/p", AWS_REGION: "ap-south-1", AWS_DEFAULT_REGION: "ap-south-1" });
|
|
267
|
+
const unset = await oneStep(forge, { aws: { role: "arn:aws:iam::1:role/p" } }, true);
|
|
268
|
+
expect(unset.step.AWS_REGION).toBeUndefined();
|
|
269
|
+
expect(unset.step.AWS_DEFAULT_REGION).toBeUndefined();
|
|
270
|
+
expect(cloudLoginSpec({ aws: { role: "r" } })).toEqual({ aws: { role: "r", audience: "sts.amazonaws.com" } });
|
|
271
|
+
const named = await oneStep(forge, SPEC, true);
|
|
272
|
+
expect(named.step).toMatchObject({ AWS_REGION: "eu-west-1", AWS_DEFAULT_REGION: "eu-west-1" });
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("a spec that names a region renders as before: the same spec, in the same order", () => {
|
|
276
|
+
expect(cloudLoginSpec(SPEC).aws).toEqual({ role: SPEC.aws!.role, region: "eu-west-1", sessionName: "terragucci-plan", audience: "sts.amazonaws.com" });
|
|
277
|
+
expect(Object.keys(cloudLoginSpec(SPEC).aws!)).toEqual(["role", "region", "sessionName", "audience"]);
|
|
278
|
+
expect(Object.keys(cloudLoginSpec({ aws: { region: "eu-west-1", role: "r" } }).aws!)).toEqual(["region", "role", "audience"]);
|
|
279
|
+
for (const forge of FORGES) expect(cloudLogin(forge, SPEC, { sameStep: false })).toEqual(cloudLogin(forge, SPEC));
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test.each(["github", "forgejo"] as const)("%s: sameStep exports into the step that runs the login, and leaves $GITHUB_ENV alone", async (forge) => {
|
|
283
|
+
const { step, githubEnv, run: r } = await oneStep(forge, SPEC, true);
|
|
284
|
+
expect(r).not.toHaveProperty("failed");
|
|
285
|
+
expect(githubEnv).toEqual({});
|
|
286
|
+
expect(step).toMatchObject({ AWS_ROLE_ARN: SPEC.aws!.role, ARM_CLIENT_ID: SPEC.azure!.clientId });
|
|
287
|
+
expect(readFileSync(step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toContain(Buffer.from(AUD.aws).toString("base64url"));
|
|
288
|
+
expect(JSON.parse(readFileSync(step.GOOGLE_APPLICATION_CREDENTIALS!, "utf-8")).type).toBe("external_account");
|
|
289
|
+
for (const k of [LOGIN_SPEC_ENV, GITLAB_LOGIN_VARS]) expect(step[k]).toBeUndefined();
|
|
290
|
+
// Without it, the step itself sees nothing: the variables are for later steps.
|
|
291
|
+
const later = await oneStep(forge, SPEC, false);
|
|
292
|
+
expect(later.step.AWS_ROLE_ARN).toBeUndefined();
|
|
293
|
+
expect(later.githubEnv.AWS_ROLE_ARN).toBe(SPEC.aws!.role);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("gitlab: sameStep is the script's own lines, as before, and the id_tokens variables are unset", async () => {
|
|
297
|
+
const { step, run: r } = await oneStep("gitlab", SPEC, true);
|
|
298
|
+
expect(r).not.toHaveProperty("failed");
|
|
299
|
+
expect(step).toMatchObject({ AWS_ROLE_ARN: SPEC.aws!.role });
|
|
300
|
+
expect(readFileSync(step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toBe("eyJgitlab.CHANT_ID_TOKEN_AWS.1");
|
|
301
|
+
for (const k of ["CHANT_ID_TOKEN_AWS", "CHANT_ID_TOKEN_GCP", "CHANT_ID_TOKEN_AZURE", LOGIN_SPEC_ENV]) expect(step[k]).toBeUndefined();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test.each(FORGES)("%s: sameStep stops the step on a failed login even with -e off, before the next line", async (forge) => {
|
|
305
|
+
const { run: r, step } = await oneStep(forge, { aws: { role: "r", tokenFile: "$NOWHERE/token" } }, true, { NOWHERE: "/nonexistent-4930" });
|
|
306
|
+
expect(r).toMatchObject({ failed: 1, stderr: expect.stringContaining("aws's tokenFile /nonexistent-4930/token cannot be read") });
|
|
307
|
+
expect(step).toEqual({});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test.each(FORGES)("%s: an AWS spec with no role points the job at the token file alone, as a Terragrunt credentials job takes it", async (forge) => {
|
|
311
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4930-tok-"));
|
|
312
|
+
writeFileSync(join(dir, "aws"), "eyJstaged.token.1\n");
|
|
313
|
+
expect(cloudLogin(forge, { aws: { tokenFile: "$STAGED/aws" } }).idTokens).toEqual({});
|
|
314
|
+
const staged = await oneStep(forge, { aws: { tokenFile: "$STAGED/aws", sessionName: "terragucci-plan" } }, true, { STAGED: dir });
|
|
315
|
+
expect(staged.run).not.toHaveProperty("failed");
|
|
316
|
+
expect(staged.step).toMatchObject({ AWS_WEB_IDENTITY_TOKEN_FILE: join(dir, "aws"), AWS_ROLE_SESSION_NAME: "terragucci-plan" });
|
|
317
|
+
expect(staged.step.AWS_ROLE_ARN).toBeUndefined();
|
|
318
|
+
// With no tokenFile the job requests the token, as for a role.
|
|
319
|
+
expect(cloudLogin(forge, { aws: {} }).idTokens).toEqual({ CHANT_ID_TOKEN_AWS: AUD.aws });
|
|
320
|
+
const requested = await oneStep(forge, { aws: {} }, true);
|
|
321
|
+
expect(readFileSync(requested.step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toMatch(forge === "gitlab" ? /^eyJgitlab\.CHANT_ID_TOKEN_AWS\.1$/ : new RegExp(Buffer.from(AUD.aws).toString("base64url")));
|
|
322
|
+
expect(requested.step.AWS_ROLE_SESSION_NAME).toBe("chant");
|
|
323
|
+
// GCP and Azure still need an identity: their files and variables name one.
|
|
324
|
+
expect(() => cloudLogin(forge, { gcp: { provider: PROVIDER } })).toThrow(/names no identity/);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("an AWS spec with roles by target and none of its own: each target's role, and the token file for the rest", async () => {
|
|
328
|
+
const { step } = await oneStep("github", { aws: { targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] } }, true, { AWS_REGION: "ap-south-1" });
|
|
329
|
+
expect(step.AWS_ROLE_ARN).toBeUndefined();
|
|
330
|
+
expect(step.AWS_WEB_IDENTITY_TOKEN_FILE).toBeDefined();
|
|
331
|
+
const prod = targetCloudEnv(step, "envs/prod/net");
|
|
332
|
+
expect(prod).toMatchObject({ AWS_ROLE_ARN: "arn:aws:iam::1:role/prod", AWS_WEB_IDENTITY_TOKEN_FILE: step.AWS_WEB_IDENTITY_TOKEN_FILE, AWS_REGION: "ap-south-1" });
|
|
333
|
+
expect(targetCloudEnv(step, "envs/dev/net").AWS_ROLE_ARN).toBeUndefined();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test.each(FORGES)("%s: a login's targets file is no trade's: CHANT_CLOUD_TRADED stays unset", async (forge) => {
|
|
337
|
+
const spec: CloudLoginSpec = { aws: { role: "arn:aws:iam::1:role/default", targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] } };
|
|
338
|
+
const { step } = await oneStep(forge, spec, true);
|
|
339
|
+
expect(step[CLOUD_TARGETS_ENV]).toBeDefined();
|
|
340
|
+
expect(step[CLOUD_TRADED_ENV]).toBeUndefined();
|
|
341
|
+
expect(cloudsTraded(step)).toEqual([]);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("the trade says it traded, with or without targets, so its targets file is told from a login's", async () => {
|
|
345
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-trade-4930-"));
|
|
346
|
+
const trade = async (spec: CloudTradeSpec): Promise<Record<string, string>> => {
|
|
347
|
+
const file = join(dir, `github-env-${Math.random().toString(16).slice(2)}`);
|
|
348
|
+
writeFileSync(file, "");
|
|
349
|
+
await run("sh", ["-c", tradeLine(file, "github-env")], { env: { PATH: process.env.PATH!, ...emu.requestEnv, RUNNER_TEMP: dir, [TRADE_SPEC_ENV]: JSON.stringify(emu.pointAt(spec)) } });
|
|
350
|
+
return parseEnv(readFileSync(file, "utf-8"));
|
|
351
|
+
};
|
|
352
|
+
const aws = { role: "arn:aws:iam::1:role/default", region: "eu-west-1", audience: "sts.amazonaws.com" };
|
|
353
|
+
const targeted = await trade({ aws: { ...aws, targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] }, gcp: { serviceAccount: "plan@p.iam.gserviceaccount.com", provider: PROVIDER, audience: AUD.gcp } });
|
|
354
|
+
expect(targeted[CLOUD_TARGETS_ENV]).toBeDefined();
|
|
355
|
+
expect(targeted[CLOUD_TRADED_ENV]).toBe("aws,gcp");
|
|
356
|
+
expect(cloudsTraded(targeted)).toEqual(["aws", "gcp"]);
|
|
357
|
+
// A trade's identity sets its own region, so a target still gets it.
|
|
358
|
+
expect(targetCloudEnv({ ...targeted, AWS_REGION: "ap-south-1" }, "envs/prod/net").AWS_REGION).toBe("eu-west-1");
|
|
359
|
+
const plain = await trade({ aws });
|
|
360
|
+
expect(plain[CLOUD_TARGETS_ENV]).toBeUndefined();
|
|
361
|
+
expect(plain[CLOUD_TRADED_ENV]).toBe("aws");
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4912: after the cloud login, the rest of the job reaches neither the
|
|
3
|
+
* forge's token request nor the token file unless it needs them, and
|
|
4
|
+
* GitLab's trade writes no file of variables. The tests run the rendered
|
|
5
|
+
* lines as a runner runs a step: GitHub and Forgejo run the step's script
|
|
6
|
+
* as a file (`bash --noprofile --norc -eo pipefail <file>`), GitLab runs the
|
|
7
|
+
* job's script in one shell. Each runs against the local emulator of the
|
|
8
|
+
* forge's token URL and the clouds (./__fixtures__/oidc-emulator.ts). Test
|
|
9
|
+
* values only; no cloud is reached.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { execFile } from "node:child_process";
|
|
13
|
+
import { mkdtempSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { promisify } from "node:util";
|
|
17
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
18
|
+
import { cloudLogin, LOGIN_CLEAR_TOKENS, LOGIN_TOKEN_FILES_ENV, type CloudLoginSpec, type LoginForge } from "./ci-login";
|
|
19
|
+
import { GITLAB_TRADE_VARS, gitlabTradeLines, idTokenVar, OIDC_REQUEST_VARS, TRADE_SPEC_ENV, type CloudTradeSpec } from "./ci-identity";
|
|
20
|
+
import { emulatedCredentials, EMULATED_JWT_PREFIX, startOidcEmulator, type OidcEmulator } from "./__fixtures__/oidc-emulator";
|
|
21
|
+
|
|
22
|
+
const run = promisify(execFile);
|
|
23
|
+
|
|
24
|
+
const PROVIDER = "projects/123/locations/global/workloadIdentityPools/ci/providers/forge";
|
|
25
|
+
const TENANT = "00000000-0000-0000-0000-000000000001";
|
|
26
|
+
const SPEC: CloudLoginSpec = {
|
|
27
|
+
aws: { role: "arn:aws:iam::111111111111:role/plan", region: "eu-west-1" },
|
|
28
|
+
gcp: { serviceAccount: "plan@proj.iam.gserviceaccount.com", provider: PROVIDER },
|
|
29
|
+
azure: { clientId: "11111111-1111-1111-1111-111111111111", tenantId: TENANT },
|
|
30
|
+
};
|
|
31
|
+
const FORGES: LoginForge[] = ["github", "gitlab", "forgejo"];
|
|
32
|
+
const FORGE_SECRET = "forge-secret-4912";
|
|
33
|
+
|
|
34
|
+
/** A child of the step that asks the forge for a token, as the change's code could: it prints what it got. */
|
|
35
|
+
const ASK = `node -e 'const u=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,k=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!u||!k){console.log("request:none");process.exit(0)}fetch(u+"&audience=x",{headers:{authorization:"bearer "+k}}).then(r=>r.text()).then(t=>console.log("request:"+t))'`;
|
|
36
|
+
|
|
37
|
+
const parseEnv = (text: string): Record<string, string> => Object.fromEntries(text.trim().split("\n").filter((l) => l.includes("=")).map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)]));
|
|
38
|
+
|
|
39
|
+
let emu: OidcEmulator;
|
|
40
|
+
beforeAll(async () => {
|
|
41
|
+
emu = await startOidcEmulator();
|
|
42
|
+
});
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
await emu.close();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Runs the login with `restart` and then `rest` as one step of `forge`,
|
|
49
|
+
* with a forge token and the job's token request (GitLab: its id_tokens) in
|
|
50
|
+
* the step's environment.
|
|
51
|
+
*/
|
|
52
|
+
async function loginStep(forge: LoginForge, spec: CloudLoginSpec, rest: string[]) {
|
|
53
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4912-"));
|
|
54
|
+
const runnerTemp = mkdtempSync(join(dir, "runner-"));
|
|
55
|
+
const scripts = mkdtempSync(join(dir, "scripts-"));
|
|
56
|
+
const githubEnv = join(scripts, "github-env");
|
|
57
|
+
writeFileSync(githubEnv, "");
|
|
58
|
+
const { steps, idTokens } = cloudLogin(forge, spec, { restart: { also: ["CHANT_FORGE_TOKEN"] } });
|
|
59
|
+
const file = join(scripts, "step.sh");
|
|
60
|
+
writeFileSync(file, [...steps[0]!.run, ...rest].join("\n") + "\n");
|
|
61
|
+
const tokens = forge === "gitlab" ? Object.fromEntries(Object.keys(idTokens).map((k) => [k, `${EMULATED_JWT_PREFIX}.${k}.gitlab`])) : emu.requestEnv;
|
|
62
|
+
const env = { PATH: process.env.PATH!, GITHUB_ENV: githubEnv, RUNNER_TEMP: runnerTemp, TMPDIR: runnerTemp, CHANT_FORGE_TOKEN: FORGE_SECRET, SCRATCH: scripts, ...tokens };
|
|
63
|
+
const args = forge === "gitlab" ? ["-e", file] : ["--noprofile", "--norc", "-eo", "pipefail", file];
|
|
64
|
+
const r = await run(forge === "gitlab" ? "sh" : "bash", args, { env }).catch((e: { stdout: string; stderr: string; code: number }) => ({ stdout: e.stdout, stderr: e.stderr, failed: e.code }));
|
|
65
|
+
return { r, scripts, runnerTemp, githubEnv };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("the login, then the step without the token request (#4912)", () => {
|
|
69
|
+
test.each(FORGES)("%s: the tool reads its token file; the step's children reach no token request, forge token or id token; the token file is empty once the step ends", async (forge) => {
|
|
70
|
+
const before = emu.log.minted.length;
|
|
71
|
+
const { r, scripts } = await loginStep(forge, SPEC, [
|
|
72
|
+
'env > "$SCRATCH/seen"',
|
|
73
|
+
`${ASK} >> "$SCRATCH/seen"`,
|
|
74
|
+
// The cloud's tool reads the token file while the step runs.
|
|
75
|
+
'cat "$AWS_WEB_IDENTITY_TOKEN_FILE" > "$SCRATCH/during"',
|
|
76
|
+
'printf "%s" "$AWS_WEB_IDENTITY_TOKEN_FILE" > "$SCRATCH/aws-file"',
|
|
77
|
+
]);
|
|
78
|
+
expect(r).not.toHaveProperty("failed");
|
|
79
|
+
const seen = readFileSync(join(scripts, "seen"), "utf-8");
|
|
80
|
+
const env = parseEnv(seen);
|
|
81
|
+
expect(env).toMatchObject({ AWS_ROLE_ARN: SPEC.aws!.role, ARM_CLIENT_ID: SPEC.azure!.clientId });
|
|
82
|
+
expect(seen).toContain("request:none");
|
|
83
|
+
expect(seen).not.toContain(FORGE_SECRET);
|
|
84
|
+
for (const v of OIDC_REQUEST_VARS) expect(env[v], v).toBeUndefined();
|
|
85
|
+
// The login ran once: a restarted step skips it.
|
|
86
|
+
expect(emu.log.minted.length - before).toBe(forge === "gitlab" ? 0 : 3);
|
|
87
|
+
expect(r.stderr.split(`logged in from the OIDC token file as ${SPEC.aws!.role}`).length - 1).toBe(1);
|
|
88
|
+
expect(readFileSync(join(scripts, "during"), "utf-8")).toContain(EMULATED_JWT_PREFIX);
|
|
89
|
+
// Once the step is done, a later step finds the login's token files empty.
|
|
90
|
+
const files = env[LOGIN_TOKEN_FILES_ENV]!.split(":");
|
|
91
|
+
expect(files).toHaveLength(3);
|
|
92
|
+
expect(files).toContain(readFileSync(join(scripts, "aws-file"), "utf-8"));
|
|
93
|
+
for (const f of files) expect(readFileSync(f, "utf-8"), f).toBe("");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test.each(["github", "forgejo"] as const)("%s: a step whose script is no file keeps running, with the request variables unset", async (forge) => {
|
|
97
|
+
const { steps } = cloudLogin(forge, { aws: SPEC.aws }, { restart: true });
|
|
98
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4912-c-"));
|
|
99
|
+
const r = await run("bash", ["-e", "-c", [...steps[0]!.run, "env", ASK].join("\n")], { env: { PATH: process.env.PATH!, RUNNER_TEMP: dir, ...emu.requestEnv } });
|
|
100
|
+
const env = parseEnv(r.stdout);
|
|
101
|
+
expect(env.AWS_ROLE_ARN).toBe(SPEC.aws!.role);
|
|
102
|
+
expect(r.stdout).toContain("request:none");
|
|
103
|
+
expect(env.ACTIONS_ID_TOKEN_REQUEST_URL).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("a runner's own token file is never emptied, and is not listed", async () => {
|
|
107
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4912-runner-"));
|
|
108
|
+
writeFileSync(join(dir, "token"), "eyJrunner.token.1\n");
|
|
109
|
+
const { steps } = cloudLogin("forgejo", { aws: { ...SPEC.aws!, tokenFile: `${dir}/token` }, azure: SPEC.azure }, { restart: true });
|
|
110
|
+
const scripts = mkdtempSync(join(tmpdir(), "chant-login-4912-rs-"));
|
|
111
|
+
const file = join(scripts, "step.sh");
|
|
112
|
+
writeFileSync(file, [...steps[0]!.run, `env > "${scripts}/seen"`].join("\n") + "\n");
|
|
113
|
+
await run("bash", ["--noprofile", "--norc", "-eo", "pipefail", file], { env: { PATH: process.env.PATH!, RUNNER_TEMP: scripts, ...emu.requestEnv } });
|
|
114
|
+
const env = parseEnv(readFileSync(join(scripts, "seen"), "utf-8"));
|
|
115
|
+
expect(env[LOGIN_TOKEN_FILES_ENV]!.split(":")).toEqual([env.AZURE_FEDERATED_TOKEN_FILE]);
|
|
116
|
+
expect(readFileSync(join(dir, "token"), "utf-8")).toBe("eyJrunner.token.1\n");
|
|
117
|
+
expect(readFileSync(env.AZURE_FEDERATED_TOKEN_FILE!, "utf-8")).toBe("");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test.each(["github", "forgejo"] as const)("%s: a login in a step of its own lists its token files for later steps, and LOGIN_CLEAR_TOKENS empties them", async (forge) => {
|
|
121
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4912-sep-"));
|
|
122
|
+
const githubEnv = join(dir, "github-env");
|
|
123
|
+
writeFileSync(githubEnv, "");
|
|
124
|
+
const { steps } = cloudLogin(forge, SPEC);
|
|
125
|
+
await run("bash", ["-e", "-c", steps[0]!.run.join("\n")], { env: { PATH: process.env.PATH!, GITHUB_ENV: githubEnv, RUNNER_TEMP: dir, ...emu.requestEnv } });
|
|
126
|
+
const vars = parseEnv(readFileSync(githubEnv, "utf-8"));
|
|
127
|
+
const files = vars[LOGIN_TOKEN_FILES_ENV]!.split(":");
|
|
128
|
+
expect(files.sort()).toEqual([vars.AWS_WEB_IDENTITY_TOKEN_FILE, vars.AZURE_FEDERATED_TOKEN_FILE, JSON.parse(readFileSync(vars.GOOGLE_APPLICATION_CREDENTIALS!, "utf-8")).credential_source.file].sort());
|
|
129
|
+
for (const f of files) expect(readFileSync(f, "utf-8")).toContain(EMULATED_JWT_PREFIX);
|
|
130
|
+
// The job's last step, after the tool.
|
|
131
|
+
await run("bash", ["-e", "-c", LOGIN_CLEAR_TOKENS], { env: { PATH: process.env.PATH!, ...vars } });
|
|
132
|
+
for (const f of files) expect(readFileSync(f, "utf-8")).toBe("");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("the restart is rendered as one block at the top of the step, and GitLab, whose script is no file, unsets instead", () => {
|
|
136
|
+
const github = cloudLogin("github", SPEC, { restart: { also: ["CHANT_FORGE_TOKEN"] } }).steps[0]!.run;
|
|
137
|
+
expect(github[0]).toBe('if [ -z "${CHANT_CLOUD_LOGGED_IN:-}" ]; then');
|
|
138
|
+
expect(github.find((l) => l.startsWith("if [ -z \"${CHANT_CLOUD_LOGGED_IN:-}\" ] && "))).toContain("exec env -u ACTIONS_ID_TOKEN_REQUEST_URL -u ACTIONS_ID_TOKEN_REQUEST_TOKEN -u CHANT_FORGE_TOKEN CHANT_CLOUD_LOGGED_IN=1 bash");
|
|
139
|
+
expect(cloudLogin("forgejo", SPEC, { restart: { shell: "sh" } }).steps[0]!.run.join("\n")).toContain('CHANT_CLOUD_LOGGED_IN=1 sh -e "$0"');
|
|
140
|
+
const gitlab = cloudLogin("gitlab", SPEC, { restart: { also: ["CHANT_FORGE_TOKEN"] } }).steps[0]!.run;
|
|
141
|
+
expect(gitlab.join("\n")).not.toContain("exec env");
|
|
142
|
+
expect(gitlab).toContain("unset CHANT_FORGE_TOKEN");
|
|
143
|
+
// restart takes the step's form: sameStep is implied.
|
|
144
|
+
for (const forge of FORGES) expect(cloudLogin(forge, SPEC, { restart: true }).steps[0]!.run.join("\n")).not.toContain("$GITHUB_ENV");
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("GitLab's trade writes no file (#4912)", () => {
|
|
149
|
+
test("the trade's exports are captured and evaluated, the token variables unset, and no file is written", async () => {
|
|
150
|
+
const lines = gitlabTradeLines(["CHANT_FORGE_TOKEN"]);
|
|
151
|
+
expect(lines).toHaveLength(3);
|
|
152
|
+
expect(lines.join("\n")).not.toMatch(/\brm\b/);
|
|
153
|
+
expect(lines[0]).toMatch(new RegExp(`^${GITLAB_TRADE_VARS}="\\$\\(cd / && node -e '.*' "-" sh\\)"$`));
|
|
154
|
+
const tmp = mkdtempSync(join(tmpdir(), "chant-trade-4912-tmp-"));
|
|
155
|
+
const scripts = mkdtempSync(join(tmpdir(), "chant-trade-4912-"));
|
|
156
|
+
const file = join(scripts, "job.sh");
|
|
157
|
+
writeFileSync(file, [...lines, "env"].join("\n"));
|
|
158
|
+
const spec: CloudTradeSpec = emu.pointAt({ aws: { role: "arn:aws:iam::111111111111:role/plan", region: "eu-west-1", audience: "sts.amazonaws.com" } });
|
|
159
|
+
const r = await run("sh", ["-e", file], { env: { PATH: process.env.PATH!, TMPDIR: tmp, CI_JOB_ID: "4912", CHANT_FORGE_TOKEN: FORGE_SECRET, [idTokenVar("aws")]: `${EMULATED_JWT_PREFIX}.aws.gitlab`, [TRADE_SPEC_ENV]: JSON.stringify(spec) } });
|
|
160
|
+
const env = parseEnv(r.stdout);
|
|
161
|
+
expect(env.AWS_ACCESS_KEY_ID).toBe(emulatedCredentials("arn:aws:iam::111111111111:role/plan").accessKeyId);
|
|
162
|
+
for (const v of [...OIDC_REQUEST_VARS, GITLAB_TRADE_VARS, "CHANT_FORGE_TOKEN"]) expect(env[v], v).toBeUndefined();
|
|
163
|
+
expect(readdirSync(tmp)).toEqual([]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("a failed trade stops the script", async () => {
|
|
167
|
+
const scripts = mkdtempSync(join(tmpdir(), "chant-trade-4912-f-"));
|
|
168
|
+
const file = join(scripts, "job.sh");
|
|
169
|
+
writeFileSync(file, [...gitlabTradeLines(), "echo went-on"].join("\n"));
|
|
170
|
+
const r = await run("sh", ["-e", file], { env: { PATH: process.env.PATH!, CI_JOB_ID: "4912", [TRADE_SPEC_ENV]: JSON.stringify({ aws: { role: "r", region: "eu-west-1", audience: "a" } }) } }).catch((e: { stdout: string; code: number }) => e);
|
|
171
|
+
expect(r).toMatchObject({ code: 1 });
|
|
172
|
+
expect((r as { stdout: string }).stdout).not.toContain("went-on");
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("GCP's stsEndpoint takes a full token URL too (#4912)", () => {
|
|
177
|
+
test("the login writes it as the credential file's token_url, and the base form still gains /v1/token", async () => {
|
|
178
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-login-4912-gcp-"));
|
|
179
|
+
for (const [sts, url] of [
|
|
180
|
+
["https://sts.us-east1.rep.googleapis.com/v1/token", "https://sts.us-east1.rep.googleapis.com/v1/token"],
|
|
181
|
+
["https://sts.googleapis.com/", "https://sts.googleapis.com/v1/token"],
|
|
182
|
+
] as const) {
|
|
183
|
+
const githubEnv = join(dir, `env-${Math.random().toString(16).slice(2)}`);
|
|
184
|
+
writeFileSync(githubEnv, "");
|
|
185
|
+
const { steps } = cloudLogin("github", { gcp: { ...SPEC.gcp!, stsEndpoint: sts } });
|
|
186
|
+
await run("bash", ["-e", "-c", steps[0]!.run.join("\n")], { env: { PATH: process.env.PATH!, GITHUB_ENV: githubEnv, RUNNER_TEMP: dir, ...emu.requestEnv } });
|
|
187
|
+
const vars = parseEnv(readFileSync(githubEnv, "utf-8"));
|
|
188
|
+
expect(JSON.parse(readFileSync(vars.GOOGLE_APPLICATION_CREDENTIALS!, "utf-8")).token_url).toBe(url);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("the trade posts to a full token URL as given", async () => {
|
|
193
|
+
const lines = gitlabTradeLines();
|
|
194
|
+
const scripts = mkdtempSync(join(tmpdir(), "chant-trade-4912-gcp-"));
|
|
195
|
+
const file = join(scripts, "job.sh");
|
|
196
|
+
writeFileSync(file, [...lines, "env"].join("\n"));
|
|
197
|
+
const pointed = emu.pointAt({ gcp: { serviceAccount: "plan@proj.iam.gserviceaccount.com", provider: PROVIDER, audience: `https://iam.googleapis.com/${PROVIDER}` } });
|
|
198
|
+
const spec = { gcp: { ...pointed.gcp!, stsEndpoint: `${pointed.gcp!.stsEndpoint}/v1/token` } };
|
|
199
|
+
const before = emu.log.impersonated.length;
|
|
200
|
+
const r = await run("sh", ["-e", file], { env: { PATH: process.env.PATH!, CI_JOB_ID: "4912", [idTokenVar("gcp")]: `${EMULATED_JWT_PREFIX}.gcp.gitlab`, [TRADE_SPEC_ENV]: JSON.stringify(spec) } });
|
|
201
|
+
expect(parseEnv(r.stdout).GOOGLE_OAUTH_ACCESS_TOKEN).toMatch(/^ya29\./);
|
|
202
|
+
expect(emu.log.impersonated.slice(before)).toEqual(["plan@proj.iam.gserviceaccount.com"]);
|
|
203
|
+
});
|
|
204
|
+
});
|