Skip to content

feat(migrate): verified TLS for migrate, and the deploy's expand step over the Access tunnel - #154

Merged
aRustyDev merged 1 commit into
mainfrom
feat/migrate-tls-expand-step
Nov 14, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/migrate-tls-expand-step

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

The second of four staged PRs for the deploy pipeline (#49, ADR-0110 round 29). #153, the version header and the smoke, is merged. The pipeline itself (deploy.yml) is the third PR, and #49 stays open until the last of the four. This PR deploys nothing, and nothing calls the new script yet.

thrust-pg accepts only TLS and has no public endpoint, so the deploy's expand migration needs a TLS client and a route to the database:

  • migrate over verified TLS. DATABASE_SSLMODE is disable (the default, so contract.sh and the CI Docker path are unchanged) or verify-ca; DATABASE_SSLROOTCERT names the CA. verify-ca checks the certificate chain, signature and dates, and skips only the name check, because the deploy reaches thrust-pg through cloudflared access tcp at 127.0.0.1 while the certificate names a host. It never falls back to plaintext (tokio-postgres's default prefer would), and a URL whose sslmode contradicts the setting is refused. The connector is thrust_adapters_postgres::tls, behind the native feature, so it is never built into the Worker. It uses rustls with the ring provider, which the workspace already builds for reqwest.
  • scripts/migrate-ci.sh. Starts cloudflared access tcp with the Access service token in the environment (never argv), waits for the local end, runs a built migrate under verify-ca without the token, and stops the tunnel whatever happens. It refuses a DATABASE_URL that does not point at the tunnel, and never runs migrate when the tunnel is not up.
  • migrate prints the error with its causes. tokio-postgres leaves the cause out of its Display ("error performing TLS handshake", "db error"), so a deploy log would not have said why a connection failed.

Decisions to look at

  • require and verify-full are refused on purpose. Only disable and verify-ca are accepted, so a setting that cannot be honoured is an error and not a quiet downgrade. require (encrypt, verify nothing) is the weakest useful mode and nothing here needs it; say so if you want it.
  • The route is Tunnel + Access with an Access service token, as decided on chore(cd): deploy pipeline per ADR-0110 round 29 (expand, deploy 100 %, smoke, auto-rollback) #49. The Cloudflare API token for the deploy itself (an ADR-0101 deviation) is the third PR.
  • Whether to run migrate at all is the workflow's decision, so deciding that only changed migrations run belongs to the third PR. migrate itself still re-runs all 16 files each time.

Tests

  • 87 hermetic tests in thrust-adapters-postgres/tests/tls.rs: in-memory handshakes between a real rustls server and the client, a matrix over trust, validity and name, a property that no other mode is accepted, and a spy server that shows no plaintext follows a refusal. Certificates are made per run, so no key is committed.
  • 28 cases in .github/scripts/tests/test-migrate-ci.sh (added to the ci-scripts job), each checking the exit status and a message fragment. Run under dash as well as bash.
  • 3 tests in the pg_adapter binary (Docker) against a real Postgres 16 that takes only TLS: the server's own pg_stat_ssl says the session is encrypted, a plaintext client is refused, a wrong CA and an expired certificate are refused, a server with no TLS is refused, and the whole schema migrates over the encrypted connection. They are in the existing opt-in suite, so the default nextest profile is unchanged.
  • Controls: hand mutants of the verifier, the connect path, error_chain and nine of migrate-ci.sh were each caught by at least one test.

The first run of the Docker tests failed two of three. One was the test reading the error's Display, where the cause is only in its source chain; that was a real finding, corrected in the code (error_chain), with the assertion unchanged. The other was a container start-up timeout while the local Docker daemon took 36 seconds to run a trivial container; it passed on re-run, with no timeout changed.

Not verified

  • The route against the real thrust-pg, and that Cloudflare Access accepts the service token. The tunnel route, Access application, service token and migration role are infrastructure-repo work and do not exist yet. The cloudflared variable names come from its local --help, not from a run.
  • cargo deny was not run (not installed here). The new crates are rcgen and its small dependencies, dev-only; CI's deny job audits them.
  • How a different Postgres, or a proxy in front of one, answers when migrate hangs up. Against Postgres 16 it was clean, and migrate ignores the result either way.
  • docs/src/architecture/infra.md now says the script is not called yet and the route has not been run against the real database.

Checks run locally

cargo fmt --all --check, cargo clippy --workspace --all-targets --locked -- -D warnings and the wasm Worker clippy, cargo nextest run --profile ci --workspace, cargo test --doc --workspace, scripts/check-deps.sh, check-topology.sh, check-placement.sh, and both script tests. The rebased tree is what was checked.

Refs: #49

🤖 Generated with Claude Code

… over the Access tunnel

`thrust-pg` accepts only TLS and has no public endpoint, so the deploy's expand migration needs a TLS client and a route. This is
the second of four staged PRs for the deploy pipeline (ADR-0110 round 29); it deploys nothing and nothing calls the new script yet.

migrate (thrust_adapters_postgres::tls, `native` feature only, never the Worker):
- DATABASE_SSLMODE is `disable` (the default, so contract.sh and the CI Docker path are unchanged) or `verify-ca`. `require` and
  `verify-full` are refused on purpose: a setting that cannot be honoured is an error, not a quiet downgrade. DATABASE_SSLROOTCERT
  names the CA; verify-ca needs it and disable refuses it.
- verify-ca is a rustls verifier that checks the chain, signature and dates and skips only the name error, because the deploy
  reaches thrust-pg through `cloudflared access tcp` at 127.0.0.1 while the certificate names a host. It never falls back to
  plaintext (tokio-postgres's default `prefer` would), and a URL whose sslmode contradicts the setting is refused.
- rustls and tokio-rustls with the `ring` provider, which the workspace already builds for reqwest; no aws-lc-rs. rcgen is a
  dev-dependency, so no private key is committed.
- migrate prints the error with its causes (`error_chain`). tokio-postgres leaves the cause out of its Display ("error performing
  TLS handshake", "db error"), so a deploy log would not have said why a connection failed.

scripts/migrate-ci.sh starts `cloudflared access tcp` with the service token in the environment (never argv), waits for the local
end, runs a built `migrate` under verify-ca without the token, and stops the tunnel whatever happens. It refuses a DATABASE_URL
that does not point at the tunnel, and never runs migrate when the tunnel is not up. The test runs under dash as well as bash.

Tests. 87 hermetic tests in thrust-adapters-postgres/tests/tls.rs (in-memory handshakes between a real rustls server and the client:
a matrix over trust x validity x name, a property that no other mode is accepted, a spy server that shows no plaintext follows a
refusal, with controls); 28 cases in .github/scripts/tests/test-migrate-ci.sh, each checking the exit status and a message fragment;
and three tests in thrust-adapters-selfhosted's pg_adapter binary against a real Postgres 16 that takes only TLS (the server's own
pg_stat_ssl says the session is encrypted, a plaintext client is refused, a wrong CA and an expired certificate are refused, and the
whole schema migrates over the encrypted connection). Hand mutants of the verifier, the connect path, error_chain and nine of
migrate-ci.sh were each caught.

The first run of the real-Postgres tests failed two of three. One was the test reading `{e}` where the cause is only in the error's
source chain: that was a real finding, fixed in the code (`error_chain`), with its assertion unchanged. The other was a container
start-up timeout while the local Docker daemon took 36 s to run a trivial container; it passed on re-run, with no timeout changed.

Not verified: the route against the real thrust-pg (the tunnel route, Access application, service token and migration role are
infrastructure-repo work), and that Access accepts the token; the cloudflared variable names come from its local `--help`. The new
dependencies are checked by CI's `deny` job; cargo-deny is not installed locally.

Refs: #49
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​rcgen@​0.14.109610093100100

View full report

@aRustyDev
aRustyDev merged commit a6182ac into main Nov 14, 2026
35 checks passed
@aRustyDev
aRustyDev deleted the feat/migrate-tls-expand-step branch November 14, 2026 05:28
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