mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-04 22:13:21 +00:00
Added REDIS_USER variable in the generation of .env
This commit is contained in:
66
setup.sh
66
setup.sh
@@ -641,9 +641,9 @@ install_redis() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configure Redis with password
|
# Configure Redis with user authentication
|
||||||
configure_redis() {
|
configure_redis() {
|
||||||
print_info "Configuring Redis with password authentication..."
|
print_info "Configuring Redis with user authentication..."
|
||||||
|
|
||||||
# Check if Redis is running
|
# Check if Redis is running
|
||||||
if ! systemctl is-active --quiet redis-server; then
|
if ! systemctl is-active --quiet redis-server; then
|
||||||
@@ -651,45 +651,70 @@ configure_redis() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Generate Redis username based on instance
|
||||||
|
REDIS_USER="patchmon_${DB_SAFE_NAME}"
|
||||||
|
|
||||||
|
print_info "Creating Redis user: $REDIS_USER for database $REDIS_DB"
|
||||||
|
|
||||||
# Create Redis configuration backup
|
# Create Redis configuration backup
|
||||||
if [ -f /etc/redis/redis.conf ]; then
|
if [ -f /etc/redis/redis.conf ]; then
|
||||||
cp /etc/redis/redis.conf /etc/redis/redis.conf.backup.$(date +%Y%m%d_%H%M%S)
|
cp /etc/redis/redis.conf /etc/redis/redis.conf.backup.$(date +%Y%m%d_%H%M%S)
|
||||||
print_info "Created Redis configuration backup"
|
print_info "Created Redis configuration backup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Configure Redis with password
|
# Configure Redis with admin password first
|
||||||
print_info "Setting Redis password: $REDIS_PASSWORD"
|
print_info "Setting Redis admin password: $REDIS_PASSWORD"
|
||||||
|
|
||||||
# Add password configuration to redis.conf
|
# Add password configuration to redis.conf
|
||||||
if ! grep -q "^requirepass" /etc/redis/redis.conf; then
|
if ! grep -q "^requirepass" /etc/redis/redis.conf; then
|
||||||
echo "requirepass $REDIS_PASSWORD" >> /etc/redis/redis.conf
|
echo "requirepass $REDIS_PASSWORD" >> /etc/redis/redis.conf
|
||||||
print_status "Added password configuration to Redis"
|
print_status "Added admin password configuration to Redis"
|
||||||
else
|
else
|
||||||
# Update existing password
|
# Update existing password
|
||||||
sed -i "s/^requirepass.*/requirepass $REDIS_PASSWORD/" /etc/redis/redis.conf
|
sed -i "s/^requirepass.*/requirepass $REDIS_PASSWORD/" /etc/redis/redis.conf
|
||||||
print_status "Updated Redis password configuration"
|
print_status "Updated Redis admin password configuration"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restart Redis to apply changes
|
# Restart Redis to apply admin password
|
||||||
print_info "Restarting Redis to apply password configuration..."
|
print_info "Restarting Redis to apply admin password configuration..."
|
||||||
systemctl restart redis-server
|
systemctl restart redis-server
|
||||||
|
|
||||||
# Wait for Redis to start
|
# Wait for Redis to start
|
||||||
sleep 3
|
sleep 3
|
||||||
|
|
||||||
# Test Redis connection with password
|
# Test admin connection
|
||||||
if redis-cli -a "$REDIS_PASSWORD" --no-auth-warning ping > /dev/null 2>&1; then
|
if ! redis-cli -a "$REDIS_PASSWORD" --no-auth-warning ping > /dev/null 2>&1; then
|
||||||
print_status "Redis password configuration successful"
|
print_error "Failed to configure Redis admin password"
|
||||||
|
|
||||||
# Mark the selected database as in-use
|
|
||||||
redis-cli -a "$REDIS_PASSWORD" --no-auth-warning -n "$REDIS_DB" SET "patchmon:initialized" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > /dev/null
|
|
||||||
print_status "Marked Redis database $REDIS_DB as in-use"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
print_error "Failed to configure Redis password"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
print_status "Redis admin password configuration successful"
|
||||||
|
|
||||||
|
# Create Redis user with ACL
|
||||||
|
print_info "Creating Redis ACL user: $REDIS_USER"
|
||||||
|
|
||||||
|
# Create user with password and permissions for the specific database
|
||||||
|
if redis-cli -a "$REDIS_PASSWORD" --no-auth-warning ACL SETUSER "$REDIS_USER" on ">${REDIS_PASSWORD}" ~* +@all > /dev/null 2>&1; then
|
||||||
|
print_status "Redis user '$REDIS_USER' created successfully"
|
||||||
|
else
|
||||||
|
print_error "Failed to create Redis user"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test user connection
|
||||||
|
print_info "Testing Redis user connection..."
|
||||||
|
if redis-cli --user "$REDIS_USER" --pass "$REDIS_PASSWORD" --no-auth-warning -n "$REDIS_DB" ping > /dev/null 2>&1; then
|
||||||
|
print_status "Redis user connection test successful"
|
||||||
|
else
|
||||||
|
print_error "Redis user connection test failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Mark the selected database as in-use
|
||||||
|
redis-cli --user "$REDIS_USER" --pass "$REDIS_PASSWORD" --no-auth-warning -n "$REDIS_DB" SET "patchmon:initialized" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > /dev/null
|
||||||
|
print_status "Marked Redis database $REDIS_DB as in-use"
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install nginx
|
# Install nginx
|
||||||
@@ -983,6 +1008,7 @@ AGENT_RATE_LIMIT_MAX=1000
|
|||||||
# Redis Configuration
|
# Redis Configuration
|
||||||
REDIS_HOST=localhost
|
REDIS_HOST=localhost
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
REDIS_USER=$REDIS_USER
|
||||||
REDIS_PASSWORD=$REDIS_PASSWORD
|
REDIS_PASSWORD=$REDIS_PASSWORD
|
||||||
REDIS_DB=$REDIS_DB
|
REDIS_DB=$REDIS_DB
|
||||||
|
|
||||||
@@ -1487,6 +1513,7 @@ Database Information:
|
|||||||
Redis Information:
|
Redis Information:
|
||||||
- Host: localhost
|
- Host: localhost
|
||||||
- Port: 6379
|
- Port: 6379
|
||||||
|
- User: $REDIS_USER
|
||||||
- Password: $REDIS_PASSWORD
|
- Password: $REDIS_PASSWORD
|
||||||
- Database: $REDIS_DB
|
- Database: $REDIS_DB
|
||||||
|
|
||||||
@@ -1641,6 +1668,7 @@ deploy_instance() {
|
|||||||
echo -e "${YELLOW}Database Name: $DB_NAME${NC}"
|
echo -e "${YELLOW}Database Name: $DB_NAME${NC}"
|
||||||
echo -e "${YELLOW}Database User: $DB_USER${NC}"
|
echo -e "${YELLOW}Database User: $DB_USER${NC}"
|
||||||
echo -e "${YELLOW}Database Password: $DB_PASS${NC}"
|
echo -e "${YELLOW}Database Password: $DB_PASS${NC}"
|
||||||
|
echo -e "${YELLOW}Redis User: $REDIS_USER${NC}"
|
||||||
echo -e "${YELLOW}Redis Password: $REDIS_PASSWORD${NC}"
|
echo -e "${YELLOW}Redis Password: $REDIS_PASSWORD${NC}"
|
||||||
echo -e "${YELLOW}Redis Database: $REDIS_DB${NC}"
|
echo -e "${YELLOW}Redis Database: $REDIS_DB${NC}"
|
||||||
echo -e "${YELLOW}JWT Secret: $JWT_SECRET${NC}"
|
echo -e "${YELLOW}JWT Secret: $JWT_SECRET${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user