Skip to content

Secrets & Config

skynet-dealer loads runtime configuration from AWS at import time via fs_config (src/dealer/config/cfg.py). Select the environment with ENVIRONMENT (prd default, stg or local for development). No database or queue credentials are stored in the repository.

Reused shared secrets (AISD-14 — do not duplicate)

Value Store Path
RabbitMQ connection Secrets Manager /<env>/shared/rabbitmq
Redis connection Secrets Manager /<env>/shared/redis

Dealer-specific MySQL secret (deliberate deviation)

Value Store Path
MySQL (skynet_harvester, snh_remote_user) Secrets Manager /<env>/skynet-dealer/mysql

Dealer does not reuse the shared /<env>/mysql/skynet-harvester secret: that secret holds the root credential, while dealer's legacy user is the least-privilege snh_remote_user. Repointing dealer at the shared secret would silently escalate its DB privileges, so least-privilege wins over reuse here.

Dealer-specific SSM parameters

Value Store Path
Queue names (queue, buffer, tasks) SSM String (JSON) /<env>/skynet-dealer/rabbitmq-queues
Preprod queue names SSM String (JSON) /<env>/skynet-dealer/rabbitmq-queues-preprod
Local-dev queue names (dealer-dev, ...) SSM String (JSON) /stg/skynet-dealer/rabbitmq-queues-dev
Redis db index SSM String (int) /<env>/skynet-dealer/redis-db

Rule of thumb: passwords and usernames are secrets (Secrets Manager). Queue names and Redis db index are config (Parameter Store).

Example queue JSON (/<env>/skynet-dealer/rabbitmq-queues)

Staging:

{"queue": "dealer-stg", "buffer": "buffer-stg", "tasks": "tasks-stg"}

Production:

{"queue": "dealer-prd", "buffer": "buffer-prd", "tasks": "tasks-prd"}

Preprod (DEALER_VARIANT=preprod on the host):

{"queue": "dealer-preprod", "buffer": "buffer-preprod", "tasks": "tasks-preprod"}

Environment variables

Variable Purpose Default
ENVIRONMENT prd, stg, or local prd
LOCAL_PROD_DB When ENVIRONMENT=local, use prod MySQL only off
DEALER_VARIANT preprod selects the preprod queue SSM param unset

Deploy (scripts/after_install) writes /srv/skynet-dealer/.env — the same convention as skynet-app-api, skynet-sources-harvester, and tiktok-api. run_server.sh sources it (set -a; source .env) before exec'ing the server, mirroring the harvester's execute*.sh wrappers.

Host prerequisite (one-time): the supervisor program for the dealer must invoke the wrapper, not the python entry point directly. Keep the host's existing server arguments exactly as they are — change only the command path (the wrapper passes arguments through):

[program:skynet-dealer]
; before: command=/srv/skynet-dealer/env/bin/python /srv/skynet-dealer/src/dealer/server.py <existing args>
command=/srv/skynet-dealer/run_server.sh <existing args>

Do not invent or "tidy" the argument set while migrating: server.py parses --prod/--rest/--socket with argparse type=bool, so any non-empty value (including false) is truthy, and --prod <x> without --rest/--socket matches no branch — the process starts no server and exits 0.

Without the wrapper, ENVIRONMENT is unset at runtime and cfg.py defaults to prd — a staging host would read production secrets. Verify after the first deploy with supervisorctl status plus a /health check.

Provisioning (done for AISD-24; reference for re-creation only)

All required AWS resources exist as of the AISD-24 rollout (stg + prd): the shared AISD-14 secrets, the dealer MySQL secret, and the dealer SSM parameters below. Nothing needs to run before a normal deploy.

To verify, read the parameters back:

aws ssm get-parameters --region us-east-1 --names \
  "/stg/skynet-dealer/rabbitmq-queues" "/stg/skynet-dealer/redis-db"

If /<env>/skynet-dealer/mysql ever needs re-creating, use the rotated password (never the value from git history), reading the secret string from a local file so it does not land in shell history:

aws secretsmanager create-secret --region us-east-1 \
  --name "/stg/skynet-dealer/mysql" \
  --secret-string file:///tmp/dealer-mysql.json   # then shred the file

JSON shape: {"host", "port", "user", "password", "database"} with user=snh_remote_user.

To re-create the SSM parameters (values match the legacy settings.*.json):

aws ssm put-parameter --region us-east-1 --name "/stg/skynet-dealer/rabbitmq-queues" \
  --type String --value '{"queue":"dealer-stg","buffer":"buffer-stg","tasks":"tasks-stg"}'
aws ssm put-parameter --region us-east-1 --name "/stg/skynet-dealer/redis-db" \
  --type String --value "1"
aws ssm put-parameter --region us-east-1 --name "/prd/skynet-dealer/rabbitmq-queues" \
  --type String --value '{"queue":"dealer-prd","buffer":"buffer-prd","tasks":"tasks-prd"}'
aws ssm put-parameter --region us-east-1 --name "/prd/skynet-dealer/rabbitmq-queues-preprod" \
  --type String --value '{"queue":"dealer-preprod","buffer":"buffer-preprod","tasks":"tasks-preprod"}'
aws ssm put-parameter --region us-east-1 --name "/prd/skynet-dealer/redis-db" \
  --type String --value "1"

The EC2 instance role needs secretsmanager:GetSecretValue on shared paths and ssm:GetParameter on /<env>/skynet-dealer/* (see SkynetAppConfigSSMRead on SkynetEC2InstanceRole).

Credential rotation

Plaintext RabbitMQ and MySQL passwords were previously committed under settings*.json. Rotate the shared RabbitMQ and harvester MySQL credentials in AWS after deploy; git history may still contain the old values.

Local development

export ENVIRONMENT=local   # resolves stg secrets
export PYTHONPATH=$(pwd)/src
python src/dealer/server.py --port 5001

Requires AWS credentials with read access to staging secrets and SSM.

ENVIRONMENT=local uses the isolated dealer-dev/buffer-dev/tasks-dev queues (/stg/skynet-dealer/rabbitmq-queues-dev), matching the old settings.lcl.json — a local dealer never competes with the staging service for its queues. MySQL defaults to stg; set LOCAL_PROD_DB=1 to point only MySQL at prod.