250 likes | 486 Views
Module 10 Assigning Server and Database Roles. Module Overview. Working with Server Roles Working with Fixed Database Roles Creating User-defined Database Roles. Lesson 1: Working with Server Roles. Server- s coped Permissions Typical Server-scoped Permissions
E N D
Module 10 Assigning Server and Database Roles
Module Overview • Working with Server Roles • Working with Fixed Database Roles • Creating User-defined Database Roles
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
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 USEmaster; GO GRANTALTERONLOGIN::HRApp TO [AdventureWorks\Holly]; GO GRANTALTERANYDATABASE TO [AdventureWorks\Holly]; GO
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
public Server Role public is a special server role with server-scope. • 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
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
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
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 GRANTCREATE TABLE TOHRManager; GO GRANTVIEW DEFINITION TO James; GO
Assigning Users to Roles • Users can be assigned to roles • Using GUI • Using T-SQL USE AdventureWorks2008R2; GO EXECsp_addrolemember 'db_datareader', 'James'; GO
Database Owner dboThesa login and members of sysadmin role are mapped to dboaccount, along with the owner of the database
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
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
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 USEMarketDev; GO CREATEROLEMarketingReaders AUTHORIZATIONdbo; GO GRANTSELECTONSCHEMA::Marketing TOMarketingReaders; GO
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 IFIS_MEMBER('BankManagers')= 0 BEGIN PRINT'Operation is only for bank manager use'; ROLLBACK; END;
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
Defining Application Roles User runs app App authenticates using sp_setapprole App connects to db as user App assumes app role Application roles are used to enable permissions for users only while they are running particular applications.
Demonstration 3B: Application Roles • In this demonstration, you will see how to: • Create an application role • Change security context to an application role
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: 45minutes
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.
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?
Module Review and Takeaways • Review Questions • Best Practices