The goal of this tutorial is to show the power of using the Virtual Private Database capability to restrict access to certain data to certain users.
Approximately 30 minutes
This tutorial covers the following topics:
Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor over each individual icon in the following steps to load and view only the screenshot associated with that step.
The Virtual Private Database (VPD) provides row-level access control beyond the capabilities of roles and views. For Internet access, the Virtual Private Database can ensure that online banking customers see only their own accounts. The Web-hosting companies can maintain data of multiple companies in the same Oracle database, while permitting each company to see only its own data.
Within the enterprise, the Virtual Private Database results in lower costs of ownership in deploying applications. Security can be built once, in the data server, rather than in each application that accesses data. Security is stronger, because it is enforced by the database, no matter how a user accesses data. Security is no longer bypassed by a user accessing an ad hoc query tool or new report writer. The Virtual Private Database is a key technology that enables organizations to build hosted, Web-based applications. Indeed, many Oracle applications themselves use VPD to enforce data separation for hosting, including Oracle SalesOnline.com and Oracle Portal.
The Virtual Private Database is enabled by associating one or more security policies with tables or views. Direct or indirect access to a table with an attached security policy causes the database to consult a function that implements the policy. The policy function returns an access condition known as a predicate (a WHERE clause), which the database appends to the user's SQL statement, thus dynamically modifying the user's data access.
You can implement VPD by writing a stored procedure to append a SQL predicate to each SQL statement that controls row-level access for that statement. For example, if John Doe (who belongs to Department 10) inputs the SELECT * FROM emp statement, then you can use VPD to add the WHERE DEPT = 10 clause. In this way, you use query modification to restrict data access to certain rows.
The Virtual Private Database ensures that, no matter how a user gets to the data (through an application, a report writing tool, or SQL*Plus), the same strong access control policy is enforced. In this way, VPD can help banks ensure that customers see only their own accounts, that telecommunications firms can keep customer records safely segregated, and that human resources applications can support their complex rules of data access to employee records.
In this tutorial, you create two different administrator users:
sec_admin | This user creates the policy function, applies the policy to the table, and creates an index on the table to improve performance.
|
hr_sec | This user creates the database users and roles after verifying they are contained in either the CUSTOMERS or EMPLOYEES tables.
|
Before you perform this tutorial, you should:
1. | Perform the Installing Oracle Database 10g on Windows tutorial. |
|
2. | Download and unzip the vpd.zip file into your working directory (c:\wkdir). |
In this tutorial, you create a set of users and roles to demonstrate how VPD works. To create users and roles, perform the following steps:
1. |
Select Start > Programs > Oracle - OraDb10g_home1 > Application Development > SQL Plus. Enter /nolog for the User Name and click OK. Then enter the following command: @c:\wkdir\create_admin_users_and_roles set echo off
|
You apply a VPD policy to the ORDERS table, so that both internal (employees) and external users (customers) have access only to their information. Perform the following steps:
1. | From your SQL*Plus window, execute the following script: @c:\wkdir\enable_vpd_policy The enable_vpd_policy.sql script contains the following: connect sec_admin/welcome1;
|
|
2. | From your SQL*Plus window, execute the following script: @c:\wkdir\apply_vpd_policy The apply_vpd_policy.sql script contains the following: begin
|
Now you can test the policy. Perform the following steps:
1. |
The user Matthias has a CUSTOMER_ID of 106. The security policy verifies his login name in the Application Context against the CUSTOMERS table and then allows access only to his own orders in the ORDERS table. From your SQL*Plus window, execute the following script: @c:\wkdir\select_orders_as_matthias connect "MATTHIAS.HANNAH@GREBE.COM"/welcome1;
|
|
2. | Louise Doran is a Sales Rep with EMPLOYEE_ID=160. Run a query to show only the orders placed by her own customers. From your SQL*Plus window, execute the following script: @c:\wkdir\select_orders_as_ldoran connect LDORAN/welcome1;
|
|
3. | Karen Partner is a Sales Manager with EMPLOYEE_ID=146. Run a query to show only the orders placed by customers of her team of Sales Reps. From your SQL*Plus window, execute the following script: @c:\wkdir\select_orders_as_kpartner connect KPARTNER/welcome1;
|
|
4. | Run a query to see how many orders are in the ORDERS table as the OE owner. From your SQL*Plus window, execute the following script: @c:\wkdir\select_count_orders_as_oe connect oe/oe;
|
|
5. | Now run the same query as Steven King. Notice how the result is the same number and he can see all the orders. This is because he is the president and can see everything. From your SQL*Plus window, execute the following script: @c:\wkdir\select_count_orders_as_sking connect SKING/welcome1;
|
The VPD policy appends a WHERE clause to all queries against the protected table. To verify the WHERE clauses are correct (your auditor may ask for this), perform the following steps:
1. | From your SQL*Plus window, execute the following script: @c:\wkdir\vpd_where_clause_orders connect system/oracle Note: After the policy is applied to the table, all queries by authorized users are filtered according to the WHERE clauses defined in the policy function. In order to improve performance, you can apply an index to the protected table over the column used in the WHERE clause. In this tutorial, several indexes are already applied to the ORDERS table by default.
|
In this section, you enable and apply a VPD policy with Relevant Columns and Column Filtering. This policy is applied to the CUSTOMERS table, so that only employees have access to information they really need. Customers are not granted any access rights. Access to confidential information (i.e. CREDIT_LIMIT) is regulated by the policy. Perform the following steps:
1. |
From your SQL*Plus window, execute the following script: @c:\wkdir\enable_vpd_policy2 connect sec_admin/welcome1;
|
|
2. | Now you can apply the policy to the table. To increase performance, the parameter context_sensitive is added, so that the function is only executed when the content of the application context changes (i.e. when a new user logs in). From your SQL*Plus window, execute the following script: @c:\wkdir\apply_vpd_policy2 begin
|
Now you can test the policy. Perform the following steps:
1. | Matthias Hannah is using a customer_role, which does not include access rights to the CUSTOMERS table at all. From your SQL*Plus window, execute the following script: @c:\wkdir\select_customers_as_matthias connect "MATTHIAS.HANNAH@GREBE.COM"/welcome1;
|
|
2. | Eleni Zlotkey is a Sales Manager with EMPLOYEE_ID=149. She is able to only see the Credit Limit for the customers she worked on. All others are hidden from her. From your SQL*Plus window, execute the following script: @c:\wkdir\select_customers_as_ezlotkey connect EZLOTKEY/welcome1; Scroll up a bit to see another ACCOUNT_MGR_ID. Notice that the credit limit is hidden.
|
|
3. | Run a query to see how the list of customers for Steven King. Since he is the President, he can see everything.. From your SQL*Plus window, execute the following script: @c:\wkdir\select_customers_as_sking connect SKING/welcome1; Scroll up a bit to see that Steven King can see all the credit limits for any ACCOUNT_MGR_ID.
|
The VPD policy appends a WHERE clause to all queries against the protected table. To verify the WHERE clauses are correct (your auditor may ask for this), perform the following steps:
1. | From your SQL*Plus window, execute the following script: @c:\wkdir\vpd_where_clause_customers connect system/oracle Note: After the policy is applied to the table, all queries by authorized users are filtered according to the WHERE clauses defined in the policy function. In order to improve performance, you can apply an index to the protected table over the column used in the WHERE clause. In this tutorial, several indexes are already applied to the CUSTOMERS table by default.
|
Perform the following steps to cleanup your database:
1. | From your SQL*Plus window, execute the following script: @c:\wkdir\vpd_cleanup connect hr_sec/welcome1;
|
In this tutorial, you learned how to:
Enable a VPD policy | ||
View the policy | ||
Apply a VPD policy with relevant columns and column filtering |