Safety LAMP: data security & agile languages

78
Safety LAMP data security in the age of agile languages Josh Berkus PostgreSQL Experts, Inc. Enterprise LAMP 2009

description

 

Transcript of Safety LAMP: data security & agile languages

Page 1: Safety LAMP: data security & agile languages

Safety LAMP

data securityin the age of

agile languages

Josh BerkusPostgreSQL Experts, Inc.Enterprise LAMP 2009

Page 2: Safety LAMP: data security & agile languages

LAMP 1.0 (1998)

Linux

Apache

MySQL

Perl,PHP,Python

Page 3: Safety LAMP: data security & agile languages

LAMP 1.1 (2002)

Linux

Apache

Middleware

PostgreSQL

Page 4: Safety LAMP: data security & agile languages

LAMP 2.0 (2008)

Linux,Solaris, BSD

Apache,Lighttpd, appservers

MySQL,PostgreSQL, SQLite,CouchDB, Memcached,etc.

Python,Ruby,PHP,Perl, Javascript

Page 5: Safety LAMP: data security & agile languages

LAMP 2.0 (2008)

Linux,Solaris, BSD

Apache,Lighttpd, appservers

MySQL,PostgreSQL, SQLite,CouchDB, Memcached,etc.

Python,Ruby,PHP,Perl, Javascript

Page 6: Safety LAMP: data security & agile languages

Why shouldyoucareabout

data security?

Page 7: Safety LAMP: data security & agile languages

“I don't need to know”

“Our network security will take care of it.”

“I applied all the web server and PHP patches.”

“Security belongs in the application layer.”

“Database security slows development.”

“Nobody will hack my website. We run Linux.”

Page 8: Safety LAMP: data security & agile languages
Page 9: Safety LAMP: data security & agile languages
Page 10: Safety LAMP: data security & agile languages
Page 11: Safety LAMP: data security & agile languages

microsoft

Page 12: Safety LAMP: data security & agile languages

nokia

Page 13: Safety LAMP: data security & agile languages

government agencies

Page 14: Safety LAMP: data security & agile languages

the U.N.

Page 15: Safety LAMP: data security & agile languages

political parties

Page 16: Safety LAMP: data security & agile languages
Page 17: Safety LAMP: data security & agile languages
Page 18: Safety LAMP: data security & agile languages
Page 19: Safety LAMP: data security & agile languages

The cost of unsafe data

Contacting 19,000 customers: $380,000

Paying for credit reports for 19,000 customers: $931,000

Shipping stolen merchandise:$4,600,000

Lost customer goodwill and reputation as an insecure & careless company:Priceless!

Page 20: Safety LAMP: data security & agile languages

Why is LAMP special?

1. AgilityLAMP platforms are designed for rapid development and deployment

2. Constant UpgradesLAMP components are rapidly advancing

3. LightweightLAMP stacks are simple and have few layers

Page 21: Safety LAMP: data security & agile languages

Why is LAMP special?

1. Agilityrapidly deploy security holes

2. Constant Upgradesnew versions � new exploits

3. Lightweightfew layers � fast to hack

Page 22: Safety LAMP: data security & agile languages

How do you make your data safe?

Page 23: Safety LAMP: data security & agile languages

securityprinciples

Page 24: Safety LAMP: data security & agile languages

one:security != control

Page 25: Safety LAMP: data security & agile languages

control systems

Page 26: Safety LAMP: data security & agile languages

control systems correctly employed

improved security

Page 27: Safety LAMP: data security & agile languages

control systemsincorrectly employed

reduced security

Page 28: Safety LAMP: data security & agile languages
Page 29: Safety LAMP: data security & agile languages

two:security

is a process

Page 30: Safety LAMP: data security & agile languages

two:security

is a process

not a result

Page 31: Safety LAMP: data security & agile languages

security process

1.plan

2.design

3.develop

4.test

5.deploy

6.monitor

7.repeat

Page 32: Safety LAMP: data security & agile languages

perimeter-only security

webserver load-balancer

databaseserver

firewall

anti-DOS

openopen

secureinsecure

Page 33: Safety LAMP: data security & agile languages
Page 34: Safety LAMP: data security & agile languages
Page 35: Safety LAMP: data security & agile languages
Page 36: Safety LAMP: data security & agile languages
Page 37: Safety LAMP: data security & agile languages

perimeter-only security

webserver load-balancer

databaseserver

firewall

anti-DOS

openopen

secureinsecure

Page 38: Safety LAMP: data security & agile languages

perimeter-only security

webserver load-balancer

databaseserver

firewall

anti-DOS

openopen

secureinsecure

Page 39: Safety LAMP: data security & agile languages
Page 40: Safety LAMP: data security & agile languages
Page 41: Safety LAMP: data security & agile languages

multilayer security

webserverdatabaseserver

firewall

anti-DOS

restricted

secure

updates

tripwireabstraction

permissions

restrictedauditload-balancer

Page 42: Safety LAMP: data security & agile languages

three:every component

in yourLAMP stack

must be secure

Page 43: Safety LAMP: data security & agile languages

four:how much security

do you need?

Page 44: Safety LAMP: data security & agile languages

Data Security

Cost

Deployment Speed

Performance

Page 45: Safety LAMP: data security & agile languages

five:have a threat model

What is your vulnerable data? (assets)

Who wants this data? (threats) How will they get it? (attack vectors)

What are the consequences of lost data? (costs)

Page 46: Safety LAMP: data security & agile languages

How do you make your data safe?

Page 47: Safety LAMP: data security & agile languages

your database engine can help

webserver routerdatabaseserver

firewall

anti-DOS

restricted

secure

updates

tripwireabstraction

permissions

restrictedaudit

Page 48: Safety LAMP: data security & agile languages

attack vectors

Primary attack vectors for data theft in LAMP:

1.SQL injection

2.direct connection

3.application server compromise

4.staff malfeasance/mistake

5.physical access

Page 49: Safety LAMP: data security & agile languages

attack vectors

Primary attack vectors for data theft in LAMP:

1.SQL injection

2.direct connection

3.application server compromise

4.staff malfeasance/mistake

5.physical access

Page 50: Safety LAMP: data security & agile languages

database tools

1.access control

2.authentication

3.drivers

4.privileges

5.data abstraction

6.encryption

7.data auditing

8.advanced security frameworks

Page 51: Safety LAMP: data security & agile languages

access control

Goal: Use database access control lists to prevent connections from anywhere but specified networks.

webserverdatabaseserver

Page 52: Safety LAMP: data security & agile languages

access control

Network Isolation:

isolated network segment

only appservers & admins can connect

use firewall tools to restrict ports & networks

Page 53: Safety LAMP: data security & agile languages

access control

Database Access Control

restrict which users can connect to which databases from which networks

PostgreSQL

pg_hba.conf, listen_addresses, pgbouncer

MySQL

users table, MySQL Proxy

Page 54: Safety LAMP: data security & agile languages

authentication

Goal: prevent privilege escalation through direct connections to the database.

psql -U postgres -h masterserver -c 'update users set password = \'haxx0r\'where login = \'administrator\'

Page 55: Safety LAMP: data security & agile languages

authentication methods

ident: host OS responsible for security

good for: administrative tasks

bad for: external users

Page 56: Safety LAMP: data security & agile languages

authentication methods

hashed user/password

good for: most things bad for: application server / network compromise

Page 57: Safety LAMP: data security & agile languages

authentication methods

krb5 / sspi / ldap: identity checked against authentication servers

good for: network/application server compromises

bad for: performance, troubleshooting, uptime

Page 58: Safety LAMP: data security & agile languages

driver tools

Goal: prevent SQL injection

prepared queries:

$q = prepare(“SELECT * FROM profile WHERE user = ?”);

execute($q, db_escape($this_user));

Page 59: Safety LAMP: data security & agile languages

driver tools

Goal: prevent SQL injection

switches

no multi-statement

read-only connection

Page 60: Safety LAMP: data security & agile languages

database privileges

Goal: prevent authenticated low-level users from modifying or accessing restricted data.

SELECT FROM users;

UPDATE users;

Page 61: Safety LAMP: data security & agile languages

database privileges

Privileges Rule #1: your app should not be connecting as the database owner or superuser

Page 62: Safety LAMP: data security & agile languages

ROLEs

create some ROLEs (users and groups)

public

application_user

application_admin

admins

claudio felipe

users

dataentry readonly

guestwei-chenleo

db_admin superuser

Page 63: Safety LAMP: data security & agile languages

privileges best way to restrict access to specific data

SQL standard

Both MySQL & PostgreSQL support:

database/schema, table, column

Page 64: Safety LAMP: data security & agile languages

privileges

PostgreSQL privileges:

tables: SELECT, INSERT, UPDATE, DELETE, ALTER

schema: USAGE, CREATE, ALTER

function: EXECUTE, ALTER

database: CONNECT, TEMP, CREATE, OWNER

Page 65: Safety LAMP: data security & agile languages

database abstraction

Goal: prevent theft of sensitive data by not allowing direct access to base tables

memberschema admin

rightssettings

schema membersprofilesmessagesviewuser_names

login()change_pw()

users

Page 66: Safety LAMP: data security & agile languages

database abstraction

views

a VIEW is a “stored query” with its own permissions

limit access to specific rows or columns

stored procedures

SECURITY DEFINER procedures allow controlled privilege escalation

make sure to lock them down, though!

Page 67: Safety LAMP: data security & agile languages

encryption

Goal: prevent misuse of sensitive data by anyone who has managed to capture it

the only protection against physical possesion

encrypt your backups!

Page 68: Safety LAMP: data security & agile languages

encryption

1. encrypted authentication

2. encrypted connections

3. encryption of specific data

4. whole database encryption

Page 69: Safety LAMP: data security & agile languages

the biggest problem with encryption

??

Page 70: Safety LAMP: data security & agile languages

What do you do if they get in anyway?

sometimes your other measures fail

exploits

loopholes

misconfiguration

sometimes the bad guys have legitimate access

users

staff

sysadmins

Page 71: Safety LAMP: data security & agile languages

database auditing

Goal: know what happened after it happened, and be able to restore your data without searching backup tapes.

Page 72: Safety LAMP: data security & agile languages

auditing: logs

dozens of log options

users

connections

queries run

errors

the log can help you analyze a break-in

maybe even tell you what was stolen

Page 73: Safety LAMP: data security & agile languages

secure your logs

best way to find “DBA corruption”

make sure that not even the admins can erase/alter all copies

make sure few people can change postgresql.conf

use a secured log server

“syslog” is good for this

make a plan for secure log archiving

Page 74: Safety LAMP: data security & agile languages

data auditing

Goal: figure out exactly which data changed, when and how, and be able to reverse it.

Methods

Triggers

Replication

Snapshots

Page 75: Safety LAMP: data security & agile languages

data auditing

table members.profiles

member | interests

josh | pottery, cooking

table audit_members.profiles

member | interests | changed | change_by

josh | gaming | 5/23/01 | claudio

josh | pottery | 3/24/08 | felipe

Page 76: Safety LAMP: data security & agile languages

xtreme security:multilevel

Page 77: Safety LAMP: data security & agile languages

xtreme security:SE Postgres

Page 78: Safety LAMP: data security & agile languages

contact Josh Berkus

[email protected]

it.toolbox.com/blogs/database-soup

PostgreSQL

www.postgresql.org

SEPostgres: http://code.google.com/p/sepgsql

PostgreSQL Experts, Inc.

www.pgexperts.com

Copyright 2009 Josh Berkus, distributable under the creative commons attribution license

Thanks to KaiGai Kohei for SEPostgres diagrams, and to Harrison Fisk for MySQL examples.Thanks to Google Images for the various images, which belong to their original owners.