Skip to content

feat(connections): add reusable credential profiles shared across connections - #2876

Merged
datlechin merged 3 commits into
mainfrom
feat/credential-profiles
Sep 15, 2026
Merged

datlechin merged 3 commits into
mainfrom
feat/credential-profiles

Conversation

@datlechin

Copy link
Copy Markdown
Member

Closes #2853. Builds on #2872, which is already merged.

A credential profile is one username and password that any number of connections point at. Rotating the password is one edit instead of one per connection, which is what the issue asked for.

The shape, and why it is not the SSH profile's

#2853 says to follow the reusable SSH profiles pattern. #2872 explains why that pattern is the wrong model to copy: it freezes the non-secret half into each connection and resolves only the secrets live, so a profile edit never reaches a linked connection's host or username.

So the link is DatabaseConnection.credentialMode = .inline | .profile(id:) with no snapshot, and the username is kept current by a write-through fan-out in CredentialProfileStorage.updateProfile.

The write-through is load-bearing rather than a convenience. connection.username is read raw by the AWS IAM signer, the ~/.pgpass lookup, NativeDumpRegistry's -U / -u / --username= flags, ExternalConnectionTrustKey and the connection record pushed to iCloud. Blanking it for a linked connection would have pushed an empty username over the good value on a second Mac, because SyncRecordMapper writes connection.username on every connection sync while the new profile record is still inert. ConnectionCredentialResolver.resolveUsername covers the window before a fan-out has run.

Storage

credentialProfiles.json sits beside connections.json and is HMAC-stamped by the same key, not in UserDefaults where SSH profiles live. A credential profile can declare a PasswordSource.command(shell:), and that tag is the only thing between an attacker-writable file and a command this Mac never agreed to run. ConnectionCredentialResolver checks CredentialProfileStorage.storeIsTrusted before running one, exactly as it checks ConnectionStorage.storeIsTrusted for a connection's own.

IntegrityStampedFileStore<Element: Codable> is that read-verify-adopt and write-stamp cycle, extracted from ConnectionStorage rather than copied. ConnectionStorage adopts it in this PR, so there is one implementation to be right. Its load is three-valued on purpose: a file that will not decode is not an empty list, and saving over it would destroy what it held.

The Keychain prefix is com.TablePro.credprofile., not com.TablePro.password.<profileId>. #2872 has the measurement: iOS sweeps that prefix and deletes any item whose trailing UUID is not a saved connection, and a profile id never is one.

What a profile carries

Username, and the password as one of four modes: stored in the Keychain, asked for every time, ~/.pgpass, or a PasswordSource (file, environment variable, command output, 1Password, Vault, AWS Secrets Manager). Plus the plugin-declared secure fields an engine needs beyond a password, such as an AWS secret access key.

There is deliberately no database type on the profile. DatabaseDriverFactory.buildAdditionalFields already loops over secureConnectionFieldIds(for: connection.type), so a connection reads only the fields its own type declares and one profile can carry several engines' keys without a type constraint.

"Ask every time" asks once per profile per launch, not once per connection: DatabaseManager.promptedPasswords is keyed by ConnectionCredentialResolver.promptCacheKey, which is the profile when there is one.

UI

A new Profiles pane in Settings lists both kinds in one place, with the name, a summary and how many connections use each. Before this, profiles of either kind were reachable only from three small buttons inside a connection form's Network tab, with no list anywhere and no way to see what depended on one.

The connection form's Authentication section opens with a Credentials picker. Enter Below comes first so the menu is never empty and keeps today's behavior. Picking a profile replaces the username and password rows with a read-only summary. Save These as a Profile… promotes what is already filled in.

The Settings window goes from 720 to 800 points wide. Measured: eleven pane labels total 447pt of text, and a twelfth at the 20-24pt per-item padding a .preference toolbar uses puts twelve items at 726-774pt, which is an overflow chevron at 720.

Safety

  • Linking deletes the connection's own Keychain password. Leaving it behind means an encrypted export still carries it and a duplicate copies it.
  • Duplicate Connection copies the link, not the secret.
  • Deleting a profile hands each connection the username and password as its own, and refuses without changing anything when those secrets cannot be read.
  • Two profiles cannot share a name, since every picker offers them by name alone.
  • The PasswordSource payload never enters a CKRecord. A profile using one arrives on a second Mac set to ask instead.

Sync

SyncRecordType.credentialProfile and CredentialProfileSyncField are declared with an empty verifiedInProduction, exactly as FavoriteDatabase is, and SyncSchemaGateTests.pendingProductionDeploy lists it. The type is inert: CloudKitSyncEngine.push withholds it and the parity suites pass because its rawValue is absent from CloudKit/production-schema.ckdb.

Profiles do not sync yet, and the docs say so. The coordinator's push, pull and tombstone arms land in PR 3 alongside the schema flip. What this PR does carry is the one sync change the feature cannot ship without: applyRemoteConnection preserves the local credentialMode, because a connection record has no field for it and a remote update would otherwise decode as .inline, unlink the connection, and leave it with no password at all.

Review

Two reviewers read this diff.

swiftui-pro found seven, two of them behavioural: the Picker had no tag matching a missing profile, so a connection bound to a profile this Mac does not have rendered as nothing selected; and the editor decoded the whole profiles file four times per body pass, which is once per keystroke, because IntegrityStampedFileStore.load() has no cache. The rest were accessibility identifiers, a stale list when a profile is created from a connection window, and the secure-field type opening on MySQL whatever the connection was.

Codex found seventeen, nine of them P1, and all are fixed. The ones worth naming:

  • An untagged credentialProfiles.json was adopted and stamped, which would sign a planted command-backed profile and mark it trusted. adoptsUnstamped is now opt-in and only connections.json has the pre-tag history that justifies it.
  • Any remote connection update silently dropped the profile link, and linking has already deleted the connection's password.
  • A mistyped ask-every-time password was cached before the connect, locking out every connection on that profile until relaunch.
  • Unlinking a .source or .pgpass profile left its connections with nothing, because only a stored password was carried across.
  • A locked Keychain plus an unrelated rename deleted the profile's secrets. secretsWereReadable is the same tri-state fix(connections): apply SSH profile edits and deletes to the connections that use them #2872 introduced for the connection form, applied here.
  • Keychain write failures were ignored, so a rotation could report success while keeping the old secret.
  • SyncSchemaGateTests broke deterministically, which I had not run.

Skill(security-review) then found two High-severity issues, both the same shape: a .command(shell:) from an untrusted profiles file being laundered into a trusted store. Both are fixed and pinned by tests.

  • unlinkConnections copied a profile's passwordSource onto each connection, and connections.json re-stamps itself trusted on the next save, so deleting an unfamiliar profile was the consent gesture that blessed the command. It now carries a source only from a file TablePro itself last wrote.
  • save() stamped unconditionally, and a profile write is a read-modify-write over the whole list, so renaming your own profile re-signed everything else in the file. userSaveEstablishesTrust separates the two stores: connections.json keeps its documented behaviour where a save clears a tamper flag, credentialProfiles.json persists edits without ever blessing what it did not write.

It cleared the rest: the Keychain prefixes cannot collide, no secret reaches a log or a CKRecord, and the record type is genuinely inert. Its one sub-threshold note is that promptedPasswords is never pruned, so a prompted password outlives a disconnect in memory; it was already cached on the session before this change.

I did not take its suggestion to apply the same save guard to ConnectionStorage.saveConnections. DatabaseManager+TunnelCommand.swift:15-19 documents re-saving a connection in the app as the intended way to clear its tamper flag, so that is a deliberate design outside this feature.

Verification

  • verify.sh build PASS
  • verify.sh test on the suites owning every changed type: 78 cases, 78 passed
  • swift test on the package's sync parity suites
  • verify.sh lint TablePro TableProTests
  • verify.sh docs

New tests: CredentialProfileStorageTests (round trip, write-through, password stored once, delete converting to inline, tombstone ordering, refusing to delete when secrets are unreadable, refusing to overwrite a file that will not decode, the trust tag, duplicate sharing the link) and CredentialProfileSyncTests (inert while unverified, name round trip, and that a password source never survives a trip through CloudKit).

Screenshots are placeholders

docs/images/settings-profiles{,-dark}.png and docs/images/credential-profile-picker{,-dark}.png are placeholders at the right 1560x960, so the page renders. They need a real capture. I launched a sandboxed Debug build to take them and stopped: two TablePro processes were running, one of them the real app, and System Events drives by process name, so the keystrokes could have landed in the wrong one.

Not in this PR

Sync coordinator wiring, export/import, and iOS (PR 3).

@mintlify

mintlify Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 15, 2026, 4:20 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

# Conflicts:
#	CHANGELOG.md
#	TablePro/Core/Database/ConnectionCredentialResolver.swift
#	TablePro/Core/Storage/SSHProfileStorage.swift
#	TablePro/Views/ConnectionForm/ConnectionFormCoordinator.swift
#	TablePro/Views/ConnectionForm/ViewModels/AuthPaneViewModel.swift
#	TableProTests/Core/Storage/SSHProfileStorageTests.swift
@datlechin
datlechin merged commit 715b28c into main Sep 15, 2026
5 of 8 checks passed
@datlechin
datlechin deleted the feat/credential-profiles branch September 15, 2026 04:33

This branch was successfully deployed

1 active deployment
staging - docs — 421177fe Deployed Sep 15, 2026 by mintlify[bot]
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.

Reusable database credential profiles

1 participant