Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 10 Assigning Server and Database Roles. Module Overview Working with Server Roles Working with Fixed Database Roles Creating User-defined Database.

Similar presentations


Presentation on theme: "Module 10 Assigning Server and Database Roles. Module Overview Working with Server Roles Working with Fixed Database Roles Creating User-defined Database."— Presentation transcript:

1 Module 10 Assigning Server and Database Roles

2 Module Overview Working with Server Roles Working with Fixed Database Roles Creating User-defined Database Roles

3 Lesson 1: Working with Server Roles Server-scoped Permissions Typical Server-scoped Permissions Overview of Fixed Server Roles public Server Role Demonstration 1A: Assigning Fixed Server Roles

4 Server-scoped Permissions Permissions at the server level can be assigned in two ways:  Fixed server roles  Specific server-scoped permissions Minimize the use of fixed server roles  Assign more specific permissions USE master; GO GRANT ALTER ON LOGIN::HRApp TO [AdventureWorks\Holly]; GO GRANT ALTER ANY DATABASE TO [AdventureWorks\Holly]; GO USE master; GO GRANT ALTER ON LOGIN::HRApp TO [AdventureWorks\Holly]; GO GRANT ALTER ANY DATABASE TO [AdventureWorks\Holly]; GO

5 Typical Server-scoped Permissions Current database must be master when assigning server- scoped permissions Permissions assignments are visible by querying the sys.server_permissions view Typical Server-scoped Permissions ALTER ANY DATABASEALTER TRACE BACKUP DATABASEBACKUP LOG CONNECTCREATE DATABASE VIEW ANY DEFINITIONVIEW SERVER STATE

6 Overview of Fixed Server Roles RoleDescriptionServer-level Permission sysadminPerform any activityCONTROL SERVER (with GRANT option) dbcreator Create and alter databasesALTER ANY DATABASE diskadmin Manage disk filesALTER RESOURCES serveradmin Configure server-wide settings ALTER ANY ENDPOINT, ALTER RESOURCES, ALTER SERVER STATE, ALTER SETTINGS, SHUTDOWN, VIEW SERVER STATE securityadmin Manage and audit server loginsALTER ANY LOGIN processadmin Manage SQL Server processes ALTER ANY CONNECTION ALTER SERVER STATE bulkadmin Run the BULK INSERT statementADMINISTER BULK OPERATIONS setupadmin Configure replication and linked servers ALTER ANY LINKED SERVER

7 public Server Role Not considered a fixed server role as its permissions can be changed By default, is granted:  VIEW ANY DATABASE permission  CONNECT permission on default endpoints public is a special server role with server-scope.

8 Demonstration 1A: Assigning Fixed Server Roles In this demonstration, you will see:  How to view the available fixed server roles using the GUI  How to assign a fixed server role using the GUI  How to view the available fixed server roles using T-SQL  How to assign a fixed server role using T-SQL  How to view the members of fixed server roles using T-SQL  How to view the server permissions that are currently assigned

9 Lesson 2: Working with Fixed Database Roles Database-scoped Permissions Overview of Fixed Database Roles Assigning Users to Roles Database Owner Demonstration 2A: Managing Roles and Users

10 Database-scoped Permissions Permissions at the database level can be assigned in three ways:  Fixed database roles  User-defined database roles  Specific database-scoped permissions Minimize the use of fixed database roles  Assign more specific permissions USE AdventureWorks2008R2; GO GRANT CREATE TABLE TO HRManager; GO GRANT VIEW DEFINITION TO James; GO USE AdventureWorks2008R2; GO GRANT CREATE TABLE TO HRManager; GO GRANT VIEW DEFINITION TO James; GO

11 Overview of Fixed Database Roles RoleDescription db_owner Perform any configuration and maintenance activities on the DB and can drop it db_securityadmin Modify role membership and manage permissions db_accessadmin Add or remove access to the DB for logins db_backupoperator Back up the DB db_ddladmin Run any DDL command in the DB db_datawriter Add, delete, or change data in all user tables db_datareader Read all data from all user tables db_denydatawriter Cannot add, delete, or change data in user tables db_denydatareader Cannot read any data in user tables

12 Assigning Users to Roles Users can be assigned to roles  Using GUI  Using T-SQL USE AdventureWorks2008R2; GO EXEC sp_addrolemember 'db_datareader', 'James'; GO USE AdventureWorks2008R2; GO EXEC sp_addrolemember 'db_datareader', 'James'; GO

13 Database Owner dbo The sa login and members of sysadmin role are mapped to dbo account, along with the owner of the database

14 Demonstration 2A: Managing Roles and Users In this demonstration you will see:  How to view the available fixed database roles using the GUI  How to assign a fixed database role using the GUI  How to view the available fixed database roles using T-SQL  How to assign a fixed database role using T-SQL  How to view the members of fixed database roles using T-SQL

15 Lesson 3: Creating User-defined Database Roles Working with User-defined Database Roles Applying Roles in Common Scenarios Demonstration 3A: User-defined Database Roles Defining Application Roles Demonstration 3B: Application Roles

16 Working with User-defined Database Roles Database roles can be created, modified, and dropped  CREATE ROLE statement to create  Roles have owners  Permissions are granted to role  Role permissions are inherited by role members USE MarketDev; GO CREATE ROLE MarketingReaders AUTHORIZATION dbo; GO GRANT SELECT ON SCHEMA::Marketing TO MarketingReaders; GO USE MarketDev; GO CREATE ROLE MarketingReaders AUTHORIZATION dbo; GO GRANT SELECT ON SCHEMA::Marketing TO MarketingReaders; GO

17 Applying Roles in Common Scenarios Typical scenario  Define dbo users and other administrative roles  Define permission groups within the database  Consider the use of the public role for common permissions  Create roles and assign permissions to them  Add users to roles For decision-making within code  IS_SRVROLEMEMBER, IS_MEMBER IF IS_MEMBER('BankManagers') = 0 BEGIN PRINT 'Operation is only for bank manager use'; ROLLBACK; END; IF IS_MEMBER('BankManagers') = 0 BEGIN PRINT 'Operation is only for bank manager use'; ROLLBACK; END;

18 Demonstration 3A: User-defined Database Roles In this demonstration you will see:  How to create a user-defined database role using the GUI  How to create a user-defined database role using T-SQL  How to view the available database roles using T-SQL

19 Defining Application Roles User runs app App connects to db as user App authenticates using sp_setapprole App assumes app role Application roles are used to enable permissions for users only while they are running particular applications.

20 Demonstration 3B: Application Roles In this demonstration, you will see how to:  Create an application role  Change security context to an application role

21 Lab 10: Assigning Server and Database Roles Exercise 1: Assign Server Roles Exercise 2: Assign Fixed Database Roles Exercise 3: Create and Assign User-defined Database Roles Challenge Exercise 4: Check Role Assignments (Only if time permits) Logon information Estimated time: 45 minutes

22 Lab Scenario You have created the SQL Server logins and Database users. You now need to assign the logins and users to the required roles based upon the security requirements for the MarketDev database. You should assign the minimum level of access that will allow each user to perform their job. This will require a combination of server, fixed database, and user defined database roles. Do not be concerned with object and schema permissions as these will be assigned in Module 11 but you do need to consider the role requirements that will be required at that time. Note: the changes you make will later be migrated to the production environment. You should use T-SQL commands to implement the required changes.

23 Lab Review What is the biggest challenge when assigning permissions to users? Why do users often get granted more permissions than they need to do their work?

24 Module Review and Takeaways Review Questions Best Practices


Download ppt "Module 10 Assigning Server and Database Roles. Module Overview Working with Server Roles Working with Fixed Database Roles Creating User-defined Database."

Similar presentations


Ads by Google