Skip to content
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

EnsureDatabaseExistsAsync breaks in environments where "master" access disallowed #233

Open
mikeredick opened this issue Sep 13, 2024 · 5 comments · May be fixed by #234
Open

EnsureDatabaseExistsAsync breaks in environments where "master" access disallowed #233

mikeredick opened this issue Sep 13, 2024 · 5 comments · May be fixed by #234
Labels
bug Something isn't working

Comments

@mikeredick
Copy link

In companies with stronger security policies, like mine, it may not be possible to give the application login access to the master database. We can run the scripts to manually create the schema/tables but EnsureDatabaseExistsAsync will fail to log into the master database preventing the listeners from starting up:

Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException : The listener for function 'MyFunction' was unable to start. ---> Microsoft.Data.SqlClient.SqlException : Login failed for user '<token-identified principal>'.
   at Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async DurableTask.SqlServer.SqlDbManager.EnsureDatabaseExistsAsync() at /_/src/DurableTask.SqlServer/SqlDbManager.cs : 183
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async DurableTask.SqlServer.SqlDbManager.AcquireDatabaseLockAsync(Boolean createDatabaseIfNotExists) at /_/src/DurableTask.SqlServer/SqlDbManager.cs : 137
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async DurableTask.SqlServer.SqlDbManager.CreateOrUpgradeSchemaAsync(Boolean recreateIfExists) at /_/src/DurableTask.SqlServer/SqlDbManager.cs : 33
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskExtension.StartTaskHubWorkerIfNotStartedAsync() at D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\DurableTaskExtension.cs : 1414
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.StartAsync(??) at D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs : 68
   End of inner exception```

@cgillum cgillum added bug Something isn't working and removed Needs: Triage 🔍 labels Sep 13, 2024
@cgillum cgillum linked a pull request Sep 13, 2024 that will close this issue
@cgillum
Copy link
Member

cgillum commented Sep 13, 2024

@mikeredick I've created a draft PR to fix this, but I don't have cycles to test it quite yet. Your scenario is supposed to work but I think it was regressed in a recent release.

If you can provide detailed repro steps, then I think I can validate and release the fix much faster.

@mikeredick
Copy link
Author

Is this good enough?

To reproduce:

  1. Create database manually
  2. Run the setup scripts from github
  3. Create login/user for the database, ensure it does NOT have access to log in to master
  4. Add user to dt_runtime role
  5. Configure durable task project to use the database
  6. Run it, it should show the errors as it tries to start the event listeners

@cgillum
Copy link
Member

cgillum commented Sep 16, 2024

The main thing I was looking for is any SQL commands for step 3 in your list, but I can try to figure it out when I have cycles.

@mikeredick
Copy link
Author

I've asked our infrastructure team as they created the login and user. I'll let you know when I hear back from them.

@mikeredick
Copy link
Author

Ended up having to dig through their pipeline code to find the command, looks like it is just logging into the target database and running:

CREATE USER username FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER username;
ALTER ROLE db_datawriter ADD MEMBER username;
ALTER ROLE dt_runtime ADD MEMBER username;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants