Oracle® Database Security Guide 10g Release 1 (10.1) Part Number B10773-01 |
|
|
View PDF |
Creating an application security policy is the first step when writing secure database applications. An application security policy is a list of application security requirements and rules that regulate user access to database objects.
This chapter discusses aspects of application security and Oracle Database features that you should consider when drafting security policies for database applications. It contains the following topics:
You should draft security policies for each database application. For example, each database application should have one or more database roles that provide different levels of security when executing the application. The database roles can be granted to user roles, or directly to specific usernames.
Applications that potentially allow unrestricted SQL statement execution (through tools such as SQL*Plus) also need security policies that prevent malicious access to confidential or important schema objects.
The following sections describe aspects of application security and the Oracle Database features that you can use to plan and develop secure database applications.
See Also:
|
Two main issues to consider when you formulate and implement application security are listed as follows:
Oracle Corporation recommends that, where possible, you build applications in which application users are database users. In this way you can leverage the intrinsic security mechanisms of the database.
For many commercial packaged applications, application users are not database users. For these applications, multiple users authenticate themselves to the application, and the application then connects to the database as a single, highly-privileged user. We will call this the "One Big Application User" model.
Applications built in this fashion generally cannot use many of the intrinsic security features of the database, because the identity of the user is not known to the database.
For example, use of the following features is compromised by the One Big Application User model:
Applications whose users are also database users can either build security into the application, or rely upon intrinsic database security mechanisms such as granular privileges, virtual private database (fine-grained access control with application context), roles, stored procedures, and auditing (including fine-grained auditing). To the extent possible, Oracle recommends that applications utilize the security enforcement mechanisms of the database.
When security is enforced in the database itself, rather than in the application, it cannot be bypassed. The main shortcoming of application-based security is that security is bypassed if the user bypasses the application to access data. For example, a user who has SQL*Plus access to the database can execute queries without going through the Human Resources application. The user thus bypasses all of the security measures in the application.
Applications that use the One Big Application User model must build security enforcement into the application rather than use database security mechanisms. Because it is the application--and not the database--which recognizes users, the application itself must enforce security measures for each user.
This approach means that each application which accesses data must re-implement security. Security becomes expensive because organizations must implement the same security policies in multiple applications. Each new application requires an expensive re-implementation.
Most database applications involve different privileges on different schema objects. Keeping track of which privileges are required for each application can be complex. In addition, authorizing users to run an application can involve many GRANT
operations.
To simplify application privilege management, you can create a role for each application and grant that role all the privileges a user needs to run the application. In fact, an application might have a number of roles, each granted a specific subset of privileges that allow greater or lesser capabilities while running the application.
For example, suppose that every administrative assistant uses the Vacation application to record vacation taken by members of the department. To best manage this application, you should:
VACATION
role.VACATION
role.VACATION
role to all administrative assistants or to a role named ADMIN_ASSISTS
(if previously defined).Grouping application privileges in a role aids privilege management. Consider the following administrative options:
ROLE_TAB_PRIVS
and ROLE_SYS_PRIVS
data dictionary views.DBA_ROLE_PRIVS
data dictionary view.
See Also:
Chapter 10, "Administering User Privileges, Roles, and Profiles" for a complete discussion of creating, enabling, and disabling roles, and granting and revoking privileges |
After database access privileges are grouped into roles, the roles are granted to the application user. Securing these roles can be accomplished in two ways:
Within the package that implements the secure application role:
SYS_CONTEXT
SQL function with the USERENV namespace attributes ('userenv', <session_attribute>). The information returned by this function can indicate the way the user was authenticated, the IP address of the client, and whether the user was proxied.DBMS_SESSION.SET
ROLE
).
Note: Because users cannot change the security domain inside definer's rights procedures, secure application roles can only be enabled inside invoker's rights procedures. |
See Also:
|
To create a secure application role:
hr.hr_admin
is the example authorized package.
CREATE ROLE admin_role IDENTIFIED USING hr.hr_admin; CREATE ROLE staff_role IDENTIFIED USING hr.hr_admin;
/* Create a dedicated authentication function for manageability so that changes in authentication policies would not affect the source code of the application - this design is up to the application developers */ /* the only policy in this function is that current user must have been authenticated using the proxy user 'SCOTT' */ CREATE OR REPLACE FUNCTION hr.MySecurityCheck RETURN BOOLEAN AS BEGIN
/* a simple check to see if current session is authenticated by the proxy user 'SCOTT' */ if (sys_context('userenv','proxy_user') = 'SCOTT') then
return TRUE;
else
return FALSE;
end IF;
END; GRANT EXECUTE ON hr.MySecurityCheck TO PUBLIC; /*Create the procedure*/ CREATE OR REPLACE PACKAGE hr_admin AUTHID CURRENT_USER IS PROCEDURE hr_app_report; END; / CREATE OR REPLACE PACKAGE BODY hr_admin IS PROCEDURE hr_app_report IS BEGIN
/* set application context in 'responsibility' namespace */ hr_logon.hr_set_responsibility; /* authentication check here */ if (hr.MySecurityCheck = TRUE) then
/* check 'responsibility' being set, then enable the roles without supplying the password */ if (sys_context('hr','role') = 'admin' )
then
dbms_session.set_role('admin_role');
else
dbms_session.set_role('staff_role'); end if;
end if;
END; END;
When enabling the secure application role, the database verifies that the authorized PL/SQL package is on the calling stack. This step verifies that the authorized PL/SQL package is issuing the command to enable the role. Also, when enabling the user's default roles, no checking is performed for application roles.
You can use secure application role to ensure a database connection. Because a secure application role is a role implemented by a package, the package can validate that users can connect to the database through a middle tier or from a specific IP address. In this way, the secure application role prevents users from accessing data outside an application. They are forced to work within the framework of the application privileges that they have been granted.
A single user can use many applications and associated roles. However, you should ensure that the user has only the privileges associated with the running database role. Consider the following scenario:
ORDER
role (for the Order application) contains the UPDATE
privilege for the INVENTORY
tableINVENTORY
role (for the Inventory application) contains the SELECT
privilege for the INVENTORY
tableORDER
and INVENTORY
rolesIn this scenario, an order entry clerk who has been granted both roles, can use the privileges of the ORDER
role when running the INVENTORY
application to update the INVENTORY
table. The problem is that updating the INVENTORY
table is not an authorized action when using the INVENTORY
application, but only when using the ORDER
application.
To avoid such problems, consider using either the SET
ROLE
statement or the SET_ROLE
procedure as explained in the following section. You can also use the secure application role feature to allow roles to be set based on criteria you define.
Topics in this section include:
Use a SET
ROLE
statement at the beginning of each application to automatically enable its associated role and to disable all others. In this way, each application dynamically enables particular privileges for a user only when required.
The SET
ROLE
statement simplifies privilege management. You control what information users can access and when they can access it. The SET
ROLE
statement also keeps users operating in a well-defined privilege domain. If a user obtains privileges only from roles, the user cannot combine these privileges to perform unauthorized operations.
See Also:
|
The PL/SQL package DBMS_SESSION.SET_ROLE
is functionally equivalent to the SET ROLE
statement in SQL. Roles are not supported in definer's rights procedures, so the DBMS_SESSION.SET_ROLE
command cannot be called from them. However, the DBMS_SESSION.SET_ROLE
command can be called from the following:
SET ROLE
takes effect only at execution time. Because anonymous blocks compile and execute simultaneously, roles are set before security checks are performed, so the block completes successfully. With respect to invoker's rights stored procedures, if they contain static SQL statements and access to objects in the SQL are authorized through roles, then the procedure may fail during compilation. (Because the roles are not enabled until the procedure executes.) To resolve this problem, replace static SQL with dynamic SQL by using the DBMS_SQL
package. Then security checks are performed at execution, at the same time the SET ROLE
statement enables roles.
See Also:
PL/SQL Packages and Types Reference for information about the |
This section shows how static and dynamic SQL affect the assignment of roles.
Suppose you have a role named ACCT
that has been granted privileges allowing you to select from table FINANCE
in the JOE
schema. In this case, the following procedure that uses static SQL fails:
CREATE OR REPLACE PROCEDURE statSQL_proc AUTHID CURRENT_USER AS n NUMBER; BEGIN SYS.DBMS_SESSION.SET_ROLE('acct'); SELECT empno INTO n FROM JOE.FINANCE; END;
The procedure fails because the security check which verifies that you have the SELECT
privilege on table JOE
.FINANCE
occurs at compile time. At compile time, however, the ACCT
role is not yet enabled. The role is not enabled until the procedure is executed.
In contrast, the DBMS_SQL
package, which uses dynamic SQL, is not subject to this restriction. When you use this package, the security checks are performed when the procedure executes--not when it is compiled. Thus, the following block is successful:
CREATE OR REPLACE PROCEDURE dynSQL_proc AUTHID CURRENT_USER AS n NUMBER; BEGIN SYS.DBMS_SESSION.SET_ROLE('acct'); EXECUTE IMMEDIATE 'select empno from joe.finance' INTO n; --other calls to SYS.DBMS_SQL END; /
See Also:
"Choosing Between Native Dynamic SQL and the |
A schema is a security domain that can contain database objects. The privileges granted to each user or role control access to these database objects. This section covers:
Most schemas can be thought of as usernames: the accounts which enable users to connect to a database and access the database objects. However, unique schemas do not allow connections to the database, but are used to contain a related set of objects. Schemas of this sort are created as normal users, yet are not granted the CREATE
SESSION
system privilege (either explicitly or through a role). However, you must temporarily grant the CREATE
SESSION
and RESOURCE
privilege to such schemas if you want to use the CREATE
SCHEMA
statement to create multiple tables and views in a single transaction.
For example, the schema objects for a specific application might be owned by a given schema. If application users have the privileges to do so, then they can connect to the database using typical database usernames and use the application and the corresponding objects. However, no user can connect to the database using the schema set up for the application. This configuration prevents access to the associated objects through the schema, and provides another layer of protection for schema objects. In this case, the application could issue an ALTER SESSION SET CURRENT_SCHEMA
statement to connect the user to the correct application schema.
For many applications, users do not need their own accounts-- their own schemas--in a database. These users only need to access an application schema. For example, users John, Firuzeh, and Jane are all users of the Payroll application, and they need access to the Payroll
schema on the Finance
database. None of them need to create their own objects in the database. They need only access Payroll
objects. To address this issue, Oracle Advanced Security provides enterprise users (schema-independent users).
Enterprise users, users managed in a directory service, do not need to be created as database users because they use a shared database schema. To reduce administration costs, administrator can create an enterprise user once in the directory, and point the user at a shared schema that many other enterprise users can also access.
See Also:
Oracle Advanced Security Administrator's Guide for information about how shared schemas are created and used for Enterprise User Security |
As part of designing your application, you need to determine the types of users who will be working with the application, and the level of access they need to accomplish their designated tasks. You must categorize these users into role groups, and then determine the privileges that must be granted to each role. This section covers:
End users are typically granted object privileges. An object privilege allows a user to perform a particular action on a specific table, view, sequence, procedure, function, or package. Table 12-1 summarizes the object privileges available for each type of object.
Object Privilege | Applies to Table? | Applies to View? | Applies to Sequence? | Applies to Procedure?Foot 1 |
---|---|---|---|---|
|
Yes |
No |
Yes |
No |
|
Yes |
Yes |
No |
No |
|
No |
No |
No |
Yes |
|
YesFoot 2 |
No |
No |
No |
|
Yes |
Yes |
No |
No |
|
YesFootref 2 |
No |
No |
No |
|
Yes |
YesFoot 3 |
Yes |
No |
|
Yes |
Yes |
No |
No |
1 Stand-alone stored procedures, functions, and public package constructs. 2 Privilege that cannot be granted to a role. 3 Can also be granted for snapshots. |
As you implement and test your application, you should create each necessary role. Test the usage scenario for each role to be certain that the users of your application will have proper access to the database. After completing your tests, coordinate with the administrator of the application to ensure that each user is assigned the proper roles.
Table 12-2 lists the SQL statements permitted by the object privileges shown in Table 12-1.
See Also:
"Understanding User Privileges and Roles" for a discussion of object privileges |