Complete guide for setting up Go-Auth in development and production environments.
- Prerequisites
- Quick Start (Development)
- Detailed Setup
- Configuration
- CLI Commands
- Docker Deployment
- Production Deployment
- Troubleshooting
Check version:
go version
# Should output: go version go1.24.x ...Installation:
- macOS:
brew install go - Linux: Download from golang.org/dl
- Windows: Download installer from golang.org/dl
Check version:
psql --version
# Should output: psql (PostgreSQL) 13.x or higherInstallation:
- macOS:
brew install postgresql@14 - Linux (Ubuntu):
sudo apt install postgresql postgresql-contrib - Windows: Download from postgresql.org
- Docker:
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=admin postgres:14
Check version:
redis-cli --version
# Should output: redis-cli 6.x.x or higherInstallation:
- macOS:
brew install redis - Linux (Ubuntu):
sudo apt install redis-server - Windows: Use WSL or Docker
- Docker:
docker run -d -p 6379:6379 redis:7-alpine
Check:
make --versionInstallation:
- macOS: Included with Xcode Command Line Tools
- Linux: Usually pre-installed, or
sudo apt install build-essential - Windows: Install via Chocolatey
choco install make
For containerized deployment.
Check:
docker --version
docker-compose --versionInstallation: Follow Docker Desktop guide
git clone <repository-url>
cd go-authcp .env.sample .envEdit .env if needed (default values work for local development).
make devThis starts:
- PostgreSQL on port 5432
- Redis on port 6379
- Mailhog SMTP on port 1025
- Mailhog UI on http://localhost:8025
make initThis creates:
- Default permissions (users.read, users.write, etc.)
- Default roles (super-admin, admin, user)
- Role-permission assignments
make create-superuserDefault credentials:
- Email:
admin@go-auth.local - Password:
SuperSecure123!
make runServer runs on http://localhost:42069
# Health check
curl http://localhost:42069/health
# Signup
curl -X POST http://localhost:42069/api/v1/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123!",
"first_name": "John",
"last_name": "Doe"
}'
# Check Mailhog for verification email
open http://localhost:8025
# Signin
curl -X POST http://localhost:42069/api/v1/auth/signin \
-H "Content-Type: application/json" \
-d '{
"email": "admin@go-auth.local",
"password": "SuperSecure123!"
}'Already included in docker-compose.yml:
postgres:
image: postgres:14-alpine
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: auth
ports:
- "5432:5432"-
Create Database:
createdb auth
-
Create User (if needed):
CREATE USER admin WITH PASSWORD 'admin'; GRANT ALL PRIVILEGES ON DATABASE auth TO admin;
-
Update
.env:DB_URL=localhost DB_PORT=5432 DB_USER=admin DB_PASS=admin DB_NAME=auth
Already included in docker-compose.yml:
redis:
image: redis:7-alpine
ports:
- "6379:6379"-
Start Redis:
redis-server
-
Verify:
redis-cli ping # Should return: PONG -
Update
.env:REDIS_HOST=127.0.0.1 REDIS_PORT=6379
Already included in docker-compose.yml:
mailhog:
image: mailhog/mailhog:latest
ports:
- "1025:1025" # SMTP server
- "8025:8025" # Web UIAccess web UI at http://localhost:8025
-
Configure AWS Credentials:
export AWS_REGION=us-east-1 export AWS_ACCESS_KEY_ID=your_access_key export AWS_SECRET_ACCESS_KEY=your_secret_key
-
Update Email Provider in
cmd/server.go:// Replace MailhogProvider with SESProvider emailProvider := provider.NewSESProvider( os.Getenv("AWS_REGION"), "noreply@yourdomain.com", logger, )
-
Verify SES Domain:
- Go to AWS SES Console
- Verify your sending domain
- Move out of sandbox mode for production
# Build binary
make build
# Binary location: ./bin/go-auth
./bin/go-auth --helpgo mod tidy
go mod vendor
go build -o go-auth .
./go-auth --help./bin/go-auth init --config ./configs/rbac-config.yamlOutput:
Created 12 permissions
Updated 0 permissions
Created 3 roles: super-admin, admin, user
Updated 0 roles
RBAC initialization completed successfully
Customize RBAC by editing configs/rbac-config.yaml:
permissions:
- code: "custom.read"
name: "Read Custom Resource"
resource: "custom"
action: "read"
roles:
- code: "custom-role"
name: "Custom Role"
description: "Custom role with specific permissions"
permissions:
- "custom.read"
- "users.read"Then re-run make init (idempotent operation).
./bin/go-auth admin create-superuser \
--email admin@yourdomain.com \
--password YourSecurePassword123! \
--first-name Admin \
--last-name UserConstraints:
- Only 1 super-admin allowed (enforced by
max_users: 1in RBAC config) - Super-admin role must exist (created by
initcommand)
./bin/go-auth jobs jwks-refresh --interval 24h &This rotates JWT signing keys every 24 hours for enhanced security.
./bin/go-auth server --port 42069Server Logs (JSON format):
{"time":"2025-10-19T10:00:00Z","level":"INFO","msg":"Starting HTTP server","port":"42069"}
{"time":"2025-10-19T10:00:05Z","level":"INFO","msg":"Request completed","request_id":"abc123","method":"POST","path":"/api/v1/auth/signin","status":200,"duration":"45ms"}Create .env file in project root:
# Database Configuration
DB_URL=localhost # PostgreSQL host
DB_PORT=5432 # PostgreSQL port
DB_USER=admin # Database user
DB_PASS=admin # Database password
DB_NAME=auth # Database name
# Redis Configuration
REDIS_HOST=127.0.0.1 # Redis host
REDIS_PORT=6379 # Redis port
# JWT Configuration
SECRET_KEY_ID=key1 # Key identifier for JWKS
SECRET_PRIVATE_KEY=<RSA_PRIVATE_KEY> # Generated by InitializeKeys
# API Configuration
API_PORT=42069 # HTTP server port
# Email Configuration (Production)
EMAIL_PROVIDER=ses # ses or mailhog
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
# Logging
LOG_LEVEL=info # debug, info, warn, error
GIN_MODE=release # debug or releaseEdit configs/rbac-config.yaml:
permissions:
# Define permissions with code, name, resource, action
- code: "users.read"
name: "View Users"
description: "Can view user information"
resource: "users"
action: "read"
- code: "users.write"
name: "Manage Users"
description: "Can create and update users"
resource: "users"
action: "write"
roles:
# Define roles with code, name, permissions
- code: "super-admin"
name: "Super Administrator"
description: "Full system access"
is_system: true # Cannot be modified via API
is_default: false # Not assigned to new users
max_users: 1 # Limit to 1 super-admin
permissions:
- "*" # All permissions (wildcard)
- code: "admin"
name: "Administrator"
description: "Admin with elevated privileges"
is_system: true
permissions:
- "users.*" # All user permissions
- "rbac.*" # All RBAC permissions
- code: "user"
name: "User"
description: "Default user role"
is_default: true # Assigned to new signups
permissions:
- "users.read.self" # Can only read own profile
- "users.write.self" # Can only update own profileWildcard Matching:
*: All permissionsusers.*: All permissions starting with "users."users.read: Exact match only
# Start HTTP server
go-auth server [--port PORT]
# Examples:
go-auth server # Use port from .env
go-auth server --port 8080 # Override port# Initialize RBAC from config
go-auth init [--config PATH]
# Examples:
go-auth init # Use default config
go-auth init --config /path/to/custom-rbac.yaml # Custom config# Create super-admin user
go-auth admin create-superuser \
--email EMAIL \
--password PASSWORD \
--first-name FIRST \
--last-name LAST
# Example:
go-auth admin create-superuser \
--email admin@company.com \
--password SecurePass123! \
--first-name Alice \
--last-name Admin# Run JWKS key refresh job
go-auth jobs jwks-refresh --interval DURATION
# Examples:
go-auth jobs jwks-refresh --interval 24h # Rotate every 24 hours
go-auth jobs jwks-refresh --interval 1h # Rotate every hour-
Build Image:
make docker-build
-
Start All Services:
make docker-up
This starts:
- PostgreSQL
- Redis
- Mailhog
- Go-Auth API server
-
View Logs:
make docker-logs
-
Stop Services:
make docker-down
version: '3.8'
services:
postgres:
image: postgres:14-alpine
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: auth
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
ports:
- "6379:6379"
go-auth:
build: .
ports:
- "42069:42069"
environment:
DB_URL: postgres
DB_PORT: 5432
DB_USER: admin
DB_PASS: admin
DB_NAME: auth
REDIS_HOST: redis
REDIS_PORT: 6379
API_PORT: 42069
depends_on:
- postgres
- redis
command: server
volumes:
postgres_data:# Set production environment
export GIN_MODE=release
# Build optimized binary
go build -ldflags="-s -w" -o go-auth .Create production .env:
DB_URL=prod-postgres.example.com
DB_PORT=5432
DB_USER=auth_user
DB_PASS=<strong_password>
DB_NAME=auth_prod
REDIS_HOST=prod-redis.example.com
REDIS_PORT=6379
SECRET_KEY_ID=prod-key-2025
API_PORT=42069
EMAIL_PROVIDER=ses
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=<prod_key>
AWS_SECRET_ACCESS_KEY=<prod_secret>
LOG_LEVEL=info
GIN_MODE=release# Initialize RBAC (idempotent)
./go-auth init --config ./configs/rbac-config.yaml
# Create super-admin
./go-auth admin create-superuser \
--email admin@company.com \
--password <strong_password> \
--first-name Admin \
--last-name UserCreate /etc/systemd/system/go-auth.service:
[Unit]
Description=Go-Auth API Server
After=network.target postgresql.service redis.service
[Service]
Type=simple
User=go-auth
WorkingDirectory=/opt/go-auth
EnvironmentFile=/opt/go-auth/.env
ExecStart=/opt/go-auth/go-auth server
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.targetCreate /etc/systemd/system/go-auth-jwks.service:
[Unit]
Description=Go-Auth JWKS Refresh Job
After=network.target redis.service
[Service]
Type=simple
User=go-auth
WorkingDirectory=/opt/go-auth
EnvironmentFile=/opt/go-auth/.env
ExecStart=/opt/go-auth/go-auth jobs jwks-refresh --interval 24h
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl daemon-reload
sudo systemctl enable go-auth go-auth-jwks
sudo systemctl start go-auth go-auth-jwks
sudo systemctl status go-authdocker run -d \
--name go-auth \
--restart always \
-p 42069:42069 \
--env-file .env \
go-auth:latest \
serverserver {
listen 80;
server_name auth.example.com;
location / {
proxy_pass http://localhost:42069;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Enable HTTPS with Let's Encrypt:
sudo certbot --nginx -d auth.example.com# Liveness check (always returns 200)
curl http://localhost:42069/health
# Readiness check (checks database)
curl http://localhost:42069/readyLogs are JSON formatted for easy parsing:
# View logs
journalctl -u go-auth -f
# Filter by level
journalctl -u go-auth | jq 'select(.level=="ERROR")'
# Monitor specific endpoint
journalctl -u go-auth | jq 'select(.path=="/api/v1/auth/signin")'Check:
# Test PostgreSQL connection
psql -h $DB_URL -p $DB_PORT -U $DB_USER -d $DB_NAME
# Verify credentials in .env
cat .env | grep DB_Solution:
- Ensure PostgreSQL is running
- Check firewall rules
- Verify credentials
Check:
# Test Redis connection
redis-cli -h $REDIS_HOST -p $REDIS_PORT ping
# Check Redis status
redis-cli info serverSolution:
- Ensure Redis is running
- Check firewall rules
- Verify Redis is not password-protected (or configure password)
Solution:
# Re-run RBAC initialization
./go-auth init --config ./configs/rbac-config.yaml
# Verify roles created
psql -h localhost -U admin -d auth -c "SELECT * FROM roles;"Error: "role has reached maximum users limit (1)"
Solution:
- For super-admin: Only 1 allowed by design
- For custom roles: Edit
configs/rbac-config.yamland increasemax_users, then re-runinit
Mailhog (Development):
- Check Mailhog UI: http://localhost:8025
- Verify SMTP port 1025 is accessible
SES (Production):
# Test SES sending
aws ses send-email \
--from noreply@yourdomain.com \
--to test@example.com \
--subject "Test" \
--text "Test email"- Verify domain in SES Console
- Check SES sending limits
- Move out of SES sandbox mode
Check:
# Verify JWKS keys in Redis
redis-cli keys "auth:jwks:*"
# Get public key
redis-cli get "auth:jwks:key:key1"Solution:
# Regenerate keys
redis-cli del "auth:jwks:key:key1"
redis-cli del "auth:jwks"
# Restart server (will regenerate keys)
systemctl restart go-authCheck file permissions:
ls -la /opt/go-auth/Solution:
# Fix ownership
sudo chown -R go-auth:go-auth /opt/go-auth/
# Fix executable
chmod +x /opt/go-auth/go-authAfter successful setup:
- Read Architecture Docs: See ARCHITECTURE.md
- Review API Flows: See API_FLOWS.md
- Test Endpoints: Use Postman or curl to test API
- Customize RBAC: Edit
configs/rbac-config.yamlfor your needs - Integrate with Frontend: Use JWT tokens from signin endpoint
- Monitor Logs: Set up log aggregation (ELK, Datadog, etc.)
- Configure Backups: Set up PostgreSQL backups
- Enable Rate Limiting: Implement Redis-based rate limiting (future enhancement)
For issues, questions, or contributions:
- GitHub Issues: [Link to repo issues]
- Documentation: [Link to main README]
- License: MIT License