From b16fa31d306f586754061095fc8503310372ee17 Mon Sep 17 00:00:00 2001 From: astrovm <~@4st.li> Date: Tue, 13 Oct 2026 17:43:23 -0300 Subject: [PATCH 1/2] Add CI / Required aggregate check --- .github/workflows/smoke-state.yml | 145 ---------------------------- .github/workflows/test.yml | 151 ++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 145 deletions(-) delete mode 100644 .github/workflows/smoke-state.yml diff --git a/.github/workflows/smoke-state.yml b/.github/workflows/smoke-state.yml deleted file mode 100644 index 14fad33..0000000 --- a/.github/workflows/smoke-state.yml +++ /dev/null @@ -1,145 +0,0 @@ -permissions: - contents: read - -name: Smoke state preservation - -on: - pull_request: - branches: ["main"] - workflow_dispatch: - -# New commits supersede older runs for the same pull request. -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - preserve-state: - name: Preserve existing Hosty state - runs-on: ubuntu-26.04 - timeout-minutes: 20 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Install dependencies - run: | - sudo apt-get -qq update - sudo DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 install -y \ - expect dash cron - - - name: Test installer from a noexec temporary directory - run: | - noexec_dir=$(mktemp -d) - cleanup() { - sudo rm -f /usr/local/bin/hosty - sudo umount "$noexec_dir" 2>/dev/null || true - rmdir "$noexec_dir" - } - trap cleanup EXIT - - sudo mount -t tmpfs -o noexec,size=1m tmpfs "$noexec_dir" - sudo env TMPDIR="$noexec_dir" HOSTY_URL="$PWD/hosty.sh" sh ./install.sh "$fake_bin/curl" <<'EOF_CURL' - #!/bin/sh - output="" - saw_proto=0 - saw_proto_redir=0 - - while [ "$#" -gt 0 ]; do - case $1 in - --proto) - shift - [ "$1" = '=https,file' ] || exit 91 - saw_proto=1 - ;; - --proto-redir) - shift - [ "$1" = '=https' ] || exit 92 - saw_proto_redir=1 - ;; - -o) - shift - output=$1 - ;; - esac - shift - done - - [ "$saw_proto" -eq 1 ] && [ "$saw_proto_redir" -eq 1 ] && [ -n "$output" ] || exit 93 - cp "$HOSTY_FIXTURE" "$output" - EOF_CURL - chmod +x "$fake_bin/curl" - - sudo env \ - PATH="$fake_bin:$PATH" \ - HOSTY_FIXTURE="$PWD/hosty.sh" \ - HOSTY_URL=https://example.invalid/hosty.sh \ - sh ./install.sh /dev/null - printf '%s\n' '#!/bin/sh' 'printf "%s\n" preserve-me' | sudo tee /usr/local/bin/hosty >/dev/null - sudo chmod 755 /usr/local/bin/hosty - printf '%s\n' '#!/bin/sh' 'printf "%s\n" preserve-cron' | sudo tee /etc/cron.daily/hosty >/dev/null - sudo chmod 700 /etc/cron.daily/hosty - printf '%s\n' '17 3 * * * echo preserve-me # hosty-ci-preserve' | sudo crontab - - - - name: Run smoke suite - run: | - chmod +x hosty.sh install.sh ci/smoke.sh ci/check-sources.sh ci/expect/*.exp - mkdir -p ci-logs - if ! ./ci/smoke.sh > ci-logs/smoke-state.out 2>&1; then - cat ci-logs/smoke-state.out - exit 1 - fi - - - name: Upload CI logs on failure - if: failure() - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: smoke-state-logs - path: ci-logs/ - if-no-files-found: ignore - - - name: Verify restored state - run: | - sudo cmp /tmp/hosty-hosts.before /etc/hosts - test "$(stat -c '%a' /etc/hosts)" = 644 - test "$(sudo cat /etc/hosty/preserved)" = preserve-me - test "$(sudo /usr/local/bin/hosty)" = preserve-me - test "$(sudo /etc/cron.daily/hosty)" = preserve-cron - test "$(stat -c '%a' /etc/cron.daily/hosty)" = 700 - sudo crontab -l | grep -qF -e '# hosty-ci-preserve' - - - name: Test hosts metadata restoration - run: | - mode_core=$(mktemp) - cleanup() { - sudo chmod 644 /etc/hosts - rm -f "$mode_core" - } - trap cleanup EXIT - - cat > "$mode_core" <<'EOF_CORE' - #!/bin/sh - sudo chmod 644 /etc/hosts - EOF_CORE - - sudo chmod 600 /etc/hosts - HOSTY_SMOKE_CORE="$mode_core" ./ci/smoke.sh - test "$(stat -c '%a' /etc/hosts)" = 600 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24b642c..b3e6b4e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -257,3 +257,154 @@ jobs: name: source-health-report path: ci-logs/ if-no-files-found: ignore + + preserve-state: + if: github.event_name == 'pull_request' + name: Preserve existing Hosty state + runs-on: ubuntu-26.04 + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Install dependencies + run: | + sudo apt-get -qq update + sudo DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 install -y \ + expect dash cron + + - name: Test installer from a noexec temporary directory + run: | + noexec_dir=$(mktemp -d) + cleanup() { + sudo rm -f /usr/local/bin/hosty + sudo umount "$noexec_dir" 2>/dev/null || true + rmdir "$noexec_dir" + } + trap cleanup EXIT + + sudo mount -t tmpfs -o noexec,size=1m tmpfs "$noexec_dir" + sudo env TMPDIR="$noexec_dir" HOSTY_URL="$PWD/hosty.sh" sh ./install.sh "$fake_bin/curl" <<'EOF_CURL' + #!/bin/sh + output="" + saw_proto=0 + saw_proto_redir=0 + + while [ "$#" -gt 0 ]; do + case $1 in + --proto) + shift + [ "$1" = '=https,file' ] || exit 91 + saw_proto=1 + ;; + --proto-redir) + shift + [ "$1" = '=https' ] || exit 92 + saw_proto_redir=1 + ;; + -o) + shift + output=$1 + ;; + esac + shift + done + + [ "$saw_proto" -eq 1 ] && [ "$saw_proto_redir" -eq 1 ] && [ -n "$output" ] || exit 93 + cp "$HOSTY_FIXTURE" "$output" + EOF_CURL + chmod +x "$fake_bin/curl" + + sudo env \ + PATH="$fake_bin:$PATH" \ + HOSTY_FIXTURE="$PWD/hosty.sh" \ + HOSTY_URL=https://example.invalid/hosty.sh \ + sh ./install.sh /dev/null + printf '%s\n' '#!/bin/sh' 'printf "%s\n" preserve-me' | sudo tee /usr/local/bin/hosty >/dev/null + sudo chmod 755 /usr/local/bin/hosty + printf '%s\n' '#!/bin/sh' 'printf "%s\n" preserve-cron' | sudo tee /etc/cron.daily/hosty >/dev/null + sudo chmod 700 /etc/cron.daily/hosty + printf '%s\n' '17 3 * * * echo preserve-me # hosty-ci-preserve' | sudo crontab - + + - name: Run smoke suite + run: | + chmod +x hosty.sh install.sh ci/smoke.sh ci/check-sources.sh ci/expect/*.exp + mkdir -p ci-logs + if ! ./ci/smoke.sh > ci-logs/smoke-state.out 2>&1; then + cat ci-logs/smoke-state.out + exit 1 + fi + + - name: Upload CI logs on failure + if: failure() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: smoke-state-logs + path: ci-logs/ + if-no-files-found: ignore + + - name: Verify restored state + run: | + sudo cmp /tmp/hosty-hosts.before /etc/hosts + test "$(stat -c '%a' /etc/hosts)" = 644 + test "$(sudo cat /etc/hosty/preserved)" = preserve-me + test "$(sudo /usr/local/bin/hosty)" = preserve-me + test "$(sudo /etc/cron.daily/hosty)" = preserve-cron + test "$(stat -c '%a' /etc/cron.daily/hosty)" = 700 + sudo crontab -l | grep -qF -e '# hosty-ci-preserve' + + - name: Test hosts metadata restoration + run: | + mode_core=$(mktemp) + cleanup() { + sudo chmod 644 /etc/hosts + rm -f "$mode_core" + } + trap cleanup EXIT + + cat > "$mode_core" <<'EOF_CORE' + #!/bin/sh + sudo chmod 644 /etc/hosts + EOF_CORE + + sudo chmod 600 /etc/hosts + HOSTY_SMOKE_CORE="$mode_core" ./ci/smoke.sh + test "$(stat -c '%a' /etc/hosts)" = 600 + + required-ci: + name: CI / Required + # Always report a result, including when a prerequisite failed or was skipped. + if: ${{ always() && github.event_name == 'pull_request' }} + needs: + - lint + - smoke + - coverage + - smoke-alpine + - smoke-openbsd + - source-health + - preserve-state + runs-on: ubuntu-26.04 + timeout-minutes: 5 + steps: + - name: Require every PR validation job to pass + env: + RESULTS: ${{ toJSON(needs.*.result) }} + run: jq --exit-status 'length > 0 and all(. != "failure" and . != "cancelled")' <<< "$RESULTS" From 271447fba95d2651b3b2e029164ee535109009d8 Mon Sep 17 00:00:00 2001 From: astrovm <~@4st.li> Date: Tue, 13 Oct 2026 17:51:30 -0300 Subject: [PATCH 2/2] Limit CI / Required token permissions --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3e6b4e..a160c28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -403,6 +403,7 @@ jobs: - preserve-state runs-on: ubuntu-26.04 timeout-minutes: 5 + permissions: {} steps: - name: Require every PR validation job to pass env: