As the DBA for revenue-generating applications, I am frequently invited by my CIO to meetings with Sarbanes-Oxley auditors to discuss the security and integrity of corporate data. In a nutshell, we're expected to answer any number of questions, via appropriate documentation, about who has access to our data, how access is granted, and how we are monitoring to prevent someone from sneaking in, logging on, and doing something they shouldn't be doing.

My CIO and I have looked at a number of commercial solutions for documenting Sarbanes-Oxley compliance. However, we decided to use SQL Server 2005's built-in tools to create our own "home-grown" auditing system.

What's new in Server 2005
Before SQL Server 2005, we used data manipulation language (DML) triggers to tell us when changes to data occurred in the database. We could point to the audit log and say, there is a list of all of the INSERT, UPDATE, and DELETE statements we've issued since the last audit, including the time, date, and person or program that executed the statement.

DML triggers, which are specialized stored procedures that the database engine fires, have been very useful in giving us the ability to create an audit trail of changes to our data. However, DML triggers were limited to only fire when changes to data occur. Before SQL Server 2005, we had no good way to track structural or security changes to our database server.

SQL Server 2005 supports data definition language (DDL) triggers. These triggers can be setup to fire when any number of server- or database-level events occur. DDL triggers allow us to track critical changes to our database environment--changes that may be intentional, by mistake, or malicious.

DDL events are fired at two different scopes: the database-level and the server-level. When you design DDL triggers, it's important to determine what events you want to audit, and to determine in which scope each event occurs. In this article, we'll write a trigger to capture logins, which are server-level events.

Tracking all logins
Here's a good example of how DDL triggers improve our ability to monitor the database. In previous versions of SQL Server, it was difficult to keep track of when new logins were created, when new databases were created, or when new permissions were assigned to different users.

It's relatively easy to track such security changes in SQL Server 2005. To demonstrate how, let's design a solution that keeps track of all activity on the server, regardless of the user. We'll use the DDL trigger event DDL_LOGIN_EVENTS to set up the audit trail. This event trigger will look for any login events that occur on the server, including all CREATE LOGIN, ALTER LOGIN, and DELETE LOGIN events.

Of course we'll want to track all changes in a database to which the DBA and development team have very limited access. Limiting the ability of the DBA to change the audit trail of a server or database is a key step in ensuring the integrity of the audit trail.

In SQL Server 2005, create a database for the audit trail by running the statement CREATE DATABASE DDLTriggerTest, and then define the following fields:

  • IDCol SMALLINT IDENTITY(1,1) PRIMARY KEY,
  • XMLEvent XML,
  • DatabaseName VARCHAR(50),
  • SystemUser VARCHAR(50),
  • EntryDate DATETIME DEFAULT (GETDATE())

Note that the table makes use of the XML data-type, which is new in SQL Server 2005. As you'd assume by its name, its job is to hold XML data.

Related links

Comments

1

Peter Loo - 11/05/06

This is a handy tool. Can it be customised to track changes to database tables (instead of just sql events)?
If changes are inserted into the audit trail table as snapshot XML data, can we use sql to report on differences between 2 snapshot records?

» Report offensive content

2

Peter Joint - 12/05/06

Neat approach, although I'd be concerned about the performance impact of putting triggers on data changes. Another approach is what Embarcadero have done with their DSAuditor solution (aquired from Ambeo last year) - having a solution that tracks all that, doesn't involve changing the database and is zero impact, I see as another good way to approach this issue.

» Report offensive content

3

Tim Chapman - 26/05/06

You can use DML triggers to track changes to data.
These triggers make use of the INSERTED and DELETED tables. In 2005 you can also use the OUTPUT statement for custom DML statement auditing. I've written an article about the OUTPUT statement: http://techrepublic.com.com/5100-9592_11-6074046.html?tag=search#

» Report offensive content

4

Tony Finnemore - 24/07/06

The major problem I perceive with in-house developed solutions, even smart ones like these, is that "authorised users" can still conduct "unauthorised activities" if they can gain access to the respository of audit data or the triggers etc. Then there is the performance impact of triggers - especially on high transaction systems!

There is only one SQL Server auditing product I know of which is self auditing and can tell you when and who changed the auditing configurations or audited data. This auditing tool - SQL compliance manager - from Idera was developed with the assistance of Ernst & Young, DBAs from the finance world and Microsoft who provided assistance with minimising impact on SQL Server resources.

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

4

Tony Finnemore - 24/07/06

The major problem I perceive with in-house developed solutions, even smart ones like these, is that "authorised users" can still conduct ... more

3

Tim Chapman - 26/05/06

You can use DML triggers to track changes to data. These triggers make use of the INSERTED and DELETED tables. In ... more

2

Peter Joint - 05/12/06

Neat approach, although I'd be concerned about the performance impact of putting triggers on data changes. Another approach is what ... more

Log in


Sign up | Forgot your password?

  • Staff Shadow chasing in browsers

    The punching and counterpunching continued in the ongoing web browser development bout. Each time one browser closes a feature gap, a new feature appears in one of the others -- how we ever put up with the years of browser stagnation, I'll never know. Read more »

    -- posted by Staff

  • Chris Duckett Safari gets Gears

    Since its release in May last year, Gears has supported only Internet Explorer and Firefox browsers. With the addition of Safari into the Gears fold, it closes the loop of major browsers to support Gears Read more »

    -- posted by Chris Duckett

  • Renai LeMay MyPerfect.com.au has potential

    Victorian Web start-up My Perfect has a strong story and rationale for why it will succeed. But it has to overcome some challenges and design flaws first. Read more »

    -- posted by Renai LeMay

What's on?