Improving Apache2 log format

While the default format for Apache logs has some benefits (the CLF is understood by many log analyzers), it’s very awkward zu read (only one space separating entries) and difficult to parse on the command line (spaces everywhere, and no hostname in the actual lines, which makes parsing multiple files a slight hassle).
As I had to change the log format anyway to include the response time (for identifying slow requests), I changed it to the following:

#ServerName	date time	port	r_ip	status	rtime	request	referer		user_agent	rsize
LogFormat "[%v]	%{%F %T}t	%p	%a	%>s	%D	%r	%{Referer}i	%{User-agent}i	%B" combined

The big difference? The actual fields are tab-delimited. Thus they can be easily parsed by cut -f , which avoids all the awkward awk/grep/sed hassle of the CLF; or can be imported into spreadsheet softwares (as tab-delimited CSV) for visualization. This saves a lot of time if someone needs some ad-hoc statistics again and I don’t want to run webalizer or something similar over the aggregated logfiles. Also, the bigger space between each entry makes it much easier to read manually.

(Since LogFormat directives can override each other, deployment can be reduced to “throw two lines into a file in apache2/conf.d, throw file into one of our deb packages, update package on servers”).


RSA encryption in JavaScript and PHP

For a new project (password management application), I’m investigating the usage of RSA in JavaScript and PHP. Had I known the amount of bullshit ahead of me beforehand, I’d have resorted to sticky notes for password management…

Anyway. I quickly settled for Tom Wu’s Bigint and RSA library. It is, for the most part, pretty decent. However, it’s still somewhat bugged (a leading zero in BigIntegers is sometimes skipped, which makes messages unparseable), some functions simply make no sense (UTF-8 in the decryption function might be well meant, but is kinda useless if you have non-UTF-8 strings… like binary data) and it’s lacking functionality for messages longer than the key size. This blog post thankfully outlines how to add this functionality for encryption (I added similar functions for decryption, see the source).
For signing/verifying, I chose to ignore the RFCs (implementing another padding scheme in both PHP and JS would have taken too long) and just used swapped encrypt/decrypt functions.

Another limitation of Wu’s lib was the lack of a “proper” import function – I use a modified version (making use of Wu’s jsbn library) of Lapo Luchini’s ASN1 library plus some glue code to extract the actual key data.


For the PHP side, I use PHPSecLib, which works actually pretty well (I only replaced the user_error reporting with proper Exceptions). The only tricky part is that you need to liberally use hex2bin/bin2hex (I build a thin wrapper around it to do exactly that).


After only… oh, about five days of debugging, the libs work as far as I supposed them to work from the beginning. Project deadlines are overrated anyway.

Code, including examples, on GitHub


Mac OS X and Univention Samba

It took us a while to get this hipster crap OS X to play nice with our Samba server (UCS 2.4). In the default settings, the access rights would be completely insane (732 and similar impossible combinations). By deactivating the UNIX extensions (unix extensions = no) we achieved slightly less insane rights (755, which is better, but doesn’t allow others to modify the folders/files). By modifying the umask (create mode = 0775) we got that, too (it would be better if OS X users could set the permissions via the finder UI, but that doesn’t seem to be possible atm, maybe with UCS3?).


TAOFirewall2 Revision 3 erschienen

Heute wurden erstmals über Qemu virtualisierte Windows-Gäste über die TAOFirewall2 geschützt. Dabei sind zwei Bugs in configure_iface.sh aufgetaucht, die durch eine Besonderheit von test und ein Versäumnis entstanden sind. Die TAOFirewall2 erkennt automatisch, wenn eine virtuelle Maschine eine von Qemu emulierte Netzwerkkarte nutzt und setzt dann das Flag IOEMU, wodurch Antispoofing deaktiviert werden sollte. Die Abfrage, ob das Flag gesetzt ist, hat aber nicht richtig funktioniert; hier als Beispiel:

testvar="false"
echo $([ $testvar != "true" ]) $?
0
testvar="true"
echo $([ $testvar != "true" ]) $?
0

Es wird offenbar das true erkannt und der Rest gar nicht mehr evaluiert.

testvar="false"
echo $([ ! $testvar ]) $?
1
testvar="true"
echo $([ ! $testvar ]) $?
1

Als C-Nutzer verblüfft einen wiederum auch dieses Verhalten. Schlussendlich nutzen wir diese Variante:

testvar="false"
echo $([ ! $testvar = "true" ]) $?
0
testvar="true"
echo $([ ! $testvar = "true" ]) $?
1

Diese Abfrage wurde außerdem auf Schnittstellen ausgeweitet, für die die Firewall nicht deaktiviert wurde.

Die jeweils neueste Version der Firewall finden Sie unter http://www.tao.at/special/TAOFirewall2.tar.bz2.


Outlook-Daten exportieren

Für unsere Migration weg von Kolab und Outlook hin zu SOGo und Thunderbird haben wir (etwas spät) feststellen müssen, dass es keine vernünftigen Konverter gibt – Thunderbird kann nur theoretisch Outlook-CSVs importieren, und andere Programme sind ziemlich beschränkt (Wir haben ursprünglich freeMiCal für Kalender getestet, das kann aber immer nur den ersten Kalender exportieren – und auch den nicht immer).

Aus dem Grund habe ich ein Python-Script geschrieben, das Outlook-CSVs ins LDIF- (für Adressbücher) bzw. CSV-Format (für Kalender und Aufgaben-Listen) exportiert. Das Script ist etwas mit der heißen Nadel gestrickt und konvertiert längst nicht alle Felder (und ist für mod_python geschrieben, wofür ich vermutlich von den WSGI-Genossen gesteinigt werde), sollte aber erweiterbar genug sein, dass diese bei Bedarf nachgerüstet werden können – welche Felder ausgelesen werden, kann mit den *.in-Templates bestimmt werden.
Die einzige externe Bibliothek, die das Script braucht, ist das iCalendar package für Python (und mod_python, wobei man das Script leicht für Kommandozeilenbenutzung abändern oder eine GUI drauflegen kann kann).

Download v0.1


Alternative zu jqTransform

Eine bekannte und durchaus sehr praktische Möglichkeit um HTML Form Elementen ein schöneres Aussehen zu verleihen bietet jqTransform, doch wie sieht es hier eigentlich mit Alternativen aus…?

Durch eine kurze Recherche lies sich diese Frage schnell beantworten und wir konnten folgende 3 Alternativen ausfindig machen.

Niceforms:

http://www.emblematiq.com/projects/niceforms/

Niceforms steht jqTransform wohl um nichts nach. Wirkt sehr ansprechend und läuft in allen gängigen Browsern. Benötigt keine externe jQuery Library, dürfte somit etwas bessere Performance bieten.

JNice:

http://plugins.jquery.com/project/jNice

Auf ersten Blick nicht sehr ansprechend, könnte aber an dem grafisch schlechten Beispiel liegen. Funktionalitäts mässig dürfte JNice jedoch sehr gut sein, da es nicht nur in den aktuellen Browsersn, sondern auch noch im IE 6 läuft. Leider schon längere Zeit keine neue Version.

Uniform:

http://uniformjs.com/

Etwas aufwendiger beim Integrieren, scheint allerdings etwas mehr an Funktionalität zu liefern. Bei Select Elementen gibt es hier wohl eine Schwäche, da diese beim Beispiel nicht komplett gestylt sind.

Aufgrund der oben erwähnten Vor- bzw Nachteile wurde Niceform ausgewählt um es für ein Projekt einzusetzen.

Nach einer kurzen Einarbeitungsphase kam man doch recht schnell zu guten Ergebnissen. Beim Feinschliff gabs dann allerdings doch ein paar Probleme die etwas Zeit in Anspruch nahmen.

Fazit:

Ganz zufrieden waren wir dann mit Niceforms nicht, das stylen der Form Elemente funktioniert zwar ohne große Probleme, aber beim Platzieren der Elemente gabs dann doch das eine oder andere Problem. Wenn man es somit öfters verwenden möchte, sollte man sich Gedanken darüber machen die Funktionalität ein wenig anzupassen bzw zu erweitern.


TAOFirewall2 – Bugfixes & Lenny compatibility

Lately I installed the firewall on a Debian Lenny Dom0 with Xen 3.2-1. It does work well despite the hotplugpath.sh script the provided network-route-tao script tries to include – simply comment it out; it’s not needed.

But I  also discovered three bugs:

  1. Completely or partially disabling the firewall for an interface means it doesn’t get NAT for the disabled directions.
  2. All guests using ioemu as device driver (e.g. Windows) use some tapX device. The firewall doesn’t account for that and thus antispoofing blocks all outgoing traffic.
  3. Not very important but there: When a firewall is disabled in whole its temporary files are not deleted.

The first one was fixed partially; it does work now for outgoing connections but still doesn’t for incoming ones. This is due to the very nature of NAT so this is a WONTFIX. The second one is tough to solve because Xenstore does not provide the necessary information. Spoofing protection is thus simply disabled for IOEMU-using DomUs. And 3. was fixed, of course.

Also there where some minor improvements made to the package. It now contains a install.sh script which creates/moves all directories and files to the right locations and we removed the configuration directory for Xen since basically the only difference between the configuration for Xen and any other machine is the variable XEN right at the beginning of taofirewall.conf which is set to TRUE.

How to install?

Download TAOFirewall2 1.0.2 to the computer you want to install the script on. You’ll need bzip2 installed on it to extract the files from the package.

tar xpf TAOFirewall2.0.2.tar.bz2
cd TAOFirewall2
./install.sh

After you’ve configured it you may start the firewall and see if it’s working by issuing the following:

invoke-rc.d firewall start
iptables -L -n -v | more

In case you locked yourself out: restart your server and you’ll be able to connect to it again. Once everything is working as you expect it to, you can run the following to start the firewall when the system boots up:

update-rc.d firewall defaults

Good luck!


TAOFirewall2 – Complete revamp of the firewall script

Two and a half months later and after a lot of cursing we are proud to present a completely reworked version of our firewall for Xen Dom0s and “normal” servers, including DomUs. There have been tons of changes and basically there is nothing as it was in the previous versions.

Overview

First of all this version provides both IPv4 and IPv6 support within one set of scripts. This also means that we had to change the way we configure the firewall but let’s talk about the new configuration in the next paragraph. The second most important thing is that it fully integrates into Xen implying it now dynamically adds and deletes rules as DomUs are going on and off line. Additionally it comes with modified scripts for Xen to use IPv6 in the DomUs. To increase execution speed and avoid some problems we now use iptables-restore instead of calling ip(6)tables directly but you can easily switch back to iptables. The last but most certainly not least important new feature is the ability to manage outgoing connections as well. Most striking though might be that we split the script into multiple files in multiple directories. Oh, and by the way: We got rid of the Python code. (mehr…)


Update für die TAOFirewall & IPv6

In einem vorangehenden Beitrag haben wir unser Skript präsentiert, das aus ein paar recht einfach aufgebauten Konfigurationsdateien Instruktionen für die Firewall des Linux-Kernels ableitet. Dabei gab es vor allem noch ein Problem, dass den Einsatz auf einem Xen Dom0 betraf: Durch den Aufbau des Skripts konnte es dazu kommen, dass eine DomU vollständig auf eine andere DomU zugreifen konnte, obwohl diese das verbot. Dieser Fehler wurde nun behoben. Statt, wie zuvor, gleich während der Abarbeitung der Regeln für eine DomU dieser einen Freifahrtschein für ausgehende Verbindungen zu verpassen, wird ihre IP nun auf einen Stapel gepackt, der erst nach Einfügen aller anderen Regeln abgearbeitet wird. (mehr…)


Automatisiertes Herunterfahren für Spezialfälle

Wir haben kürzlich ein Cisco Small Business NSS 326 angeschafft, um dessen Tauglichkeit für unsere Zwecke zu erkunden. Diese sind unter anderem Einbindung in unsere Domäne, um das NAS als CIFS-Ressource nutzen zu können. Um die Sicherheit unserer Daten zu gewähren ist es aber unbedingt notwendig, dass das NAS am USV hängt und im Ernstfall automatisch heruntergefahren wird. Zu diesem Zweck bringt das Cisco auch einen eingebauten Client mit, der eine SNMP-Trap oder eine per USB angeschlossene USV überwachen kann. Leider entspricht dies nicht ganz den Anforderungen unseres Systems, da wir zur USV-Überwachung bevorzugt einen unserer Server einsetzen. Ein wenig Graben in den Konfigurationsdateien fördert zutage, dass das NSS 326 sogar das gleiche Programm zur USV-Überwachung per USB nutzt wie es unsere Debian Machinen tun (apcupsd), dummerweise aber ohne die bei Debian einkompilierte Unterstützung für den Netzwerkdienst von apcupsd. (mehr…)