-
Notifications
You must be signed in to change notification settings - Fork 31
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
Managed identity SQL auth problems (schema creation, new instance events) #166
Comments
Hold on, Meanwhile, may I suggest that you add these references on your quickstarts page relating to Azure SQL Database Getting Started / Database setup / Azure SQL database |
@cgillum RESOLUTION I have found that (at least when using Azure SQL Database as SQL Server of the provider) if you want to use another SQL server user than the sql server admin ( This holds regardless whether the user in Is this intentional?
The I guess another way, that I haven't tried, would be to only run with |
Hi @andsj073. I think what you're describing is a behavior/requirement of Azure SQL Database and isn't specific to this project. However, I think fundamentally what you're looking for is detailed instructions (or even a tool) to help with the initial setup? Is that correct? I don't think there's a way to remove the requirement for admin credentials when creating the database or setting up the users/roles. However, we may be able to streamline the process so that a DB admin can use a simple script to do the one-time setup and allow the developer to then just use the created database. Would that address your concerns? |
Hi @cgillum |
Ok. I'm glad that I found this issue because I'm already busy for two days trying to create the tables in my Azure SQL Server database. I really think it's somewhere a bug. I searched in the repo code but I can't find the real solution. Ok this is my scenario (like @andsj073). I have an Azure pipeline that automates everything, so I repeated this multiple times. Deleted Azure resources and rolled out everything.
USE [master]; -- does not work, so run in this DB manually using SSMS or the like
CREATE USER [msi name here] FROM EXTERNAL PROVIDER;
ALTER ROLE dbmanager ADD MEMBER [msi name here]; The tables are created immediatly. This took me two whole days. But the problem is that I still don't understand why. The reason is this: I have another app service (not function) that is pointing to exactly the same database, uses the same scripts and also uses a managed identity that can connect instantly. Still, I have a third principal that is my Azure Pipeline service connection principal. That is also using the same script to set the roles on the database (not the master) and that principal DOES create tables because it's creating the database and it fires my Entity Framework Core Migrations sql script. They all have db_owner permissions. I do nothing with the master database. I tried searching for roles connected to members but I see no difference in the security. When I look at the (Azure) SQL Server roles documentation (found here) it states the following for
Basically, it says: I really think it's a bug in this SQL Server provider. |
Here is some extra information about the principal added to the -- Show user/groups/db roles names and access
SELECT DISTINCT pr.principal_id, pr.name, pr.type_desc, pr.authentication_type_desc, pe.state_desc, pe.permission_name
FROM sys.database_principals AS pr
JOIN sys.database_permissions AS pe
ON pe.grantee_principal_id = pr.principal_id
--where pr.name IN ('name here')
ORDER BY pr.name
-- show role membership
SELECT DP1.name AS DatabaseRoleName,
isnull (DP2.name, 'No members') AS DatabaseUserName
FROM sys.database_role_members AS DRM
RIGHT OUTER JOIN sys.database_principals AS DP1
ON DRM.role_principal_id = DP1.principal_id
LEFT OUTER JOIN sys.database_principals AS DP2
ON DRM.member_principal_id = DP2.principal_id
WHERE DP1.type = 'R' ORDER BY DP1.name; |
Hello
The issue
I continuously fail to get the dt schema created in DFX provider SQL Database when using a Managed Identity (either User Assigned or System Assigned) in the SQL_DB_Connection string of the Function App during first run.
The only error message given, when using Mgd Identity, in Logs is:
Could not find stored procedure 'dt.CreateInstance'.
Creation works fine if I use the more basic SQL Server auth with user id and password.
But then, once the schema is in place, and back to using the Mgd Identity for auth to SQL, the created instance/event (by StartNewAsync) does not trigger Durable Orchestration execution, even though a row is created in NewEvents.
The environment
Using a clean install of Azure SQL Database on SQL Server with Elastic pool Standard DTU
and running the VS Code generated "SayHello" durable function on ASP Elastic Premium.
The Mgd Identity of the Function App is added to SQL Server Users executing (as AAD authenticated admin)
Both rows returns successfully and the User is been verified by inspected using SSMS.
No RBAC roles are assigned to the Managed Identity.
Connection string to SQL Database in app settings of Function:
The
{redacted client id}
is meticulously verified to be the client id of the Managed Identity in portalThe host.json contains
There is no VNet integration, no private endpoints or service endpoints etc. The Function App can positively access the Database through firewall rules. The durable function execution triggered by HTTP returns 500.
Additional information and behavior
Again, everything works fine if I change to connection string in app settings to:
The the dt Schema is created and the Durable Function executes normally, and rows in TaskHub are created, ending up in RuntimeStatus Completed, with rows in History and Payloads.
However, to add to this for understanding, if I now switch back to the same User Assigned Managed Identity (switching connection string again), then the Durable Function starts execution and creates rows in the dt.NewEvents and dt.Instances table (with RuntimeStatus=Pending), but nothing else (no Payloads and no History) and the Function execution never completes (stuck in RuntimeStatus Pending).
Row in NewEvents
Row in Instances
For this run, no errors can be observed in Logs / Application Insight for the instance. Only successful execution information of the run.
Hence the following method is successfully executed (see logs below) and the
DurableFunctionsOrchestrationCSharp1 (Orchestrator)
is scheduled (Executed stored procedure dt.CreateInstance in 11ms
), but the consecutive execution ofDurableFunctionsOrchestrationCSharp1
never happens. No apparent errors.The Function NuGets
Oh, and adding to the above, the same erroneous behavior is observed when trying with a System Assigned Mgd Identity of the Function (that is added as db_owner User to the SQL): The execution starts, with a row to Instances, but never completes (no exeuction of the Durable Tasks I guess) and stays in Pending.
Logs
The text was updated successfully, but these errors were encountered: