Database AdministrationUnit 213 min read
Oracle Security: Users, Privileges, Roles & Access Control
Unit 2 of Database Administration: Covers Oracle’s security model—how users, roles, privileges, and authentication work together to protect data, with practical examples of access control, auditing, and real-world applications like eSewa’s transaction security.
TAKEAWAYS:
- Oracle secures data via users, roles, and privileges, with granular control over SQL commands and objects.
- Authentication uses passwords, certificates, or external systems (e.g., LDAP), while authorization enforces "least privilege."
- Locking mechanisms (row, table, DDL) prevent concurrent conflicts; locking modes (shared/exclusive) balance performance and safety.
- Roles group privileges (e.g.,
DBA,CONNECT) for easier management, but must be explicitly granted. - Auditing logs actions (e.g.,
ALTER TABLE) for compliance (e.g., NEPSE trade audits). - Real-world: eSewa uses Oracle roles to restrict admin users from modifying transaction logs; NTC secures network access via Oracle’s
NETWORK_ADMINrole.
1. Oracle Database Security Overview
Oracle’s security model protects data at three layers:
- Authentication: Verifying who you are (user credentials).
- Authorization: What you can do (privileges/roles).
- Audit & Compliance: Tracking actions for accountability.
Why it matters:
- eSewa uses Oracle roles to ensure only approved staff can modify payment gateways.
- Ncell secures customer data via Oracle’s
CREATE SESSIONprivilege, restricting unauthorized logins.
2. Users and Authentication
User Creation
Users are created with a schema (default tablespace) and default tablespace for storage.
CREATE USER john DOMAIN dbadmin
IDENTIFIED BY "SecurePass123"
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA 100M ON users;
DOMAIN: Adds a prefix to the username (e.g.,john@dbadmin).QUOTA: Limits storage usage (e.g., 100MB forjohn).
Authentication Methods
| Method | Description | Example Use Case |
|---|---|---|
| Password | Plaintext or hashed (default). | Local Oracle databases. |
| Certificate | Public-key cryptography (e.g., SSL client certs). | Secure remote connections. |
| External (LDAP) | Integrates with Active Directory or OpenLDAP. | Enterprise environments (e.g., NTC). |
Worked Example: Scenario: Ncell wants to restrict admin access to Oracle DB. Solution:
CREATE USER ncell_admin
IDENTIFIED EXTERNALLY 'LDAP://ldap.ncell.com';
- Uses Ncell’s LDAP server for authentication, enforcing company policies.
3. Privileges: The "What You Can Do" Layer
Privileges grant permissions on:
- SQL commands (e.g.,
CREATE TABLE,DROP USER). - Database objects (e.g.,
SELECToncustomerstable).
Types of Privileges
mindmap
root((Privileges))
System Privileges
CREATE SESSION
CREATE TABLE
DROP USER
Object Privileges
SELECT ON customers
INSERT ON orders
ALTER ON salaryGranting Privileges
-- Grant system privilege
GRANT CREATE TABLE TO john;
-- Grant object privilege
GRANT SELECT, INSERT ON employees TO hr_staff;
-- Revoke privilege
REVOKE UPDATE ON orders FROM sales_team;
Real-World Tie: Daraz Inventory System:
- Privilege:
SELECT ON products→ Onlyinventory_analystcan query stock levels. - Role:
DARAZ_INVENTORY→ GroupsSELECT,UPDATEonproductsfor efficiency.
4. Roles: Grouping Privileges
Roles bundle privileges for easier management. Common Oracle Roles:
| Role | Privileges Granted |
|---|---|
CONNECT |
CREATE SESSION, CREATE TABLE, CREATE VIEW |
RESOURCE |
CONNECT + CREATE INDEX, CREATE PROCEDURE, UNLIMITED TABLESPACE |
DBA |
Full administrative access (use sparingly!). |
EXP_FULL_DATABASE |
Export data (used in Data Pump migrations). |
Example:
-- Create a custom role
CREATE ROLE daraz_reports;
-- Grant privileges to the role
GRANT SELECT ON sales_data TO daraz_reports;
GRANT SELECT ON customer_data TO daraz_reports;
-- Grant the role to a user
GRANT daraz_reports TO analytics_team;
Advantages:
- Simplifies administration: Assign roles instead of individual privileges.
- Enforces least privilege: Users get only what they need (e.g.,
analytics_teamcannotDROP TABLE).
Disadvantages:
- Role explosion: Too many roles can complicate auditing.
- Granularity limits: Some tasks require fine-grained privileges (e.g.,
ALTER TABLEon specific columns).
5. Locking Mechanisms: Preventing Concurrent Conflicts
Oracle uses locks to manage concurrent access to data. Lock Types:
| Lock Type | Scope | Purpose |
|---|---|---|
| Row Lock | Single row | Prevents two users from editing the same row simultaneously. |
| Table Lock | Entire table | Used during ALTER TABLE or DROP TABLE operations. |
| DDL Lock | Database-wide | Granted automatically for DDL statements (e.g., CREATE INDEX). |
Locking Modes
| Mode | Description | Example Use Case |
|---|---|---|
| Shared (S) | Allows concurrent reads. | Multiple users querying employees. |
| Exclusive (X) | Blocks all other locks (reads/writes). | Updating a critical salary table. |
| Row Share (RS) | Allows concurrent reads but blocks writes. | High-read, low-write scenarios. |
How Locks Are Acquired:
- Automatic Locking:
- Oracle grants locks when a user executes DML (e.g.,
UPDATE). - Example: Locking a row during
UPDATE salary SET bonus = 1000 WHERE emp_id = 100.
- Oracle grants locks when a user executes DML (e.g.,
- Manual Locking:
- Using
LOCK TABLEorSELECT ... FOR UPDATE:-- Lock a table for exclusive access LOCK TABLE orders IN EXCLUSIVE MODE; -- Lock a row for update SELECT * FROM accounts WHERE account_id = 123 FOR UPDATE;
- Using
Worked Example: Scenario: Pathao drivers need to update their availability status without conflicts. Solution:
-- Driver locks their row to prevent another driver from updating it
SELECT * FROM drivers WHERE driver_id = 42 FOR UPDATE;
-- Now, only driver 42 can modify their status.
6. Auditing: Tracking Actions for Compliance
Oracle audits track who did what, when, and why. Auditing Methods:
- Default Auditing (enabled by
AUDITcommand):AUDIT ALTER TABLE, DROP TABLE BY john;- Logs all
ALTER/DROPactions byjohnto theAUD$table.
- Logs all
- Fine-Grained Auditing (FGA):
CREATE POLICY salary_audit USING (salary > 100000) FOR UPDATE, DELETE STORE EXCEPT WHENEVER SUCCESSFUL;- Audits
UPDATE/DELETEonsalary > 100,000.
- Audits
Real-World Example: NEPSE Trading System:
- Audit Rule:
AUDIT TRADE_EXECUTE BY TRADER_ROLE; - Why: Ensures no trader alters trade records after execution (prevents fraud).
AUD$ Table Structure:
-- Key columns in AUD$
SELECT * FROM AUD$
WHERE username = 'john'
ORDER BY timestamp DESC;
| Column | Description |
|---|---|
username |
User who performed the action. |
objname |
Object affected (e.g., employees). |
privilege |
Privilege used (e.g., UPDATE). |
timestamp |
When the action occurred. |
7. Security Best Practices
- Least Privilege Principle:
- Grant only the privileges needed (e.g.,
SELECTonorders, notDROP TABLE).
- Grant only the privileges needed (e.g.,
- Regular Audits:
- Review
AUD$for suspicious activity (e.g., unexpectedDROP USERcommands).
- Review
- Role Hierarchy:
- Avoid granting roles to roles (e.g.,
GRANT DBA TO CONNECT).
- Avoid granting roles to roles (e.g.,
- Password Policies:
- Enforce strong passwords:
ALTER PROFILE default LIMIT PASSWORD_LIFE_TIME 90; ALTER PROFILE default LIMIT PASSWORD_REUSE_TIME UNLIMITED; ALTER PROFILE default LIMIT PASSWORD_REUSE_MAX 10;
- Enforce strong passwords:
- Network Security:
- Restrict
NETWORK_ADMINrole to trusted admins (used in Oracle Listener config).
- Restrict
In the Real World
eSewa Payment Gateway:
- Idea: Roles + Least Privilege
- How:
eSewa_DB_ADMINrole hasALTER TABLEontransactions, buteSewa_AUDITORonly hasSELECT. - Why: Prevents fraud by separating write and read access.
NTC’s Network Management:
- Idea: External Authentication
- How: NTC’s Oracle DB uses
IDENTIFIED EXTERNALLYwith NTC’s LDAP server. - Why: Ensures only NTC employees (via Active Directory) can log in.
Daraz Order Processing:
- Idea: Locking + Auditing
- How:
- Orders locked during
UPDATE status(prevents race conditions). AUDIT UPDATE ON orders BY order_processor;
- Orders locked during
- Why: Tracks who changed an order’s status (e.g., from "Processing" to "Shipped").
Exam Tip
- Focus on:
- Syntax:
CREATE USER,GRANT ROLE,AUDITcommands. - Concepts: Least privilege, role hierarchy, lock types.
- Real-World Mapping: Always tie answers to apps like eSewa or NEPSE.
- Syntax:
- Common Pitfalls:
- Mixing up privileges (what you can do) and roles (groups of privileges).
- Forgetting to include authentication methods (passwords, certificates, LDAP).
- Overlooking auditing—exams often ask how to track actions.
- How to Score Full Marks:
- Diagrams: Draw a role-privilege hierarchy (e.g.,
CONNECT→CREATE TABLE). - Examples: Use Daraz’s inventory system or NEPSE’s trade audits in answers.
- Commands: Always show
CREATE USER,GRANT ROLE, andAUDITsyntax.
- Diagrams: Draw a role-privilege hierarchy (e.g.,
In the real world
- eSewa: Uses Oracle’s
EXCLUSIVElocks on transaction tables to prevent double-spending during payment processing. The system grantsUPDATEprivileges only to thePAYMENT_HANDLERrole, which holds an exclusive lock during critical operations. - NTC: Implements
ROW SHARElocks for high-traffic network logs (e.g.,SELECToncall_records) while allowing concurrent reads. TheNETWORK_ADMINrole is restricted toALTERoperations with exclusive locks. - Nepali Banks (e.g., NMB): Audits
DROP TABLEoperations via Oracle’sAUDITfeature to comply with RBI regulations, logging actions to theAUD$table with timestamps and user IDs.
Based on the TU BIT syllabus for Database Administration (BIT352), unit 2.
Discussion
Loading…