Docker docs:

Docker routes container traffic in the nat table, which means that packets are diverted before it reaches the INPUT and OUTPUT chains that ufw uses. Packets are routed before the firewall rules can be applied, effectively ignoring your firewall configuration.

  • dohpaz42@lemmy.world
    link
    fedilink
    English
    arrow-up
    24
    ·
    3 months ago

    It’s my understanding that docker uses a lot of fuckery and hackery to do what they do. And IME they don’t seem to care if it breaks things.

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      21
      ·
      3 months ago

      To be fair, the largest problem here is that it presents itself as the kind of isolation that would respect firewall rules, not that they don’t respect them.

      People wouldn’t make the same mistake in NixOS, despite it doing exactly the same.

    • Guilvareux@feddit.uk
      link
      fedilink
      arrow-up
      5
      ·
      3 months ago

      I don’t know how much hackery and fuckery there is with docker specifically. The majority of what docker does was already present in the Linux kernel namespaces, cgroups etc. Docker just made it easier to build and ship the isolated environments between systems.

  • grrgyle@slrpnk.net
    link
    fedilink
    arrow-up
    23
    ·
    3 months ago

    If I had a nickel for every database I’ve lost because I let docker broadcast its port on 0.0.0.0 I’d have about 35¢

      • grrgyle@slrpnk.net
        link
        fedilink
        arrow-up
        4
        ·
        3 months ago

        I exposed them because I used the container for local development too. I just kept reseeding every time it got hacked before I figured I should actually look into security.

        • MangoPenguin@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          14
          ·
          edit-2
          3 months ago

          For local access you can use 127.0.0.1:80:80 and it won’t put a hole in your firewall.

          Or if your database is access by another docker container, just put them on the same docker network and access via container name, and you don’t need any port mapping at all.

          • grrgyle@slrpnk.net
            link
            fedilink
            arrow-up
            1
            ·
            3 months ago

            Yeah, I know that now lol, but good idea to spell it out. So what Docker does, which is so confusing when you first discover the behaviour, is it will bind your ports automatically to 0.0.0.0 if all you specify is 27017:27017 as you port (without an IP address prefixing). AKA what the meme is about.

          • grrgyle@slrpnk.net
            link
            fedilink
            arrow-up
            1
            ·
            3 months ago

            My use case was run a mongodb container on my local, while I run my FE+BE with fast live-reloading outside of a container. Then package it all up in services for docker compose on the remote.

            • Ethan@programming.dev
              link
              fedilink
              English
              arrow-up
              2
              ·
              3 months ago

              Ok… but that doesn’t answer my question. Where are you physically when you’re working on this that people are attacking exposed ports? I’m either at home or in the office, and in either case there’s an external firewall between me and any assholes who want to exploit exposed ports. Are your roommates or coworkers those kinds of assholes? Or are you sitting in a coffee shop or something?

              • grrgyle@slrpnk.net
                link
                fedilink
                arrow-up
                2
                ·
                edit-2
                3 months ago

                This was on a VPS (remote) where I didn’t realise Docker was even capable of punching through UFW. I assumed (incorrectly) that if a port wasn’t reversed proxied in my nginx config, then it would remain on localhost only.

                Just run docker run -p 27017:27017 mongo:latest on a VPS and check the default collections after a few hours and you’ll likely find they’re replaced with a ransom message.

  • ohshit604@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    14
    ·
    3 months ago

    This post inspired me to try podman, after it pulled all the images it needed my Proxmox VM died, VM won’t boot cause disk is now full. It’s currently 10pm, tonight’s going to suck.

      • ohshit604@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        3 months ago

        Okay so I’ve done some digging and got my VM to boot up! This is not Podman’s fault, I got lazy setting up Proxmox and never really learned LVM volume storage, while internally on the VM it shows 90Gb used of 325Gb Proxmox is claiming 377Gb is used on the LVM-Thin partition.

        I’m backing up my files as we speak, thinking of purging it all and starting over.

        Edit: before I do the sacrificial purge This seems promising.

  • MangoPenguin@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    12
    ·
    3 months ago

    This only happens if you essentially tell docker “I want this app to listen on 0.0.0.0:80”

    If you don’t do that, then it doesn’t punch a hole through UFW either.

  • steventhedev@lemmy.world
    link
    fedilink
    arrow-up
    12
    ·
    3 months ago

    You’re forgetting the part where they had an option to disable this fuckery, and then proceeded to move it twice - exposing containers to everyone by default.

    I had to clean up compromised services twice because of it.

  • Harbinger01173430@lemmy.worldBanned
    link
    fedilink
    arrow-up
    9
    ·
    3 months ago

    Nat is not security.

    Keep that in mind.

    It’s just a crutch ipv4 has to use because it’s not as powerful as the almighty ipv6

  • jwt@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    3 months ago

    Somehow I think that’s on ufw not docker. A firewall shouldn’t depend on applications playing by their rules.

    • qaz@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      11
      ·
      3 months ago

      ufw just manages iptables rules, if docker overrides those it’s on them IMO

      • jwt@programming.dev
        link
        fedilink
        arrow-up
        8
        ·
        3 months ago

        Feels weird that an application is allowed to override iptables though. I get that when it’s installed with root everything’s off the table, but still…

        • MangoPenguin@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          3
          ·
          3 months ago

          Linux lets you do whatever you want and that’s a side effect of it, there’s nothing preventing an app from messing with things it shouldn’t.

          • WhyJiffie@sh.itjust.works
            link
            fedilink
            English
            arrow-up
            3
            ·
            3 months ago

            there’s nothing preventing an app from messing with things it shouldn’t.

            that’s not exactly a linux specialty

      • null_dot@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        4
        ·
        3 months ago

        Not really.

        Both docker and ufw edit iptables rules.

        If you instruct docker to expose a port, it will do so.

        If you instruct ufw to block a port, it will only do so if you haven’t explicitly exposed that port in docker.

        Its a common gotcha but it’s not really a shortcoming of docker.

      • pressanykeynow@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        iptables is deprecated for like a decade now, the fact that both still use it might be the source of the problem here.

  • purplemonkeymad@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    3 months ago

    Well yea ofc it works like that, the services are not on the same network, so the packets need to be sent onto another adapter. That means either nat or forwarding tables.

    Now if that was a good design of docker is another question.

    • qaz@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 months ago

      That caused issues with Docker containers being unable to communicate with eachother for me.

        • qaz@lemmy.worldOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          3 months ago

          Yes, you can fix it by doing this

          echo "Adding rules for Docker subnets to allow communication between containers..."
          for subnet in $(docker network inspect bridge -f '{{range .IPAM.Config}}{{.Subnet}} {{end}}'); 
              sudo ufw allow from $subnet
              echo "Added rule for $subnet"
          done