Oracle® Database Security Guide 10g Release 2 (10.2) Part Number B14266-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 user names.
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:
Chapter 7, "Security Policies" for an overview of database security policies
"Application Developer Security" for a discussion of application developer database privileges
"Application Administrator Security" for a description of the security-related tasks of an application administrator
Two main issues to consider when you formulate and implement application security are covered in the following sections:
Oracle 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 databases (fine-grained access control with application context), roles, stored procedures, and auditing (including fine-grained auditing). Oracle recommends that applications utilize the security enforcement mechanisms of the database as far as possible.
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, therefore, 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, that recognizes users, the application itself must enforce security measures for each user.
This approach means that each application that accesses data must reimplement security. Security becomes expensive, because organizations must implement the same security policies in multiple applications. Each new application requires an expensive reimplementation.
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 the vacation taken by members of the department. To best manage this application, you should:
Create a VACATION
role.
Grant all privileges required by the Vacation application to the VACATION
role.
Grant the 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:
You can grant the role, rather than many individual privileges, to those users who run the application. Then, as employees change jobs, you need to grant or revoke only one role, rather than many privileges.
You can change the privileges associated with an application by modifying only the privileges granted to the role, rather than the privileges held by all users of the application.
You can determine the privileges that are necessary to run a particular application by querying the ROLE_TAB_PRIVS
and ROLE_SYS_PRIVS
data dictionary views.
You can determine which users have privileges on which applications by querying the DBA_ROLE_PRIVS
data dictionary view.
See Also:
Chapter 11, "Administering User Privileges, Roles, and Profiles" for a complete discussion of creating, enabling, and disabling roles, and granting and revoking privilegesAfter database access privileges are grouped into roles, the roles are granted to the application user. Securing these roles can be accomplished in two ways:
Embedding passwords inside the applications by creating what are called application roles
Creating application roles and specifying which PL/SQL package is authorized to enable the roles, which are called secure application roles
Within the package that implements the secure application role:
The application must do the necessary validation. For example, the application must validate that the user is in a particular department, the user session was created by proxy, the request comes from a particular IP address, or that the user was authenticated using an X.509 certificate. To perform the validation, applications can use session information accessible by using the SYS_CONTEXT
SQL function with the USERENV
namespace attributes ('userenv
', <session_attribute
>). The information returned by this function can indicate the way in which the user was authenticated, the IP address of the client, and whether the user was proxied.
The application must issue a SET_ROLE
command by using dynamic SQL (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:
"Secure Application Roles" for conceptual information about this topic
Table 14-1, "Key to Predefined Attributes in USERENV Namespace"
PL/SQL User's Guide and Reference for information about definer's rights versus invoker's rights procedures and how to create them
Steps to create a secure application role is as follows:
Create the roles as application roles and specify the authorized package that will enable the roles. In this example, 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;
Note:
You need to set up the following data structures for the examples in this section to work:CREATE OR REPLACE PACKAGE hr_logon IS PROCEDURE hr_set_responsibility; END; / CREATE OR REPLACE PACKAGE BODY hr_logon IS PROCEDURE hr_set_responsibility IS BEGIN DBMS_SESSION.SET_IDENTIFIER (1234); END; END; /
Create an invoker's right procedure.
/* 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 default user roles, no checking is performed for application roles.
You can use secure application roles 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 current database role. Consider the following scenario:
The ORDER
role (for the Order application) contains the UPDATE
privilege for the INVENTORY
table
The INVENTORY
role (for the Inventory application) contains the SELECT
privilege for the INVENTORY
table
Several order entry clerks have been granted both the ORDER
and INVENTORY
roles
In 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, then the user cannot combine these privileges to perform unauthorized operations.
See Also:
When Do Grants and Revokes Take Effect? for information about enabling and disabling roles
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, while at the same time the SET ROLE
statement enables roles.
Note:
If you useDBMS_SESSION.SET_ROLE
within an invoker's rights procedure, then the role remains in effect until you explicitly disable it. In keeping with the least privilege principle (that users should have the fewest privileges they need to do their jobs), you should explicitly disable roles set within an invoker's rights procedure, at the end of the procedure.See Also:
PL/SQL Packages and Types Reference for information about theDBMS_SESSION
and the DBMS_SQL
packagesThis section shows how static and dynamic SQL affect the assignment of roles.
Note:
You need to set up the following data structures for the examples in this section to work:CONNECT system/manager DROP USER joe CASCADE; CREATE USER joe IDENTIFIED BY joe; GRANT CREATE SESSION, RESOURCE, UNLIMITED TABLESPACE TO joe; GRANT CREATE SESSION, RESOURCE, UNLIMITED TABLESPACE TO scott; DROP ROLE acct; CREATE ROLE acct; GRANT acct TO scott; ALTER USER scott DEFAULT ROLE ALL EXCEPT acct; CONNECT joe/joe; CREATE TABLE finance (empno NUMBER); GRANT SELECT ON finance TO acct; CONNECT scott/tiger
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 that 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, and 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 theDBMS_SQL
Package in Oracle Database Application Developer's Guide - FundamentalsA 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 user names: the accounts that 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, and 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 user names 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 or 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, an 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 Database Advanced Security Administrator's Guide for information about how shared schemas are created and used for Enterprise User SecurityAs 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 that 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 13-1 summarizes the object privileges available for each type of object.
Table 13-1 How Privileges Relate to Schema Objects
Object Privilege | Applies to Table? | Applies to View? | Applies to Sequence? | Applies to Procedure?Foot 1 |
---|---|---|---|---|
ALTER |
Yes | No | Yes | No |
DELETE |
Yes | Yes | No | No |
EXECUTE |
No | No | No | Yes |
INDEX |
YesFoot 2 | No | No | No |
INSERT |
Yes | Yes | No | No |
REFERENCES |
YesFootref 2 | No | No | No |
SELECT |
Yes | YesFoot 3 | Yes | No |
UPDATE |
Yes | Yes | No | No |
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 13-2 lists the SQL statements permitted by the object privileges shown in Table 13-1.
Table 13-2 SQL Statements Permitted by Database Object Privileges
See Also:
"Understanding User Privileges and Roles" for a discussion of object privileges