Live data from Hacker News

Securing a Postgres Database

goteleport.com

51–60 of 104 posts

Re: Securing a Postgres Database

#51
post #46

Earlier quoted context omitted.

"Unfortunately, this sort of air-gapped setup is not something PostgreSQL supports out-of-the-box." Not sure what they mean by "out of the box", but you can make the listen_addresses list empty: "listen_addresses (string) ...If the list is empty, the server does not listen on any IP interface at all, in which case only Unix-domain sockets can be used to connect to it..." https://www.postgresql.org/docs/9.3/runtime-co…

I’m sure the article author meant, by saying “out-of-the-box,” the features available on initial, default install. I disagree with the author and agree that indeed a fresh install supports (i.e. allows one to configure without rebuilding) not talking over a network at all.

Ah, yes, re-read, and they do mention this.

Re: Securing a Postgres Database

#52

>By default, PostgreSQL listens on a TCP port 5432. This post seems to outright state that by default postgres is listening to everyone via TCP for connection. This is not true. Unless you edit pg_ident.conf, your postgres install will not listen for connections outside of on localhost. So, while it's correct to say that it listens to TCP port 5432, there is a very narrow limit to whom it's listening for. Namely, the…

The worst of both worlds: not accessible from the outside, yet insecure because it’s accessible to any user on the inside.

What is the advantage of listening on localhost compared to using a socket, with free access control?

Re: Securing a Postgres Database

#53
post #26

A good overview, but the most secure way is to not give any table-level access privileges and only allow access using SECURITY DEFINER stored procedures (the PG equivalent of the setuid bit). For instance if you have a table of users with login and hashed salted password, you could implement a check_password() procedure. If the app account is compromised, it would not have access to the password hashes or even be abl…

I mean, it's likely you have some other stored procedure that does enumerate users, for use by app adminstrators. Ideally it doesn't return password hashes though, since they are really not useful for humans to look at. Also ideally, the admin stored procedures are not executable by the end-user app.

Usually application uses connection pool to connect with database server. I'm not sure if that pattern could be used, when different requests need different database roles.

Re: Securing a Postgres Database

#54
This is surely a silly question (and probably a lot of devops will think I am an idiot), but what do you recommend to secure a PostgreSQL that is accesed by different IPs? We use Azure PostgreSQL database, which I guess they take care of most of the security, but they allow us to set up firewall rules, as only allowing connectins by established IPs.

My (our) problem is that we use a lof ot AWS lambda functions that read and write to the database, and they always execute from different (dynamic) IPs, so what is the best solution in this case?

Re: Securing a Postgres Database

#55
post #54

This is surely a silly question (and probably a lot of devops will think I am an idiot), but what do you recommend to secure a PostgreSQL that is accesed by different IPs? We use Azure PostgreSQL database, which I guess they take care of most of the security, but they allow us to set up firewall rules, as only allowing connectins by established IPs. My (our) problem is that we use a lof ot AWS lambda functions that r…

You can attach the Lambda functions to a VPC. So you can control their outbound IP.

Re: Securing a Postgres Database

#58
I see quite a few posts discussing running Postgres in a separate VPC or network. We currently run our Postgres databases within Kubernetes and leverage network policies to ensure that only application pods can access the database.

The application pods ingest the db credentials from Vault. The biggest concern we have today is automating credential rotation.

Curious if anyone else has a similar setup or thoughts on ours?

Re: Securing a Postgres Database

#59
post #26

A good overview, but the most secure way is to not give any table-level access privileges and only allow access using SECURITY DEFINER stored procedures (the PG equivalent of the setuid bit). For instance if you have a table of users with login and hashed salted password, you could implement a check_password() procedure. If the app account is compromised, it would not have access to the password hashes or even be abl…

Stored procedures are really not used enough. They’re incredibly useful, and not just for security. People can make out-of-band updates to the query, like making it more efficient or migrating it, without requiring any changes to the all.

I have an impression that many developers actively avoid stored procedures, trigger or any 'complex' database features because they don't fit well into a typical CI/CD pipeline which deals only with application code.

It is quite possible to test stored procedures, it's just requires some additional work/infrastructure.

Re: Securing a Postgres Database

#60

Teleport looks cool. We have a pretty elaborate home grown bastion host setup. Seems like an area that should have more competition. Especially after looking at teleports pricing.

Disclaimer: I work at Teleport

If our Enterprise pricing is too high, take a look Teleport's open core version:

https://github.com/gravitational/teleport

Post reply on HN