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
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,97 @@ jobs:
stop-bots status --quiet || true
sudo apt-get remove -y stop-bots

# The RPM, built the way release.yml builds it, then published to a
# throwaway dnf repository with a throwaway key by the same
# scripts/build-rpm-repo.sh the release uses, and installed from it on
# Fedora, Rocky 9 and Rocky 8 by packaging/rpm/check-install.sh. That is
# the only place the repository is exercised before a tag publishes it.
#
# Two packages go into it: this version as a release candidate, and this
# version. Installing the first and upgrading to the second proves the
# `~` in scripts/rpm-version.sh sorts a candidate before its release, on
# the rpm each distribution ships rather than on a comparison here.
rpm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stable
with:
targets: x86_64-unknown-linux-musl
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: musl-rpm

# rpm for rpmsign and for reading the package back; createrepo-c for
# the repository. Both are what the release's `dnf` job installs.
- name: Install musl, rpm and createrepo_c
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y musl-tools rpm createrepo-c

- uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1
with:
tool: cargo-generate-rpm@0.21.1

- name: Build the packages
env:
CC_x86_64_unknown_linux_musl: musl-gcc
run: |
cargo build --release --target x86_64-unknown-linux-musl
target/x86_64-unknown-linux-musl/release/stop-bots generate-docs --out target/assets
mkdir -p dist
release="$(scripts/rpm-version.sh)"
candidate="$(scripts/rpm-version.sh "${release}-ci.1")"
for version in "$candidate" "$release"; do
cargo generate-rpm --target x86_64-unknown-linux-musl \
--set-metadata "version = \"$version\"" -o dist/
done
echo "RPM_RELEASE=$release" >> "$GITHUB_ENV"
echo "RPM_CANDIDATE=$candidate" >> "$GITHUB_ENV"
ls -l dist

# As the `deb` job's check: the paths the rest of the project tells
# people about, and the man pages and completions where Fedora and
# RHEL look for them (zsh's site-functions, not Debian's
# vendor-completions). And no dependency beyond rpm's own features:
# the binary is static, so anything else would be a mistake.
- name: Check the contents
run: |
package="dist/stop-bots-${RPM_RELEASE}-1.x86_64.rpm"
rpm -qpi "$package"
echo "recommends: $(rpm -qp --recommends "$package")"
echo "suggests: $(rpm -qp --suggests "$package")"
extra="$(rpm -qp --requires "$package" | grep -v '^rpmlib(' || true)"
[ -z "$extra" ] || { echo "::error::the package requires: $extra"; exit 1; }
contents="$(rpm -qpl "$package")"
for path in /usr/bin/stop-bots /usr/share/doc/stop-bots/README.md \
/usr/share/licenses/stop-bots/LICENSE \
/usr/share/man/man1/stop-bots-batch.1 \
/usr/share/bash-completion/completions/stop-bots \
/usr/share/zsh/site-functions/_stop-bots \
/usr/share/fish/vendor_completions.d/stop-bots.fish; do
echo "$contents" | grep -qx "$path" \
|| { echo "::error::the package does not ship $path"; exit 1; }
done

- name: Publish to a throwaway repository
run: |
export GNUPGHOME="$(mktemp -d)"
gpg --batch --pinentry-mode loopback --passphrase '' \
--quick-gen-key 'stop-bots CI <ci@invalid>' rsa4096 sign never
key="$(gpg --list-secret-keys --with-colons | awk -F: '/^fpr:/ { print $10; exit }')"
scripts/build-rpm-repo.sh pages dist "$key"

# No network inside: every package comes from the repository above,
# so a mirror being slow cannot fail this and cannot be what passed it.
- name: Install from it
run: |
for image in fedora:43 rockylinux:9 rockylinux:8; do
docker run --rm --network none \
-v "$PWD/pages:/pages:ro" -v "$PWD/packaging/rpm:/rpm:ro" \
"$image" sh /rpm/check-install.sh "$RPM_CANDIDATE" "$RPM_RELEASE"
done

# The README's quick start, as a stranger would follow it, on a fresh
# Debian 12 and a fresh Ubuntu 24.04 under real systemd: `apt install`
# of the package the `deb` job just built, then `status`, `batch`,
Expand Down
135 changes: 132 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,23 @@ jobs:
# Viable here only because the dependency tree has no C TLS in it —
# `reqwest` resolves to `rustls` — so `musl-gcc` has exactly one thing
# to compile: the SQLite that `rusqlite`'s `bundled` feature carries.
# `rpm` only to read the .rpm back in "Inspect the package"; it is
# built by cargo-generate-rpm, which needs nothing installed.
- name: Install musl toolchain
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y musl-tools
sudo apt-get install --no-install-recommends -y musl-tools rpm

- name: Install cargo-deb
uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1
with:
tool: cargo-deb

- name: Install cargo-generate-rpm
uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1
with:
tool: cargo-generate-rpm@0.21.1

# The target-specific `CC_*` rather than a bare `CC`: build scripts and
# proc macros are compiled for the *host*, and pointing their C compiler
# at musl too is how a build that looks cross-aware fails inside a
Expand Down Expand Up @@ -175,6 +182,16 @@ jobs:
cargo deb --no-build --no-strip --deb-version "$(scripts/deb-version.sh)"
--target ${{ matrix.target }} --output dist/

# From the same binary, man pages and completions as the .deb, by
# `[package.metadata.generate-rpm]`. `--set-metadata` so a release
# candidate is `0.1.0~rc.1`, which sorts before `0.1.0`; see
# scripts/rpm-version.sh. Unsigned here, like everything else on the
# release page: the `dnf` job signs the copies it publishes.
- name: Build .rpm
run: >-
cargo generate-rpm --target ${{ matrix.target }}
--set-metadata "version = \"$(scripts/rpm-version.sh)\"" --output dist/

# The tarball stays, for the AUR `-bin` package and for anyone who would
# rather not add a repository to their machine. Same binary as the .deb.
- name: Package tarball
Expand All @@ -198,7 +215,7 @@ jobs:
- name: Checksums
working-directory: dist
run: |
for asset in *.tar.gz *.deb; do
for asset in *.tar.gz *.deb *.rpm; do
sha256sum "$asset" > "$asset.sha256"
done
cat ./*.sha256
Expand All @@ -207,6 +224,8 @@ jobs:
run: |
dpkg-deb --info dist/*.deb
dpkg-deb --contents dist/*.deb
rpm -qpi dist/*.rpm
rpm -qpl dist/*.rpm

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
Expand Down Expand Up @@ -250,6 +269,7 @@ jobs:
subject-path: |
dist/*.tar.gz
dist/*.deb
dist/*.rpm

release:
needs: [verify-version, build, attest]
Expand Down Expand Up @@ -283,7 +303,7 @@ jobs:
for sum in *.sha256; do
sha256sum --check --strict "$sum"
done
sha256sum *.tar.gz *.deb > SHA256SUMS
sha256sum *.tar.gz *.deb *.rpm > SHA256SUMS
cat SHA256SUMS

- name: Create release
Expand Down Expand Up @@ -436,3 +456,112 @@ jobs:
fi
git commit -m "apt: publish ${GITHUB_REF_NAME}"
git push "https://x-access-token:${{ github.token }}@github.com/${GITHUB_REPOSITORY}.git" gh-pages

# Republishes the dnf repository, rpm/ on the same `gh-pages` branch, with
# this release's .rpms signed and added. scripts/build-rpm-repo.sh says
# what is signed and why.
#
# After `apt`, because both push to `gh-pages` and the second push of two
# started together would be rejected. Whatever `apt` concluded, though:
# the two repositories are independent, and a failed `apt` should leave
# one of them published rather than neither. Each can be re-run alone.
# Not for a release candidate, for the reason `apt` gives.
dnf:
needs: [release, apt]
if: ${{ always() && needs.release.result == 'success' && !contains(github.ref_name, '-') }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: source

# Cloned now, after `apt` pushed, so this builds on its commit. Never
# an orphan here: `apt` creates the branch, and a branch that is
# missing at this point means something is wrong that a fresh one
# would hide.
- name: Check out gh-pages
run: |
git clone --branch gh-pages --single-branch \
"https://github.com/${GITHUB_REPOSITORY}.git" pages
echo "Found gh-pages with $(find pages/rpm -name '*.rpm' 2>/dev/null | wc -l) RPM(s)."

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: dist-*
merge-multiple: true
path: dist

- name: Install createrepo_c and rpmsign
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y createrepo-c rpm

- name: Import the signing key
id: gpg
env:
APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
run: |
if [ -z "${APT_GPG_PRIVATE_KEY}" ]; then
echo "::error::secret APT_GPG_PRIVATE_KEY is not set — see RELEASING.md"
exit 1
fi
printf '%s' "${APT_GPG_PRIVATE_KEY}" | gpg --batch --import
key="$(gpg --list-secret-keys --with-colons | awk -F: '/^fpr:/ { print $10; exit }')"
echo "key=${key}" >> "$GITHUB_OUTPUT"
echo "Imported ${key}"

- name: Build and sign the repository
env:
GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: |
mkdir rpms
cp dist/*.rpm rpms/
source/scripts/build-rpm-repo.sh pages rpms "${{ steps.gpg.outputs.key }}"
cp source/packaging/rpm/stop-bots.repo pages/stop-bots.repo

# What `apt`'s verify step is for the APT side: dnf refuses a bad
# repository, but every host configured for it would get that
# refusal, so prove it is right before pushing.
- name: Verify the signatures and the index
run: |
cd pages/rpm
gpg --verify repodata/repomd.xml.asc repodata/repomd.xml
db="$(mktemp -d)"
rpmkeys --dbpath "$db" --import ../key.asc
version="$(../../source/scripts/rpm-version.sh "${GITHUB_REF_NAME#v}")"
primary="$(zcat repodata/*-primary.xml.gz)"
for arch in x86_64 aarch64; do
package="packages/stop-bots-${version}-1.${arch}.rpm"
# `digests signatures OK`, and not merely `digests OK`, which is
# what an unsigned package says.
rpmkeys --dbpath "$db" --checksig "$package" | grep -q 'digests signatures OK$' \
|| { echo "::error::${package} is not signed by the imported key"; rpmkeys --dbpath "$db" --checksig -v "$package"; exit 1; }
echo "$primary" | grep -q "href=\"${package}\"" \
|| { echo "::error::the index does not list ${package}"; exit 1; }
done
# Every package the index lists must exist, or dnf fails at
# install time having already said it was available.
missing=""
for href in $(echo "$primary" | sed -n 's/.*<location href="\([^"]*\)".*/\1/p'); do
[ -f "$href" ] || missing="${missing} ${href}"
done
if [ -n "$missing" ]; then
echo "::error::the index points at missing file(s):${missing}"
exit 1
fi
echo "rpm/ lists ${version} for both architectures, signed, and every package resolves."

- name: Publish
run: |
cd pages
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "Repository unchanged — nothing to publish."
exit 0
fi
git commit -m "dnf: publish ${GITHUB_REF_NAME}"
git push "https://x-access-token:${{ github.token }}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ covered: it can change in any release. `RELEASING.md` says what counts as breaki

## [Unreleased]

### Added

- **An RPM, and a dnf repository to install it from**, for Fedora, RHEL, Rocky, AlmaLinux
and the like, 8 or newer. The same static binary, man pages and completions as the
`.deb`, for `x86_64` and `aarch64`, attached to each release and published beside the
APT repository, signed with the same key:

```
sudo curl -fsSL -o /etc/yum.repos.d/stop-bots.repo \
https://ivankovic.github.io/stop-bots/stop-bots.repo
sudo dnf install stop-bots
```

dnf checks both the index and each package's signature. As with the `.deb`, installing
it starts nothing, and it depends on nothing: a firewall backend is recommended and a
web server suggested. It is checked to install and upgrade on Fedora and Rocky Linux 8
and 9; stop-bots itself is tested on Debian and Ubuntu, and `install cron` and
`install firewall` assume what those have.

## [0.11.0] — 2026-11-10

A security, detection and usability review, fixed: IPv4-mapped clients blocked as what they are,
Expand Down
42 changes: 42 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,48 @@ assets = [
["target/assets/completions/stop-bots.fish", "usr/share/fish/vendor_completions.d/stop-bots.fish", "644"],
]

# The RPM for Fedora, RHEL and its rebuilds, from the same static binary and
# the same generated man pages and completions as the .deb, built by
# `cargo generate-rpm` (see packaging/rpm/ and release.yml). The decisions
# above hold here too: no scriptlets, no cron file, no unit.
#
# `version` is not set here: release.yml passes scripts/rpm-version.sh's,
# which turns a release candidate's `-rc.1` into `~rc.1` so it sorts before
# the release, as deb-version.sh does for the .deb. Building without it
# uses Cargo.toml's version, which is right for everything but a candidate.
[package.metadata.generate-rpm]
summary = "Stop bad bots without hiding behind a CDN"
release = "1"
# Static against musl, so there is no shared library to find. Said outright
# rather than left to the builtin `ldd` scan, which would reach the same
# answer only as long as the binary stays static -- and release.yml's own
# check is where that is enforced.
auto-req = "no"
# Nothing in the package is a shell script and there are no scriptlets, so
# it needs no /bin/sh either.
require-sh = false
# Man pages are `doc`, as rpmbuild would mark them, so an image installed
# with `tsflags=nodocs` leaves them out with the rest of the documentation.
assets = [
{ source = "target/release/stop-bots", dest = "/usr/bin/stop-bots", mode = "755" },
{ source = "README.md", dest = "/usr/share/doc/stop-bots/README.md", mode = "644", doc = true },
{ source = "CHANGELOG.md", dest = "/usr/share/doc/stop-bots/CHANGELOG.md", mode = "644", doc = true },
{ source = "LICENSE", dest = "/usr/share/licenses/stop-bots/LICENSE", mode = "644" },
{ source = "target/assets/man/*.1", dest = "/usr/share/man/man1/", mode = "644", doc = true },
{ source = "target/assets/completions/stop-bots.bash", dest = "/usr/share/bash-completion/completions/stop-bots", mode = "644" },
{ source = "target/assets/completions/_stop-bots", dest = "/usr/share/zsh/site-functions/_stop-bots", mode = "644" },
{ source = "target/assets/completions/stop-bots.fish", dest = "/usr/share/fish/vendor_completions.d/stop-bots.fish", mode = "644" },
]

# The same weak dependencies as the .deb, for the same reasons. Fedora and
# RHEL ship `iptables-restore` in `iptables-nft` (or `iptables-legacy`);
# Apache is `httpd`.
[package.metadata.generate-rpm.recommends]
"(nftables or iptables-nft or iptables-legacy)" = ""

[package.metadata.generate-rpm.suggests]
"(nginx or httpd)" = ""

[dependencies]
# For TUI
ratatui = "0.30"
Expand Down
Loading
Loading