this post was submitted on 23 Oct 2024
17 points (90.5% liked)

Selfhosted

39842 readers
466 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

I've recently learned that UFW firewall rules do not affect Docker containers. I am looking into learning firewall rules in depth but in the meantime I want make sure I don't fuck something up, so here are a few questions:

1- On a host that drops all incoming connections (configured through UFW), if I have a container with only a single port mapping 127.0.0.1:8080:80 is there any way to access this container through the public internet, what about 8080:80 or no port mapping at all?

2- How do I drop all incoming connections to all Docker containers and do I need to do that? Similar to ufw default deny incoming?

3- Is there a way to see all incoming/outgoing connections of all containers?

Thanks in advance and any resource advice for securing docker for dummies is appreciated.

you are viewing a single comment's thread
view the rest of the comments
[–] Max_P@lemmy.max-p.me 11 points 6 days ago (1 children)

With Docker, the internal network is just a bridge interface. The reason most firewall rules don't apply is a combination of:

  • Containers have their own namespace including network namespace, so each container have a blank iptables just for them.
  • For container communication, that goes through the FORWARD table, not the INPUT/OUTPUT ones.
  • Docker adds its own rules to ensure that this works as expected.

The only thing that should be affected by the host firewall is the proxy service Docker uses to listen on a port on the host and send it to the container.

When using Docker, each container acts like an independent machine, and your host gets configured to act as a router. You can firewall Docker containers, the rules just need to be in the right place to work.

[–] Quail4789@lemmy.ml 1 points 6 days ago* (last edited 6 days ago)

Thanks, just to clarify, even if I deny all forwards on the host using UFW, that still won't have an affect on Docker because Docker inserts its rules above UFW rules. Correct?