Use secure shell (ssh) with public key authentication (pka) to directly access root and other privileged accounts on UNIX
The standard paradigm to control access to the root and other sensitive accounts on UNIX systems utilizes personal accounts for administrative personnel, passwords, and sudo. While generally accepted, this approach has significant vulnerabilities that can be circumvented via ssh using pka. Additional procedures and scripts can be put in place to further enhance the security of pka access to privileged accounts - something that's difficult and/or impossible to do with sudo access.
I was a Russian Linguist in the United States Air Force for 12 years during which time I held elevated security clearances. The importance of communications, information, operations, and computer security was continually impressed upon me. In 1987, I took over supervision of the Small Computer Support Branch for my military unit. In that role, I wrote and implemented most of the regulations, policies, and procedures for computer security for my unit and wing. Additinally, I had significant input into the regulations of the Electronic Security Command. In my civilian career, I've generated security policies for two companies and conducted UNIX security audits for numerous clients. I am also a (EC-Council) Certified Ethical Hacker and (ISC2) Certified Information System Security Professional (CISSP). Security in general and computer security in particular has been an integral part of my entire adult life.
There are two very valid reasons for prohibiting direct password-based access to root and other privileged accounts: authentication and non-repudiation.
There are three factors of authentication
The validitiy and trust in the authentication process increases with the number of factors employed.
Password based authentication, be it telnet, ssh, or web based, is single factor authentication. You know the password.
Most people that work in reasonably large companies are familiar with the secure ID tokens used for remote access to the company network. These employ 2-factor authentication as you have the token and know the PIN that enables it.
ssh/pka is also 2-factor authentication as you have the private key and know the passphrase to it.
The third factor is generally classified as biotmetrics (retinal scans, finger prints, etc) and isn't widely used in the civilian community for authentication yet.
Jan 1 13:26:55 2008 : oleary : HOST=myhost : TTY=pts/0 ;
PWD=/home/dkoleary/working/ssh/comparison ; USER=root ; COMMAND=/usr/bin/su -
That shows date and time, who I am, what target ID I accessed, and the command I used. This log entry does not show what system I accessed myhost from, however. While a detailed analysis of the log files would identify that, it would take some additional time.
Conversely, the ssh/pka access logs entries:
Jan 1 13:30:51 myhost sshd[143]: Connection from 192.168.12.26 port 51798 Jan 1 13:30:51 myhost sshd[143]: Failed none for root from 192.168.12.26 port 51798 ssh2 Jan 1 13:30:51 myhost sshd[143]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 1 13:30:52 myhost sshd[143]: Accepted publickey for root from 192.168.12.26 port 51798 ssh2 Jan 1 13:30:52 myhost sshd[143]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 1 13:30:52 myhost sshd[143]: Connection closed by 192.168.12.26
These log entries too show date, time, target account. They also show the system that I accessed myhost from which would enable quicker tracing of the access back to its source. Using the default configuration, it could be somewhat more difficult to identify the user; however, with a minor modification, that too is easily done:
# ssh-keygen -l -f ./dkoleary_laptop.pub 1024 c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 ./dkoleary_laptop.pub
Note that the key fingerprints match exactly.
As discussed above, ssh/pka provides greatly improved security authentication and can log the same information as does sudo. There are four actions required to enable that level of security, two optional ones to improve the maintenance of the ssh/pka environment and two additional scripts can be implemented to further enhance the automation of access removal and post employment access alerts.
$ ssh myhost ls -ld /tmp drwxrwxrwt 69 bin bin 24576 Jan 4 08:32 /tmp $ ssh myhost tail -15 /var/adm/syslog/syslog.log Jan 4 08:30:49 myhost inetd[19731]: registrar/tcp: Connection from myhost (192.168.12.24) at Fri Jan 4 08:30:49 2008 Jan 4 08:32:19 myhost sshd[19794]: Connection from 192.168.12.24 port 62633 Jan 4 08:32:20 myhost sshd[19794]: Failed none for root from 192.168.12.24 port 62633 ssh2 Jan 4 08:32:20 myhost sshd[19794]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 4 08:32:20 myhost sshd[19794]: Accepted publickey for root from 192.168.12.24 port 62633 ssh2 Jan 4 08:32:20 myhost sshd[19794]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 4 08:32:20 myhost syslog: ssh/pka executed ls -ld /tmp Jan 4 08:32:20 myhost sshd[19794]: Connection closed by 192.168.12.24 Jan 4 08:32:20 myhost sshd[19794]: Closing connection to 192.168.12.24 Jan 4 08:32:35 myhost sshd[19807]: Connection from 192.168.12.24 port 62634 Jan 4 08:32:36 myhost sshd[19807]: Failed none for root from 192.168.12.24 port 62634 ssh2 Jan 4 08:32:36 myhost sshd[19807]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 4 08:32:36 myhost sshd[19807]: Accepted publickey for root from 192.168.12.24 port 62634 ssh2 Jan 4 08:32:36 myhost sshd[19807]: Found matching DSA key: c2:dc:f6:dc:29:2a:86:24:f4:6c:c5:d0:61:90:a5:f3 Jan 4 08:32:36 myhost syslog: ssh/pka executed tail -15 /var/adm/syslog/syslog.log
The underlined/bold lines show the commands I ran and that they're reflected in the system's syslog.
This functionality is enabled by setting an option in the public key:
command="/root/bin/sshroot" ssh-dss AAAAB3NzaC1kc3MAAACBALKnuTrmoeO6X1TI6gWSq5ysxx [[ LOTS snipped ]]
Regardless of what's entered on the command line, ssh will execute /root/bin/sshroot. That script logs the commands via the logger command and then runs the commands as requested. The script is available here
openssh keeps all authorized public keys in one file - one very long public key per line:
command="/root/bin/sshroot" ssh-dss AAAAB3NzaC1kc3MAAACBALKnuT rmoeO6X1TI6gWSq5ysxx+BzufrbfZGRcZTAZgVTityx4I+vpP6U+IveSH+gqbgkSCjD P6g1Jl64IIAYEchMBpIl1Kx6reEzJlAM9FQk/FhAt2EJQaiyhVq4R5FBf8E2WRJTBHx KdBEMiNTae+/1VNhpFURDBCozcU0e2Z7AAAAFQC5ORw9d7+dSMNkfY38InxUYsnCWQA AAIEAk3uSlj0421cRkdvgd8TFdlA0uGYb9UxV8/oJb8TboKeoebNldqXQxQzf+bJBAr 7OEd9fMZzsdjQYslf5kWB04Fi9mC3ZVMviQfDzG/Qy34JodaZGMtQmhpYwPV3O85KiB 79rhM3PafcwGc1NwkoJkw0yMg+Dx7jPKi8aiC3+QF8AAACAJEeK+UjoOZHdLTP4/jKd ttpGNCPS/dieXwANT4rj7uavXRoezP+GY/JvKGw2q6UVjvCZ79nkjgBOK4LktSE2QqW usR/6wmV67SbqqjGrOHw0NT72gxuOEV+THI45cwcLwQSiw/SBsXXPEdlXRYRPFDo0r0 kqLlzMhOQIDDukRIE= dkoleary@myhost.com
That's one line. In a generic/default environment, if an admin were to leave the company, we would have to edit the authorized_keys file on each system individually, search for the correct key, and delete it. Many iterations of that and you have yourself an official unholy nightmare.
One way around this issue is to use cfengine which is a software product that helps centralize management of files across an enviornment. Cfengine configuration is way beyond the scope of this document; however, if used, removing a key could be as simple as editing one file and waiting for the next cfengine run - typically every half an hour
On systems that aren't cfengine managed, I maintain each key authorized to a specifc account in a separate file under ~/.ssh/pub_keys
admin1_myhost.pubRecreating the authorized_keys file is easy:
cd ~/.ssh/pub_keys cat *.pub > ../authorized_keys
Adding or deleting access is a simple matter of copying in or deleting the appropriate key file, then running those two commands.
At one client, I configured a centralized logging server on a management node. Using syslog-ng on the management node, I sent any lines with sshd in them through a script filter called ssh_logger which would compare the fingerprints against a cfengine managed file of key fingerprints. If there was was not a match or a match but an unauthorized access, the script would automatically page out to the on call SA. All of the SAs would receive an email in the morning showing who accessed their systems.
No security model is perfect and ssh/pka does have it's share of items over which to be concerned.
First and foremost, utilizing this model effectively moves some of the authentication off of the target system. Some admins are known to use null passphrased keys as their default, interactive keys. If you do this, you are putting your root account at risk. If you regularly leave your terminal unlocked, you are putting your root account at risk.
There are ways around some of these concerns; however, the cost of implementing thse can increase rather dramatically and very quickly.
My typical concern is that the SAs will use null passphrased keys. You can test for a null passphrased key by obtaining a copy of the private key and attempting to add it into an ssh-agent command. If it loads without asking for a passphrase, then the SA is using a null passphrased key.
If you implement that, though, the SA may simply put a passphrase on the key, provide a copy, then remove the passphrase again. You can get around this by setting up a management node and configuring the sshd on each host to accept ssh connections only from that management node. On that management node, you can then scan for private keys and attempt to add them to an ssh-agent procss as described above.
So, what happens if your management node crashes? You have just lost ssh access to your entire environment. You can get around this by clustering the management node or by configuring several management nodes.
Hopefully, it's obvious by now that there are always ways to address security concerns; however, ever time you address one concern, you're opening up possibilities of others.
I generally suggest that the concern of null passphrased keys be addressed through education. If I see someone using a null passphrased key, I tell them why its a bad idea and how they can get the exact same ability through the use of ssh-agents.
A second concern is that this level of access can be dangerous for inexperienced or careless administrators. Running the following loop will result in a very long and very bad day:
for h in $(cat list-o-hosts)
do
echo ${h}
ssh -l root ${h} rm /etc/shadow
done
I actually saw an admin doing that. Fortunately, I was able to stop him before he hit the final enter and I was able to have my heart attack in peace.
There really is no sure way around inexperience or carelessness. Every time you make something idiot proof, nature develops a better idiot.
From a security viewpoint, particularly relating to authentication and non-repudiation, ssh/pka is inherently superior to any form of password authentication. With some modifications and scripting, it can provide for automatic access removal and invalid access attempt alerts, something that is difficult, if not impossible to do with the password/sudo access paradigm.
Feel free to contact me at dkoleary@olearycomputers.com with any questions, comments, or concerns.
| Document: | |
| URL: | |
| Last updated: |