SlideShare a Scribd company logo
A Comparison of PostgreSQL Encryption
Options
Syed Faisal Akber, Staff Technical Support Engineer
Dong Ye, Staff Engineer

© 2013 VMware Inc. All rights reserved
Agenda






2

Why encryption?
Some Postgres encryption options
Performance results

Real-world use cases
Conclusions
Why Encrypt Data?

 Protect sensitive information
 Prevent identity theft
 Satisfy paranoia
 Comply with laws and standards (SOX, HIPPA, PCI, …)

3
Typical Architecture

4
Postgres Encryption Options

 Where?
• Encrypting Specific Columns
• Encrypting Data Partitions
• Encrypting Data Across Network

 Who?
• Database Server/Client Communication over SSL
• Complete Application Encryption

5
Encrypting Specific Columns

 Why?
• Offload
• Centralize

 Use the pgcrypto module
 Require application change

6
Encrypting Specific Columns: Diagram

A

B

C

1

1200

F7956d6e

2

-45

249e401

Specific columns are protected

7
Encrypting Specific Columns: pgcrypto

 Provide a number of functions
• General hashing functions
• Password hashing functions
• PGP functions
• RAW encryption/decryption functions

8
Using pgcrypto

 Build Server and Extension, Use Extension
./configure --with-openssl
make
make install
cd contrib/pgcrypto
make
make install
pgbench=# CREATE EXTENSION pgcrypto;

 Augment DML in application
INSERT Example
INSERT INTO z (a, b, c) VALUES (3, 34500, encrypt('Test'::bytea,
'key'::bytea, 'aes'));

SELECT Example
SELECT a, b, convert_from(decrypt(c, 'key'::bytea, 'aes'),
current_setting('server_encoding'))::int AS c FROM z WHERE a = 1;

9
Encrypting Data Partition: Diagram

10
Encrypting Data Partition (Filesystem)

 Prepare an encrypted filesystem with dm-crypt
dd if=/dev/zero of=/data/crypt count=8 bs=1G

chmod 600 /data/crypt
losetup /dev/loop0 /data/crypt
cryptsetup -y create secretfs /dev/loop0
cryptsetup status secretfs

mke2fs -j -O dir_index /dev/mapper/secretfs
tune2fs -l /dev/mapper/secretfs
mkdir /mnt/secretfs
mount /dev/mapper/secretfs /mnt/secretfs/

 Run initdb on the encrypted filesystem
 Start Postgres server
11
Encrypting Data Across Network

Two main methods
 Postgres built-in SSL
 SSH tunnel

12
Encrypting Data Across Network

13
Encrypting Data Across Network: SSL






Facility exists in Postgres
Configure server
Configure SSL flag in client
May need to open ports in firewall/router
Cisco PAT configuration in Cisco IOS
ip nat inside source static tcp 10.4.3.2 5432 interface Serial0 5432

14
Server Configuration
Build Server
./configure --with-openssl
make
make install

Create SSL Keys and Sign Certificate
openssl req -new -text -out server.req

openssl rsa -in privkey.pem -out server.key
rm privkey.pem
openssl req -x509 -in server.req -text -key server.key -out
server.crt
chmod 600 server.key

15
Server Configuration (cont.)

 Update pg_hba.conf
hostssl all

all

 Update postgresql.conf
• Ensure listen_addresses is set correctly
• Add ssl = on
• Check SSL certificate files location
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'

 Restart Postgres server

16

0.0.0.0/0

md5
Client Configuration

 Connect using sslmode option with one of four values:
• disable
• allow
• prefer
• require
PHP Connection Example
$link = pg_connect("host=10.4.3.2 port=5432 dbname=pgbench
user=pgbench password=pgbench sslmode=require");

17
Encrypting Data Across Network: SSH Tunnel

 No modifications to Postgres configuration
 Use of existing SSH gateway
ssh -f -N -L 127.0.0.1:2000:10.4.3.2:5432 user@sshgw.corp.net

PHP Connection Example
$link = pg_connect("host=127.0.0.1 port=2000 dbname=pgbench
user=pgbench password=pgbench");

18
Complete Application Encryption

 Application encrypts and writes data into database
 Application reads and decrypts data from database
 Requires no involvement of database and network
• Listed here for completeness
• No tests done

19
Complete Client Encryption

20
Test Bed







4x Intel Xeon E5-5640 (32 cores in total), EMC VNX5500 SAN
Hypervisor: VMware ESXi 5.1 Express Patch 2
Virtual machine: 32 vCPUs, 12GB vRAM

Guest operating system: SuSE Linux Enterprise Server 11 SP1
Postgres 9.3.0:
• shared_buffers= 8GB, checkpoint_segments=100
• Separate partitions for PGDATA and XLOG

 Benchmark:
• pgbench -i -s 100; pgbench -c 32 -j 32 -M prepared -T 300

21
Encrypting Columns (pgcrypto) Tests

 Test bed
• pgbench connects over LAN
• Workload: pgbench from postgresql.git versus pgbench modified
• pgbench modified: encrypt/decrypt abalance column in pgbench_accounts
UPDATE pgbench_accounts SET abalance = encrypt( decrypt(abalance) + :delta)
WHERE tid = :tid;
SELECT convert_from(decrypt(abalance, 'key'::bytea, 'aes'),
current_setting('server_encoding')) FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_accounts SET abalance = encrypt(0::text::bytea, 'key'::bytea,
'aes');

 Results
Baseline
pgbench tps

22

pgcrypto

3483

3311
Encrypting Data Partition Tests

 Test bed
• pgbench connects over Unix domain sockets

 Results
Baseline
pgbench tps

23

Encrypting DATA & XLOG

13814

5414
Encrypting Data over Network Tests

 Test bed
• pgbench connects over LAN and WAN (coast-to-coast)

 Results
pgbench tps

SSL

SSH tunnel

LAN

3250

3132

1510

WAN

24

Baseline

42.11

42.01

34.68
Real-World Use Cases

 E-commerce website
 Patient information application

25
E-Commerce Website

 Case
• Web server is hosted on public cloud
• Database server is hosted internally

 Options to encrypt data on the wire
• SSL
• pgcrypto for specific columns (e.g., credit card)

26
Patient Information Application

 Case
• Internal application
• Information remains in-house (within clinic or hospital)

 Options to encrypt data on disk
• Data partition
• Specific columns

27
Conclusions

 Why Encrypt Data?
 Encryption Options
• pg_crypto and Column based Encryption
• SSL/SSH Tunnel
• Filesystem Encryption

 Performance results
 Real-world Examples

28
Questions?

29
References














30

http://www.postgresql.org/docs/current/static/encryption-options.html
http://www.postgresql.org/docs/current/static/pgbench.html
http://www.postgresql.org/docs/current/static/ssl-tcp.html
http://www.postgresql.org/docs/current/static/ssh-tunnels.html
http://www.postgresql.org/docs/current/static/libpq-connect.html

http://www.postgresql.org/docs/current/static/pgcrypto.html
http://www.postgresql.org/docs/current/static/libpq-ssl.html
http://www.revsys.com/writings/quicktips/ssh-tunnel.html
http://cubist.cs.washington.edu/doc/ExamplePHPwPostgreSQL.shtml
http://php.net/manual/en/ref.pgsql.php
http://www.php.net/manual/en/function.pg-connect.php
http://wiki.centos.org/HowTos/EncryptedFilesystem
http://www.faqs.org/docs/Linux-HOWTO/Loopback-Encrypted-Filesystem-HOWTO.html

More Related Content

ODP
PostgreSQL: Welcome To Total Security
PDF
A Performance Characterization of Postgres on Different Storage Systems
PPTX
PGEncryption_Tutorial
PDF
Secure PostgreSQL deployment
PDF
Nginx Internals
PDF
How to monitor NGINX
PDF
Squid proxy-configuration-guide
KEY
Nginx - Tips and Tricks.
PostgreSQL: Welcome To Total Security
A Performance Characterization of Postgres on Different Storage Systems
PGEncryption_Tutorial
Secure PostgreSQL deployment
Nginx Internals
How to monitor NGINX
Squid proxy-configuration-guide
Nginx - Tips and Tricks.

What's hot (20)

PDF
Load Balancing with Nginx
PPTX
NGINX: High Performance Load Balancing
PDF
ReplacingSquidWithATS
PPTX
Introduction to NGINX web server
PDF
Extending functionality in nginx, with modules!
PPTX
Choosing A Proxy Server - Apachecon 2014
PDF
Load Balancing MySQL with HAProxy - Slides
PDF
Known basic of NFV Features
PDF
Intro ProxySQL
PDF
Varnish SSL / TLS
PDF
Nginx dhruba mandal
PPT
Squid server
PPTX
ODP
Squid Proxy Server
PDF
Ceph Day Beijing - SPDK for Ceph
DOCX
Project on squid proxy in rhel 6
PDF
Simplifying Ceph Management with Virtual Storage Manager (VSM)
PPTX
PPTX
Rate Limiting with NGINX and NGINX Plus
ODP
Ceph Day Melbourne - Troubleshooting Ceph
Load Balancing with Nginx
NGINX: High Performance Load Balancing
ReplacingSquidWithATS
Introduction to NGINX web server
Extending functionality in nginx, with modules!
Choosing A Proxy Server - Apachecon 2014
Load Balancing MySQL with HAProxy - Slides
Known basic of NFV Features
Intro ProxySQL
Varnish SSL / TLS
Nginx dhruba mandal
Squid server
Squid Proxy Server
Ceph Day Beijing - SPDK for Ceph
Project on squid proxy in rhel 6
Simplifying Ceph Management with Virtual Storage Manager (VSM)
Rate Limiting with NGINX and NGINX Plus
Ceph Day Melbourne - Troubleshooting Ceph
Ad

Similar to PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options (20)

PDF
Securing PostgreSQL from External Attack
PDF
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
PDF
PG Day'14 Russia, Secure PostgreSQL Deployment, Magnus Hagander
PDF
Transparent Data Encryption in PostgreSQL
PDF
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
PPTX
Get Your Insecure PostgreSQL Passwords to SCRAM
PDF
PostgreSQL instance encryption: More database security
PDF
Achieving Pci Compliace
PPTX
postgres_data_security_2017
PPTX
Enterprise-class security with PostgreSQL - 1
PDF
Learning postgresql
PDF
PostgreSQL: How to Store Passwords Safely
PPTX
Postgre sql best_practices
PDF
PostgreSQL 9.5 - Major Features
PDF
DB vs. encryption
PDF
way to join Real illuminati agent 0782561496,0756664682
PDF
illuminati Uganda brotherhood agent in Kampala call 0756664682,0782561496
PDF
REAL ILLUMINATI UGANDA KAMPALA CALL 0782561496,0756664682
PDF
Real illuminati agent from Uganda Kampala call 0782561496/0756664682
ODP
Introduction to PostgreSQL
Securing PostgreSQL from External Attack
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
PG Day'14 Russia, Secure PostgreSQL Deployment, Magnus Hagander
Transparent Data Encryption in PostgreSQL
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAM
PostgreSQL instance encryption: More database security
Achieving Pci Compliace
postgres_data_security_2017
Enterprise-class security with PostgreSQL - 1
Learning postgresql
PostgreSQL: How to Store Passwords Safely
Postgre sql best_practices
PostgreSQL 9.5 - Major Features
DB vs. encryption
way to join Real illuminati agent 0782561496,0756664682
illuminati Uganda brotherhood agent in Kampala call 0756664682,0782561496
REAL ILLUMINATI UGANDA KAMPALA CALL 0782561496,0756664682
Real illuminati agent from Uganda Kampala call 0782561496/0756664682
Introduction to PostgreSQL
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
Spectroscopy.pptx food analysis technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
Spectroscopy.pptx food analysis technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
sap open course for s4hana steps from ECC to s4
Encapsulation theory and applications.pdf

PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options