dbcodeio / public

The Power of Databases, The Convenience of VS Code: All in One Place
6 stars 0 forks source link

MSSQL Add Integrated Authentication / Entra Support #13

Open HunterFrisby opened 2 months ago

HunterFrisby commented 2 months ago

Hi, is it possible to add support for sql server integrated authentication / entra to connections?

mikeburgh commented 2 months ago

From a quick read of the documentation.. Maybe..

A couple of questions:

Tedious, the underlying driver we use, supports a number of different Azure based auth methods (https://tediousjs.github.io/tedious/api-connection.html#function_newConnection) , but I think the two relevant ones for this are: azure-active-directory-password and azure-active-directory-service-principal-secret

azure-active-directory-password

azure-active-directory-service-principal-secret

HunterFrisby commented 2 months ago

Hi

I appreciate your efforts in exploring this request.

Thank you.

mikeburgh commented 2 months ago

Thanks for confirming, we will setup a test Azure server and see if we can get this going, would be nice to leverage the VSCode signed in account if we can.

mikeburgh commented 1 month ago

Support for Entra ID has been added to the Azure connection type in 0.16.0, which should be available now.

We also added Azure as a cloud provider, since a lot of the functionality overlapped as was on the road map to support Azure as a cloud provider.

This means you can add the Azure cloud provider and browse all your databases without needing to make individual connections for them. Authentication to the databases found via the cloud provider is done via Entra ID only, including for MySQL and Postgres databases.

HunterFrisby commented 1 month ago

I appreciate you adding this support! I have updated to the latest version and have tried connecting with the new settings (see below). Though when I try to connect I get an "Error connecting to Jitterbit-DEV, error: Login failed for user ''." error. I was able to select my Entra account and authorize access appropriately.

Settings image

Error image

P.S. I have also tried connecting through the Azure Cloud connection, but I believe that since in my case the server is not on the same host address (e.g. xxxx.azuresynapes.net) as my username (User@company.com) it doesn't apply correctly.

mikeburgh commented 1 month ago

Thanks, digging into this.. we used a default Azure AD environment, so guessing there is something more to it..

mikeburgh commented 1 month ago

Did you use a connection that you had already created by chance ? Can you delete it, and add a new connection and see if that works ? Hopefully we identified the issue.

If that does not fix it, we will release a build with extra logging so we can try and see what's happening inside the connection creation.. It will show the trace details and require you to paste them here, so you can review first for any information you want to omit (eg host names etc)

HunterFrisby commented 1 month ago

I have retired with removing the connection and adding it again, as well as adding a different connection. Which still results in the "Error connecting to Jitterbit-DEV, error: Login failed for user ''." error.

I am still on v0.16.0 and don't show any update, if the issue you mentioned is supposed to be on a later/new version?

mikeburgh commented 1 month ago

I did some more digging into Azure, the xxxx.azuresynapes.net is one of their hosted services, it's SQL Server underneath (among other things) but it does present and work as SQL Server.

I created one to test it out, and was able to find and connect to it via the cloud provider as well as a manual connection using Entra ID, so it's not specific to that service.

I also tried creating other tenants and accessing resources across tenant, and was not able to get any errors like yours..

Heres one screenshot of the various connections and tenants we tested, note the synapse connection manually at the bottom.. it's also in the synapseworkspace.

Azure

A new version 0.16.1 is out now with some updated drivers, I am doubtful it fixes your issue, but hoping it gives us a better error response. Can you give it a try.

MS is also in the middle of changing over the approach for token auth for the SQL driver (https://github.com/tediousjs/tedious/pull/1641), as soon as that's out I am going to try it to see if it's any better.

Assuming this new version does not fix it for you, can you reach out to help@dbcode.io and we can send you a build with more tracing so we can try and identify where the issue in your Azure environment is.