Skip to content

Commit 9ec1115

Browse files
committed
fix: security first development
- criar gerador de Secrets JWT e Rails - udpate docker envs
1 parent e46e790 commit 9ec1115

File tree

3 files changed

+75
-31
lines changed

3 files changed

+75
-31
lines changed

.env.example

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
1-
# Database
2-
DB_HOST=localhost
3-
DB_PORT=5432
4-
DB_USERNAME=postgres
5-
DB_PASSWORD=
1+
# ===========================================
2+
# Docker Compose Configuration
3+
# ===========================================
4+
5+
# PostgreSQL (when using local Docker postgres)
6+
POSTGRES_DB=prostaff_api_development
7+
POSTGRES_USER=postgres
8+
POSTGRES_PASSWORD=password
9+
POSTGRES_PORT=5432
10+
11+
# Redis
12+
REDIS_PORT=6379
13+
REDIS_URL=redis://redis:6379/0
14+
15+
# API Port
16+
API_PORT=3333
17+
18+
# ===========================================
19+
# Application Configuration
20+
# ===========================================
21+
22+
# Database Connection
23+
# For Docker with local postgres: postgresql://postgres:password@postgres:5432/prostaff_api_development
24+
# For Supabase: postgresql://user:password@host:port/database
25+
DATABASE_URL=postgresql://postgres:password@postgres:5432/prostaff_api_development
626

727
# Rails
828
RAILS_ENV=development
929
SECRET_KEY_BASE=your_secret_key_here
1030

11-
# JWT
31+
# JWT Authentication
1232
JWT_SECRET_KEY=your_jwt_secret_key_here
1333
JWT_EXPIRATION_HOURS=24
1434

1535
# Riot API
1636
RIOT_API_KEY=your_riot_api_key_here
1737

18-
# Redis (for Sidekiq and caching)
19-
REDIS_URL=redis://localhost:6379/0
38+
# CORS - Add your frontend URLs separated by commas
39+
CORS_ORIGINS=http://localhost:8888,http://localhost:5173,http://localhost:8080,http://localhost:3001
2040

21-
# CORS
22-
CORS_ORIGINS=http://localhost:8888,http://localhost:5173,http://localhost:8080
41+
# ===========================================
42+
# Email Configuration (Optional)
43+
# ===========================================
2344

24-
# Email (for password reset)
2545
SMTP_ADDRESS=smtp.gmail.com
2646
SMTP_PORT=587
2747
SMTP_USERNAME=[email protected]
28-
SMTP_PASSWORD=your_password
48+
SMTP_PASSWORD=your_app_password
2949
SMTP_DOMAIN=gmail.com
3050

3151
# Frontend URL (for email links)
3252
FRONTEND_URL=http://localhost:8888
3353

54+
# ===========================================
3455
# Rate Limiting
56+
# ===========================================
57+
3558
RACK_ATTACK_LIMIT=300
3659
RACK_ATTACK_PERIOD=300

docker-compose.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ services:
33
postgres:
44
image: postgres:15-alpine
55
environment:
6-
POSTGRES_DB: prostaff_api_development
7-
POSTGRES_USER: postgres
8-
POSTGRES_PASSWORD: password
6+
POSTGRES_DB: ${POSTGRES_DB:-prostaff_api_development}
7+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
8+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
99
volumes:
1010
- postgres_data:/var/lib/postgresql/data
1111
ports:
12-
- "5432:5432"
12+
- "${POSTGRES_PORT:-5432}:5432"
1313
healthcheck:
14-
test: ["CMD-SHELL", "pg_isready -U postgres"]
14+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
1515
interval: 10s
1616
timeout: 5s
1717
retries: 5
@@ -22,7 +22,7 @@ services:
2222
volumes:
2323
- redis_data:/data
2424
ports:
25-
- "6399:6379"
25+
- "${REDIS_PORT:-6379}:6379"
2626
healthcheck:
2727
test: ["CMD", "redis-cli", "ping"]
2828
interval: 10s
@@ -33,34 +33,35 @@ services:
3333
api:
3434
build: .
3535
environment:
36-
DATABASE_URL: postgresql://postgres:password@postgres:5432/prostaff_api_development
37-
REDIS_URL: redis://redis:6379/0
38-
RAILS_ENV: development
39-
JWT_SECRET_KEY: your_jwt_secret_key_for_development
40-
CORS_ORIGINS: http://localhost:5173,http://localhost:8080,http://localhost:3001
36+
DATABASE_URL: ${DATABASE_URL}
37+
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
38+
RAILS_ENV: ${RAILS_ENV:-development}
39+
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
40+
CORS_ORIGINS: ${CORS_ORIGINS}
41+
RIOT_API_KEY: ${RIOT_API_KEY}
4142
volumes:
4243
- .:/app
4344
- bundle_cache:/usr/local/bundle
4445
ports:
45-
- "3333:3000"
46+
- "${API_PORT:-3333}:3000"
4647
depends_on:
47-
postgres:
48-
condition: service_healthy
4948
redis:
5049
condition: service_healthy
5150
command: >
5251
sh -c "
53-
bundle exec rails db:create db:migrate db:seed &&
54-
bundle exec rails server -b 0.0.0.0
52+
rm -f tmp/pids/server.pid &&
53+
bundle exec rails db:migrate &&
54+
bundle exec rails server -b 0.0.0.0 -p 3000
5555
"
5656
5757
# Sidekiq for background jobs
5858
sidekiq:
5959
build: .
6060
environment:
61-
DATABASE_URL: postgresql://postgres:password@postgres:5432/prostaff_api_development
62-
REDIS_URL: redis://redis:6379/0
63-
RAILS_ENV: development
61+
DATABASE_URL: ${DATABASE_URL}
62+
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
63+
RAILS_ENV: ${RAILS_ENV:-development}
64+
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
6465
volumes:
6566
- .:/app
6667
- bundle_cache:/usr/local/bundle

scripts/generate_secrets.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
echo "================================================"
4+
echo "🔐 ProStaff API - Secret Generator"
5+
echo "================================================"
6+
echo ""
7+
echo "Cole esses valores no seu arquivo .env:"
8+
echo ""
9+
10+
echo "# Rails Secret Key Base"
11+
echo "SECRET_KEY_BASE=$(openssl rand -hex 64)"
12+
echo ""
13+
14+
echo "# JWT Secret Key"
15+
echo "JWT_SECRET_KEY=$(openssl rand -hex 64)"
16+
echo ""
17+
18+
echo "================================================"
19+
echo "✅ Secrets gerados com sucesso!"
20+
echo "================================================"

0 commit comments

Comments
 (0)