Lecture 10
Lecture 10
Database Security
Mohamed al-jaafari
Lecture10 – Spring2023
Contents
Login Authentication
Database User Accounts and Roles
Types of Roles
Permission Validation
SQL Server Security Components
How do Permission Work?
Login Authentication
Database User Accounts and Roles
Permission Validation
Types of Roles
Principals
Entities that can be authenticated to access the SQL Server resources.
For example, your Windows login can be configured as a principal
that allows you to connect to a SQL Server database.
SQL Server supports three types of principals: logins, users, and
roles.
Logins exist at the server level
Users exist at the database level
Roles can exist at either level
SQL Server Security Components
Securables
SQL Server resources that can be accessed by a principal. Securables
are the actual resources you’re trying to protect, whether at the server
level (e.g., availability groups), database level (e.g., fulltext catalog),
or the schema level (e.g., table or function).
SQL Server Security Components
Permissions
Types of access granted on a securable to a specific principal. For
example, you can grant a Windows login (the principal) the ability to
view data (the permission) in a specific database schema (the
securable).
SQL Server Security Components
Principals V Securables
SQL Server–Authenticated Logins
To create an authenticated login use:
Change Password
ALTER LOGIN Mohamed WITH PASSWORD = 'bestsite';
Disable a Login
ALTER LOGIN Mohamed DISABLE;
Enable a Login
ALTER LOGIN Mohamed ENABLE;
SQL Server–Authenticated Logins
Rename a Login
ALTER LOGIN Ali WITH NAME= Mohamed;
Find Logins
SELECT * FROM master.sys.sql_logins
Drop Logins
DROP LOGIN login_name;
SQL Server–Authenticated Logins
After creating a login, the login can connect to SQL Server, but
only has the permissions granted to the public role.
Consider performing some of the following activities. To connect
to a database, create a database user for the login.
Create a user-defined server role by using CREATE SERVER
ROLE. Use ALTER SERVER ROLE ... ADD MEMBER to add
the new login to the user-defined server role.
Use sp_addsrvrolemember to add the login to a fixed server role.
Use the GRANT statement, to grant server-level permissions to the
new login or to a role containing the login.
SQL Server–Database Users
DROP USER
DROP USER user_name;
Find Users
SELECT * FROM master.sys.database_principals;
SELECT * FROM master.sys.sysusers;
Fixed Server-Level Roles
serveradmin
Members of the serveradmin fixed server role can change server
wide configuration options and shut down the server.
Fixed Server-Level Roles
securityadmin
Members of the securityadmin fixed server role manage logins and
their properties. They can GRANT, DENY, and REVOKE server-
level permissions. They can also GRANT, DENY, and REVOKE
database level permissions if they have access to a database.
Additionally, they can reset passwords for SQL Server logins.
processadmin
Members of the processadmin fixed server role can end processes
that are running in an instance of SQL Server.
Fixed Server-Level Roles
setupadmin
Members of the setupadmin fixed server role can add and remove
linked servers by using Transact-SQL statements.
bulkadmin
Members of the bulkadmin fixed server role can run the BULK
INSERT statement.
diskadmin
The diskadmin fixed server role is used for managing disk files.
Fixed Server-Level Roles
dbcreator
Members of the dbcreator fixed server role can create, alter, drop, and
restore any database.
public
Every SQL Server login belongs to the public server role.
Manipulating Server Roles
db_datareader
Can read all data from all user tables and views.
db_denydatawriter
Cannot add , modify, or delete any data in the user tables within a
database.
db_denydatareader
Cannot read any data from the user tables and views within a database
Manipulating Database Roles
Role_name
Specifies the database role to change.
ADD MEMBER database_principal
Adds the specified database principal to the database role.
DROP MEMBER database_principal
Removes the specified database principal to the database role.
WITH NAME = new_name
Specifies the new name of the user_defined database role. This name
cannot already exist in the database
Manipulating Database Roles
You can grant users various privileges to tables. These permissions can
be any combination of SELECT, INSERT, UPDATE, DELETE,
REFERENCES, ALTER, or ALL.
Syntax
GRANT { ALL [ PRIVILEGES ] }
| permission [ ( column [ ,...n ] ) ] [ ,...n ]
[ ON object ] TO name [ ,...n ]
[ WITH GRANT OPTION ]
How do Permission Work?
Object
The name of the database object that you are granting permissions for.
In the case of granting privileges on a table, this would be the table
name.
User
The name of the user that will be granted these privileges
How do Permission Work?
GRANT SELECT, INSERT, UPDATE, DELETE ON Customers
TO Mohamed;
REVOKE EXECUTE ON
OBJECT :: dbo.getStudentSemesters FROM Ahmed ;
How do Permission work?