Unlock gnome-keyring from a temp dbus session

1.2k views Asked by At

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:

  1. Start a new dbus session
  2. Unlock the gnome-keyring in that dbus session
  3. Extract the credentials from the keyring
  4. 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?

1

There are 1 answers

0
Philip Withnall On

You will either need to spawn a second program in your project beneath dbus-run-session, or you will need to use something other than dbus-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 own dbus-daemon instance from your top-level program, replicating some of the behaviour of dbus-run-session.

Typically this would involve:

  • Providing a dbus-daemon configuration file to use.
  • Running dbus-daemon --config-file=path/to/config --address=path/to/socket --nofork.
  • Setting DBUS_SESSION_BUS_ADDRESS=unix:path/to/socket in your program’s environment before doing anything with the keyring.
  • Doing whatever you need to with the keyring.
  • Terminating the dbus-daemon subprocess.