Two kinds of privilege. System privileges allow an action anywhere (CREATE TABLE, SELECT ANY TABLE). Object privileges allow an action on one object (SELECT ON ord_owner.orders). The ANY privileges are the dangerous ones: SELECT ANY TABLE means every table in the database including the ones holding other applications' data. Grant them essentially never.
Roles group privileges. Oracle ships several that are commonly over-granted. DBA is not an administrative convenience; it is everything. RESOURCE has historically carried UNLIMITED TABLESPACE, which is a quota bypass. And a role granted to a user is not active inside a definer's-rights PL/SQL unit - privileges needed by a package must be granted directly to the owner, which is the single most confusing permission behaviour in Oracle.
Definer's rights versus invoker's rights is the related design decision. A package defaults to AUTHID DEFINER: it runs with the owner's privileges, so callers need no table access at all. AUTHID CURRENT_USER runs with the caller's. Definer's rights is the basis of the narrow-interface pattern and is usually what you want.
Unified auditing (12c+) replaced the older mechanisms with one consolidated trail. Create policies for what you will actually review - failed logons, privilege grants, schema changes, access to sensitive tables - and then review them. An audit policy capturing everything produces volume nobody reads, which is indistinguishable from no audit at all.
Encryption. Transparent Data Encryption encrypts tablespaces or columns at rest and is part of the Advanced Security option - separately licensed on Enterprise Edition. Network encryption is included. As always, the hard part is key management: the wallet must be backed up separately from the database, and losing it loses the data permanently.
Storage. Tablespaces, data files, and optionally ASM, Oracle's own volume manager providing striping and mirroring across disks. Multitenant administration adds commands operating at the container level - a PDB can be cloned, unplugged, plugged into another CDB, or flashed back independently, which makes refreshing a test environment dramatically simpler than it is elsewhere.
Laboratory exercise 6 - make it defensible.
Implement least privilege: a schema owner, an application user with only object privileges on what it needs, a read-only reporting user, and a user with only EXECUTE on your package and no table privileges at all. Test every denial.
Demonstrate the definer's-rights behaviour: grant a privilege through a role, show the package failing to compile or run, then grant it directly and show it working. This is the thing that will cost you an afternoon in a real project.
Configure unified auditing for failed logons, grants and schema changes. Trigger each and read the trail back.
Clone a PDB and demonstrate refreshing a test environment from it.
Deliverable: the DDL, a test script attempting every forbidden operation with its output, the role-versus-direct-grant demonstration, the audit extract, a monitoring configuration with metrics and thresholds, and a deployment, capacity and licence checklist naming every separately licensed feature in your design.
-- ================= Privileges: system vs object ====================
GRANT CREATE SESSION TO ord_app; -- system
GRANT SELECT, INSERT, UPDATE ON ord_owner.orders TO ord_app; -- object
GRANT SELECT ON ord_owner.customer TO ord_app;
-- NEVER, except with a specific written reason:
-- GRANT SELECT ANY TABLE TO ... -- every table in the database
-- GRANT DBA TO ... -- everything. Not "an admin role".
-- GRANT RESOURCE TO ... -- historically carries
-- -- UNLIMITED TABLESPACE, a quota bypass
-- Roles for the application's functions:
CREATE ROLE ord_reader;
CREATE ROLE ord_writer;
GRANT SELECT ON ord_owner.orders TO ord_reader;
GRANT SELECT ON ord_owner.order_line TO ord_reader;
GRANT ord_reader TO ord_writer;
GRANT INSERT, UPDATE ON ord_owner.orders TO ord_writer;
GRANT ord_writer TO ord_app;
-- ================= THE BEHAVIOUR THAT COSTS AN AFTERNOON ===========
-- A role is NOT active inside a definer's-rights PL/SQL unit.
--
-- GRANT ord_reader TO ord_owner; -- via a role
-- CREATE PACKAGE BODY ... SELECT ... FROM other_schema.table ...
-- -> PLS-00201: identifier must be declared
--
-- Privileges a package body needs must be granted DIRECTLY to its
-- owner:
GRANT SELECT ON other_schema.reference_data TO ord_owner;
-- Definer's vs invoker's rights:
CREATE OR REPLACE PACKAGE ord_owner.order_api
AUTHID DEFINER -- the default: runs as the OWNER, so callers
AS ... -- need no table privileges at all. This is
-- the narrow-interface pattern.
-- AUTHID CURRENT_USER -- runs as the CALLER; they need the grants.
GRANT EXECUTE ON ord_owner.order_api TO ord_app;
-- ord_app can now place an order and cannot read the orders table.
-- ================= Verify the denials ==============================
-- The assessed part. Every one of these must fail.
-- CONNECT ord_app/...
-- SELECT * FROM ord_owner.product; -- ORA-00942
-- DELETE FROM ord_owner.orders; -- ORA-01031
-- DROP TABLE ord_owner.orders; -- ORA-01031
-- ALTER USER ord_owner IDENTIFIED BY x; -- ORA-01031
SELECT grantee, privilege, table_name FROM dba_tab_privs
WHERE grantee IN ('ORD_APP','ORD_READER','ORD_WRITER') ORDER BY grantee;
SELECT grantee, privilege FROM dba_sys_privs
WHERE grantee IN ('ORD_APP') ORDER BY privilege;
-- Who holds the dangerous ones? Run this on every inherited database:
SELECT grantee, privilege FROM dba_sys_privs
WHERE privilege LIKE '%ANY%' AND grantee NOT IN ('SYS','SYSTEM','DBA')
ORDER BY grantee;
-- ================= Unified auditing ================================
CREATE AUDIT POLICY ord_security_policy
PRIVILEGES CREATE ANY TABLE, DROP ANY TABLE, ALTER ANY TABLE
ACTIONS CREATE TABLE, DROP TABLE, GRANT, REVOKE,
ALTER USER, CREATE USER
ACTIONS SELECT ON ord_owner.customer;
AUDIT POLICY ord_security_policy;
AUDIT POLICY ord_security_policy WHENEVER NOT SUCCESSFUL; -- failures too
SELECT event_timestamp, dbusername, action_name, object_name,
return_code, sql_text
FROM unified_audit_trail
WHERE event_timestamp > SYSTIMESTAMP - INTERVAL '1' DAY
ORDER BY event_timestamp DESC FETCH FIRST 50 ROWS ONLY;
-- Audit what will be REVIEWED. Everything else is volume that makes
-- the trail unusable, which is the same as having no trail.
-- ================= TDE - separately licensed on EE =================
-- ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '/opt/oracle/wallet'
-- IDENTIFIED BY "Str0ng#Wallet";
-- ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "Str0ng#Wallet"
-- WITH BACKUP;
--
-- CREATE TABLESPACE app_secure DATAFILE ... ENCRYPTION USING 'AES256'
-- DEFAULT STORAGE (ENCRYPT);
--
-- BACK UP THE WALLET, separately from the database. Lose it and the
-- data is unrecoverable - permanently, by design.
SELECT wrl_type, status, wallet_type FROM v$encryption_wallet;
-- ================= Multitenant administration ======================
-- Cloning a PDB: the fastest test-environment refresh available in
-- any database.
-- ALTER PLUGGABLE DATABASE freepdb1 CLOSE;
-- ALTER PLUGGABLE DATABASE freepdb1 OPEN READ ONLY;
-- CREATE PLUGGABLE DATABASE testpdb FROM freepdb1;
-- ALTER PLUGGABLE DATABASE testpdb OPEN;
SELECT con_id, name, open_mode, restricted, total_size/1024/1024 AS mb
FROM v$pdbs;
-- ================= What to alert on ================================
SELECT ROUND(100*space_used/space_limit,1) AS fra_pct FROM v$recovery_file_dest;
SELECT tablespace_name, ROUND(100*(used_space/tablespace_size),1) AS pct_used
FROM dba_tablespace_usage_metrics ORDER BY pct_used DESC;
SELECT name, value FROM v$dataguard_stats WHERE name = 'apply lag';
SELECT COUNT(*) FROM v$session WHERE blocking_session IS NOT NULL;
SELECT COUNT(*) FROM dba_objects WHERE status = 'INVALID';
Discussion
No questions on this topic yet. Sign in to ask the first one.