Skip to content

feat(config): type secrets as such and read config from several files - #857

Merged
cjorge-thegraph merged 3 commits into
mainfrom
cjorge/typed-secrets
Nov 23, 2026
Merged

cjorge-thegraph merged 3 commits into
mainfrom
cjorge/typed-secrets

Conversation

@cjorge-thegraph

@cjorge-thegraph cjorge-thegraph commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #848. Instead of _file references and DIPPER__ environment overrides, dipper now knows which fields are secrets by their type, and its configuration can come from several files merged in order.

The problem: dipper read its whole configuration from 1 JSON file, so every secret sat next to settings that are not secret. The file could then only be kept as a secret, out of review. The secret fields were also typed unevenly:

  • The RPC provider URLs, which carry API keys, were plain Urls, and the Kafka sasl_password was a plain String with hand-written redaction.
  • serde quoted a value it could not read in its error, so a mistyped secret ended up in a log: invalid type: string "hunter2-secret", expected u32.

Secrets known by type

  • Hidden<T> (dipper-core) leaves a value it can't deserialise out of the error, and so does the signer key's hex adapter. The error keeps its position.
  • Kafka: the sasl_passwords in dipper-producer are now Hidden<String>. dipper-producer depends on dipper-core for this; it already depended on thegraph-core.
  • SecretUrl (new) is used for chain_client.providers and alerts.slack_webhook_url.
    • Shown: the URL's scheme, host, port and the shape of its path.
    • Masked: the user and password, every query value (its name stays), the fragment, and every path segment but a version such as v2.
    • Fingerprint: when anything was masked, a short keccak fingerprint of the whole URL follows: https://mainnet.infura.io/v3/*** (fingerprint e1d789). 2 log lines can then be told to use the same key or not, without showing it.
    • Why mask every segment: a key can look like any word (/v2/rpc-key), so dipper doesn't guess which segment holds it; the fingerprint is what tells keys apart.
    • Errors: a URL that fails to parse is left out of the error.
    • Code: ChainClientConfig::provider_urls() exposes the real URLs for connecting.
    • Visible change: the startup config dump now shows the webhook's host and its path masked. Before, the whole webhook was hidden, and the providers showed by host only.

Config from several files

  • Usage: dipper-service config.json [secrets.json ...]. Every argument is a file, merged in order: objects key by key, anything else (a string, a number, a list, null) replaced by the later file.
  • Read once: the merged result is deserialised once, so deny_unknown_fields still refuses a misspelt field in any file.
  • Each file is read whole: it holds 1 JSON value and nothing after it, so a stray } that closes the configuration early is refused rather than leaving the later sections unread. A key given twice in 1 object of a file is refused, with 1 file or several.
  • Errors name the field through serde_path_to_error (db.password: …), and leave out any string the field held. A secret given in the wrong shape, such as a provider URL with its key where the list of providers belongs, is not quoted either. A single file still reports its line and column.
  • Failed loads: a missing or unreadable file, or no file at all, exits with code 2 and a usage line rather than a panic.
  • Where secrets live:
    • A test setup keeps everything inline in 1 file.
    • Production keeps config.json free of secrets in the ConfigMap, reviewable in git, and adds a secrets.json holding only the secret fields. That file lives in a Secret, for example one External Secrets renders from the secret store.
  • Docs: k8s/README.md shows the shape of secrets.json and the extra mount and args. It notes that a list (chain_client.providers) is replaced whole, and that a changed secret needs a restart. The main README lists the secret fields.

Dropped from #848

  • _file references
  • the DIPPER__ environment overrides
  • the guessing between JSON and string values

That removes the review's findings on #848: ambiguous types, values in errors, map defaults wiped by an override, unreachable list items, and the UTF-8 panic.

Not done: a startup warning when a secret field sits inline in the 1st file while a 2nd is given, which would catch a secret committed to the ConfigMap. It is easy to add if wanted.

Tests

  • a_rejected_secret_is_left_out_of_the_error (dipper-core) failed on main with the quoted value above, and passes now.
  • SecretUrl: hosted RPC URLs (Alchemy, Infura, Ankr, QuickNode), a word-like key, Slack, user-info, query and fragment, a URL with nothing to mask, fingerprints, Debug/Display, and rejected values.
  • Loader:
    • a secrets file merging into the example config;
    • the same config from 1 file or 2;
    • merge rules;
    • an unknown field in a later file;
    • errors naming db.password and alerts.slack_webhook_url without their values;
    • a secret in the wrong shape (a provider URL where a list belongs, a signing key where the signer's section belongs) left out of the error;
    • anything after the configuration in a file refused;
    • a key given twice in 1 of several files refused, naming that file;
    • a later file that isn't JSON refused, naming it and quoting none of it;
    • line numbers for a single file;
    • no file or a missing file;
    • the logged config masking keys.
  • The existing dump test still finds no rpc-key in the output. The webhook test now checks that the host shows with the path masked.
  • On current main (sqlx 0.9, Rust 1.94): cargo +nightly fmt, cargo clippy --workspace --all-targets --all-features -D warnings and cargo nextest run --all-features (1,284 tests) pass locally.

🤖 Generated with Claude Code

Dipper read its whole configuration from 1 JSON file, so every secret had to sit next to settings
that are not secret, and the file could then only be kept as a secret, out of review. And the
secret fields were typed unevenly: the RPC provider URLs, which carry API keys, and the Kafka
password were plain values, and serde quoted a secret it could not read in the error, which ends
up in a log.

Secrets are now known by type:

- `Hidden<T>` leaves a value it cannot deserialise out of the error, as does the signer key's
  hex adapter, and the Kafka `sasl_password`s become `Hidden<String>`.
- `SecretUrl`, for `chain_client.providers` and `alerts.slack_webhook_url`, shows a URL with its
  scheme, host, port and the shape of its path, masking the user and password, query values,
  the fragment and every path segment but a version such as `v2`, with a short fingerprint
  when anything was masked: `https://mainnet.infura.io/v3/*** (fingerprint e1d789)`. A key can
  look like any word, so dipper does not guess which segment holds it; the fingerprint tells 2
  keys apart. A URL that fails to parse is left out of the error.

The config now comes from every file on the command line, merged in order: objects key by key,
anything else replaced by the later file. The merged result is read once, so an unknown field is
refused wherever it came from, and an error names the field (`db.password: ...`); a single file
still reports its line and column. Secrets can stay inline in 1 file, as a test setup wants, or
go in a later `secrets.json` that holds only the secret fields, kept in a Secret, so the
ConfigMap holds none and can be reviewed. The READMEs and the manifest describe both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cjorge-thegraph and others added 2 commits November 23, 2026 19:43
…ngs out of errors

- A single config file is now read to its end: anything after the configuration, such
  as a stray `}` that closed it early and left later sections unread, is refused, as
  `serde_json::from_str` did before.
- With several files, a key given twice in 1 object of a file is refused, as it is with
  1 file, instead of the last one being used without a word. Later files still merge
  into earlier ones.
- An error about a field no longer repeats a string it held, whatever the field: a
  provider URL with its key given where a list belongs, or a signing key where the
  signer's section belongs, used to be quoted in full.
- The URL fingerprint's doc no longer claims it can't help guess a weak password.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cjorge-thegraph
cjorge-thegraph marked this pull request as ready for review November 23, 2026 20:16
@cjorge-thegraph
cjorge-thegraph merged commit fe92407 into main Nov 23, 2026
13 checks passed
cjorge-thegraph added a commit that referenced this pull request Nov 23, 2026
The writer fence's tests start their Postgres on its Unix socket only, as #861 does
for the rest, and the registry's test databases keep the operator session and the
writer pool on top of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MoonBoi9001 pushed a commit that referenced this pull request Nov 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.4](v0.3.3...v0.3.4)
(2026-11-23)


### Added

* **config:** type secrets as such and read config from several files
([#857](#857))
([fe92407](fe92407))
* **db:** connect to Postgres over TLS
([#847](#847))
([2673181](2673181))
* **db:** let only 1 dipper process write, enforced by the database
([#858](#858))
([6f88900](6f88900))
* **db:** make the database password optional
([#850](#850))
([cb5d3b1](cb5d3b1))
* **metrics:** serve Prometheus metrics and optionally log as JSON
([#851](#851))
([523819e](523819e))
* **rpc:** expose effective indexing targets and chain identity
([#860](#860))
([aafc0ce](aafc0ce))
* **startup:** wait for Postgres and IISA instead of exiting
([#849](#849))
([d1406d4](d1406d4))


### Fixed

* **db:** sslmode=verify-ca skips the hostname check, as libpq does
([#859](#859))
([5fec97d](5fec97d))
* **k8s:** roll dipper out one pod at a time
([#846](#846))
([de57e46](de57e46))
* **shutdown:** stop taking jobs first and fit the teardown in its
budget ([#854](#854))
([a1bc47d](a1bc47d))


### Tests

* run each test's Postgres on its Unix socket only
([#861](#861))
([bc9e2b2](bc9e2b2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@MoonBoi9001
MoonBoi9001 deleted the cjorge/typed-secrets branch November 26, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant