SlideShare a Scribd company logo
Security Best Practices for
your Postgres Deployment
Presented by
Sameer Kumar, DB Solution Architect, Ashnik
“By default PostgreSQL is Possibly the most
security – aware database available…”
- Database Hacker’s Handbook
pgDayAsia2016,Singapore
• Security Model
• Security Features in Postgres
• Securing the access
• Avoiding common attacks
• Access Control and Securing data
• Logging and Auditing
• Patching – OS and PostgreSQL
Agenda
2
pgDayAsia2016,Singapore
• A random Oracle-DB2 DBA who started working on PostgreSQL
• And found it absolutely great
• Works for Ashnik Pte Ltd – Open Source Solutions and consulting
• Who also works on noSQL databases
• Hobbies – Cycling and Photography
3
About Me
Postgres Security
pgDayAsia2016,Singapore
Secure access is a two step process:
• Authentication
• Ensures a user is who he/she claims to be
• Authorization
• Ensures an authenticated user has access to only the data for which
he/she has been granted the appropriate privileges.
Security Model: Authentication and Authorization
5
pgDayAsia2016,Singapore
• Object level privileges assigned to roles and users
• Virtual Private Database- Row level security
• Kerberos and LDAP authentication
• Host base authentication
• SSL communication
• Data Level Encryption (AES, 3DES, etc)
• Ability to utilize 3rd party Key Stores in a full PKI Infrastructure
• Foundation for full compliance with the strictest of security
standards (PCI Data Security Standard)
• Flexible field level encryption and row level security
High Level Features
6
pgDayAsia2016,Singapore
• Kerberos : Kerberos based encrypted "ticket" for authentication
• Password : md5 and plain text
• LDAP authentication : It uses LDAP as the password verification
method
• Trust : Authentication without password or Auth token
• RADIUS: Use radius server for authentication
Different Authentication Methods
7
Securing Postgres
pgDayAsia2016,Singapore
• Override the default port of Postgres
• Use a non-default name for the superuser
• Can be specified during “initdb”
• While initializing the cluster with “initdb” use -A to specify
authentication mode
• By default each new DB has connect privilege granted to public
• revoke connect on my_new_db from public;
• grant connect on my_new_db to my_app_user;
Override the defaults
9
pgDayAsia2016,Singapore
• Use listen_addresses to control where you Database is listening for
connections
• Make sure that you don’t listen on public network interface
• Control who can connect from where
• Use pg_hba.conf to control which user can connect to specific databases from
specific IP addresses
• Avoid using general rules e.g. Database name “all” or IP Address range –
“0.0.0.0/0”
• Restrict superuser access
• Allow superuser to make connections only from the localhost/unix domain
• Avoid using “trust” authentication
• Effectively use “reject”
• reject the connections from blacklist/exception IP addresses/users
Secure the access
10
pgDayAsia2016,Singapore
• Use different users for different purpose
• A separate user for owning application database and schema
• Use a different user for making DB connection from application
• Allow DBAs to use their personal users (e.g. DBA Sameer uses a
user “sameer”)
• Use a different (non-superuser) user for physical backup and
replication
• Allow replication connection using specific user from specific hosts
• Use a different user for logical backup
Separating users as per their role
11
pgDayAsia2016,Singapore
• Password hacks are vulnerable to
• Weak passwords
• Re-use of old passwords
• Brute-force password attack
• These attacks can be avoided by
• Maintaining strong passwords or enforcing password policy
• Enforce password expiry and reuse policy
• Enforce account lock policy on consecutive authentication failures
• These can be enforced with external authentication methods e.g. LDAP,
PAM etc
Avoid Password Hacks
12
pgDayAsia2016,Singapore
• Control the number connections
• max_connection
• superuser_reserved_slots
• max_replication_slots
• max_wal_senders
• Don’t use a superuser as an application user
• For multi-user/multi-DB server set DB or user level limit
• Set temp_file_limit to control the disk usage per session for sorting
• Log long running queries
• Monitor transactions and sessions
• long running transactions
• sessions with “idle in transaction state”
• Use connection timeout
Avoid Denial of Service Attack – Set limits
13
pgDayAsia2016,Singapore
• Set per statement/sessions parameters wisely
• work_mem
• maintenance_work_mem
• temp_buffers
• max_prepared_transactions
• Some of these parameters can be set at user, db or session level
• Set them at appropriate granularity
Avoid Denial of Service Attack – Parameter
granularity
14
pgDayAsia2016,Singapore
• Typically network attacks
• Eavesdropping
• Protection against Man-in-the-middle
• Impersonation
• Postgres clients send query in plain-text format
• Data is sent is not encrypted
• Use SSL connection to encrypt client/server communication
• sslmode – prefer is not secure
• sslmode – require – data is encrypted but still exposed to impersonation and
Man-in-the-middle
• Use sslmode verify-ca or verify-full in client connection to avoid all THREE
• SSL usage must be configured on both client and sever
Avoid Network Spoofing
15
pgDayAsia2016,Singapore
• Control which users have access to what
• Use GRANT and REVOKE to control access to
• DATABASE
• TABLESPACE
• SCHEMA
• OBJECTS
• Use row level security to restrict access to specific rows for specific
users
Access Control
16
pgDayAsia2016,Singapore
• Use pg_crypto or application API for encryption/decryption
• Encrypt personal and profile data e.g. Credit Card information
• Key Maintenance
• Use an intermediate key store
• Use a hardware for key/token generation on client end
• Hash the sensitive data e.g. password, pin etc
• Matches are always done using hash of input criteria
• Use disk level or file system level encryption
Securing Data
17
pgDayAsia2016,Singapore
• Enable logging and auditing to ensure all events are logged
• logging_collector must be on
• log_destination
• log_directory
• Avoid overwriting log files
• Set log_truncate_on_rotation to off
• PostgreSQL does not have separate Audit handlers
• pg_audit
• EDB Audit
Logging and Auditing – Avoid pitfalls
18
pgDayAsia2016,Singapore
• Log important events
• Connections and Disconnections, Long running operations, Replication
commands
• Log Resource usages
• Checkpoints, Temp Files
• Control information being logged
• Statements, Hostname, Application Name
• log_line_prefix – Application Name, Hostname, DB Name, User Name etc
• PostgreSQL does not have separate Audit handlers
• pg_audit
• EDB Audit
• Triggers and Event Triggers
Logging and Auditing – Log to Track
19
pgDayAsia2016,Singapore
Avoid Vulnerabilities – Timely Patching
• Keep a tab on latest vulnerabilities announced by various
organizations
• Ensure that your whole stack is timely patched
• A bug or security vulnerability in OS or one of the libraries can lead
to a leak in DB as well
• Ensure you apply OS and library patches
• Ensure you apply patches released by Postgres community/your
vendor
20
pgDayAsia2016,Singapore
- Achieving PCI Compliance with PostgreSQL
- IBM Developer Work Article on Total Security in PostgreSQL
- Bruce Momjian’s PPT
- PostgreSQL Hardening – By OpenSGC
Further Resources
21
Twitter - @sameerkasi200x | @ashnikbiz
Email - sameer.kumar@ashnik.com | success@ashnik.com
LinkedIn - https://www.linkedin.com/in/samkumar150288
We are hiring!

More Related Content

What's hot (20)

PDF
mysql 8.0 architecture and enhancement
lalit choudhary
 
PDF
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
PDF
Backup and-recovery2
Command Prompt., Inc
 
PDF
Redo log improvements MYSQL 8.0
Mydbops
 
PDF
Automated master failover
Yoshinori Matsunobu
 
PDF
PostgreSQL : Introduction
Open Source School
 
PDF
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
PPTX
Liquibase
Sergii Fesenko
 
PDF
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
PDF
Get to know PostgreSQL!
Oddbjørn Steffensen
 
PDF
MariaDB 10: The Complete Tutorial
Colin Charles
 
PDF
AWS 환경에서 MySQL BMT
I Goo Lee
 
PPTX
Database versioning with liquibase
Return on Intelligence
 
PPTX
MySQL Slow Query log Monitoring using Beats & ELK
YoungHeon (Roy) Kim
 
PDF
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
PDF
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PDF
PostgreSQL Deep Internal
EXEM
 
PDF
Using all of the high availability options in MariaDB
MariaDB plc
 
PDF
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
Altinity Ltd
 
PDF
Percona xtrabackup - MySQL Meetup @ Mumbai
Nilnandan Joshi
 
mysql 8.0 architecture and enhancement
lalit choudhary
 
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
Backup and-recovery2
Command Prompt., Inc
 
Redo log improvements MYSQL 8.0
Mydbops
 
Automated master failover
Yoshinori Matsunobu
 
PostgreSQL : Introduction
Open Source School
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
Liquibase
Sergii Fesenko
 
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
Get to know PostgreSQL!
Oddbjørn Steffensen
 
MariaDB 10: The Complete Tutorial
Colin Charles
 
AWS 환경에서 MySQL BMT
I Goo Lee
 
Database versioning with liquibase
Return on Intelligence
 
MySQL Slow Query log Monitoring using Beats & ELK
YoungHeon (Roy) Kim
 
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PostgreSQL Deep Internal
EXEM
 
Using all of the high availability options in MariaDB
MariaDB plc
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
Altinity Ltd
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Nilnandan Joshi
 

Viewers also liked (9)

PDF
Researching postgresql
Fernando Ike
 
PDF
PostgreSQL Conference: West 08
Joshua Drake
 
PDF
5 Tips to Simplify the Management of Your Postgres Database
EDB
 
PPTX
Enterprise grade deployment and security with PostgreSQL
Himanchali -
 
PDF
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
Mark Wong
 
PDF
24/7 Monitoring and Alerting of PostgreSQL
InMobi Technology
 
PDF
Pitr Made Easy
Joshua Drake
 
PDF
Managing Postgres with Ansible
Gulcin Yildirim Jelinek
 
PPTX
PGDay India 2016
Himanchali -
 
Researching postgresql
Fernando Ike
 
PostgreSQL Conference: West 08
Joshua Drake
 
5 Tips to Simplify the Management of Your Postgres Database
EDB
 
Enterprise grade deployment and security with PostgreSQL
Himanchali -
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
Mark Wong
 
24/7 Monitoring and Alerting of PostgreSQL
InMobi Technology
 
Pitr Made Easy
Joshua Drake
 
Managing Postgres with Ansible
Gulcin Yildirim Jelinek
 
PGDay India 2016
Himanchali -
 
Ad

Similar to Security Best Practices for your Postgres Deployment (20)

PDF
Best Practices in Security with PostgreSQL
EDB
 
PPTX
Best Practices in Security with PostgreSQL
EDB
 
PDF
Best Practices in Security with PostgreSQL
EDB
 
PPTX
Creating a Multi-Layered Secured Postgres Database
EDB
 
PDF
Kangaroot EDB Webinar Best Practices in Security with PostgreSQL
Kangaroot
 
PPTX
PostgreSQL Security. How Do We Think?
Ohyama Masanori
 
PPTX
Enterprise-class security with PostgreSQL - 1
Ashnikbiz
 
PPTX
Protecting PII & AI Workloads in PostgreSQL
Dev Raj Gautam
 
PPTX
Postgresql
NexThoughts Technologies
 
PDF
Achieving Pci Compliace
Denish Patel
 
PPTX
Postgre sql best_practices
Jacques Kostic
 
PPTX
Postgre sql best_practices
Emiliano Fusaglia
 
PPTX
TechEvent PostgreSQL Best Practices
Trivadis
 
PDF
PostgreSQL Security. How Do We Think? at PGCon 2017
Ohyama Masanori
 
ODP
Postgre sql unleashed
Marian Marinov
 
PDF
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PDF
Securing PostgreSQL from External Attack
All Things Open
 
PDF
PG Day'14 Russia, Secure PostgreSQL Deployment, Magnus Hagander
pgdayrussia
 
PDF
Safety LAMP: data security & agile languages
PostgreSQL Experts, Inc.
 
PPTX
How to Monitor Postgres Like a Pro!
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Creating a Multi-Layered Secured Postgres Database
EDB
 
Kangaroot EDB Webinar Best Practices in Security with PostgreSQL
Kangaroot
 
PostgreSQL Security. How Do We Think?
Ohyama Masanori
 
Enterprise-class security with PostgreSQL - 1
Ashnikbiz
 
Protecting PII & AI Workloads in PostgreSQL
Dev Raj Gautam
 
Achieving Pci Compliace
Denish Patel
 
Postgre sql best_practices
Jacques Kostic
 
Postgre sql best_practices
Emiliano Fusaglia
 
TechEvent PostgreSQL Best Practices
Trivadis
 
PostgreSQL Security. How Do We Think? at PGCon 2017
Ohyama Masanori
 
Postgre sql unleashed
Marian Marinov
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
Securing PostgreSQL from External Attack
All Things Open
 
PG Day'14 Russia, Secure PostgreSQL Deployment, Magnus Hagander
pgdayrussia
 
Safety LAMP: data security & agile languages
PostgreSQL Experts, Inc.
 
How to Monitor Postgres Like a Pro!
EDB
 
Ad

More from PGConf APAC (20)

PDF
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PDF
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PDF
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PDF
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PDF
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PDF
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PDF
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PDF
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PDF
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
PDF
Amazon (AWS) Aurora
PGConf APAC
 
PDF
Use Case: PostGIS and Agribotics
PGConf APAC
 
PDF
How to teach an elephant to rock'n'roll
PGConf APAC
 
PDF
PostgreSQL on Amazon RDS
PGConf APAC
 
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
Amazon (AWS) Aurora
PGConf APAC
 
Use Case: PostGIS and Agribotics
PGConf APAC
 
How to teach an elephant to rock'n'roll
PGConf APAC
 
PostgreSQL on Amazon RDS
PGConf APAC
 

Recently uploaded (20)

PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 

Security Best Practices for your Postgres Deployment

  • 1. Security Best Practices for your Postgres Deployment Presented by Sameer Kumar, DB Solution Architect, Ashnik “By default PostgreSQL is Possibly the most security – aware database available…” - Database Hacker’s Handbook
  • 2. pgDayAsia2016,Singapore • Security Model • Security Features in Postgres • Securing the access • Avoiding common attacks • Access Control and Securing data • Logging and Auditing • Patching – OS and PostgreSQL Agenda 2
  • 3. pgDayAsia2016,Singapore • A random Oracle-DB2 DBA who started working on PostgreSQL • And found it absolutely great • Works for Ashnik Pte Ltd – Open Source Solutions and consulting • Who also works on noSQL databases • Hobbies – Cycling and Photography 3 About Me
  • 5. pgDayAsia2016,Singapore Secure access is a two step process: • Authentication • Ensures a user is who he/she claims to be • Authorization • Ensures an authenticated user has access to only the data for which he/she has been granted the appropriate privileges. Security Model: Authentication and Authorization 5
  • 6. pgDayAsia2016,Singapore • Object level privileges assigned to roles and users • Virtual Private Database- Row level security • Kerberos and LDAP authentication • Host base authentication • SSL communication • Data Level Encryption (AES, 3DES, etc) • Ability to utilize 3rd party Key Stores in a full PKI Infrastructure • Foundation for full compliance with the strictest of security standards (PCI Data Security Standard) • Flexible field level encryption and row level security High Level Features 6
  • 7. pgDayAsia2016,Singapore • Kerberos : Kerberos based encrypted "ticket" for authentication • Password : md5 and plain text • LDAP authentication : It uses LDAP as the password verification method • Trust : Authentication without password or Auth token • RADIUS: Use radius server for authentication Different Authentication Methods 7
  • 9. pgDayAsia2016,Singapore • Override the default port of Postgres • Use a non-default name for the superuser • Can be specified during “initdb” • While initializing the cluster with “initdb” use -A to specify authentication mode • By default each new DB has connect privilege granted to public • revoke connect on my_new_db from public; • grant connect on my_new_db to my_app_user; Override the defaults 9
  • 10. pgDayAsia2016,Singapore • Use listen_addresses to control where you Database is listening for connections • Make sure that you don’t listen on public network interface • Control who can connect from where • Use pg_hba.conf to control which user can connect to specific databases from specific IP addresses • Avoid using general rules e.g. Database name “all” or IP Address range – “0.0.0.0/0” • Restrict superuser access • Allow superuser to make connections only from the localhost/unix domain • Avoid using “trust” authentication • Effectively use “reject” • reject the connections from blacklist/exception IP addresses/users Secure the access 10
  • 11. pgDayAsia2016,Singapore • Use different users for different purpose • A separate user for owning application database and schema • Use a different user for making DB connection from application • Allow DBAs to use their personal users (e.g. DBA Sameer uses a user “sameer”) • Use a different (non-superuser) user for physical backup and replication • Allow replication connection using specific user from specific hosts • Use a different user for logical backup Separating users as per their role 11
  • 12. pgDayAsia2016,Singapore • Password hacks are vulnerable to • Weak passwords • Re-use of old passwords • Brute-force password attack • These attacks can be avoided by • Maintaining strong passwords or enforcing password policy • Enforce password expiry and reuse policy • Enforce account lock policy on consecutive authentication failures • These can be enforced with external authentication methods e.g. LDAP, PAM etc Avoid Password Hacks 12
  • 13. pgDayAsia2016,Singapore • Control the number connections • max_connection • superuser_reserved_slots • max_replication_slots • max_wal_senders • Don’t use a superuser as an application user • For multi-user/multi-DB server set DB or user level limit • Set temp_file_limit to control the disk usage per session for sorting • Log long running queries • Monitor transactions and sessions • long running transactions • sessions with “idle in transaction state” • Use connection timeout Avoid Denial of Service Attack – Set limits 13
  • 14. pgDayAsia2016,Singapore • Set per statement/sessions parameters wisely • work_mem • maintenance_work_mem • temp_buffers • max_prepared_transactions • Some of these parameters can be set at user, db or session level • Set them at appropriate granularity Avoid Denial of Service Attack – Parameter granularity 14
  • 15. pgDayAsia2016,Singapore • Typically network attacks • Eavesdropping • Protection against Man-in-the-middle • Impersonation • Postgres clients send query in plain-text format • Data is sent is not encrypted • Use SSL connection to encrypt client/server communication • sslmode – prefer is not secure • sslmode – require – data is encrypted but still exposed to impersonation and Man-in-the-middle • Use sslmode verify-ca or verify-full in client connection to avoid all THREE • SSL usage must be configured on both client and sever Avoid Network Spoofing 15
  • 16. pgDayAsia2016,Singapore • Control which users have access to what • Use GRANT and REVOKE to control access to • DATABASE • TABLESPACE • SCHEMA • OBJECTS • Use row level security to restrict access to specific rows for specific users Access Control 16
  • 17. pgDayAsia2016,Singapore • Use pg_crypto or application API for encryption/decryption • Encrypt personal and profile data e.g. Credit Card information • Key Maintenance • Use an intermediate key store • Use a hardware for key/token generation on client end • Hash the sensitive data e.g. password, pin etc • Matches are always done using hash of input criteria • Use disk level or file system level encryption Securing Data 17
  • 18. pgDayAsia2016,Singapore • Enable logging and auditing to ensure all events are logged • logging_collector must be on • log_destination • log_directory • Avoid overwriting log files • Set log_truncate_on_rotation to off • PostgreSQL does not have separate Audit handlers • pg_audit • EDB Audit Logging and Auditing – Avoid pitfalls 18
  • 19. pgDayAsia2016,Singapore • Log important events • Connections and Disconnections, Long running operations, Replication commands • Log Resource usages • Checkpoints, Temp Files • Control information being logged • Statements, Hostname, Application Name • log_line_prefix – Application Name, Hostname, DB Name, User Name etc • PostgreSQL does not have separate Audit handlers • pg_audit • EDB Audit • Triggers and Event Triggers Logging and Auditing – Log to Track 19
  • 20. pgDayAsia2016,Singapore Avoid Vulnerabilities – Timely Patching • Keep a tab on latest vulnerabilities announced by various organizations • Ensure that your whole stack is timely patched • A bug or security vulnerability in OS or one of the libraries can lead to a leak in DB as well • Ensure you apply OS and library patches • Ensure you apply patches released by Postgres community/your vendor 20
  • 21. pgDayAsia2016,Singapore - Achieving PCI Compliance with PostgreSQL - IBM Developer Work Article on Total Security in PostgreSQL - Bruce Momjian’s PPT - PostgreSQL Hardening – By OpenSGC Further Resources 21
  • 22. Twitter - @sameerkasi200x | @ashnikbiz Email - [email protected] | [email protected] LinkedIn - https://www.linkedin.com/in/samkumar150288 We are hiring!