feat: implement license platform business flows and delivery tooling
Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
22
scripts/backup-delivery.sh
Normal file
22
scripts/backup-delivery.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Run during an upload/admin-write maintenance window. This script never reads or copies the signing key.
|
||||
: "${MYSQL_HOST:?set MYSQL_HOST}"
|
||||
: "${MYSQL_USER:?set MYSQL_USER}"
|
||||
: "${MYSQL_PASSWORD_FILE:?set protected MYSQL_PASSWORD_FILE}"
|
||||
: "${MYSQL_DATABASE:?set MYSQL_DATABASE}"
|
||||
: "${PACKAGE_STORAGE_ROOT:?set PACKAGE_STORAGE_ROOT to the private package directory}"
|
||||
: "${BACKUP_DIR:?set BACKUP_DIR to a protected destination}"
|
||||
case "$BACKUP_DIR" in /*) ;; *) echo 'BACKUP_DIR must be absolute' >&2; exit 1;; esac
|
||||
case "$PACKAGE_STORAGE_ROOT" in /*) ;; *) echo 'PACKAGE_STORAGE_ROOT must be absolute' >&2; exit 1;; esac
|
||||
mkdir -p "$BACKUP_DIR"; chmod 700 "$BACKUP_DIR"
|
||||
name=$(date -u +%Y%m%dT%H%M%SZ); work="$BACKUP_DIR/.delivery-$name"
|
||||
mkdir "$work"; trap 'unset MYSQL_PWD; rm -rf "$work"' EXIT HUP INT TERM
|
||||
export MYSQL_PWD=$(cat "$MYSQL_PASSWORD_FILE")
|
||||
mysqldump --host="$MYSQL_HOST" --port="${MYSQL_PORT:-3306}" --user="$MYSQL_USER" --single-transaction --no-tablespaces --routines --triggers "$MYSQL_DATABASE" > "$work/mysql.sql"
|
||||
unset MYSQL_PWD
|
||||
tar --sort=name --mtime='UTC 1970-01-01' --owner=0 --group=0 --numeric-owner -C "$PACKAGE_STORAGE_ROOT" -cf "$work/packages.tar" .
|
||||
(cd "$work" && sha256sum mysql.sql packages.tar > SHA256SUMS)
|
||||
printf '%s\n' 'Signing keys are intentionally excluded. Record migration version and quiescence window separately.' > "$work/METADATA.txt"
|
||||
mv "$work" "$BACKUP_DIR/delivery-$name"
|
||||
printf '%s\n' "$BACKUP_DIR/delivery-$name"
|
||||
18
scripts/check-delivery.sh
Normal file
18
scripts/check-delivery.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
expected=1
|
||||
for file in backend/migrations/*.up.sql; do
|
||||
[ -s "$file" ] || { echo 'empty migration' >&2; exit 1; }
|
||||
base=${file%.up.sql}
|
||||
[ -s "$base.down.sql" ] || { echo 'missing down migration' >&2; exit 1; }
|
||||
name=${base##*/}
|
||||
version=${name%%_*}
|
||||
[ "$version" = "$(printf '%06d' "$expected")" ] || { echo 'migration sequence must be contiguous and unique' >&2; exit 1; }
|
||||
expected=$((expected + 1))
|
||||
done
|
||||
[ "$expected" -gt 1 ] || { echo 'no migrations found' >&2; exit 1; }
|
||||
for file in backend/migrations/*.down.sql; do
|
||||
[ -s "${file%.down.sql}.up.sql" ] || { echo 'missing up migration' >&2; exit 1; }
|
||||
done
|
||||
for file in scripts/*.sh deploy/entrypoint.sh; do sh -n "$file"; done
|
||||
printf '%s\n' 'Migration naming/pairs and shell syntax passed; this does not execute migrations or Compose.'
|
||||
22
scripts/restore-delivery.sh
Normal file
22
scripts/restore-delivery.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Restore only into an explicitly empty isolated database/private directory. Never restores signing keys.
|
||||
: "${MYSQL_HOST:?set MYSQL_HOST}"; : "${MYSQL_USER:?set MYSQL_USER}"; : "${MYSQL_PASSWORD_FILE:?set protected MYSQL_PASSWORD_FILE}"; : "${MYSQL_DATABASE:?set MYSQL_DATABASE}"
|
||||
: "${PACKAGE_STORAGE_ROOT:?set PACKAGE_STORAGE_ROOT for the empty private target directory}"; : "${BACKUP_DIR:?set BACKUP_DIR containing delivery-*/mysql.sql and packages.tar}"
|
||||
: "${CONFIRM_EMPTY_RESTORE:?set CONFIRM_EMPTY_RESTORE=YES after independently verifying isolation}"
|
||||
[ "$CONFIRM_EMPTY_RESTORE" = YES ] || { echo 'CONFIRM_EMPTY_RESTORE must be YES' >&2; exit 1; }
|
||||
case "$PACKAGE_STORAGE_ROOT" in /*) ;; *) echo 'PACKAGE_STORAGE_ROOT must be absolute' >&2; exit 1;; esac
|
||||
[ -d "$PACKAGE_STORAGE_ROOT" ] || { echo 'target package directory must exist' >&2; exit 1; }
|
||||
[ -z "$(find "$PACKAGE_STORAGE_ROOT" -mindepth 1 -print -quit)" ] || { echo 'target package directory must be empty' >&2; exit 1; }
|
||||
backup=$(find "$BACKUP_DIR" -mindepth 1 -maxdepth 1 -type d -name 'delivery-*' -exec test -f '{}/mysql.sql' \; -print | sort | tail -1)
|
||||
[ -n "$backup" ] || { echo 'no backup found' >&2; exit 1; }
|
||||
(cd "$backup" && sha256sum -c SHA256SUMS)
|
||||
case "$MYSQL_DATABASE" in ''|*[!a-zA-Z0-9_]*) echo 'MYSQL_DATABASE must be an ASCII identifier' >&2; exit 1;; esac
|
||||
export MYSQL_PWD=$(cat "$MYSQL_PASSWORD_FILE")
|
||||
trap 'unset MYSQL_PWD' EXIT HUP INT TERM
|
||||
count=$(mysql --host="$MYSQL_HOST" --port="${MYSQL_PORT:-3306}" --user="$MYSQL_USER" --batch --skip-column-names "$MYSQL_DATABASE" -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '$MYSQL_DATABASE'")
|
||||
[ "$count" = 0 ] || { echo 'target database must exist and be empty' >&2; exit 1; }
|
||||
mysql --host="$MYSQL_HOST" --port="${MYSQL_PORT:-3306}" --user="$MYSQL_USER" "$MYSQL_DATABASE" < "$backup/mysql.sql"
|
||||
unset MYSQL_PWD
|
||||
tar -C "$PACKAGE_STORAGE_ROOT" -xf "$backup/packages.tar"
|
||||
printf '%s\n' 'Restore completed without restoring signing keys. Run explicit migrations/version checks and release/object checksum verification before traffic.'
|
||||
Reference in New Issue
Block a user