Skip to content

fix(macos): reuse one Vault database user per profile and wait for a new one to load - #4230

Merged
datlechin merged 2 commits into
mainfrom
fix/vault-lease-reuse-4189
Nov 12, 2026
Merged

datlechin merged 2 commits into
mainfrom
fix/vault-lease-reuse-4189

Conversation

@datlechin

@datlechin datlechin commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A Vault database role signs in as one user per credential profile and role, keyed by the Vault endpoint and the token that read it. Test Source, Test Connection, Connect, reconnects, pooled connections, lanes and backups share it.
  • Before, each sign-in leased a new user and revoked it when the sign-in failed, so a database slow to load users (Vitess here) never accepted one.
  • A MySQL-family 1045 while the lease is younger than 30 seconds dials the same user again after 2, 4 and 8 seconds, then at the 30-second mark. The connection window shows "Waiting for the database to accept the new Vault user", and the connect deadline moves out by the wait.
  • A user still refused when the window closes fails with that reason and stays for the next attempt.
  • A refused sign-in on any engine asks Vault, by renewing the lease, whether it still exists, which is how Vault Agent drops a cached lease. Only a lease Vault no longer has is replaced, and every connection on it signs in again.
  • A MySQL 1045 for a user a server accepted before also stops it being handed out, since Vault renews MySQL users without asking the database. Sessions on it keep it. On other engines, a user dropped in the database stays until every connection on the profile disconnects.
  • VaultLeaseCache owns each lease and hands out holds. A lease is revoked when the last live connection that used it disconnects, after 10 minutes unused, and at quit (up to 3 seconds for Vault). Before, quit left every lease alive until its TTL.
  • A backup tool that takes the password on its command line (SqlPackage) gets a user of its own, revoked when the backup ends.
  • An unattended reconnect stops on a Vault refusal the renewal also treats as final, with Vault's reason. Vault 429, 502, 503, 504 and 500 are retried.
  • SQL Server: a refused login names the server's reason. db-lib hands login messages the handle it is still building, so a failed open said only "Check host, port, credentials, and TLS settings". The reason is now read under loginStartLock. Measured with scripts/probes/check-freetds-login-messages.sh.
  • Refused logins are recognized in SQL Server, Oracle, Redis, Cassandra and Snowflake wording, except SQL Server's script-upgrade and single-user refusals, which pass.
  • A profile-linked connection through a tunnel (SSH, Cloudflare, Cloud SQL Proxy, SOCKS, tunnel command) signs in with its profile. tunneledConnection dropped credentialMode, so it used the connection's own Keychain password.
  • A new profile keeps one id from Test Source to save, so its first connect reuses the tested user. Test Source on an unsaved connection revokes its lease at once.
  • ConnectionFailureClassifier.isAuthenticationFailure replaces DatabaseManager.isAuthenticationFailure, so the driver adapter can call it off the main actor.
  • PluginDriverAdapter.cellValue(for:) moved unchanged to PluginDriverAdapter+CellValue.swift to keep the adapter under SwiftLint's length limits.
  • Tests changed on purpose: VaultDatabaseCredentialsTests "Each sign-in reads a new lease" is now "Sign-ins for one owner and role share one lease"; the revoke-on-release test now revokes through endUse; VaultLeaseOwnershipTests "A driver revokes the lease it signed in with when it disconnects" now hands the lease back to the cache.

Credential profile editor, Vault caption (light, then dark):

Before After
Before, light After, light
Before, dark After, dark

Docs: TableProApp/docs#221 (draft, merges after this one).

Test plan

  • VaultLeaseCacheTests: one read per key, concurrent sign-ins, idle retention, endings reach every hold, a refusal on a revoked, live, or accepted then refused lease, endUse with live and leftover connections, end(), quit revoke, redial delays.
  • VaultLeaseOwnershipTests: a young lease redials until accepted; the window closing gives VaultUserNotLoaded and keeps the user; a PostgreSQL refusal of a revoked lease replaces it; a 1045 after an accepted sign-in replaces it; a 1044 keeps it; a cancel during the wait dials no more.
  • ConnectionFailureClassifierTests: refused logins per engine, SQL Server refusals that pass.
  • VaultDatabaseCredentialsTests (429 and 503 as unreachable, 500 as Vault's failure), ReconnectCredentialRecoveryTests, DatabaseManagerTunnelTests (credential profile through a tunnel), PasswordSourceTestModelTests, PasswordSourceResolverTests, NativeDumpRegistryTests, PluginDriverAdapterConcurrencyTests.
  • scripts/probes/check-freetds-login-messages.sh against the shipped libsybdb.a: OK. verify.sh plugins: PASS.
  • The "before" shots render this branch's sheet with the old caption restored for the shot; nothing else on the sheet changed.

Fixes #4189

…new one to load

# Conflicts:
#	apple/TablePro/Core/Database/NativeDumpService.swift
#	apple/TablePro/Core/Plugins/PluginDriverAdapter.swift
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.

Vault database role: connect fails when a new user takes a few seconds to become active

1 participant