security
Security
Hardening Script
The connect.sh script (or infra/secure-deploy.sh) performs these hardening steps:
-
UFW Firewall
- Default deny incoming
- Allow SSH (22), HTTP (80), HTTPS (443)
- Rate limiting on SSH
-
SSH Hardening
PermitRootLogin prohibit-password— key-only root accessPasswordAuthentication no— no password logins- Key-only authentication enforced
-
🔒 SSH Keys Encrypted at Rest
- Private keys are encrypted with AES-256-GCM before being written to PostgreSQL
- Key derived from
SSH_ENCRYPTION_KEYenv var (orAUTH_SECRETas fallback) - Backward compatible — existing plaintext keys work without migration
- Decrypted on-the-fly in memory just before SSH connection
-
Fail2Ban
- SSH jail: 3 failed attempts → 1-hour ban
- Persistent across restarts
-
Cron Guard
- Hourly cron job at
/etc/cron.hourly/srvly-key-guard - Re-checks and re-adds the srvly SSH key if removed
- Prevents accidental lockout
- Hourly cron job at
API Security
- Input validation — All REST endpoints validated with Zod schemas (types, bounds, regex pattern checks)
- RCE prevention — Environment variables use heredoc +
--env-fileinstead of inline shell interpolation - Host validation — IP/hostname format verified before SSH connection
- Auth required — All agent endpoints require Bearer token authentication
AI Agent Safety
When using AI agents through srvly, the agent prompt includes strict safety rules:
- Agents cannot modify SSH configuration
- Agents cannot change firewall rules
- Agents cannot run system upgrades
- Agents cannot access sensitive files
- Agents must verify domain/port availability before deploying