I'm trying to write a python application that can unlock gnome-keyring
from a text-only system (headless machine) and retrieve the credentials. I have the gnome-keyring
package installed in this machine.
Basically, my application will:
- Start a new dbus session
- Unlock the gnome-keyring in that dbus session
- Extract the credentials from the keyring
- Destroy the dbus session bus
I'm trying to follow this tutorial: https://pypi.org/project/keyring/#using-keyring-on-headless-linux-systems
I tried reading: Python DBUS SESSION_BUS - X11 dependency but, the OP uses dbus-launch
instead of the dbus-run-session
. The original man page for dbus-launch
says to use 'dbus-run-session` for text-only systems.
If I start a new dbus session using python's subprocess, how can I run the step #2 in the same dbus-session?
You will either need to spawn a second program in your project beneath
dbus-run-session
, or you will need to use something other thandbus-run-session
to run your own session bus.dbus-run-session
is designed to run a single program in its own bus; once that program terminates, the bus is shut down. So either you need to provide a second program which does steps 2 and 3 from your plan, or you need to more explicitly set up and tear down your owndbus-daemon
instance from your top-level program, replicating some of the behaviour ofdbus-run-session
.Typically this would involve:
dbus-daemon
configuration file to use.dbus-daemon --config-file=path/to/config --address=path/to/socket --nofork
.DBUS_SESSION_BUS_ADDRESS=unix:path/to/socket
in your program’s environment before doing anything with the keyring.dbus-daemon
subprocess.