Skip to content

[7.0.3] Fix | Reenable SqlBulkCopy in least-privilege environments#4402

Merged
paulmedynski merged 9 commits into
dotnet:release/7.0from
edwardneal:port-7.0/pr-4306
Jul 6, 2026
Merged

[7.0.3] Fix | Reenable SqlBulkCopy in least-privilege environments#4402
paulmedynski merged 9 commits into
dotnet:release/7.0from
edwardneal:port-7.0/pr-4306

Conversation

@edwardneal

Copy link
Copy Markdown
Contributor

Description

This PR ports #4306 to the 7.0 branch, and this contains the full description.
The automated test uses the RAII primitives, so I've also needed to include these.

Issues

Fixes #4370.
Ports #4306.

Testing

Automated tests ported from #4306, with one addition.

Copilot AI 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.

Pull request overview

Ports the SqlBulkCopy least-privilege fix (guarding sys.all_columns metadata access via HAS_PERMS_BY_NAME) onto the 7.0 branch, along with supporting ManualTests coverage and small shared test RAII primitives.

Changes:

  • Updates SqlBulkCopy initial metadata query to conditionally query sys.all_columns based on permissions.
  • Adds ManualTests coverage for unprivileged SQL logins and adjusts an existing stats-based bulk copy test for the additional query.
  • Introduces shared transient database-object helpers (ServerLogin, DatabaseUser, Table) and a net462-only MemberNotNullAttribute shim for nullable analysis in ManualTests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs Adds HAS_PERMS_BY_NAME gating around sys.all_columns query in the initial metadata SQL batch.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/UnprivilegedLogin.cs Adds ManualTests validating SqlBulkCopy behavior under a login denied access to sys.all_columns.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader.cs Updates expected connection statistics to account for the additional metadata/permission query.
src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj Includes new ManualTests source files (nullable attribute shim + new test).
src/Microsoft.Data.SqlClient/tests/ManualTests/Extensions/CodeAnalysis.netfx.cs Adds a net462-only MemberNotNullAttribute shim for nullable flow analysis in tests.
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs Adds helper properties/methods for server role membership and SQL-auth capability detection.
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/DatabaseObjects/DatabaseObject.cs Adds shared RAII base for transient database objects (create/drop + unique naming).
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/DatabaseObjects/DatabaseUser.cs Adds RAII wrapper for database users, including cross-database command execution.
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/DatabaseObjects/ServerLogin.cs Adds RAII wrapper for SQL logins with generated compliant passwords.
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/DatabaseObjects/Table.cs Adds RAII wrapper for transient tables used by tests.

Comment thread src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs Outdated
Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/Extensions/CodeAnalysis.netfx.cs Outdated
Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs Outdated
@apoorvdeshmukh

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.94%. Comparing base (8c70cec) to head (bf84bb8).

Files with missing lines Patch % Lines
...Client/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs 93.33% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (8c70cec) and HEAD (bf84bb8). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (8c70cec) HEAD (bf84bb8)
CI-SqlClient 1 0
Additional details and impacted files
@@               Coverage Diff               @@
##           release/7.0    #4402      +/-   ##
===============================================
- Coverage        73.08%   67.94%   -5.14%     
===============================================
  Files              280      275       -5     
  Lines            43087    67052   +23965     
===============================================
+ Hits             31488    45561   +14073     
- Misses           11599    21491    +9892     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 67.94% <93.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cheenamalhotra cheenamalhotra moved this from To triage to In review in SqlClient Board Jun 26, 2026
@paulmedynski paulmedynski changed the title Port | PR 4306 [7.0.3] Fix | Reenable SqlBulkCopy in least-privilege environments Jun 30, 2026
@paulmedynski

Copy link
Copy Markdown
Contributor

/azp run

@paulmedynski
paulmedynski enabled auto-merge (squash) June 30, 2026 14:05
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski
paulmedynski merged commit b4163f6 into dotnet:release/7.0 Jul 6, 2026
300 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Jul 6, 2026
@edwardneal
edwardneal deleted the port-7.0/pr-4306 branch July 6, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[7.0] SqlBulkCopy v7 breaking change: now requires metadata visibility for sys.all_columns

6 participants