r/docker • • 4d ago

which sslmode in postgres to use

i have a docker stack with a postgres image, is it completly necesary to have the postgres to be configured with the ssl mode to verify-full , because, the outside world cannot interact with the db, just the backend server can (the network is not attachable and it doesn't expose any ports)

sorry if this is a little bit of a stretch because is not a full docker docker thing u.u

0 Upvotes

12 comments sorted by

4

u/xonxoff 4d ago

How exactly are you running this? Just on your local host? If it’s just running locally on a single machine, it might not need ssl, otherwise I’d suggest turning ssl on.

2

u/mariiiiiiiiiiiiiiiel 4d ago

is a vps, this is for the production version of the server

3

u/serverhorror 4d ago

verify full if it is production.

It's setup overhead, it's also best practice

1

u/Quirky-Net-6436 4d ago

Is it really fully private? So no external connectivity at all? If not, you should aim for zero trust, so verify-full is very useful, even if the database is only reachable from local system.

1

u/mariiiiiiiiiiiiiiiel 4d ago

i have a docker stack like this with the services listed as below

the db is just accesible for the backend (cause the network is not attachable, and there are not ports exposed)

db:
networks:
  networks:
    service_network
server:
  ports: 7777:3000
  networks:
    service_network
network: 
   service_network

like they are not allowed inside in any capacity (as far as i know please correct me if i am wrong)

the only i can think that data might get leaked to the outside world without my consent would be if a malicious attacker could get into my server, and sniffed into the network of it and well read the data because well, is not encrypted, but even then, i don't even know if that is possible, cause im not familiar with the way docker/networking works under the hood, (my guess would still be that even if the services are inside a container they still use the server resources so the data should be there in the network)

how do u have this setup? if u wanna share of course :3

1

u/Quirky-Net-6436 4d ago

So if some service is accessible on public endpoints you need several layers of defense and security. How to protect the service itself, the database, the proxy and so on. Every decision comes with its trade-offs. In your snippet you’re not exposing locally… see  https://docs.docker.com/engine/network/port-publishing/. Why do you expose a service directly without a reverse proxy which is used by an application gateway or any kind of WAF?

1

u/mariiiiiiiiiiiiiiiel 4d ago

i do use a reverse proxy

here is the full thing reddit comment doesn't let me do proper format for the yaml

https://pastebin.com/FpLqhjr7

3

u/pelazas1 4d ago

If postgres is only on that internal network with no ports out, sslmode=disable is fine. verify-full only matters once the traffic crosses a network you don't trust.

1

u/BorysTheBlazer 3d ago

Not strictly. On a private single-host network, verify-full mainly protects against another compromised container on that network spoofing the database.