CORE-784: Generate unique passwords for development environments Replace the shared, publicly documented default password with randomly generated credentials for admin and member users across `scripts/develop.sh`, Docker Compose, and ephemeral deployments. - Generate separate 32-character passwords, stored in permission-restricted files (`0600`) and reused across restarts and database resets. - Automatically replace legacy default passwords on existing instances without overwriting passwords changed manually. - Reject the old default as an override. Limit `--password` and `CODER_DEV_ADMIN_PASSWORD` to the admin user and persist successful overrides. - Improve login banners, password recovery errors, and Compose bootstrap token recovery. - Update ephemeral deployment tooling and documentation to use stored credentials instead of hardcoded passwords. - Add Go tests covering password generation, migration, persistence, overrides, and error handling. **Validation:** Go tests, linting, and shell checks pass. All 20 original manual scenarios passed, although several were run before subsequent changes. Additional unit, stub, and integration tests cover the updated behavior; some final Compose changes have not been retested against a live environment. Refs CORE-784
49 lines
1.4 KiB
Bash
Executable File
49 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
# shellcheck source=scripts/docker-dev/password.sh
|
|
. /scripts/password.sh
|
|
|
|
CODER="go run ./cmd/coder"
|
|
TOKEN_FILE="/bootstrap/token"
|
|
|
|
echo "=== Setting up users ==="
|
|
|
|
reject_old_default CODER_DEV_MEMBER_PASSWORD "${CODER_DEV_MEMBER_PASSWORD:-}"
|
|
|
|
# Load bootstrap token
|
|
CODER_SESSION_TOKEN=$(cat "$TOKEN_FILE")
|
|
if [ -z "${CODER_SESSION_TOKEN}" ]; then
|
|
echo "Bootstrap token not found in ${TOKEN_FILE}"
|
|
exit 1
|
|
fi
|
|
export CODER_SESSION_TOKEN
|
|
|
|
if [ -n "${CODER_DEV_MEMBER_PASSWORD:-}" ]; then
|
|
PASSWORD="$CODER_DEV_MEMBER_PASSWORD"
|
|
elif [ -s "$MEMBER_PASSWORD_FILE" ]; then
|
|
PASSWORD="$(cat "$MEMBER_PASSWORD_FILE")"
|
|
elif $CODER users show member >/dev/null 2>&1; then
|
|
# setup-init writes the password file when it creates the first user
|
|
# or replaces the old default, so a member without a file has a
|
|
# password that was set some other way.
|
|
warn_password_unknown member@coder.com
|
|
echo "Member login: member@coder.com (password was not set by this environment)"
|
|
echo "=== Users setup complete ==="
|
|
exit 0
|
|
else
|
|
echo "Member password file $MEMBER_PASSWORD_FILE is missing or empty." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Create member user (idempotent)
|
|
echo "Creating member user..."
|
|
$CODER users create \
|
|
--email=member@coder.com \
|
|
--username=member \
|
|
--full-name="Regular User" \
|
|
--password="$PASSWORD" 2>/dev/null || echo "Member user already exists."
|
|
|
|
echo "Member login: member@coder.com / $PASSWORD"
|
|
echo "=== Users setup complete ==="
|