A PostgreSQL Security Primer



Similar documents
Secure PostgreSQL Deployments

Deploying PostgreSQL in a Windows Enterprise

Encrypted PostgreSQL

Domino and Internet. Security. IBM Collaboration Solutions. Ask the Experts 12/16/2014

This chapter describes how to set up and manage VPN service in Mac OS X Server.

Certificate technology on Pulse Secure Access

Greenplum Database. Security Configuration Guide. Rev: A01

CA Performance Center

RemotelyAnywhere. Security Considerations

Managing rights in PostgreSQL

Certificate technology on Junos Pulse Secure Access

Apache Security with SSL Using Linux

CHAPTER 7 SSL CONFIGURATION AND TESTING

Configuring Sponsor Authentication

Securing PostgreSQL From External Attack

User Authentication. FortiOS Handbook v3 for FortiOS 4.0 MR3

Certificate Management. PAN-OS Administrator s Guide. Version 7.0

SSL Tunnels. Introduction

EventTracker Windows syslog User Guide

External Authentication with Juniper SSL VPN appliance Authenticating Users Using SecurAccess Server by SecurEnvoy

External Authentication with Windows 2003 Server with Routing and Remote Access service Authenticating Users Using SecurAccess Server by SecurEnvoy

Chapter 7 Managing Users, Authentication, and Certificates

Apache, SSL and Digital Signatures Using FreeBSD

How to generate SSL certificates for use with a KVM box & XViewer with XCA v0.9.3

7.1. Remote Access Connection

ipad or iphone with Junos Pulse and Juniper SSL VPN appliance Authenticating Users Using SecurAccess Server by SecurEnvoy

How to Configure Captive Portal

App Orchestration 2.0

Secure Messaging Server Console... 2

Apache Security with SSL Using Ubuntu

Kenna Platform Security. A technical overview of the comprehensive security measures Kenna uses to protect your data

App Orchestration 2.5

What s New in MySQL 5.7 Security Georgi Joro Kodinov Team Lead MySQL Server General Team

Configuring Multiple ACE Management Servers VMware ACE 2.0

User Identification (User-ID) Tips and Best Practices

Implementing Secure Sockets Layer on iseries

FortiOS Handbook - Authentication VERSION 5.2.6

External Authentication with Cisco VPN 3000 Concentrator Authenticating Users Using SecurAccess Server by SecurEnvoy

MassTransit 6.0 Enterprise Web Configuration for Macintosh OS 10.5 Server

Unifying Information Security. Implementing TLS on the CLEARSWIFT SECURE Gateway

Borderware Firewall Server Version 7.1. VPN Authentication Configuration Guide. Copyright 2005 CRYPTOCard Corporation All Rights Reserved

Security IIS Service Lesson 6

Implementing and Administering Security in a Microsoft Windows Server 2003 Network

Dlink DFL 800/1600 series: Using the built-in MS L2TP/IPSEC VPN client with certificates

Configuration Guide BES12. Version 12.3

The PCI Compliant Database. Christophe Pettus PostgreSQL Experts, Inc. PGConf Silicon Valley 2015

Network-Enabled Devices, AOS v.5.x.x. Content and Purpose of This Guide...1 User Management...2 Types of user accounts2

Fireware How To Authentication

3. Broken Account and Session Management. 4. Cross-Site Scripting (XSS) Flaws. Web browsers execute code sent from websites. Account Management

Using Network Attached Storage with Linux. by Andy Pepperdine

Funkwerk UTM Release Notes (english)

Advanced Administration

CONTENTS. PCI DSS Compliance Guide

FINAL DoIT v.8 APPLICATION SECURITY PROCEDURE

MongoDB Security Guide

Centralized Oracle Database Authentication and Authorization in a Directory

Centrify Cloud Connector Deployment Guide

Configuring User Identification via Active Directory

Embedded Web Server Security

SECUR IN MIRTH CONNECT. Best Practices and Vulnerabilities of Mirth Connect. Author: Jeff Campbell Technical Consultant, Galen Healthcare Solutions

WebLogic Server 6.1: How to configure SSL for PeopleSoft Application

Authentication Types. Password-based Authentication. Off-Line Password Guessing

Configuring Digital Certificates

How To Integrate Watchguard Xtm With Secur Access With Watchguard And Safepower 2Factor Authentication On A Watchguard 2T (V2) On A 2Tv 2Tm (V1.2) With A 2F

Architecture and Data Flow Overview. BlackBerry Enterprise Service Version: Quick Reference

Configuration Guide BES12. Version 12.2

The following process allows you to configure exacqvision permissions and privileges for accounts that exist on an Active Directory server:

Unlocking & Locking Big Data: Defending the DataLake

Citrix Receiver for Mobile Devices Troubleshooting Guide

TechNote. Contents. Overview. Using a Windows Enterprise Root CA with DPI-SSL. Network Security

CERTIFICATE-BASED SINGLE SIGN-ON FOR EMC MY DOCUMENTUM FOR MICROSOFT OUTLOOK USING CA SITEMINDER

Enabling SSO between Cognos 8 and WebSphere Portal

How To Enable A Websphere To Communicate With Ssl On An Ipad From Aaya One X Portal On A Pc Or Macbook Or Ipad (For Acedo) On A Network With A Password Protected (

Setting Up SSL on IIS6 for MEGA Advisor

Implementing and Managing Security for Network Communications

NETASQ ACTIVE DIRECTORY INTEGRATION

Smart Card Authentication Client. Administrator's Guide

KMIP installation Guide. DataSecure and KeySecure Version SafeNet, Inc

Configuring Secure Socket Layer and Client-Certificate Authentication on SAS 9.3 Enterprise BI Server Systems That Use Oracle WebLogic 10.

MySQL Security: Best Practices

SECURE FTP CONFIGURATION SETUP GUIDE

2.4: Authentication Authentication types Authentication schemes: RSA, Lamport s Hash Mutual Authentication Session Keys Trusted Intermediaries

A brief on Two-Factor Authentication

Use Enterprise SSO as the Credential Server for Protected Sites

This chapter describes how to use the Junos Pulse Secure Access Service in a SAML single sign-on deployment. It includes the following sections:

DIGIPASS KEY series and smart card series for Juniper SSL VPN Authentication

How to setup and use XViewer & XImpcert

External authentication with Astaro AG Astaro Security Gateway UTM appliances Authenticating Users Using SecurAccess Server by SecurEnvoy

Configuration Guide BES12. Version 12.1

Authentication Methods

PowerChute TM Network Shutdown Security Features & Deployment

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

Decryption. Palo Alto Networks. PAN-OS Administrator s Guide Version 6.0. Copyright Palo Alto Networks

External authentication with Fortinet Fortigate UTM appliances Authenticating Users Using SecurAccess Server by SecurEnvoy

Enabling Single-Sign-On between IBM Cognos 8 BI and IBM WebSphere Portal

Configuring SSL VPN on the Cisco ISA500 Security Appliance

ShareFile Security Overview

Transcription:

A PostgreSQL Security Primer PGDay'15 Russia St Petersburg, Russia Magnus Hagander magnus@hagander.net PRODUCTS CONSULTING APPLICATION MANAGEMENT IT OPERATIONS SUPPORT TRAINING

Magnus Hagander PostgreSQL Core Team member Committer PostgreSQL Europe Redpill Linpro Infrastructure services Principal database consultant

Security

It's hard Security

Security It's hard No, really!

There is no one solution Security

Security There is no one requirement

Security PostgreSQL provides a toolbox You don't need everything Maybe you don't need anything...

Environment Communication Authentication Application Agenda today

Environment Communication Authentication Application Agenda today

Secure PostgreSQL Environment Only as secure as the environment If someone owns the OS, they own the db Owns the server -> owns the OS Owns the datacenter -> owns the server Defined trust levels! e.g. outsourcing/cloud vendors

Operating system Pick your operating system Something you know Regardless of PostgreSQL Secure "reasonably" No other local users!

Operating system Use standard installers Don't roll your own Usually adapted for OS E.g. SELinux Consistent security!

Operating system Keep updated Both operating system and PostgreSQL yum/apt makes it easier But you have to use it! Monitor! Mind restarts!

Operating system Encrypted disks? Performance/reliability implications Attack vectors? Key management? What happens on restart?

Multi instance Different security domains? Different OS user Sometimes not well packaged Virtualization/containers?

Environment Communication Authentication Application Agenda today

Securing communications Do you need it? Attack vectors? Overhead!

Securing communications (physical) Firewalls VPN ipsec SSL

Firewalls PostgreSQL traffic is simple Single port TCP Block at perimeter Block at host (Does not replace pg_hba!)

VPN Many scenarios Site -> Site Host -> Site Host -> Host Typically ipsec or pptp Combine with firewall!

IPSEC Transport security Individual connections Allows for detailed policies Kernel/system implementation

Connection encryption Individual connections Protocol adapted SSL

SSL in PostgreSQL OpenSSL only (sorry) Abstraction in 9.5 No other implementations yet Certificate/key Like any other service Disabled by default on server Enabled on client!!

SSL in PostgreSQL Negotiated upon connection Same port! First packets of exchange Before authentication etc

Certificates Server certificate mandatory Does not need public ca Probably should not use public ca "Snakeoil" self-signed works But no MITM protection! Use custom (dedicated?) CA!

OpenSSL CA OpenSSL comes with built in CA Or use other CA software Always distribute CA certificate But not the key

Setting up certificate Generate secret and public key Generate certificate request Sign :g:`certificate request Deploy certificate

Generating OpenSSL cert $ openssl req -new -newkey rsa:4096 -text -out server.req General SSL parameters apply Use large enough keys! Always set CN to server name Other attributes ignored

Generating OpenSSL cert OpenSSL always secures key with passphrase Makes auto-start impossible Remove key: $ openssl rsa -in privkey.pem -out server.key $ rm privkey.pem

Generating OpenSSL cert Securely store server.key Transfer server.req to CA Does not have to be secured If you verify fingerprint!

Sign certificate request Use your CA For example, OpenSSL built-in one Or generate self-signed: $ openssl req -x509 -in server.req -text -key server.key -out server.crt Securely transfer server.crt

Distribute CA certificate Each client needs cert to verify CA Not required, but strongly recommended ~/.postgresql/root.crt Also distribute CRL if used ~/.postgresql/root.crl Connection string can override file names

Enable server SSL Set ssl=on server.key/server.crt in data directory Check permissions! Should be 0600, must be 0x00. Restart, done.

CA Certificate on server Required for client certificate auth root.crt CRL not required but recommended root.crl File names controllable in postgresql.conf

SSL negotiation SSL negotiated between client and server Server provides Client decides Controlled by sslmode parameter

SSL negotiation sslmode default is prefer This is stupid... No guarantees Don't use!

SSL negotiation

SSL enforcement Client decides??!!?!?! Huh?? Client decides, but server can reject Using hostssl in pg_hba.conf

SSL enforcement.. hostssl xxx yyy..... Always use!

Client certificates Not required by default Can be requested by server clientcert=1 in pg_hba.conf.. hostssl xxx yyy zzz abc clientcert=1..

Client certificates Provide in PEM format file Or through OpenSSL compatible engine Validated against root CA on server PostgreSQL specific root By default just needs to exist

Client certificate authentication Use for full login Username extracted from CN attribute Must chain to known trusted CA Can map using pg_ident.conf

Environment Communication Authentication Application Agenda today

Authentication Make sure it's the correct user And that they can prove it

Authentication PostgreSQL supports many methods Host Based Authentication Combined in the same installation! Don't just "dumb down"

pg_hba.conf Top-bottom file Filter by: Connection type User Database Connection source "Firewall" and authentication choice

pg_hba.conf Order by most specific: local all all peer host all all 127.0.0.1/32 md5 hostnossl webdb webuser 10.1.1.0/30 md5 hostssl all +admin 192.168.0.0/24 gss Implicit reject at end

Authentication methods Many choices Internal OS integrated Fully external And some really bad ones...

trust Trust everybody everywhere Why would anybody claim they're someone else? "Turn off all security" Any use case? Maybe one...

Use it? Change it! trust

peer Only over Unix sockets Sorry Windows, sorry Java Local connections only Asks OS kernel Trustworthy!

Simplest one? Username/password Double MD5-hash Do not use "password" md5

ldap Looks like password to client Regular prompt Passed over to LDAP server No special support needed Construct URLs different ways Prefix+suffix Search+bind

ldap Suffix and prefix ldapprefix="cn=" ldapsuffix=", DC=domain, DC=com" Binds to CN=mha, DC=domain, DC=com

ldap Double binding ldapbasedn="dc=domain, DC=com" ldappbinddn="cn=postgres, DC=domain, DC=com" ldapbindpasswd="supersecret" ldapsearchattribute="uid"

ldap Double binding URL syntax ldapurl="ldap://1.2.3.4/dc=domain, dc=com?uid?sub" ldappbinddn="cn=postgres, DC=domain, DC=com" ldapbindpasswd="supersecret"

ldap Cleartext! Use with ldaptls=1 Use with hostssl Password policies from LDAP server Only authentication!

gss Kerberos based GSSAPI Including Active Directory Single Sign-On No password prompt! All Kerberos supported auth methods Secure tickets "krb5" deprecated/removed

gss Uses kerberos keytabs Uses principals and realms Similar to users and domains Mutual authentication Default service principal postgres/server.domain.com Case sensitive!

gss Install keytab Readable by PostgreSQL Can be specific for PostgreSQL or shared Any principal will be accepted But must match client!

gss Client principals user@domain.com Matched with or without realms Recommendation is to always include Strip with pg_ident.conf

gss gss include_realm=1 map=gss can also restrict realms gss include_realm=1 krb_realm=domain.com

radius Looks like password to client Use with hostssl! Shared-secret encryption to Radius server Common for OTP solutions

radius radiusserver=1.2.3.4 radiussecret=supersecret

cert Map client certificate to login Uses CN attribute Any certificate "engine" supported by OpenSSL Normally uses PEM encoded files

cert Server must have CA certificate And CRL if used Client must have CA certificate And CRL if used

User name mapping External systems with different usernames Peer gss/sspi cert Allow static or pattern mapping

User name mapping pg_hba.conf: local all all peer map=local hostssl all all 10.0.0/24 gss map=gss includerealm=1 hostssl all all 0.0.0.0/0 cert map=cert

User name mapping pg_ident.conf: local root postgres.. gss /^(.*)@DOMAIN.COM$/ \1.. cert /^cn=(.*)$/ \1

Environment Communication Authentication Application Summary Agenda today

Application security Huge topic Let's stick to a few tips... And an example or two

Superuser Never use superuser Disables all security Allows arbitrary code execution! Allows replacement of configuration!

Database owner Avoid using database owner Overrides any object permissions But much better than superuser

Schema boundaries Schemas for compartmentalization USAGE required to access all objects Object permissions required as well Sub-divide access

Password management Specifically considering webapps Lots of data collected today Username Password Email and more

And then what happens? What typically happens?

And then what happens? You get hacked Seems to only be a matter of time So plan for that!

So what do we do? Didn't we already solve this? Passwords are hashed! We've even got extra advanced methods!

People still get hacked Hashed passwords prevent some hacks But "dumping" those still allow offline attacks Leaked email addresses are valuable Valuable makes it a target

So what can we do? We can easily improve on this There is no reason for bulk downloads Your database can help So let's look at a typical webapp

The valuable users table CREATE TABLE users ( userid text, pwdhash text, email text )

The SQL injection attack Lets the attacker do: SELECT * FROM users And they get all data... Hashed passwords for offline attacks Email addresses for sale

Remind you of anything? Haven't we seen this before?

Remind you of anything? Haven't we seen this before? Like pre-1990?

Remind you of anything? Haven't we seen this before? Pre-1990 /etc/passwd

Remind you of anything? Shadow passwords!! Invented a long time ago (1988, SysV 3.2 - Linux 1992) Why are we repeating the mistakes?

Shadow passwords in PG Shadow passwords are based on "views" We have this in PostgreSQL Shadow passwords requires "suid" We have this in PostgreSQL

Shadow passwords in PG The problem: webapp=# SELECT * FROM users; userid pwdhash email --------+------------------------------------------+--------------------- mha $2a$06$1dtSqWdv0hfsbpDRsfZ9eOHlGoLUj... magnus@hagander.net

Shadow passwords in PG webapp=# ALTER TABLE users RENAME TO shadow; ALTER TABLE webapp=# REVOKE ALL ON shadow FROM webuser; REVOKE

Shadow passwords in PG webapp=# CREATE VIEW users AS webapp-# SELECT userid, NULL::text AS pwdhash, NULL::text as email webapp-# FROM shadow; CREATE VIEW webapp=# GRANT SELECT ON users TO webuser; GRANT

Shadow passwords in PG webapp=> SELECT * FROM shadow; ERROR: permission denied for relation shadow webapp=> SELECT * FROM users; userid pwdhash email --------+---------+------- mha

Shadow passwords in PG But now it's useless... No way to log in

Shadow passwords in PG webapp=# CREATE EXTENSION pgcrypto; CREATE EXTENSION

pgcypto password hashing pgcrypto provides crypt() Dual-use function Create password hashes (salted, of course!) Validate password hashes

SECURITY DEFINER Functions with SECURITY DEFINER Acts like setuid binary Powerful access

SECURITY DEFINER CREATE OR REPLACE FUNCTION login(_userid text, _pwd text, OUT _email text) RETURNS text LANGUAGE plpgsql SECURITY DEFINER AS $$ BEGIN SELECT email INTO _email FROM shadow WHERE shadow.userid=lower(_userid) AND pwdhash = crypt(_pwd, shadow.pwdhash); END;$$

SECURITY DEFINER webapp=> SELECT * FROM login('mha', 'foobar'); _email -------- (1 row) webapp=> SELECT * FROM login('mha', 'topsecret'); _email --------------------- magnus@hagander.net

SECURITY DEFINER Beware!! SQL-in-SQL injections Unbounded data access Never use superuser

Environment Communication Authentication Application Summary Agenda today

Security Determine your requirements Determine your trust levels Determine your attack surface Determine your threat vectors

Security Deploy correct countermeasures "Checkbox featuring" is useless Or even counterproductive Lock all doors E.g. why encrypt disks if keys are local? Why require smartcards if data is cleartext?

Layered security A firewall alone doesn't protect you Doesn't mean you shouldn't have one

Too simple to mention Never use trust (not even in testing) Use pg_hba.conf Mix auth methods Restrict IP addresses Go SSL if you have to

Iterative process Re-evaluate Requirements and landscape are dynamic! Stay secure!

Thank you! Magnus Hagander magnus@hagander.net @magnushagander http://www.hagander.net/talks/ This material is licensed CC BY-NC 4.0.