Authentication using AccessToken / ServicePrincipal

156 Views Asked by At

Am having a SSDT unit test project with EntraID authentication to my azure database.

This SSDT unit test project shall be executed (see image below):

  • Locally in VS Code using the connection string +

    Active Directory InteractiveAuthentication

  • And within my AzureDevOps Pipeline + Using ??Service Principal?? authentication

enter image description here

... this is the app.config for local execution: enter image description here

How do i need to configure my app.config in order to use my ServicePrincipal from the AzureDevOps-Pipeline?

1

There are 1 best solutions below

0
On

How do i need to configure my app.config in order to use my ServicePrincipal from the AzureDevOps-Pipeline?

To use the AAD Service Principal in the app.config -> ConnectionString, you can set the Authentication to ActiveDirectoryServicePrincipal.

Here is an example:

Data Source=xx.database.windows.net,1433;Initial Catalog=DATABASE;Persist Security Info=False;User ID={appid};Password={appsecret};Multiple Active Result Sets=False;Encrypt=True;TrustServerCertificate=False;Authentication=ActiveDirectoryServicePrincipal

If you want to avoid storing sensitive information in a connection string in app.config. You can store the connectionString in a secret variable in your pipeline.

And use tokens connectionString="#{sqlDbTestConnectionString}#" in app.config in place of real connection strings.

Then add replace token task before VsTest task in your pipeline to replace the tokens #{sqlDbTestConnectionString}# in app.config with the real connectionString defined in secret variable.

You can check this blog for more information.