diff --git a/.github/platform-allowlist.py b/.github/platform-allowlist.py new file mode 100644 index 0000000..5baa987 --- /dev/null +++ b/.github/platform-allowlist.py @@ -0,0 +1,13 @@ +"""Print the image allowlist the platform's nodes get from this catalog, as the JSON body of +PUT /v1/image-allowlist: every repository the recipes use, without tag or digest.""" +import glob, json, yaml + +names = set() +for path in glob.glob("apps/*/template.yml"): + for svc in ((yaml.safe_load(open(path)) or {}).get("services") or {}).values(): + ref = str((svc or {}).get("image", "")).split("@")[0] + if ref.rfind(":") > ref.rfind("/"): + ref = ref[: ref.rfind(":")] + if ref: + names.add(ref) +print(json.dumps({"images": sorted(names)})) diff --git a/.github/platform-check.sh b/.github/platform-check.sh index 1017122..c4ab4ed 100755 --- a/.github/platform-check.sh +++ b/.github/platform-check.sh @@ -14,7 +14,11 @@ api() { curl -fsS -H "Authorization: Bearer $HARBOR_TOKEN" "$@"; } json() { python3 -c "import sys,json; d=json.load(sys.stdin); print($1)"; } slug=$(basename "$dir") -api -X POST -H 'Content-Type: application/yaml' --data-binary @"$dir/template.yml" "$HARBOR_URL/v1/templates" >/dev/null +# on a refusal (an image not on the allowlist, say) show the platform's reasons +if ! out=$(curl -sS --fail-with-body -H "Authorization: Bearer $HARBOR_TOKEN" -X POST -H 'Content-Type: application/yaml' \ + --data-binary @"$dir/template.yml" "$HARBOR_URL/v1/templates"); then + echo "$slug: the platform refused template.yml: $out"; exit 1 +fi version=$(api "$HARBOR_URL/v1/templates?slug=$slug" | json "sorted(d['data'], key=lambda t: t['created_at'])[-1]['version']") health=$(api "$HARBOR_URL/v1/templates/$slug?version=$version" | json "d.get('health_path','/')") ref="smoke-$slug-$$" diff --git a/.github/platform.ref b/.github/platform.ref index e91083b..0f618fd 100644 --- a/.github/platform.ref +++ b/.github/platform.ref @@ -1 +1 @@ -e6c8b85797a9068c211702afa30a9b8bba082f66 +1c42cea53cd56434bdee4c4efea7fb9a3a8ac4b4 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 8b9982e..f9e8e9a 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -83,6 +83,11 @@ jobs: # the runner's sudo ignores -E, so pass the settings explicitly H="HARBOR_DATA_DIR=$HARBOR_DATA_DIR HARBOR_RUNTIME=$HARBOR_RUNTIME HARBOR_BASE_DOMAIN=$HARBOR_BASE_DOMAIN HARBOR_CAPACITY_CPU_MILLIS=$HARBOR_CAPACITY_CPU_MILLIS HARBOR_CAPACITY_MEMORY_MB=$HARBOR_CAPACITY_MEMORY_MB HARBOR_CAPACITY_STORAGE_MB=$HARBOR_CAPACITY_STORAGE_MB" export HARBOR_TOKEN=$(sudo env $H /tmp/harbord token create ci | grep -o 'hbr_[A-Za-z0-9_-]*') - sudo env $H /tmp/harbord serve & sleep 2 + # As on the servers, the node only runs images on its allowlist, and the control plane + # sets that list from the catalog. A name the node won't take fails here, not in production. + sudo env $H HARBOR_IMAGE_ALLOWLIST_MANAGED=true /tmp/harbord serve & sleep 2 export HARBOR_URL=http://127.0.0.1:7700 + python3 .github/platform-allowlist.py > "$RUNNER_TEMP/allowlist.json" + curl -sS --fail-with-body -X PUT -H "Authorization: Bearer $HARBOR_TOKEN" -H 'Content-Type: application/json' \ + --data-binary @"$RUNNER_TEMP/allowlist.json" "$HARBOR_URL/v1/image-allowlist" for app in apps/*/; do sh .github/platform-check.sh "$app"; done diff --git a/README.md b/README.md index c907f96..364af84 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ by the right user, the default memory and CPU limits, no-new-privileges, and the needs Docker with Compose v2, `python3` and `curl`. Every pull request runs the same test on the recipes it changes, plus Cottage's own checks of -every recipe. Make sure both pass; we can't merge a recipe until they do. Pull requests from forks +every recipe. Those run the platform as the servers do, with an image allowlist built from this +catalog, so the servers will accept every image a merged recipe uses. Make sure both pass; we can't merge a recipe until they do. Pull requests from forks get the Compose test, and we run Cottage's checks before merging. [docs/licensing.md](docs/licensing.md) lists which apps we can host under their licences, and on