#!/bin/blog

April 24, 2009

OpenSSH connection multiplexing

Filed under: Security, UNIX & Linux — Tags: , , — martin @ 6:44 am

The Challenge

I was in touch with a developer the other day who used SSH to programmatically connect to a remote machine where he would start some kind of processing job. Unfortunately, he was in trouble when he wanted to kill the remote process. Killing the local SSH client would leave his job active. He claimed that there used to be some sort of signal forwarding feature in OpenSSH on the machine where he had developed his application in OpenSSH 3.x days, but this feature seems to have been removed by now.

I wasn’t able to confirm anything of this, but this gentleman’s problem got me curious. I started to wonder: Is there some kind of sideband connection that I might use in SSH to interact with a program that is running on a remote machine?

The first thing I thought of were port forwards. These might actually be used to maintain a control channel to a running process on the other side. On the other hand, sockets aren’t trivial to implement for a /bin/ksh type of guy, such as the one I was dealing with. Also, this approach just won’t scale. Coordination of local and remote ports is bound to turn into a bureaucratic nightmare.

I then started to skim the SSH man pages for anything that looked like a “sideband”, “session control” or “signaling” feature. What I found, were the options ControlMaster and ControlPath. These configure connection multiplexing in SSH.

Proof Of Concept

Manual one-shot multiplexing can be demonstrated using the -M and -S options:

1) The first connection to the remote machine is opened in Master mode (-M). A UNIX socket is specified using the -S option. This socket enables the connection to be shared with other SSH clients:

localhost$ ssh -M -S ~/.ssh/controlmaster.test.socket remotehost

2) A second SSH session is attached to the running session. The socket that was opened before is specified with the -S option. The remote shell opens without further authentication:

localhost$ ssh -S ~/.ssh/controlmaster.test.socket remotehost

The interesting thing about this is that we now have two login sessions running on the remote machine, who are children of the same sshd process:

remotehost$ pstree -p $PPID
sshd(4228)─┬─bash(4229)
           └─bash(4252)───pstree(4280)

What About The Original Challenge?

Well, he can start his transaction by connecting to the remote machine in Master mode. For simplicity’s sake, let’s say he starts top in one session and wants to be able to kill it from another session:

localhost$ ssh -t -M -S ~/.ssh/controlmaster.mytopsession.socket remotehost top

Now he can pick up the socket and find out the PIDs of all other processes running behind the same SSH connection:

localhost$ ssh -S ~/.ssh/controlmaster.mytopsession.socket remotehost 'ps --ppid=$PPID | grep -v $$'
  PID TTY          TIME CMD
 4390 pts/0    00:00:00 top

This, of course, leads to:

localhost$ ssh -S ~/.ssh/controlmaster.mytopsession.socket remotehost 'ps --no-headers -o pid --ppid=$PPID | grep -v $$ | xargs kill'

Then again, our shell jockey could just use PID or touch files. I think this is what he’s doing now anyway.

Going Fast And Flexible With Multiplexed Connections

With my new developer friend’s troubles out of the way, what else could be done with multiplexed connections? The SSH docs introduce “opportunistic session sharing”, which I believe might actually be quite useful for me.

It is possible to prime all SSH connections with a socket in ~/.ssh/config. If the socket is available, the actual connection attempt is bypassed and the ssh client hitches a ride on a multiplexed connection. In order for the socket to be unique per multiplexed connection, it should be assigned a unique name through the tokens %r (remote user), %h (remote host) and %p (destination port):

ControlPath ~/.ssh/controlmaster.socket.%r.%h.%p
# Will create socket as e.g.: ~/.ssh/controlmaster.socket.root.remotehost.example.com.22

If there is no socket available, SSH connects directly to the remote host. In this case, it is possible to automatically pull up a socket for subsequent connections using the following option in ~/.ssh/config:

ControlMaster auto

So Where’s The Actual Benefit?

I use a lot of complex proxied SSH connections who take ages to come up. However, connecting through an already established connection goes amazingly fast:

# Without multiplexing:
localhost$ time ssh remotehost /bin/true
real    0m1.376s
...
# With an already established shared connection:
localhost$ time ssh remotehost /bin/true
real    0m0.129s
...

I will definitely give this a try for a while, to see if it is usable for my daily tasks.

Update, 2009/05/04: No, it isn’t. Disconnecting slave sessions upon logout of the master session are too much of a nuisance for me.

April 17, 2009

Internetfilterung in Deutschland

Filed under: Politics — Tags: , , — martin @ 7:26 pm

Diesen Artikel hatte ich eigentlich für eine Lokalzeitung geschrieben. Ich habe ihn trotz der durch Konjunktiv und Verwendung der dritten Person erfolgten Distanzierung nicht veröffentlicht. Als jemand, der kleine Kinder und verschlüsselte Festplatten hat, muß man heutzutage gut aufpassen, was man sagt, und was die Leute einem deshalb andichten könnten. Auch wenn hier nichts geschrieben steht, was meine Leser nicht ohnehin schon wissen, ist der Artikel hiermit zur beliebigen Verwendung unter eurem eigenem Namen freigegeben.

Internetfilterung in Deutschland

Am heutigen Freitag wurden vom Bundesfamilienministerium mit mehreren großen deutschen Internetanbietern Vereinbarungen zur Filterung von Internetzugängen abgeschlossen.

Für Ministerin Ursula von der Leyen handelt es sich beim Abschluß der Vereinbarungen um einen großen Durchbruch. Die beteiligten Anbieter sollen auf dieser Basis den Zugang zu Webseiten sperren, auf denen kinderpornographische Darstellungen angeboten werden. Zu diesem Zweck wird den Internetanbietern vom Bundeskriminalamt eine Sperrliste zur Verfügung gestellt.

Die Einführung dieser Filtermaßnahmen wurde im Vorfeld von Technikern, Datenschützern und auch Opfern heftig kritisiert. Die Kritikpunkte waren dabei vielfältig. Die Filterung könnte etwa mit einfachsten Mitteln umgangen werden und sei somit in der Realität wirkungslos.

Kritisiert wurde weiterhin, daß Sperrlisten, die trotz Geheimhaltung an die Öffentlichkeit gedrungen waren, zum großen Teil auf Server verwiesen, die in Deutschland und den europäischen Nachbarländern betrieben werden. Die sollten an Stelle von Sperrungen besser direkt selbst vom Netz genommen werden. Mit den nun in Umsetzung befindlichen Filtermaßnahmen würde das Problem lediglich ausgeblendet, aber effektiv nichts zu einer Lösung beigetragen.

Des weiteren sei zu befürchten, daß die nun vereinbarte Filterregelung als Vehikel genutzt werden könnte, über das etwa die finanzstarke Medienindustrie die Sperrung des Zugangs zu Webseiten betreiben könnte, durch die sie ihre Rechte verletzt sieht. Letztlich könnte über die Filterregelung auch der Zugang zu politisch kritischen Seiten, wie etwa von Globalisierungsgegnern, gesperrt werden. Dies wäre eine beträchtliche Einschränkung der vom Grundgesetz zugesicherten Meinungsfreiheit.

Sollte es so weit kommen, würde aus dem vermeintlichen Kinderschutzsystem eine Infrastruktur für die Zensur des Internet. Deutschland würde sich damit in bester Gesellschaft von Staaten wie etwa China, Pakistan oder Irak befinden.

Ob es so weit kommt, wie die Kritiker befürchten, wird die Zukunft zeigen. Der heutige Tag könnte sich dabei als Wendepunkt für die Freiheit des Internetzugangs in Deutschland entpuppen.

April 15, 2009

Freakshow revisited

Filed under: Politics — Tags: , — martin @ 12:05 am

Irgendwo in USA läuft also noch irgendein 90 Jahre altes todkrankes KZ-Sadistenarschloch im Rahmen seiner Möglichkeiten frei rum. Und dem glaubt man nun, in Deutschland den Prozeß machen zu müssen.

Schön, wenn irgendwo nochmal so ein Alt-Nazi auftaucht. Auch wenn die Umstände, unter denen man ihn vor Gericht zerren muß, einem Rechtsstaat nicht notwendigerweise gut zu Gesicht stehen. Aber man muß halt manchmal gewisse Zugeständnisse machen.

Hauptsache, man hat nochmal jemanden, den man als ganz realen moralischen Abschaum geißeln kann.

Blog at WordPress.com.