BlueGit

timfa posprint

Harden AUR CI: BUILDDIR perms, slim job, strip v-tags.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-07-21 · 3 months ago

Hash
75837d0b965a10ee3ae3d5175ba2b252e91f22fa
Parent
64121172
3 files changed +33 −13
.gitlab-ci.yml +3 −1
@@ -137,8 +137,10 @@ publish:aur:
137 137 needs:
138 138 - release:gitlab
139 139 before_script:
140 # Only tools needed to update the AUR git repo (no Rust GUI build deps).
141 # Do not install package name "cargo" — it prompts for a provider (rust vs rustup).
140 142 - pacman -Syu --noconfirm
141 - pacman -S --noconfirm --needed rust cargo pkgconf openssl libxkbcommon libxcb dbus wayland libx11 fontconfig freetype2 libglvnd git rsync curl openssh coreutils
143 - pacman -S --noconfirm --needed git openssh curl coreutils shadow util-linux
142 144 - chmod +x scripts/aur-ssh-setup.sh
143 145 - ./scripts/aur-ssh-setup.sh
144 146 script:
@@ -137,8 +137,10 @@ publish:aur:
137 needs:
137 needs:
138 - release:gitlab
138 - release:gitlab
139 before_script:
139 before_script:
140 # Only tools needed to update the AUR git repo (no Rust GUI build deps).
141 # Do not install package name "cargo" — it prompts for a provider (rust vs rustup).
140 - pacman -Syu --noconfirm
142 - pacman -Syu --noconfirm
141 - pacman -S --noconfirm --needed rust cargo pkgconf openssl libxkbcommon libxcb dbus wayland libx11 fontconfig freetype2 libglvnd git rsync curl openssh coreutils
143 - pacman -S --noconfirm --needed git openssh curl coreutils shadow util-linux
142 - chmod +x scripts/aur-ssh-setup.sh
144 - chmod +x scripts/aur-ssh-setup.sh
143 - ./scripts/aur-ssh-setup.sh
145 - ./scripts/aur-ssh-setup.sh
144 script:
146 script:
docs/AUR.md +3 −1
@@ -40,7 +40,9 @@ When a Git tag is pushed:
40 40 - computes its SHA-256
41 41 - clones the AUR repo
42 42 - updates `pkgver`, `pkgrel`, and `sha256sums`
43 - regenerates `.SRCINFO` via `makepkg --printsrcinfo` (as a non-root user when CI runs as root)
43 - regenerates `.SRCINFO` via `makepkg --printsrcinfo` (as non-root `aurbuild` when CI runs as root; parent tempdir is made traversable and `BUILDDIR` is forced under that user)
44 - strips a leading `v` from the tag when resolving the GitLab source archive URL
45
44 46 - commits and pushes to AUR `master`
45 47
46 48 ## GitLab CI secrets
@@ -40,7 +40,9 @@ When a Git tag is pushed:
40 - computes its SHA-256
40 - computes its SHA-256
41 - clones the AUR repo
41 - clones the AUR repo
42 - updates `pkgver`, `pkgrel`, and `sha256sums`
42 - updates `pkgver`, `pkgrel`, and `sha256sums`
43- regenerates `.SRCINFO` via `makepkg --printsrcinfo` (as a non-root user when CI runs as root)
43- regenerates `.SRCINFO` via `makepkg --printsrcinfo` (as non-root `aurbuild` when CI runs as root; parent tempdir is made traversable and `BUILDDIR` is forced under that user)
44- strips a leading `v` from the tag when resolving the GitLab source archive URL
45
44 - commits and pushes to AUR `master`
46 - commits and pushes to AUR `master`
45
47
46## GitLab CI secrets
48## GitLab CI secrets
scripts/publish-aur.sh +27 −11
@@ -15,10 +15,16 @@ cd "$ROOT"
15 15 if [[ -z "$VERSION" ]]; then
16 16 VERSION="$(grep '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)"/\1/')"
17 17 fi
18 # Tags may be "0.5.1" or "v0.5.1"; GitLab archive URLs and pkgver use the bare version.
19 VERSION="${VERSION#v}"
18 20
19 21 for cmd in git makepkg sed sha256sum curl; do
20 22 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
21 23 done
24 if [[ "$(id -u)" -eq 0 ]]; then
25 command -v runuser >/dev/null || { echo "Missing command: runuser" >&2; exit 1; }
26 command -v useradd >/dev/null || { echo "Missing command: useradd" >&2; exit 1; }
27 fi
22 28
23 29 if [[ ! -f packaging/aur/PKGBUILD ]]; then
24 30 echo "Missing packaging/aur/PKGBUILD template" >&2
@@ -44,18 +50,28 @@ sed -i "s/^pkgver=.*/pkgver=${VERSION}/" PKGBUILD
44 50 sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
45 51 sed -i "s|^sha256sums=.*|sha256sums=('${ARCHIVE_SHA}')|" PKGBUILD
46 52
47 # makepkg refuses to run as root (CI images are often root).
48 if [[ "$(id -u)" -eq 0 ]]; then
49 MAKEPKG_USER="${AUR_MAKEPKG_USER:-aurbuild}"
50 if ! id "$MAKEPKG_USER" >/dev/null 2>&1; then
51 useradd --system --create-home --shell /bin/bash "$MAKEPKG_USER"
53 generate_srcinfo() {
54 # makepkg refuses root. mktemp parents are 0700 — aurbuild must be able to traverse
55 # $WORKDIR or [[ -d $BUILDDIR ]] fails and mkdir then errors.
56 if [[ "$(id -u)" -eq 0 ]]; then
57 local makepkg_user="${AUR_MAKEPKG_USER:-aurbuild}"
58 local build_tmp
59 if ! id "$makepkg_user" >/dev/null 2>&1; then
60 useradd --system --create-home --shell /bin/bash "$makepkg_user"
61 fi
62 chmod 755 "$WORKDIR"
63 chown -R "$makepkg_user:$makepkg_user" "$WORKDIR/repo"
64 build_tmp="$(runuser -u "$makepkg_user" -- mktemp -d)"
65 # Belt-and-suspenders: force BUILDDIR into a dir aurbuild definitely owns.
66 runuser -u "$makepkg_user" -- env BUILDDIR="$build_tmp" makepkg --printsrcinfo > .SRCINFO
67 rm -rf "$build_tmp"
68 chown -R root:root "$WORKDIR/repo"
69 else
70 makepkg --printsrcinfo > .SRCINFO
52 71 fi
53 chown -R "$MAKEPKG_USER:$MAKEPKG_USER" "$WORKDIR/repo"
54 runuser -u "$MAKEPKG_USER" -- makepkg --printsrcinfo > .SRCINFO
55 chown -R root:root "$WORKDIR/repo"
56 else
57 makepkg --printsrcinfo > .SRCINFO
58 fi
72 }
73
74 generate_srcinfo
59 75
60 76 if git diff --quiet -- PKGBUILD .SRCINFO; then
61 77 echo "AUR repo already up to date for ${VERSION}"
@@ -15,10 +15,16 @@ cd "$ROOT"
15if [[ -z "$VERSION" ]]; then
15if [[ -z "$VERSION" ]]; then
16 VERSION="$(grep '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)"/\1/')"
16 VERSION="$(grep '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)"/\1/')"
17fi
17fi
18# Tags may be "0.5.1" or "v0.5.1"; GitLab archive URLs and pkgver use the bare version.
19VERSION="${VERSION#v}"
18
20
19for cmd in git makepkg sed sha256sum curl; do
21for cmd in git makepkg sed sha256sum curl; do
20 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
22 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
21done
23done
24if [[ "$(id -u)" -eq 0 ]]; then
25 command -v runuser >/dev/null || { echo "Missing command: runuser" >&2; exit 1; }
26 command -v useradd >/dev/null || { echo "Missing command: useradd" >&2; exit 1; }
27fi
22
28
23if [[ ! -f packaging/aur/PKGBUILD ]]; then
29if [[ ! -f packaging/aur/PKGBUILD ]]; then
24 echo "Missing packaging/aur/PKGBUILD template" >&2
30 echo "Missing packaging/aur/PKGBUILD template" >&2
@@ -44,18 +50,28 @@ sed -i "s/^pkgver=.*/pkgver=${VERSION}/" PKGBUILD
44sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
50sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
45sed -i "s|^sha256sums=.*|sha256sums=('${ARCHIVE_SHA}')|" PKGBUILD
51sed -i "s|^sha256sums=.*|sha256sums=('${ARCHIVE_SHA}')|" PKGBUILD
46
52
47# makepkg refuses to run as root (CI images are often root).
53generate_srcinfo() {
48if [[ "$(id -u)" -eq 0 ]]; then
54 # makepkg refuses root. mktemp parents are 0700 — aurbuild must be able to traverse
49 MAKEPKG_USER="${AUR_MAKEPKG_USER:-aurbuild}"
55 # $WORKDIR or [[ -d $BUILDDIR ]] fails and mkdir then errors.
50 if ! id "$MAKEPKG_USER" >/dev/null 2>&1; then
56 if [[ "$(id -u)" -eq 0 ]]; then
51 useradd --system --create-home --shell /bin/bash "$MAKEPKG_USER"
57 local makepkg_user="${AUR_MAKEPKG_USER:-aurbuild}"
58 local build_tmp
59 if ! id "$makepkg_user" >/dev/null 2>&1; then
60 useradd --system --create-home --shell /bin/bash "$makepkg_user"
61 fi
62 chmod 755 "$WORKDIR"
63 chown -R "$makepkg_user:$makepkg_user" "$WORKDIR/repo"
64 build_tmp="$(runuser -u "$makepkg_user" -- mktemp -d)"
65 # Belt-and-suspenders: force BUILDDIR into a dir aurbuild definitely owns.
66 runuser -u "$makepkg_user" -- env BUILDDIR="$build_tmp" makepkg --printsrcinfo > .SRCINFO
67 rm -rf "$build_tmp"
68 chown -R root:root "$WORKDIR/repo"
69 else
70 makepkg --printsrcinfo > .SRCINFO
52 fi
71 fi
53 chown -R "$MAKEPKG_USER:$MAKEPKG_USER" "$WORKDIR/repo"
72}
54 runuser -u "$MAKEPKG_USER" -- makepkg --printsrcinfo > .SRCINFO
73
55 chown -R root:root "$WORKDIR/repo"
74generate_srcinfo
56else
57 makepkg --printsrcinfo > .SRCINFO
58fi
59
75
60if git diff --quiet -- PKGBUILD .SRCINFO; then
76if git diff --quiet -- PKGBUILD .SRCINFO; then
61 echo "AUR repo already up to date for ${VERSION}"
77 echo "AUR repo already up to date for ${VERSION}"