Skip to content

Commit 904887c

Browse files
authored
docs; Document minimal SQL Server permissions
Document minimal SQL Server permissions
2 parents 759f40f + d4ccec8 commit 904887c

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,61 @@ The results of some ad-hoc performance testing yielded that you can expect about
157157

158158
Do note that a broadcast message is considered a single message. Any call to `SendAsync` within a hub is a single message.
159159

160+
## SQL Server Permissions
161+
162+
By default, the library will automatically create its required schema and tables on startup (`AutoInstallSchema = true`). If you allow this, the SQL login used by your application will need elevated permissions to perform DDL operations. Alternatively, you can pre-install the schema using the [`install.sql`](./src/IntelliTect.AspNetCore.SignalR.SqlServer/Internal/SqlServer/install.sql) script and then configure `AutoInstallSchema = false` to run with minimal permissions.
163+
164+
### Minimal Runtime Permissions (Recommended for Production)
165+
166+
If you pre-install the database schema and set `AutoInstallSchema = false`, the application only needs the following permissions. Replace `SignalR` with your configured schema name and `YourHubName` with your hub's table name. Repeat for each table index from `0` to `TableCount - 1` (e.g. with the default `TableCount = 1`, you would have `Messages_YourHubName_0` and `Messages_YourHubName_0_Id`):
167+
168+
``` sql
169+
-- Permissions on message tables (repeat for each table index from 0 to TableCount - 1):
170+
GRANT SELECT, INSERT, DELETE ON [SignalR].[Messages_YourHubName_0] TO [YourUser];
171+
GRANT SELECT, UPDATE ON [SignalR].[Messages_YourHubName_0_Id] TO [YourUser];
172+
```
173+
174+
If Service Broker is enabled and you want to use it for real-time notifications (instead of falling back to polling), the `SqlDependency` mechanism requires additional permissions to create and manage its temporary Service Broker objects. The simplest approach is to grant the `db_owner` role:
175+
176+
``` sql
177+
EXEC sp_addrolemember 'db_owner', 'YourUser';
178+
```
179+
180+
If `db_owner` is too broad, the following individual permissions are required at a minimum, though `SqlDependency` may still require `db_owner` in some environments:
181+
182+
``` sql
183+
-- Required for SqlDependency to subscribe to query notifications:
184+
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [YourUser];
185+
186+
-- Required for SqlDependency to create and manage its temporary Service Broker objects in the dbo schema:
187+
GRANT CREATE PROCEDURE TO [YourUser];
188+
GRANT CREATE QUEUE TO [YourUser];
189+
GRANT CREATE SERVICE TO [YourUser];
190+
GRANT CONTROL ON SCHEMA::dbo TO [YourUser];
191+
GRANT REFERENCES ON CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] TO [YourUser];
192+
193+
-- Required for receiving Service Broker error notifications:
194+
GRANT RECEIVE ON QueryNotificationErrorsQueue TO [YourUser];
195+
```
196+
197+
### Schema Installation Permissions
198+
199+
If using the default `AutoInstallSchema = true`, the login needs permissions to create the schema and tables. The simplest but broadest approach is to grant the `db_ddladmin` and `db_datawriter` database roles. For more restricted access, grant only the specific permissions needed:
200+
201+
``` sql
202+
GRANT CREATE SCHEMA TO [YourUser];
203+
GRANT CREATE TABLE TO [YourUser];
204+
GRANT ALTER ON SCHEMA::[SignalR] TO [YourUser];
205+
GRANT INSERT ON SCHEMA::[SignalR] TO [YourUser];
206+
GRANT SELECT ON SCHEMA::[SignalR] TO [YourUser];
207+
```
208+
209+
If also using `AutoEnableServiceBroker = true`, the login needs `ALTER` permission on the database:
210+
211+
``` sql
212+
GRANT ALTER ON DATABASE::[YourDatabase] TO [YourUser];
213+
```
214+
160215
## License
161216

162217
[Apache 2.0](./LICENSE.txt).

0 commit comments

Comments
 (0)