Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Audit Logging to a separate database Expand / Collapse
Author
Message
Posted Thursday, February 21, 2013 7:54 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 07, 2014 7:31 AM
Points: 36, Visits: 200
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
Post #1422600
Posted Thursday, February 21, 2013 12:08 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
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

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1422741
Posted Thursday, February 21, 2013 12:15 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 07, 2014 7:31 AM
Points: 36, Visits: 200
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
Post #1422743
Posted Thursday, February 21, 2013 12:35 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
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

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1422753
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse