从Web应用程序访问db的最佳实践

时间:2022-07-03 20:04:45

My question might be wrong but i have doubt about designing web application which accessing MySQL database.

我的问题可能是错的,但我怀疑设计访问MySQL数据库的Web应用程序。

Following conversation was happened between me and my friend.

在我和我的朋友之间发生了对话。

My friend asked me to create separate user accounts for every user roles of the system and asked me to enable the delete option only to admin users.

我的朋友让我为系统的每个用户角色创建单独的用户帐户,并要求我只为管理员用户启用删除选项。

+-----------+-----------------+                 
|User role  | Db credential   |
+-----------+-----------------+     
|Admin      | Admin           |   
+-----------+-----------------+       
|User       | User            |        
+-----------+-----------------+

I said, we could have only one user account to access the db and all other stuffs can be done by authorization principle and I quote "While developing web application we could use multiple db user accounts for every developer but while deploying web application we might use only one user account for a deployed application"

我说,我们只能有一个用户帐户来访问数据库,所有其他东西都可以通过授权原则完成,我引用“在开发Web应用程序时,我们可以为每个开发人员使用多个db用户帐户,但在部署Web应用程序时我们可能会使用只有一个已部署应用程序的用户帐户“

+---------+-------------+  
|User role|Db credential|  
+---------+-------------+  
|Admin    | Only one    |  
+---------+user account +  
|User     | for web app |  
+---------+-------------+  

My friend arguing with me that for avoiding SQL injection we could design the system as he said. I thought its entirely wrong argument to consider.

我的朋友和我争辩说,为了避免SQL注入,我们可以像他说的那样设计系统。我认为这是完全错误的论点。

Please help me to find best practices while designing web application especially with user roles and db user credentials. I'm confused by my friend.

请帮助我在设计Web应用程序时找到最佳实践,尤其是使用用户角色和db用户凭据。我的朋友很困惑。

1 个解决方案

#1


0  

normally you only have one mysql account which can access the database, more accounts for one application (to increase security) make no sense for me because if your systems gets compromised all logins are leaked because they need to defined in your application code.

通常你只有一个可以访问数据库的mysql帐户,一个应用程序的更多帐户(为了增加安全性)对我没有意义,因为如果你的系统受到攻击,所有登录都会泄露,因为它们需要在你的应用程序代码中定义。

on the other side you give attackers with many mysql accounts more possibilities to attack.

另一方面,你为攻击者提供了许多mysql帐户攻击的可能性。

so what is left for using multiple accounts in one application, ahh access user actions against the database (limit user a with no edit rights etc.).

那么在一个应用程序中使用多个帐户还剩下什么呢?访问用户对数据库的操作(限制用户a没有编辑权限等)。

what a user should do against your database (delete things a, edit things b) should be handled by your application logic, for sure it is good to limit operation access per user (eg don't allow to write into outfile etc.) but not to handle such simple things. the cost (multiple data connection per user) is in my eyes much higher then a good programming logic.

用户应该对你的数据库做什么(删除东西,编辑东西b)应该由你的应用程序逻辑处理,确保限制每个用户的操作访问(例如不允许写入outfile等)但是不要处理这么简单的事情。成本(每个用户的多个数据连接)在我眼中远远高于良好的编程逻辑。

so increase security wich multiple accounts is pointless, use one account with a strong password and let the simple actions edit, delete etc. handel by your programming logic.

因此,增加多个帐户毫无意义的安全性,使用一个具有强密码的帐户,并通过编程逻辑让简单的操作编辑,删除等等。

#1


0  

normally you only have one mysql account which can access the database, more accounts for one application (to increase security) make no sense for me because if your systems gets compromised all logins are leaked because they need to defined in your application code.

通常你只有一个可以访问数据库的mysql帐户,一个应用程序的更多帐户(为了增加安全性)对我没有意义,因为如果你的系统受到攻击,所有登录都会泄露,因为它们需要在你的应用程序代码中定义。

on the other side you give attackers with many mysql accounts more possibilities to attack.

另一方面,你为攻击者提供了许多mysql帐户攻击的可能性。

so what is left for using multiple accounts in one application, ahh access user actions against the database (limit user a with no edit rights etc.).

那么在一个应用程序中使用多个帐户还剩下什么呢?访问用户对数据库的操作(限制用户a没有编辑权限等)。

what a user should do against your database (delete things a, edit things b) should be handled by your application logic, for sure it is good to limit operation access per user (eg don't allow to write into outfile etc.) but not to handle such simple things. the cost (multiple data connection per user) is in my eyes much higher then a good programming logic.

用户应该对你的数据库做什么(删除东西,编辑东西b)应该由你的应用程序逻辑处理,确保限制每个用户的操作访问(例如不允许写入outfile等)但是不要处理这么简单的事情。成本(每个用户的多个数据连接)在我眼中远远高于良好的编程逻辑。

so increase security wich multiple accounts is pointless, use one account with a strong password and let the simple actions edit, delete etc. handel by your programming logic.

因此,增加多个帐户毫无意义的安全性,使用一个具有强密码的帐户,并通过编程逻辑让简单的操作编辑,删除等等。