For low-level which cannot be bypassed, the iptables approach is the one … but that ONLY applies to outgoing!
#
# For that specified user, this will allow any interractions with Apps that require localhost routing
#
sudo iptables -A OUTPUT -o lo -m owner --uid-owner username -j ACCEPT
#
# This will block all other outgoing traffic for that specified user
#
sudo iptables -A OUTPUT -m owner --uid-owner username -j DROP
For incoming, you have to define a rule for every service/host that you need to block! Since that is a near impossible task, you need to take two approaches:
-
[a] dis-allowing access to specified Apps by the specified user, and
-
[b] scan for, and detect, ports that the user is listening to and kill the associated processes.
For tactic [b]:
(need to build a boot-time script to start scanning and killing associated PIDs)
#
# To identify listening activity (with associated PID)
#
sudo ss -tunlp
That will report a list looking like this:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 127.0.0.1:631 0.0.0.0:* users:(("cupsd",pid=1623,fd=7))
For tactic [a]:
You need to set that user in his own group, and dissallow access to specified Apps, by making those Apps only executable by allowed groups.
Depending on how fine a control you want,
-
put every accessible App in a group by itself, then
-
add privileged users to that App group on an App-by-App basis.
In other words, if that User is not part of the group that owns and allows usage of a specified App, that User cannot use it, or even see it depending on the way the “other” privileges are set!
To express the problem in a more general security-oriented language, you basically need to fully implement what is referred to as Role-Based Access Control (RBAC). Normal Linux security offers this, essentially as a built-in, as long as the Apps and Users have been properly defined and assigned as outlined above.
IF … you need to go into such a “deep” and “disciplined” approach to limiting access for a potential interloper to who you are giving login access, there are many books out there that discuss the issues, strategies and methods of implementation.
Some reference sites:
Hope those help!