This tutorial shows you how to use DB roles to enable password-protected roles and secure application roles.
Approximately 30 minutes
This tutorial covers the following topics:
| Overview | ||
| Scenario | ||
| Prerequisites | ||
| Creating Users and Setting Table Access | ||
| Using a Secure Application Role | ||
| Cleanup | ||
| Summary | ||
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.
Roles are a powerful method for managing privileges in the Oracle Database. Roles can be granted to users and other roles. Once granted to a user, roles can be set to be default roles, so that the privileges associated with it are active as soon as the user has successfully authenticated to the database. If a role is not set as default, it can be invoked using the set_role command.
In this tutorial you learn how to protect the roles from being granted to unauthorized person by using "Secure Application Roles".
This tutorial covers how two employees of OSRD, namely Karen Partners and Louise Doran, are trying to gain information from the oe.orders table. Access rights to this table is defined in the role ots_role. Karen is Louise's manager, so Karen, as opposed to Louise, is able to access the information in oe.orders.
Before you perform this tutorial, you should:
| 1. | Perform the Installing Oracle Database 10g on Windows tutorial. |
|
| 2. | Download and unzip the approles.zip file into your working directory (c:\wkdir). |
|
Before you start creating and assigning roles, you need to create your users and set access to the appropriate tables. 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\sec_approles_create_users The sec_approles_create_users script contains the following commands: connect system/oracle drop user "LOUISE.DORAN@OSRD.COM" cascade; drop user "KAREN.PARTNERS@OSRD.COM" cascade; create user "LOUISE.DORAN@OSRD.COM" identified by welcome1; create user "KAREN.PARTNERS@OSRD.COM" identified by welcome1; grant connect, create session to "LOUISE.DORAN@OSRD.COM"; grant connect, create session to "KAREN.PARTNERS@OSRD.COM"; connect hr/hr update employees set email='LOUISE.DORAN@OSRD.COM' where email='LDORAN'; update employees set email='KAREN.PARTNERS@OSRD.COM' where email='KPARTNER';
|
| 2. |
Now you can set access to the tables you use during this tutorial. Execute the following script: @c:\wkdir\sec_approles_set_access The sec_approles_set_access script contains the following commands: connect oe/oe revoke select on oe.orders from public; revoke select on oe.customers from public; connect hr/hr grant select on hr.employees to public;
|
| 1. |
You first need to create the role. From your SQL*Plus window and execute the following SQL script: @c:\wkdir\sec_approles_create_role The sec_approles_create_role script contains the following commands: connect system/oracle drop role ots_role; create role ots_role;
|
| 2. |
Next you need to grant select access to oe.orders and oe.customers. Then grant the role to each user and set their profile role to none. From your SQL*Plus window and execute the following SQL script: @c:\wkdir\sec_approles_grant_role The sec_approles_grant_role script contains the following commands: connect oe/oe grant select on oe.orders to ots_role; grant select on oe.customers to ots_role; connect system/oracle grant ots_role to "KAREN.PARTNERS@OSRD.COM"; alter user "KAREN.PARTNERS@OSRD.COM" default role none; grant ots_role to "LOUISE.DORAN@OSRD.COM"; alter user "LOUISE.DORAN@OSRD.COM" default role none;
|
| 3. |
You can now set the role for Karen and perform a select on the oe.orders table. From your SQL*Plus window and execute the following SQL script: @c:\wkdir\sec_approles_test_role_karen The sec_approles_test_role_karen script contains the following commands: connect "KAREN.PARTNERS@OSRD.COM"/welcome1; set role ots_role; select sales_rep_id, order_total from oe.orders order by order_total desc;
|
| 4. | Notice what happens if you do not set the role before performing the select. Execute the following SQL script: @c:\wkdir\sec_approles_test_wo_role_louise The sec_approles_test_wo_role_louise script contains the following commands: connect "LOUISE.DORAN@OSRD.COM"/welcome1; select sales_rep_id, order_total from oe.orders order by order_total desc;
|
| 5. | Louise has not been granted the ots_role, so she has no access to the tables defined in this role. But all she needs to know is the name of the role (ots_role), and the command set role, and she can fix this 'problem' herself. In other words, she very easily gained access to information she's not supposed to know. Run the following script: @c:\wkdir\sec_approles_test_w_role_louise The sec_approles_test_wo_role_louise script contains the following commands: set role ots_role; select sales_rep_id, order_total from oe.orders order by order_total desc;
|
In this topic you create and use a secure application role. Perform the following steps:
| 1. | You first need to create the role. From your SQL*Plus window and execute the following SQL script: @c:\wkdir\sec_approles_sar_create_role The sec_approles_sar_create_role script contains the following commands: connect system/oracle drop role ots_role; create role ots_role IDENTIFIED USING sec_roles;
|
| 2. | Next you need to grant select access to oe.orders and oe.customers. Then grant the role to each user and set their profile role to none. From your SQL*Plus window and execute the following SQL script: @c:\wkdir\sec_approles_grant_role The sec_approles_grant_role script contains the following commands: connect oe/oe grant select on oe.orders to ots_role; grant select on oe.customers to ots_role; connect system/oracle grant ots_role to "KAREN.PARTNERS@OSRD.COM"; alter user "KAREN.PARTNERS@OSRD.COM" default role none; grant ots_role to "LOUISE.DORAN@OSRD.COM"; alter user "LOUISE.DORAN@OSRD.COM" default role none;
|
| 3. | Now you can create the security application role procedure. From your SQL*Plus window, execute the following SQL script; note that all kinds of security checks can be performed by this procedure. In this example, you first compare the 'session_user' with the email-address from the hr.employees table. Then you check the employee's manager_id. The procedure sets the role for the user only when manager_id=100, otherwise the role is not set. @c:\wkdir\sec_approles_sar_create_proc The sec_approles_sar_create_proc script contains the following commands: connect system/oracle
|
| 4. | You need to grant execute rights to the procedure. From your SQL*Plus window, execute the following SQL script; in this example, the internal security policy of OSRD could determine that execution rights to this procedure are granted all employees: @c:\wkdir\sec_approles_sar_grant_proc The sec_approles_sar_grant_proc script contains the following commands: connect system/oracle GRANT EXECUTE ON sec_roles to "KAREN.PARTNERS@OSRD.COM"; GRANT EXECUTE ON sec_roles to "LOUISE.DORAN@OSRD.COM";
|
| 5. | Now you can test the access for Karen. Execute the following SQL script: @c:\wkdir\sec_approles_sar_test_role_karen The sec_approles_sar_test_role_karen script contains the following commands: connect "KAREN.PARTNERS@OSRD.COM"/welcome1; execute system.sec_roles; select sales_rep_id, order_total from oe.orders order by order_total desc;
|
| 6. | Now you can test the access for Louise. Execute the following SQL script: @c:\wkdir\sec_approles_sar_test_role_louise The sec_approles_sar_test_role_louise script contains the following commands: connect "LOUISE.DORAN@OSRD.COM"/welcome1; execute system.sec_roles; select sales_rep_id, order_total from oe.orders order by order_total desc;
|
Perform the following steps to cleanup the environment. You must follow these steps if you plan on performing any other OBE after performing this one:
| 1. | From your SQL*Plus window, execute the following SQL script: @c:\wkdir\sec_approles_cleanup The sec_appsrole_cleanup script contains the following commands: connect system/oracle
|
In this tutorial, you learned how to:
| Use a database role | ||
| Use a secure application role | ||