Skip to content

feat(credentials): saved PostgreSQL, MySQL, and SQL Server connections - #9929

Merged
waleedlatif1 merged 13 commits into
stagingfrom
feat/saved-database-connections
Nov 12, 2026
Merged

waleedlatif1 merged 13 commits into
stagingfrom
feat/saved-database-connections

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Adds saved database connections for PostgreSQL, MySQL and SQL Server under three new service-account provider ids (postgresql-service-account, mysql-service-account, mssql-service-account). A connection stores host, port, database, login and password, plus the SSL mode (or SQL Server's encrypt and trust-certificate settings). It is modeled on the existing Oracle Database credential.
  • Saving runs SELECT 1 through each family's own guarded connection path, so validateDatabaseHost, IP pinning and TLS match a real run. The connection is encrypted only after the database answers. Driver errors are never shown, and there is no connection cache.
  • One list per provider (databaseConnectionFieldIds: the login fields plus the descriptor's TLS fields) says what a saved connection holds. The stored schema picks exactly those fields from the operation's own connection schema, with tighter bounds, and is strict. The tools' credentialSuppliedParams come from the same list. The TLS values and defaults therefore have one source, and the modal's options are keyed by the same value types. A field added to an operation later (like SQL Server's per-block connection timeout) never enters the stored blob and is never pinned by a saved connection.
  • The tools read the connection server-side inside the operation (withSavedDatabaseConnection), bound to the run's workspace or organization. It replaces every connection field in the call, so a caller or model cannot point a shared credential at another host. The three families are wrapped when they are registered (registerSavedDatabaseFamily, like registerAwsFamily). A registry test fails if any tool that names a saved database connection runs outside a wrapped family.
  • New postgresql_v2, mysql_v2 and mssql_v2 blocks offer only the connection picker. The legacy blocks keep their inline inputs and run unchanged; they are hidden from the toolbar and marked as replaced.
  • The Oracle lookup now goes through the shared owner-scoped secret read. Its behavior is unchanged.
  • Out of scope, with design notes: MongoDB, ClickHouse, Neo4j and IAM database auth (RDS, Cloud SQL, Entra).

Compatibility

  • Existing provider ids, stored secrets and legacy blocks are untouched. The new stored blobs keep their v1 shape, and the stored schemas accept the same fields and defaults as before.
  • The 18 postgresql_*, mysql_* and mssql_* tools now declare an optional saved credential. Besides gaining an optional credentialId, their Copilot and v2 schemas no longer list the connection fields (host, port, database, username, password, ssl or encrypt/trustServerCertificate) as required. Those fields are now checked at runtime by enforceCopilotCredentialSelection, which refuses a call that has neither a credentialId nor the inline fields. This is the repo's documented hybrid-tool pattern.

Product update (if relevant)

Workspace and organization admins can save a database connection once in Integrations and share it across workflows and agents, so the password no longer sits in block fields. Setup is documented on the PostgreSQL, MySQL and SQL Server integration pages, including what each TLS mode actually guarantees.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Unit tests in lib/credentials/database-connections/server.test.ts:
    • For each engine, a saved connection round-trips: save proves the exact login with SELECT 1, and a later run gets that login plus the stored TLS defaults.
    • For each engine, a run on a saved connection replaces exactly the params its tools declare as credential-supplied. A block-set SQL Server connection timeout is kept. Revert proof: building the SQL Server stored schema from the whole operation schema, or dropping a TLS field from the declared params, turns it red.
    • Invalid input is refused without connecting, and driver errors are kept out of messages.
    • A call without a credential passes through, and a credential for another service is ignored.
    • These return 403 without running: another engine's row, an organization row, a foreign blob type, an unknown stored field.
    • Abort is honored.
  • Saved-credential version cases were added for all three blocks.
  • lib/internal/tool-operations/registry.server.test.ts: every tool whose provider is a saved-database service is registered in a wrapped family for that service. Revert proof: registering MySQL without the wrapper turns it red.
  • Integration test lib/credentials/__integration__/database-connection.integration.ts runs against real Postgres through the registered postgresql_query operation. It checks that:
    • a valid save is accepted, and a save of a missing database is refused;
    • a run uses the saved connection despite bogus inline fields;
    • runs are refused in another workspace and after revocation.
  • Revert proof: weakening the field override or the service guard turns the matching tests red.
  • Checks run: biome, a type-check of the changed files, block-successors, tool-metadata, deployment-config, docs, boundaries, client-boundary, egress-boundary, tool-registry-boundary, unused-exports, explicit-any, source-conventions, file-names, utils, comment-hygiene, test-patterns, and check-block-registry against staging (saved-credential contract).
  • Reviewers should look at withSavedDatabaseConnection (field override and owner binding) and the TLS hints, which describe Sim's driver mapping:
    • MySQL Required checks the certificate chain but not the host name (like VERIFY_CA), and Preferred never falls back to plaintext.
    • SQL Server Encrypt requests TLS, but tedious continues unencrypted when the server answers NOT_SUP.
    • PostgreSQL Preferred can be downgraded by an on-path attacker.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 12, 2026 4:14pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking findings remain.

Summary

Adds saved PostgreSQL, MySQL, and SQL Server connections with server-side reads and connection pickers.

  • Admins can save verified connections for three SQL databases.
  • SQL tools can run with a saved connection selected for the workflow.
  • New SQL blocks use saved connections while old workflows keep their inline settings.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Connection details] --> B[Check database connection]
  B --> C[Encrypt and save]
  D[Workflow or agent call] --> E[Authorize saved credential]
  E --> F[Check owner and read connection]
  C --> F
  F --> G[Replace connection fields]
  G --> H[Run database operation]
Loading

Reviews (8) · Last reviewed commit: "docs(databases): describe the PostgreSQL..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 58 files

Confidence score: 4/5

  • database-connection.integration.ts ignores the host in TEST_DATABASE_URL, so valid IPv6 test environments may not run reliably. Derive the connection host and egress allowlist from databaseUrl.hostname.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/credentials/__integration__/database-connection.integration.ts">

<violation number="1" location="apps/sim/lib/credentials/__integration__/database-connection.integration.ts:27">
P3: This fixture ignores the host from `TEST_DATABASE_URL`, so valid IPv6 test environments cannot run it reliably. Derive the connection host and the egress allowlist from `databaseUrl.hostname` (and preserve the URL’s bracketed IPv6 form).</violation>
</file>

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 59 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the feat/saved-database-connections branch from 5142237 to 63ff5a5 Compare November 12, 2026 13:27
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 59 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 force-pushed the feat/saved-database-connections branch from 63ff5a5 to b6854c7 Compare November 12, 2026 14:12
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 59 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 60 files

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 60 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

…read

Oracle Database's saved-connection lookup now reads its row through one
owner-scoped helper, so the saved database connections that follow bind
to their owner and provider the same way instead of copying the query.
Adds three service-account providers (postgresql-, mysql-, and
mssql-service-account) that store a database connection: host, port,
database, login, password, and the SSL mode or SQL Server encrypt and
trust-certificate settings. Saving proves the connection with SELECT 1
through each family's own query operation, so host validation and IP
pinning match a real run, and only then encrypts it; driver errors are
never surfaced. The connection is read back inside the tool operation,
bound to the run's workspace or organization, by
withSavedDatabaseConnection, which replaces every connection field in the
call so a caller or model cannot steer a shared credential.

One client-safe descriptor table drives the provider ids, required
fields, provider catalog, token resolvers, secret builders, and a shared
connect modal.
…a saved connection

Every PostgreSQL, MySQL, and SQL Server tool now declares an optional
service-account credential policy (required: false), so its inline
connection fields keep working unchanged and a saved connection can stand
in for them. The executor authorizes the selected credential and passes
it through trusted context; the family's operation handler, wrapped by
withSavedDatabaseConnection, reads the stored connection bound to the
run's owner and replaces every connection field before parsing. The
providers resolve inside the operation, like AWS, so they join
OPERATION_RESOLVED_CREDENTIAL_PROVIDERS.

A real-Postgres integration test saves a connection (SELECT 1 through
the guarded path), refuses one the server rejects, runs a query on the
saved connection whatever fields the call carries, and refuses it to
another workspace and once revoked.
postgresql_v2, mysql_v2, and mssql_v2 spread their legacy blocks and swap
the connection fields (host, port, database, username, password, and SSL
mode or SQL Server encrypt and trust-certificate settings) for a saved
connection picker through withSavedCredential. Their canvas sentences
drop the database clause the block no longer holds.

The legacy blocks change only by hideFromToolbar and a legacy sunset
pointing at the successor, so existing workflows keep their inline
connection fields and run exactly as before. Generated block successors,
docs, icon maps, and deployment metadata are regenerated.
…nnections

Each page's intro now explains adding a saved connection, how Sim proves
it before saving, what every SSL mode or SQL Server TLS setting does in
the runtime's drivers, and that existing workflows keep their inline
connection fields.
…e saved-connection schemas from the operations

- Register the PostgreSQL, MySQL, and SQL Server families through
  registerSavedDatabaseFamily, which applies withSavedDatabaseConnection and
  records each tool id's service. A registry test now fails when a tool that
  names a saved database connection runs outside a wrapped family, the case
  the saved-credential contract skips for operation-resolved providers.
- Build the stored connection schemas from each operation's own connection
  schema (bounds tightened, strict), so the TLS values and defaults have one
  source. Stored blobs decode exactly as before.
- Reuse the SQL Server default connection timeout instead of repeating it,
  and parse a submitted connection once.
- Unit tests prove save-then-run round trips and drive refusals through the
  run wrapper; the workspace and revocation cases stay in the integration
  test, which now runs through the registered operation.
…apply them

- MySQL Required verifies the certificate chain but not the host name (like
  VERIFY_CA), and both Preferred and Required refuse a server without TLS.
- SQL Server Encrypt connection requests TLS; a server that does not support
  encryption gets an unencrypted session rather than an error.
- PostgreSQL Preferred can be downgraded by an on-path attacker, so the hint
  and docs steer to Required when the server supports TLS.
- Picker options are keyed by each operation schema's value type, so a mode
  the operations add or drop fails to compile instead of drifting.
…redential-supplied params from one list

The stored v1 schema now picks exactly the descriptor's login and TLS fields
out of each operation schema instead of extending the whole schema, and the
tools' credentialSuppliedParams come from the same list. An operation field
added later can no longer change the stored blob, get pinned on every run,
or stay visible on the credential-only block.
…carry TLS tradeoffs into the provider catalog

The connection modal now refuses a port that is not a whole number from 1 to
65535 and says so beside the field, instead of a generic verify failure. The
v2 provider catalog hint for saved PostgreSQL, MySQL, and SQL Server
connections now includes each transport-security field's tradeoff, so API
callers see what Preferred, Encrypt, and Trust server certificate give up.
The integration fixture decodes the database name from TEST_DATABASE_URL.
@waleedlatif1
waleedlatif1 force-pushed the feat/saved-database-connections branch from 980a0e5 to 471705c Compare November 12, 2026 16:01
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/internal/mysql/schema.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 60 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 60 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit ef7bc52 into staging Nov 12, 2026
83 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/saved-database-connections branch November 12, 2026 17:01

This branch was previously deployed

1 inactive deployment
Preview — 7ba8f3d3 Deployed Nov 12, 2026 by vercel[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.

1 participant