secure postgresql deployment

42
Secure PostgreSQL Deployments JDCon-East 2010 Philadelphia, PA Magnus Hagander Redpill Linpro AB

Upload: command-prompt-inc

Post on 19-May-2015

1.852 views

Category:

Documents


4 download

DESCRIPTION

Magnus HaganderPostgreSQL supports several options for securing communications when deployed outside the typical webserver/database combination. This talk will go into some details about the features that make this possible, with some extra focus on the changes in 8.4. The main areas discussed are:* Securing the channel between client and server using SSL, including an overview of the threats and how to secure against them* Securing the login process, using LDAP, Kerberos or SSL certificates, including the use of smartcards to log into the databaseThe talk will not focus on security and access control inside the database once the user is connected and authenticated.

TRANSCRIPT

Page 1: Secure PostgreSQL deployment

Secure PostgreSQL Deployments

JDCon-East 2010Philadelphia, PA

Magnus HaganderRedpill Linpro AB

Page 2: Secure PostgreSQL deployment

There's much to security● Identify the threats● Apply the correct measures

– Don't do things just because you can

Page 3: Secure PostgreSQL deployment

Not in this talk● Application security● Data Access Control● Data Encryption● etc● etc

Page 4: Secure PostgreSQL deployment

Definitely not in this talk● Unix vs Windows● Linux vs BSD● SELinux/SEPostgreSQL● Any other religion

Page 5: Secure PostgreSQL deployment

In this talk!● Authentication methods● Connection security

Page 6: Secure PostgreSQL deployment

Authentication methods● How do we determine who the

user is● When do we determine who the

user is

Page 7: Secure PostgreSQL deployment

pg_hba.conf● Lets you use different auth

methods from different clients● Not just limited to

username/password● For convenience or security● Internal or external

Page 8: Secure PostgreSQL deployment

pg_hba.conf

local all all trusthost all all 127.0.0.1/32 trusthost webdb webuser 10.0.0.0/24 md5host all @dba 192.168.0.0/24 gss

Page 9: Secure PostgreSQL deployment

Trust Authentication● Any user can be anyone he/she

claims to be!

Page 10: Secure PostgreSQL deployment

Trust Authentication● Any user can be anyone he/she

claims to be!● Anyone think this is a bad idea?

Page 11: Secure PostgreSQL deployment

Username/password● Normally, use md5 method

– crypt has been removed, avoid plaintext

● What everybody does● What everybody expects

Page 12: Secure PostgreSQL deployment

LDAP authentication● To the client, username/password● Backend verification is off-loaded

to directory server● Common in enterprise

deployments● Password policies, expiry, etc

Page 13: Secure PostgreSQL deployment

LDAP authentication● Single password not single signon

Client

PostgreSQLServer

LDAPServer

1. Connect

3. Send password2. Request password

Page 14: Secure PostgreSQL deployment

LDAP news in 9.0● search/bind combination● Can use non-cn fields in login

– Anything that's LDAP searchable– Common choice: uid

Page 15: Secure PostgreSQL deployment

RADIUS (new in 9.0)● Remote Authentication Dial In User

Service● Simple single-packet UDP service● Original use-case: ISP dialup● Common for one-time passwords, etc● Good policy frameworks

Page 16: Secure PostgreSQL deployment

Kerberos/GSSAPI/SSPI● Single signon● Same benefits as LDAP (mostly)● Most common: Active Directory

● («krb5» is deprecated)

Page 17: Secure PostgreSQL deployment

Kerberos/GSSAPI/SSPI● Single password not single signon

Client

PostgreSQLServer

KDC

1. Request ticket2. Return ticket

3. Present ticket

Page 18: Secure PostgreSQL deployment

PAM● Provided by OS● Can do password, LDAP, etc● Can also do Kerberos & friends● One-time passwords

– RSA SecurID, Vasco, etc– RADIUS (no need in 9.0)

Page 19: Secure PostgreSQL deployment

SSL

Page 20: Secure PostgreSQL deployment

SSL secured connections● Encryption● Man-in-the-middle protection● Authentication

Page 21: Secure PostgreSQL deployment

SSL secured connections● Enabled on the server (ssl=yes)

– Platform quirks!

● Optionally required through pg_hba

● Optionally required in libpq

Page 22: Secure PostgreSQL deployment

SSL secured connections● Need to protect data in both

directions● For example username/password● Must know before connection is

started– Unknown equals unprotected

Page 23: Secure PostgreSQL deployment

SSL encryption● SSL always requires a server

certificate● Can be self-signed● Does not need to be known by

client

Page 24: Secure PostgreSQL deployment

Certificate chains

Issuer

Issuer

Issuer Root certificate

Intermediate certificate

Server certificate

Page 25: Secure PostgreSQL deployment

Certificate chains

Issuer

Issuer

Issuer Root certificate

Intermediate certificate

Server certificate

Self-signedcertificate

Page 26: Secure PostgreSQL deployment

SSL secured connections

Client Server

Page 27: Secure PostgreSQL deployment

Threats handled by SSL: Eavesdropping

Client Server

SELECT * FROM secret_stuff

Page 28: Secure PostgreSQL deployment

Eavesdropping● Prevented by encrypting all data● Key negotiation is automatic

– On initial connection– After 512Mb traffic

● Server certificate used but not verified

Page 29: Secure PostgreSQL deployment

Key renegotiation● Broken in the SSL protocol –

OOPS!● Fixed SSL libraries are available● Broken fixes were pushed by

vendors● ssl_renegotiation_limit = 512MB

Page 30: Secure PostgreSQL deployment

Threats handled by SSL:Man in the middle

Client Server

Fake server

Valid SSL session Valid SSL session

Page 31: Secure PostgreSQL deployment

SSL server verification● On top of encryption● Validate that the server is who it

claims to be● CA issues certificate, can be self-

signed● CA certificate known by client

Page 32: Secure PostgreSQL deployment

Threats handled by SSL:Man in the middle

Client Server

Fake server

Valid SSL session

Page 33: Secure PostgreSQL deployment

SSL client authentication● On top of encryption● Normally on top of server

verificateion, but not necessary● CA issued certificate on client● Match CN on certificate to user id● Protect client certificate!

Page 34: Secure PostgreSQL deployment

SSL client authentication

Client

PostgreSQLServer

1. Present certificate

Page 35: Secure PostgreSQL deployment

SSL client certificates● Can also be used together with

other authentication● Require client certificate● Also require e.g.

username/password

Page 36: Secure PostgreSQL deployment

SSL in libpq● Controlled by sslmode parameter● Or environment PGSSLMODE● For security, must be set on client

– Remember, unknown = unsecure

Page 37: Secure PostgreSQL deployment

Summary of libpq SSL modes

Protect against Compatible with server set to...

Performance

Client Mode

Eavesdrop MITM SSL required SSL disabled overhead

disable no no FAIL works no

allow no no works works If necessary

prefer no no works works If possible

require yes no works FAIL yes

verify-ca yes yes works FAIL yes

verify-full yes yes works FAIL yes

Page 38: Secure PostgreSQL deployment

Summary of libpq SSL modes

Protect against Compatible with server set to...

Performance

Client Mode

Eavesdrop MITM SSL required SSL disabled overhead

disable no no FAIL works no

allow no no works works If necessary

prefer no no works works If possible

require yes no works FAIL yes

verify-ca yes yes works FAIL yes

verify-full yes yes works FAIL yes

Page 39: Secure PostgreSQL deployment

Summary of libpq SSL modes

Protect against Compatible with server set to...

Performance

Client Mode

Eavesdrop MITM SSL required SSL disabled overhead

disable no no FAIL works no

allow no no works works If necessary

prefer no no works works If possible

require yes no works FAIL yes

verify-ca yes yes works FAIL yes

verify-full yes yes works FAIL yes

Page 40: Secure PostgreSQL deployment

Summary of libpq SSL modes

Protect against Compatible with server set to...

Performance

Client Mode

Eavesdrop MITM SSL required SSL disabled overhead

disable no no FAIL works no

allow no no works works If necessary

prefer no no works works If possible

require yes no works FAIL yes

verify-ca yes yes works FAIL yes

verify-full yes yes works FAIL yes

Page 41: Secure PostgreSQL deployment

Not a bad idea: ipsec● If already deployed● Application transparent● Global policies● Integrated management● Somebody Elses Problem?

Page 42: Secure PostgreSQL deployment

Secure PostgreSQL Deployments

Questions?

[email protected]: @magnushagander

http://blog.hagander.net