[Top] [Prev] [Next]

Chapter 10

Security and Auditing on SQL Server


Security Features

SQL Server's security features protect the system and its data against unauthorized use. SQL Server also provides mechanisms for identifying authorized users and keeping track of the use of system resources.

Integrity and security are critical requirements with on-line applications that involve data access by dozens, hundreds, or even thousands of users. Integrity refers to the accuracy and consistency of data. Security means authorizing and controlling access to data. SQL Server addresses these requirements by enforcing integrity and security centrally, rather than in each application that accesses the data.

This approach provides important benefits:

SQL Server's security is targeted at the Class C2 requirements of the National Computer Security Center (NCSC) Trusted Computer System Evaluation Criteria. This means that it provides identification, authentication and auditing, as well as access control based on grant and revoke. All of these features are available on SQL Server; some features, such as auditing, are optional.

A separate Sybase product, Secure SQL Server, is targeted at the Class B1 requirements. It adds mandatory access controls based on sensitivity labels associated with data and users. Granularity of access can be as fine as an individual data row.

This chapter describes the SQL Server security features that protect the system and its data against unauthorized use. It also describes the mechanisms available for identifying authorized users and keeping track of the use of system resources.This chapter contains the following sections:

Secure SQL Server, an extension of the standard SQL Server, addresses the problems associated with storing information with multiple sensitivity classifications.

User Identification

SQL Server uses a variety of mechanisms to positively identify an individual user and to enforce accountability and security, such as:

User Roles

SQL Server recognizes three security-related operational and administrative roles that can be assigned to a user: the System Administrator, the System Security Officer and the Operator. The ability to grant permissions is determined by each user's role as System Administrator, Database Owner, or database object owner.

The System Administrator

System Administrator tasks include:

A System Administrator operates outside the object and command protection system¯SQL Server does no permission checking on commands executed by a System Administrator. (For system procedures restricted to System Security Officers, a system function within the procedure verifies that the user has the correct role.) A System Administrator takes on the identity of Database Owner in any database he or she enters, including master.

There are several commands and system procedures that only a System Administrator can execute, and on which permissions cannot be transferred to other users.

System Security Officer

The System Security Officer is responsible for the security-sensitive tasks in SQL Server, such as:

The System Security Officer has no special permissions on database objects. There are several system procedures that only a System Security Officer can execute and on which permissions cannot be transferred to other users.

The Operator

An Operator is a user who can back up and load databases on a server-wide basis. The Operator role allows a single user to use the dump database, dump transaction, load database, and load transaction commands to back up and restore all databases on a server without having to be the owner of each one. These operations can be performed in a single database by the Database Owner and the System Administrator.

Managing Roles

When you first install SQL Server, there is a single login named "sa" that has the System Administrator, System Security Officer and Operator roles. To increase the accountability of users who perform system administration and security functions, you should:

Special built-in functions allow you to:

You can grant each role to multiple users, and a user may have more than one role. In addition, you can turn roles on and off during a SQL Server session.

Ownership Types

Two types of ownership are recognized by SQL Server:

Database Owners

A Database Owner is the creator of a database and has full privileges inside that database. The System Administrator can grant authority to create databases to other SQL Server users, or can create a database and transfer ownership to a user.

The owner of a database may:

Database Object Owner

Database Owners can grant authority to create particular types of objects to users of their database. A user who creates a database object (a table, index, view, default, constraint, trigger, rule, or procedure) is its owner.

A database object owner is automatically granted all permissions on that object. He or she can see and modify the data, or drop the object. Other users must be granted explicit access permission on that object by its owner in order to select or modify the data. Even the Database Owner cannot use an object directly unless the object owner grants him or her the appropriate permission.

Managing User Identifications and Permissions

SQL Server provides system procedures for managing login accounts for SQL Server users. For each user, these steps provide an account on a SQL Server and access to its data:

The System Security Officer creates logins on a SQL Server. A System Administrator or the Database Owner can add users to or drop users from specific SQL Server databases and change existing user identification and permissions. Other system procedures provide information about user accounts and protection levels.

The following sections summarize the system procedures used in managing user accounts. The permission column in the following tables specifies the lowest default permission level.

Managing Users: An Overview

System procedures are used to manage user login accounts. In addition to adding and dropping user login names, system procedures can be used to change passwords, to assign users to groups, and to add users to a specific database.

Adding Login Accounts, Users, and Groups

The process of adding new login accounts to SQL Server, adding users to databases, and granting them permission to use commands and database objects is divided among the System Security Officer, System Administrator, and Database Owner.

Table 10-1: System procedures for adding users to SQL Server and databases

System procedure Task Executed by Where
sp_addlogin Create new logins, assign default databases, assign password SSO Any database
sp_addgroup Create groups DBO or SA User database
sp_adduser Add users to database, assign groups DBO or SA User database

Dropping Logins, Users, and Groups

The following system procedures allow a System Administrator or Database Owner to drop logins, users and groups.

Table 10-2: Dropping logins, users, and groups

System procedure Task Executed by Where
sp_droplogin Drop login account from SQL Server SA masterdatabase
sp_dropuser Drop user from database DBO or SA User database
sp_dropgroup Drop group from database DBO or SA User database

Locking SQL Server Logins

You cannot drop the login account for a user who owns database objects. The sp_locklogin account allows you to lock the account, denying the user access to the server, without having to drop and re-create the objects.

Table 10-3: Locking Logins

System procedure Task Executed by Where
sp_locklogin Lock a SQL Server login SA or SSO Any database

Changing User Information

Additional system procedures allow you to change the information added with the commands discussed earlier in this chapter. For example, sp_modifylogin and sp_password change default databases and passwords for SQL Server users. The system procedures described in Table 10-4 change aspects of users' logins and database usage.

Table 10-4: System procedures for changing user information

System procedure Task Executed by Where
sp_password Change another user's passwordChange own password SSOUser Any database
sp_changegroup Change group assignment of a user SA or DBO User database
sp_modifylogin Change a login account's default database, default language, or full name SA Any database

Using Aliases in Databases

The alias mechanism allows you to treat more than one person as the same user inside a database, so that they all have the same privileges. An alias is often used so that several users can assume the role of database owner or object owner. The alias mechanism can also be used to set up a collective user identity, within which the identities of individual users can be traced using auditing.

For example, say several vice presidents want to use a database with identical privileges and ownerships. One way to accomplish this is to add a login named "vp" to SQL Server and the database; each vice president logs in as "vp". The problem with this method is that there is no way to tell the individual users apart. The other approach is to alias all the vice presidents, each of whom has his or her own SQL Server account, to the database user name "vp".

The following system procedures manage aliases:


Table 10-5: System procedures for managing aliases

System procedure Task Executed by Where
sp_addalias Add an alias for a user DBO or SA User database
sp_dropalias Drop an alias DBO or SA User database

Getting Information About Users

The following procedures allow users to obtain information about users, groups and current SQL Server usage.

Table 10-6: System procedures that report on SQL Server users and groups

Procedure Function
sp_who Reports on current SQL Server users and processes
sp_displaylogin Displays information about login accounts
sp_helpuser Reports on users and aliases in a database
sp_helpgroup Reports on groups within a database

By default, all users can execute these system procedures.

User Permissions

SQL Server's protection system is controlled through the use of the SQL commands grant and revoke. These two commands specify which users or groups of users can issue specific commands and perform specific operations on which tables, views, or columns.

Some Transact-SQL commands can be issued at any time by any user, with no grant permission required. Other Transact-SQL commands can be used only by users of certain status (for example, only by the System Administrator). Permission to use certain commands is not transferable with grant.

By using the with grant option clause to the grant command, the Database Owner or System Administrator can give other users the ability to grant permission to access database objects. For example, if the Database Owner grants select permission on the titles table to user "mary" specifying with grant option, user "mary" can grant the same permission to other users. A similar option for the revoke command, cascade, revokes permissions from "mary" and from everyone to whom "mary" granted permission.

Permissions to Create and Access Objects

There are two categories of permissions:

Each database has its own independent protection system. Being granted permission to use a certain command in one database has no effect in other databases. The create database command can be granted only by a System Administrator, and only to users of the master database.

If you try to use a command or database object for which you have not been assigned permission, SQL Server responds with an error message.

The Permission Hierarchy

The different types of SQL Server users exist in a hierarchy, with users having the System Administrator role at the top.

Database Owners are next in the hierarchy. System Administrators and Database Owners can grant and revoke object creation permissions to other users (so that they become the next level: database object owners).

At the next lower level are the owners of database objects (tables, views, and stored procedures), who control access permission on their objects. For example, a user who creates (and therefore owns) a table automatically has all of the object access permissions that apply to that table¯select, insert, update, and delete. No other users have any permissions on the table until the owner specifically grants them with the grant command.

At the bottom of the hierarchy are the other database users (also known as "public"). Permissions are granted to or revoked from them by object owners, Database Owners, and/or the System Administrator. These users are specified by user name, by group name, or as members of "public".

Views and Stored Procedures as Security Mechanisms

Views and stored procedures can serve as security mechanisms. Users can be granted permission on a view or on a stored procedure even if they have no permissions on objects the view or procedure references. Permissions on views and stored procedures are checked when the object is used, not when the view or procedure is created.

Views

Through a view, users can query and modify only the data they can see. The rest of the data is neither visible nor accessible.

Permission to access data in a view must be explicitly granted or revoked, regardless of the set of permissions in force on the view's underlying table(s). Data in an underlying table that is not included in the view is hidden from users who are authorized to access the view but not the underlying table.

By defining different views and selectively granting permissions on them, an owner can restrict a user (or any combination of users) to different subsets of data:

Stored Procedures

Users with permission to execute a stored procedure can do so even if they do not have permissions on tables or views referenced in it. For example, a user might be given permission to execute a stored procedure that updates a row-and-column subset of a specified table, even though that user does not have any other permissions on that table.

Auditing in SQL Server

Auditing records security-related system activity in an audit trail, which can be used to detect penetration of the system and misuse of resources. By examining the audit trail, System Security Officers can inspect patterns of access to objects in databases, and can monitor the activity of specific users. Audit records are traceable to specific users, enabling the audit system to act as a deterrent to users attempting to misuse the system.

SQL Server can be configured to provide an audit trail for events such as:

New Auditing System in Forthcoming Releases


Note
These auditing changes do not affect System 11.0 auditing, but are described only to alert you to changes in future releases that may impact your installation.
In the next major releases of SQL Server, the auditing system will provide these enhancements:

The next major releases of SQL Server will not support sp_auditoption, sp_auditlogin, sp_auditdatabase, sp_auditobject, and sp_auditsproc. Functions provided by these system procedures will be provided by the new system procedure sp_audit. The new auditing system will continue to allow users to add their own audit records with sp_addauditrecord.

The Audit System

The audit system consists of:

The sybsecurity Database

Essential to auditing in SQL Server is the sybsecurity database. It is created as part of the auditing installation process. It contains all system tables found in the model database and two additional system tables:

The Auditing System Procedures

Auditing is managed with the following system procedures:

Table 10-8: System procedures used to manage auditing options

System procedure Description
sp_auditoption Enables and disables system-wide auditing and global audit options.
sp_auditdatabase Establishes auditing of different types of events within a database, or of references to objects within that database from another database.
sp_auditobject Establishes selective auditing of accesses to tables and views.
sp_auditsproc Audits the execution of stored procedures and triggers.
sp_auditlogin Audits a user's attempts to access tables and views, or the text of commands that the user executes.
sp_addauditrecord Allows users to enter user-defined audit records (comments) into the audit trail.

The Audit Queue

When an audited event occurs, an audit record first goes to the in-memory audit queue, where it is held until it can be processed by the audit process and added to the audit trail. You can configure the size of the audit queue with sp_configure.

Establishing Auditing

The System Security Officer manages the audit system. Only a user who has been granted that role can:

The System Security Officer who is going to manage the audit system must be granted access to the sybsecurity database.

Auditing can be established at two levels:

Server-Level Auditing Options

At the server level, the System Security Officer can establish auditing for any combination of these events:

Database-Level Auditing Options

You can activate selective auditing at the database level to detect:

Within a specific database, you can also:

Example: Auditing a Stored Procedure

This example illustrates how to audit a stored procedure that updates an accounts table. The procedure takes two arguments, an account number and an amount, like this:

update_acct 23475, 200.00

The update_acct procedure (without any error checking) is simple:

create proc update_acct  @acct int,

                         @amount smallmoney

as

update acct set amount = amount + @amount 

where acct = @acct

To initiate auditing on successful executions of this procedure, the System Security Officer uses sp_auditsproc:

sp_auditsproc update_acct, pubs2, ok

Here is a query that returns auditing information about the procedure from sysaudits:

select eventtime, loginame, extrainfo

from sysaudits

where objname = "upd_acct"

order by eventtime

For stored procedures, sysaudits stores the arguments to the procedure in the extrainfo field, so it is easy to trace all activity performed on the table by auditing the procedure.

eventtime           loginname     extrainfo

------------------- ------------- --------------------

Oct 19 1993  4:44PM henry         23475, 200.00

Oct 19 1993  4:49PM lulu          22376, -30.89

Oct 19 1993  4:49PM lulu          22376, 1057.23

Oct 19 1993  4:55PM carol         67892, 98.73



[Top] [Prev] [Next] [Bottom]