Forensic Audit Logging for PostgreSQL

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

BY LECTURER/ AISHA DAWOOD DW Lab # 3 Overview of Extraction, Transformation, and Loading.
1 DB2 Access Recording Services Auditing DB2 on z/OS with “DBARS” A product developed by Software Product Research.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 12 System and Object Privileges.
The Audit System for TWS z/OS
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
Adapted from Afyouni, Database Security and Auditing DB Auditing Examples (Ch. 9) Dr. Mario Guimaraes.
Linux Operations and Administration
Session 5: Working with MySQL iNET Academy Open Source Web Development.
FireRMS SQL Audit, Archiving & Purging Presented by Laura Small FireRMS Quality Assurance.
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
1. Automate a Secure Historical Data Store with Oracle Total Recall Venky RadhakrishnanKevin Jernigan Database DeveloperSenior Director Product Management.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
1 Oracle Database 11g – Flashback Data Archive. 2 Data History and Retention Data retention and change control requirements are growing Regulatory oversight.
Week 6 Lecture 2 System and Object Privileges. Learning Objectives  Identify and manage system and object privileges  Grant and revoke privileges to.
1 Lecture 19 Configuration Management Software Engineering.
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
An introduction to SQL 1/21/2014 – See chapter 2.3 and 6.1 PostgreSQL -
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
INTRODUCTION TO DBS Database: a collection of data describing the activities of one or more related organizations DBMS: software designed to assist in.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Chapter 3: Relational Databases
SQL SERVER AUDITING. Jean Joseph DBA/Consultant Contact Info: Blog:
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
SQL Triggers, Functions & Stored Procedures Programming Operations.
Strategies for Working with Texas-sized Databases Robert L Davis Database Engineer
SQL Basics Review Reviewing what we’ve learned so far…….
What is the Flashback Database? Improves a database’s availability Useful alternative to traditional restoration methods Contains Flashback logs Archived.
23 Copyright © 2004, Oracle. All rights reserved. Preferring the Past: Flashback.
ORACLE's Approach ORALCE uses a proprietary mechanism for security. They user OLS.... ORACLE Labeling Security. They do data confidentiality They do adjudication.
Understanding Core Database Concepts Lesson 1. Objectives.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
SQL Database Management
With Temporal Tables and More
Rob Gleasure robgleasure.com
SQL Query Getting to the data ……..
Katowice,
Temporal Databases Microsoft SQL Server 2016
Rob Gleasure robgleasure.com
Introduction To Database Systems
Example of a page header
Auditing in SQL Server 2008 DBA-364-M
Structured Query Language (Data definition Language)
Traveling in time with SQL Server 2017
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
The Audit System for IWS z/OS
Blog: Slides:
Prof. Arfaoui. COM390 Chapter 9
The Audit System for IWS z/OS
Understanding Core Database Concepts
Survey Results Respondents: 39 of 51 – 76%
Responding to Data Manipulation Via Triggers
Presentation transcript:

Forensic Audit Logging for PostgreSQL Moshe Jacobson http://cyanaudit.neadwerx.com

The Situation Data is mysteriously wrong/missing Legal is asking for records Who, when, how? How to respond? CYA with proof! Data wrong due to: race conditions; uncaught error conditions; unpredictable customers; heisenbugs Customer/boss looking for scapegoat Data went missing and you have no proof it was there? Restore a backup to find it? Forgetaboutit Is it a bug? Stories?

Application-Level Logging Explicit Tedious Easy to miss something Not always consistent Increases development time Better alternative? Do you add logging as you go? Or afterward? Tell about event tables, meta fields. Different places logging same event differently!

Database-Level Logging pg_audit https://github.com/jcasanov/pg_audit pgtrail http://code.google.com/p/pgtrail/ tablelog http://pgfoundry.org/projects/tablelog/ Audit trigger 91plus http://wiki.postgresql.org/wiki/Audit_trigger_91plus Half-baked home-grown solutions? I wanted something better. Note last updated timestamps here.

Our Application 80,000 users 1TB database 450 tables, 3200 columns 14 million daily page requests 8.5 million daily database updates 99.999% uptime SLA

Wishlist Extension-based Space-efficient, organized logging Per-column control of logging Attach descriptions to events Scalability to years’ worth of logs Export / import between log & files Automated log maintenance Easy recovery from mistakes

Cyan Audit - Logged Data Timestamp Name of table & column modified Integer PK of row modified You do have integer surrogate PKs, right?? Application-level userid of responsible user Transaction ID Application-supplied description Operation type ('I', 'U', 'D') Old and new values (stored as text)

Installation – Part I Unpack extension tarball, “make install” Configure custom_variable_classes in postgresql.conf (9.1 only): custom_variable_classes = 'cyanaudit' Create extension db=# create schema cyanaudit; db=# create extension cyanaudit schema cyanaudit; Set up logging triggers db=# select cyanaudit.fn_update_audit_fields(); Now you’re logging! Mention two letter prefixes such as fn_ At end, summarize mandatory vs. optional steps

Installation – Part II Install cron jobs to rotate and archive logs Set your database-specific settings alter database mydb set cyanaudit.archive_tablespace = 'big_slow_drive'; ... set cyanaudit.user_table = 'users'; ... set cyanaudit.user_table_uid_col = 'entity'; ... set cyanaudit.user_table_username_col = 'username'; ... set cyanaudit.user_table_email_col = 'email_address'; Add cyanaudit schema to database search path alter database mydb set search_path = public, cyanaudit; Mention two letter prefixes such as fn_ At end, summarize mandatory vs. optional steps

Post-installation

Post-installation

Selecting what to log Upon installation, all fields are enabled Consider high traffic fields tb_audit_field has one row per table/column "active" boolean controls logging for a column select fn_update_audit_fields() reindexes fields after DDL Disable logging for a session: set cyanaudit.enabled = 0

Selecting what to log Mention naming scheme of triggers and that they are created automatically

Selecting what to log

Selecting what to log

Selecting what to log

Selecting what to log

Selecting what to log

Querying the audit log View: vw_audit_log Columns: recorded | uid | user_email | txid | description | table_name | column_name | pk_val | op | old_value | new_value Millions of rows accumulate quickly Especially when you’re doing admin work and forget to turn off logging… Use indexed columns when querying: recorded, table_name + column_name, txid

Example

Example

Example Extended format not typical!

Reconstructing Queries View: vw_audit_transaction_statement Reconstructs queries effectively equivalent to original DML Columns: txid | recorded | email | description | query

Reconstructing Queries

Reconstructing Queries

When You F*** Up… We can reconstruct queries… Why not reverse them? fn_undo_transaction(txid) Undoes recorded changes for txid fn_get_last_audit_txid() Gives txid of last logged transaction select fn_undo_last_transaction() Combines two functions above. Story of working 3 days straight to fix data error. Can only undo recorded DML Undo not accurate if on out of order

When You F*** Up

When You F*** Up

Application Integration How DBAs see application code: Scary middleware code!

Application Integration Don't want to? Don't have to! Two modifications if you want: Attach UIDs to transactions Attach descriptions to transactions Scary middleware code!

Attaching UIDs to DML fn_set_audit_uid(uid) Match current_user to user_table_username_col Otherwise, assume 0

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Attaching UIDs to DML

Labeling transactions Not everyone understands the schema. Let's help them out. Two functions for labeling transactions: fn_label_audit_transaction(label, txid) fn_label_last_audit_transaction(label)

Labeling transactions

Labeling transactions

Log Rotation/Archival You’re gonna run out of space eventually. What is the solution?

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival

Log Rotation/Archival cyanaudit_log_rotate.pl Log entries since last rotation become a new child partition of parent table tb_audit_event. cyanaudit_dump.pl Back up audit data, remove old tables. cyanaudit_restore.pl Restore dumps created with cyanaudit_dump.pl

Wishlist – Nailed it! Extension-based Space-efficient, organized logging Per-column control of logging Attach descriptions to events Scalability to years’ worth of logs Export / import between log & files Automated log maintenance Easy recovery from mistakes Plus: Released under PostgreSQL license

Cyan Audit Caveats PostgreSQL version compatibility: >= 9.3.3: All features supported < 9.3.3: No DDL triggers. After any DDL you must select fn_update_audit_fields() < 9.2.0: Must modify postgresql.conf with custom_variable_classes = cyanaudit < 9.1.7: Not supported Logs only tables with integer PK. Logs only public schema. Truncates are not logged. Does not store original SQL. Mention bug in 9.1.6 – Extension’s sequences not correctly saved in dump/restore Mention bug in 9.3.2 - Extension’s event triggers not correctly saved in dump/restore

Cyan Audit Challenges Proper behavior with pg_dump/pg_restore Log tables using OID as PK Log tables in other schemas than public Amazon RDB – non-extension version? Automatic testing Leverage 9.4’s logical replication Wide use, inclusion with PostgreSQL core! YEAAH! Mention bug in 9.1.6 – Extension’s sequences not correctly saved in dump/restore Mention bug in 9.3.2 - Extension’s event triggers not correctly saved in dump/restore

Questions? Comments? Moshe Jacobson moshe@neadwerx.com Download: http://cyanaudit.neadwerx.com Thanks to Nead Werx, my employer, for sponsoring the development of Cyan Audit.