You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The authentication method you use to connect to a source SQL Server instance needs certain minimal permissions to query the requisite information. The required permissions are as follows:
| All User Databases | SELECT |`sys.sql_expression_dependencies`|
9
34
10
-
# Permissions required for SQL Server Assessment
11
-
The login used to connect to a source SQL Server instance needs certain minimal permissions to query the requisite information. The required permissions are as follows:
12
-
13
-
|Database|Permission|Object(s)|
14
-
|-|-|-|
15
-
|master|CONNECT ANY DATABASE||
16
-
|master|SELECT|sys.sql_expression_dependencies|
17
-
|master|EXECUTE|sys.xp_regenumkeys|
18
-
|master|VIEW DATABASE STATE||
19
-
|master|VIEW SERVER STATE||
20
-
|master|VIEW ANY DEFINITION||
21
-
|msdb|EXECUTE|dbo.agent_datetime|
22
-
|msdb|SELECT|dbo.sysjobsteps|
23
-
|msdb|SELECT|dbo.syssubsystems|
24
-
|msdb|SELECT|dbo.sysjobhistory|
25
-
|msdb|SELECT|dbo.syscategories|
26
-
|msdb|SELECT|dbo.sysjobs|
27
-
|msdb|SELECT|dbo.sysmaintplan_plans|
28
-
|msdb|SELECT|dbo.syscollector_collection_sets|
29
-
|msdb|SELECT|dbo.sysmail_profile|
30
-
|msdb|SELECT|dbo.sysmail_profileaccount|
31
-
|msdb|SELECT|dbo.sysmail_account|
32
-
|All User Databases|VIEW DATABASE STATE||
33
-
|All User Databases|SELECT|sys.sql_expression_dependencies|
34
-
35
35
## Special considerations for Always On Availability Groups
36
-
For SQL Server instances that host availability group replicas, it's recommended to provision a Windows Domain account with required permissions for assessment.
37
-
38
-
When SQL Server Authentication or a local Windows login is used, mismatched SIDs can prevent the custom login from resolving on the other replicas of the Always On Availability Group. To prevent this issue, after the login is created on the first of all the instances that host an Always On Availability Group, note the SID of the login created. Provide this SID as a parameter when creating the login in the instances hosting the remaining replicas of the Always On Availability Group.
39
-
40
-
## Configure the custom login for Assessment
41
36
42
-
The following are sample scripts for creating a login and provisioning it with the necessary permissions.
37
+
For SQL Server instances that host availability group replicas, provision a Windows domain account with the required permissions for assessment.
38
+
39
+
When you use SQL Server Authentication or a local Windows authentication, mismatched SIDs can prevent the custom authentication from resolving on the other replicas of the Always On Availability Group. To prevent this problem, after you create the authentication on the first instance that hosts an Always On Availability Group, note the SID of the authentication. Provide this SID as a parameter when creating the authentication in the instances hosting the remaining replicas of the Always On Availability Group.
40
+
41
+
## Configure the custom authentication for assessment
42
+
43
+
The following sample scripts show how to create an authentication and grant it the necessary permissions.
44
+
45
+
### Windows Authentication
43
46
44
-
### Windows Authentication
45
-
46
47
```sql
47
48
-- Create a login to run the assessment
48
49
use master;
49
-
-- If a SID needs to be specified, add here
50
+
-- If a SID needs to be specified, add here
50
51
DECLARE @SID NVARCHAR(MAX) = N'';
51
52
CREATE LOGIN [MYDOMAIN\MYACCOUNT] FROM WINDOWS;
52
-
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROMsys.sysloginswhere name ='MYDOMAIN\MYACCOUNT'
53
-
IF (ISNULL(@SID,'') !='')
54
-
PRINT N'Created login [MYDOMAIN\MYACCOUNT] with SID = '+ @SID
55
-
ELSE
56
-
PRINT N'Login creation failed'
57
-
GO
58
-
59
-
-- Create user in every database other than tempdb and model and provide minimal read-only permissions.
53
+
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROMsys.sysloginswhere name ='MYDOMAIN\MYACCOUNT'
54
+
IF (ISNULL(@SID,'') !='')
55
+
PRINT N'Created login [MYDOMAIN\MYACCOUNT] with SID = '+ @SID
56
+
ELSE
57
+
PRINT N'Login creation failed'
58
+
GO
59
+
60
+
-- Create user in every database other than tempdb and model and provide minimal read-only permissions.
60
61
use master;
61
62
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY CREATE USER [MYDOMAIN\MYACCOUNT] FOR LOGIN [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
62
63
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY GRANT SELECT ON sys.sql_expression_dependencies TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
63
64
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY GRANT VIEW DATABASE STATE TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
64
65
GO
65
-
66
+
66
67
-- Provide server level read-only permissions
67
68
use master;
68
69
BEGIN TRY GRANTSELECTONsys.sql_expression_dependencies TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
@@ -71,12 +72,12 @@ The following are sample scripts for creating a login and provisioning it with t
71
72
BEGIN TRY GRANT VIEW SERVER STATE TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
72
73
BEGIN TRY GRANT VIEW ANY DEFINITION TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
73
74
GO
74
-
75
+
75
76
-- Required from SQL 2014 onwards for database connectivity.
76
77
use master;
77
78
BEGIN TRY GRANT CONNECT ANY DATABASE TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
78
79
GO
79
-
80
+
80
81
-- Provide msdb specific permissions
81
82
use msdb;
82
83
BEGIN TRY GRANT EXECUTE ON [msdb].[dbo].[agent_datetime] TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
@@ -91,7 +92,7 @@ The following are sample scripts for creating a login and provisioning it with t
91
92
BEGIN TRY GRANTSELECTON [msdb].[dbo].[sysmail_profileaccount] TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
92
93
BEGIN TRY GRANTSELECTON [msdb].[dbo].[sysmail_account] TO [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
93
94
GO
94
-
95
+
95
96
-- Clean up
96
97
--use master;
97
98
-- EXECUTE sp_MSforeachdb 'USE [?]; BEGIN TRY DROP USER [MYDOMAIN\MYACCOUNT] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;'
@@ -100,37 +101,37 @@ The following are sample scripts for creating a login and provisioning it with t
100
101
```
101
102
102
103
### SQL Server Authentication
103
-
104
+
104
105
```sql
105
106
-- Create a login to run the assessment
106
107
use master;
107
-
-- If a SID needs to be specified, add here
108
+
-- If a SID needs to be specified, add here
108
109
DECLARE @SID NVARCHAR(MAX) = N'';
109
-
IF (@SID = N'')
110
-
BEGIN
111
-
CREATE LOGIN [evaluator]
112
-
WITH PASSWORD ='<provide a strong password>'
113
-
END
114
-
ELSE
115
-
BEGIN
116
-
CREATE LOGIN [evaluator]
117
-
WITH PASSWORD ='<provide a strong password>'
118
-
, SID = @SID
119
-
END
120
-
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROMsys.sysloginswhere name ='evaluator'
121
-
IF (ISNULL(@SID,'') !='')
122
-
PRINT N'Created login [evaluator] with SID = '+@SID
123
-
ELSE
124
-
PRINT N'Login creation failed'
125
-
GO
126
-
127
-
-- Create user in every database other than tempdb and model and provide minimal read-only permissions.
110
+
IF (@SID = N'')
111
+
BEGIN
112
+
CREATE LOGIN [evaluator]
113
+
WITH PASSWORD ='<provide a strong password>'
114
+
END
115
+
ELSE
116
+
BEGIN
117
+
CREATE LOGIN [evaluator]
118
+
WITH PASSWORD ='<provide a strong password>'
119
+
, SID = @SID
120
+
END
121
+
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROMsys.sysloginswhere name ='evaluator'
122
+
IF (ISNULL(@SID,'') !='')
123
+
PRINT N'Created login [evaluator] with SID = '+@SID
124
+
ELSE
125
+
PRINT N'Login creation failed'
126
+
GO
127
+
128
+
-- Create user in every database other than tempdb and model and provide minimal read-only permissions.
128
129
use master;
129
130
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY CREATE USER [evaluator] FOR LOGIN [evaluator]END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
130
131
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY GRANT SELECT ON sys.sql_expression_dependencies TO [evaluator]END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
131
132
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) BEGIN TRY GRANT VIEW DATABASE STATE TO [evaluator]END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH'
132
133
GO
133
-
134
+
134
135
-- Provide server level read-only permissions
135
136
use master;
136
137
BEGIN TRY GRANTSELECTONsys.sql_expression_dependencies TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
@@ -139,12 +140,12 @@ The following are sample scripts for creating a login and provisioning it with t
139
140
BEGIN TRY GRANT VIEW SERVER STATE TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
140
141
BEGIN TRY GRANT VIEW ANY DEFINITION TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
141
142
GO
142
-
143
+
143
144
-- Required from SQL 2014 onwards for database connectivity.
144
145
use master;
145
146
BEGIN TRY GRANT CONNECT ANY DATABASE TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
146
147
GO
147
-
148
+
148
149
-- Provide msdb specific permissions
149
150
use msdb;
150
151
BEGIN TRY GRANT EXECUTE ON [msdb].[dbo].[agent_datetime] TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
@@ -159,7 +160,7 @@ The following are sample scripts for creating a login and provisioning it with t
159
160
BEGIN TRY GRANTSELECTON [msdb].[dbo].[sysmail_profileaccount] TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
160
161
BEGIN TRY GRANTSELECTON [msdb].[dbo].[sysmail_account] TO [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;
161
162
GO
162
-
163
+
163
164
-- Clean up
164
165
--use master;
165
166
-- EXECUTE sp_MSforeachdb 'USE [?]; BEGIN TRY DROP USER [evaluator] END TRY BEGIN CATCH PRINT ERROR_MESSAGE() END CATCH;'
@@ -169,12 +170,12 @@ The following are sample scripts for creating a login and provisioning it with t
169
170
170
171
## How to use the permissions script
171
172
172
-
The permissions script can be used as follows:
173
+
Use the permissions script as follows:
173
174
174
-
- Save the appropriate permissions script (with valid password string) as an_.sql_ file, say _c:\workspace\MinPermissions.sql_
175
-
- Connect to the instance(s) using an account with sysadmin permissions and execute the script. You can use **SQL Server Management Studio** or **sqlcmd**. The following example uses a trusted connection.
175
+
- Save the appropriate permissions script (with a valid password string) as a_.sql_ file, such as _c:\workspace\MinPermissions.sql_.
176
+
- Connect to the instances by using an account with sysadmin permissions and run the script. You can use SQL Server Management Studio or **sqlcmd**. The following example uses a trusted connection.
0 commit comments