Managing Users Permissions on SQL Server - Page 2August 13, 2003 Enhancing Security Using ViewsViews can be used to enhance security because permissions to access a view can be granted, denied, or revoked, regardless of the set of permissions to access the underlying table(s). Views can also be used to limit the data that is available to a user. For example, one peace of data can be accessible to users for modifications while another piece of data can be accessible to users for query, and the rest of the data is invisible and inaccessible. Views can be used to restrict access to the following subsets of data:
Suppose you need to assign the Accounting role access to query the entire employee table, the Sales role to access only the LName, FName, and HireDate columns of the employee table, and the Tech role should not have any access either to the view or to the employee table itself. This can be achieved using the following script:
Using Stored Procedures to Enhance SecurityStored procedures can be used to enhance security in much the same way as views. The permissions to execute a stored procedure can be granted, denied, or revoked instead of granting permissions on the underlying data objects. Stored procedures can be used to conceal the underlying data objects too. For example, you can give a user only the permission to execute a stored procedure and the user will not know anything about underlying data objects. By using stored procedures, you can also limit the data that is available to a user. You can give the users only permission to execute a stored procedure to work with the restricted set of the columns and rows instead of querying the entire table. For example, the Salary and the Address columns in the employee table contain confidential employee information and should be available only to the members of the Accounting database role, but the rest of the columns contain information that should be available to all database users. This script shows how the above security task can be achieved:
Because each database user has the public role permission, you can grant the desirable permission to the public role if you need to grant this permission to all database users. If the business logic of your application allows some users to update values in several columns in the table without having permission to update anything else on the table, you can also use a stored procedure. For example, any members of the Accounting database role are allowed to update the Salary column in the employee table without having permission to update other columns. The employee table was created using the following CREATE TABLE statement: The following script shows how the above security task can be achieved:
Permissions IntersectionUnder the permissions intersection we understand the results permission, which a user will have when different permissions were granted or revoked to this user or (and) for the roles to which this user belong. A permissions conflict can arise, if the user is a member of several roles with different permissions to access an object. As we described above, permissions can be granted, revoked, or denied. The GRANT statement removes the denied or revoked permission at the level granted, so the denied permission at another level still applies. For example, if you need to allow the user Alex to select the employee table and the select permissions were denied to both user Alex and Accounting role to which Alex belongs, you can run the following statement: GRANT SELECT ON employee TO Alex, Accounting
The REVOKE statement is used to remove a previously granted or denied permission at the level revoked, so the same permission granted or denied at another level still applies. For example, if you need to prevent the user Alex from selecting the employee table and the select permissions were granted to both user Alex and Accounting role to which Alex belongs, you can run one of the following statements:
|