Skip to content

fix(mssql): read descriptions from the right database, honour encryption per driver, bound query timeouts - #32574

Merged
Khairajani merged 25 commits into
mainfrom
fix/mssql-connector-hardening
Sep 23, 2026
Merged

Khairajani merged 25 commits into
mainfrom
fix/mssql-connector-hardening

Conversation

@Khairajani

@Khairajani Khairajani commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #33342

Connector-local fixes from the MSSQL connector audit. Each one is a silent failure today: the run reports success and the metadata is quietly wrong.

What changes

Fix What goes wrong today
Descriptions read from the right database The DB_NAME()-scoped queries ran before the inspector switched, so an ingest-all-databases run documented every database from the previously connected one. Nothing matched, leaving table, column, schema, database and stored-procedure descriptions silently missing.
Encryption honoured per driver setup_ssl only ever applied it to pyodbc, so on mssql+pytds — the default scheme — a service configured to encrypt connected in the clear. pytds has no encrypt switch: it enables TLS only when a CA certificate is supplied, and then always verifies the chain, so trustServerCertificate now drops the host-name check alone. Encrypt with no CA certificate warns instead of lying about it; mssql+pymssql, which takes no TLS parameters at all, warns too.
Query timeouts bounded No driver had a query bound and the shared builder sets none, so a hung read stalled a workflow forever. Each now gets one (pyodbc's is a connection attribute, not a connect keyword), applied to a copy of the connection so a stored service connection never gains a timeout nobody configured, plus pool_pre_ping. The default is 12h — the profiler's own timeoutSeconds budget — so it rules out only the wait that never ends; timeout in connectionArguments tightens it per service.
Unique constraints ingested The dialect method raised NotImplementedError, which the catalogue swallows, so they were dropped for every table.
Indexed views typed as materialized views They are persisted and engine-maintained, but were reported as plain views.
Docs Mssql.md and the schema descriptions now state the per-driver encryption behaviour and the timeout default.

Files outside mssql/

File Why
utils/ssl_manager.py Every edit is inside the MssqlConnection dispatch branch. The only shared file here — worth a deliberate look.
ssisConnection.json, wherescapeConnection.json, serviceConnection.json, generated .ts Two description strings, fanned out because SSIS and WhereScape embed the MSSQL connection schema. Machine-generated.
tests/unit/test_source_connection.py Two methods in that class were both named test_mssql_url (hence the # noqa: F811), so the first never ran. Merged into the survivor; its database=None case could not be revived, as the schema has since made the field required.

Testing

The container suite gains a second database with descriptions at all five levels, a unique constraint and an indexed view, so anything read per database is exercised against more than one. test_reflection.py asserts what the source reads straight from SQL Server (no OpenMetadata server needed) and test_metadata.py asserts the catalogue side. Every new assertion was checked to fail with its fix reverted.

Two calls I would like a second opinion on

  1. Warn, or fail hard? The pytds/pymssql encryption mismatch currently warns, which keeps existing runs working. Refusing to connect is defensible — say the word.
  2. The pyodbc timeout changes behaviour on upgrade. There timeout is the login timeout, so a service that already sets it had unbounded queries; it now bounds queries at the same value. If you would rather keep the two separate, I will move the query bound to its own key.

Not included, deliberately

The shared builders.py timeout/retry and pool bound, four-part name resolution in sql_lineage.py, ownership, and the resultLimit docs — each wants its own PR.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the latest changes resolve the remaining test-quality concern without introducing a new actionable issue.

Summary

This PR corrects several silent MSSQL ingestion failures and strengthens their coverage.

  • Switches inspectors before loading database-scoped descriptions.
  • Applies driver-appropriate encryption handling, bounded query timeouts, and pool pre-ping.
  • Reflects unique constraints and reports indexed views as materialized views.
  • Updates schemas, generated artifacts, connector documentation, and integration coverage.
  • Since the previous review, rewrites timeout tests to exercise real SQLAlchemy engines instead of mocked factory wiring.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[MSSQL service connection] --> B{Driver}
    B -->|pyodbc| C[ODBC TLS switches]
    B -->|pytds| D[CA-backed TLS parameters]
    B -->|pymssql| E[Warn when connector TLS settings cannot be applied]
    C --> F[Engine with pre-ping]
    D --> F
    E --> F
    F --> G{Query timeout mechanism}
    G -->|pyodbc| H[DBAPI connect listener sets connection.timeout]
    G -->|pytds or pymssql| I[Connect argument supplies socket timeout]
    F --> J[Switch inspector to target database]
    J --> K[Load database-scoped descriptions]
    K --> L[Reflect tables, unique constraints, procedures, and views]
    L --> M[Classify indexed views as materialized views]
Loading

Reviews (10) · Last reviewed commit: "test(mssql): assert the engine's behavio..."

…ion per driver, bound query timeouts

Descriptions are read per database through DB_NAME()-scoped queries, but the
maps were loaded before the inspector switched, so in an ingest-all-databases
run every database was documented from the previously connected one, which no
lookup can match. The maps now load after the switch.

setup_ssl only ever applied encryption to pyodbc. pytds, the default scheme, has
no encrypt switch: it enables TLS only when a CA certificate is supplied, and
then always verifies the chain, so trustServerCertificate can drop the host name
check alone - which it now does. Encrypt with no CA certificate cannot be
honoured by that driver, and warns instead of connecting in the clear while the
configuration claims otherwise. pymssql, which takes no TLS parameters at all,
warns as well.

pytds and pymssql default to no socket timeout and pyodbc to no query timeout,
and the shared engine builder sets neither, so a hung read stalled a workflow
indefinitely. Each driver now gets a ten minute bound, applied to a copy of the
connection so that a stored service connection never gains a timeout nobody
configured, and engines are built with pre-ping.

Unique constraints were dropped for every table: the dialect method raised
NotImplementedError, which the catalogue swallows. They are now read from
INFORMATION_SCHEMA alongside the primary keys the dialect already reads.

Indexed views are persisted and kept up to date by the engine, so they are
reported as materialized views rather than plain views.

The container suite gains a second database, descriptions at every level, a
unique constraint and an indexed view, so what is read per database is exercised
against more than one of them. The shadowed duplicate of test_mssql_url asserted
a connection with no database, which the schema has since made required, so it
is removed rather than revived.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit c8abf6122c271b3680e6b0c1c6b45ab3b3b71b95 in Playwright run 35850390000, attempt 1.

✅ 4556 passed · ❌ 0 failed · 🟡 9 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 53m 56s

⏱️ Max setup 5m 32s · max shard execution 21m 35s · max shard-job elapsed before upload 24m 58s · reporting 25s

🌐 224.66 requests/attempt · 2.23 app boots/UI scenario · 47.10% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 47.1% (convergence target: at most 15%).
  • Browser traffic was 224.66 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10833 boots / 4864 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 65 0 0 0 0 0
✅ Shard advanced-search-02 65 0 0 0 0 0
✅ Shard chromium-01 127 0 0 0 0 0
✅ Shard chromium-02 141 0 0 0 0 0
✅ Shard chromium-03 169 0 0 0 0 0
✅ Shard chromium-04 133 0 0 0 0 0
🟡 Shard chromium-05 149 0 1 0 0 0
✅ Shard chromium-06 188 0 0 0 0 0
✅ Shard chromium-07 152 0 0 0 0 0
🟡 Shard chromium-08 143 0 1 0 0 0
✅ Shard chromium-09 173 0 0 0 0 0
✅ Shard chromium-10 162 0 0 0 0 0
✅ Shard chromium-11 143 0 0 0 0 0
✅ Shard chromium-12 146 0 0 0 0 0
✅ Shard chromium-13 203 0 0 0 0 0
🟡 Shard chromium-14 192 0 1 0 0 0
✅ Shard chromium-15 140 0 0 0 0 0
✅ Shard chromium-16 151 0 0 0 0 0
✅ Shard chromium-17 176 0 0 0 0 0
✅ Shard chromium-18 145 0 0 0 0 0
✅ Shard chromium-19 190 0 0 0 0 0
✅ Shard chromium-20 159 0 0 0 0 0
✅ Shard chromium-21 140 0 0 1 0 0
✅ Shard chromium-22 144 0 0 0 0 0
✅ Shard chromium-23 171 0 0 0 0 0
🟡 Shard chromium-24 180 0 3 0 0 0
🟡 Shard chromium-25 163 0 3 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 22 0 0 0 0 0
✅ Shard import-export-02 70 0 0 0 0 0
✅ Shard import-export-03 58 0 0 0 0 0
✅ Shard ingestion-01 65 0 0 0 0 0
✅ Shard ingestion-02 35 0 0 0 0 0
✅ Shard reindex-01 40 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 9 flaky test(s) (passed on retry)
  • Features/AIMode/CustomPropertiesPanel.spec.ts › deletes a custom property via the confirmation modal (shard chromium-05, 1 retry)
  • Features/ActivityFeed.spec.ts › emoji reactions can be added and toggled off on a feed card (shard chromium-08, 1 retry)
  • Features/ContextCenterDashboard.spec.ts › Create > Quick Link creates a quick link that appears in the Articles pillar card recent list (shard chromium-14, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-24, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should perform CRUD and Removal operations for database (shard chromium-24, 1 retry)
  • Features/MultipleRename.spec.ts › Classification - should handle multiple consecutive renames (shard chromium-24, 1 retry)
  • Features/Announcements/AnnouncementEntity.spec.ts › creates an announcement on a domain (shard chromium-25, 1 retry)
  • Pages/CustomProperties.spec.ts › Should clear search and show all properties for metric in right panel (shard chromium-25, 1 retry)
  • Pages/Domains.spec.ts › Multiple consecutive domain renames preserve all associations (shard chromium-25, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@Khairajani Khairajani added safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

Ten minutes was picked for metadata and query-log reads, but every workflow
builds its engine through the same connection: the profiler and data quality
reach _get_client through get_ssl_connection too, and the profiler's own default
budget is 12 hours per table. A ten minute socket bound on pytds and pymssql -
where the wait for the first byte is the server-side execution time - would have
failed profiling runs that are working as designed.

The bound now matches that budget, so it rules out only the wait that never
ends, which is the failure it exists for; a dead pooled connection is still
caught far sooner by pre-ping. Tightening it per service through `timeout` in
connectionArguments is unchanged and documented.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/) have been automatically updated based on JSON schema
changes in this PR.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

Khairajani and others added 9 commits September 22, 2026 00:47
pyodbc spends `timeout` on the login, so a service that set one still ran its
queries against the 12 hour default - the opposite of what setting it means.
The listener now takes the configured value when there is one, and the docs say
that on pyodbc the single value bounds both.

The description-ordering tests asserted the order of three mocked calls, which
holds whether or not the load reads the database it was meant to. They now
record which database the connection pointed at when each load ran and assert
that against the database being ingested, so reverting the fix fails them with
the symptom it causes: the entry-point database read first, then each database
read from its predecessor.
…a server

The catalogue assertion read table.tableConstraints straight off get_by_name,
but tableConstraints is not a default field - TableRepository returns null for
it unless it is named in fields - so the composite UNIQUE looked missing when it
had in fact been ingested.

The gap that let that read as a connector failure is that nothing covered the
step between reflection and the entity, so add it to the server-free suite:
get_columns_and_constraints against the container, asserting the single-column
UNIQUE lands on the column and the composite one on the table.
The per-driver encryption behaviour was argued from the drivers' source and
asserted at the level of connection arguments, which cannot show what actually
travels on the wire. sys.dm_exec_connections.encrypt_option can, so ask it:
with Encrypt Connection on and no CA certificate, both pytds and pymssql report
FALSE, and the connector's warning is what the user gets instead.

pyodbc is left out deliberately. It needs Microsoft's ODBC driver, which the CI
runners no more install than a dev machine does - unixodbc-dev is the manager,
not a driver - so a connection test there could only ever skip. The part this
connector owns, Encrypt and TrustServerCertificate reaching the connection
arguments, is already covered in the unit suite.
Installing Microsoft's ODBC driver makes the pyodbc half of the matrix
runnable, and the server confirms it: Encrypt plus TrustServerCertificate
gives encrypt_option TRUE, which is the claim that pyodbc is the one scheme
able to enforce encryption against a certificate OpenMetadata was given
nothing to verify. It skips where the driver is absent, which includes CI.
Khairajani and others added 4 commits September 23, 2026 18:28
sys.extended_properties.value is sql_variant, and FreeTDS hands that back as
bytes where the other drivers return text, so every table description ingested
through mssql+pymssql arrived as b'...' - the repr of a bytes object reaching
the catalogue, or a validation failure. The database, schema and stored
procedure queries already cast it; the table one did not.

Found by running the source end to end against a real server once per driver,
which is also why the regression test builds a pymssql source: the container
suite only ever exercised pytds, so no driver-specific difference could show.
The guard skipped only when no ODBC driver at all was registered, but the
connection asks the driver manager for the schema's default by name. A machine
carrying some other driver - FreeTDS, which this connector supports - would
therefore have run the test and failed during connection setup instead of
skipping. It now reads that name from the schema rather than repeating the
literal, and says which driver is missing when it skips.
The pre-ping and query-timeout tests mocked the engine factory and read back the
arguments it was called with, so they would have stayed green had the engine
stopped applying either. SQLAlchemy resolves a dialect and builds a pool without
opening a socket, so the connector can be driven for real: the assertions now
read pre-ping off the pool, and fire the engine's own connect listener to see
the bound a fresh connection comes away with.

All three fail when the behaviour is removed, which is what they could not do
before.
@gitar-bot

gitar-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · MSSQL driver TLS handling changes encryption and certificate-validation behavior

Hardens the MSSQL connector by reading descriptions after switching to the target database, applying driver-specific encryption configuration, bounding query timeouts to 12 hours, and reflecting unique constraints and indexed views. Resolved socket timeout handling on pytds/pymssql and pyodbc driver matching in tests.

✅ 2 closed
✅ Edge Case: Default 600s socket timeout may break long healthy reads on pytds/pymssql

📄 ingestion/src/metadata/ingestion/source/database/mssql/connection.py:145-159
with_default_query_timeout sets timeout for pytds/pymssql, which those drivers apply as a per-read socket timeout. A legitimately long metadata/lineage read on a large catalogue (e.g. a query-log or reflection call whose first bytes take >10 minutes to arrive) will now fail where it previously succeeded, since no timeout existed before. This is an intentional, documented, and user-overridable trade-off, but worth confirming 600s is comfortably above the slowest expected healthy read; consider a larger default if very large SQL Server estates are in scope.

✅ Edge Case: pyodbc skip guard accepts any ODBC driver, not the one the test uses

📄 ingestion/tests/integration/sql_server/test_encryption.py:94-99 📄 ingestion/tests/integration/sql_server/test_encryption.py:102-115
_no_odbc_driver() only skips when pyodbc.drivers() is empty. The test builds the connection without a driver, so it falls back to the schema default "ODBC Driver 18 for SQL Server". A machine with some other ODBC driver installed (FreeTDS, which this connector already supports for data diff, or a PostgreSQL/SQLite driver) will run the test anyway and fail with a driver-not-found error. The docstring says the test should skip in that case. The fix is to skip unless that specific driver is registered.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSSQL: audit found five silent failures in metadata ingestion and connection setup

3 participants