diff --git a/.github/scripts/review-upstream-diff.sh b/.github/scripts/review-upstream-diff.sh
new file mode 100755
index 0000000..2aca83e
--- /dev/null
+++ b/.github/scripts/review-upstream-diff.sh
@@ -0,0 +1,120 @@
+#!/usr/bin/env bash
+# Mechanical review of an upstream diff before it is merged into the NEMTUS branch.
+#
+# Usage: .github/scripts/review-upstream-diff.sh
+#
+# Prints a Markdown report on stdout and classifies the diff through the exit status:
+# 0 routine - only version lines changed (nginx, s6-overlay, docker-gen, acme-tiny,
+# the 00-welcome banner)
+# 3 review - anything else; the report lists what to look at
+# 4 blocked - the diff touches .github/, which would run with this repository's
+# privileges once merged; mirror-sync refuses to open a pull request
+#
+# This is a tripwire, not a malware detector: it surfaces the obvious signs (new download
+# hosts, pipe-to-shell, binaries, opaque blobs, changes to startup scripts) so the human
+# review of the sync pull request starts in the right place. A change it calls "routine"
+# still has to be read.
+#
+# It only reads git objects. It never checks out or executes anything from .
+set -euo pipefail
+
+base="${1:?usage: review-upstream-diff.sh }"
+head="${2:?usage: review-upstream-diff.sh }"
+
+routine_files='Dockerfile fs_overlay/etc/cont-init.d/00-welcome'
+routine_line='^(ARG +DIST=nginx:[0-9]+\.[0-9]+\.[0-9]+|ENV +(S6_OVERLAY_VERSION|DOCKER_GEN_VERSION|ACME_TINY_VERSION)=v?[0-9]+(\.[0-9]+)*|HTTPS-PORTAL v[0-9]+\.[0-9]+\.[0-9]+)$'
+suspicious='(curl|wget)[^|;&]*\|[[:space:]]*(ba|z|da)?sh|base64[[:space:]]+(-d|--decode)|\beval\b|/dev/tcp/|\bnc[[:space:]]+-|\bncat\b|\bsocat\b|chmod[[:space:]]+[0-7]*[4267][0-7]{3}\b|chmod[[:space:]]+[ug]?\+s|authorized_keys|\bcrontab\b|LD_PRELOAD|python[0-9.]*[[:space:]]+-c|perl[[:space:]]+-e|ruby[[:space:]]+-e|\bpip3?[[:space:]]+install|\bgem[[:space:]]+install|\bnpm[[:space:]]+(i|install)\b|--no-check-certificate|[[:space:]]-k[[:space:]]|--insecure'
+url_host='https?://[A-Za-z0-9._-]+'
+
+verdict=0
+blocked=()
+review=()
+flag_review() { review+=("$1"); [ "${verdict}" -ge 3 ] || verdict=3; }
+flag_blocked() { blocked+=("$1"); verdict=4; }
+clip() { cut -c1-200; }
+
+mapfile -t files < <(git diff --name-only "${base}" "${head}")
+
+for file in "${files[@]}"; do
+ case "${file}" in
+ .github/*) flag_blocked "\`${file}\`" ;;
+ esac
+done
+
+# Files outside the routine set, and non-version lines inside it.
+for file in "${files[@]}"; do
+ if [[ " ${routine_files} " == *" ${file} "* ]]; then
+ while IFS= read -r line; do
+ [ -n "${line}" ] || continue
+ if ! grep -Eq "${routine_line}" <<< "${line:1}"; then
+ flag_review "\`${file}\`: non-version line \`$(clip <<< "${line}")\`"
+ fi
+ done < <(git diff -U0 "${base}" "${head}" -- "${file}" | grep -E '^[+-]' | grep -Ev '^(\+\+\+|---) ' || true)
+ continue
+ fi
+ case "${file}" in
+ .github/*) ;;
+ fs_overlay/*) flag_review "\`${file}\`: changed (shipped inside the image)" ;;
+ *) flag_review "\`${file}\`: changed" ;;
+ esac
+done
+
+added="$(git diff -U0 "${base}" "${head}" | grep -E '^\+' | grep -Ev '^\+\+\+ ' || true)"
+
+# Hosts that appear in added lines but nowhere in the base tree.
+known_hosts="$(git grep -hoEI "${url_host}" "${base}" -- . 2>/dev/null | sort -u || true)"
+while IFS= read -r host; do
+ [ -n "${host}" ] || continue
+ if ! grep -qxF "${host}" <<< "${known_hosts}"; then
+ flag_review "new host in added lines: \`${host}\`"
+ fi
+done < <(grep -oE "${url_host}" <<< "${added}" | sort -u || true)
+
+while IFS= read -r line; do
+ [ -n "${line}" ] || continue
+ flag_review "suspicious pattern: \`$(clip <<< "${line}")\`"
+done < <(grep -E -- "${suspicious}" <<< "${added}" || true)
+
+if grep -Eq '[A-Za-z0-9+/=]{120,}' <<< "${added}"; then
+ flag_review 'added line with a long opaque string (120+ base64-like characters)'
+fi
+
+while IFS=$'\t' read -r adds dels file; do
+ if [ "${adds}" = '-' ] && [ "${dels}" = '-' ]; then
+ flag_review "\`${file}\`: binary file"
+ fi
+done < <(git diff --numstat "${base}" "${head}")
+
+while IFS= read -r line; do
+ [ -n "${line}" ] || continue
+ flag_review "file mode: \`${line# }\`"
+done < <(git diff --summary "${base}" "${head}" | grep -E 'mode change|create mode 100755|create mode 120000' || true)
+
+echo "### Upstream diff review (\`$(git rev-parse --short "${base}")..$(git rev-parse --short "${head}")\`)"
+echo
+case "${verdict}" in
+ 0) echo '**Routine**: only version lines changed.' ;;
+ 3) echo '**Needs review**: the diff goes beyond version lines.' ;;
+ 4) echo '**Blocked**: the diff touches `.github/`.' ;;
+esac
+echo
+echo '```'
+git diff --stat "${base}" "${head}" | cut -c1-160
+echo '```'
+if [ "${#blocked[@]}" -gt 0 ]; then
+ echo
+ echo 'Files under `.github/` (these would run with this repository'"'"'s privileges):'
+ echo
+ printf -- '- %s\n' "${blocked[@]}" | head -n 50
+fi
+if [ "${#review[@]}" -gt 0 ]; then
+ echo
+ echo 'Look at:'
+ echo
+ printf -- '- %s\n' "${review[@]}" | head -n 80
+ [ "${#review[@]}" -le 80 ] || echo "- ... and $(( ${#review[@]} - 80 )) more"
+fi
+echo
+echo '_Mechanical check only. It catches obvious signs, not subtle changes; read the diff._'
+
+exit "${verdict}"
diff --git a/.github/workflows/mirror-sync.yml b/.github/workflows/mirror-sync.yml
new file mode 100644
index 0000000..047dd14
--- /dev/null
+++ b/.github/workflows/mirror-sync.yml
@@ -0,0 +1,361 @@
+name: mirror-sync (upstream SteveLTN/https-portal)
+
+# Follows upstream github.com/SteveLTN/https-portal:master and reports when NEMTUS has a
+# release to make. See docs/nemtus-fork.md ("Automation").
+#
+# `sync` (daily):
+# 1. Reviews the new upstream commits with .github/scripts/review-upstream-diff.sh.
+# A diff that touches .github/ is BLOCKED: merged, those files would run with this
+# repository's privileges. The run fails and nothing is pushed.
+# 2. Fast-forwards the `master` mirror to upstream.
+# 3. Waits out a cooldown (COOLDOWN_DAYS since upstream's branch last moved, taken from
+# GitHub's activity log, not from commit dates, which the author controls). A bad
+# upstream change is usually noticed and reverted within days; not picking it up the
+# moment it lands keeps it out of this fork. Dispatch with `skip_cooldown` for an
+# urgent security fix.
+# 4. Merges upstream into a `sync/upstream-` branch and opens a pull request into
+# `nemtus` with the review report in its body, titled [routine] or [needs review].
+# Merge it with a MERGE COMMIT. A conflict fails the run with the details in the job
+# summary.
+#
+# This job has a write token, so it must never execute upstream code: it runs git and
+# the review script from the trusted `nemtus` checkout only. Building happens in
+# nemtus-image.yml with a read-only token.
+#
+# `release-watch` (daily, read-only): reports when upstream's latest release is not
+# contained in the latest `nemtus-v*` release. Releasing stays a human decision: the tag
+# is signed and restricted to admins.
+#
+# `notify`: posts to Discord (repository secret DISCORD_WEBHOOK_URL; skipped when unset)
+# when a run fails, when new upstream commits are first seen, when a sync pull request
+# is opened, and when a release is pending (on the day upstream releases, then Mondays).
+#
+# `keepalive`: resets GitHub's 60-day scheduled-workflow auto-disable clock.
+
+on:
+ schedule:
+ - cron: '23 3 * * *' # daily, 03:23 UTC
+ workflow_dispatch:
+ inputs:
+ skip_cooldown:
+ description: 'Open the sync pull request now, without waiting out the cooldown'
+ type: boolean
+ default: false
+
+permissions:
+ contents: read
+
+concurrency:
+ group: mirror-sync
+ cancel-in-progress: false
+
+env:
+ UPSTREAM_REPO: SteveLTN/https-portal
+ UPSTREAM_BRANCH: master
+ MIRROR_BRANCH: master
+ LOCAL_BRANCH: nemtus
+ COOLDOWN_DAYS: 3
+ # This repository is a fork: without GH_REPO, gh targets the parent repository.
+ GH_REPO: ${{ github.repository }}
+
+jobs:
+ sync:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ pull-requests: write
+ actions: write
+ outputs:
+ message: ${{ steps.sync.outputs.message }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: nemtus
+ fetch-depth: 0
+ persist-credentials: true
+
+ - name: Sync upstream
+ id: sync
+ env:
+ GH_TOKEN: ${{ github.token }}
+ SKIP_COOLDOWN: ${{ inputs.skip_cooldown }}
+ run: |
+ set -euo pipefail
+ git config user.name 'github-actions[bot]'
+ git config user.email 'github-actions[bot]@users.noreply.github.com'
+
+ upstream_url="https://github.com/${UPSTREAM_REPO}.git"
+ git remote add upstream "${upstream_url}"
+ git fetch --no-tags upstream "${UPSTREAM_BRANCH}"
+ git fetch --no-tags origin "+refs/heads/${MIRROR_BRANCH}:refs/remotes/origin/${MIRROR_BRANCH}"
+ upstream="upstream/${UPSTREAM_BRANCH}"
+ upstream_sha="$(git rev-parse "${upstream}")"
+ short="$(git rev-parse --short "${upstream}")"
+ sync_branch="sync/upstream-${short}"
+ say() { echo "message=$1" >> "$GITHUB_OUTPUT"; }
+
+ # Close automated sync pull requests that a newer one (or the base) supersedes.
+ # Only bot-authored pull requests whose head commit the bot made; a branch a
+ # human pushed to is left alone.
+ close_superseded() {
+ local keep="$1" reason="$2" number branch committer
+ while read -r number branch; do
+ [ -n "${number}" ] && [ "${branch}" != "${keep}" ] || continue
+ committer="$(gh api "repos/${GH_REPO}/commits/${branch}" --jq '.commit.committer.email' || true)"
+ if [ "${committer}" != 'github-actions[bot]@users.noreply.github.com' ]; then
+ echo "::notice::#${number} (${branch}) has commits not made by the sync bot; leaving it open."
+ continue
+ fi
+ gh pr close "${number}" --delete-branch --comment "${reason}" ||
+ echo "::warning::could not close #${number}"
+ done < <(gh pr list --base "${LOCAL_BRANCH}" --state open --limit 100 \
+ --json number,headRefName,author \
+ --jq '.[] | select(.headRefName | startswith("sync/upstream-")) | select(.author.is_bot) | "\(.number) \(.headRefName)"')
+ }
+
+ if git merge-base --is-ancestor "${upstream}" HEAD; then
+ echo "Up to date with upstream@${short}." | tee -a "$GITHUB_STEP_SUMMARY"
+ close_superseded '' "\`${LOCAL_BRANCH}\` already contains every upstream commit this pull request would merge."
+ exit 0
+ fi
+
+ # 1. Review. The script comes from the nemtus checkout and only reads git objects.
+ base="$(git merge-base HEAD "${upstream}")"
+ set +e
+ report="$(.github/scripts/review-upstream-diff.sh "${base}" "${upstream}")"
+ verdict=$?
+ set -e
+ printf '%s\n' "${report}" >> "$GITHUB_STEP_SUMMARY"
+ case "${verdict}" in
+ 0) label='routine' ;;
+ 3) label='needs review' ;;
+ 4)
+ say "BLOCKED: upstream@${short} touches .github/. Nothing was synced; review the upstream diff by hand."
+ echo "::error::upstream@${short} touches .github/; refusing to sync."
+ exit 1
+ ;;
+ *)
+ echo "::error::review-upstream-diff.sh failed (exit ${verdict})"
+ exit 1
+ ;;
+ esac
+
+ # 2. Fast-forward the mirror branch.
+ first_seen=''
+ if [ "$(git rev-parse "origin/${MIRROR_BRANCH}")" != "${upstream_sha}" ]; then
+ if ! git merge-base --is-ancestor "origin/${MIRROR_BRANCH}" "${upstream}"; then
+ say "FAILED: ${MIRROR_BRANCH} cannot be fast-forwarded to upstream@${short} (upstream history was rewritten, or ${MIRROR_BRANCH} has local commits)."
+ echo "::error::${MIRROR_BRANCH} is not an ancestor of upstream@${short}."
+ exit 1
+ fi
+ git push origin "${upstream_sha}:refs/heads/${MIRROR_BRANCH}"
+ first_seen=1
+ fi
+ compare="${GITHUB_SERVER_URL}/${GH_REPO}/compare/${LOCAL_BRANCH}...${MIRROR_BRANCH}"
+
+ # 3. Cooldown, measured from when upstream's branch last moved.
+ if [ "${SKIP_COOLDOWN}" != 'true' ]; then
+ moved_at="$(gh api "repos/${UPSTREAM_REPO}/activity?ref=${UPSTREAM_BRANCH}&per_page=1" \
+ --jq "map(select(.after == \"${upstream_sha}\")) | .[0].timestamp // empty")"
+ if [ -z "${moved_at}" ]; then
+ # Upstream moved between the fetch and the API call, or the entry is missing:
+ # count from now. The next run sees a consistent state.
+ moved_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+ fi
+ ready_epoch="$(( $(date -u -d "${moved_at}" +%s) + COOLDOWN_DAYS * 86400 ))"
+ ready_at="$(date -u -d "@${ready_epoch}" +%Y-%m-%dT%H:%M:%SZ)"
+ if [ "$(date -u +%s)" -lt "${ready_epoch}" ]; then
+ {
+ echo
+ echo "Cooldown: upstream@${short} landed ${moved_at}; the sync pull request opens after ${ready_at}."
+ echo "Dispatch this workflow with \`skip_cooldown\` to open it now."
+ } >> "$GITHUB_STEP_SUMMARY"
+ if [ -n "${first_seen}" ]; then
+ say "New upstream commits (upstream@${short}, ${label}). Sync pull request opens after ${ready_at}; dispatch with skip_cooldown for an urgent fix. ${compare}"
+ fi
+ exit 0
+ fi
+ fi
+
+ # 4. Merge into a sync branch and open the pull request.
+ if git ls-remote --exit-code --heads origin "${sync_branch}" > /dev/null; then
+ echo "${sync_branch} already exists on origin; not rebuilding it."
+ else
+ git checkout -b "${sync_branch}"
+ if ! git merge --no-ff -m "Merge upstream ${UPSTREAM_REPO}:${UPSTREAM_BRANCH}@${short} into ${LOCAL_BRANCH}" "${upstream}"; then
+ conflicts="$(git diff --name-only --diff-filter=U | sort)"
+ hunks="$(git diff --diff-filter=U | head -c 60000)"
+ git merge --abort
+ {
+ echo
+ echo "## Upstream sync conflict: ${UPSTREAM_REPO}@${short}"
+ echo
+ echo 'Conflicting files:'
+ echo '```'
+ echo "${conflicts}"
+ echo '```'
+ echo '```diff'
+ echo "${hunks}"
+ echo '```'
+ echo 'Resolve locally (merge commit, not squash):'
+ echo '```bash'
+ echo "git fetch origin && git switch -c ${sync_branch} origin/${LOCAL_BRANCH}"
+ echo "git merge --no-ff origin/${MIRROR_BRANCH}"
+ echo '# resolve, keeping the NEMTUS layer (docs/nemtus-fork.md), then:'
+ echo "git push -u origin ${sync_branch}"
+ echo "gh pr create -R ${GH_REPO} --base ${LOCAL_BRANCH} --title 'Sync upstream ${UPSTREAM_REPO}:${UPSTREAM_BRANCH}@${short}'"
+ echo '```'
+ } >> "$GITHUB_STEP_SUMMARY"
+ say "FAILED: upstream@${short} conflicts with ${LOCAL_BRANCH}; resolve by hand (steps in the job summary)."
+ echo "::error::upstream@${short} does not merge cleanly into ${LOCAL_BRANCH}."
+ exit 1
+ fi
+ git push -u origin "${sync_branch}"
+ fi
+
+ pr_url="$(gh pr list --head "${sync_branch}" --base "${LOCAL_BRANCH}" --state open --json url --jq '.[0].url // empty')"
+ if [ -n "${pr_url}" ]; then
+ echo "Sync pull request already open: ${pr_url}" | tee -a "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+
+ body="$(printf '%s\n' \
+ "Automated mirror sync. Merges upstream \`${UPSTREAM_REPO}:${UPSTREAM_BRANCH}\`@\`${short}\` into \`${LOCAL_BRANCH}\`." \
+ '' \
+ '**Merge this pull request with a MERGE COMMIT (not squash).** Squashing drops the upstream parent, and every later sync would replay upstream history.' \
+ '' \
+ 'Read the upstream diff before merging: nothing here is published until a `nemtus-v*` tag is pushed, but this merge is the review gate.' \
+ '' \
+ "${report}")"
+ pr_url="$(gh pr create --base "${LOCAL_BRANCH}" --head "${sync_branch}" \
+ --title "Sync upstream ${UPSTREAM_REPO}:${UPSTREAM_BRANCH}@${short} [${label}]" \
+ --body "${body}")"
+ echo "Opened ${pr_url}" | tee -a "$GITHUB_STEP_SUMMARY"
+
+ # A pull request opened with GITHUB_TOKEN does not trigger pull_request
+ # workflows, so start the required `build` check on the sync branch explicitly.
+ gh workflow run nemtus-image.yml --ref "${sync_branch}" ||
+ echo "::warning::could not start nemtus-image.yml on ${sync_branch}; run it by hand."
+
+ close_superseded "${sync_branch}" "Superseded by ${pr_url}, which merges a newer upstream head."
+ say "Sync pull request opened (${label}): ${pr_url}"
+
+ release-watch:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ outputs:
+ message: ${{ steps.watch.outputs.message }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: nemtus
+ fetch-depth: 0
+ persist-credentials: false
+
+ - name: Compare upstream's latest release with the latest NEMTUS release
+ id: watch
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ set -euo pipefail
+ git fetch --quiet --tags origin
+
+ release="$(gh api "repos/${UPSTREAM_REPO}/releases/latest" --jq '.tag_name')"
+ published="$(gh api "repos/${UPSTREAM_REPO}/releases/latest" --jq '.published_at')"
+ if ! printf '%s' "${release}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
+ echo "::error::unexpected upstream release tag '${release}'"
+ exit 1
+ fi
+ git fetch --quiet --no-tags "https://github.com/${UPSTREAM_REPO}.git" \
+ "+refs/tags/${release}:refs/upstream-tags/${release}"
+ release_commit="$(git rev-parse "refs/upstream-tags/${release}^{commit}")"
+
+ latest="$(git tag --list 'nemtus-v*' --sort=-creatordate | head -n 1)"
+ {
+ echo '## Release watch'
+ echo
+ echo "| | |"
+ echo "|---|---|"
+ echo "| upstream latest release | \`${release}\` (\`${release_commit:0:7}\`, published ${published}) |"
+ echo "| NEMTUS latest release | \`${latest:-none}\` |"
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ if [ -n "${latest}" ] && git merge-base --is-ancestor "${release_commit}" "${latest}^{commit}"; then
+ echo "| status | up to date |" >> "$GITHUB_STEP_SUMMARY"
+ if ! git diff --quiet "${latest}" "origin/${LOCAL_BRANCH}" -- Dockerfile fs_overlay; then
+ echo "| note | \`${LOCAL_BRANCH}\` has unreleased image changes since \`${latest}\` |" >> "$GITHUB_STEP_SUMMARY"
+ fi
+ exit 0
+ fi
+
+ # Next free tag for this upstream version: nemtus-vX.Y.Z, then -2, -3, ...
+ count="$(git tag --list "nemtus-v${release}" "nemtus-v${release}-*" | wc -l)"
+ if [ "${count}" -eq 0 ]; then
+ next="nemtus-v${release}"
+ else
+ next="nemtus-v${release}-$((count + 1))"
+ fi
+ if git merge-base --is-ancestor "${release_commit}" "origin/${LOCAL_BRANCH}"; then
+ action="\`${LOCAL_BRANCH}\` already contains it; release by pushing a signed \`${next}\` tag."
+ else
+ action="Merge the sync pull request into \`${LOCAL_BRANCH}\` first, then push a signed \`${next}\` tag."
+ fi
+ echo "| status | **release pending**: ${action} |" >> "$GITHUB_STEP_SUMMARY"
+
+ # Notify on the day upstream releases, then weekly, and on a manual run.
+ age="$(( $(date -u +%s) - $(date -u -d "${published}" +%s) ))"
+ if [ "${age}" -lt 93600 ] || [ "$(date -u +%u)" = 1 ] || [ "${GITHUB_EVENT_NAME}" = workflow_dispatch ]; then
+ echo "message=Release pending: upstream released ${release} (${published}) and ${latest:-no NEMTUS release} does not contain it. ${action}" >> "$GITHUB_OUTPUT"
+ fi
+
+ # Reset GitHub's 60-day scheduled-workflow auto-disable clock.
+ keepalive:
+ runs-on: ubuntu-latest
+ permissions:
+ actions: write
+ steps:
+ - name: Re-enable scheduled workflows (60-day inactivity guard)
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: gh api -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/mirror-sync.yml/enable"
+
+ # No third-party action: plain curl.
+ notify:
+ needs: [sync, release-watch]
+ if: always()
+ runs-on: ubuntu-latest
+ permissions: {}
+ steps:
+ - name: Notify Discord
+ env:
+ WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
+ SYNC_RESULT: ${{ needs.sync.result }}
+ SYNC_MESSAGE: ${{ needs.sync.outputs.message }}
+ WATCH_RESULT: ${{ needs.release-watch.result }}
+ WATCH_MESSAGE: ${{ needs.release-watch.outputs.message }}
+ run: |
+ set -euo pipefail
+ run_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
+ lines=()
+ [ -z "${SYNC_MESSAGE}" ] || lines+=("${SYNC_MESSAGE}")
+ if [ "${SYNC_RESULT}" != success ] && [ -z "${SYNC_MESSAGE}" ]; then
+ lines+=("FAILED: sync job ended with '${SYNC_RESULT}'.")
+ fi
+ [ -z "${WATCH_MESSAGE}" ] || lines+=("${WATCH_MESSAGE}")
+ if [ "${WATCH_RESULT}" != success ]; then
+ lines+=("FAILED: release-watch job ended with '${WATCH_RESULT}'.")
+ fi
+ if [ "${#lines[@]}" -eq 0 ]; then
+ echo 'Nothing to report.'
+ exit 0
+ fi
+ content="$(printf '[mirror-sync] %s\n' "${lines[@]}")"
+ content="$(printf '%s\n%s' "${content}" "${run_url}" | head -c 1900)"
+ echo "${content}"
+ if [ -z "${WEBHOOK}" ]; then
+ echo 'DISCORD_WEBHOOK_URL not configured; skipping notification.'
+ exit 0
+ fi
+ payload="$(jq -n --arg c "${content}" '{content: $c}')"
+ curl -fsS -H 'Content-Type: application/json' -d "${payload}" "${WEBHOOK}"
diff --git a/.github/workflows/nemtus-image.yml b/.github/workflows/nemtus-image.yml
index 36d2850..e6ca36b 100644
--- a/.github/workflows/nemtus-image.yml
+++ b/.github/workflows/nemtus-image.yml
@@ -21,6 +21,9 @@ name: nemtus-image (build / publish)
# - workflow_dispatch -> build + smoke test; with `push: true` also publish. Dispatched
# on a release tag it republishes that release with fresh base layers; dispatched on a
# branch it publishes only `:sha-`, never a version tag or `:latest`.
+# mirror-sync.yml dispatches it (without push) on each sync branch.
+#
+# Publishing is refused unless the commit is on the `nemtus` branch.
on:
pull_request:
@@ -82,12 +85,21 @@ jobs:
- name: Decide tags
id: meta
env:
+ GH_TOKEN: ${{ github.token }}
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
sha="$(git rev-parse --short HEAD)"
+ # Publish only commits that are on `nemtus`, i.e. that went through a pull
+ # request. A tag or a dispatch on any other commit must not reach the registry.
+ status="$(gh api "repos/${GITHUB_REPOSITORY}/compare/nemtus...${GITHUB_SHA}" --jq '.status')"
+ if [ "${status}" != identical ] && [ "${status}" != behind ]; then
+ echo "::error::${GITHUB_SHA} is not on the nemtus branch (compare status: ${status}); refusing to publish."
+ exit 1
+ fi
+
if [ "${REF_TYPE}" != tag ]; then
# A dispatch from a branch publishes only the commit-addressed tag, so an
# unreleased build can never take over a version tag or :latest.
diff --git a/docs/nemtus-fork.md b/docs/nemtus-fork.md
index 913d165..cfa5260 100644
--- a/docs/nemtus-fork.md
+++ b/docs/nemtus-fork.md
@@ -18,12 +18,49 @@ The fork publishes the same image to GHCR as `ghcr.io/nemtus/https-portal`.
The NEMTUS layer is deliberately small:
- `.github/workflows/nemtus-image.yml` — build, smoke test and publish to GHCR
+- `.github/workflows/mirror-sync.yml` — daily upstream sync and release watch
- `.github/scripts/smoke-test.sh` — the smoke test, runnable locally
+- `.github/scripts/review-upstream-diff.sh` — mechanical review of an upstream diff
- `docs/nemtus-fork.md` — this file
Anything else that differs from upstream should be a fix that is also proposed upstream.
-## Syncing with upstream
+## Automation
+
+`mirror-sync.yml` runs daily (and on demand) and does two things.
+
+**Sync.** When upstream `master` has commits that `nemtus` lacks, it:
+
+1. Reviews the diff with `review-upstream-diff.sh` and classifies it:
+ - `routine` — only version lines changed (nginx, s6-overlay, docker-gen, acme-tiny, the
+ `00-welcome` banner);
+ - `needs review` — anything else; the report lists new download hosts, pipe-to-shell and
+ similar patterns, binaries, opaque strings, mode changes and every file outside the
+ version lines;
+ - `blocked` — the diff touches `.github/`. Merged, those files would run with this
+ repository's privileges, so the run fails and nothing is pushed. Review upstream by
+ hand and sync manually if it is legitimate.
+2. Fast-forwards the `master` mirror.
+3. Waits out a cooldown of 3 days (`COOLDOWN_DAYS`) since upstream's branch last moved. A
+ bad upstream change is usually noticed and reverted within days. For an urgent security
+ fix, run the workflow manually with `skip_cooldown`.
+4. Opens a pull request `sync/upstream-` into `nemtus`, titled `[routine]` or
+ `[needs review]`, with the report in its body, and starts the `build` check on it.
+
+**Release watch.** Reports when upstream's latest release is not contained in the latest
+`nemtus-v*` release, with the tag to push. It never tags or publishes.
+
+Notifications go to Discord through the repository secret `DISCORD_WEBHOOK_URL` (skipped
+when it is not set): failures, new upstream commits, an opened sync pull request, and a
+pending release (on the day upstream releases, then every Monday).
+
+The review script is a tripwire, not a malware detector, and it does not see what the
+Dockerfile downloads at build time (the base image and release archives are fetched by
+version, without checksums). The gates that matter are human: reading the sync pull
+request before merging it, and pushing the signed release tag. `nemtus-image.yml` refuses
+to publish a commit that is not on `nemtus`.
+
+## Syncing with upstream by hand
Bring upstream changes into `nemtus` with a **merge commit, never a squash or rebase**, so
ancestry is preserved for later syncs:
@@ -64,6 +101,10 @@ updates), either re-run the workflow on the existing tag with `push: true`, or p
default branch).
- After the first publish, set the `https-portal` package visibility to public if it should
be pullable without authentication.
+- Add the repository secret `DISCORD_WEBHOOK_URL` for notifications.
+- Rulesets: `nemtus` requires a pull request (merge commits only) and the `build` check;
+ `master` and all tags cannot be deleted or force-pushed; creating `nemtus-v*` tags is
+ restricted to admins.
## Testing