Restricting SSH access based on boolean ip expression
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Restricting SSH access based on boolean ip expression
Hello,
I understand we can restrict SSH access based on ip address(s) using either tcpwrapper or iptable rules. I have an use case where SSH access is defined by a boolean expression - something like:
ssh.access "host=10.56.7.1 or (host=10.56.7.2 and host=10.56.7.3)"
10.56.7.1 - Allow (above expression evaluates to true)
10.56.7.2 - Deny (above expression evaluates to false)
10.56.7.3 - Deny (above expression evaluates to false)
Is there any simpler way to do this ? One way I can think of is to modify the SSH code and for each incoming ip address, evaluate the above expression, but I don't think that is a good way to do this.
No, it is going to be just from one ip. When the connection is made, it has to be evaluated against the Boolean expression.
To give another use case, the user can allow access from any ip in the 10.22.9 subnet except 10.22.9.170 and 10.22.9.169 using the following rule:
ssh.access "host=10.22.9.1/24 and host!=10.22.9.170,10.22.9.169"
No, it is going to be just from one ip. When the connection is made, it has to be evaluated against the Boolean expression.
To give another use case, the user can allow access from any ip in the 10.22.9 subnet except 10.22.9.170 and 10.22.9.169 using the following rule:
ssh.access "host=10.22.9.1/24 and host!=10.22.9.170,10.22.9.169"
With iptables that would go like this (example):
Code:
iptables -A INPUT -p TCP --dport 22 -s 10.22.9.170 -j DROP
iptables -A INPUT -p TCP --dport 22 -s 10.22.9.169 -j DROP
iptables -A INPUT -p TCP --dport 22 -s 10.22.9.0/24 -j ACCEPT
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.