Skip to main content

Collector reference

The collector's CLI surface, file formats, environment and outputs. The complete operational reference, including the security reasoning behind every rule, is apps/collector/README.md.

Commands​

# Build (also builds packages/db)
pnpm --filter @env-sync-viewer/collector... build

# Collect. The default inventory is apps/collector/inventory.json
node apps/collector/dist/main.js [path/to/inventory.json]

# Same thing through turbo, as CI runs it. Args after `--` reach only the collect task
pnpm exec turbo run collect --filter=@env-sync-viewer/collector -- <path>

# Pre-flight: check an inventory against the allowlist, write the filtered inventory
pnpm --filter @env-sync-viewer/collector exec tsx scripts/preflight.ts [inventory.json] [inventory.allow.json]

# Fetch manifests: one Contents API call per repo (needs GH_TOKEN)
bash apps/collector/scripts/fetch-manifests.sh [repo ...]

# Tests (Docker for the Postgres-backed suite)
pnpm --filter @env-sync-viewer/collector test:unit

env-sync invocation​

The collector depends on exactly one contract: env-sync diff --format json, schemaVersion: 1. Per selector it runs, with the entry's manifestDir as the working directory:

env-sync diff --service <name> --env <env> --format json # one per listed service
env-sync diff --all --env <env> --format json # when `services` is omitted

Exit 0 means the document is trusted. Any other exit means stdout is ignored. For everything else env-sync can do, see catesworks/env-sync (currently a private repo).

inventory.json​

A JSON array. Each entry is one (manifest, env) pair that is expected to exist.

[
{ "manifestDir": "../../manifests/orders", "env": "prod", "services": ["api", "worker"] },
{ "manifestDir": "/srv/manifests/billing", "env": "prod" }
]
FieldRequiredMeaning
manifestDiryesDirectory holding secrets.manifest.yml. A relative path resolves against the inventory file's directory
envyesThe --env value. Non-empty, must not start with -
servicesnoOne --service invocation per name. Omit for one --all invocation, only if every service is deployed to env
platformsoutputWritten only by the pre-flight. The pre-flight rejects an input that carries it, so a credential scope can't be forged

inventory.allow.json​

A JSON array of records, exactly these six keys, one per (repo, service):

{
"repo": "orders",
"service": "api",
"platforms": ["caprover"],
"captainDomain": "captain.example.com",
"source": "app-secrets/orders/api",
"appName": "orders-api"
}

repo is the basename of the entry's manifestDir. A duplicate repo/service is an error. platforms may only name platforms with a credential rule, which today means caprover only.

Pre-flight​

A service passes only if it exists in the manifest, its source matches the record exactly, it has no unknown service-level fields, and every target passes, in this order:

  1. dotenv targets are always rejected.
  2. The platform must have a credential rule (src/platform-rules.ts).
  3. The platform must be in the record's platforms.
  4. No target field outside the platform's known set. For CapRover: platform, captainDomain, appName, read_only, non_diffable.
  5. The identity check: for CapRover, captainDomain and appName equal the record's.

The manifest is parsed with a verbatim copy of env-sync's own YAML parser, so both read the same text the same way.

OutputContent
$RUNNER_TEMP/inventory.filtered.jsonone entry per kept selector, absolute manifestDir, plus platforms
$RUNNER_TEMP/preflight.droppedone dropped name per line (<repo>/<service> or <repo>/--all)
stdoutone ::error::pre-flight dropped ... per drop, then an N entries kept summary
$GITHUB_OUTPUTdropped=<N>, when that variable is set

Without RUNNER_TEMP it writes to the OS temp directory. An --all entry is all-or-nothing: every service in the manifest must pass or the entry is dropped.

Environment​

The collector process reads:

VariablePurpose
DATABASE_URLlogin role that is a member of collector. Never passed to env-sync
CIwhen set, enables the exit-2 guards
PATHmust find env-sync (also used by the probes)
OP_SERVICE_ACCOUNT_TOKEN, ENV_SYNC_CONNECT_HOST/_TOKEN/_VAULTSforwarded to every child
CAPROVER_ADMIN_PASSWORD, CAPROVER_ALLOWED_DOMAINSforwarded only to children scoped to caprover

Each env-sync child gets an explicit environment. Nothing is inherited:

  • Base floor: PATH, LANG, LC_ALL, TZ (each only if set), OP_SERVICE_ACCOUNT_TOKEN, ENV_SYNC_CONNECT_HOST, ENV_SYNC_CONNECT_TOKEN, ENV_SYNC_CONNECT_VAULTS.
  • Platform credentials for the entry's platforms only.
  • HOME, XDG_CONFIG_HOME, TMPDIR: a fresh, empty, 0700 temp directory, removed afterwards.
  • ENV_SYNC_ALLOWED_PLATFORMS: the comma-joined scope, set last so nothing can override it. An unscoped entry (a local run that skipped the pre-flight) gets it empty, which env-sync treats as "allow nothing".
  • Never: DATABASE_*, NODE_OPTIONS, GITHUB_*, RUNNER_*, CI, DEBUG, OP_CONNECT_*, AWS_*, ENV_SYNC_AWS_*, USER/USERNAME, or anything else unlisted.

Outputs​

Everything lives in the env_sync schema.

TableOne row perKey columns
collector_runsenv-sync invocationid, started_at, completed_at, outcome, error_summary
drift_snapshots(run, service, env, target)collector_run_id, service, env, target_platform, target_descriptor, diff_mode, status, target_error
drift_snapshot_keyskey in a target snapshotsnapshot_id, key, key_status, expected_fingerprint, actual_fingerprint

Constraints: outcome is success/partial/failed; diff_mode is fingerprint/presence; status is ok/error; key_status is one of MATCH, DRIFT, MISSING_FROM_1PASSWORD, PRESENCE_PRESENT, PRESENCE_MISSING, NON_DIFFABLE. Fingerprints are 12 lowercase hex characters, or null for presence-mode keys.

Outcomes​

CLI resultoutcomeSnapshot rows
exit 0, no service or target errorssuccessone per target, one key row per key
exit 0, some services[].error or target errorpartialsame, with errors in error_summary/target_error
non-zero exit, invalid JSON, or schemaVersion ≠ 1failednone
an ENV_SYNC_ALLOWED_PLATFORMS refusal anywhere in the outputfailednone. error_summary starts ENV_SYNC_ALLOWED_PLATFORMS guard refused:
exit 0 but the database rejects the documentfailednone (rolled back, then the failed run is written)

dotenv targets are dropped before classification: a central collector cannot observe a file on someone's laptop. Error strings are capped at 2000 characters. That cap is not redaction; the CLI redacts before the collector ever sees the text.