or: How I Learned to Stop Using EXECUTE AS and Love Certificates

Slides:



Advertisements
Similar presentations
Login dan Permission dfd, Jenis Login dfd, 2012 SQL Server Authentication Membutuhkan password Windows Authentication Mode Tidak membutuhkan password.
Advertisements

Login dan Permission dfd, Jenis Login dfd, 2012 SQL Server Authentication Membutuhkan password Windows Authentication Mode Tidak membutuhkan password.
Advantage Data Dictionary. agenda Creating and Managing Data Dictionaries –Tables, Indexes, Fields, and Triggers –Defining Referential Integrity –Defining.
Chapter 10 Overview  Implement Microsoft Windows Authentication Mode and Mixed Mode  Assign login accounts to database user accounts and roles  Assign.
Mike Fal - SQL SERVER SECURITY GRANTING, CONTROLLING, AND AUDITING DATABASE ACCESS March 17, 2011.
Database Security Managing Users and Security Models.
Administration of Users Dr. Gabriel. 2 Documentation of User Administration Part of the administration process Reasons to document: –Provide a paper trail.
Database Application Security Models
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 3 Administration of Users.
Introduction to SQL Server 2000 Security Dave Watts CTO, Fig Leaf Software
Database Design for DNN Developers Sebastian Leupold.
Today’s Objectives Chapters 10 and 11 Security in SQL Server –Manage server logins and database users. –Manage server-level, database-level, and application.
Maintaining a Mirrored Database Tips and Tricks by Paul G. Hiles.
Security David Frommer Principal Architect Business Intelligence Microsoft Partner of the Year 2005 & 2007.
1 SQL Server 2000 Administration Kashef Mughal MSB.
Module 9 Designing and Implementing Stored Procedures.
MICROSOFT SQL SERVER 2005 SECURITY  Special Purpose Logins and Users  SQL Server 2005 Authentication Modes  Permissions  Roles  Managing Server Logins.
Module 9 Authenticating and Authorizing Users. Module Overview Authenticating Connections to SQL Server Authorizing Logins to Access Databases Authorization.
Module 4: Managing Security. Overview Implementing an Authentication Mode Assigning Login Accounts to Users and Roles Assigning Permissions to Users and.
Module 14 Configuring Security for SQL Server Agent.
Module 10 Assigning Server and Database Roles. Module Overview Working with Server Roles Working with Fixed Database Roles Creating User-defined Database.
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
Securing SQL Server 2005 Anil Desai. Speaker Information Anil Desai –Independent consultant (Austin, TX) –Author of several SQL Server books –Instructor,
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Module 11 Authorizing Users to Access Resources. Module Overview Authorizing User Access to Objects Authorizing Users to Execute Code Configuring Permissions.
Module 6: Data Protection. Overview What does Data Protection include? Protecting data from unauthorized users and authorized users who are trying to.
INTRO TO SQL SERVER SECURITY By Robert Biddle
SQL Server 2005 Implementation and Maintenance Chapter 6: Security and SQL Server 2005.
Oracle 11g: SQL Chapter 7 User Creation and Management.
SQL Server Security Basics Starting with a good foundation Kenneth Fisher
Secure Data Access with SQL Server 2005 Doug Rees Associate Technologist, CM Group
SQL Server Permissions and Security Principals William Assaf Sparkhound, Inc. SQLSAT CLUTCH CITY 2015.
Introduction to SQL Server  Working with MS SQL Server and SQL Server Management Studio.
Data Security Superior Consulting Services Rick Bielawski 350 West Burnsville Parkway Suite 550 Burnsville, MN
Module 9: Implementing Functions. Overview Creating and Using Functions Working with Functions Controlling Execution Context.
Data Security Lighthouse Software Solutions Rick Bielawski 2042 Wooddale Dr. Suite 125 St. Paul, MN On the web at lssinc.com.
SQL Server Encryption Ben Miller Blog:
WELCOME! SQL Server Security. Scott Gleason This is my 9 th Jacksonville SQL Saturday Over ten years DBA experience Director of Database Operations
Administrating a Database
Recommended Practices & Fundamentals
Microsoft SQL Server 2014 for Oracle DBAs Module 8
Lighthouse Software Solutions
Chapter 14: System Protection
Outsourcing Database Administration
6/16/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
DBA and IT Professional for ~9 years. Currently I am a Data Architect
A Technical Overview of Microsoft® SQL Server™ 2005 Beta 2
Access, Users, Permissions
SQL Server Security For Everyone
Introduction to SQL Server 2000 Security
Contained DB? Did it do something wrong?
Common Security Mistakes
Unique, Pseudo Random Numbers
Who Has What to Which? (The Permissions Superset)
Designing Database Solutions for SQL Server
DevOps Database Administration
Implementing Security inside SQL Server
Transactional Replication A Deeper Dive Drew Furgiuele, Senior DBA IGS
DevOps Database Administration
5 WAYS TO BYPASS *OR ENSURE* SQL SERVER SECURITY MATT MARTIN
SQL Server Security from the ground up
Securing SQL Server Processes with Certificates
SQL Server Security For Everyone
DBA for ~4+years, IT Professional for 7.5 years.
Intermediate Security Topics in SQL SERver
Outsourcing Database Administration
༂རཱི⿻⍰〄ポשׁ⍰ꬤᆱ◬Ꮡ⯑☠o̐̈́̈́̈́͢ㅴ
Module 10: Implementing Managed Code in the Database
Administrating a Database
SQL Server Security from the ground up
Presentation transcript:

or: How I Learned to Stop Using EXECUTE AS and Love Certificates Module Signing or: How I Learned to Stop Using EXECUTE AS and Love Certificates Module Signing or: How I Learned to Stop Using EXECUTE AS and Love Certificates Version: 2.2-B (20171228) Version 1.0 (20170311)

Reference: Simpsons spoof of “Dr Reference: Simpsons spoof of “Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb” (1964) http://www.imdb.com/title/tt0057012/

C:\> whoami Working in IT and with databases since 1996: SQL Server (since 2002), SQLCLR (since 2006) Areas of interest / concentration: SQLCLR, Module Signing, Collations & Encodings Variety of Roles, OSes, Languages, and DBs Articles: SQL Server Central (incl. Stairway to SQLCLR series) Simple-Talk Founder of Sql Quantum Lift: SQL# (SQLsharp) : SQLCLR library of functions OmniExec : Multi-threaded, multi-server & DB query tool �

Agenda Typical Problems Security Basics Typical Solutions Problems with Typical Solutions Module Signing What it is, What it can do, and Why use it Asymmetric Keys & Certificates Example Wrap-up / Q & A

You Gotta Problem? Common “Problem” Scenarios: Need Elevated Permission that is not Grantable Need Elevated Permission that is not Granular Dynamic SQL Cross-Database Operations Allow Access to a Restricted Database

What Are Ya Gonna Do About It? Common Solutions Cross-Database Ownership Chaining Impersonation ( EXECUTE AS ) TRUSTWORTHY ON

Security Basics: SIDs, Logins and Users Security Identifier (SID) Binary: 0x0106000000000009010000006A91F17B3F6334F2C782536D9D66E88A07624983 String: S-1-9-1-2079428970-4063519551-1834189511-2330486429-2202624519 Logins: Server / Instance –level sys.server_principals & sys.server_permissions SUSER_NAME(), SUSER_ID() Users: Database-level sys.database_principals & sys.database_permissions USER_NAME(), USER_ID() SID matches Login’s SID, but Name can be different “Guest” if no User entry “dbo” always principal_id = 1 SID changes to Login of owner

Security Basics: Logins and Users Name = Bob SID = 0x123456 Server Database 1 User: Name = Bob SID = 0x123456 Database 2 User: Name = Sally SID = 0x123456 Database 3 User: Name = guest SID = 0x00

Security Basics: Ownership Chains Inherently how permissions work Permissions check skipped if sub-object is same owner DML, SELECT, and EXEC only Slight performance benefit Within single DB by default Can enable Cross-Database Ownership Chaining Image taken from: https://technet.microsoft.com/en-us/library/ms188676.aspx

Cross-Database Ownership Chaining Ownership chaining activation Server-level “cross db ownership chaining” When enabled, enables all Databases Database-level DB_CHAINING Only used for enabling when server-level is disabled Extends ownership chain between DBs Owner SID must exist in both DBs Can’t elevate permissions Dynamic SQL breaks unless User in both Databases

Impersonation

Impersonation “Instead-of” Permissions Account-based security Requires a Login and/or User with elevated permissions Security Context (SESSION_USER) changes to this “impersonated” principal Accomplished via EXECUTE AS

EXECUTE AS Clause Statement Part of “CREATE OBJECT” statement Impersonated Principals are always DB level No IMPERSONATE permission needed Statement Can do Server-level Logins and DB-level Users Requires IMPERSONATE permission

Problems with Impersonation & Cross-Database Ownership Chaining Cross-DB Ownership Chaining: security risk (can spoof User / DB-level) db_ddladmin & db_owner users can create objects for other owners Users with CREATE DATABASE permission can create new databases and attach existing databases Impersonation: If IMPERSONATE is required: can be used any time No granular control over permissions Cross-DB operations need TRUSTWORTHY ON Need to use ORIGINAL_LOGIN() for Auditing Elevated permissions last until process / sub-process ends or REVERT TRUSTWORTHY: Bigger security risk (can also spoof Logins, such as “sa” !)

Problems with Impersonation / TRUSTWORTHY

And the Preferred Solution is...

Module Signing “In Addition To” Permissions Code-based security Signatures = authenticity and change detection Hash only provides change detection Security Context (SESSION_USER) does NOT change to this “privileged” principal

Module Signing (cont.) Also requires a Login and/or User with elevated permissions Accomplished using ADD SIGNATURE Regular vs. COUNTER SIGNATURE Can sign modules: Multi-statement Table-Valued Functions Stored Procedures Scalar Functions Triggers SQLCLR Assemblies

Benefits Privileged principal cannot be impersonated Very Granular permissions No security holes (e.g. TRUSTWORTHY, etc.) Signature is dropped if code is changed !! Elevated permissions confined to signed code Multiple Signatures can be used to combine permission “sets”

Signatures and Counter Signatures Stored Procedure ABC Signature = 0x12AB Requires permission X, Executes Proc DEF Certificate Signature = 0x12AB Stored Procedure DEF Counter Signature of 0x12AB Needs Permission Y User from Certificate Signature = 0x12AB Has permission X Has permission Y Can EXEC Procedure DEF Regular User Can only execute Procedure ABC Does NOT have permission X Does NOT have permission Y Cannot execute Procedure DEF

Asymmetric Keys & Certificates Common Aspects Consist of a Private Key and Public Key Can have the Private Key removed Common Properties: Thumbprint (hash of Public Key, sys.crypt_properties) SID Principal_id name Create from File (.snk or .dll) or Assembly Provide password or use Database Master Key (DMK)

Asymmetric Keys Where: SELECT * FROM [sys].[asymmetric_keys]; Properties: public_key Can create from Key Store / EKM BUT, EKM created Keys not supported for Module Signing Can specify Algorithm: Cannot backup  More likely to misspelllll “assimetric?” ;-)

Certificates Where: SELECT * FROM [sys].[certificates]; Asymmetric Key + extra properties Properties: Serial Number: unique ID of the Certificate Subject: essentially a description Start Date: UTC; default = GETUTCDATE(); Expiration Date: UTC; default = 1 year from Start Module Signing ignores Expiration Date Can backup !!

(example code) Grant a database role in current database with permission to execute a SP in msdb http://dba.stackexchange.com/questions/168604/grant-a-database-role-in-current-database-with-permission-to-execute-a-sp-in-msd/168808#168808 What minimum permissions do I need to provide to a user so that it can check the status of SQL Server Agent Service? https://dba.stackexchange.com/questions/62230/what-minimum-permissions-do-i-need-to-provide-to-a-user-so-that-it-can-check-the/103275#103275

Conclusionarium Module Signing Info ( https://ModuleSigning.info/ ) Cross-Database Ownership Chaining Impersonation / EXECUTE AS TRUSTWORTHY ON S.U.C.K.S. 💩 😠 😧 😭 🚽 Certificates and Module Signing AWESOME !!! 😺 😹 😇 🙌 Module Signing Info ( https://ModuleSigning.info/ )

Hiding in Plain Sight Module Signing Resources: Articles: SQLsharp.com https://ModuleSigning.info/ Articles: http://www.SqlServerCentral.com/Authors/Articles/Solomon_Rutzky/294002/ http://www.SqlServerCentral.com/stairway/105855/ ( Stairway to SQLCLR ) https://www.simple-talk.com/author/solomon-rutzky/ SQLsharp.com https://SQLsharp.com/ StackOverflow.com & DBA.StackExchange.com https://StackExchange.com/users/281451/solomon-rutzky LinkedIn http://www.LinkedIn.com/in/srutzky/ Email: SRutzky@SqlQuantumLift.com