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

Cross DB Chaining Madness Expand / Collapse
Author
Message
Posted Tuesday, January 29, 2013 7:09 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, October 18, 2014 9:49 AM
Points: 25, Visits: 169
At the risk of posting yet another message on cross chaining... I'm at my wits end. I've read and read until my eyes hurt. I'm missing something. All I want to do is create a view in database B that accesses an table in database A, that I don't want the user to ever access directly.

Here's the story: I have a giant database called "DataMart". In that database is a table innocuously called "Branch". According to the Auditors, the branch table contains data that will cause some people to go blind. Some of those people are my friends, and I would hate for that to happen (to the friends list).

I have a 2nd database called "MiniMart" where I plan to park views that a) reduces the number of objects they can see and b) restricts (or mangles) columns they cannot see.

Here is what I have:
SQL Server 2k8
Cross DB Chaining at the server is OFF.
Cross DB Chaining in both databases is ON
Trustworthy is ON for both databases.
Both databases are owned by the same user (idAdmin)
SELECT is revoked for PUBLIC on DataMart.DBO.Branch
my view and the Branch table are bothed owned by DBO.

I have a test user called "LowAccessTest", who exists as a user in DataMart but has no specific privileges (If I give this user db_datareader, they can see everything in the datamart database).

LowAccessTest is db_datareader in MiniMart.

In MiniMart, I have created a view:
create view DBO.limited_access_test as
select branch_nbr, name from datamart.dbo.branch
GO
grant select on limited_access_test to LowAccessTest

I then make a connection to MiniMart using LowAccessTest and attempt to query limited_access_test and I get:
Error: The SELECT permission was denied on the object 'BRANCH', database 'DataMart, schema 'dbo'. (State:42000, Native Code: E5)

If I make LowAccessTest a db_datareader in DataMart, my view works, but I can also query datamart.dbo.branch.

If I turn of db_datareader and grant Select on datamart.dbo.branch to LowAccessTest my view works, but I can also query datamart.dbo.branch.

What have I missed?


Post #1413413
Posted Wednesday, January 30, 2013 1:18 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:06 AM
Points: 225, Visits: 1,753
jchapman (1/29/2013)
...
I have a test user called "LowAccessTest", who exists as a user in DataMart but has no specific privileges (If I give this user db_datareader, they can see everything in the datamart database).


Why you want add LowAccessTest to role db_reader in the DataMart? You should give him only select on the table
Post #1413505
Posted Wednesday, January 30, 2013 6:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, October 18, 2014 9:49 AM
Points: 25, Visits: 169
I don't. I only included that to illustrate that if I open up access the user can query the table. Ideally, I do not want to grant select rights on the underlying table at all .. Just the view.
Post #1413608
Posted Wednesday, January 30, 2013 7:27 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:12 AM
Points: 7,135, Visits: 12,746
You should not have to enable the TRUSTWORTHY bit. In fact I would recommend turning that off if only enabled during this effort in an attempt to get something working.

Steps that work:

- Enable cross-database ownership chaining on DataMart and MiniMart databases.
- Create Database User in DataMart and MiniMart from same Server Login.
- Create view in MiniMart that references table in DataMart.
- Grant SELECT on VIEW in MiniMart.


Here is a quick demo:

USE master
GO
CREATE LOGIN LowAccessTest WITH PASSWORD = 'mypwd!'
GO
--------------------------------------------------------------------------
CREATE DATABASE MyDataMart
GO
ALTER AUTHORIZATION ON DATABASE::MyDataMart TO sa
ALTER DATABASE MyDataMart SET DB_CHAINING ON;
GO
USE MyDataMart
GO
CREATE USER LowAccessTest FROM LOGIN LowAccessTest WITH DEFAULT_SCHEMA = dbo;
GO
CREATE TABLE dbo.Branch (id INT)
GO
--------------------------------------------------------------------------
CREATE DATABASE MyMiniMart
GO
ALTER AUTHORIZATION ON DATABASE::MyMiniMart TO sa
ALTER DATABASE MyMiniMart SET DB_CHAINING ON;
GO
USE MyMiniMart
GO
CREATE USER LowAccessTest FROM LOGIN LowAccessTest WITH DEFAULT_SCHEMA = dbo;
GO
CREATE VIEW dbo.limited_access_test
AS
SELECT id
FROM MyDataMart.dbo.branch
GO
GRANT SELECT ON dbo.limited_access_test TO LowAccessTest
GO
--------------------------------------------------------------------------
-- succeeds
USE MyMiniMart
GO
EXECUTE AS LOGIN = 'LowAccessTest'
GO
SELECT * FROM dbo.limited_access_test;
GO
REVERT
GO
--------------------------------------------------------------------------
-- fails with error, as it should
USE MyDataMart
GO
EXECUTE AS LOGIN = 'LowAccessTest'
GO
SELECT * FROM dbo.Branch;
GO
REVERT
GO

And the cleanup:

USE master
ALTER DATABASE MyDataMart SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE MyDataMart
ALTER DATABASE MyMiniMart SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE MyMiniMart
DROP LOGIN LowAccessTest;



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1413630
Posted Thursday, January 31, 2013 3:24 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, October 18, 2014 9:49 AM
Points: 25, Visits: 169
Well I'm glad I wasn't completely crazy... I had the concept right... but obviously I missed a piece.

Thank you SO much for that code. I ran your example as is, and "poof" it worked, as advertised (not suprised, just pleased!).

I then modified the code to issue the alters to my existing databases... first pass, it didn't work. Second pass, I deleted the LowAccessTest user from both databases and started clean. "poof" it worked.

I think the key however, is (as you indicated in your checklist), is the database owners. If I issue a Alter Auth on one, and set the owner to SA, set the owner to idAdmin on the other, it's broken. Make them the same, and "poof".

I know I checked the owners... obviously I missed something, or just had so many plates spinning by that point, and stopped paying attention to the details.

I really appreciate the amount of time you spent on that script and the explaination. Thank you.

If you ever find your self in Northern New England, drop me a note; Dinner and and epic Belgium beers are on me.
Post #1414374
Posted Thursday, January 31, 2013 3:34 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:12 AM
Points: 7,135, Visits: 12,746
It was my pleasure. I am in Denver, CO and do not expect to be out that way in the near future but that's a heck of a nice offer, thanks for brightening my afternoon

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1414376
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse