denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.82k stars 499 forks source link

Support for Azure SQL MI authentication using token credential #794

Open sasathy1 opened 9 months ago

sasathy1 commented 9 months ago

Is your feature request related to a problem? Please describe. The mssqldb SDK supports Azure SQL authentication through few different ways:

  1. username/password
  2. service principal
  3. managed identity (through access token)

Would it be possible to support managed identity through token credential as well (ie. something akin to azidentity.ManagedIdentityCredential)?

Reason for the ask Our system works on the edge in most scenarios, but we need to use MI auth to communicate with Azure SQL in the cloud. We are relying heavily on azure-sdk-for-go since the SDK takes care of doing the heavylifting for us (ie. defining the right scope and calling the appropriate MSI endpoint in the edge). Since we are abstracted from the nitty gritties of fetching the token, it would be easier for us if SQL could support MI Auth through token credential instead of just access token.

Describe the solution you'd like I am expecting to do something like below to perform MI auth with Azure SQL:

connString := fmt.Sprintf("Server=foo;Database=bar") cred, _ := azidentity.NewManagedIdentityCredential(nil) connector, err := mssql.WithTokenCredential(connString,cred) conn := mssql.OpenDB(connector)