Overview

Oracle security layers: authentication (users, passwords, external identity), authorisation (system and object privileges, roles), fine-grained access control (VPD, Real Application Security), auditing, and encryption (TDE, network). Apply least privilege and never let applications connect as SYS, SYSTEM or the schema owner.

Core concepts

  • Users and schemas: a user owns a schema. Create an owner (no login for the app), a read-write application user and read-only users, with grants through roles.
  • Privileges: system (CREATE SESSION, CREATE TABLE) and object (SELECT on kb.orders). ANY privileges are broad and dangerous. Roles are not active inside definer’s-rights PL/SQL (oracle-plsql).
  • Profiles set resource limits and password rules: FAILED_LOGIN_ATTEMPTS, PASSWORD_LIFE_TIME, PASSWORD_LOCK_TIME, SESSIONS_PER_USER, IDLE_TIME, password complexity function.
  • Unified auditing: audit policies (CREATE AUDIT POLICY, AUDIT POLICY) write to UNIFIED_AUDIT_TRAIL. Prefer it to the legacy AUDIT statement and AUD$.
  • VPD (Virtual Private Database / row-level security) via DBMS_RLS.ADD_POLICY: Oracle appends a predicate returned by your function to every statement on the table.
  • Data Redaction masks values at query time; Database Vault separates duties (option).
  • TDE (Transparent Data Encryption) encrypts tablespaces and columns at rest using a master key in a keystore (wallet). Network encryption (SQLNET.ENCRYPTION_*, TLS) protects data in transit.
  • Use bind variables and DBMS_ASSERT to prevent SQL injection; privileges alone do not stop it.

Worked example

Executed on the Free container. A limited user, a profile and an audit policy:

CREATE PROFILE app_prof LIMIT failed_login_attempts 5 password_lock_time 1 password_life_time 90
                                sessions_per_user 10 idle_time 30;
CREATE USER app_u IDENTIFIED BY "<secret>" PROFILE app_prof;
GRANT CREATE SESSION TO app_u;
GRANT SELECT ON kb.orders TO app_u;
 
CREATE AUDIT POLICY kb_orders_read ACTIONS SELECT ON kb.orders;
AUDIT POLICY kb_orders_read WHENEVER SUCCESSFUL;
-- app_u runs: SELECT COUNT(*) FROM kb.orders WHERE customer_id = 7
SELECT dbusername, action_name, object_schema||'.'||object_name obj, sql_text
FROM unified_audit_trail WHERE unified_audit_policies LIKE '%KB_ORDERS_READ%';
-- APP_U | SELECT | KB.ORDERS | select count(*) from kb.orders where customer_id=7

VPD: only paid orders for APP_U (policy function returns status = 'paid' for that user, NULL = no filter for others):

BEGIN DBMS_RLS.ADD_POLICY(object_schema=>'KB', object_name=>'ORDERS', policy_name=>'ORDERS_PAID_ONLY',
  function_schema=>'KB', policy_function=>'VPD_ORDERS', statement_types=>'SELECT'); END;
/
-- SYS sees 500000 rows; APP_U sees 300000 rows with one distinct status

TDE was not configured: V$ENCRYPTION_WALLET reported NOT_AVAILABLE in this image.

Pitfalls and production notes

  • Never put real passwords in notes, scripts or version control; use a secret manager and rotate.
  • VPD predicates must be fast and correct; test them with EXPLAIN and for all roles, because SYSDBA and EXEMPT ACCESS POLICY bypass them.
  • Revoke PUBLIC privileges you do not need and review DBA_SYS_PRIVS and DBA_ROLE_PRIVS regularly.
  • Keep the audit trail on a managed size and purge policy (DBMS_AUDIT_MGMT).
  • Back up the TDE wallet and keep it separate from the data backups; losing it makes encrypted data unrecoverable (oracle-rman-backup).
  • Compare with PostgreSQL roles and RLS (pg-security-roles) and SQL Server security (sqlserver-security).

Practice questions

  1. Why is an application connecting as the schema owner a risk?
  2. How does VPD differ from a view that filters rows?
  3. What must you back up besides data files when TDE is on?

References

  • Oracle Database Security Guide

oracle-plsql · oracle-multitenant · sqlserver-security · pg-security-roles