Currently, I have denied some operation on system object by doing:
DENY INSERT, UPDATE, DELETE ON OBJECT::sph_syslog TO SQLEditorSpecificUser;
And it is not allowing me to do any direct operation on an object. Then I have given the following permission to execute and alter the stored procedure.
GRANT CONTROL ON SCHEMA::dbo TO SQLEditorSpecificUser;
GRANT ALTER ON SCHEMA::dbo TO SQLEditorSpecificUser;
Now, when I try to execute the stored procedure with following details:
ALTER PROCEDURE [AshishTest]
AS
BEGIN
UPDATE sph_syslog
SET duration = 8285
WHERE id = 1372042
END
On executing this stored procedure ( Execute AshishTest
), it is updating the syslog
table.
I do not want to update or delete syslog directly or indirectly. How I can achieve that?
1条答案
按热度按时间ix0qys7i1#
As mentioned in the comments, this is actually by design, and is how permission chaining works; if you give someone permission to (for example)
EXECUTE
a procedure and that procedureUPDATE
s a table that has the same owner then permission is still granted. This allows administrators toDENY
USER
s access to aTABLE
but they still have permission to use aVIEW
(which might, for example, expose fewer columns), or not allow aUSER
toUPDATE
a table directly but can through aPROCEDURE
(as it has additional workflow defined in it).The method Dan Guzman recommends in their comment is probably the "best" way; change the schema the object is on and ensure that schema is owned by a different
USER
(or notdbo
).An alternative method, if you "can't" do this (perhaps moving the object's schema will be a breaking change) would be to use a deferred statement by using
sys.sp_executesql
; this will also break the ownership chain.I demonstrate both in the below, but suggest that the schema solution is the better option: