Score:1

How to block all outgoing connections from a particular user except localhost?

id flag

I wish to block all outgoing connections from a particular user user after they have ssh'd into my server (running RHEL 7.4), that is, user should not be able to ssh into/ping other servers on the network.

I initially configured the following firewall-cmd rule, and it was working.

firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 -m owner --uid-owner user -j DROP

However, user now needs to access Jupyter Notebook also running on the same server (http://localhost:8888), but was unable to. There was an error about the websocket. Once the firewall rule above was removed, user can access the Notebook.

I'm not sure why user was unable to access localhost, because I thought the rule only blocks outgoing connections.

How do I allow user to access localhost on any port, or a specific port range, while still blocking network access to everywhere else?

djdomi avatar
za flag
add an exception?
id flag
Thanks, I'll try that.
Score:2
it flag

As djdomi mentioned, you'd like to add an exception before that DROP rule you already have. This could work

firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 -m owner --uid-owner user --dport=8888 -j ACCEPT

Place it before the rule yuo already have.

BR

id flag
I was wondering what exception to add. I saw an answer online where the exception added was `-o lo` to allow for local services, so I'll try that and the port like you suggested. Do you know why the DROP rule did not allow for access to the localhost? I thought it was only supposed to block outgoing connections, and access to 127.0.0.1 should still be allowed. Or is it blocking all ports, regardless of the IP (internal or not)?
djdomi avatar
za flag
deny is deny and will impact always first. if you do not allow ita denied. thats the easiest way to explain the process and situation
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.