Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for new "trusted" connections feature is confusing #49

Open
Pxtl opened this issue Jun 2, 2023 · 3 comments
Open

Error message for new "trusted" connections feature is confusing #49

Pxtl opened this issue Jun 2, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Pxtl
Copy link

Pxtl commented Jun 2, 2023

Fresh, default install of SQL server 2019 developer edition.

Updated to latest release version of SqlServer .

Executed

Invoke-SqlCmd -serverInstance localhost -query "SELECT 'Hello, world'"

fails with error

Invoke-SqlCmd : A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL
Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
At line:1 char:1
+ Invoke-SqlCmd -serverInstance localhost -query "SELECT 'Hello, world' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Powershell version 5.1.19041.2673
SqlServer module 22.0.59

This is confusing for the end-user because the default install of the SqlServer PS module is now incompatible with the default install of SqlServer, and the message does not clearly explain what needs to be done to correct the issue. Notifying the user that they must either install a trusted certificate into the server, add the self-signed cert into the client certificate store, or use the trusting mode for Invoke-SqlCmd would help.

@Matteo-T Matteo-T self-assigned this Jun 3, 2023
@Matteo-T Matteo-T added the enhancement New feature or request label Jun 3, 2023
@Matteo-T Matteo-T added this to the v22.2 milestone Jun 3, 2023
@admiraljohndoe
Copy link

We also noticed this behavior on the SqlServer module of an older version which was not updated/upgraded to the latest version (it basically was unchanged).

May I ask the question, could it be possible, that this behavior is brought in by a dependency being updated required for running this PowerShell module "SqlServer" or by a new Windows security setting

@Delamater
Copy link

Delamater commented Jul 19, 2023

What's also confusing (and I realize this is an issue with the ODBC driver, not the SqlServer module) is that you can bypass the certificate chain error in two ways, that seem functionally identical. That is, you can:

  1. Pass the Encrypt switch the Optional value, or set it the Encrypt value to No within a connection string parameter of Invoke-SqlCmd.
    or
  2. You can pass the TrustServerCertificate switch.

If I read Microsoft's instructions on this correctly, both approaches yield the following result on ODBC 17 and ODBC 18:

  • Server certificate isn't checked.
  • Data sent between client and server isn't encrypted.

Two approaches to do exactly the same thing makes me think I missed something important.

p.s. @Pxtl : I get that same error in SSMS if I use the options button during connection time and specify the encrypt without putting certificates in place.

@Pxtl
Copy link
Author

Pxtl commented Jul 24, 2023

I'm aware that other tools can also trigger this behavior but AFAIK Invoke-SqlCmd is distinct in that it's now the default behavior. A naive user of SSMS will not trip over this case, whereas whereas this is effectively a breaking change for SqlServer PS 22, even in the default use-case. A justifiable breaking change, but a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants