Repository navigation
feat(migrate): verified TLS for migrate, and the deploy's expand step over the Access tunnel - #154
Merged
Merged
Conversation
… 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]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-pgaccepts only TLS and has no public endpoint, so the deploy's expand migration needs a TLS client and a route to the database:migrateover verified TLS.DATABASE_SSLMODEisdisable(the default, socontract.shand the CI Docker path are unchanged) orverify-ca;DATABASE_SSLROOTCERTnames the CA.verify-cachecks the certificate chain, signature and dates, and skips only the name check, because the deploy reachesthrust-pgthroughcloudflared access tcpat127.0.0.1while the certificate names a host. It never falls back to plaintext (tokio-postgres's defaultpreferwould), and a URL whosesslmodecontradicts the setting is refused. The connector isthrust_adapters_postgres::tls, behind thenativefeature, so it is never built into the Worker. It uses rustls with theringprovider, which the workspace already builds forreqwest.scripts/migrate-ci.sh. Startscloudflared access tcpwith the Access service token in the environment (never argv), waits for the local end, runs a builtmigrateunderverify-cawithout the token, and stops the tunnel whatever happens. It refuses aDATABASE_URLthat does not point at the tunnel, and never runsmigratewhen the tunnel is not up.migrateprints the error with its causes. tokio-postgres leaves the cause out of itsDisplay("error performing TLS handshake", "db error"), so a deploy log would not have said why a connection failed.Decisions to look at
requireandverify-fullare refused on purpose. Onlydisableandverify-caare 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.migrateat all is the workflow's decision, so deciding that only changed migrations run belongs to the third PR.migrateitself still re-runs all 16 files each time.Tests
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..github/scripts/tests/test-migrate-ci.sh(added to theci-scriptsjob), each checking the exit status and a message fragment. Run under dash as well as bash.pg_adapterbinary (Docker) against a real Postgres 16 that takes only TLS: the server's ownpg_stat_sslsays 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.error_chainand nine ofmigrate-ci.shwere 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
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. Thecloudflaredvariable names come from its local--help, not from a run.cargo denywas not run (not installed here). The new crates arercgenand its small dependencies, dev-only; CI'sdenyjob audits them.migratehangs up. Against Postgres 16 it was clean, andmigrateignores the result either way.docs/src/architecture/infra.mdnow 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 warningsand 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