SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Tables and Views and Ownership Chains Oh My


Tables and Views and Ownership Chains Oh My

Author
Message
Deuce
Deuce
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2160 Visits: 14
Probably asked and answered 100 times but I'm stuck.

Have a production database and I need to give a third party access to a subset of data via views. I do not want them to have access to the underlying tables as that would defeat the purpose.

db1 has table [Location]
db2 has view [Location]

Database Owner of both db1 and db2 is the same login.
Schema of both [location] objects is dbo, schema owner is DBO.
user myLogin exists in both db1 and db1
myLogin has been granted Select permission on view [Location]
table [Location] has permissions assigned to two custom Database Roles of which myLogin is not a member


select * from location fails
Msg 229, Level 14, State 5, Line 1
The SELECT permission was denied on the object 'Location'



Deuce
Deuce
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2160 Visits: 14
Bah! SQL doesn't enable ownership chaining by default.

https://msdn.microsoft.com/en-us/library/bb669059(v=vs.110).aspx



Erland Sommarskog
Erland Sommarskog
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21112 Visits: 886
Enabling DB chaining for the two databases is probably the simple way out.

However, beware that if one user is db_owner in one database and plain user in the other, this user can exploit the fact that ownership chaining is in force access data in the other database he should not have access to.

For a longer discussion see the article Giving Permissions through Stored Procedures on my web site.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Brian Kelley
Brian Kelley
Keeper of the Duck
Keeper of the Duck (94K reputation)

Group: Moderators
Points: 94967 Visits: 1929
No, cross-database ownership chaining is not enabled by default and you couldn't disable it. It used to be, until SQL Server 2000 SP3. After that, you must enable yourself. See Erland's warnings about enabling it. Make sure you don't expose more than you expected. It's a feature because there's a time and place for it. sounds like you've got such a case.

K. Brian Kelley
@kbriankelley
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