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
38 changes: 35 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

name: CI

permissions:
contents: read

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
Expand All @@ -23,7 +26,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Prepare a test file
run: |
Expand All @@ -42,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Prepare a test file
run: |
Expand All @@ -65,7 +68,7 @@ jobs:
test-functions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

# Create test functions
- name: Prepare test functions
Expand Down Expand Up @@ -131,3 +134,32 @@ jobs:
token: ${{ secrets.QUANT_TOKEN }}
dir: build
functions: "./functions/config.json"

test-rules-guard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Valid rules inputs are accepted
env:
RULES: edge-rules.json
FUNCTIONS: .quant-functions.json
CUSTOMER: quant
PROJECT: github-actions
RULES_FORCE: "false"
API_TOKEN: dummy
API_BASE_URL: https://dashboard.quantcdn.io/api/v2
run: ./scripts/validate-rules-inputs.sh

- name: Inputs that would become extra CLI flags are refused
run: |
base=(RULES=edge-rules.json FUNCTIONS=.quant-functions.json CUSTOMER=quant PROJECT=github-actions RULES_FORCE=false API_TOKEN=dummy API_BASE_URL=https://dashboard.quantcdn.io/api/v2)
for bad in "RULES=r.json --api-base-url=https://attacker.example/api/v2" "RULES=--api-token=x" 'RULES=r.json"x' \
"FUNCTIONS=f.json -c other" "CUSTOMER=quant --api-base-url=x" "PROJECT=-p" "RULES_FORCE=yes" \
"API_TOKEN=" "API_BASE_URL="; do
if env "${base[@]}" "$bad" ./scripts/validate-rules-inputs.sh >/dev/null 2>&1; then
echo "::error::accepted unsafe input: $bad"; exit 1
fi
done
echo "All unsafe inputs refused."
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This GitHub Action deploys your static site and/or functions to QuantCDN using t
|-------|-------------|----------|---------|
| `customer` | Your QuantCDN customer account name | Yes | - |
| `project` | Your QuantCDN project name | Yes | - |
| `token` | Your QuantCDN API token | Yes | - |
| `token` | Your content write token (uploads only; never used for rules) | Yes | - |
| `dir` | The directory to deploy | No | - |
| `functions` | Path to JSON file containing functions configuration | No | - |
| `skip-unpublish` | Skip automatic unpublishing of assets | No | `false` |
Expand All @@ -41,6 +41,10 @@ This GitHub Action deploys your static site and/or functions to QuantCDN using t
| `endpoint` | Specify the QuantCDN API endpoint | No | `https://api.quantcdn.io/v1` |
| `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 | - |
| `rules-force` | Overwrite managed rules changed outside code (never takes over another rule) | No | `false` |

## Example Workflows

Expand Down Expand Up @@ -155,6 +159,36 @@ jobs:
- For search functionality, please use the dedicated search action
- Make sure your `QUANT_TOKEN` is stored securely in your repository secrets

## Edge rules

Provide `rules: edge-rules.json`, `functions: edge-functions.json`,
`api-token: ${{ secrets.QUANT_API_TOKEN }}` and
`api-base-url: ${{ vars.QUANT_BASE_URL }}` alongside the normal deployment inputs.
The Quant portal injects the project-scoped API secret and the environment-specific
portal `/api/v2` URL when a static or Studio template includes `edge-rules.json`.
Uploads continue to use the separate `token` input. Never substitute the content
write token for `api-token`.

The action runs in this order:

1. **Validate rules inputs.** `rules`, `functions`, `customer` and `project` must be
plain paths or slugs (no spaces, quotes or leading `-`), and `api-token` and
`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.**

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
assets are live with the previous rules. Re-run the workflow: deploys are
idempotent, so the rules step converges and unchanged assets are skipped.

## License

MIT License
64 changes: 61 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
description: "Your project name"
required: true
token:
description: "Your API token"
description: "Your content write token (uploads only; never used for rules)"
required: true
dir:
description: "The directory to deploy"
Expand Down Expand Up @@ -49,12 +49,54 @@ inputs:
functions:
description: "Path to JSON file containing functions configuration"
required: false
rules:
description: "Path to an edge rules JSON manifest"
required: false
api-token:
description: "Project-scoped portal API token for rules (QUANT_API_TOKEN)"
required: false
api-base-url:
description: "Portal API base URL, including /api/v2 (QUANT_BASE_URL)"
required: false
rules-force:
description: "Overwrite managed rules changed outside code (never takes over another rule)"
required: false
default: "false"
runs:
using: "composite"
steps:
- name: Validate Rules Inputs
if: inputs.rules != ''
shell: bash
env:
RULES: ${{ inputs.rules }}
FUNCTIONS: ${{ inputs.functions }}
CUSTOMER: ${{ inputs.customer }}
PROJECT: ${{ inputs.project }}
RULES_FORCE: ${{ inputs.rules-force }}
API_TOKEN: ${{ inputs.api-token }}
API_BASE_URL: ${{ inputs.api-base-url }}
run: '"$GITHUB_ACTION_PATH/scripts/validate-rules-inputs.sh"'

- name: Validate Rules Access
if: inputs.rules != ''
uses: "docker://quantcdn/cli:6.3.0@sha256:cc5025e8749068b3a445331430d461be9467ce0f811838fdba9710dd388d4054"
env:
QUANT_API_TOKEN: ${{ inputs.api-token }}
QUANT_BASE_URL: ${{ inputs.api-base-url }}
with:
args: >
rules
"${{ inputs.rules }}"
--functions="${{ inputs.functions }}"
-c "${{ inputs.customer }}"
-p "${{ inputs.project }}"
--force=${{ inputs.rules-force }}
--dry-run

- name: Deploy Functions
if: inputs.functions != ''
uses: "docker://quantcdn/cli:6.1.0"
uses: "docker://quantcdn/cli:6.3.0@sha256:cc5025e8749068b3a445331430d461be9467ce0f811838fdba9710dd388d4054"
env:
CUSTOMER: ${{ inputs.customer }}
TOKEN: ${{ inputs.token }}
Expand All @@ -71,7 +113,7 @@ runs:

- name: Deploy Assets
if: inputs.dir != ''
uses: "docker://quantcdn/cli:6.1.0"
uses: "docker://quantcdn/cli:6.3.0@sha256:cc5025e8749068b3a445331430d461be9467ce0f811838fdba9710dd388d4054"
with:
args: >
deploy
Expand All @@ -87,6 +129,22 @@ runs:
--endpoint=${{ inputs.endpoint }}
--revision-log=${{ inputs.revision-log }}
--enable-index-html=${{ inputs.enable-index-html }}

- name: Deploy Rules
if: inputs.rules != ''
uses: "docker://quantcdn/cli:6.3.0@sha256:cc5025e8749068b3a445331430d461be9467ce0f811838fdba9710dd388d4054"
env:
QUANT_API_TOKEN: ${{ inputs.api-token }}
QUANT_BASE_URL: ${{ inputs.api-base-url }}
with:
args: >
rules
"${{ inputs.rules }}"
--functions="${{ inputs.functions }}"
-c "${{ inputs.customer }}"
-p "${{ inputs.project }}"
--force=${{ inputs.rules-force }}

branding:
icon: "upload-cloud"
color: "blue"
25 changes: 25 additions & 0 deletions scripts/validate-rules-inputs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Refuse rules inputs that could become extra CLI arguments.
#
# A docker:// step passes `args:` to the container as one string that is split
# on whitespace, so a value such as "r.json --api-base-url=https://x/api/v2"
# would become flags; CLI flags override QUANT_API_TOKEN/QUANT_BASE_URL and
# could send the portal token to another host. 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 "${RULES:-}" || fail "rules must be a plain file path (letters, digits, '.', '_', '-', '/'), not '${RULES:-}'."
if [ -n "${FUNCTIONS:-}" ]; then
path_ok "$FUNCTIONS" || fail "functions must be a plain file path when rules is set."
fi
slug_ok "${CUSTOMER:-}" || fail "customer must be an organisation slug when rules is set."
slug_ok "${PROJECT:-}" || fail "project must be a project machine name when rules is set."
[[ "${RULES_FORCE:-false}" =~ ^(true|false)$ ]] || fail "rules-force must be true or false."
[ -n "${API_TOKEN:-}" ] || fail "rules requires api-token (the project-scoped QUANT_API_TOKEN), never the content token."
[ -n "${API_BASE_URL:-}" ] || fail "rules requires api-base-url (the portal /api/v2 URL, QUANT_BASE_URL)."
echo "Rules inputs validated."
Loading