Security and User Management
Database security and auditing, authentication and authorization methods, managing user accounts in CDB and PDB, privilege management (system and object), role management, and profile management for password and resource control.
Topics in this chapter
- Database Security and Auditing (Standard, Fine-grained, Unified Auditing)
- Database Authentication and Authorization Methods
- Managing user accounts in CDB and PDB (Common and local users)
- Privilege Management (System and object privileges)
- Role management (Create, assign, modify, drop, predefined roles)
- Profile Management (Password policies, resource limits)
Database Security and Auditing
Security Principles and Guidelines
Database security is a multi-layered discipline that encompasses confidentiality, integrity, and availability of data. Oracle implements a defense-in-depth strategy through the following security layers: network security (firewalls, encryption), operating system security (file permissions, OS authentication), database access control (authentication, authorization, privileges), data encryption (Transparent Data Encryption — TDE), and auditing (tracking access and changes). The DBA must enforce the principle of least privilege — granting users only the minimum privileges necessary to perform their jobs — and regularly review access rights.
The security guidelines prescribed by Oracle include: restricting administrative privileges to the minimum necessary set of accounts, using strong password policies, implementing Transparent Data Encryption (TDE) for sensitive data at rest and in transit, encrypting network traffic using Oracle Net encryption, applying security patches promptly, and auditing all privileged operations.
Standard Auditing
Standard auditing tracks SQL statements, privileges, and schema objects. It is configured using the AUDIT command and recorded in the AUD$ base table (or, in newer versions, written to operating system files). The audit trail can be stored in the database (AUDIT_TRAIL=DB), in OS files (AUDIT_TRAIL=OS), or in XML files (AUDIT_TRAIL=XML).
-- Enable auditing of all DDL statements
AUDIT CREATE TABLE, CREATE VIEW, ALTER TABLE, DROP TABLE BY ACCESS;
-- Audit all inserts, updates, and deletes on a sensitive table
AUDIT INSERT, UPDATE, DELETE ON hr.employees BY ACCESS;
-- Audit all failed login attempts
AUDIT SESSION WHENEVER NOT SUCCESSFUL;
The audit trail can be queried through DBA_AUDIT_TRAIL (for database audit trail) or DBA_AUDIT_OBJECT and DBA_AUDIT_SESSION views. The DBA should periodically purge old audit records to prevent the SYSTEM tablespace from filling up.
Fine-Grained Auditing (FGA)
Fine-Grained Auditing extends standard auditing by allowing the DBA to define conditional audit policies at the row and column level. FGA policies are created using the DBMS_FGA package:
BEGIN
DBMS_FGA.ADD_POLICY(
object_schema => 'HR',
object_name => 'EMPLOYEES',
policy_name => 'AUDIT_HIGH_SALARY',
audit_condition => 'SALARY > 10000',
audit_column => 'SALARY',
handler_schema => NULL,
handler_module => NULL,
enable => TRUE,
statement_types => 'SELECT, INSERT, UPDATE, DELETE'
);
END;
This policy audits any access to the SALARY column of the EMPLOYEES table when the salary exceeds 10,000. FGA policies can also invoke a handler procedure (e.g., to send an email alert) when the policy is violated. The audit trail is accessible through DBA_FGA_AUDIT_TRAIL.
Unified Auditing
Starting with Oracle Database 12c, Unified Auditing consolidates all audit records into a single, read-only UNIFIED_AUDIT_TRAIL view. It replaces the fragmented audit trails of standard, FGA, and mandatory auditing. Unified auditing is enabled by default in Oracle 21c and later. Policies are created using the CREATE AUDIT POLICY statement:
CREATE AUDIT POLICY hr_sensitive_actions
ACTIONS SELECT ON hr.employees,
INSERT ON hr.employees,
UPDATE ON hr.employees,
DELETE ON hr.employees
WHEN 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') NOT IN (''HR_ADMIN'')'
EVALUATE PER SESSION;
AUDIT POLICY hr_sensitive_actions;
The unified audit trail provides a single source of truth for all audit data, simplifying compliance reporting and forensic analysis. The UNIFIED_AUDIT_TRAIL view can be queried with standard SQL, and its records are stored in the SYSAUX tablespace by default.
Privilege, Role, and Profile Management
Common and Local Users
In the multitenant architecture, the distinction between common and local users is fundamental to isolation guarantees:
- Common Users: Created in the root container (
CDB$ROOT) with aC##orc##prefix (by default, configurable viaCOMMON_USER_PREFIX). Common users can connect to any PDB and perform administrative tasks, provided they hold the appropriate privileges. Common users are stored in the root's data dictionary and are visible across all containers. - Local Users: Exist only within a single PDB. They have no visibility beyond their container and cannot connect to other PDBs or the root. Local users are created without the
C##prefix and are scoped strictly to the current container.
-- Create a common user in the root
CREATE USER C##db_admin IDENTIFIED BY password CONTAINER=ALL;
-- Grant common privileges
GRANT CREATE SESSION, SET CONTAINER TO C##db_admin CONTAINER=ALL;
-- Create a local user in a PDB
ALTER SESSION SET CONTAINER = hrpdb;
CREATE USER app_user IDENTIFIED BY password;
GRANT CONNECT, RESOURCE TO app_user;
Monitoring User Information
The DBA can monitor user information through several data dictionary views:
DBA_USERS(orCDB_USERSfor all containers): Username, account status, default tablespace, temporary tablespace, profile, and authentication type.DBA_PROFILES(orCDB_PROFILES): Profile resource limits and password parameters.DBA_ROLE_PRIVS: Roles granted to users.DBA_SYS_PRIVS: System privileges granted to users.DBA_TAB_PRIVS: Object privileges granted to users.