Security is a major concern for the modern age systems/network/database administrators. It is natural for an administrator to worry about hackers and external attacks while implementing security. But there is more to it. It is essential to first implement security within the organization, to make sure right people have access to the right data. Without these security measures in place, you might find someone destroying your valuable data, or selling your company's secrets to your competitors or someone invading the privacy of others. Primarily a security plan must identify which users in the organization can see which data and perform which activities in the database.
Windows Authentication, SQL Server Authentication, Windows Groups, Database Roles, Schema, and Application Roles are all aspects used to manage SQL Server Security.
Principals, Securables and Permissions
Principal
Principals are individuals, groups, and processes that can request SQL Server resources.
* Logins, Users, Roles, etc
Securable
Securables are the resources to which the SQL Server Database Engine authorization system regulates access
* Tables, Views, Endpoints, etc
Permission
Permissions grant principals access to securables
* A user has select rights on a tables, etc
* New types of permissions like Control, Alter Any and Impersonate
* Permissions work in hierarchies
Database roles (also referred to as database-level roles) are security roles that exist on a database level, as opposed to the server level. If you are familiar with any aspect of system administration, database roles are similar to groups in the world of Windows system administration. Just like a Windows group, when a user is added to a role they inherit all the rights and permissions of the role.
There are two kinds of database roles in SQL Server: fixed roles and flexible roles
Fixed Roles
Fixed roles automatically exist in each database. Adding a user to one of these roles will not change that user’s permissions in any other database.
Any user or role can be added to a database role. Once a user has been added to a role, they can add other users or roles to that role.
A Word of Warning: Be exceptionally careful when adding flexible roles to a fixed role. You could very easily elevate privileges for a large number of users in one simple step.
With that warning out of the way, let’s take a look at the fixed roles available in SQL Server:
db_owner
db_securityadmin
db_accessadmin
db_backupoperator
db_ddladmin
db_datawriter
db_datareader
db_denydatawriter
db_denydatareader
Public
* db_owner
Users in the db_owner role have it all, within a single database. They can grant and revoke access, create tables, stored procedures, views, run backups and schedule jobs. A user who is db_owner can even drop the database.
However, just because you have the keys to the kingdom doesn’t mean that you can do everything. Users who have been granted db_owner will still need specific permissions to run traces and view many of the dynamic management views. Why is that? Those are managed at the server level and will require that server-level permissions or roles are granted to your login.
Why Use db_owner?
You would want to add a user to the db_owner role if you have a user who needs to make extensive modifications to all aspects of a database:
Creating users
Adding them to roles
Creating tables/views and stored procedures,
Adding security settings for tables, views, and stored procedures
* db_securityadmin
Users in the db_securityadmin role can modify role permissions and manage permissions. Users in this role have, in theory, almost as much power members of db_owner. The only thing that a member of db_securityadmin can’t do is add users to the db_owner role. Members of db_securityadmin also cannot add users to fixed database roles (this requires membership in the db_owner role).
Why Use db_securityadmin?
You might want to use db_securityadmin when you need to grant privileges to a trusted user and allow them to manage privileges across an application. Take care when granting db_securityadmin to make sure that you trust the user to not give themselves additional permissions.
* db_accessadmin
Members of the db_accessadmin role have the ability to change database access. They can grant and revoke access to Windows logins, Windows groups and SQL Server logins. The users that they grant access to will be members of the Public role and will have all the privileges associated with that role.
Why Use db_accessadmin?
This role would be used when you have a user who is responsible for maintaining access to a specific database. When combined with db_securityadmin you have a user who is capable of granting and revoking general access to a database as well as controlling the security permissions for almost any user. This combination is quite powerful and should be granted carefully. With auditing in place, you can mitigate any risk of granting both roles to a single user.
* db_backupoperator
Members of this role can create database backups. It’s important to note that they cannot, by default, restore the backups that they create. The only users that can restore a backup are members of the sysadmin and dbcreator server roles and the owner of the database (dbo).
Why Use db_backupoperator?
If you have an automated process that connects to the database and creates a backup, it would be a good idea to have all backup operations connect to the database using a user/login that only has db_backupoperator access to prevent any unauthorized data access due to a user being compromised.
* db_datareader/db_denydatareader
Members of the db_datareader role are able to read all data from all user tables. Even the super secret table UserPayHistoryAndSocialSecurityNumbers can be read by members of db_datareader.
Conversely, members of db_denydatareader are explicitly denied the ability to write to any user created tables. They live in the dark about the contents of the database.
Why Use db_datareader?
Let’s say the Accounting department has a separate database. Everyone in Accounting is able to create and run ad hoc reports directly against this database, but they shouldn’t be able to do anything else apart from seeing the contents of the database. Clearly granting db_owner access is out of the question. Your junior DBA is out sick today, so you can’t make him grant SELECT permissions to every table in the database while you go out for lunch. Instead, you can simply grant db_datareader access to the Accounting department’s Windows group.
Why Use db_denydatareader?
In addition to the Accounting department’s requirement to be able to create ad hoc reports as needed, HR needs to be able to run the canned reports available to them through your carefully crafted stored procedures, but they should not be able to run ad hoc reports. However, it turns out that they are also able to create and run ad hoc reports. By granting db_denydatareader permissions to the HR Windows group, you can prevent members of the HR group from running the ad hoc reports (assuming Windows Forms authentication is being used). You simply get in touch with the application developers and have them hide ad hoc reports from the HR group in the application front end.
* db_datawriter/db_denydatawriter
Much like db_datareader and db_denydatareader, the name of this role is largely self-explanatory: members of the db_datawriter role can INSERT, UPDATE, and DELETE data from any user created table. Likewise, members of the db_denydatawriter role are explicitly denied the ability to perform INSERT, UPDATE, and DELETE operations on any user created tables.
Why Use db_datawriter?
db_datawriter would be a good choice for a user or login that runs an automated ETL process on a regular basis. This ensures that access to all tables is maintained even when new tables are added and reduces maintenance overhead.
Why use db_denydatawriter?
If you want to limit write access for a login or user, it is easy to add them to the db_denydatawriter role and allow specific access to a subset of tables. This might be desirable when users may need to make adjustments to certain tables - such as a bill, order or account balance - but they do not need the ability to modify all data in the database.
* db_ddladmin
Members of the db_ddladmin role are able to execute DDL commands (CREATE, ALTER, DROP) within the current database. It’s pretty self-explanatory - a member of db_ddladmin can run any CREATE, ALTER or DROP command within the current database. They cannot create new databases, nor can they alter or drop the current database.
Why Use db_ddladmin?
Your company has brought on several consultants to help develop a new application. Their work will require that they are able to create, or change, new tables, views, indexes and stored procedures. However, they don’t need the ability to create users or manage security. In this case, your best solution would be to add the consultants to the db_ddladmin role.
* Public
The Public role is a bit different from all of the other roles. Every database user is a member of the Public role. If a user does not have any explicit permissions on a database object, they will inherit the permissions of the Public role. It is important to note that users cannot be removed from the Public role.
What kind of access does public have?
None. PUBLIC has no access
Through a careful combination of users, logins, roles, Windows users and Windows groups, you can assemble a very secure, robust security infrastructure in SQL Server that can handle a variety of tasks while make your administrative life a lot easier.
Thursday, February 25, 2010
Subscribe to:
Posts (Atom)