简体   繁体   English

SQL Server用户的权限有限

[英]Limited permissions for a SQL Server user

I have a .NET application which connects to SQL Server 2008 for storing some data. 我有一个.NET应用程序连接到SQL Server 2008以存储一些数据。 I use SQL Server authenthication providing an sq username and a password to my end-user in app.config file. 我使用SQL Server身份验证为app.config文件中的最终用户提供sq用户名和密码。 If something more needs to be changed I give to the end-user some other credentials. 如果需要更改某些内容,我会向最终用户提供其他一些凭据。

How can I limit the sql user to only have permission to read/write data and executing existing stored procedures and everything else to be forbidden? 如何限制sql用户只有读/写数据和执行现有存储过程的权限以及其他禁止的内容? What is the best practice for setting permisions for a sql user that an application is using to connect to a database? 为应用程序用于连接数据库的sql用户设置permisions的最佳实践是什么? Can I prevent somehow the user from logging in Management Studio and mess with my data? 我可以以某种方式阻止用户登录Management Studio并弄乱我的数据吗? I'm not searching for the perfect 100% reliable solution, but the best existing practice to do this. 我不是在寻找完美的100%可靠解决方案,而是最好的现有做法。 Thank you very much in advance. 非常感谢你提前。

Update : I work on a shared hosting SQL Server environment. 更新 :我在共享托管SQL Server环境中工作。

You'll need to create a new SQL user, something like 'LimitedUser'. 您需要创建一个新的SQL用户,例如'LimitedUser'。 To do this in SSMS, select the Security Folder of the server you are using, right-click, select New, select Login. 要在SSMS中执行此操作,请选择您正在使用的服务器的安全性文件夹,右键单击,选择“新建”,然后选择“登录”。

Select your authentication type (SQL server authentication is easily managed), and set the Default database to your database. 选择您的身份验证类型(轻松管理SQL Server身份验证),并将Default数据库设置为您的数据库。

You'll need to set Server Roles so this new user only maps to your DB, and in the last page (Status), set Login to false so they cannot use these credentials to login to SSMS and 'mess with your data'. 您需要设置服务器角色,以便此新用户仅映射到您的数据库,并在最后一页(状态)中将Login设置为false,这样他们就无法使用这些凭据登录SSMS并“弄乱您的数据”。

Click OK, and you're done creating your limited user. 单击“确定”,即可创建有限的用户。

Assign it to your database, and then in SSMS, right-click on your db, select Properties, Permissions. 将其分配给您的数据库,然后在SSMS中,右键单击您的数据库,选择“属性”,“权限”。

Select your user or role, and in the permission grid below, switch on only what need to be switched on. 选择您的用户或角色,然后在下面的权限网格中,仅启用需要打开的内容。

Shared SQL Server hosting where a single instance is shared among multiple customers is not compatible with with typical client-server applications. 在多个客户之间共享单个实例的共享SQL Server托管与典型的客户端 - 服务器应用程序不兼容。 You are expected to perform all operations through a middle tier server such a WCF Data Service and maintain user accounts within your database in a table with Forms Authentication etc. 您需要通过中间层服务器(如WCF数据服务)执行所有操作,并使用表单身份验证等在数据库中维护用户帐户。

For your client-server application you need VPS hosting with your own instance of SQL server where you can create server-level logins. 对于您的客户端 - 服务器应用程序,您需要使用自己的SQL Server实例进行VPS托管,您可以在其中创建服务器级别的登录。 Without creating server-level logins there is no method to secure a client-server application. 如果不创建服务器级别的登录,则无法保护客户端 - 服务器应用程序。 Any workarounds are just pseudo-security. 任何变通办法都只是伪安全性。

As I see, your question is fully concerned with SQL server security. 正如我所看到的,您的问题完全与SQL服务器安全性有关。

You can limit user permissions on server, database or object scope, using GRANT statement, server or database roles . 您可以使用GRANT语句,服务器或数据库角色限制服务器,数据库或对象作用域的用户权限。 For example, you can assign db_datareader role for user, and then grant EXECUTE permission to this user for some stored procedures (or for entire database). 例如,您可以为用户分配db_datareader角色,然后为某些存储过程(或整个数据库)的此用户授予EXECUTE权限。

The current practice in my organization is to create the database roles (eg application admin, operator, and so on), adding the appropriate permissions to these roles and then assign these roles to database users. 我组织中的当前做法是创建数据库角色(例如,应用程序管理员,操作员等),为这些角色添加适当的权限,然后将这些角色分配给数据库用户。

I'm not completelly sure that you can prevent login into SQL Server Managent studio (SSMS), but SSMS wll not display information that must be invisible for user with user current permissions. 我不完全确定您可以阻止登录到SQL Server Managent studio(SSMS),但SSMS不会显示对于具有用户当前权限的用户必须是不可见的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM