From c599f1b006585ee8f5c8c8eb52f1a0713eed1256 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Wed, 28 Oct 2026 09:06:27 +1000 Subject: [PATCH 1/2] feat: kv-indexes input --- .github/workflows/main.yml | 25 ++++++++++++++++++ README.md | 37 +++++++++++++++++++++++---- action.yml | 27 +++++++++++++++++++ scripts/validate-kv-indexes-inputs.sh | 20 +++++++++++++++ 4 files changed, 104 insertions(+), 5 deletions(-) create mode 100755 scripts/validate-kv-indexes-inputs.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7b31479..0b54989 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -191,3 +191,28 @@ jobs: done echo "All unsafe inputs refused." + + test-kv-indexes-guard: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - name: Valid kv-indexes inputs are accepted + env: + KV_INDEXES: quant/meta.json + CUSTOMER: quant + PROJECT: github-actions + API_TOKEN: dummy + API_BASE_URL: https://dashboard.quantcdn.io/api/v2 + run: ./scripts/validate-kv-indexes-inputs.sh + + - name: Inputs that would become extra CLI flags are refused + run: | + base=(KV_INDEXES=quant/meta.json CUSTOMER=quant PROJECT=github-actions API_TOKEN=dummy API_BASE_URL=https://dashboard.quantcdn.io/api/v2) + for bad in "KV_INDEXES=meta.json --api-base-url=https://attacker.example/api/v2" "KV_INDEXES=--dry-run" 'KV_INDEXES=m.json"x' \ + "KV_INDEXES=" "CUSTOMER=quant --api-token=x" "PROJECT=-p" "API_TOKEN=" "API_BASE_URL="; do + if env "${base[@]}" "$bad" ./scripts/validate-kv-indexes-inputs.sh >/dev/null 2>&1; then + echo "::error::accepted unsafe input: $bad"; exit 1 + fi + done + echo "All unsafe inputs refused." diff --git a/README.md b/README.md index 72e7db1..eb8773f 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,10 @@ This GitHub Action deploys your static site and/or functions to QuantCDN using t | `revision-log` | Specify a location for the local revision log file | No | `false` | | `enable-index-html` | Enable index.html creation in Quant | No | `false` | | `rules` | Path to an edge rules manifest (`edge-rules.json`) | No | - | -| `api-token` | Project-scoped portal API token for rules (`QUANT_API_TOKEN`); required with `rules` | No | - | -| `api-base-url` | Portal API base URL including `/api/v2` (`QUANT_BASE_URL`); required with `rules` | No | - | +| `api-token` | Project-scoped portal API token (`QUANT_API_TOKEN`); required with `rules` or `kv-indexes` | No | - | +| `api-base-url` | Portal API base URL including `/api/v2` (`QUANT_BASE_URL`); required with `rules` or `kv-indexes` | No | - | | `rules-force` | Overwrite managed rules changed outside code (never takes over another rule) | No | `false` | +| `kv-indexes` | Path to `quant/meta.json`; declares its KV indexes with `api-token` and `api-base-url` | No | - | ## Example Workflows @@ -183,8 +184,9 @@ The action runs in this order: `api-base-url` must be set. 2. **Validate rules access** with a dry run: token scope, manifest and drift are checked before anything is uploaded. -3. Deploy functions, then assets. -4. **Deploy rules.** +3. **Declare KV indexes**, when `kv-indexes` is set (see [KV indexes](#kv-indexes)). +4. Deploy functions, then assets. +5. **Deploy rules.** Rules deployed this way are managed in code and are read-only in the dashboard. If one was changed outside code anyway, step 2 fails before any upload and the @@ -192,10 +194,35 @@ log lists the changed fields. Set `rules-force: true` for one run to overwrite those rules with the manifest; it never takes over a rule the manifest did not create. -If step 4 fails after the uploads (for example a transient portal error), the new +If step 5 fails after the uploads (for example a transient portal error), the new assets are live with the previous rules. Re-run the workflow: deploys are idempotent, so the rules step converges and unchanged assets are skipped. +## KV indexes + +Provide `kv-indexes: quant/meta.json` with `api-token` and `api-base-url` to +declare the KV indexes of the stores in `quant/meta.json` before the functions +deploy: + +```yaml +- uses: quantcdn/deploy-action@v7 + with: + customer: your-customer-id + project: your-project-name + token: ${{ secrets.QUANT_TOKEN }} + dir: dist + functions: quant/edge-functions.json + kv-indexes: quant/meta.json + api-token: ${{ secrets.QUANT_API_TOKEN }} + api-base-url: ${{ vars.QUANT_BASE_URL }} +``` + +The step runs `quant kv-indexes`. It declares each index that the store does not +have yet, and it never drops or changes an index. An index with a different +definition from `meta.json` fails the step. The `api-token` needs the `kv:read` +and `kv:write` scopes. If it does not have them, the step prints a warning and +continues, and the indexes are not declared. + ## License MIT License diff --git a/action.yml b/action.yml index de2f4f1..bc4be7a 100644 --- a/action.yml +++ b/action.yml @@ -62,6 +62,9 @@ inputs: description: "Overwrite managed rules changed outside code (never takes over another rule)" required: false default: "false" + kv-indexes: + description: "Path to quant/meta.json; declares its KV indexes with the project-scoped api-token" + required: false runs: using: "composite" steps: @@ -94,6 +97,30 @@ runs: --force=${{ inputs.rules-force }} --dry-run + - name: Validate KV Index Inputs + if: inputs.kv-indexes != '' + shell: bash + env: + KV_INDEXES: ${{ inputs.kv-indexes }} + CUSTOMER: ${{ inputs.customer }} + PROJECT: ${{ inputs.project }} + API_TOKEN: ${{ inputs.api-token }} + API_BASE_URL: ${{ inputs.api-base-url }} + run: '"$GITHUB_ACTION_PATH/scripts/validate-kv-indexes-inputs.sh"' + + - name: Declare KV Indexes + if: inputs.kv-indexes != '' + uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + env: + QUANT_API_TOKEN: ${{ inputs.api-token }} + QUANT_BASE_URL: ${{ inputs.api-base-url }} + with: + args: > + kv-indexes + "${{ inputs.kv-indexes }}" + -c "${{ inputs.customer }}" + -p "${{ inputs.project }}" + - name: Deploy Functions if: inputs.functions != '' uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" diff --git a/scripts/validate-kv-indexes-inputs.sh b/scripts/validate-kv-indexes-inputs.sh new file mode 100755 index 0000000..d3d65e1 --- /dev/null +++ b/scripts/validate-kv-indexes-inputs.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Refuse kv-indexes inputs that could become extra CLI arguments. +# +# The same reason as validate-rules-inputs.sh: a docker:// step splits `args:` +# on whitespace, so a value with a space could become a flag that overrides +# QUANT_API_TOKEN/QUANT_BASE_URL. Values reach this script only through the +# environment, never through the command line. +set -euo pipefail + +fail() { echo "::error::$1"; exit 1; } + +path_ok() { [[ "$1" =~ ^[A-Za-z0-9_./][A-Za-z0-9_./-]*$ ]]; } +slug_ok() { [[ "$1" =~ ^[A-Za-z0-9][A-Za-z0-9_-]*$ ]]; } + +path_ok "${KV_INDEXES:-}" || fail "kv-indexes must be a plain file path (letters, digits, '.', '_', '-', '/'), not '${KV_INDEXES:-}'." +slug_ok "${CUSTOMER:-}" || fail "customer must be an organisation slug when kv-indexes is set." +slug_ok "${PROJECT:-}" || fail "project must be a project machine name when kv-indexes is set." +[ -n "${API_TOKEN:-}" ] || fail "kv-indexes requires api-token (the project-scoped QUANT_API_TOKEN with kv:read and kv:write), never the content token." +[ -n "${API_BASE_URL:-}" ] || fail "kv-indexes requires api-base-url (the portal /api/v2 URL, QUANT_BASE_URL)." +echo "KV index inputs validated." From e6e484da4daa09cafced42328e68886b979062b4 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Wed, 28 Oct 2026 19:14:36 +1000 Subject: [PATCH 2/2] Quant CLI 7.1.1 --- README.md | 4 ++-- action.yml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index eb8773f..ea5eed1 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ jobs: ## Notes -- This action uses Quant CLI v7 (`quantcdn/cli:7.0.1@sha256:d85c0969…`, pinned by digest) +- This action uses Quant CLI v7 (`quantcdn/cli:7.1.1@sha256:cefe76b4…`, pinned by digest) - For search functionality, please use the dedicated search action - Make sure your `QUANT_TOKEN` is stored securely in your repository secrets @@ -229,7 +229,7 @@ MIT License ## Upgrading from v6 to v7 -v7 runs Quant CLI 7 (7.0.1 from deploy-action v7.0.1). The only breaking change is for edge functions: +v7 runs Quant CLI 7 (7.1.1 from deploy-action v7.1.0). The only breaking change is for edge functions: - Every entry in the `functions` manifest needs an explicit `uuid`. v6 derived one from `id` when it was missing. v7 fails the "Deploy Functions" step (or the diff --git a/action.yml b/action.yml index bc4be7a..17c273f 100644 --- a/action.yml +++ b/action.yml @@ -83,7 +83,7 @@ runs: - name: Validate Rules Access if: inputs.rules != '' - uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b" env: QUANT_API_TOKEN: ${{ inputs.api-token }} QUANT_BASE_URL: ${{ inputs.api-base-url }} @@ -110,7 +110,7 @@ runs: - name: Declare KV Indexes if: inputs.kv-indexes != '' - uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b" env: QUANT_API_TOKEN: ${{ inputs.api-token }} QUANT_BASE_URL: ${{ inputs.api-base-url }} @@ -123,7 +123,7 @@ runs: - name: Deploy Functions if: inputs.functions != '' - uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b" env: CUSTOMER: ${{ inputs.customer }} TOKEN: ${{ inputs.token }} @@ -140,7 +140,7 @@ runs: - name: Deploy Assets if: inputs.dir != '' - uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b" with: args: > deploy @@ -159,7 +159,7 @@ runs: - name: Deploy Rules if: inputs.rules != '' - uses: "docker://quantcdn/cli:7.0.1@sha256:d85c0969bd55fe10393e358a47670c551626335c45d6c7463ac0753074722880" + uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b" env: QUANT_API_TOKEN: ${{ inputs.api-token }} QUANT_BASE_URL: ${{ inputs.api-base-url }}