
I ve written a simple application which will automatically extract media from CDs and DVDs when they are inserted into the drive attached to my server. This makes it easy for me to compile all of my media in one place and access it anytime I like. The application uses the modern
udisks API, formerly known as
DeviceKit-disks, and I wrote it in part to learn get some experience working with
udisks (which, it turns out, is rather nice indeed).
Naturally, I wanted to grant this application the privileges necessary to mount, unmount and eject removable media. The server is headless, and the application runs as a daemon, so this would require explicit configuration. udisks uses PolicyKit for authorization, so I expected this to be very simple to do. In fact, it is very simple, but finding out exactly how to do it wasn t quite so easy.
The Internet is full of web pages which recommend editing
/etc/PolicyKit/PolicyKit.conf. As far as I can tell, nothing pays attention to this file anymore, and all of these instructions have been rendered meaningless. My system was also full of tools like
polkit-auth, from the apparently-obsolete
policykit package, which kept their configuration in some other ignored place, i.e.
/var/lib/PolicyKit. It seems the configuration system has been through a revolution or two recently.
In Ubuntu 10.04, the right place to configure these things seems to be
/var/lib/polkit-1/localauthority, and this is documented in
pklocalauthority(8). Authorization can be tested using
pkcheck(1), and the default policy can be examined using
pkaction(1).
I solved my problem by creating a file in
/var/lib/polkit-1/localauthority/50-local.d with a
.pkla extension with the following contents:
[Access to removable media for the media group]
Identity=unix-group:media
Action=org.freedesktop.udisks.drive-eject;org.freedesktop.udisks.filesystem-mount
ResultAny=yes
This took effect immediately and did exactly what I needed. I lost quite some time trying to figure out why the other methods weren t working, so perhaps this post will save the next person a bit of time. It may also inspire some gratitude for the infrastructure which makes all of this work automatically for more typical usage scenarios, so that most people don t need to worry about any of this.
Along the way, I whipped up a
patch to add a
--eject option to the handy
udisks(1) tool, which made it easier for me to test along the way.