gendesign/scripts/auth/remove_user.sh
lekss361 cc2d148967
All checks were successful
Deploy / changes (push) Successful in 5s
Deploy / build-worker (push) Successful in 30s
Deploy / build-frontend (push) Successful in 28s
Deploy / build-backend (push) Successful in 31s
Deploy / deploy (push) Successful in 53s
feat(security): закрыть gendsgn.ru basic_auth gate (multi-user, 11 users) (#426)
Pilot demo 28.05.2026: closed gendsgn.ru/* (включая trade-in/) basic_auth gate. /health и /preview/* остаются public через route { } wrapper (Caddy 2.x directive ordering fix).

11 users (admin + user1..user10), bcrypt cost=14, snippet в git (audit trail). Scripts: scripts/auth/{add,remove,list}_user.sh.

Fixup PR #426 (route{} wrap + log rotation + base64 busybox-compat + runbook audit log fix).
2026-05-23 08:16:10 +00:00

42 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# remove_user.sh — удалить пользователя из caddy/users.caddy.snippet
# Usage: ./scripts/auth/remove_user.sh <username>
#
# НЕ коммитит изменения — это задача разработчика.
set -euo pipefail
SNIPPET="$(dirname "$(dirname "$(realpath "$0")")")/caddy/users.caddy.snippet"
usage() {
echo "Usage: $0 <username>" >&2
exit 1
}
[[ $# -lt 1 ]] && usage
USERNAME="$1"
# Validate username format
if ! [[ "$USERNAME" =~ ^[a-z][a-z0-9-]{2,30}$ ]]; then
echo "ERROR: invalid username '$USERNAME'. Must match ^[a-z][a-z0-9-]{2,30}$" >&2
exit 1
fi
# Check user exists
if ! grep -qP "^\s+${USERNAME}\s" "$SNIPPET" 2>/dev/null; then
echo "ERROR: user '$USERNAME' not found in $SNIPPET" >&2
exit 1
fi
# Remove the line with this username (safe in-place via temp file)
TMP="$(mktemp)"
trap 'rm -f "$TMP"' EXIT
grep -vP "^\s+${USERNAME}\s" "$SNIPPET" > "$TMP"
mv "$TMP" "$SNIPPET"
echo "Removed user '$USERNAME' from $SNIPPET"
echo ""
echo "Next steps:"
echo " 1. Commit caddy/users.caddy.snippet → PR → merge → GHA deploy"
echo " 2. After deploy, Caddy auto-reloads — user access revoked"