Replace Ownership Chaining in SQL Server!

Replace Ownership Chaining in SQL Server!

In my previous post 'Mitigating Double Hop in SQL Server', I have explained about the double hop issue and the resolution within the same database. Double hop can occur in different databases, which is called 'Cross Database Ownership Chaining'. In SQL Server 2000 Cross Database Ownership Chaining was a mechanism to allow DML access to other database resources such as table without explicitly granting the permission of access to the user.

Unfortunately, Microsoft does not recommend to use this mechanism in SQL Server 2000 due to security risks.(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_security_4iyb.asp). Fortunately, in SQL Server 2005 and later, DBAs are able to resolve this matter with two different ways which is first, EXECUTE AS command and second, digital signatures.

While this approach has some advantages, including:

  1. No need to create/re-use a login for the application
  2. Works as a CDOC replacement, in addition, works with dynamic SQL
  3. Denied permissions on the caller will be honored
  4. Easier to script for ISV applications (i.e. the signature can be precalculated)
  5. Can be easily adapted for either DB or server scoped permissions

As any other security feature, this approach also has some limitations you should consider before deploying:

  1. Doesn’t work if the operation requires creating an object or use the calling’s primary identity. Do not rely on implicit user creation!
  2. Be extra careful when using dynamic SQL as SQL injection attacks can abuse the escalated privileges.
  3. Need to write the certificate to disk (at least temporarily) in order to create the certificate in 2 or more databases.
  4. If you require calling nested modules, each one of the nested modules should be signed or counter signed as well.

Scenario: John has permission to execute SP_A in DB_A, which as below figure shows, SP_A retrieves data from table dbo.TA in DB_B, which John does not have "Select" permission on dbo.TA table in DB_B.

Solution: The above scenario is same as multiple hops, the only different is the one of the resources is in the different database and the user does not have permission on that specific resource. To resolve this issue, administrator needs to create a certificate and sign the specific stored procedure and then remove the private key, after that, administrator needs to back up the certificate and restore it in the destination server. At the final step, he/she needs to create a user from the certificate and assign proper permission to it and needs to make sure that the Trustworthy option of both databases are enabled.

Below codes resolve the ownership chaining issue for mentioned scenario.

To view or add a comment, sign in

More articles by Hamid J. Fard

  • My Success Guide - Plan for Future

    Sometimes happen when you get wrapped up in your routine life till forget to articulate purpose of living clearly in…

    3 Comments
  • My Success Guide - Preface

    It's been a while I was having a dilemma on writing "My Success Guide" series of chapters. The "My Success Guide" is a…

    5 Comments
  • Ai-DBA | Frequently Asked Questions

    How Ai-DBA works? Database administration is very crusial task which requies lots of time to interpret and analyze the…

  • How to Update SQL Server Statistics in Heavy Workload Database

    Sometimes we do need to disable AUTO_STATS_UPDATE or AUTO_STATS_UPDATE_ASYNC due to many reasons such as database…

    3 Comments
  • SQL Server Temporary Tables and Performance Impact

    It’s been a while, that I did not write up any blog post. So as the title mentions, I would like to write about…

  • Boost-Up SQL Server Performance with Minimal Investment

    DBAs are always under pressure to boost-up the database performance by tuning queries and re-fining the database design…

    5 Comments
  • Why SQL Server Optimization Matters?

    Database optimization is the act of design and developing database systems to take maximum advantage of the resources…

    2 Comments
  • Why SQL Server Health Check Matters?

    Deep down I know just how important it is to schedule the time to do SQL Server health check-up, and I know you are not…

  • SQL Server High Availability Solutions

    It is quiet tough to decide what kind of high availability solution is available on the table and which one can fit all…

    2 Comments
  • Why SQL Server Consolidation Matters?

    Reduce your cost and improve your agility with SQL Server Consolidation I want to bring everyone on the same page on…

    3 Comments

Others also viewed

Explore content categories