Configure SQL Server with Azure Active Directory Service Principal authentication for Keycloak - sql-server

I have an SQL Server database hosted on azure. It can access using the Azure Active Directory Service Principal. I'm trying to deploy keycloak (16.1.0) on AKS and configure the database mentioned earlier. I have an application that can connect to that SQL Server using the Azure Active Directory Service Principal. But using keycloak, it has no luck.
I have used JDBC_PARAMS="authentication=ActiveDirectoryServicePrincipal" to configure database properties in keycloak.
Thanks

Deploying keycloak on AKS
Please Follow this doc:
Connect to that SQL Server using the Azure Active Directory Service Principal
Active Directory Service Principal authentication mode, the client application can connect to Azure SQL data sources by providing the client ID and secret of a service principal identity. Service principal authentication involves:
Setting up an app registration with a secret.
Granting permissions to the app in the Azure SQL Database instance.
Connecting with the correct credential.
Grant access to Azure SQL Database
We need to give your application access to the Azure SQL Database service. This is done through the API Permissions.
Reference 1
Add client authentication
In order to authenticate Active Directory representation of it, switch over to Certificates and create a New client secret.
The following example shows how to use Active Directory Service Principal authentication
Reference 2
The following example shows how to use Active Directory Service Principal authentication.
// Use your own server, database, app ID, and secret.
string ConnectionString = #"Server=demo.database.windows.net; Authentication=Active Directory Service Principal; Database=testdb; User Id=App Id; Password=secret";
using (SqlConnection conn = new SqlConnection(ConnectionString)) {
conn.Open();
}
Refer this link .

Related

Is it possible to connect to an Azure Sql Database from Sql Server Management Studio with service principal/app registration?

I have configured my sql server with an Azure Active Directory admin that is a service principal (app registration). Is it possible to use clientid/secret to connect from Sql Management Studio?
I have tried Azure Active Directory - password authentication but client id and secret did not work.
It works just fine from my C# code with the same id and secret.
As suggested by #junnas in the comment section we cannot connect to Azure SQL database with Service Principal in SSMS.
Please check this blog

Deployment issues when publishing Azure SQL database using Azure SQL Dacpack task in Azure pipelines within an agent job

I am trying to publish Azure SQL database using Azure SQL Dacpack task in Azure pipelines within an agent job. The authentication type I am using to publish is Service Principal.
I have added service principal as a contained DB user in the Azure SQL database and have given db owner permissions to service principal. When Service principal is a member of Active Directory Admin of Azure SQL Server, the deployment works fine. But , when Service principal is not a member of Active Directory Admin of Azure SQL Server , the deployment fails.
The error that I get is:
Unable to connect to target server . Please verify the connection information such as the server name, login credentials, and firewall rules for the target server. + Login failed for user '< token-identified principal>'. The Azure SQL DACPAC task failed. SqlPackage.exe exited with code 1.
Security team in my organization is not allowing me to have SP as Active Directory Admin of Azure SQL Server.
Azure SQL database only allow server admin/AD admin account to restore/backup the database. That's the permission limit and we can't change it.
Like you said, only if the service principal is a member of Active Directory Admin of Azure SQL Server, the account has the permission restore the database from .BACPAC file.
HTH.

Azure app service Web API connect to a SQL Server database, with Azure AD account/windows authentication

Currently I have everything on premise - .NET Core 3.0 API and SQL Server database.
Azure AD/Service account are configured in IIS and database has given access to the service account.
All requests use that Azure AD service account.
Now we are planning for an Azure migration. API is published in App Services.
Now I want to use the same Azure AD account to connect to an Azure SQL Server database.
How should I do that?
Don't send me Microsoft links, those are having toooo much info.
Tell what and how to do configuration in Azure SQL and App Services.
Any help is appreciated.
Now I want to use the same AD account to connect to an Azure SQL Server database.
AD accounts can't connect to Azure SQL Database. Only SQL and Azure Active Directory (AAD) Logins/Users.
There are some options, but there's a clear best-practice: Provision a Managed Service Identity (MSI) for your Azure App Service Application and use that to connect to SQL Server.
Here is a simple tutorial for how you should integrate App Service and Azure SQL Database:
Tutorial: Secure Azure SQL Database connection from App Service using a managed identity

Connecting to Azure SQLDW in Azure Data Factory

There is an Azure SQL Data Warehouse that I need to connect to for a linked service in Azure Data Factory. The ADW only supports Active Directory - Integrated authentication. How can I connect in Azure Data Factory with this authentication? The only options in Azure Data Factory are SQL Authentication, Managed Identity and Service Principal.
We have credentials for individual users, not app. I have an AAD app registration we could possibly use. Do I need to have the ADW add our AAD app?
I tried SQL Authentication (obviously didn't work), we don't have a managed instance (would be our ADF instance), and don't have an obvious service principal.
Thank you in advance for your help!
Follow the steps at this link, and create a Managed Identity for your ADF.
https://learn.microsoft.com/en-us/azure/data-factory/connector-azure-sql-data-warehouse#managed-identity
Managed Identity (AAD authorisation) is not Managed Instance (database service).

Azure web app with on site SQL Server and Windows authentication

I need to connect my web app on Azure to our on site SQL Server instance via Windows authentication (not via SQL Server account authentication). Active Directory is already integrated with the on-site AD and therefore all of the users are available there.
My question is, is it possible to hook up an azure web app to an on-site SQL Server via Windows authentication.
is it possible to hook up an azure web app to an on-site SQL Server via Windows authentication.
Base on my option, it maybe that we couldn’t do that. As we have been limited to do that operation for azure WebApp. There is also another SO thread mentioned that.
If we want to connect to on premise SQL Server, we can use hybrid connections to access on-premises SQL server database in Azure WebApp, more info please refer to the document.
If we want to authenticate the WebApp with local Active Directory, and we have an on-premises secure token service (STS) like Active Directory Federation Services (AD FS), we could use that to federate authentication for our Azure WebApp. More info please refer to the document.
Hybrid connections at this time does not support AD accounts due to
because you cannot domain join an App Service worker

Resources