Database Security and Privacy UNIT - III - PPT
Database Security and Privacy UNIT - III - PPT
Database Security and Privacy UNIT - III - PPT
Prepared by
Dr. B. Muruganantham
Assistant Professor
Department of
Computer Science and
Engineering
SRMIST, Chennai
References :
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
UNIT III - Database Application Security Models & Virtual
Private Databases
Introduction
Types of Users
Security Models
Application Types
Application Security Models
Data Encryption
Overview of VPD
Implementation of VPD using Views
Application Context in Oracle
Implementing Oracle VPD
Viewing VPD Policies and Application contexts using Data Dictionary
Policy Manager Implementing Row
Column level Security with SQL Server
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Introduction
Application
A program that solves a problem or performs a specific business
function
Database
A collection of related data files used by an applications
DBMS
A collection of programs that maintain data files (Database)
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Types of Users
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models…
Access Matrix Model
A conceptual model that specifies the right that each subject
– possesses for each object
Subjects in rows and objects in columns
Object 1 Object 2 . . . Object m
. . . .
. . . .
. . . .
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models…
Access Matrix Model - Example
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models…
Access mode indicates that the subject can perform any task or not
There are two modes
Static Modes
Dynamic Modes
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models…
Access Modes – Static Modes
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Security Models…
Access Modes – Dynamic Modes
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types
Mainframe applications
Web Applications
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Mainframe applications
Years back computing in corporations was centralized in the Management Information
System(MIS)
MIS department is responsible for all information
MIS mainly developed for Mainframe projects The following figure is Mainframe
application architecture
Workstation Mainframe
Server
CODE
DB
Server
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Client / Server Applications
To overcome the limitations in MIS department the client / server architecture was
introduced
It is based on a business model, client request and the server respond
Client / Server architecture became a dominating configuration for all applications
Flexible
Scalable
Processing power
Three main components typically found in Client / Server architecture
User interface component – Represents all screens, reports, etc.,
Business logic component – Contains all the codes related to data
validations
Data access component – Contains all the codes related to retrieves,
inserts, deletes and updates
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Client / Server Applications
A client / server application consists of minimum of two tiers .
The following figure represents the logical components of a client server architecture
CLIENT
Tier 1
User Tier 2
Interface Business Tier 3
Logic Business Tier 4
Logic
Tier 5
SERVER
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Client Server
DB
User Business Data Server
Interface Logic Access
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Web Applications
Client server application once dominated but not for long.
Another architecture evolved with rise of dot-com and Web-based companies
The new client / server architecture is based on the web and it is referred as a web
application or a Web-based application
Web application uses HTTP protocol to connect and communicate to the server.
Web pages are embedded with other web services.
The following figure represents the logic components of Web application
architecture
CLIENT
Web browser layer Tier 1
Web server layer Tier 2
Application server layer Tier 3
Business logic layer Tier 4
Database server layer Tier 5
SERVER
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
Components of Web application
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
The following figure shows a physical architecture that is typical for a
web-based application.
In this architecture , each layer resides on a separate computer
Server
Client
Application Server
Business Logic
Web Server
Web DB
browser Internet Server
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Types …
The following figure shows the Physical and Logical structure of a data
warehouse
Server
DB
Server
Client Server
OL AP
ionr
Applicat
Data Source
DB Transform
Server Data Application
Server
Server
Data
Warehouse DB
Database Server
Application
Server
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Security Model based on Database Roles
This model depends on the application to authenticate the application users by
maintaining an end users in a table with their encrypted passwords
In this model each end user is assigned a database role
The user can access whatever the privileges are assigned to the role
In this model proxy user needed to activate assigned roles
The following figure shows the data model for this application (Security data
model based on database roles)
APPLICATION USERS APPLICATION USERS ROLES
APP_USER_ID
APP_USER-ID (FK)
APP-USERNAME
APP_ENC_PASSWORD ROLE_NAME
FIRST_NAME CTL_INS_DTIM
LAST_NAME CTL_UPD_DTIM
CTL_INS_DTIM CTL_USER_USER
CTL_UPD_DTIM CTL_USER_STAT
CTL_UPD_USER
CTL_REC_STAT
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
The following list presents the a brief description of these columns
CONTROL COLUMN DESCRIPTION
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Tables used in security data model based on database roles
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Architecture of a security data model based on database roles
Application
Authorization table
End User
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
The following points on this type of security model are worth noting:
Therefore it is DB independent
If the roles are implemented poorly , the model does not work properly
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Implementation in ORACLE
1. Creating the users by entering the following code:
Creating Application Owner
SQL > CREATE USER APP_OWNER IDENTIFIED BY APP_OWNER
2 DEFAULT TABLESPACE USERS
3 TEMPORARY TABLESPACE TEMP
4 QUOTA UNLIMITED ON USERS;
User created
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Creating Application tables
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Creating Application Roles
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Assign grants
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
2. Add rows to the CUSTOMER table
SQL> COMMIT
Commit complete
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
3. Add a row for an application user called APP_USER:
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Application roles are the special roles you create in the database, that are then
activated at the time of authorization.
Application roles requires a password and cannot contain members
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Creating Application Roles using the command line
To create an application role in the Query Analyzer, use the SP_ADDPROFILE system-stored
procedure
Where :
@rolename – The name of the application role ( The value must be a valid
identifier and cannot already exist in the database)
@password – The password required to activate the role. (SQL Server stores
the password as an encrypted hash)
Example :
To create the application role of clerk for your Pharmacy database , use this command
exec sp_addapprole ‘clerk’, ‘Clerk@ccess’
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Where
@rolename – The Application role to drop.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Security Model based on Application Roles
Depends on the application authenticate the application users.
Authentication is accomplished by maintaining all end users in a table with their
encrypted passwords.
Each end user is assigned an application role to read / write specific modules of
the applications.
The following table contains the description of tables used for this model.
APPLICATION_USERS
APP_USER_ID APPLICATION USERS
APP_ROLE_ID
APP_ROLE_ID (FK)
APP_USERNAME
APP_ENC_PASSWORD APP_ROLE_NAME
FIRST_NAME APP_ROLE_DESCRIPTIO
LAST_NAME N
CTL_INS_DTTM APP_ROLE_PRIVILEGE
CTL_UPD_DTTM CTL_INS_DTTM
CTL_UPD_USER CTL_UPD_DTTM
CTL_REC_STAT CTL_UPD_USER
CTL_REC_STAT
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Architecture of Security Model based on Application Roles
Application
Authorization table
End User
Schema Owner
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Security Model based on Application Roles
This model is primitive and does not allow the flexibility required to make
changes necessary for security
Privileges are limited to any combination like read, add, read / update /
admin and so on
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Security Model based on Application Functions
Based on application functions depends on the application to authenticate the
application users
Application divided into functions
The following figure represents a data model for this type of application
APPLICATION_FUNCTION_PRIVILEGE
APP_FUNCTION_PRIVILEGE_ID
APP_FUNCTION_PRIVILEGE_OPERATION
CTL_INS_DTTM
CTL_UPD_DTTM
CTL_UPD_USER
CTL_REC_STAT
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Architecture of Security Model based on Application Functions
Application
Authorization
End User tables owned
Schema Owner by application
owner
Schema Owner
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
The application authenticates users by maintaining all end users in a table with
their encrypted passwords
Applications are divided into functions and roles are assigned to functions that
are in turn assigned to users.
This model is highly flexible in implementing application security.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
The following figure represents a data model for Security Model Based
on Application showing the ER Diagram
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Application
Authorization
table
Schema Owner
Schema Owner
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Security Model Based on Application Tables
Depends on application to authenticate users by maintaining all end users in a
table with their encrypted passwords
All application provides privileges to the user based on tables
User is assigned access privilege to each table owned by the application owner
The following figure represents a data model for this security model
APPLICATION_USERS APPLICATION_USER_TABLES APPLICATION_TABLES
APPLICATION_TABLE_PRIVILEGES
APP_TABLE_PREVILIGES_ID
APP_TABLE_PRIVILEGE_DESCRIPTION
CTL_INS_DTTM
CTL_UPD_DTTM
CTL_UPD_USER
CTL_REC_STAT
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Architecture of a Security Model Based on Application Tables
Application
Authorization
table
Schema Owner
Schema Owner
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Application Security Models …
Characteristics of Security Model
Security Model
Applicatio
Database Application
Application n Role and Application
Role Function
Role based Function Table Based
based Based
Characteristics Based
Is flexible in implementing
application security No No No Yes No
Maintenance of application
security does not require
specific DB privileges No No No Yes No
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Data Encryption
Encryption is a security method in which information is encoded in
such a way that only authorized user can read it.
Types of Encryption
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Data Encryption
Symmetric key encryption algorithm uses same cryptographic keys for both
encryption and decryption of cipher text.
Public key encryption algorithm uses pair of keys, one of which is a secret key and
one of which is public. These two keys are mathematically linked with each other.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
VPD (Virtual Private Database) is shared database schema containing data
that belongs to many users , and each user can view or manipulate
the data the user owns
Schema Owner
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Architecture of Virtual Private Database
Use
O
DBMS_RLS Add RACLE
Package and s
Regi upplied
ster
a po PL/SQL
licy
for t package
he E
MP to
tabl
e
Policy
Function
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Test VPD
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Setup Test Environment
First we must create a user to act as the schema owner for this example. Obviously, you will
perform the following tasks using your current schema owner.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
CONN schemaowner/schemaowner@service
CREATE TABLE users (id NUMBER(10) NOT NULL, ouser VARCHAR2(30) NOT
NULL, first_name VARCHAR2(50) NOT NULL, last_name VARCHAR2(50) NOT
NULL);
COMMIT;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Create an Application Context
Grant CREATE ANY CONTEXT to the schema owner then create the context and
context package.
CONNECT schemaowner/schemaowner@service;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Next we create the context_package body which will actually set the user context.
BEGIN
SELECT id INTO v_id FROM users WHERE ouser = v_ouser;
DBMS_SESSION.set_context('SCHEMAOWNER','USER_ID', v_id);
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_SESSION.set_context('SCHEMAOWNER','USER_ID', 0);
END;
DBMS_SESSION.set_context('SCHEMAOWNER','SETUP','FALSE');
END set_context;
END context_package;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Next we make sure that all users have access to the Context_Package.
Next we must create a trigger to fire after the user logs onto the database.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Create Security Policies
In order for the context package to have any effect on the users interaction with
the database, we need to define a security_package for use with the security
policy. This package will tell the database how to treat any interactions with the
specified table.
CONNECT schemaowner/schemaowner@service;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Next we create the security_package body.
CREATE OR REPLACE PACKAGE BODY Security_Package IS
FUNCTION user_data_select_security(owner VARCHAR2, objname VARCHAR2) RETURN VARCHAR2 IS
predicate VARCHAR2(2000);
BEGIN
predicate := '1=2';
IF (SYS_CONTEXT('USERENV','SESSION_USER') = 'SCHEMAOWNER') THEN
predicate := NULL;
ELSE
predicate := 'USER_ID = SYS_CONTEXT(''SCHEMAOWNER'',''USER_ID'')';
END IF;
RETURN predicate;
END user_data_select_security;
BEGIN
DBMS_RLS.add_policy('SCHEMAOWNER', 'USER_DATA',
'USER_DATA_INSERT_POLICY',
'SCHEMAOWNER', 'SECURITY_PACKAGE.USER_DATA_INSERT_SECURITY',
'INSERT', TRUE);
DBMS_RLS.add_policy('SCHEMAOWNER', 'USER_DATA',
'USER_DATA_SELECT_POLICY',
'SCHEMAOWNER', 'SECURITY_PACKAGE.USER_DATA_SELECT_SECURITY',
'SELECT');
END;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Test VPD
Finally, test that the VPD is working correctly.
CONNECT user1/user1@service;
INSERT INTO schemaowner.user_data (column1, user_id) VALUES ('User 1', 1);
COMMIT;
CONNECT user2/user2@service
INSERT INTO schemaowner.user_data (column1, user_id) VALUES ('User 1', 1);
COMMIT;
CONNECT schemaowner/schemaowner@service
SELECT * FROM schemaowner.user_data;
CONNECT user1/user1@Service;
CONNECT user2/user2@Service
SELECT * FROM schemaowner.user_data;
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST
Virtual Private Databases
Column level Security with SQL Server
Column level permissions provide a more granular level of security for data in
your database. You do not need to execute a separate GRANT or DENY
statements for each column; just name them all in a query:
GO
GO
If you execute a DENY statement at table level to a column for a user, and after
that you execute a GRANT statement on the same column, the DENY permission
is removed and the user can have access to that column. Similarly, if you execute
GRANT and then DENY, the DENY permission will be in force.
10/25/2023 Dr.B.Muruganantham
AP / CSE / SRMIST