Securing Your Data in Postgres Payal Singh DBA@OmniTI - - PowerPoint PPT Presentation

securing your data in postgres
SMART_READER_LITE
LIVE PREVIEW

Securing Your Data in Postgres Payal Singh DBA@OmniTI - - PowerPoint PPT Presentation

Securing Your Data in Postgres Payal Singh DBA@OmniTI payal@omniti.com Contents Event Triggers Authentication ACLs Auditing Row-Level Security SSL / TLS Encryption Replication https://www.postgresql.org/support/security/ 1.


slide-1
SLIDE 1

Securing Your Data in Postgres

Payal Singh DBA@OmniTI payal@omniti.com

slide-2
SLIDE 2

Contents

Authentication Encryption Row-Level Security SSL / TLS ACLs Event Triggers Auditing Replication

slide-3
SLIDE 3

https://www.postgresql.org/support/security/

slide-4
SLIDE 4

1. Authentication

slide-5
SLIDE 5

# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128

slide-6
SLIDE 6

md5 scram Password trust

peer reject

ldap ident

slide-7
SLIDE 7

#> SET password_encryption = 'scram'; SET #> CREATE ROLE sales PASSWORD 'ReallyBadPassword'; CREATE ROLE #> SELECT substring(rolpassword, 1, 14) FROM pg_authid WHERE rolname = 'sales'; substring

  • scram-sha-256:

(1 row)

slide-8
SLIDE 8

Trust TRUST !

Initdb -A md5

Don’t

slide-9
SLIDE 9

Reject

slide-10
SLIDE 10

psql#> SELECT pg_realod_conf( ) ;

slide-11
SLIDE 11

Grand Total Of Fall Throughs Allowed:

slide-12
SLIDE 12

2. Access Control Lists

slide-13
SLIDE 13

list st of permissions attached to an

  • bject. An ACL specifies which

users or system processes are granted ac acces cess to objects, as well as what operations are allowed on given objects.

Grant Revo voke ke

slide-14
SLIDE 14

rolename=xxxx -- privileges granted to a role =xxxx -- privileges granted to PUBLIC r -- SELECT ("read") w -- UPDATE ("write") a -- INSERT ("append") d -- DELETE D -- TRUNCATE x -- REFERENCES t -- TRIGGER X -- EXECUTE U -- USAGE C -- CREATE c -- CONNECT T -- TEMPORARY arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects) * -- grant option for preceding privilege /yyyy -- role that granted this privilege

slide-15
SLIDE 15

Transactional DDLs

psql#> BEGIN; BEGIN psql#> GRANT SELECT ON test TO payal; GRANT psql#> ROLLBACK; ROLLBACK postgres@postgres:5432# \dp test Access privileges Schema | Name | Type | Access privileges | Column privileges | Policies

  • -------+------+-------+-------------------+-------------------+----------

public | test | table | | | (1 row)

slide-16
SLIDE 16

ALTER IN SCHEMA <schema_name> GRANT <privilege> ON TABLES TO <role>;

DEFAULT PRIVILEGES

slide-17
SLIDE 17

Roles and Groups Roles

Sales Bob: Rachel:

slide-18
SLIDE 18

Column Level ACLs

postgres@postgres:5432# GRANT ON test TO rachel; GRANT postgres@postgres:5432# \dp test Access privileges Schema | Name | Type | Access privileges | Column privileges | Policies

  • -------+------+-------+-------------------+---------------------+----------

public | test | table | | +| | | | | | (1 row) UPDATE(name) name: rachel=w/postgres

slide-19
SLIDE 19

PUBLIC Schema

slide-20
SLIDE 20

3. Row Level Security

slide-21
SLIDE 21

Row Level Security

CREATE TABLE accounts (manager text, company text, contact_email text); ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;

CREATE POLICY account_managers ON accounts TO managers USING (manager = current_user);

slide-22
SLIDE 22

RLS

BYPASSRLS Table Owner ALTER TABLE accounts FOR

FORCE CEROW LEVEL SECURITY;

Default Policy Exceptions

slide-23
SLIDE 23
slide-24
SLIDE 24

4. SSL / TLS

slide-25
SLIDE 25

ssl = o

  • n

# (change e requires es restart) #ssl_cipher ers = 'ALL:! :!ADH:! :!LOW:! W:!EXP:! :!MD5:@ :@STRE TRENGTH GTH' ' # allow

  • wed

ed SSL ciphers #ssl_prefer er_ser erver er_cipher ers = on # (change e requires es restart) #ssl_ecdh_curve e = 'prime2 e256v1' ' # (change e requires es restart)

ssl_ce cert_fi t_file = '/etc tc/ssl ssl/post stgre res/ s/sta starr rry. y.io.

  • .crt'

crt'

# (change e requi uires es restart)

ssl_key_ y_fi file = '/etc tc/ssl ssl/postg

  • stgre

res/ s/sta starry. ry.io.

  • .key'

y'

# (change e requires es restart) ssl_ca_file le = '' # (change e requires es restart) #ssl_crl_ l_file le = '' # (change e requires es restart)

slide-26
SLIDE 26

OpenSSL

  • -with-openssl at build time

Encryption Permissions New Certificates

slide-27
SLIDE 27

No SSL connections allowed

DISABLE

Allow SSL Connections if connections without SSL fails

ALLOW

Allow non-SSL connection if SSL connection fails

PREFER

Certificate verification required to connect

REQUIRE

Verify server certificate

VERIFY-CA

Server HostName same as name in certificate

VERIFY-FULL

Modes

slide-28
SLIDE 28

Tunneling

ssh -L 63333:localhost:5432 joe@foo.com psql -h localhost -p 63333 postgres

slide-29
SLIDE 29

5. Event Triggers

slide-30
SLIDE 30

Event Triggers

slide-31
SLIDE 31

Auditing Unwanted modification of data Accidental data loss Trigger-based replication Ownership

slide-32
SLIDE 32

ddl_command_start ddl_command_end sql_drop

table_rewrite in pg10!

slide-33
SLIDE 33

6. Auditing

slide-34
SLIDE 34
slide-35
SLIDE 35

Storage !

slide-36
SLIDE 36

Pg_Audit

slide-37
SLIDE 37

Monitoring Roles (PG10 and onwards)

Pg_monitor Pg_read_all_settings Pg_read_all_stats Pg_stat_scan_tables

slide-38
SLIDE 38

7. Encryption & PCI

slide-39
SLIDE 39

At-Rest

pgcrypto

  • AES-128, AES-192, or AES-256
  • Performance impact

Backups Volumes instance-level - 3rd party patch!

https://www.postgresql.org/message-id/CA%2BCSw_tb3bk5i7if6inZFc3yyf%2B9HEVNTy51QFBoeUk7UE_V%3Dw@mail.gmail.com

slide-40
SLIDE 40

Shared_preload_libraries = ‘pg_stat_statements’

slide-41
SLIDE 41

Monitors

slide-42
SLIDE 42

Key Management

Key Storage Location Encryption/Decryption Location Encrypted query processing

slide-43
SLIDE 43

8. Replication

slide-44
SLIDE 44

Binary Replication

READ-ONLY Replicas Orchestrators

  • Chef Data Bags
  • Ansible Vault

Recovery File

slide-45
SLIDE 45

Logical Replication

Create publication CREATE privilege Add tables table owner Add all tables superuser Create subscription superuser Subscriptions apply process

slide-46
SLIDE 46

9. Procedural Languages

slide-47
SLIDE 47

Trusted VS Untrusted Security Definer LEAKPROOF

slide-48
SLIDE 48

Upcoming Features in PG11

SCRAM-SHA-256-Plus

  • Channel Binding SASL mechanism
  • Mutual Authentication
  • tls-unique
  • tls-server-end-point

PG_TEST_EXTRA

  • More authentication type tests

Large object ACL permissions

slide-49
SLIDE 49

Desired Features

Data Redaction Oracle TDE - key management

http://www.oracle.com/technetwork/database/security/twp-transparent-data-encryption-bes-130696.pdf

SHOW GRANTS

slide-50
SLIDE 50

Thank You !

Twitter: @postgres_women Slack: #pgsql-women