News for hackers. Stuff that matters.
Re:Securing a Postgres Database by greatjack613 on Friday April 02, 2021 @03:36PM (#26675151)
I personally secure my postgres instances by putting them in a silod vpc without internet access. I then limit incoming connections to only be allowed from the separate vpc containing the application server

I then use a bastion host when I need to access ssh on the instance. The bastion host remains off and inaccessible except for when I need to perform maintenance.

The advantages of this is that there is no "always-open" access to the instance.

Not sure why the author does not advocate this.

Re:Securing a Postgres Database by chatmasta on Friday April 02, 2021 @03:59PM (#26675323)
> Not sure why the author does not advocate this.

Probably because the blog post is an advertisement for their product, which already allows you to implement bastion hosts as you describe.

From the bottom:

> Databases do not need to be exposed on the public Internet and can safely operate in air-gapped environments using Teleport’s built-in reverse tunnel subsystem.

Re:Securing a Postgres Database by greatjack613 on Friday April 02, 2021 @04:02PM (#26675344)
Did not catch that. Sneaky self promotion there :)

Not sure what there reverse tunnel product is, but a bastion host is super easy to implement, just spin up an ec2 and walla.

Curious as to what value they are providing

Re:Securing a Postgres Database by jdmichal on Saturday April 03, 2021 @11:19AM (#26681720)
Unsure whether you meant walla, but just in case this is what you meant: It's "voila", from French "et violà".

https://www.collinsdictionary.com/dictionary/french-english/...

Re:Securing a Postgres Database by chatmasta on Friday April 02, 2021 @04:04PM (#26675372)
They've been around a while, it actually seems quite cool. Bastion hosts are simple to setup, sure, but Teleport adds a whole bunch of porcelain on top, e.g. integration with SSO, web UI for administration, etc.

Haven't used them myself but I wouldn't be against trying it if in the market for something like that.

Re:Securing a Postgres Database by duckfang on Friday April 02, 2021 @04:52PM (#26675860)
I find that porcelain has a very bad time in breaking when you least suspect it.

The same is true for server applications that have weird 3rd party dependencies that may go down when you least suspect it.

Re:Securing a Postgres Database by duckfang on Friday April 02, 2021 @03:47PM (#26675222)
Yep, and your answer is the better default answer.

Bastion<->app host<->DB

Bastion can talk to the net.

App host can talk outbound but inbound only accepts bastion and DB.

DB can only talk with app host.

Obviously, you harden everything appropriately... But with this arrangement, it's very difficult to penetrate this sort of network. Think of it as a network that as a whole is default-deny.

Re:Securing a Postgres Database by 120bits on Friday April 02, 2021 @04:35PM (#26675694)
Currently I have a postgres/timescaledb running on EC2 in VPC which has no internet access. I do VPN tunnel to access private local subnet and have security group settings that allows my and 1 more machine access only. I usually have a jump server that I use, but I don't want to keep my ssh keys on the server or leave it behind.
Re:Securing a Postgres Database by clan on Friday April 02, 2021 @05:04PM (#26675988)
If the jumpserver is trusted and controlled by you then you should have a look at ssh agent forwarding. Then you avoid leaving keys on the jumphost.
Re:Securing a Postgres Database by ylk on Friday April 02, 2021 @05:12PM (#26676049)
A better alternative would be ProxyJump. See e.g. https://serverfault.com/questions/958222/bastion-server-use-...

Edit: To add some details - using ProxyJump you don’t have to expose anything to the jump host and instead just proxy through it.

Re:Securing a Postgres Database by zomgwat on Friday April 02, 2021 @04:14PM (#26675454)
One alternative to keeping the bastion off is to restrict access to the bastion by IP address. Ideally, the list of IP addresses that need access to the bastion should be relatively small.

In cloud environments, it's straightforward to update network firewall rules as IP addresses change. Residential and office IP addresses don't change much so it's not much of a hassle in my experience. That said, it can get annoying if you find your self working on a network that rotates your IP address frequently (e.g., a hotspot).

Re:Securing a Postgres Database by lovedswain on Friday April 02, 2021 @05:14PM (#26676062)
What value is added by using a separate VPC? Equivalent restrictions can more easily be done with security groups, including on the outbound networking
Re:Securing a Postgres Database by cj on Friday April 02, 2021 @05:28PM (#26676195)
I would suggest considering segregation by subnets (in addition to security groups), using public / private subnets, where any server in a private subnet (behind a nat gateway) doesn't/can't have a public ip address, and therefore cannot be accessed via the public internet.

You could then use a bastion to access servers in the private subnet, or use something like AWS Session Manager which provides command line access via web browser in lieu of a bastion.

Re:Securing a Postgres Database by lovedswain on Friday April 02, 2021 @05:42PM (#26676286)
> What value is added by using a separate VPC?

Adding more mechanisms on top is pointless when the effort could be invested in, for example, automated auditing of SGs, which is vastly more potent from a hardening perspective than adding additional layers of technical redundancy that are still exposed to the same flawed human processes.

When you reach a team of 10-20 folk on a project, stuff tends to get confusing and/or lazy with elaborate configurations. Security design therefore is about more about managing that outcome through simplicity and process hardening than.. well.. I don't even know what threats a separate VPC protects against

Re:Securing a Postgres Database by cj on Friday April 02, 2021 @06:26PM (#26676614)
> When you reach a team of 10-20 folk on a project, stuff tends to get confusing

From the perspective of maintaining security in the least confusing way possible in a team setting, I could see a scenario where you have a VPC that only has private subnets, and no public subnets at all.

You could call it “Database VPC” and assuming your team doesn’t reconfigure the VPC to add public subnets, you can be comfortable with your team adding more EC2 servers / databases / whatever in that VPC since they would all be in private subnets inaccessible by the public internet.

And then you could have a 2nd VPC with private/public subnets that are less locked down than the database VPC, which might contain your load balancers, application servers, etc.

I suppose the benefit would be the logical separation of databases into a VPC without any public subnets. And the only way to gain access to subnets in that VPC would be through VPC peering.

(The above assumes you’re using AWS). Although after typing all that, I still think you can accomplish a comparably secure (on a network level) architecture using security groups, or even separate subnets, without separate VPCs.

In general I try to avoid multiple VPCs because VPC peering in AWS can get tricky (or impossible if both VPCs have overlapping CIDR blocks).

Re:Securing a Postgres Database by brightball on Friday April 02, 2021 @04:32PM (#26675659)
Agreed. What would be the best way when using something like Heroku?
Re:Securing a Postgres Database by fmajid on Friday April 02, 2021 @05:26PM (#26676176)
Something like Nebula (https://github.com/slackhq/nebula) or Tailscale, perhaps?
Re:Securing a Postgres Database by brightball on Saturday April 03, 2021 @10:44AM (#26681455)
Can you setup Nebula on your Heroku dynos and an RDS instance?
Re:Securing a Postgres Database by moltar on Saturday April 03, 2021 @04:09AM (#26679181)
I use almost the same approach.

I also limit access to just one IP, which is a VPN server hosted on a different cloud provider.

You can run a bulletproof VPN server easily using something like algo (https://github.com/trailofbits/algo)

Re:Securing a Postgres Database by polskibus on Friday April 02, 2021 @03:42PM (#26675203)
How do you monitor node health?
Re:Securing a Postgres Database by duckfang on Friday April 02, 2021 @03:49PM (#26675235)
You can put other machines with a highly restrictive set of network rules that allow data to cross inside the network and outside the network in very controlled ways.

Email is one such way.

Re:Securing a Postgres Database by capableweb on Friday April 02, 2021 @04:56PM (#26675900)
> Email is one such way.

I'm sorry but could you clarify? You mean that you monitor and/or collect data from hosts inside of a network via email somehow?

Re:Securing a Postgres Database by abhishekjha on Friday April 02, 2021 @05:15PM (#26676075)
I am curious. Most of the monitoring stacks include something like telegram/Prometheus to collect metrics and send to influxdb. How would you do this via email?
Re:Securing a Postgres Database by duckfang on Friday April 02, 2021 @07:41PM (#26677052)
Inside the he bastion network/VPC, there can be logging, monitoring, ad/kerb+openldap stuff to do the requisite thing. And your logging and monitoring can send trigger emails when they catch bad things.

Your inbox needs to be an automatable inbox, say controlled by bleeder or another flowengine. From there you can build a full messaging dashboard and have it done in something that could pass a very stringent audit.