SlideShare a Scribd company logo
1 of 37
Session
VDA306


  Dealing with SQL Security
        from ADO.NET
          Fernando G. Guerrero
                SQL Server MVP
              .NET Technical Lead
                    QA plc

                 October 2002
Quick info about Fernando
                     (2 milliseconds)

                     •   MCSD, MCSE+Internet (W2K), MCDBA, MCT,




QA
                         SQL Server MVP

                     •   This is where I work: QA, The best learning
                         environment in Europe

                     •   Writing for SQL Sever Magazine and SQL
                         Server Professional

                     •   This is my main web site: www.callsql.com

                     •   This is my book (so far):
                          –   Microsoft SQL Server 2000 Programming by
                              Example (ISBN : 0789724499, co-authored with Carlos
                              Eduardo Rojas)


                     •   Currently writing on ADO.NET and SQL Server
                         2000


VS.NET Connections
Agenda

• SQL Server Authentication modes
• Access to SQL Server Databases
• Application security using SQL Server 2000
  and ADO.NET

• Note: as this is a VS.NET session, I’ll show you as much
  ADO.NET, VB.NET and SQL-DMO code as possible, but
  you need to know about how SQL Server deals with security
  as well

VS.NET Connections
SQL Server Authentication modes

• SQL Server Authentication
   – SQL Server specific logins
   – Not recommended for Windows users
   – Specify UID/PWD in the ConnectionString
• Windows integrated
   – Create logins for Windows groups, not users
   – Deny access to SQL Server by creating Windows
     logins in SQL Server
   – Specify Trusted_Connection=true in the
     ConnectionString
VS.NET Connections
SQL Server Authentication

•   Easy to understand
•   Independent of the Windows Domain structure
•   Not too flexible
•   Easier to break
•   Connection pooling unfriendly




VS.NET Connections
SQL Server Authentication (2)

• Most applications still connect as sa and no
  password (or password as password)
• Could provide an extra layer of authentication
• IIS+NT friendly
• If you write your UID/PWD in the connection
  string, someone could read it
• Connection pooling friendly



VS.NET Connections
How to create SQL Server
   logins programmatically from
     Visual Basic .NET (demo)




VS.NET Connections
Windows Authentication
• Easier to administer in the long run
• Complex security combinations
   – NT Groups to reflect actual business structure
   – Combinations of groups give actual
     permissions
• Comprehensive security control based on
  Windows NT / 2000 / .NET security:
   – Password policies
   – Location and time control
   – Automatic account blocking
VS.NET Connections
Windows Authentication (2)
• Grant access to lots of users in a single
  shot
• Deny access to lots of users in a single shot
  too
• Make code easier to deploy and maintain
• You don’t write your UID/PWD in the
  connection string, so it is more difficult to
  hack


VS.NET Connections
Connection Strings and
      Windows authentication in
         ADO.NET (demo)




VS.NET Connections
How to create programmatically
Windows logins in SQL Server
 2000 from Visual Basic .NET
           (demo)




VS.NET Connections
Using SQL-DMO from VB.NET to
  manage the authentication
mode, and SQL Server security
• In this demonstration you will see
  how to:
   – Change the SQL Server Authentication
     Mode
   – Manage SQL Server logins
• And we will do it by using VB.NET
  with:
   – SQL-DMO
   – SQLCommand objects

VS.NET Connections
The nasty error 18452




• SQL Server is configured for Windows
  Authentication only:
   – Not even the sa can login
• Before changing to Mixed authentication mode,
  give a strong password to the sa login!
VS.NET Connections
What if you dropped the
       Builtin/Administrators login?
• Unless you have a valid login to access SQL
  Server, you are into troubles
• You can start a new session using the Windows
  service account and create the appropriate
  logins
• Or edit the registry and change the value of the
  following key to 2:
   – Default instance:
       • HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLSe
         rverMSSQLServerLoginMode
   – Named instances:
       • HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft
         SQL ServerInstanceNameMSSQLServerLoginMode

VS.NET Connections
Fixed Server Roles
• Administrative groups to easier server-wide
  permissions
   – Sysadmin: They can do anything, SQL Server
     permissions don’t affect them
• Other roles are subsets of sysadmin, for
  better permissions’ granularity:
    – setupadmin
    – securityadmin
    – processadmin
    – dbcreator
    – diskadmin
    – bulkadmin
VS.NET Connections
How to use Server Roles from
              ADO.NET
• Simply put: you don’t
• The connection gets automatically server
  role membership according to the login
  used to connect to SQL Server
• To get the permission path used to
  connect to SQL Server, execute:
   – xp_logininfo [DomainNameUserName]


VS.NET Connections
Getting role membership information
• Use the IS_SRVROLEMEMBER function
• Execute the sp_helpsrvrolemember stored
  procedure
• Use the ListMembers method from SQL-DMO
• Execute this query for actual logins defined in
  SQL Server:
           SELECT 'ServerRole' = spv.name
           FROM master.dbo.spt_values spv
           JOIN master.dbo.sysxlogins lgn
           ON spv.low = 0
             AND spv.type = 'SRV'
             AND lgn.srvid IS NULL
             AND spv.number & lgn.xstatus = spv.number
           WHERE lgn.sid = SUSER_SID('LoginName')


VS.NET Connections
Trying (unsuccessfully) to apply
   permissions to sysadmin
       members (demo)




VS.NET Connections
Agenda


• SQL Server Authentication modes
• Access to SQL Server Databases
• Application security using SQL Server
  2000 and ADO.NET



VS.NET Connections
Access to SQL Server
            Databases
• A login gives you access to SQL Server
• To access a database, you need a user on that
   database
• Retrieve the current login using the
   SYSTEM_USER function
• Retrieve the current user using the
   CURRENT_USER function
• It doesn’t matter how many Windows groups you
   belong to: SQL Server knows you.
• The dbo user
VS.NET Connections
• The guest user
Fixed Database Roles

• A very important one: Public
    – Everybody belongs to Public
    – Useful to set default permissions
•   Other roles simplify permissions:
•   db_owner
•   db_accessadmin / db_securityadmin
•   db_ddladmin
•   db_backupoperator
•   db_datareader / db_denydatareader
•   db_datawriter / db_denydatawriter
VS.NET Connections
Do db_owner members have all
   permissions they think they
         have? (demo)




VS.NET Connections
Agenda


• SQL Server Authentication modes
• Access to SQL Server Databases
• Application security using SQL
  Server 2000 and ADO.NET


VS.NET Connections
Application security using SQL
  Server 2000 and ADO.NET
• You can deny permissions to every user on all
  access to tables
• Grant permissions to use views
• Grant permissions to execute stored procedures
• As long as all of them have the same owner, user
  will need permissions only on views / stored
  procedures
• SQL Server won’t check permissions on
  underlying objects / statements
• It doesn’t work with dynamic execution
VS.NET Connections
Testing application security with
  views and stored procedures
     from ADO.NET (demo)




VS.NET Connections
Granting and denying permissions
        on SQL statements
• GRANT Permission TO User/Role:
   –   CREATE DATABASE
   –   CREATE DEFAULT
   –   CREATE FUNCTION
   –   CREATE PROCEDURE
   –   CREATE RULE
   –   CREATE TABLE
   –   CREATE VIEW
   –   BACKUP DATABASE
   –   BACKUP LOG
VS.NET Connections
Granted – Denied - Revoked
• No permissions (not granted nor denied) means
  I’M SORRY
• Granted means PERHAPS
   – You might o might not have final permission
   – Depends on membership on other roles/groups
• Denied means NO WAY
   – You can’t perform that action, no matter what
• Revoked means I FORGOT ABOUT IT
   – Your security record has been removed (it could have
     been granted or denied in the past)
   – Effective permissions depend on role/groups
     membership
VS.NET Connections
Granting and denying permissions
   on specific database objects
• GRANT Permission
  ON Object TO
  User/Role




VS.NET Connections
Permissions Errors
• A permission error doesn’t break
  connections
• A permission error doesn’t break
  execution
• A permission error doesn’t roll
  transactions back
• So, it is up to you to check for errors on
  permissions and take the right action
VS.NET Connections
SQL Server application roles

•   Defined at Database level
•   Password required
•   Don’t have any members
•   Always belong to Public role
•   May belong to other database roles
•   Need to be activated before use
•   Cannot be de-activated
•   Connection-pooling unfriendly
VS.NET Connections
SQL Server application roles
           (Creation)
• EXEC sp_addapprole ‘RoleName’,
  ‘RolePassword’
• It is considered as a special user in the
  database, not a group
• Grant permissions to the role by using:
• GRANT Permissions ON Object to AppRole
• Deny permissions to the role by using:
• DENY Permissions ON Object to AppRole
VS.NET Connections
SQL Server application roles
          (Activation)
• EXEC sp_setapprole ‘RoleName’,
  {Encrypt N ‘Password'}, ‘ODBC‘
• How to protect the password?
   – Store it in a encrypted file
   – Scramble it through the code and protect
     it against debug mode
   – Store it in Active Directory
   – Encapsulate this call in a Component
VS.NET Connections
Using application roles from
        ADO.NET (demo)




VS.NET Connections
Passport-like authentication
• Your application can authenticate
  users from login/password data
• Store open login, encrypted password
• Compare encrypted passwords
• Create the entire thing as system
  objects

VS.NET Connections
Do you want to know more?
• “Inside SQL Server 2000” (Kalen Delaney, MSPress)
• “Advanced Transact-SQL for SQL Server 2000” (Itzik Ben-
  Gan & Tom Moreau, APress)
• “SQL Server 2000 Programming” (Robert Vieira, WROX)
• “Microsoft SQL Server 2000 Programming by Example”
  (Fernando G. Guerrero & Carlos Eduardo Rojas, QUE)
• “System.Data: A Clockwork Link between VB.NET and
  SQL Server ” (Fernando G. Guerrero, Apress)
• SQL Server 2000 Resource Kit (MSPress & TechNet)
• Visit the Microsoft public newsgroups:
   – msnews.microsoft.com/microsoft.public.sqlserver.*


 VS.NET Connections
Thank you!
                     Questions?
• Download the source code of this
  session from:
   – http://www.callsql.com/en/articles
• You can contact me at:
   – fernan@guerrerog.org




VS.NET Connections
Thank you!
                          • Please drop off your
                            session evaluations in
                            the basket at the back
                            of the room!
                          • Your comments are
                            greatly appreciated!




VS.NET Connections

More Related Content

What's hot

Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NETrchakra
 
For Beginners - Ado.net
For Beginners - Ado.netFor Beginners - Ado.net
For Beginners - Ado.netTarun Jain
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Mubarak Hussain
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworksLuis Goldster
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETEverywhere
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12Sisir Ghosh
 
JAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and RetrievalJAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and RetrievalDr. Ranbijay Kumar
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code FirstJames Johnson
 

What's hot (20)

ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Ado .net
Ado .netAdo .net
Ado .net
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Ado.net
Ado.netAdo.net
Ado.net
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
For Beginners - Ado.net
For Beginners - Ado.netFor Beginners - Ado.net
For Beginners - Ado.net
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
ODI User and Security
ODI User and Security ODI User and Security
ODI User and Security
 
Ado.net
Ado.netAdo.net
Ado.net
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 
Data Binding
Data BindingData Binding
Data Binding
 
JAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and RetrievalJAM819 - Native API Deep Dive: Data Storage and Retrieval
JAM819 - Native API Deep Dive: Data Storage and Retrieval
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 

Viewers also liked

Magnum Networking Update
Magnum Networking UpdateMagnum Networking Update
Magnum Networking UpdateDaneyon Hansen
 
7 Habits of Highly Effective Contirbutors
7 Habits of Highly Effective Contirbutors7 Habits of Highly Effective Contirbutors
7 Habits of Highly Effective ContirbutorsAdrian Otto
 
Analytics & Reporting for Amazon Cloud Logs
Analytics & Reporting for Amazon Cloud LogsAnalytics & Reporting for Amazon Cloud Logs
Analytics & Reporting for Amazon Cloud LogsCloudlytics
 
Colca valley arequipa peru
Colca valley arequipa peruColca valley arequipa peru
Colca valley arequipa peruMartin Lakers
 
Trusted Advisors in Retained Executive Search
Trusted Advisors in Retained Executive SearchTrusted Advisors in Retained Executive Search
Trusted Advisors in Retained Executive SearchCharles Moore
 
Xen versus kvm_20080623
Xen versus kvm_20080623Xen versus kvm_20080623
Xen versus kvm_20080623Todd Deshane
 
DPACC Acceleration Progress and Demonstration
DPACC Acceleration Progress and DemonstrationDPACC Acceleration Progress and Demonstration
DPACC Acceleration Progress and DemonstrationOPNFV
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureAdrian Otto
 
Debunking Myths & Mysteries of Retained Search
Debunking Myths & Mysteries of Retained SearchDebunking Myths & Mysteries of Retained Search
Debunking Myths & Mysteries of Retained SearchCharles Moore
 
Magnum first-class-resource
Magnum first-class-resourceMagnum first-class-resource
Magnum first-class-resourceAdrian Otto
 
What's Next in OpenStack? A Glimpse At The Roadmap
What's Next in OpenStack? A Glimpse At The RoadmapWhat's Next in OpenStack? A Glimpse At The Roadmap
What's Next in OpenStack? A Glimpse At The RoadmapShamailXD
 
Xen versus kvm_slides_20080623
Xen versus kvm_slides_20080623Xen versus kvm_slides_20080623
Xen versus kvm_slides_20080623Todd Deshane
 
New Am Resorts Corp Presentation 4 18 12
New Am Resorts Corp Presentation  4 18 12New Am Resorts Corp Presentation  4 18 12
New Am Resorts Corp Presentation 4 18 12Pamela Payne, CMP
 
AMResorts Meetings & Incentives Presentation
AMResorts Meetings & Incentives PresentationAMResorts Meetings & Incentives Presentation
AMResorts Meetings & Incentives PresentationPamela Payne, CMP
 
Docker Meetup Bangalore - Docker + Openstack
Docker Meetup Bangalore - Docker + OpenstackDocker Meetup Bangalore - Docker + Openstack
Docker Meetup Bangalore - Docker + OpenstackAshish Billore
 

Viewers also liked (20)

Magnum Networking Update
Magnum Networking UpdateMagnum Networking Update
Magnum Networking Update
 
INCAR SERVICE SRL
INCAR SERVICE SRLINCAR SERVICE SRL
INCAR SERVICE SRL
 
7 Habits of Highly Effective Contirbutors
7 Habits of Highly Effective Contirbutors7 Habits of Highly Effective Contirbutors
7 Habits of Highly Effective Contirbutors
 
Analytics & Reporting for Amazon Cloud Logs
Analytics & Reporting for Amazon Cloud LogsAnalytics & Reporting for Amazon Cloud Logs
Analytics & Reporting for Amazon Cloud Logs
 
Colca valley arequipa peru
Colca valley arequipa peruColca valley arequipa peru
Colca valley arequipa peru
 
Trusted Advisors in Retained Executive Search
Trusted Advisors in Retained Executive SearchTrusted Advisors in Retained Executive Search
Trusted Advisors in Retained Executive Search
 
Xen versus kvm_20080623
Xen versus kvm_20080623Xen versus kvm_20080623
Xen versus kvm_20080623
 
Conflict styles
Conflict stylesConflict styles
Conflict styles
 
DPACC Acceleration Progress and Demonstration
DPACC Acceleration Progress and DemonstrationDPACC Acceleration Progress and Demonstration
DPACC Acceleration Progress and Demonstration
 
Brand Promotion Looped
Brand Promotion LoopedBrand Promotion Looped
Brand Promotion Looped
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
 
Debunking Myths & Mysteries of Retained Search
Debunking Myths & Mysteries of Retained SearchDebunking Myths & Mysteries of Retained Search
Debunking Myths & Mysteries of Retained Search
 
Magnum first-class-resource
Magnum first-class-resourceMagnum first-class-resource
Magnum first-class-resource
 
What's Next in OpenStack? A Glimpse At The Roadmap
What's Next in OpenStack? A Glimpse At The RoadmapWhat's Next in OpenStack? A Glimpse At The Roadmap
What's Next in OpenStack? A Glimpse At The Roadmap
 
Redmine Applied for Large Scale
Redmine Applied  for Large ScaleRedmine Applied  for Large Scale
Redmine Applied for Large Scale
 
Xen versus kvm_slides_20080623
Xen versus kvm_slides_20080623Xen versus kvm_slides_20080623
Xen versus kvm_slides_20080623
 
New Am Resorts Corp Presentation 4 18 12
New Am Resorts Corp Presentation  4 18 12New Am Resorts Corp Presentation  4 18 12
New Am Resorts Corp Presentation 4 18 12
 
AMResorts Meetings & Incentives Presentation
AMResorts Meetings & Incentives PresentationAMResorts Meetings & Incentives Presentation
AMResorts Meetings & Incentives Presentation
 
Sap MM
Sap MMSap MM
Sap MM
 
Docker Meetup Bangalore - Docker + Openstack
Docker Meetup Bangalore - Docker + OpenstackDocker Meetup Bangalore - Docker + Openstack
Docker Meetup Bangalore - Docker + Openstack
 

Similar to SQL Security and ADO.NET in .NET

Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETFernando G. Guerrero
 
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101IDERA Software
 
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...SpanishPASSVC
 
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 201510 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015Scott Sutherland
 
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginners
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginnersSQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginners
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginnersTobias Koprowski
 
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012Michael Noel
 
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint SecuritySPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint SecurityMichael Noel
 
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...Michael Noel
 
sql server authentication types by moamen hany
sql server authentication types by moamen hanysql server authentication types by moamen hany
sql server authentication types by moamen hanyMoamen Hany ELNASHAR
 
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsTROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsScott Sutherland
 
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellDerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellScott Sutherland
 
The Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityThe Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityChris Bell
 
Lesson 5 security
Lesson 5   securityLesson 5   security
Lesson 5 securityRam Kedem
 
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...Michael Noel
 
AUSPC 2013 - Understanding the Five Layers of SharePoint Security
AUSPC 2013 - Understanding the Five Layers of SharePoint SecurityAUSPC 2013 - Understanding the Five Layers of SharePoint Security
AUSPC 2013 - Understanding the Five Layers of SharePoint SecurityMichael Noel
 
SafePeak - How to configure SQL Server agent in a safepeak deployment
SafePeak - How to configure SQL Server agent in a safepeak deploymentSafePeak - How to configure SQL Server agent in a safepeak deployment
SafePeak - How to configure SQL Server agent in a safepeak deploymentVladi Vexler
 
SQL Server Lecture 1
SQL Server Lecture 1SQL Server Lecture 1
SQL Server Lecture 1Hazem Torab
 

Similar to SQL Security and ADO.NET in .NET (20)

Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NET
 
Where should I be encrypting my data?
Where should I be encrypting my data? Where should I be encrypting my data?
Where should I be encrypting my data?
 
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101
 
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
 
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 201510 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
 
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginners
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginnersSQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginners
SQLSaturday#290_Kiev_WindowsAzureDatabaseForBeginners
 
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012
 
Partially Contained Databases
Partially Contained DatabasesPartially Contained Databases
Partially Contained Databases
 
A to z for sql azure databases
A to z for sql azure databasesA to z for sql azure databases
A to z for sql azure databases
 
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint SecuritySPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
 
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
 
sql server authentication types by moamen hany
sql server authentication types by moamen hanysql server authentication types by moamen hany
sql server authentication types by moamen hany
 
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory EnvironmentsTROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
TROOPERS 20 - SQL Server Hacking Tips for Active Directory Environments
 
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShellDerbyCon2016 - Hacking SQL Server on Scale with PowerShell
DerbyCon2016 - Hacking SQL Server on Scale with PowerShell
 
The Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityThe Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server Security
 
Lesson 5 security
Lesson 5   securityLesson 5   security
Lesson 5 security
 
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
 
AUSPC 2013 - Understanding the Five Layers of SharePoint Security
AUSPC 2013 - Understanding the Five Layers of SharePoint SecurityAUSPC 2013 - Understanding the Five Layers of SharePoint Security
AUSPC 2013 - Understanding the Five Layers of SharePoint Security
 
SafePeak - How to configure SQL Server agent in a safepeak deployment
SafePeak - How to configure SQL Server agent in a safepeak deploymentSafePeak - How to configure SQL Server agent in a safepeak deployment
SafePeak - How to configure SQL Server agent in a safepeak deployment
 
SQL Server Lecture 1
SQL Server Lecture 1SQL Server Lecture 1
SQL Server Lecture 1
 

More from Fernando G. Guerrero

Itinerarios de Grado de Ingenieria Informatica EPS Alicante
Itinerarios de Grado de Ingenieria Informatica EPS AlicanteItinerarios de Grado de Ingenieria Informatica EPS Alicante
Itinerarios de Grado de Ingenieria Informatica EPS AlicanteFernando G. Guerrero
 
New gTLDs between two rounds: trade mark challenges
 New gTLDs between two rounds: trade mark challenges New gTLDs between two rounds: trade mark challenges
New gTLDs between two rounds: trade mark challengesFernando G. Guerrero
 
Concurrency problems and locking techniques in SQL Server 2000 and VB.NET
Concurrency problems and locking techniques in SQL Server 2000 and VB.NETConcurrency problems and locking techniques in SQL Server 2000 and VB.NET
Concurrency problems and locking techniques in SQL Server 2000 and VB.NETFernando G. Guerrero
 
Achieve the Impossible: Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...
Achieve the Impossible:Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...Achieve the Impossible:Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...
Achieve the Impossible: Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...Fernando G. Guerrero
 
Datos Geométricos y Espaciales en SQL Server 2008
Datos Geométricos y Espaciales en SQL Server 2008Datos Geométricos y Espaciales en SQL Server 2008
Datos Geométricos y Espaciales en SQL Server 2008Fernando G. Guerrero
 
Microsoft Changed the Game Again and Gave New Wings to an Entire Industry
Microsoft Changed the Game Again and Gave New Wings to an Entire IndustryMicrosoft Changed the Game Again and Gave New Wings to an Entire Industry
Microsoft Changed the Game Again and Gave New Wings to an Entire IndustryFernando G. Guerrero
 
Making business sense of the continuous and anarchic flow of Social Media data
Making business sense of the continuous and anarchic flow of Social Media dataMaking business sense of the continuous and anarchic flow of Social Media data
Making business sense of the continuous and anarchic flow of Social Media dataFernando G. Guerrero
 
Designing Role-Based Database Systems to Achieve Unlimited Database Scalability
Designing Role-Based Database Systems to Achieve Unlimited Database ScalabilityDesigning Role-Based Database Systems to Achieve Unlimited Database Scalability
Designing Role-Based Database Systems to Achieve Unlimited Database ScalabilityFernando G. Guerrero
 
Data Mining for Moderation of Social Data
Data Mining for Moderation of Social DataData Mining for Moderation of Social Data
Data Mining for Moderation of Social DataFernando G. Guerrero
 
Solid q universidad empresa 2011 10 27
Solid q universidad empresa 2011 10 27Solid q universidad empresa 2011 10 27
Solid q universidad empresa 2011 10 27Fernando G. Guerrero
 

More from Fernando G. Guerrero (12)

Udf eficientes
Udf eficientesUdf eficientes
Udf eficientes
 
Itinerarios de Grado de Ingenieria Informatica EPS Alicante
Itinerarios de Grado de Ingenieria Informatica EPS AlicanteItinerarios de Grado de Ingenieria Informatica EPS Alicante
Itinerarios de Grado de Ingenieria Informatica EPS Alicante
 
New gTLDs between two rounds: trade mark challenges
 New gTLDs between two rounds: trade mark challenges New gTLDs between two rounds: trade mark challenges
New gTLDs between two rounds: trade mark challenges
 
Concurrency problems and locking techniques in SQL Server 2000 and VB.NET
Concurrency problems and locking techniques in SQL Server 2000 and VB.NETConcurrency problems and locking techniques in SQL Server 2000 and VB.NET
Concurrency problems and locking techniques in SQL Server 2000 and VB.NET
 
Vda305 concurrency guerrero
Vda305 concurrency guerreroVda305 concurrency guerrero
Vda305 concurrency guerrero
 
Achieve the Impossible: Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...
Achieve the Impossible:Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...Achieve the Impossible:Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...
Achieve the Impossible: Use INSTEAD OF triggers in SQL Server 2000 to Deal Tr...
 
Datos Geométricos y Espaciales en SQL Server 2008
Datos Geométricos y Espaciales en SQL Server 2008Datos Geométricos y Espaciales en SQL Server 2008
Datos Geométricos y Espaciales en SQL Server 2008
 
Microsoft Changed the Game Again and Gave New Wings to an Entire Industry
Microsoft Changed the Game Again and Gave New Wings to an Entire IndustryMicrosoft Changed the Game Again and Gave New Wings to an Entire Industry
Microsoft Changed the Game Again and Gave New Wings to an Entire Industry
 
Making business sense of the continuous and anarchic flow of Social Media data
Making business sense of the continuous and anarchic flow of Social Media dataMaking business sense of the continuous and anarchic flow of Social Media data
Making business sense of the continuous and anarchic flow of Social Media data
 
Designing Role-Based Database Systems to Achieve Unlimited Database Scalability
Designing Role-Based Database Systems to Achieve Unlimited Database ScalabilityDesigning Role-Based Database Systems to Achieve Unlimited Database Scalability
Designing Role-Based Database Systems to Achieve Unlimited Database Scalability
 
Data Mining for Moderation of Social Data
Data Mining for Moderation of Social DataData Mining for Moderation of Social Data
Data Mining for Moderation of Social Data
 
Solid q universidad empresa 2011 10 27
Solid q universidad empresa 2011 10 27Solid q universidad empresa 2011 10 27
Solid q universidad empresa 2011 10 27
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

SQL Security and ADO.NET in .NET

  • 1. Session VDA306 Dealing with SQL Security from ADO.NET Fernando G. Guerrero SQL Server MVP .NET Technical Lead QA plc October 2002
  • 2. Quick info about Fernando (2 milliseconds) • MCSD, MCSE+Internet (W2K), MCDBA, MCT, QA SQL Server MVP • This is where I work: QA, The best learning environment in Europe • Writing for SQL Sever Magazine and SQL Server Professional • This is my main web site: www.callsql.com • This is my book (so far): – Microsoft SQL Server 2000 Programming by Example (ISBN : 0789724499, co-authored with Carlos Eduardo Rojas) • Currently writing on ADO.NET and SQL Server 2000 VS.NET Connections
  • 3. Agenda • SQL Server Authentication modes • Access to SQL Server Databases • Application security using SQL Server 2000 and ADO.NET • Note: as this is a VS.NET session, I’ll show you as much ADO.NET, VB.NET and SQL-DMO code as possible, but you need to know about how SQL Server deals with security as well VS.NET Connections
  • 4. SQL Server Authentication modes • SQL Server Authentication – SQL Server specific logins – Not recommended for Windows users – Specify UID/PWD in the ConnectionString • Windows integrated – Create logins for Windows groups, not users – Deny access to SQL Server by creating Windows logins in SQL Server – Specify Trusted_Connection=true in the ConnectionString VS.NET Connections
  • 5. SQL Server Authentication • Easy to understand • Independent of the Windows Domain structure • Not too flexible • Easier to break • Connection pooling unfriendly VS.NET Connections
  • 6. SQL Server Authentication (2) • Most applications still connect as sa and no password (or password as password) • Could provide an extra layer of authentication • IIS+NT friendly • If you write your UID/PWD in the connection string, someone could read it • Connection pooling friendly VS.NET Connections
  • 7. How to create SQL Server logins programmatically from Visual Basic .NET (demo) VS.NET Connections
  • 8. Windows Authentication • Easier to administer in the long run • Complex security combinations – NT Groups to reflect actual business structure – Combinations of groups give actual permissions • Comprehensive security control based on Windows NT / 2000 / .NET security: – Password policies – Location and time control – Automatic account blocking VS.NET Connections
  • 9. Windows Authentication (2) • Grant access to lots of users in a single shot • Deny access to lots of users in a single shot too • Make code easier to deploy and maintain • You don’t write your UID/PWD in the connection string, so it is more difficult to hack VS.NET Connections
  • 10. Connection Strings and Windows authentication in ADO.NET (demo) VS.NET Connections
  • 11. How to create programmatically Windows logins in SQL Server 2000 from Visual Basic .NET (demo) VS.NET Connections
  • 12. Using SQL-DMO from VB.NET to manage the authentication mode, and SQL Server security • In this demonstration you will see how to: – Change the SQL Server Authentication Mode – Manage SQL Server logins • And we will do it by using VB.NET with: – SQL-DMO – SQLCommand objects VS.NET Connections
  • 13. The nasty error 18452 • SQL Server is configured for Windows Authentication only: – Not even the sa can login • Before changing to Mixed authentication mode, give a strong password to the sa login! VS.NET Connections
  • 14. What if you dropped the Builtin/Administrators login? • Unless you have a valid login to access SQL Server, you are into troubles • You can start a new session using the Windows service account and create the appropriate logins • Or edit the registry and change the value of the following key to 2: – Default instance: • HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLSe rverMSSQLServerLoginMode – Named instances: • HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerInstanceNameMSSQLServerLoginMode VS.NET Connections
  • 15. Fixed Server Roles • Administrative groups to easier server-wide permissions – Sysadmin: They can do anything, SQL Server permissions don’t affect them • Other roles are subsets of sysadmin, for better permissions’ granularity: – setupadmin – securityadmin – processadmin – dbcreator – diskadmin – bulkadmin VS.NET Connections
  • 16. How to use Server Roles from ADO.NET • Simply put: you don’t • The connection gets automatically server role membership according to the login used to connect to SQL Server • To get the permission path used to connect to SQL Server, execute: – xp_logininfo [DomainNameUserName] VS.NET Connections
  • 17. Getting role membership information • Use the IS_SRVROLEMEMBER function • Execute the sp_helpsrvrolemember stored procedure • Use the ListMembers method from SQL-DMO • Execute this query for actual logins defined in SQL Server: SELECT 'ServerRole' = spv.name FROM master.dbo.spt_values spv JOIN master.dbo.sysxlogins lgn ON spv.low = 0 AND spv.type = 'SRV' AND lgn.srvid IS NULL AND spv.number & lgn.xstatus = spv.number WHERE lgn.sid = SUSER_SID('LoginName') VS.NET Connections
  • 18. Trying (unsuccessfully) to apply permissions to sysadmin members (demo) VS.NET Connections
  • 19. Agenda • SQL Server Authentication modes • Access to SQL Server Databases • Application security using SQL Server 2000 and ADO.NET VS.NET Connections
  • 20. Access to SQL Server Databases • A login gives you access to SQL Server • To access a database, you need a user on that database • Retrieve the current login using the SYSTEM_USER function • Retrieve the current user using the CURRENT_USER function • It doesn’t matter how many Windows groups you belong to: SQL Server knows you. • The dbo user VS.NET Connections • The guest user
  • 21. Fixed Database Roles • A very important one: Public – Everybody belongs to Public – Useful to set default permissions • Other roles simplify permissions: • db_owner • db_accessadmin / db_securityadmin • db_ddladmin • db_backupoperator • db_datareader / db_denydatareader • db_datawriter / db_denydatawriter VS.NET Connections
  • 22. Do db_owner members have all permissions they think they have? (demo) VS.NET Connections
  • 23. Agenda • SQL Server Authentication modes • Access to SQL Server Databases • Application security using SQL Server 2000 and ADO.NET VS.NET Connections
  • 24. Application security using SQL Server 2000 and ADO.NET • You can deny permissions to every user on all access to tables • Grant permissions to use views • Grant permissions to execute stored procedures • As long as all of them have the same owner, user will need permissions only on views / stored procedures • SQL Server won’t check permissions on underlying objects / statements • It doesn’t work with dynamic execution VS.NET Connections
  • 25. Testing application security with views and stored procedures from ADO.NET (demo) VS.NET Connections
  • 26. Granting and denying permissions on SQL statements • GRANT Permission TO User/Role: – CREATE DATABASE – CREATE DEFAULT – CREATE FUNCTION – CREATE PROCEDURE – CREATE RULE – CREATE TABLE – CREATE VIEW – BACKUP DATABASE – BACKUP LOG VS.NET Connections
  • 27. Granted – Denied - Revoked • No permissions (not granted nor denied) means I’M SORRY • Granted means PERHAPS – You might o might not have final permission – Depends on membership on other roles/groups • Denied means NO WAY – You can’t perform that action, no matter what • Revoked means I FORGOT ABOUT IT – Your security record has been removed (it could have been granted or denied in the past) – Effective permissions depend on role/groups membership VS.NET Connections
  • 28. Granting and denying permissions on specific database objects • GRANT Permission ON Object TO User/Role VS.NET Connections
  • 29. Permissions Errors • A permission error doesn’t break connections • A permission error doesn’t break execution • A permission error doesn’t roll transactions back • So, it is up to you to check for errors on permissions and take the right action VS.NET Connections
  • 30. SQL Server application roles • Defined at Database level • Password required • Don’t have any members • Always belong to Public role • May belong to other database roles • Need to be activated before use • Cannot be de-activated • Connection-pooling unfriendly VS.NET Connections
  • 31. SQL Server application roles (Creation) • EXEC sp_addapprole ‘RoleName’, ‘RolePassword’ • It is considered as a special user in the database, not a group • Grant permissions to the role by using: • GRANT Permissions ON Object to AppRole • Deny permissions to the role by using: • DENY Permissions ON Object to AppRole VS.NET Connections
  • 32. SQL Server application roles (Activation) • EXEC sp_setapprole ‘RoleName’, {Encrypt N ‘Password'}, ‘ODBC‘ • How to protect the password? – Store it in a encrypted file – Scramble it through the code and protect it against debug mode – Store it in Active Directory – Encapsulate this call in a Component VS.NET Connections
  • 33. Using application roles from ADO.NET (demo) VS.NET Connections
  • 34. Passport-like authentication • Your application can authenticate users from login/password data • Store open login, encrypted password • Compare encrypted passwords • Create the entire thing as system objects VS.NET Connections
  • 35. Do you want to know more? • “Inside SQL Server 2000” (Kalen Delaney, MSPress) • “Advanced Transact-SQL for SQL Server 2000” (Itzik Ben- Gan & Tom Moreau, APress) • “SQL Server 2000 Programming” (Robert Vieira, WROX) • “Microsoft SQL Server 2000 Programming by Example” (Fernando G. Guerrero & Carlos Eduardo Rojas, QUE) • “System.Data: A Clockwork Link between VB.NET and SQL Server ” (Fernando G. Guerrero, Apress) • SQL Server 2000 Resource Kit (MSPress & TechNet) • Visit the Microsoft public newsgroups: – msnews.microsoft.com/microsoft.public.sqlserver.* VS.NET Connections
  • 36. Thank you! Questions? • Download the source code of this session from: – http://www.callsql.com/en/articles • You can contact me at: – fernan@guerrerog.org VS.NET Connections
  • 37. Thank you! • Please drop off your session evaluations in the basket at the back of the room! • Your comments are greatly appreciated! VS.NET Connections