Security7:管理SQL Server Agent的权限

SQL Server Agent对象包括警报(Alert),操作员(Operator),Job,调度(Schedule)和代理(Proxy),SQL Server使用msdb系统数据库管理Agent 对象的权限,msdb内置三个固定数据库角色,按照权限从小到大的顺序,依次是:SQLAgentUserRoleSQLAgentReaderRole 和SQLAgentOperatorRole。如果一个用户不是这三个角色或sysadmin角色中的成员,那么该用户通过SSMS的Object Explorer看不到Agent节点。一个用户必须是SQLAgent的角色或sysadmin角色的成员,才能使用SQL Server Agent。

另外,Agent的权限,还跟代理(Proxy)的访问权限有关,代理是用来执行Job Step的,只有建立代理和登陆(Login)之间的映射,用户创建(Own)的Job才能执行。

一,Agent固定数据库角色

SQLAgentUserRole 角色被授予操作Agent的最小权限的集合,其成员只能对其创建的本地Job和Job Schedule具有操作权限,也就是有,该角色的成员对于Owner是自己的Job具有权限,并且不能修改job的所有权(Ownership)。

SQLAgentUserRole 角色具有的权限:

  • 具有操作本地Job和Job Schedule的所有权限,包括创建(Create)、删除(Delete),修改(Modify),启用(Enable)、禁用(Disable)、执行(Execute)、开始(Start)、停止(Stop)等,但是不能修改Job的所有权关系(Ownership);
  • 查看Owned Jobs的执行日志,但是不具有删除历史日志的权限;
  • 查看可用的Operator列表;
  • 查看可用的Proxy列表;

SQLAgentReaderRole 角色,除了具有Multiserver jobs的查看权限之外,和SQLAgentUserRole角色的权限相同;

SQLAgentOperatorRole 角色,除了具有查看警告(Alert)的列表和属性的权限之外,和SQLAgentReaderRole 角色的权限相同;

SQLAgentUserRoleSQLAgentReaderRole 和SQLAgentOperatorRole 都对自己创建的Job具有操作权限,都不能修改Job的所有权:

 

 sysadmin 角色的成员,具有SQL Server Agent的全部权限,能够修改Job的所有权。

二,执行Job Step的权限

在执行Job Step时,SQL Server Agent使用两种类型的权限,分别是Job Owner和代理(Proxy)。如果创建的Job Step是 Transact-SQL script (T-SQL) 类型,那么使用Job Owner的权限去执行TSQL脚本;如果创建的Job Step是另外11种类型种的一种,那么使用代理的权限去执行Job Step。在Job Step执行之前,Agent模拟凭证指定的Windows User的权限,在该权限范围(Security Context)内执行Job Step,使Job Step有权限访问SQL Server 实例之外的资源。

代理(Proxy)使得Job Step在特定的安全上下文中执行,DBA需要创建代理,并为代理设置必须的权限。

SQL Server Agent lets the database administrator run each job step in a security context that has only the permissions required to perform that job step, which is determined by a SQL Server Agent proxy. To set the permissions for a particular job step, you create a proxy that has the required permissions and then assign that proxy to the job step. A proxy can be specified for more than one job step. For job steps that require the same permissions, you use the same proxy.

1,创建代理

每一个Proxy都关联一个凭证(Credential),凭证定义了执行Job Step的安全上下文(Security Context)。使用SSMS创建代理,在SQL Server Agent目录下打开新建代理账户(New Proxy Account)的向导,输入新建的代理名称和关联的凭证名称,从11个子系统(subsystem)列表中选择“SQL Server Intergration Services Package”,该子系统用于执行SSIS的Package。

由于代理的权限是由凭证决定的,因此,在创建代理时,为了有效管控执行Job Step的权限,一般情况下,需要为代理(Proxy)创建专用的用户账户,并未用户授予必需的权限,

  • Create dedicated user accounts specifically for proxies, and only use these proxy user accounts for running job steps.

  • Only grant the necessary permissions to proxy user accounts. Grant only those permissions actually required to run the job steps that are assigned to a given proxy account.

2,授予Login访问代理的权限

在SQL Server中,不是所有的login都有权限访问Proxy。为Proxy添加服务器级别(Server-Level)的安全主体(Login),授予其访问Proxy的权限,这样,用户就能够引用Proxy去执行Job Step。

在Principals Tab中,授予Login,服务器角色(server role)或msdb数据库角色访问Proxy的权限。只有被授予访问Proxy权限的Principal,才能在Job Step中使用Proxy。默认情况下,固定服务器角色 sysadmin的成员有权限访问实例中的所有Proxy。

 

3,引用代理

如果Login有权限访问Proxy,或者Login属于有权限访问Proxy的服务器角色(Server Role),那么用户能够在Job Step中使用Proxy,例如,在创建Job Step,从Run as 列表种选择可访问的Proxy:

三,安全组(Security Group)

在Windows 域环境中,如果把Job的Owner设置为Security Group(SG),该组的成员无法访问该Job,只有把Job的Owner设置为用户的Windows 账户时,用户才能操作Job。

 

参考文档:

SQL Server Agent

Implement SQL Server Agent Security

SQL Server Agent Fixed Database Roles

Setting Up Your SQL Server Agent Correctly

posted @ 2017-11-24 13:59  悦光阴  阅读(3863)  评论(0编辑  收藏  举报