Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Audit Logging to a separate database


Audit Logging to a separate database

Author
Message
andykr-773587
andykr-773587
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 276
Here is the scenario:
On a single server there are two databases:
DB1 = OLTP database for an application
DB2 = Audit Log Database
Cross database ownership is enabled
Both databases are marked as Trustworthy

There is an Active Directory Group used by the application to connect to the database and that group is assigned to a Database Role that exists in both databases. This role has the following permissons ONLY
Stored Procedure = Execute
Stored Procedure = View Definition
View = SELECT
Access to all other objects are denied.

Certain tables in DB1 need to be audited, and have triggers on them that detect changed values and write those values out to tables in DB2.

Tables and Triggers in DB1 are all in the dbo schema
Audit Log tables in DB2 are in the dbo schema

The Stored procedures in DB1 that actually perform the updates are in the ZBO schema, and are called from exposed procedures in the DBO schema.

This all works perfectly when I am logged in as me (SysAdmin) but when logged in as the application user all changes are applied correctly, and there are no errors, but the audit logs remain empty.

It makes no difference whether the trigger does a direct insert into the audit tables (using three-part naming of course) or calls a stored procedure in DB2 that does the insert. Nothing gets written if the user is a member of the application role.

I have tried explicitly granting SELECT/INSERT/UPDATE permissions on the tables in DB2 to the application role
I have tried explicitly setting the properties of the app role in DB2 (the log database) to dbo - still no good.

I even tried moving the audit tables back into the same database (i.e. DB1) and it still doesn't work!

I am guessing that I need some particular combination of settings here, but I can't figure out what that is.

Has anyone got any ideas?

----
Regards
Andy Kramek
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8243 Visits: 14368
andykr-773587 (2/21/2013)
Here is the scenario:
On a single server there are two databases:
DB1 = OLTP database for an application
DB2 = Audit Log Database
Cross database ownership is enabled
Both databases are marked as Trustworthy

There is an Active Directory Group used by the application to connect to the database and that group is assigned to a Database Role that exists in both databases. This role has the following permissons ONLY
Stored Procedure = Execute
Stored Procedure = View Definition
View = SELECT
Access to all other objects are denied.

Certain tables in DB1 need to be audited, and have triggers on them that detect changed values and write those values out to tables in DB2.

Tables and Triggers in DB1 are all in the dbo schema
Audit Log tables in DB2 are in the dbo schema

The Stored procedures in DB1 that actually perform the updates are in the ZBO schema, and are called from exposed procedures in the DBO schema.

This all works perfectly when I am logged in as me (SysAdmin) but when logged in as the application user all changes are applied correctly, and there are no errors, but the audit logs remain empty.

It makes no difference whether the trigger does a direct insert into the audit tables (using three-part naming of course) or calls a stored procedure in DB2 that does the insert. Nothing gets written if the user is a member of the application role.

I have tried explicitly granting SELECT/INSERT/UPDATE permissions on the tables in DB2 to the application role
I have tried explicitly setting the properties of the app role in DB2 (the log database) to dbo - still no good.

I even tried moving the audit tables back into the same database (i.e. DB1) and it still doesn't work!

I am guessing that I need some particular combination of settings here, but I can't figure out what that is.

Has anyone got any ideas?


If the insert failed I would expect an error to be raised, unless it is being trapped by a TRY/CATCH in the trigger and not being bubbled out to stop the auditable transaction. Can you post some trigger code representative of the logic and error handling?

When you say 'application role' do you mean an application role or do you mean the User-defined Database Role the application is a member of?

To do cross-database calls transparently you would need to setup cross-database ownership chaining, else you could look into signing the triggers with certificates so the security context can be changed within them to a login capable of writing to the other database without elevating the permissions of the callers.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
andykr-773587
andykr-773587
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 276
Thanks for the reply but actually I solved the issue without implementing cross-database chaining.

By granting the "VIEW DEFINITION" permission on the source table, and adding the user to the dbReader/dbWriter database role on the target table everything is working fine.

----
Regards
Andy Kramek
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8243 Visits: 14368
By granting the "VIEW DEFINITION" permission on the source table

Are you sure that had anything to do with anything?

, and adding the user to the dbReader/dbWriter database role on the target table everything is working fine.

That will get the job done but it defeats the purpose of using stored procedures since your Users can now directly access the Audit tables, which I would think would also defeat the purpose of having the Audit tables.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search