In the SINGLE mode only one user is permitted to access the database at a time. In the RESTRICTED mode only members of the db_owner, dbcreator, and sysadmin roles can connect to the database.
Database Read-Only (READ_ONLY or READ_WRITE)
You can use Database Read-Only option to control whether updates are allowed on the database. When set to TRUE in SQL Server Management Studio or ON when using the ALTER DATABASE command, users can only read from the database and are not permitted to modify data. When set to FALSE, the read and write operations are permitted on the database. To change the state of this option, you must have exclusive access to the database.
You can use Database State option to control the state of the database. When set to NORMAL, the database is fully operational and available for use. When the database is set to CLOSED, the database is shut down cleanly and marked offline. The database cannot be accessed or modified while in this state. When set to EMERGENCY, the database is marked READ_ONLY, logging is disabled, and access is limited to members of the sysadmin fixed server role. The EMERGENCY database state is used primarily for troubleshooting purposes.
Restrict Access (DB_USER_ACCESS_OPTION)
Restrict Access can be used this option to control access to the database. In MULTIPLE mode all users are allowed to connect to the database as long as they have the appropriate permissions. Conversely, in the SINGLE mode only one user is permitted to access the database at a time. In the RESTRICTED mode only members of the db_owner, dbcreator, and sysadmin roles can connect to the database.
Database objects aren’t the only things that you can secure. You can create rights and privileges for everything from the server itself to each database and each object that they contain. Securables in SQL Server 2005 are the resources to which the SQL Server Database Engine authorization system regulates access. Some securables can be contained within others, creating nested hierarchies called “scopes” that can themselves be secured. You can secure at server level, database level and schema level. The securable scopes are
Securable scope Server contains following securables on SQL Server 2005
Securable scope database contains the following securables on SQL Server 2005
- Application role
- Message Type
- Remote Service Binding
- Fulltext Catalog
- Asymmetric Key
- Symmetric Key
Securable scope schema contains the following securables on SQL Server 2005
- XML Schema Collection
SQL Server Objects
The following securables are members of the object class for SQL Server 2005
Changing the passwords regularly is an important requirement of robust security implementation. And it becomes more important when login is sa. To analyze that when last time you implemented this good practice, use following script.
USE Master GO SELECT sid, [name], createdate, updatedate FROM master.dbo.syslogins WHERE [name] = 'sa' GO
And if specific to SQL Server 2005 then
USE Master GO SELECT [name], sid, create_date, modify_date FROM sys.sql_logins WHERE [name] = 'sa' GO
The script will return name, sid, creation date and update/modification date of all of your logins. As sa account can not be updated/modified except that of password, so update date here will be the date when password of sa was changed. And if no name condition is provided then update date tells you any last any update for other logins.
USE Master GO SELECT [name], sid, create_date, modify_date FROM sys.sql_logins GO
Following best practices may be implemented as base line for standard security of SQL Server
- Ensure the physical security of each SQL Server, preventing any unauthorized users to physically accessing your servers.
- Only install required network libraries and network protocols on your SQL Server instances.
- Minimize the number of sysadmins allowed to access SQL Server.
- As a DBA, log on with sysadmin privileges only when needed. Create separate accounts for DBAs to access SQL Server when sysadmin privileges are not needed.
- Assign the SA account a very obscure password, and never use it to log onto SQL Server. Use a Windows Authentication account to access SQL Server as a sysadmin instead.
- Give users the least amount of permissions they need to perform their job.
- Use stored procedures or views to allow users to access data instead of letting them directly access tables.
- When possible, use Windows Authentication logins instead of SQL Server logins.
- Use strong passwords for all SQL Server login accounts.
- Don’t grant permissions to the public database role.
- Remove user login IDs who no longer need access to SQL Server.
- Remove the guest user account from each user database.
- Disable cross database ownership chaining if not required.
- Never grant permission to the xp_cmdshell to non-sysadmins.
- Remove sample databases from all production SQL Server instances.
- Use Windows Global Groups, or SQL Server Roles to manage groups of users that need similar permissions.
- Avoid creating network shares on any SQL Server.
- Turn on login auditing so you can see who has succeeded, and failed, to login.
- Don’t use the SA account, or login IDs who are members of the Sysadmin group, as accounts used to access SQL Server from applications.
- Ensure that your SQL Servers are behind a firewall and are not exposed directly to the Internet.
- Remove the BUILTIN/Administrators group to prevent local server administrators from being able to access SQL Server. Before you do this on a clustered SQL Server, check Books Online for more information.
- Run each separate SQL Server service under a different Windows domain account
- Only give SQL Server service accounts the minimum rights and permissions needed to run the service. In most cases, local administrator rights are not required, and domain administrator rights are never needed. SQL Server setup will automatically configure service accounts with the necessary permissions for them to run correctly, you don’t have to do anything.
- When using distributed queries, use linked servers instead of remote servers.
- Do not browse the web from a SQL Server.
- Instead of installing virus protection on a SQL Server, perform virus scans from a remote server during a part of the day when user activity is less.
- Add operating system and SQL Server service packs and hot fixes soon after they are released and tested, as they often include security enhancements.
- Encrypt all SQL Server backups with a third-party backup tool, such as SQL Backup Pro.
- Only enable C2 auditing or Common Criteria compliance if required.
- Consider running a SQL Server security scanner against your SQL servers to identify security holes.
- Consider adding a certificate to your SQL Server instances and enable SSL or IPSEC for connections to clients.
- If using SQL Server 2005, enable password policy checking.
- If using SQL Server 2005, implement database encryption to protect confidential data.
- If using SQL Server 2005, don’t use the SQL Server Surface Area Configuration tool to unlock features you don’t absolutely need.
- If using SQL Server 2005 and you create endpoints, only grant CONNECT permissions to the logins that need access to them. Explicitly deny CONNECT permissions to endpoints that are not needed by users.
Chosen from SQL Server DBA best practices By Brad M.mcGehee