Skip to content

World to host not working (& host to container) #705

Description

@MichaelVoelkel

Hi,

being on Debian12, I switched to NFT now again. The basic configuration is just from the docs, /etc/nftables.conf:

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
    chain input {
        type filter hook input priority 0; policy drop;
        tcp dport 22 accept
    }
    chain forward {
        type filter hook forward priority 0; policy drop;
    }
    chain output {
        type filter hook output priority 0; policy accept;
    }
}

/etc/nftables exists but I don't use it. I hope it makes no trouble.

I can connect to ssh and nothing else works, so far so good.

Now I have portainer running on 9443 where I could before have world access and host access (it has the ports mapping of 9443:9443, so I should access it via localhost, e.g., nc -vv localhost 9443). As connection times out both ways, I'd assume that the package is dropped.

My rules.toml is: (yeah, small, nothing else)

[[wider_world_to_container.rules]]
network = "portainer_network"
expose_port = 9443
dst_container = "portainer"

I run dfw currently like this to see the logs:

docker run --rm       --name=dfw       -v /var/run/docker.sock:/var/run/docker.sock:ro       -v $PWD/rules.toml:/config/dfw.toml       --net host --cap-add=NET_ADMIN       pitkley/dfw:1.2.1 --log-level trace --config-path /config  

And yeah, stuff like nc etc. I do via a second ssh session, so I keep it open. :)

So, my problem clearly is that I cannot connect but would hope/expect to do so.

Some more information / pecularities / questions / comments:

  • sudo nft list ruleset does not seem to show any rules that have been created, is this expected?
table inet filter {
	chain input {
		type filter hook input priority filter; policy drop;
		tcp dport 22 accept
	}

	chain forward {
		type filter hook forward priority filter; policy drop;
	}

	chain output {
		type filter hook output priority filter; policy accept;
	}
}
table inet dfw {
	chain input {
		type filter hook input priority filter - 5; policy accept;
		ct state invalid drop
		ct state { established, related } accept
		iifname "docker0" meta mark set 0x000000df accept
	}

	chain forward {
		type filter hook forward priority filter - 5; policy accept;
		ct state invalid drop
		ct state { established, related } accept
	}
}
table ip dfw {
	chain prerouting {
		type nat hook prerouting priority dstnat - 5; policy accept;
	}

	chain postrouting {
		type nat hook postrouting priority srcnat - 5; policy accept;
	}
}
table ip6 dfw {
	chain prerouting {
		type nat hook prerouting priority dstnat - 5; policy accept;
	}

	chain postrouting {
		type nat hook postrouting priority srcnat - 5; policy accept;
	}
}
  • I'm puzzled why I need to state a network. Before I just had "bridge" network, so I also tried putting that as name. Later, I created a new custom bridge network and connected the container to it (which I double-checked via docker inspect) that I called portainer_network and which you see in my rules-file now.
  • I was unsure whether I needed to restart the container first or not, so I did that. I also stopped and started it (which retained the specific network)... nothing helped here.

Probably I messed up something very basic. I tried also to make sure that old iptables is disabled but sudo systemctl disable iptables told me it did not even know iptables.

Hm, when I reset nft rules to /etc/nftables.conf, it's empty though, when I start dfw, it fills up to the config shown above, so it seems to do something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions