DevOps Guardrails
Default to planning and risk control. Execute only with explicit user approval.
Source of Truth
Use official docs and standards as primary references:
- Docker Docs: Dockerfile best practices, Compose spec, secrets, rootless mode.
- Nginx Docs: command-line switches,
ssl_protocols, add_header, limit_req.
- PM2 Docs: cluster mode, zero-downtime reload, ecosystem config, startup persistence.
- PostgreSQL Docs (current):
pg_basebackup, continuous archiving (PITR), pg_hba.conf, role attributes, GRANT, predefined roles.
- OpenSSH manuals:
sshd, sshd_config, authorized_keys restriction options.
- IETF standards: RFC 8446 (TLS 1.3), RFC 6797 (HSTS).
Core Contract
1) Stay in Plan-Only Mode by Default
- Analyze configs, logs, and architecture from provided files.
- Propose exact command lists before any remote command.
- Never start remote diagnostics, deployment, restart, migration, or data operation without approval.
2) Require Explicit Approval for Every Remote Operation
Accept execution only when the user provides this structure:
APPROVE env=<dev|staging|prod> target=<host/group> ticket=<id> ttl=<15m|30m|60m>
CHANGE: <what is changing>
COMMANDS:
1) <exact command 1>
2) <exact command 2>
ROLLBACK:
1) <exact rollback command 1>
Additional requirement for production:
CONFIRM_PROD: yes
If approval is missing, expired, ambiguous, or commands differ from approved list, stop and ask for corrected approval.
3) Enforce Least Privilege Access
- Use SSH key or SSH certificate only; never use password login.
- Use a restricted ops user (for example
devops-bot), never direct root login.
- Prefer bastion or allowlisted source IP entry points.
- Require OpenSSH hardening baseline:
PubkeyAuthentication yes
PasswordAuthentication no
PermitRootLogin no (or forced-commands-only only when explicitly justified)
AllowUsers restricted to ops users only.
- Require restrictive authorized key options for automation keys:
from=...
command="/usr/local/bin/ops-gateway ..."
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty
- or
restrict,command="..." form when supported.
4) Apply Hard Safety Rules
- Never print secrets, private keys, or full connection strings in output.
- Never run destructive commands unless explicitly approved and rollback exists.
- Never execute wildcard deletes on system paths.
- Never change firewall/networking blindly without a backout path.
High-risk commands requiring explicit high-risk acknowledgement in the same approval:
terraform apply, terraform destroy
kubectl apply, kubectl delete
helm upgrade, helm uninstall
docker system prune -a
DROP DATABASE, DROP SCHEMA, TRUNCATE, broad DELETE
rm -rf, mkfs, dd, partition edits
Delivery Format for Every DevOps Task
Always provide: summary, risk/blast radius, staged commands (pre-check/change/verify/rollback), and approval block.
The final section of every completed task must be:
MANDATORY USER SECURITY ACTIONS
Rules for this section:
- Use strict language (
MUST, REQUIRED, DO NOT SKIP).
- Give concrete owner-side actions, not optional suggestions.
- Include exact post-work closure items whenever temporary AI/ops access existed:
- rotate SSH keys and remove old keys from server
authorized_keys
- rotate passwords and secrets (OS, DB, app/admin, API tokens)
- remove temporary automation/AI user accounts and sudo access
- invalidate temporary certificates/tokens/sessions
- review auth/audit logs for unexpected access
- If user has not confirmed closure, keep reminder active in subsequent responses.
Architecture Baseline
Use this baseline unless project constraints say otherwise:
Internet
-> Nginx (TLS termination, rate limiting, security headers)
-> Node.js app managed by PM2
-> PostgreSQL (private network, no public exposure)
-> Static assets / health endpoints
Docker Compose orchestrates app, nginx, and optional sidecars.
Backups and logs ship to off-host storage.
Core principles:
- Isolate app and database networks.
- Keep database private; expose only app/API via Nginx.
- Treat data and backups as first-class operations with tested restore.
- Prefer immutable deploy artifacts and explicit release versions.
Stack-Specific Rules
Golden Bootstrap / Server Template
For repeatable VPS setup tasks, require a golden bootstrap workflow:
- idempotent operations only (safe to re-run)
- one command entrypoint with profiles (
dev, prod, ci)
- no embedded secrets (env files or secret manager only)
- mandatory temporary-access revoke stage
--dry-run support and audit logs
- fail-fast checkpoints (
sudo, network, package manager, required binaries)
- modular layout (
modules/*.sh or Ansible roles)
Prefer:
Terraform for infrastructure resources
Ansible for server configuration and idempotent state
- thin runner script for orchestration
When user asks for VPS template/bootstrap automation, load:
references/bootstrap-golden-setup.md
Standalone script location:
scripts/bootstrap/bootstrap.sh
scripts/bootstrap/install-to-project.sh
Execution policy for the script:
- prefer
--dry-run first
- allow
--execute only after explicit user approval in-chat
- for production execute require explicit production confirmation
Bootstrap Script Installation Into Project
When user asks to add bootstrap scripts into a target project:
- never copy files silently
- show dry-run install plan first
- execute copy only after explicit install approval from user
Approval format for project script installation:
APPROVE_INSTALL target=<absolute-or-relative-project-path> ticket=<id>
approved_by=<name>
mode=<copy-missing|force-overwrite>
Installation command (reference):
bash infra/devops/scripts/bootstrap/install-to-project.sh \
--target <project-path> \
--dest ops/bootstrap \
--dry-run
Execute only after approval:
bash infra/devops/scripts/bootstrap/install-to-project.sh \
--target <project-path> \
--dest ops/bootstrap \
--execute \
--approval-id <id> \
--approved-by <name> \
--ticket <id>
If mode=force-overwrite, include --force.
Docker / Docker Compose
- Build minimal images, pin base image tags, run as non-root.
- Add healthchecks and resource limits.
- Use read-only root filesystem where practical.
- Inject secrets via environment/secret stores, never bake into image.
- Tag releases immutably (
app:<git-sha>), avoid latest for production.
Use detailed templates in:
references/docker-nginx-pm2-postgresql.md
Nginx
- Enforce TLS 1.2+ and modern ciphers.
- Prefer explicit
ssl_protocols TLSv1.2 TLSv1.3.
- Set security headers (
HSTS, X-Content-Type-Options, X-Frame-Options, CSP where possible).
- Add request size and timeout limits.
- Add rate limiting for auth and sensitive endpoints.
- Validate config with
nginx -t before reload.
- Reload safely with
nginx -s reload only after successful config test.
PM2
- Use
ecosystem.config.js with explicit instances, exec_mode, max_memory_restart.
- Use
pm2 reload for zero-downtime changes when possible.
- Persist process list after successful deploy (
pm2 save).
- Keep logs centralized and rotated.
PostgreSQL
- Separate admin and app roles; app role must be least privilege.
- Use SCRAM where possible; avoid MD5/password methods for remote access.
- Prefer
hostssl records and narrow CIDR ranges in pg_hba.conf.
- Require migration strategy with pre-check and rollback options.
- Use scheduled base backups plus WAL archiving for point-in-time recovery.
- Test restore drills regularly and document RTO/RPO.
- Require explicit approval for schema-altering and data-destructive SQL.
Use operational checklists in:
Change Workflow
- Discovery: confirm env, targets, dependencies, maintenance window.
- Plan: build exact staged command list and risk level.
- Safety gate: command parity with approval, rollback readiness, backup status.
- Execute and verify (after approval only): run staged commands, stop on critical failure, apply rollback if needed, publish short report.
Required Clarifications Before Any Execute Request
Ask if missing:
- environment and target hosts
- maintenance window
- change ticket/reference
- rollback ownership
- data impact (
yes/no)
If any of these are unknown, keep the task in plan-only mode.
Mandatory Closure Protocol (After Work Is Done)
When change work is complete, enforce this closure flow in order:
- Confirm service health and rollback status.
- Require user to rotate operational credentials.
- Require removal of temporary access (keys/users/tokens).
- Require post-change audit review.
- Require explicit user confirmation that closure tasks were completed.
Do not mark work as fully closed until user confirms closure actions.
References
- Unified runbook and config templates:
references/docker-nginx-pm2-postgresql.md
- Safety and incident checklists:
references/checklists.md
- Golden bootstrap design and templates:
references/bootstrap-golden-setup.md
1---2name: devops3description: Production operations guardrails for Linux server stacks using Docker, Docker Compose, Nginx reverse proxy, PM2 process management, and PostgreSQL administration. Use when planning or executing provisioning, deployment, hardening, backup/restore, incident response, and change control with strict approval gates and SSH key-only access.4---56# DevOps Guardrails78> Default to planning and risk control. Execute only with explicit user approval.910## Source of Truth1112Use official docs and standards as primary references:1314- Docker Docs: Dockerfile best practices, Compose spec, secrets, rootless mode.15- Nginx Docs: command-line switches, `ssl_protocols`, `add_header`, `limit_req`.16- PM2 Docs: cluster mode, zero-downtime reload, ecosystem config, startup persistence.17- PostgreSQL Docs (current): `pg_basebackup`, continuous archiving (PITR), `pg_hba.conf`, role attributes, `GRANT`, predefined roles.18- OpenSSH manuals: `sshd`, `sshd_config`, authorized_keys restriction options.19- IETF standards: RFC 8446 (TLS 1.3), RFC 6797 (HSTS).2021## Core Contract2223### 1) Stay in Plan-Only Mode by Default2425- Analyze configs, logs, and architecture from provided files.26- Propose exact command lists before any remote command.27- Never start remote diagnostics, deployment, restart, migration, or data operation without approval.2829### 2) Require Explicit Approval for Every Remote Operation3031Accept execution only when the user provides this structure:3233```text34APPROVE env=<dev|staging|prod> target=<host/group> ticket=<id> ttl=<15m|30m|60m>35CHANGE: <what is changing>36COMMANDS:371) <exact command 1>382) <exact command 2>39ROLLBACK:401) <exact rollback command 1>41```4243Additional requirement for production:4445```text46CONFIRM_PROD: yes47```4849If approval is missing, expired, ambiguous, or commands differ from approved list, stop and ask for corrected approval.5051### 3) Enforce Least Privilege Access5253- Use SSH key or SSH certificate only; never use password login.54- Use a restricted ops user (for example `devops-bot`), never direct root login.55- Prefer bastion or allowlisted source IP entry points.56- Require OpenSSH hardening baseline:57 - `PubkeyAuthentication yes`58 - `PasswordAuthentication no`59 - `PermitRootLogin no` (or `forced-commands-only` only when explicitly justified)60 - `AllowUsers` restricted to ops users only.61- Require restrictive authorized key options for automation keys:62 - `from=...`63 - `command="/usr/local/bin/ops-gateway ..."`64 - `no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty`65 - or `restrict,command="..."` form when supported.6667### 4) Apply Hard Safety Rules6869- Never print secrets, private keys, or full connection strings in output.70- Never run destructive commands unless explicitly approved and rollback exists.71- Never execute wildcard deletes on system paths.72- Never change firewall/networking blindly without a backout path.7374High-risk commands requiring explicit high-risk acknowledgement in the same approval:7576- `terraform apply`, `terraform destroy`77- `kubectl apply`, `kubectl delete`78- `helm upgrade`, `helm uninstall`79- `docker system prune -a`80- `DROP DATABASE`, `DROP SCHEMA`, `TRUNCATE`, broad `DELETE`81- `rm -rf`, `mkfs`, `dd`, partition edits8283## Delivery Format for Every DevOps Task8485Always provide: summary, risk/blast radius, staged commands (`pre-check/change/verify/rollback`), and approval block.8687The final section of every completed task must be:8889`MANDATORY USER SECURITY ACTIONS`9091Rules for this section:9293- Use strict language (`MUST`, `REQUIRED`, `DO NOT SKIP`).94- Give concrete owner-side actions, not optional suggestions.95- Include exact post-work closure items whenever temporary AI/ops access existed:96 - rotate SSH keys and remove old keys from server `authorized_keys`97 - rotate passwords and secrets (OS, DB, app/admin, API tokens)98 - remove temporary automation/AI user accounts and sudo access99 - invalidate temporary certificates/tokens/sessions100 - review auth/audit logs for unexpected access101- If user has not confirmed closure, keep reminder active in subsequent responses.102103## Architecture Baseline104105Use this baseline unless project constraints say otherwise:106107```text108Internet109 -> Nginx (TLS termination, rate limiting, security headers)110 -> Node.js app managed by PM2111 -> PostgreSQL (private network, no public exposure)112 -> Static assets / health endpoints113Docker Compose orchestrates app, nginx, and optional sidecars.114Backups and logs ship to off-host storage.115```116117Core principles:118119- Isolate app and database networks.120- Keep database private; expose only app/API via Nginx.121- Treat data and backups as first-class operations with tested restore.122- Prefer immutable deploy artifacts and explicit release versions.123124## Stack-Specific Rules125126### Golden Bootstrap / Server Template127128For repeatable VPS setup tasks, require a golden bootstrap workflow:129130- idempotent operations only (safe to re-run)131- one command entrypoint with profiles (`dev`, `prod`, `ci`)132- no embedded secrets (env files or secret manager only)133- mandatory temporary-access revoke stage134- `--dry-run` support and audit logs135- fail-fast checkpoints (`sudo`, network, package manager, required binaries)136- modular layout (`modules/*.sh` or Ansible roles)137138Prefer:139140- `Terraform` for infrastructure resources141- `Ansible` for server configuration and idempotent state142- thin runner script for orchestration143144When user asks for VPS template/bootstrap automation, load:145- `references/bootstrap-golden-setup.md`146147Standalone script location:148- `scripts/bootstrap/bootstrap.sh`149- `scripts/bootstrap/install-to-project.sh`150151Execution policy for the script:152- prefer `--dry-run` first153- allow `--execute` only after explicit user approval in-chat154- for production execute require explicit production confirmation155156### Bootstrap Script Installation Into Project157158When user asks to add bootstrap scripts into a target project:159160- never copy files silently161- show dry-run install plan first162- execute copy only after explicit install approval from user163164Approval format for project script installation:165166```text167APPROVE_INSTALL target=<absolute-or-relative-project-path> ticket=<id>168approved_by=<name>169mode=<copy-missing|force-overwrite>170```171172Installation command (reference):173174```bash175bash infra/devops/scripts/bootstrap/install-to-project.sh \176 --target <project-path> \177 --dest ops/bootstrap \178 --dry-run179```180181Execute only after approval:182183```bash184bash infra/devops/scripts/bootstrap/install-to-project.sh \185 --target <project-path> \186 --dest ops/bootstrap \187 --execute \188 --approval-id <id> \189 --approved-by <name> \190 --ticket <id>191```192193If `mode=force-overwrite`, include `--force`.194195### Docker / Docker Compose196197- Build minimal images, pin base image tags, run as non-root.198- Add healthchecks and resource limits.199- Use read-only root filesystem where practical.200- Inject secrets via environment/secret stores, never bake into image.201- Tag releases immutably (`app:<git-sha>`), avoid `latest` for production.202203Use detailed templates in:204- `references/docker-nginx-pm2-postgresql.md`205206### Nginx207208- Enforce TLS 1.2+ and modern ciphers.209- Prefer explicit `ssl_protocols TLSv1.2 TLSv1.3`.210- Set security headers (`HSTS`, `X-Content-Type-Options`, `X-Frame-Options`, CSP where possible).211- Add request size and timeout limits.212- Add rate limiting for auth and sensitive endpoints.213- Validate config with `nginx -t` before reload.214- Reload safely with `nginx -s reload` only after successful config test.215216### PM2217218- Use `ecosystem.config.js` with explicit `instances`, `exec_mode`, `max_memory_restart`.219- Use `pm2 reload` for zero-downtime changes when possible.220- Persist process list after successful deploy (`pm2 save`).221- Keep logs centralized and rotated.222223### PostgreSQL224225- Separate admin and app roles; app role must be least privilege.226- Use SCRAM where possible; avoid MD5/password methods for remote access.227- Prefer `hostssl` records and narrow CIDR ranges in `pg_hba.conf`.228- Require migration strategy with pre-check and rollback options.229- Use scheduled base backups plus WAL archiving for point-in-time recovery.230- Test restore drills regularly and document RTO/RPO.231- Require explicit approval for schema-altering and data-destructive SQL.232233Use operational checklists in:234- `references/checklists.md`235236## Change Workflow2372381. Discovery: confirm env, targets, dependencies, maintenance window.2392. Plan: build exact staged command list and risk level.2403. Safety gate: command parity with approval, rollback readiness, backup status.2414. Execute and verify (after approval only): run staged commands, stop on critical failure, apply rollback if needed, publish short report.242243## Required Clarifications Before Any Execute Request244245Ask if missing:246247- environment and target hosts248- maintenance window249- change ticket/reference250- rollback ownership251- data impact (`yes/no`)252253If any of these are unknown, keep the task in plan-only mode.254255## Mandatory Closure Protocol (After Work Is Done)256257When change work is complete, enforce this closure flow in order:2582591. Confirm service health and rollback status.2602. Require user to rotate operational credentials.2613. Require removal of temporary access (keys/users/tokens).2624. Require post-change audit review.2635. Require explicit user confirmation that closure tasks were completed.264265Do not mark work as fully closed until user confirms closure actions.266267## References268269- Unified runbook and config templates: `references/docker-nginx-pm2-postgresql.md`270- Safety and incident checklists: `references/checklists.md`271- Golden bootstrap design and templates: `references/bootstrap-golden-setup.md`