UNIT - III - Database Security and Privacy
UNIT - III - Database Security and Privacy
2
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)
3
Types of Users
4
Security Models
5
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
. . . .
. . . .
. . . .
6
Security Models…
Access Matrix Model - Example
7
Security Models…
Access mode indicates that the subject can perform any task
or not
There are two modes
Static Modes
Dynamic Modes
8
Security Models…
Access Modes – Static Modes
10
Application Types
Mainframe applications
Web Applications
11
Application Types …
Mainframe applications
Years back computing in corporations was centralized in the Management
Information System(MIS)
MIS department is responsible for all information
Workstation Mainframe
Server
CODE
DB
Server
12
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
13
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
14
Application Types …
Client Server
DB
User Business Data Server
Interface Logic Access
15
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
16
Application Types …
Components of Web application
17
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
18
Application Types …
DB
Server
Client Server
OL AP
ionr
Applicat
Data Source
DB Transform
Server Data Application
Server
Server
Data
Warehouse DB
Database Server
21
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
CTL - Control 22
Application Security Models …
The following list presents the a brief description of these columns
CONTROL COLUMN DESCRIPTION
23
Application Security Models …
Tables used in security data model based on database roles
24
Application Security Models …
Architecture of a security data model based on database roles
Application
Authorization table
End User
25
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
26
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
27
Application Security Models …
Creating Application tables
28
Application Security Models …
Creating Application Roles
29
Application Security Models …
Assign grants
30
Application Security Models …
SQL> COMMIT
Commit complete
31
Application Security Models …
32
Application Security Models …
33
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
34
Application Security Models …
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’
35
Application Security Models …
36
Application Security Models …
Where
@rolename – The Application role to drop.
37
Application Security Models …
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
38
Application Security Models …
Architecture of Security Model based on Application Roles
Application
Authorization table
End User
Schema Owner
39
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
40
Application Security Models …
APPLICATION_FUNCTION_PRIVILEGE
APP_FUNCTION_PRIVILEGE_ID
APP_FUNCTION_PRIVILEGE_OPERATION
CTL_INS_DTTM
CTL_UPD_DTTM
CTL_UPD_USER
CTL_REC_STAT
41
Application Security Models …
Application
Authorization
End User tables owned
Schema Owner by application
owner
Schema Owner
42
Application Security Models …
43
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.
44
Application Security Models …
The following figure represents a data model for Security Model Based
on Application showing the ER Diagram
45
Application Security Models …
Application
Authorization
table
Schema Owner
Schema Owner
46
Application Security Models …
47
Application Security Models …
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
48
Application Security Models …
Application
Authorization
table
Schema Owner
Schema Owner
49
Application Security Models …
50
Application Security Models …
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
51
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
There are two types of encryptions schemes as listed below:
Symmetric Key encryption
Public Key encryption
52
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.
53
Objectives
54
VPD
55
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
56
Virtual Private Databases
57
Oracle VPD
How does it work?
When a user accesses a table (or view or synonym) which is
protected by a VPD policy (function),
1. The Oracle server invokes the policy function whenever
a logged on user tries to execute a query.
2. The policy function returns a predicate, based on
session attributes or database contents.
3. The server dynamically rewrites the submitted query by
appending the returned predicate to the WHERE clause.
4. The modified SQL query is executed.
58
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
59
Implementing a VPD Using Views
60
Implementing a VPD Using Views
Example implementation steps:
– Logon as DBSEC schema
– Display the EMPLOYEES table
– Create the table EMPLOYEES_VER1
– Grant SELECT and INSERT on this view to another user GRANT SELECT,
INSERT ON EMPLOYEE_VEIEW1 TO SCOTT –
Insert a row using EMPLOYEES_VIEW1
INSERT INTO DBSEC.EMPLOYEES_VIEW1(EMPLOYEE_ID, FIRST_NAME,
LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY,
MANAGER_ID, DEPARTMENT_ID, USER_NAME) VALUES(100, ‘SAM’,
‘AFYOUNI’, ‘SAFYOUNI’, ‘123.234.3456’, SYSDATE, ‘WM_CLK’, 1000, 1000,
10, USER);
– USER is a function that returns the user name value of the person who
is logged on.
– If log on as DESEC, USER = DBSEC
63
Implementing a VPD Using Views
64
Implementing a VPD Using Views
65
Implementing a VPD Using Views
66
Implementing a VPD Using Views
67
Implementing a VPD Using Views
68
Implementing a VPD Using Views
69
Implementing a VPD Using Views
70
Implementing a VPD Using Views
71
Implementing a VPD Using Views
72
Virtual Private Databases
Test VPD
73
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.
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;
75
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;
76
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;
77
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.
78
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;
79
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;
81
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;
82
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.
83
References :
84
87
Column-level VPD
• Instead of attaching a policy to a whole table or
a view, attach a policy only to security-relevant
columns
– Default behavior: restricts the number of rows
returned by a query.
– Masking behavior: returns all rows, but returns
NULL values for the columns that contain sensitive
information.
• Restrictions
– Applies only to ‘select’ statements
– The predicate must be a simple boolean expression.
88
Column-level VPD : : Example
• Suppose Alice has the following table.
Employees(e_id number(2), name varchar2(10),
salary number(3));
As user VARCHAR2(100);
Begin
user := SYS_CONTEXT(‘userenv’, ‘SESSION_USER’);
return ‘Name = ‘ || user;
end if;
End;
90
Column-level VPD : : Example
2. Attach the policy function to Employees
(default behavior)
execute dbms_rls.add_policy (object_schema => ‘Alice’,
object_name => ‘employees’,
policy_name => ‘my_policy’,
function_schema => ‘Alice’,
policy_function=> ‘sec_function’,
sec_relevant_cols=>’salary’);
91
Column-level VPD : : Example
3. Bob accesses table Employees (default behavior)
select e_id, name from Employee;
92
Column-level VPD : : Example
93
Column-level VPD : : Example
94
Implementing a VPD Using Application
Context in Oracle
Application contexts act as secure caches of data that
may be used by a fine-grained access control policy.
95
Implementing a VPD Using Application
Context in Oracle
96
Implementing a VPD Using Application
Context in Oracle
97
Implementing a VPD Using Application
Context in Oracle
Application context:
– Functionality specific to Oracle
– Allows to set database application variables
that can be retrieved by database sessions
– Variables can be used for security context
based or user
-defined environmental attributes
98
Viewing VPD Policies and Application
contexts using Data Dictionary
• Oracle is rich with data dictionary view that enable you
to everything created and stored in the database.
• VPD's are no exception.
• Oracle provides a set of data dictionary views for all
application contexts.
• Oracle also provides data dictionary views for VPD
policies.
99
Viewing VPD Policies and Applications
contexts using Data Dictionary
100
Viewing VPD Policies and Applications
Context Using Policy Manager
101
Viewing VPD Policies and Applications
Context Using Policy Manager
102
Viewing VPD Policies and
Applications Context Using Policy
Manager (continued)
103
Viewing VPD Policies and
Applications Context Using Policy
Manager (continued)
104
Implementing Row
and Column level Security with SQL
Server
105
Implementing Row
and Column level Security with SQL
Server
106
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
Implementing Row
and Column level Security with SQL
Server
• Oracle Policy Manager: graphical tool used to
administer VPD policies
• Oracle has the capability to restrict updates or
inserts on columns, using GRANT UPDATE(column)
and INSERT(column)