首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQlDependency的权限

SQlDependency的权限
EN

Stack Overflow用户
提问于 2021-06-27 06:32:15
回答 1查看 80关注 0票数 1

我有一个web服务,它使用ASP.NET缓存和SqlDependency来使缓存无效。用于SqlDependency的命令依赖于存储过程。

问题在于,web服务数据库用户至少拥有仅具有存储过程执行权限的特权。由于用户没有CREATE PROCEDURE权限,订阅时引发SqlException "CREATE PROCEDURE permission“。

如何解决为用户提供最低权限的问题?

EN

回答 1

Stack Overflow用户

发布于 2021-06-27 06:32:15

SqlDependency动态创建和删除数据库对象以支持查询通知。要允许具有最低权限的用户执行这些语句,可以为SqlDependency对象创建一个单独的模式,并将其指定为只读用户的默认模式。用户当然需要对您的存储过程拥有execute权限,并且还需要模式限定的对象名(最佳实践),它们位于不同的模式(例如dbo)中。

下面是一个带注释的示例脚本,它创建模式并将权限授予现有的最低特权用户(此处名为SqlNotificationUser )。

代码语言:javascript
复制
--create user for schema ownership
CREATE USER SqlDependencySchemaOwner WITHOUT LOGIN;
GO

--needed to allow activated cleanup proc to drop SqlDependency service owned by minimally-privileged user
GRANT ALTER ANY SERVICE TO SqlDependencySchemaOwner;
GO

--create schema for SqlDependency objects CREATE SCHEMA SqlDependency 
AUTHORIZATION SqlDependencySchemaOwner;
GO
 
--set default schema of SqlDependency schema owner (internal SqlDependecy procs do not schema-qualify object names)
ALTER USER SqlDependencySchemaOwner WITH DEFAULT_SCHEMA = SqlDependency;

--create minimally privileged login
CREATE LOGIN SqlNotificationUser WITH PASSWORD='SqlUserSt0rongP@assord';

--create minimally privileged user with default schema SqlDependency 
CREATE USER SqlNotificationUser WITH DEFAULT_SCHEMA = SqlDependency;

--grant user control permissions on SqlDependency schema
GRANT CONTROL ON SCHEMA::SqlDependency TO SqlNotificationUser;
 
--grant user impersonate permissions on SqlDependency schema owner 
GRANT IMPERSONATE ON USER::SqlDependencySchemaOwner TO SqlNotificationUser;
GO
 
--grant database permissions needed to create and use SqlDependency objects
GRANT CREATE PROCEDURE TO SqlNotificationUser;
GRANT CREATE QUEUE TO SqlNotificationUser; 
GRANT CREATE SERVICE TO SqlNotificationUser;
GRANT REFERENCES ON CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] TO SqlNotificationUser;
GRANT VIEW DEFINITION TO SqlNotificationUser;
GRANT SELECT to SqlNotificationUser;
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO SqlNotificationUser;
GRANT RECEIVE ON QueryNotificationErrorsQueue TO SqlNotificationUser;
GO
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68146706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档