Download - Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Transcript
Page 1: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Securing SQL Server 2005

Anil Desai

Page 2: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Speaker Information

• Anil Desai– Independent consultant (Austin, TX)– Author of several SQL Server books– Instructor, “Implementing and Managing SQL

Server 2005” (Keystone Learning)– Info: http://AnilDesai.net or [email protected]

Page 3: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Agenda and Outline

• SQL Server Security Architecture• Configuring Service Accounts• Managing Logins and Server Permissions• Database Users and Roles• Managing Permissions• Other Security Features

– Encryption– DDL Triggers (Auditing)

• Monitoring Security with SQL Profiler

Page 4: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Server Security Overview

• Layered Security Model:– Windows Level– SQL Server Level– Database

• Schemas (for database objects)

• Terminology:– Principals– Securables– Permissions

• Scopes and Inheritance

Page 5: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Security Overview

• (from Microsoft SQL Server 2005 Books Online)

Page 6: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Security Best Practices

• Make security a part of your standard process

• Use the principle of least privilege

• Implement defense-in-depth (layered security)

• Enable only required services and features

• Regularly review security settings

• Educate users about the importance of security

• Define security roles based on business rules

Page 7: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Server Service Accounts

• Local Service Account– Permissions of “Users” group (limited)– No network authentication

• Network Service Account– Permissions of Users group– Network authentication with Computer account

• Domain User Accounts– Adds network access for cross-server functionality

Page 8: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Server Services

• Instance-Specific (one service per instance):– SQL Server– SQL Server Agent– Analysis Services– Reporting Services– Full-Text Search

• Instance-unaware– Notification Services– Integration Services– SQL Server Browser– SQL Server Active

Directory Helper– SQL Writer

Page 9: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Server Surface Area Configuration

• Default installation: Minimal services• SAC for Services and Connections

– Allow Remote Connections– Access to Reporting Services, SSIS, etc.

• SAC for Features– Remote queries– .NET CLR Integration– Database Mail– xp_cmdshell

Page 10: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Managing Logins

• Windows Logins– Authentication/Policy managed by Windows

• SQL Server Logins– Managed by SQL Server

• Based on Windows policies

– Password Policy Options:• HASHED (pw is already hashed)• MUST_CHANGE• CHECK_EXPIRATION• CHECK_POLICY

Page 11: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Creating Logins

• Transact-SQL – CREATE LOGIN statement

• Replaces sp_AddLogin and sp_GrantLogin

– SQL Server Logins– Windows Logins

• SQL Server Management Studio– Setting server authentication options– Login Auditing– Managing Logins

Page 12: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Managing Server Roles

• Built-In Server-Level Roles:– SysAdmin– ServerAdmin – SetupAdmin– SecurityAdmin– ProcessAdmin– DiskAdmin– DBCreator– BulkAdmin

Page 13: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Database Users and Roles

• Database Users– Logins map to database users

• Database Roles– Users can belong to multiple roles– Guest (does not require a user account)– dbo (Server sysadmin users)

• Application Roles– Used to support application code

Page 14: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Database Roles

• Built-in Database Roles:– db_accessadmin– db_BackupOperation– db_DataReader– db_DataWriter– db_DDLAdmin– db_DenyDataReader– db_DenyDataWriter– db_Owner– db_SecurityAdmin– public

Page 15: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Creating Database Users and Roles

• CREATE USER– Replaces sp_AddUser and sp_GrantDBAccess– Can specify a default schema– Managed with ALTER USER and DROP USER

• CREATE ROLE– Default owner is creator of the role

• SQL Server Management Studio– Working with Users and Roles

Page 16: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Understanding Database Schemas

• Schemas– Logical collection of related database objects– Part of full object name:

• Server.Database.Schema.Object– Default schema is “dbo”

• Managing Schemas– CREATE, ALTER, DROP SCHEMA– SQL Server Management Studio– Can assign default schemes to database users:

• WITH DEFAULT_SCHEMA ‘SchemaName’

Page 17: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Configuring Permissions

• Scopes of Securables– Server– Database– Schema– Objects

• Permission Settings:– GRANT– REVOKE– DENY

• Options– WITH GRANT OPTION– AS (Sets permissions using another user or role)

Page 18: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Managing Execution Permissions

• Transact-SQL Code can run under a specific execution context– By default, will execute as the caller

• EXECUTE AS clause:– Defined when creating an object or procedure– Options:

• CALLER (Default)• SELF: Object creator• Specified database username

Page 19: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Getting Security Information

• Procedures and Functions– sys.fn_builtin_permissions – Has_Perms_By_Name– CURRENT_USER– SETUSER– IS_MEMBER– SUSER_NAME / SUSER_ID– SCHEMA_NAME

Page 20: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Security Catalog Views

• Sys.Server_Permissions• Sys.Server_Principals

• Sys.Database_Permissions• Sys.Database_Principals• Sys.Database_Role_Members

Page 21: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Other Security Options

• Encrypting Object Definitions– Use the WITH ENCRYPTION Clause – Stores the object definition in an encrypted

format

• SQL Server Agent– Proxies based on subsystems allow lock-

down by job step types

• Preventing SQL Injection attacks

Page 22: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Understanding Encryption

• Goals:– Authentication– Data Encryption

• Symmetric Encryption– Uses a single key

• Asymmetric Encryption– Uses a “key-pair”

• Public key: Can be distributed• Private key: Stored securely

– Certificates protect the public key

Page 23: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Understanding SQL Server Certificates

• Uses of Certificates– Data encryption– Service Broker endpoints – Digital signatures for objects– Web / HTTP connections

• SQL Server Certificates– Stored within user databases

• Notes:– Encryption overhead can be significant– Keys must be protected

Page 24: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Server Encryption

• Encryption Hierarchy– Windows Level

• Stores Service Master Key

– SQL Server Level• Service Master Key

– Database Master Key• Certificates• Asymmetric Keys

– Encrypted Objects / Data (varbinary)

Page 25: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Encryption Hierarchy

• (from Microsoft SQL Server 2005 Books Online)

Page 26: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Managing Certificates

• Transact-SQL commands:– CREATE CERTIFICATE

• Stored within the user database• Can use a password or a file

– BACKUP CERTIFICATE• Exports to a file

– DROP CERTIFICATE

• Encrypting Data:– EncryptBy_____ (Cert, SymmetricKey, Passphrase, etc.)– DecryptBy_____()

Page 27: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Getting Certificate Information

• Information– Sys.Certificates– Sys.Asymmetric_Keys– Sys.Symmetric_Keys

• Cert_ID returns the certificate identifier

• CertProperty(Cert_ID, ‘PropertyName’)• Start_Date, Expiry_Date, etc.

Page 28: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

DDL Triggers

• Respond to Data Definition Language (DDL) commands– Examples:

• DROP_TABLE• ALTER_TABLE• CREATE_LOGIN

• Purpose:– Preventing certain changes– Logging / sending notifications of schema changes– Can rollback changes

Page 29: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

DDL Triggers

• DDL triggers do not generate inserted/deleted tables

• Getting Details– EVENTDATA function returns details of the changes

in XML format– Can query with XQUERY expressions

• DDL Trigger Scope:– Database-Level (stored within the same database)– Server-Level (stored in the master database)

Page 30: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

Monitoring Security with SQL Profiler

• Options:– Log to a trace file or to a table– Run programmatically using SQL Trace SP’s

• “Security Auditing” Event Class– Audit Login / Audit Logoff– Audit Add DB User Event– Audit Addlogin Event

Page 31: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

SQL Profiler: Security Auditing

Page 32: Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,

For More Information

• Resources from Anil Desai– Web Site (http://AnilDesai.net)– E-Mail: [email protected] – Keystone Learning Course: “Microsoft

SQL Server 2005: Implementation and Maintenance (Exam 70-431)”

– The Rational Guide to Managing Microsoft Virtual Server 2005

– The Rational Guide to Scripting Microsoft Virtual Server 2005