0% found this document useful (0 votes)
16 views

DB_LO5_v2

Uploaded by

marwanelgammal55
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

DB_LO5_v2

Uploaded by

marwanelgammal55
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

“Database Safety & Security”

Fifth Learning Outcome

Team G2
Database Safety & Security
● Database security is the practice of protecting databases and
their contents from unauthorized access, use, disclosure,
modification or destruction.
● It involves a combination of technical,administrative and
physical controls to ensure the confidentiality, integrity and
availability of data.
● The importance of database security cannot be overstated, as
databases often contain sensitive and valuable information
such as personal data, financial information, trade secrets and
intellectual property.

● A breach of database security can result in a significant


financial and reputational damage to an organization, as well
as legal and regulatory consequences.
There are several best practices for securing databases, including:

Authentication
and Access Controls Regular Maintenance
Authorization and Patching

1 2 3 4
5
Encryption Auditing
and
Monitoring
AUTHENTICATION VS AUTHORIZATION
❏ In the authentication process, the ❏ While in authorization process, a the
identity of users are checked for person’s or user’s authorities are
providing the access to the system. checked for accessing the
resources.
❏ In the authentication process, users ❏ While in this process, users or
or persons are verified. persons are validated.

❏ It needs usually the user’s login ❏ While this process is done after the
details. authentication process.
❏ Authentication determines whether ❏ While it needs the user’s privilege
the person is user or not. or security levels.
WHAT IS THE TYPE OF SECURITY?

Activity time
…………………

…………………
Encryption Types
ENCRYPTION TYPES

● Database encryption types refer to the different methods and techniques used
to encrypt the data stored in databases.

● Encryption helps protect sensitive information from unauthorized access or


theft.

Transparent Data Encryption


Full Database Encryption

Column-level Encryption Hashing


● Full Database Encryption: This
approach involves encrypting the
entire database, including
all tables, columns and other
elements.

● It provides comprehensive protection,


● Column-level Encryption: In this
but it may impact performance due
method, specific columns containing
to the overhead of encrypting and
sensitive data are encrypted while the
decrypting large amounts of data.
rest of the database remains
unencrypted.

● It allows for more granular control over


data protection and reduces
performance overhead compared to
a full database encryption.
Transparent Data Encryption (TDE): TDE is a feature offered by many
database management systems (DBMS).

❏ It automatically encrypts data at the file level as it is written to a disk and it


decrypts it when read from a disk.
❏ This approach ensures that data remains encrypted when stored on disk,
providing an extra layer of protection
Hashing: Hashing is a one-way encryption technique that converts data into a fixed-length string of
characters (hash value) using a mathematical algorithm.
● The original data cannot be derived from the hash value, making it suitable for password
storage or verifying data integrity.
● Hashing technique is used to calculate the direct location of a data record on the disk without using
index structure.
● In this technique, data is stored at the data blocks whose address is generated by using the hashing
function. The memory location where these records are stored is known as data bucket or data
blocks.
It is important to note that the availability of specific encryption methods may vary
depending on the database management system used. Additionally, the choice of
encryption type should consider factors such as performance requirements, regulatory
compliance and the sensitivity of the data being protected.

● The below is a step-by-step instruction to encrypt MS SQL server database


◄ Step1: Identify the database:
Determine which database you want to encrypt within your SQL Server
instance

◄ Step2: Determine the Encryption Method


The encryption method of use should be decided. An SQL Server provides
two main options:
Transparent Data Encryption (TDE) and Cell-level Encryption.
TDE encrypts the entire database,while Cell-level Encryption allows
the encryption of specific columns or cells.
Step3: Set up a certificate or asymmetric key Step4: Back up the certificate or key
● Encryption in an SQL Server requires a ● It is essential to back up the certificate or key to
certificate or an asymmetric key. either a new prevent data loss. Store the backup in a secure
certificate is created or an existing certificate location.
can be used. To back up a certificate, use the following T-SQL
To create a new certificate, use the following T- statement
SQL statement BACKUP CERTIFICATE [CertificateName] TO FILE =
CREATE CERTIFICATE [CertificateName] WITH ‘CertificateBackupFilePath’
SUBJECT = ‘Certificate Subject’; WITH PRIVATE KEY ( FILE =
‘PrivateKeyBackupFilePath’, ENCRYPTION BY
PASSWORD =‘PrivateKeyPassword’);

To create a new asymmetric key, use the following To back up an asymmetric key, use the following T-SQL
T-SQL statement statement
CREATE ASYMMETRIC KEY
[AsymmetricKeyName] WITH ALGORITHM = BACKUP ASYMMETRIC KEY [AsymmetricKeyName]
RSA_2048; TO
FILE= ‘AsymmetricKeyBackupFilePath’
ENCRYPTION BY PASSWORD =
‘AsymmetricKeyPassword’;
Step5: Enable Transparent Data Encryption (TDE) (optional)
If TDE was chosen as the encryption method, it should be enabled for the
database. Right click on the database, go to “Tasks,” and select “Encrypt Data.”,
Follow the wizard instructions to set up TDE and choose the certificate created
or selected.

Step6: Encrypt columns or cells (optional)


If Cell-level Encryption is selected, specific columns or cells within the database can
be encrypted.
➡ Use the ENCRYPTBYKEY function to encrypt data in a column or cell.
➡ Use the DECRYPTBYKEY function to decrypt the encrypted data when needed.
Auditing and Monitoring
❑ AUDITING AND MONITORING
to monitor the MS SQL server database logs
and an introduction to some top known log
events:
Step 1: Enable SQL Server Error Logging
➡ Open SQL Server Management Studio
(SSMS) and connect to the SQL Server
instance
➡ Expand Management, right-click SQL Server
Logs, and then click Configure.
➡ In the Configure SQL Server Error Logs
dialog box, choose from the following options
LOG FILES COUNT ▪
▪ Limit the number of the error log files
before they are recycled :
A new error log is created each time an instance of SQL
Server is started. SQL Server retains backups of the
previous six logs,unless this option is checked and a
different maximum number of error log files is specified
below.
▪ Maximum number of error log files
Specify the maximum number of archived error log files created
before they are recycled. The default is 6, not including the
current one. This value determines the number of previous
backup logs that an SQL Server retains before recycling them
LOG FILE SIZE ▪
Maximum size for error log file in KB
The size amount of each file can be set in KB, If
it is left at 0, the log size is unlimited.
STEP 2: ACCESS SQL SERVER ERROR
➡ In SSMS, expand the “Management” node, right-
LOGS
click on “SQL Server Logs,” and choose “View SQL
Server Log.”
➡ The “Log File Viewer” window will display the SQL
Server error logs, including the current and
archived logs
SAMPLE OF TOP
KNOWN LOG EVENTS
1) Login Failures: Look for login failures indicating potential
security threats or authentication issues
2) Database Backup and Restore: Monitor successful and failed
backup and restore operations
3) SQL Server Errors: Track error messages indicating query
failures, resource limitations or database integrity issues
4) Deadlocks: Watch for deadlock events that occur when two or
more processes compete for resources
5) Performance Metrics: Analyse performance-related log events,
such as long-running queries or high CPU utilization
Database Security Threats
DATABASE SECURITY THREATS
It’s essential to be aware of the top security threats that
databases may face. Here are common security threats with
examples of what these attacks can do to your database
1)SQL Injection Attacks: occur when an attacker maliciously
injects malicious SQL code into an application’s input fields to
manipulate the database. This can lead to unauthorized
access, data theft, data modification or even complete control
of the database. For example, an attacker could exploit a
vulnerable login form to bypass authentication and gain
administrative access to the database.
:DATA BREACHES)2

data breach involves unauthorized access to sensitive


data stored in the database. Attackers can steal or
expose sensitive information such as customer records,
personal identifiable information (PII), financial data or
intellectual property. This can lead to severe
reputational damage, legal consequences and financial
losses for individuals and organizations
3) Insider Threats:
Insider threats refer to unauthorized activities
performed by individuals with legitimate
access to the database, such as employees or
contractors. These individuals may abuse their
privileges to steal, modify, delete data or to
gain unauthorized access to restricted areas.
For instance, a disgruntled employee might
intentionally delete or modify critical data,
causing significant disruptions to the
organization.
4) Denial-of-Service (DoS) Attacks:
DoS attacks aim to disrupt the availability of the
database by overwhelming it with a flood of
illegitimate requests or by exploiting vulnerabilities. As
a result, legitimate users are denied access to the
database or experience significant performance
degradation. A successful DoS attack can render the
database unavailableand impact critical business
operations.
5) Privilege Escalation:
❑ Privilege escalation attacks involve exploiting
vulnerabilities in user permissions to gain
higher privileges within the database system.
For example, an attacker may gain
unauthorized administrative access by
exploiting weak access controls or
misconfigurations. With elevated privileges,
they can perform unauthorized operations,
steal sensitive data or disrupt the database
environment

From the above problems what you should make


❑ From the above deduce importance of
implementing robust security measures, including access
controls, encryption, strong authentication mechanisms,
regular patching and monitoring. Regular security
assessments, vulnerability scanning, and penetration
testing .
1. can help identify and address potential vulnerabilities
before they are exploited
2. implementing security best practices, educating users
and keeping up-to-date with security
3. patches and updates are crucial for protecting your
database environment.tential vulnerabilities before they
are exploited.
Understanding SQL Server Security
UNDERSTANDING SQL SERVER
SECURITY
Microsoft SQL Server
❖ provides several built-in features that enable
security, including encrypted communication
over SSL/TLS, the Windows Data Protection API
(DPAPI) used to encrypt data at rest,
authentication and authorization.
❖ It is up to each database administrator to configure these
features or use additional security measures as needed to
address the security and compliance requirements of their
data and applications.
SQL Server security is based on several hierarchical entities.
1)Securables: are the server representing the
entire SQL Server instance, the database where
each server can have multiple databases, a
database is a collection of securable objects and
securable objects which stored in a database
2)Principals: a person, group, or process that
needs to access data. Privileges granted to
principals are managed by the SQL Server
security framework
3)Permissions: are granted to a principal for
every SQL server securable .
ACTIVITY
Devide students into 5 groups and every group
search about which principles we have in
1)for windows Authentication
2) SQL Server Level Authentication
3) Database Level Authentication
4) Securables in which we have
5) permision
: PRINCIPALS IN WHICH WE HAVE

a Windows Level Authentication where you can


use
i. Windows group
ii. Windows domain login
iii. Windows local login

B SQL Server Level Authentication where you


can use
iv. Fixed server role
v. SQL server login
vi. User-defined fixed server role
C Database Level Authentication
i. Fixed database role
ii. Database user
iii. Application role
iv. User-defined database role
SECURABLES IN WHICH WE HAVE

a Physical MS SQL Server


B Databases which may contains the following
objects
i. Table
ii. View
iii. Function
iv. Procedure
v. Queue
vi. Synonym
vii. Type
viii. XML schema collection
TO ACCESS DATABASE CONTENT THERE ARE THREE-
TIERED SECURITY

1) SQL Server Access, a login is a security principal


that can be authenticated by secure system to
provide a user access to specific SQL server
2) Database Access, a database user is mapped to
SQL login and provides a user group or group
access to database
3) Object Access, permissions are applied at the
object level to provide the appropriate access to
the objects within the database
QUESTION IN 5 MUNITS
From the previous slide ,Deduce in short way
how give the user access on Database

Specific SQL Server-> Specific your Database-


> Specific properties->Specific Permission ->
choose from users
Server Level Security
SERVER LEVEL SECURITY
Authentication is the act of verifying a user or
system identity and allowing them to login
using:
➡ Windows Authentication
• Windows user account
• Windows security group
➡ Mixed-mode Authentication (Windows and
SQL logins)
• SQL Server specific login
• sa account (built-in SQL administrator)
➡ SQL server includes several fixed server roles,
• Sysadmin: performs any activity on the
server
• Dbcreator: creates, alters, drops, restores
databases
• Securityadmin: manages logins and their
properties
Database & Objects Level Security
DATABASE & OBJECTS LEVEL SECURITY

• A database user is database level security


principal
that must be mapped to a login at the
server level in order to connect to the
database. A login can be mapped to
different databases as different users but
can only be mapped as one user in each
database.
User-defined database roles that have
specific permissions applied to the roles
SQL server includes several fixed database
roles:
➡ db_owner: perform all configuration
activities
➡ db_datareader: real all data from all user
tables
➡ db_datawriter: add, delete, or change data
the figure below shows the security tree and
the logins
CREATE NEW LOGIN
right click the logins
select New login 1

2
3)To assign the security admin role to the new
created user
4)from user mapping page, map user to your
database and assign database role db_
datareader to the new created user.
ADD NEW USER
From your database security -> choose user ->new
user
PERMISSIONS
From your database ->right click ->
choose properties-> choose
permissions
Then choose the your user that you
want to give permission
1 2

3
Note that the guest user account is included in
every database and can be used by any user
who has access to the database but does not
have a user account within the database. The
guest user account cannot be dropped but it
can be disabled by revoking its connect
permission
Delete Database User
DELETE DATABASE USER

To delete database user, follow the steps below

Step 1: Connect to SQL Server


➡ Open SQL Server Management Studio (SSMS) and connect to the SQL
Server instance where the user exists.
➡ Provide the appropriate credentials to establish the connection.

Step 2: Open Object Explorer


➡ In SSMS, expand the server node to view the database hierarchy
➡ Expand the “Security” folder, then expand “Logins” or “Database”
> “Security” > “Users,”depending on the user type

Step 3: Locate the User


➡ Find the user you want to delete in the list of logins or database users
STEP STEP
2 3
DELETE DATABASE USER

Step 4: Delete the User


➡ Right-click on the user and select “Delete” or “Remove.”
➡ A confirmation dialog may appear to verify the deletion. Confirm the action

Step 5: Remove User Mapping (if applicable)


➡ If the user was mapped to any databases, remove the mapping for these
databases
➡ In the “User Mapping” window, uncheck the databases the user had
access to or remove the user from specific roles within the database.

Step 6: Confirm the User Deletion


➡ Review the user deletion action and its impact
➡ Click “OK” to delete the user
STEP STEP
4 5
STEP
6 User Deletion
Confirm the
Managing Database Objects Permissions

Permissions to database objects can be managed by using the following commands

❏ Grant, provides a level of access to the object


❏ Deny, overrides any grant permission
❏ Revoke, removes the previously assigned permissions, regardless of whether it was a
deny or grant permission
Object permissions are the permissions that
allow a user to perform actions on database
objects such as tables, views and stored
procedures.
● SELECT
● INSERT
● UPDATE
● DELETE
● DRI (Data Referential Integrity)
● EXECUTE (for stored procedures)
SQL SERVER DATABASE BACKUP

● Preventing data from being lost is a fundamental


part of securing a database. That is why the
concept of having a database backup is curial .

● A Database backup is performed to restore data if it is corrupted or lost.

● A user may accidentally delete a table, this requires the database


administrator DBA to restore the table to the format it was when the last
backup was performed.

● Database backups can also be used to restore content on another SQL


server to generate reports from that server.
COMMON TYPES OF BACKUPS
● Full backup: The most basic
and comprehensive backup
method, where all data is sent
to another location.

● Incremental backup: Backs up


all files that have changed since
the last backup occurred.

● Differential backup: Backs up


only copies of all files that have
changed since the last full
backup.
Full backup contains all the data in a
specific database,a set of filegroups or files
and the portion of the transaction log
necessary to recover all the data.

This type of back takes a long time to


restore specially if you have a large amount of
data.

Differential backup contains all the


data that has changed since the differential
base.

Differential backup usually backs up less


amount of data compared to the full backup
and that is why its restore time is relatively
less compared to a full backup restore time.
Incremental backup
● contains data that has changed since the last full or incremental backup.
● Regularly the incremental backup takes a short time to restore data.

The figure shows the incremental backup scenario


● The table below compares the three backup types using the most important aspect considered when
building the database backup strategy
DATABASE BACKUPS

Based on practical experience, one of the most common backup strategies is to perform the below

1) Weekly full backup


2) Daily differential backup
3) Hourly incremental backup

● SSMS offers GUI to perform the database backup and write scripts to perform different backup Types.
● Normally write backup scripts are written and these different scripts are run based on time trigger
events.
For instance, if we want to backup the School database created throughout the course, as depicted in the figure below

Right click the database name,


select Tasks and hence select backup ,
● Make sure that the database you want to backup is typed in the database textbox.
● Select from the backup type dropdown list Full to perform full backup .
● You can select the destination of the resulted backup files using the backup to dropdown list and for
simplicity, keep Disk to save the backup files to the server hard drive.
● You can also select specific folder to save the backup files, using the below Add button, or keep the
suggested backup location as it is .

The below is what you get if you clicked Copy message


TITLE: Microsoft SQL Server Management Studio
------------------------------
The backup of database ‘School’ completed successfully.
------------------------------
BUTTONS:
OK
------------------------------
To verify that the backup file(s) are created, check the backup folder selected for the School.
bak file.
SQL SERVER DATABASE RESTORE
The task of securing the database by performing backup strategy remains useless if
database restore failed when needed.It is important not only to have a backup strategy in
place, but also to ensure that the generated backup can be restored successfully when
needed.
SSMS provides GUI to back up the database if needed and write scripts to perform the
database restore. To perform the database restore using the SSMS GUI,
● right click the database you want
● select Tasks ,
● Restore
● and finally select Database
as shown in the figure below
Database Restore
● The dialogue below will be displayed,
make sure that the source and
destination database names are
correct and that the right backup file is
selected in the backup sets to restore
option.

● Verify backup media selected using the


verify backup media button shown
below.

● Whenready click ok button to start the


restore database process.

● Check that there is no opened


connection to the database before
starting the restore task.
When restore task is completed successfully, the dialogue below will be prompted
LET’S
CODE
IT
EXERCISE
TIME
In Teams

Compare between different database backup types


in terms of storage space, backup speed, restore
speed and files needed to restore the database.
YOUR TIME TO
CODE
EXERCISE
★ Using the database implemented throughout the course, create two
different types of users to access the database.

★ For the above created users in this exercise, assign different permissions for
each user and explain the permission assigned scope.

★ Create a backup strategy plan for the database created throughout the course.
And explain the strategy tasks selected.
BEST STUDENTS
TODAY…
Student
1
Name
Student
2
Name
Student 3
Name
RESOURCES
◄ Database security
◄ https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-dat
abase-security/#what-is-database-security

◄ Authentication and authorization


◄ https://www.geeksforgeeks.org/difference-between-authentication-and-authorization/

◄ Database Backup
◄ https://www.unitrends.com/blog/types-of-backup-full-incremental-differential

◄ permissions
◄ https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-transact-sql?view=sql-s
erver-ver16
THANK
YOU

You might also like