Skip to content

Production Setup

Avinash Gupta edited this page Oct 18, 2026 · 1 revision

Production Setup

How to run rdstail as a long-lived service: permissions, where to run it, state, upgrades and hardening. Size it first with Scaling and Performance and Throughput.

Topology in one sentence: one rdstail process (or one per shard) with a persistent local disk for state.db, credentials from the platform role, metrics scraped by Prometheus. It is not clustered: never run two replicas of the same config and state.

IAM

Generate the least-privilege policy for your exact config:

rdstail iam-policy -c rdstail.yaml              # JSON, scoped to your instances / bucket+prefix
rdstail iam-policy -c rdstail.yaml --deep       # + what `validate --deep` probes
rdstail iam-policy -c rdstail.yaml --terraform  # aws_iam_policy_document

Reference policy for one S3 sink in the same account:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "rds:DescribeDBInstances",
        "rds:DescribeEvents",
        "rds:DescribeDBLogFiles",
        "rds:DownloadDBLogFilePortion"
      ],
      "Resource": "*"
    },
    { "Effect": "Allow", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::my-log-bucket/rds/*" },
    { "Effect": "Allow", "Action": "sts:GetCallerIdentity", "Resource": "*" }
  ]
}

Add kms:Encrypt + kms:GenerateDataKey on the key for SSE-KMS, and sts:AssumeRole on target roles for cross-account sources or sinks. rdstail never needs database credentials or network access to the database.

Cross-account: in each database account, create a role with the RDS read actions above, trusting the rdstail account. Then set assume_role on that account's source. For a central log bucket, set assume_role (+ external_id) on the S3 sink.

Credentials

rdstail uses the standard AWS SDK chain. Prefer platform roles over keys:

Platform Use
EC2 instance profile. In Docker on EC2, set the metadata hop limit to 2: aws ec2 modify-instance-metadata-options --instance-id i-… --http-put-response-hop-limit 2
EKS IRSA (service-account annotation) or EKS Pod Identity
ECS / Fargate task role
Elsewhere AWS_PROFILE with a mounted ~/.aws, or short-lived env credentials

Choose a runtime

systemd (VM / EC2)

sudo useradd --system --home /var/lib/rdstail --shell /usr/sbin/nologin rdstail
sudo install -d -o rdstail -g rdstail -m 0750 /var/lib/rdstail
sudo install -d -m 0755 /etc/rdstail
sudo cp rdstail.yaml /etc/rdstail/config.yaml          # state.path: /var/lib/rdstail/state.db
sudo curl -fsSLo /etc/systemd/system/rdstail.service \
  https://raw.githubusercontent.com/avinash-gupta-rdz/rdstail/main/deploy/rdstail.service
sudo systemctl daemon-reload && sudo systemctl enable --now rdstail
journalctl -u rdstail -f

The shipped unit runs as rdstail, restarts on failure and is hardened (ProtectSystem=strict, NoNewPrivileges, write access only to /var/lib/rdstail). Edit Environment=AWS_REGION=… to match your region. Secrets for ${VAR} expansion go in a drop-in:

sudo systemctl edit rdstail
# [Service]
# EnvironmentFile=/etc/rdstail/secrets.env      (chmod 600, owned by root)

Docker / Compose

services:
  rdstail:
    image: ghcr.io/avinash-gupta-rdz/rdstail:0.5.0
    volumes:
      - ./rdstail.yaml:/etc/rdstail/config.yaml:ro
      - rdstail-state:/home/nonroot          # state.path: /home/nonroot/state.db
    environment: [AWS_REGION]
    ports: ["127.0.0.1:9090:9090"]
    restart: unless-stopped
    stop_grace_period: 40s                   # > runtime.shutdown_timeout (30s)
volumes:
  rdstail-state:

A complete stack with search and alerting: Loki + Grafana recipe.

Kubernetes

One replica, Recreate strategy (two pods must never share a state file), a ReadWriteOnce volume for state, and IRSA for credentials.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: rdstail
  namespace: logging
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/rdstail
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rdstail
  namespace: logging
data:
  config.yaml: |
    sources:
      - type: rds
        region: us-east-1
        discover: {all: true, exclude_tags: {rdstail: "off"}, refresh_interval: 5m}
    sinks:
      - name: archive
        type: s3
        s3: {bucket: my-log-bucket, region: us-east-1, prefix: rds/}
    state: {type: sqlite, path: /var/lib/rdstail/state.db}
    runtime: {poll_interval: 10s, poll_interval_max: 5m, checkpoint_retention: 168h}
    metrics: {enabled: true, listen: ":9090"}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rdstail-state
  namespace: logging
spec:
  accessModes: [ReadWriteOnce]
  resources: {requests: {storage: 1Gi}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rdstail
  namespace: logging
spec:
  replicas: 1                      # never more: rdstail is not clustered
  strategy: {type: Recreate}       # old pod releases the volume before the new one starts
  selector: {matchLabels: {app: rdstail}}
  template:
    metadata:
      labels: {app: rdstail}
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9090"
    spec:
      serviceAccountName: rdstail
      terminationGracePeriodSeconds: 40
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
        fsGroup: 65532             # makes the PVC writable for the nonroot user
      containers:
        - name: rdstail
          image: ghcr.io/avinash-gupta-rdz/rdstail:0.5.0
          args: ["run", "-c", "/etc/rdstail/config.yaml"]
          ports: [{name: metrics, containerPort: 9090}]
          readinessProbe: {httpGet: {path: /readyz, port: metrics}, periodSeconds: 10}
          livenessProbe: {httpGet: {path: /healthz, port: metrics}, periodSeconds: 30}
          resources:
            requests: {cpu: 50m, memory: 64Mi}
            limits: {memory: 512Mi}
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities: {drop: [ALL]}
          volumeMounts:
            - {name: config, mountPath: /etc/rdstail, readOnly: true}
            - {name: state, mountPath: /var/lib/rdstail}
            - {name: tmp, mountPath: /tmp}     # scratch space under a read-only root
      volumes:
        - {name: config, configMap: {name: rdstail}}
        - {name: state, persistentVolumeClaim: {claimName: rdstail-state}}
        - {name: tmp, emptyDir: {}}

The health probes are served by the metrics server, so keep metrics.enabled: true. Secrets for ${VAR} expansion come from a Secret via envFrom. For more than 500 databases, run one Deployment per shard, each with its own PVC and --shard i/n (see Scaling).

ECS / Fargate

Same shape: one task (desired count 1, minimum healthy 0 % so deploys stop the old task first), the task role for credentials, and an EFS volume is not suitable for SQLite. Use an EBS volume attached to the task, or accept a fresh start (start_from: end) on each new task.

State and backups

state.db (SQLite, WAL mode) holds per-file checkpoints and the DLQ.

  • Local disk only: EBS, a PVC, a host directory. Never NFS/EFS.
  • One per process. Every shard has its own.
  • Losing it isn't catastrophic. rdstail restarts per start_from (with end, it skips what was written while it was down; with beginning, it re-ships what RDS still retains). Anything parked in the DLQ is lost too.
  • Backups: a nightly copy is enough, and rdstail can keep running: sqlite3 /var/lib/rdstail/state.db ".backup /backup/state-$(date +%F).db".
  • Housekeeping: set runtime.checkpoint_retention: 168h, or run rdstail state gc -c config.yaml --older-than 168h (safe while running).

Upgrades

  1. Read the changelog for the versions you're skipping.
  2. Back up state.db. Schema changes migrate in place on first start, and older versions can't read a migrated file. 0.4.0 introduced schema v2.
  3. Replace the binary or image tag and restart. On SIGTERM rdstail finishes the in-flight write, saves its checkpoint and exits (within runtime.shutdown_timeout, 30 s by default). It resumes exactly where it stopped.
  4. Check rdstail_logs_processed_total is rising and rdstail_dlq_depth is 0.

Rollback = previous binary + the pre-upgrade state.db backup.

Operating the DLQ

A batch that fails a sink after all retries (or gets a 4xx from HTTP) is parked in the state DB, and the pipeline keeps moving. After fixing the sink (credentials, ACLs, endpoint):

rdstail dlq list   -c config.yaml              # what's parked and why
rdstail dlq replay -c config.yaml --dry-run
rdstail dlq replay -c config.yaml              # deletes each batch only after the sink ACKs
rdstail dlq purge  -c config.yaml --yes --id 42   # drop one batch for good

Alert on rdstail_dlq_depth > 0 (Monitoring). It's the one signal that data is waiting for you.

Hardening checklist

  • Platform role, no long-lived keys; policy from rdstail iam-policy
  • Non-root user (default in the image and unit), read-only root filesystem
  • Metrics port not exposed publicly (it has no auth)
  • S3 bucket: block public access, SSE (KMS if required), lifecycle rules, Object Lock for audit logs (guide)
  • HTTP/Kafka sinks over TLS; secrets via ${VAR} from a secret store, not in the YAML
  • Remember the logs themselves contain SQL text, user names and client IPs: treat every destination as sensitive

Go-live checklist

  • rdstail validate -c config.yaml --deep passes on the production host
  • rdstail discover shows exactly the databases you expect
  • Volume and API budget checked (Performance)
  • State on persistent local disk, backed up
  • Prometheus scraping, with the ops alerts loaded
  • Restart test: stop, wait a minute, start, then confirm no gap and no duplicates beyond one batch

Clone this wiki locally