fix: improve regenerate_keys() to replace any existing key values
Changed sed patterns from matching specific placeholder strings to matching entire lines (^KEY=.*), ensuring keys are properly replaced regardless of current value. Tested in WSL2 - generates valid 64-char hex master key. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ee398534bb
commit
dfefd343b0
|
|
@ -444,21 +444,27 @@ regenerate_keys() {
|
|||
local JWT_SECRET=$(generate_random_password)
|
||||
local API_KEY=$(generate_random_password)
|
||||
|
||||
# Update only the keys that might have placeholder values
|
||||
if [ -f "$CONFIG_DIR/mpc.env" ]; then
|
||||
# Replace placeholder master key patterns
|
||||
sed -i "s/your_64_hex_characters_master_key_here/${MASTER_KEY}/g" "$CONFIG_DIR/mpc.env"
|
||||
sed -i "s/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef/${MASTER_KEY}/g" "$CONFIG_DIR/mpc.env"
|
||||
# Replace CRYPTO_MASTER_KEY and MPC_CRYPTO_MASTER_KEY lines entirely
|
||||
# This handles any existing value, not just specific placeholders
|
||||
sed -i "s/^CRYPTO_MASTER_KEY=.*/CRYPTO_MASTER_KEY=${MASTER_KEY}/" "$CONFIG_DIR/mpc.env"
|
||||
sed -i "s/^MPC_CRYPTO_MASTER_KEY=.*/MPC_CRYPTO_MASTER_KEY=${MASTER_KEY}/" "$CONFIG_DIR/mpc.env"
|
||||
|
||||
# Replace placeholder JWT key
|
||||
sed -i "s/your_super_secure_jwt_secret_key_at_least_32_characters/${JWT_SECRET}/g" "$CONFIG_DIR/mpc.env"
|
||||
# Replace JWT keys
|
||||
sed -i "s/^JWT_SECRET_KEY=.*/JWT_SECRET_KEY=${JWT_SECRET}/" "$CONFIG_DIR/mpc.env"
|
||||
sed -i "s/^MPC_JWT_SECRET_KEY=.*/MPC_JWT_SECRET_KEY=${JWT_SECRET}/" "$CONFIG_DIR/mpc.env"
|
||||
|
||||
# Replace placeholder API key
|
||||
sed -i "s/your_very_secure_api_key_at_least_32_characters/${API_KEY}/g" "$CONFIG_DIR/mpc.env"
|
||||
# Replace API key
|
||||
sed -i "s/^MPC_API_KEY=.*/MPC_API_KEY=${API_KEY}/" "$CONFIG_DIR/mpc.env"
|
||||
|
||||
log_info "Keys regenerated successfully"
|
||||
log_info "New MASTER_KEY: ${MASTER_KEY:0:16}... (hidden)"
|
||||
log_info "Restart services with: $0 restart"
|
||||
log_info "New MASTER_KEY: ${MASTER_KEY:0:16}..."
|
||||
log_info "New JWT_SECRET: ${JWT_SECRET:0:8}..."
|
||||
log_info "New API_KEY: ${API_KEY:0:8}..."
|
||||
log_info ""
|
||||
log_info "Now reconfigure PostgreSQL with new password and restart services:"
|
||||
log_info " $0 reconfigure"
|
||||
log_info " $0 restart"
|
||||
else
|
||||
log_error "Environment file not found: $CONFIG_DIR/mpc.env"
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue