Skip to content

Security Hardening

This guide covers security best practices for hardening your Rack Gateway deployment.

Deploy the gateway on a private network, not exposed to the public internet:

Options:

  • Tailscale - Zero-config VPN
  • AWS VPN - Site-to-site VPN
  • AWS PrivateLink - Private connectivity

All traffic should use TLS:

Terminal window
# Required environment variables
GATEWAY_URL=https://gateway.example.com
# TLS certificate (for standalone deployment)
TLS_CERT_FILE=/etc/ssl/certs/gateway.crt
TLS_KEY_FILE=/etc/ssl/private/gateway.key

When deployed on Convox, TLS is handled by the load balancer.

Restrict network access:

PortSourceDestinationProtocol
443VPN/TailscaleGatewayHTTPS
5432GatewayRDSPostgreSQL
443GatewayConvox APIHTTPS

Block all other inbound traffic to the gateway.

Secure your OAuth setup:

Terminal window
# Required: Restrict to your domain
GOOGLE_ALLOWED_DOMAIN=yourcompany.com
# Strong secret key (generate with: openssl rand -base64 32)
APP_SECRET_KEY=<random-32-byte-value>

Require MFA for all users or privileged roles:

SettingRecommended ValueNotes
MFA RequiredAll usersOr at minimum, admins/deployers
Step-up Window10 minutesShorter for higher security
Trusted Device TTL7 daysOr disable for highest security

Configure secure session settings:

Terminal window
# Short idle timeout (5-15 minutes recommended)
SESSION_TIMEOUT_MINUTES=5
# Secure cookies (automatic in production)
SECURE_COOKIES=true

Follow least privilege principles:

User TypeRoleNotes
Most engineersViewerStart here, upgrade as needed
Active developersDeployerOnly if deploying regularly
On-call/SREOpsDebug without deploy access
CI/CD pipelinesCI/CD tokenNever Deployer or Admin
Platform adminsAdmin2-3 people maximum

Secure your API tokens:

  1. Use CI/CD role for automation

    Never give deployer or admin to CI/CD pipelines

  2. Rotate tokens regularly

    Production tokens: quarterly minimum

  3. Use separate tokens per environment

    Different tokens for staging vs production

  4. Monitor token usage

    Review unused tokens monthly

  5. Delete unused tokens immediately

    Don’t keep “just in case” tokens

Restrict administrative access:

  • Maximum 2-3 admin users
  • Require MFA for all admins
  • Review admin actions weekly
  • Document who has admin access and why

Protect sensitive environment variables:

Terminal window
# Mark variables as protected (hidden in UI)
PROTECTED_ENV_VARS=DATABASE_URL,API_KEY,SECRET_KEY
# Never log these patterns
REDACT_PATTERNS=password,secret,token,key,credential

Store secrets securely:

SecretStorage LocationNotes
GOOGLE_CLIENT_SECRETAWS Secrets ManagerOr Convox environment
APP_SECRET_KEYAWS Secrets ManagerCritical - rotate annually
DATABASE_URLConvox environmentWith password
API tokensCI/CD secretsGitHub/CircleCI secrets

Never store secrets in:

  • Git repositories
  • Environment files checked into git
  • Logs or audit trails
  • Error messages

Secure your database:

# RDS configuration (Terraform)
resource "aws_db_instance" "gateway" {
# Encryption at rest
storage_encrypted = true
kms_key_id = aws_kms_key.rds.arn
# Network isolation
publicly_accessible = false
vpc_security_group_ids = [aws_security_group.rds.id]
# Audit logging
enabled_cloudwatch_logs_exports = ["postgresql"]
}

Restrict database access:

  • Gateway application only (no direct access)
  • Separate admin credentials for migrations
  • VPC-only access (no public endpoint)
  • Encrypted connections (require SSL)

Enable comprehensive auditing:

Terminal window
# Enable all audit features
AUDIT_ENABLED=true
AUDIT_LOG_REQUESTS=true
AUDIT_LOG_RESPONSES=false # Don't log response bodies

For compliance requirements:

Terminal window
AUDIT_ANCHOR_S3_BUCKET=audit-anchor-production
AUDIT_ANCHOR_S3_REGION=us-east-1

See Data Retention for full configuration.

Configure alerts for security events:

Terminal window
# Slack notifications
SLACK_WEBHOOK_URL=https://hooks.slack.com/...
SLACK_NOTIFY_SECURITY_EVENTS=true
# Email alerts
POSTMARK_API_KEY=your-key
SECURITY_ALERT_EMAIL=security@example.com

Alert on:

  • Multiple failed login attempts
  • RBAC denials
  • Admin actions
  • Account locks
  • Token creation/deletion

Secure your container deployment:

convox.yml
services:
gateway:
# Run as non-root user
user: "65534:65534"
# Read-only filesystem
volumes:
- /tmp:rw
# Resource limits
cpu: 256
memory: 512

Configure health checks without exposing sensitive information:

services:
gateway:
health:
path: /api/v1/health
interval: 30
timeout: 5

The health endpoint should not require authentication and should not expose internal details.

  • Gateway on private network (VPN/Tailscale)
  • HTTPS enforced with valid certificate
  • OAuth domain restriction configured
  • MFA required for privileged users
  • Session timeout ≤ 15 minutes
  • Admin users ≤ 3
  • CI/CD uses CI/CD role tokens
  • Database encrypted and VPC-only
  • Audit logging enabled
  • S3 WORM configured (if required)
  • Security alerts configured
  • Incident response runbook created
  • Weekly admin action review
  • Monthly token audit
  • Quarterly access review
  • Annual secret rotation
  • Regular security scanning
  • Incident response testing

The gateway sets secure HTTP headers:

HeaderValuePurpose
Strict-Transport-Securitymax-age=31536000Force HTTPS
X-Content-Type-OptionsnosniffPrevent MIME sniffing
X-Frame-OptionsDENYPrevent clickjacking
Content-Security-PolicyStrict policyPrevent XSS
X-XSS-Protection1; mode=blockXSS filter

The gateway uses a strict CSP:

default-src 'self';
script-src 'self' 'nonce-xxx';
style-src 'self' 'nonce-xxx';
img-src 'self' data:;
font-src 'self';
connect-src 'self';
frame-ancestors 'none';
  1. Lock the account immediately
  2. Revoke all sessions
  3. Review audit logs for suspicious activity
  4. Rotate any accessed secrets
  5. Investigate root cause
  6. Unlock after re-verification
  1. Delete the token immediately
  2. Review audit logs for token usage
  3. Create replacement token
  4. Update affected systems
  5. Investigate how token was exposed
  1. Lock all non-admin accounts
  2. Revoke all sessions
  3. Rotate all secrets
  4. Enable enhanced logging
  5. Review last 30 days of audit logs
  6. Engage security team / incident response