2016-11-20 41 views
0

工作,我有以下幾點看法(所謂view3授予權限似乎無法在視圖

enter image description here

我創建了一個角色,並授予它只是SELECTUPDATE權利兩列。

CREATE ROLE Testrole 
GRANT SELECT (Doc_ID, [Total Attentions]) ON view3 TO Testrole 

然後我分配的作用,已創建

ALTER ROLE Testrole ADD MEMBER test 

但是用戶(test)檢查時,如果一切正常的交易執行,所有的列顯示,而不是需要的兩個(上面的圖像相同)。

這是腳本

CREATE LOGIN logtest 
    WITH PASSWORD = 'logtest' 

CREATE USER test 
    FOR LOGIN logtest 

CREATE ROLE Testrole 
GRANT SELECT (Doc_ID, [Total Attentions]) ON view3 TO Testrole 
ALTER ROLE Testrole ADD MEMBER test 


SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 

BEGIN TRANSACTION 
    EXECUTE AS USER = 'test' 

    SELECT * /*This should give an error*/ 
     FROM view3 

    SELECT Doc_ID, [Total Attentions] /*This should work just fine*/ 
     FROM view3 

    REVERT 

ROLLBACK 

回答

1

授予權限是累積的。這些症狀表明存在視圖級別(所有列)權限,從此角色或其他角色繼承。運行下面的查詢來查看是否是這種情況。

SELECT 
     permission_name 
    , OBJECT_NAME(major_id) AS ObjectName 
    , CASE WHEN c.name IS NULL THEN 'All Columns' ELSE c.name END AS ColumnName 
    , USER_NAME(grantee_principal_id) AS Gratee 
FROM sys.database_permissions AS p 
LEFT JOIN sys.columns AS c ON 
    c.object_id = p.major_id 
    AND c.column_id = p.minor_id 
WHERE 
    major_id = OBJECT_ID(N'view3'); 
+0

我跑了它,它表明: 'PERMISSION_NAME:SELECT OBJECTNAME:VIEW3 的ColumnName:所有列 承授人:test' 這表明,不知何故,我授予'test' SELECT權限所有列?如果我沒有明確地這樣做,怎麼可能呢?如何解決這個問題(我的意思是,將SELECT或UPDATE特權限制在所有列中)? – Jazz

+0

通過將'REVOKE SELECT ON view3 FROM test'並再次執行,問題依然存在。 – Jazz

+0

嘗試執行'REVOKE SELECT ON view3 FROM test',驗證由於沒有權限,用戶測試失敗導致SELECT'失敗,然後再次授予列權限。我希望只有具有授權列的SELECT才能成功。 –