fix: Installation und Deploy gegen Rechteausweitung gehärtet (#1280)
Alles im Ordner des Dienstbenutzers und jeder Aufruf des heruntergeladenen Programms läuft als dieser Benutzer; Ablage auf srv04 in ~/nexus-deploy statt /tmp. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -2,9 +2,10 @@
|
||||
# Legt ein Nexus-Release auf srv04 zur Installation bereit (→ #1067).
|
||||
# Standard (Pull): srv04 lädt das vom Gitea-Runner gebaute Binary samt SHA-256-Prüfsumme aus dem Gitea-Release
|
||||
# `https://git.wlkns.org/wlkns-dev/nexus/releases` selbst herunter und prüft sie; das Binary läuft nie über den
|
||||
# Entwicklungsrechner. Es verändert auf srv04 nur den Ordner /tmp/nexus-deploy (als Benutzer stephan).
|
||||
# Entwicklungsrechner. Es verändert auf srv04 nur den Ordner ~/nexus-deploy (als Benutzer stephan, nur für ihn zugänglich;
|
||||
# nicht unter /tmp, weil daraus anschließend mit sudo ein Skript läuft, → #1280).
|
||||
# Die eigentliche Installation (root) startest du danach selbst:
|
||||
# ssh -t srv04 'sudo VERSION=<version> bash /tmp/nexus-deploy/install.sh --start'
|
||||
# ssh -t srv04 'sudo VERSION=<version> bash ~/nexus-deploy/install.sh --start'
|
||||
#
|
||||
# Aufruf: scripts/deploy-srv04.sh vX.Y.Z Release aus Gitea holen (Standard)
|
||||
# scripts/deploy-srv04.sh --lokal Notfall: lokal bauen und per scp hochladen (wie bis 0.1.7)
|
||||
@ -12,14 +13,16 @@ set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
HOST="${HOST:-srv04}"
|
||||
GITEA="${GITEA:-https://git.wlkns.org/wlkns-dev/nexus}"
|
||||
# Relativ zum Home-Verzeichnis auf $HOST.
|
||||
ABLAGE=nexus-deploy
|
||||
|
||||
if [ "${1:-}" = "--lokal" ]; then
|
||||
cargo build --release --target x86_64-unknown-linux-musl -p nexus
|
||||
BIN=target/x86_64-unknown-linux-musl/release/nexus
|
||||
VERSION="$("$BIN" version | awk '{print $2}')"
|
||||
echo "Gebaut: nexus $VERSION ($(stat -c %s "$BIN") Bytes, $(file -b "$BIN" | cut -d, -f1-2,5 | cut -c1-60))"
|
||||
ssh -o BatchMode=yes "$HOST" 'mkdir -p /tmp/nexus-deploy'
|
||||
scp -q "$BIN" "$HOST:/tmp/nexus-deploy/nexus"
|
||||
ssh -o BatchMode=yes "$HOST" "mkdir -p $ABLAGE && chmod 700 $ABLAGE"
|
||||
scp -q "$BIN" "$HOST:$ABLAGE/nexus"
|
||||
else
|
||||
TAG="${1:?Aufruf: scripts/deploy-srv04.sh vX.Y.Z (oder --lokal)}"
|
||||
case "$TAG" in v[0-9]*) ;; *) echo "Tag muss wie v0.1.7 aussehen: $TAG" >&2; exit 2 ;; esac
|
||||
@ -28,13 +31,13 @@ else
|
||||
URL="$GITEA/releases/download/$TAG"
|
||||
echo "Hole $TAG aus Gitea (auf $HOST) ..."
|
||||
# srv04 lädt selbst; die Prüfsumme muss stimmen, sonst bleibt nichts liegen.
|
||||
ssh -o BatchMode=yes "$HOST" "set -euo pipefail; mkdir -p /tmp/nexus-deploy; cd /tmp/nexus-deploy; rm -f '$FILE' '$FILE.sha256';
|
||||
ssh -o BatchMode=yes "$HOST" "set -euo pipefail; mkdir -p $ABLAGE; chmod 700 $ABLAGE; cd $ABLAGE; rm -f '$FILE' '$FILE.sha256';
|
||||
curl -fsSL -o '$FILE' '$URL/$FILE'; curl -fsSL -o '$FILE.sha256' '$URL/$FILE.sha256';
|
||||
sha256sum -c '$FILE.sha256'; cp '$FILE' nexus.neu; chmod +x nexus.neu; mv nexus.neu nexus"
|
||||
fi
|
||||
scp -q scripts/srv04-install.sh "$HOST:/tmp/nexus-deploy/install.sh"
|
||||
scp -q scripts/srv04-install.sh "$HOST:$ABLAGE/install.sh"
|
||||
# Läuft das statische Binary dort überhaupt? (Nur Version anzeigen, ändert nichts.)
|
||||
ssh -o BatchMode=yes "$HOST" 'chmod +x /tmp/nexus-deploy/nexus && /tmp/nexus-deploy/nexus version'
|
||||
ssh -o BatchMode=yes "$HOST" "chmod +x $ABLAGE/nexus && $ABLAGE/nexus version"
|
||||
echo
|
||||
echo "Abgelegt unter $HOST:/tmp/nexus-deploy. Zum Installieren (braucht dein sudo-Passwort):"
|
||||
echo " ssh -t $HOST 'sudo VERSION=$VERSION bash /tmp/nexus-deploy/install.sh --start'"
|
||||
echo "Abgelegt unter $HOST:~/$ABLAGE. Zum Installieren (braucht dein sudo-Passwort):"
|
||||
echo " ssh -t $HOST 'sudo VERSION=$VERSION bash ~/$ABLAGE/install.sh --start'"
|
||||
|
||||
Reference in New Issue
Block a user