Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why contained database user needs Persist Security Info=True

I have a database where I created a contained user and I needed to connect to my web app using that user. I have always been able to connect to the web app with a standard user having Persist Security Info=False.

However, the only way I was able to connect with the contained user was changing my connection string to Persist Security Info=True, otherwise I'd get a login failed sql exception even though I was able to connect using SSMS. I'm not sure why it worked, does anybody know why a contained user needs the property set to True?

like image 668
monica Avatar asked Aug 03 '16 16:08

monica


People also ask

What persist security information is true?

Setting Persist Security Info to true or yes allows security-sensitive information, including the user ID and password, to be obtained from a connection after it has been opened.

What is a contained database user?

Use contained database users to authenticate SQL Server and SQL Database connections at the database level. A contained database is a database that is isolated from other databases and from the instance of SQL Server/ SQL Database (and the master database) that hosts the database.

What is persistent security?

Persistence in cybersecurity occurs when a threat actor discreetly maintains long-term access to systems despite disruptions such as restarts or changed credentials. Bad actors can place an implant or a “stub” that both evades automated antivirus solutions and kickstarts more malware.

What is contained database authentication?

A contained database includes all database settings and metadata required to define the database and has no configuration dependencies on the instance of the Database Engine where the database is installed. Users can connect to the database without authenticating a login at the Database Engine level.


1 Answers

For you web app, are you using Entity Framework ? And for your DbContext are you using IdentityDbContext ?

If so, I had the same problem. I was able to connect directly with SqlConnection but encountered an "Access Deny" error when connecting with Entity Framework. When I gave enough permissions to my user, all queries were very slow.

When instantiating the Context (with IdentityDbContext) you should set the second parameter to false.

public AdeleDbContext(string connectionString) : base(connectionString, false)
{
}

The second parameter is throwIfV1Schema and when set to true (which is the default value), it will validate schema against the database by calling SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@Table for many columns.

That was the reason why the connection was slow and user needed more permissions when connecting to DB with Entity Framework and IdentityDbContext.

like image 73
Jimmy Lahaie Avatar answered Sep 17 '22 15:09

Jimmy Lahaie