490 likes | 702 Views
Security & Auditing on SQL Server 2008 R2. Antonios Chatzipavlis Software Architect Evangelist, IT Consultant MCT, MCITP, MCPD, MCSD, MCDBA, MCSA, MCTS, MCAD, MCP, OCA MVP on SQL SERVER. Objectives. Overview of SQL Server Security Protecting the Server Scope Protecting the Database Scope
E N D
Security & Auditing on SQL Server 2008 R2 Antonios Chatzipavlis Software Architect Evangelist, IT Consultant MCT, MCITP, MCPD, MCSD, MCDBA, MCSA, MCTS, MCAD, MCP, OCA MVP on SQL SERVER
Objectives • Overview of SQL Server Security • Protecting the Server Scope • Protecting the Database Scope • Managing Keys and Certificates • Auditing Security
Security & Auditing on SQL Server 2008 R2 Overview of SQL Server Security
Overview of SQL Server Security • SQL Server Security Framework • What Are Principals? • What Are Securables? • SQL Server Permissions
What Are Principals? Securables Permissions Principals Windows Group Domain User Account Local User Account Windows SQL Server Login Server Role SQL Server User Database Role Application Role Database
What Are Securables? Securables Permissions Principals Windows Group Files Domain User Account Registry Keys Local User Account Windows SQL Server Login Server Server Role SQL Server Database User Schema Database Role Application Role Database
SQL Server Permissions • Server-Level Permissions • Logins • Credentials • Server-Level Roles • Database-Level Permissions • Users • Schemas • Database Level Roles
Security & Auditing on SQL Server 2008 R2 Protecting the Server Scope
Protecting the Server Scope • What Are SQL Server Authentication Methods? • Password Policies • Server-Level Roles • Managing SQL Server Logins • Server-Scope Permissions
What Are SQL Server Authentication Methods? Windows Authentication Mixed SQL and Windows Authentication
Password Policies SQL Server Can Leverage Windows Server 2003/2008 Password Policy Mechanism Pa$$w0rd Group Policy Object (GPO) • SQL Server Can Manage: • Password Complexity • Password Expiration • Policy Enforcement
Managing SQL Server Logins CREATE LOGIN Alice WITH Password = 'Pa$$w0rd' CREATE LOGIN login_name { WITH SQL_login_options | FROM WINDOWS [ WITH windows_login_options ] } CREATE LOGIN [SERVERX\SalesDBUsers] FROM WINDOWS WITH DEFAULT_DATABASE = AdventureWorks2008
Server-Scope Permissions Server permissions USE master GRANT ALTER ANY DATABASE TO [AdventureWorks2008\Holly] Server-scope securable permissions USE master GRANT ALTER ON LOGIN :: AWWebApp TO [AdventureWorks2008\Holly]
Security & Auditing on SQL Server 2008 R2 Protecting the Database Scope
Protecting the Database Scope • What Are Database Roles? • What Are Application Roles? • Managing Users • Special Users • Database-Scope Permissions • Schema-Scope Permissions
What Are Database Roles? Database-Level Roles Application-Level Roles Users
What Are Application Roles? User runs app App authenticates using sp_setapprole App connects to db as user App assumes app role
Managing Users • Create a login • Create a database scope user • Assign permissions to the user Steps to Manage Users
Special Users DBOThesa login and members of sysadmin role are mapped to dbo account GuestThis user account allows logins without user accounts to access a database
Database-Scope Permissions Database permissions USE AdventureWorks2008 GRANT ALTER ANY USER TO HRManager Database-scope securable permissions USE AdventureWorks2008 GRANT SELECT ON SCHEMA :: Sales TO SalesUser
Schema-Scope Permissions User-defined type permissions USE AdventureWorks2008 GRANT EXECUTE ON TYPE :: Person.addressType TO SalesUser All other schema-scope permissions USE AdventureWorks2008 GRANT SELECT ON Sales.Order TO SalesUser
Security & Auditing on SQL Server 2008 R2 Managing Keys and Certificates
Managing Keys and Certificates • What Are Keys? • What Are Certificates? • SQL Server Cryptography Architecture • When to Use Keys and Certificates • Transparent Data Encryption
What Are Keys? Encrypt Decrypt • Symmetric • Same key used to encrypt and decrypt • Asymmetric • Pair of values: public key and private key • One encrypts, the other decrypts
What Are Certificates? • Associates a public key with entity that holds that key • Contents: • The public key of the subject • The identifier information of the subject • The validity period • Issuer identifier information • The digital signature of the issuer
When to Use Keys and Certificates • When to use Certificates • To secure communication in database mirroring • To sign packets • To encrypt data or connections • When to use Keys • To help secure data • To sign plaintext • To secure symmetric keys
Transparent Data Encryption Transparent data encryption performs real-time I/O encryption and decryption of the data and log files Steps to use Transparent Data Encryption • Create a master key • Create or obtain a certificate protected by the master key • Create a database encryption key and protect it by the Certificate • Set the database to use encryption
Transparent Database Encryption: More Benefits • Entire database is protected • Applications do not need to explicitly encrypt/decrypt data! • No restrictions with indexes or data types (except FILESTREAM) • Performance cost is small • Backups are unusable without key • Can be used with Extensible Key Management
Transparent Data Encryption: Mechanism • Very simple: • Database pages are encrypted before being written to disk • Page protection (e.g. checksums) applied after encryption • Page protection (e.g. checksums) checked before decryption • Database pages are decrypted when read into memory • When TDE is enabled, initial encryption of existing pages happens as a background process • Similar mechanism for disabling TDE • The process can be monitored using the encryption_state column of sys.dm_database_encryption_keys • Encryption state 2 means the background process has not completed • Encryption state 3 means the database is fully encrypted
Transparent Data Encryption: Enabling • Create a master key • CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<UseStrongPwdHere>'; • Create or obtain a certificate protected by the master key • CREATE CERTIFICATE MyDEKCert WITH SUBJECT = 'My DEK Certificate'; • Create a database encryption key and protect it by the certificate • CREATE DATABASE ENCRYPTION KEY WITH ALGORITHM = AES_128 ENCRYPTION BY SERVER CERTIFICATE MyDEKCert; • Set the database to use encryption • ALTER DATABASE MyDatabase SET ENCRYPTION ON;
Transparent Data Encryption: Backups • A backup of a TDE encrypted database is also encrypted using the database encryption key • To restore the backup OR attach the database, the DEK must be available! • There is no way around this – if you lose the DEK, you lose the ability to restore the backup (that’s the point!) • Maintain backups of server certificates too
Transparent Data Encryption: Tools Support • Database | Tasks | Manage Database Encryption
Security & Auditing on SQL Server 2008 R2 Auditing Security
Auditing Security • What Is Auditing? • Security Auditing with Profiler • Auditing with DDL Triggers • Introducing SQL Server Audit • SQL Server Audit Action Groups and Actions
What Is Auditing? • What is Auditing? • What auditing options are available in SQL Server? • Have you ever had to audit SQL Server? • If so, how did you do it? • If not, what do you think is the best use of auditing?
Security Auditing with Profiler • Using SQL Server Profiler, you can do the following: • Create a trace that is based on a reusable template • Watch the trace results as the trace runs • Store the trace results in a table • Start, stop, pause and modify the trace results • Replay the trace results
Auditing with DDL Triggers • Use DDL triggers when you want to do the following: • Prevent certain changes in your database schema • You want something to occur in the database in response to a change in your database schema • You want to record changes or events in the database schema • Start, stop, pause and modify the trace results • Replay the trace results
Introducing SQL Server Audit • SQL Server Auditing • Tracks and logs events that occur on the system • Can track changes on the server or database level • Can be managed with Transact-SQL
My Blogs • For SQL Server and Databases • www.autoexec.gr/blogs/antonch • For .NET & Visual Studio • www.dotnetzone.gr/cs/blogs/antonch