Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 233 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Test the action the way a customer uses it: `uses: ./`, on the runners we
# claim to support, against the real marketplace.
#
# The whole test runs on `dry-run: true`, so it needs NO Linro install, NO
# The whole test runs on `dry-run: true` against a stand-in install
# (testdata/stub-install.py on loopback), so it needs NO Linro install, NO real
# token, and no secrets at all. That is deliberate — a test that needs a
# credential is a test that stops running the moment the credential lapses,
# and this one has to keep working on forks and on Dependabot branches.
# and this one has to keep working on forks and on Dependabot branches. The
# stand-in serves the install's download route (bearer token, X-Linro-Sha256)
# and takes the tarball from the public marketplace; once the marketplace
# requires a key for /artifacts, it needs one too.
#
# What it does NOT cover, and cannot without an install: that a submission is
# accepted and comes back as a check run. That path is exercised continuously
Expand Down Expand Up @@ -99,10 +103,16 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Simulate a fixture plan (no install, no token)
- name: Start a stand-in install
id: stub
run: echo "url=$(testdata/start-stub.sh stub ok)" >> "$GITHUB_OUTPUT"

- name: Simulate a fixture plan (no install, no real token)
id: sim
uses: ./
with:
server: ${{ steps.stub.outputs.url }}
token: ci-token
plan: testdata/plan.json
account: "000000000000"
region: eu-central-1
Expand All @@ -118,6 +128,14 @@ jobs:
test -n "$RESOLVED" || { echo "::error::version output is empty"; exit 1; }
echo "ran linro-simulator ${RESOLVED}"

- name: The CLI came from the install, with the token
run: |
# The download route and the bearer are the v2 contract with the
# install; the stand-in logs what it was asked for.
cat "${RUNNER_TEMP}/stub.log"
grep -q '^/api/simulator/download/[^/]*/[a-z0-9]*-[a-z0-9]*\.tar\.gz auth=ok$' "${RUNNER_TEMP}/stub.log" ||
{ echo "::error::the action did not download from the install with its token"; exit 1; }

# The multi-source contract, which is the part most likely to rot: several
# sources become ONE simulation, plan and preview COMBINE, and a blank line
# is not a path.
Expand All @@ -130,9 +148,15 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Start a stand-in install
id: stub
run: echo "url=$(testdata/start-stub.sh stub ok)" >> "$GITHUB_OUTPUT"

- name: Terraform AND Pulumi, one simulation
uses: ./
with:
server: ${{ steps.stub.outputs.url }}
token: ci-token
plan: |
testdata/plan.json

Expand All @@ -147,6 +171,8 @@ jobs:
- name: OpenTofu is a label on the source, not a different format
uses: ./
with:
server: ${{ steps.stub.outputs.url }}
token: ci-token
plan: testdata/plan.json
opentofu: "true"
account: "000000000000"
Expand Down Expand Up @@ -211,12 +237,29 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Start stand-in installs
id: stub
run: |
{
echo "url=$(testdata/start-stub.sh stub ok)"
echo "bad-sha=$(testdata/start-stub.sh stub-bad-sha bad-sha)"
echo "no-sha=$(testdata/start-stub.sh stub-no-sha no-sha)"
} >> "$GITHUB_OUTPUT"

# Each case must fail AND for its own reason (testdata/expect-refusal.sh
# reads the reason the action recorded), so a stub failure cannot pass
# for the check a case is about. `if: always()` runs every check.
- name: No sources at all is refused
id: nothing
continue-on-error: true
uses: ./
with:
server: ${{ steps.stub.outputs.url }}
token: ci-token
dry-run: "true"
- name: "Check: no sources"
if: always()
run: testdata/expect-refusal.sh "no sources" "${{ steps.nothing.outcome }}" "nothing to simulate"

- name: A real submission without a token is refused
id: no-token
Expand All @@ -225,43 +268,209 @@ jobs:
with:
plan: testdata/plan.json
server: https://example.invalid
token: ""
- name: "Check: missing token"
if: always()
run: testdata/expect-refusal.sh "missing token" "${{ steps.no-token.outcome }}" "the token input is required"

- name: A dry run without a token is refused
id: dry-no-token
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.url }}
token: ""
dry-run: "true"
- name: "Check: dry run without a token"
if: always()
run: testdata/expect-refusal.sh "dry run without a token" "${{ steps.dry-no-token.outcome }}" "the token input is required"

- name: A dry run without a server is refused
id: dry-no-server
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ""
token: ci-token
dry-run: "true"
- name: "Check: dry run without a server"
if: always()
run: testdata/expect-refusal.sh "dry run without a server" "${{ steps.dry-no-server.outcome }}" "the server input is required"

- name: A server with user info is refused
id: userinfo
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: "https://user@acme.example"
token: ci-token
dry-run: "true"
- name: "Check: user info"
if: always()
run: testdata/expect-refusal.sh "user info" "${{ steps.userinfo.outcome }}" "must not carry user info"

- name: A loopback prefix with user info is refused
id: userinfo-loopback
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: "http://127.0.0.1:80@evil.example"
token: ci-token
dry-run: "true"
- name: "Check: loopback user info"
if: always()
run: testdata/expect-refusal.sh "loopback user info" "${{ steps.userinfo-loopback.outcome }}" "must not carry user info"

- name: A host that only starts with localhost is not loopback
id: localhost-suffix
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: "http://localhost.evil.com"
token: ci-token
dry-run: "true"
- name: "Check: localhost suffix"
if: always()
run: testdata/expect-refusal.sh "localhost suffix" "${{ steps.localhost-suffix.outcome }}" "plain http only for a loopback install"

- name: A host that only starts with 127.0.0.1 is not loopback
id: ip-suffix
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: "http://127.0.0.1.nip.io"
token: ci-token
dry-run: "true"
- name: "Check: 127.0.0.1 suffix"
if: always()
run: testdata/expect-refusal.sh "127.0.0.1 suffix" "${{ steps.ip-suffix.outcome }}" "plain http only for a loopback install"

- name: An IPv6 loopback with user info is refused
id: ipv6-userinfo
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: "http://[::1]@evil.example"
token: ci-token
dry-run: "true"
- name: "Check: [::1] user info"
if: always()
run: testdata/expect-refusal.sh "[::1] user info" "${{ steps.ipv6-userinfo.outcome }}" "must not carry user info"

# Not a refusal: with every proxy variable pointing at a closed port, the
# loopback stand-in is still reached, so the request (and its token)
# did not go through the proxy.
- name: A loopback install is reached past a proxy
uses: ./
# One spelling each: workflow env names are case-insensitive. curl
# reads http_proxy only in lower case, and ALL_PROXY in either.
env:
http_proxy: http://127.0.0.1:9
HTTPS_PROXY: http://127.0.0.1:9
ALL_PROXY: http://127.0.0.1:9
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.url }}
token: ci-token
dry-run: "true"

- name: A token the install refuses is refused
id: wrong-token
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.url }}
token: not-the-token
dry-run: "true"
- name: "Check: refused token"
if: always()
run: testdata/expect-refusal.sh "refused token" "${{ steps.wrong-token.outcome }}" "refused the token (HTTP 401)"

- name: Plain http to an install that is not on loopback is refused
id: plain-http
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: http://example.invalid
token: ci-token
dry-run: "true"
- name: "Check: plain http"
if: always()
run: testdata/expect-refusal.sh "plain http" "${{ steps.plain-http.outcome }}" "server must be an https:// URL"

- name: A download that does not match X-Linro-Sha256 is refused
id: bad-sha
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.bad-sha }}
token: ci-token
dry-run: "true"
- name: "Check: sha256 mismatch"
if: always()
run: testdata/expect-refusal.sh "sha256 mismatch" "${{ steps.bad-sha.outcome }}" "does not match the sha256 the install stated"

- name: A download without X-Linro-Sha256 is refused
id: no-sha
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.no-sha }}
token: ci-token
dry-run: "true"
- name: "Check: no sha256 header"
if: always()
run: testdata/expect-refusal.sh "no sha256 header" "${{ steps.no-sha.outcome }}" "sent no X-Linro-Sha256 header"

- name: A boolean that is neither true nor false is refused
id: bad-bool
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
# The whole point: `yes` must not quietly read as false and turn the
# gate off. This is the one wrong answer that looks like it worked.
server: ${{ steps.stub.outputs.url }}
token: ci-token
strict: "yes"
dry-run: "true"
- name: "Check: bad boolean"
if: always()
run: testdata/expect-refusal.sh "bad boolean" "${{ steps.bad-bool.outcome }}" "the strict input must be true or false"

- name: A version the marketplace does not serve is refused
id: bad-version
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.url }}
token: ci-token
version: v99.99.99
dry-run: "true"
- name: "Check: unknown version"
if: always()
run: testdata/expect-refusal.sh "unknown version" "${{ steps.bad-version.outcome }}" "has no linro-simulator v99.99.99"

- name: Assert each refusal actually failed
run: |
# continue-on-error records the outcome instead of ending the job, so
# a step that WRONGLY succeeded is only caught by checking here. Without
# this, "the action refuses bad input" would be an untested claim.
fail=0
for pair in "no sources:${{ steps.nothing.outcome }}" \
"missing token:${{ steps.no-token.outcome }}" \
"bad boolean:${{ steps.bad-bool.outcome }}" \
"unknown version:${{ steps.bad-version.outcome }}"; do
name="${pair%%:*}"; outcome="${pair##*:}"
if [ "$outcome" != "failure" ]; then
echo "::error::${name} should have failed the step, got '${outcome}'"
fail=1
else
echo "ok: ${name} → ${outcome}"
fi
done
exit "$fail"
- name: A version that is not a version is refused before any request
id: malformed-version
continue-on-error: true
uses: ./
with:
plan: testdata/plan.json
server: ${{ steps.stub.outputs.url }}
token: ci-token
version: "1.0/../../x"
dry-run: "true"
- name: "Check: malformed version"
if: always()
run: testdata/expect-refusal.sh "malformed version" "${{ steps.malformed-version.outcome }}" "is not a version"
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

## v2.0.0 (unreleased)

The CLI is downloaded from your Linro install, not anonymously from the
marketplace (ENG-1730). The marketplace is going to require a key for
downloads, and a customer's CI has no marketplace key; it has a Linro PAT.

- The action downloads `linro-simulator` from
`<server>/api/simulator/download/<version>/<os>-<arch>.tar.gz` with `token`
as `Authorization: Bearer`. The install fetches it from the marketplace with
its own key and checks the marketplace's sha256; the action checks the file
again against the install's `X-Linro-Sha256` header.
- **Breaking:** `server` and `token` are required on every run, dry runs
included.
- **Breaking:** the `marketplace-url` input is removed.
- `server` must be `https://`, or plain `http://` to exactly `127.0.0.1`,
`localhost` or `[::1]` (optional port), so the token never crosses the
network in clear. User info, a query or a fragment in `server` is refused.
A loopback install is never reached through a proxy; https follows the
runner's proxy settings.
- A refused token (401), a token without `SCOPE_SIMULATIONS` (403), an
unknown version (404) and an unreachable install are reported separately.
- `version` is checked before any request (a semver or an alias such as
`latest`), and the whole download, retries included, has one 10-minute
wall-clock deadline.
- `ca-cert` also applies to the CLI download, where it replaces the system
roots.

Needs an install that serves the simulator download. `@v1` keeps downloading
anonymously from the marketplace until the marketplace requires a key for
downloads.

## v1.1.1 and earlier

See the [releases](https://github.com/linro-io/simulation-github-action/releases).
Loading
Loading