|
By Bri Hatch. Summary: Introducing Authprogs, software which lets you control which machines can run authorized commands via SSH using SSH Identities. In the previous three[1] articles, I've shown you how to manually set up identity-based authentication with SSH, and how to use it to force a specific command, regardless the actual command that the client attempts to run. Unfortunately, this procedure requires that you have one identity for each program you want to allow, which can be a very big hassle.
In this article, I introduce you to
Authprogs is a very simple perl script.[3] It looks
for a file named
# The uptime command is allowed from any host [ ALL ] uptime # Localhost can list /tmp (now that's useless) [ 127.0.0.1 ] /bin/ls /tmp/ # allow multiple machines by listing them together [ 127.0.0.1 10.0.0.256 ] rsync --server --sender -logtpr . /var/www/ [ 192.168.192.283 ] /opt/bin/restart_dns # Need to imbed spaces? Use quotes. ls -l "/path/to/some graphic.png" [ 172.31.282.10 ] cd /webroot; rm *.html; wmk
In this case, any machine (ALL is a wildcard for any machine) can
run
In the third section, we list an As you see in the fourth section, if you need to allow spaces in your command arguments, just use double or single quotes normally. You can also put comments on their own line anywhere in this file, as long as you have them on their own line. Lastly, it's completely fine to have multiple commands on one line, or even shell meta-characters. For example if the user from 172.31.282.10 wanted to run the authorized command above, they'd run the following:
172.31.282.10$ ssh user@server -i /path/to/identity 'cd /webroot; rm *.html; wmk'
The quotes here are needed to make sure that the local shell
doesn't expand
So, how do you install the
Ok, so that's a long list. We'll walk through it.
Let's craft an example similar to the one from last week.
The host beepbeep.example.net is our backup server. It wants
to run the following program to back up the /etc/ directory
on host futzy.example.net:
Let's set up futzy to allow the
Now install the public key part of /home/backups/keys/futzy
on futzy.
We added several "
Now we haven't set up our
The authprogs program actually shoots an error to STDERR (the "You're not allowed..."
line above) to let the client know the command is rejected. You can use this
error to determine what command was sent, and add this command to the
However, the
This log entry indicates that the machine 192.168.25.10 (beepbeep's
IP address) tried to run the command "
So, armed with the knowledge of the command
Excellent! Let's run our command from beepbeep and test it out:
Voila! It works!
Now the beauty of
You can use the same private key on multiple machines, because the
In summary, the
NOTES:
[1] Starting with this article
[2] The TODO is available
here
[3] I apologize to the purists
who think everything should be written in C. Call me a Perl
lover, a lazy hack, or whatever you like.
[4] An example of a completely
useless example if I ever wrote one.
[5] Of course you should really avoid having
any shell meta-characters or backticks available in your allowed commands,
lest an attacker manage to trick them into running commands you didn't
think of. Explicit commands are not prone to this sort of trickery,
and are your best bet to keeping things secure.
Bri Hatch is Chief Hacker at Onsight, Inc and author of Hacking Linux Exposed and Building Linux VPNs.
He's been using SSH to secure his remote
logins since Tatu posted the first version of the code - even if the
administrators of those machines refused to install it for him.
Bri can be reached at bri@hackinglinuxexposed.com. Copyright Bri Hatch, 2003
This is the January 15, 2003 issue of the Linux Security: Tips, Tricks, and Hackery newsletter. If you wish to subscribe, visit http://lists.onsight.com/ or send email to Linux_Security-request@lists.onsight.com. |