zalando / go-keyring

Cross-platform keyring interface for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to run on docker

jonhadfield opened this issue · comments

UPDATE: I managed to find a solution as I wrote this issue but thought it worth sharing in case someone else comes across it


This is similar to #8 that discusses headless operation, but this may be docker specific.

Error
When running example code from: https://github.com/zalando/go-keyring#linux it returns error:
failed to unlock correct collection '/org/freedesktop/secrets/aliases/default'

Steps to reproduce

docker run --privileged -it ubuntu:latest /bin/bash
apt update && apt install -y curl dbus-x11 gnome-keyring git vim golang
go get github.com/zalando/go-keyring
vi test.go
add code example from: https://github.com/zalando/go-keyring#linux
go run test.go

gnome keyring is running

root@fed2abd272d4:/# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root      6320     1  0 15:09 ?        00:00:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
root      6322     1  0 15:09 ?        00:00:00 /usr/bin/gnome-keyring-daemon --start --foreground --components=secrets
...

It seems it is possible to run headless using a python keyring library: https://keyring.readthedocs.io/en/latest/#using-keyring-on-headless-linux-systems
So, I followed the examples:

root@fed2abd272d4:/# dbus-run-session -- sh
# gnome-keyring-daemon --unlock
password
GNOME_KEYRING_CONTROL=/root/.cache/keyring-HWJLG0
SSH_AUTH_SOCK=/root/.cache/keyring-HWJLG0/ssh
# go run test.go
2020/03/01 15:12:43 secret