Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Resource Governor in SQL Server 2008
Tweaks in SQL Server Reporting Services
Configure Filestream in SQL Server 2008
Capture DDL Changes using Change Data Capture with SQL Server 2008 ...

More     
 
Latest FAQ's

SQL Server Reporting Server (SSRS) service is failing to start ...
Cannot Start SQL Server Service
Users are able to connect to report manager but not able ...
Errors when SQL Server Snapshot Replication is Running

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> developer >> Ownership Chains in SQL Server 2005 ...

Ownership Chains in SQL Server 2005

By : Amol Kulkarni
May 25, 2005

Page 2 / 3

Scenario II

John creates a stored procedure that references a table that he does not own but has SELECT permissions on (the owner of the table is Mary and she has granted select permissions to John).

John grants execute permissions on the stored procedure to Scott. When Scott executes the stored procedure, SQL Server verifies that he (the caller) has permission to execute the stored procedure. Scott has execute permission, but because John is not the owner of the referenced table, SQL Server checks to see whether Scott has permissions on the table. If Scott does not have permissions, the stored procedure statement fails.

1. Login as Mary and grant select permission to John on the students table.

GRANT SELECT ON students TO john

 

2. Login as John and create a SP ‘stud_sp_john’  

CREATE PROCEDURE stud_sp_john

AS

SELECT * FROM Mary.students

 

3. Grant execute permission on the SP ‘stud_sp_john’ to Scott.
 

             GRANT EXECUTE ON stud_sp_john TO Scott
 

 

4. Now login as Scott and execute the SP

             EXECUTE John.stud_sp_john

Note: This failure is due to a Broken Ownership Chain

In SQL Server 2005, the SP’s in scenario 1 and 2 can be also written as:

CREATE PROCEDURE stud_sp_john

WITH EXECUTE AS CALLER

AS SELECT * FROM Mary.students

EXECUTE AS CALLER is the default (backward compatible) behavior.

 

Scenario III

Mary creates a stored procedure that references a table that she does not own (John is owner of a table and has granted select permission to Mary) but has SELECT permissions on. She specifies EXECUTE AS USER = Mary in the CREATE PROCEDURE statement.

Mary grants execute permissions on the stored procedure to another user, Scott. When Scott executes the stored procedure, SQL Server verifies that he has permission to execute the stored procedure; however, permissions for the referenced table are checked for Mary. In this scenario, even though Scott did not have SELECT permissions on the table directly, he was able to access the data through the procedure, because Mary, in whose context the procedure was running, had access to the procedure.

1. Login as Mary and create a SP ‘stud_sp_mary’ with “WITH EXECUTE AS USER = Mary” option.

CREATE PROCEDURE stud_sp_mary

WITH EXECUTE AS USER = Mary

AS

SELECT * FROM students

 

2. Now grant execute permission on ‘stud_sp_mary’ to Scott

             GRANT EXECUTE ON stud_sp_mary TO Scott

 

3. Login as Scott and execute the SP ‘stud_sp_mary’

             EXECUTE Mary.stud_sp_mary


<< Prev Page     Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved