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
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,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

Expand All @@ -183,26 +184,52 @@ 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
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

## 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
Expand Down
35 changes: 31 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -80,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 }}
Expand All @@ -94,9 +97,33 @@ 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.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b"
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"
uses: "docker://quantcdn/cli:7.1.1@sha256:cefe76b4374d30284f51f54b51607001350ade5f06f41b2dba294cc00518c58b"
env:
CUSTOMER: ${{ inputs.customer }}
TOKEN: ${{ inputs.token }}
Expand All @@ -113,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
Expand All @@ -132,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 }}
Expand Down
20 changes: 20 additions & 0 deletions scripts/validate-kv-indexes-inputs.sh
Original file line number Diff line number Diff line change
@@ -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."
Loading