SQL Server Permissions on Stored Procs with dynamic SQL

前端 未结 3 1043
滥情空心
滥情空心 2020-12-10 03:51

I have a database which has an application role. The role members all belong to a group in Active Directory. Instead of giving the role permissions to select from the tables

相关标签:
3条回答
  • 2020-12-10 04:34

    Can you use impersonation to another ID with the required permissions?

    SET @SQL = N'
    EXECUTE AS USER = ''TrustedUser'';
    SELECT * 
    FROM dbo.uvView1 
    INNER JOIN uvView2 ON uvView1.Id = uvView2.Id'
    
    EXEC sp_executesql @SQL
    
    0 讨论(0)
  • 2020-12-10 04:37

    No. Is there any way you can change it to not use dynamic SQL?

    0 讨论(0)
  • 2020-12-10 04:51

    Yes.

    Add an EXECUTE AS CALLER clause to the procedure, then sign the stored procedure and give the required permission to the signature. This is 100% safe, secure and bullet proof. See Signing Procedures with Certificates.

    0 讨论(0)
提交回复
热议问题