• Stars
    star
    689
  • Rank 62,956 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-platform keyring interface for Go

Go Keyring library

Go Report Card GoDoc

go-keyring is an OS-agnostic library for setting, getting and deleting secrets from the system keyring. It supports OS X, Linux/BSD (dbus) and Windows.

go-keyring was created after its authors searched for, but couldn't find, a better alternative. It aims to simplify using statically linked binaries, which is cumbersome when relying on C bindings (as other keyring libraries do).

Potential Uses

If you're working with an application that needs to store user credentials locally on the user's machine, go-keyring might come in handy. For instance, if you are writing a CLI for an API that requires a username and password, you can store this information in the keyring instead of having the user type it on every invocation.

Dependencies

OS X

The OS X implementation depends on the /usr/bin/security binary for interfacing with the OS X keychain. It should be available by default.

Linux and *BSD

The Linux and *BSD implementation depends on the Secret Service dbus interface, which is provided by GNOME Keyring.

It's expected that the default collection login exists in the keyring, because it's the default in most distros. If it doesn't exist, you can create it through the keyring frontend program Seahorse:

  • Open seahorse
  • Go to File > New > Password Keyring
  • Click Continue
  • When asked for a name, use: login

Example Usage

How to set and get a secret from the keyring:

package main

import (
    "log"

    "github.com/zalando/go-keyring"
)

func main() {
    service := "my-app"
    user := "anon"
    password := "secret"

    // set password
    err := keyring.Set(service, user, password)
    if err != nil {
        log.Fatal(err)
    }

    // get password
    secret, err := keyring.Get(service, user)
    if err != nil {
        log.Fatal(err)
    }

    log.Println(secret)
}

Tests

Running tests

Running the tests is simple:

go test

Which OS you use does matter. If you're using Linux or BSD, it will test the implementation in keyring_unix.go. If running the tests on OS X, it will test the implementation in keyring_darwin.go.

Mocking

If you need to mock the keyring behavior for testing on systems without a keyring implementation you can call MockInit() which will replace the OS defined provider with an in-memory one.

package implementation

import (
    "testing"

    "github.com/zalando/go-keyring"
)

func TestMockedSetGet(t *testing.T) {
    keyring.MockInit()
    err := keyring.Set("service", "user", "password")
    if err != nil {
        t.Fatal(err)
    }

    p, err := keyring.Get("service", "user")
    if err != nil {
        t.Fatal(err)
    }

    if p != "password" {
        t.Error("password was not the expected string")
    }

}

Contributing/TODO

We welcome contributions from the community; please use CONTRIBUTING.md as your guidelines for getting started. Here are some items that we'd love help with:

  • The code base
  • Better test coverage

Please use GitHub issues as the starting point for contributions, new ideas and/or bug reports.

Contact

  • E-Mail: [email protected]
  • Security issues: Please send an email to the maintainers, and we'll try to get back to you within two workdays. If you don't hear back, send an email to [email protected] and someone will respond within five days max.

Contributors

Thanks to:

  • [your name here]

License

See LICENSE file.

More Repositories

1

patroni

A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes
Python
6,058
star
2

postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
Go
3,686
star
3

skipper

An HTTP router and reverse proxy for service composition, including use cases like Kubernetes Ingress
Go
3,005
star
4

zalenium

A flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard.
Java
2,380
star
5

restful-api-guidelines

A model set of guidelines for RESTful APIs and Events, created by Zalando
CSS
2,067
star
6

SwiftMonkey

A framework for doing randomised UI testing of iOS apps
Swift
1,945
star
7

tailor

A streaming layout service for front-end microservices
JavaScript
1,726
star
8

logbook

An extensible Java library for HTTP request and response logging
Java
1,684
star
9

tech-radar

Visualizing our technology choices
1,491
star
10

spilo

Highly available elephant herd: HA PostgreSQL cluster using Docker
Python
1,225
star
11

intellij-swagger

A plugin to help you easily edit Swagger and OpenAPI specification files inside IntelliJ IDEA
Java
1,160
star
12

problem-spring-web

A library for handling Problems in Spring Web MVC
Java
997
star
13

nakadi

A distributed event bus that implements a RESTful API abstraction on top of Kafka-like queues
Java
928
star
14

zally

A minimalistic, simple-to-use API linter
Kotlin
873
star
15

problem

A Java library that implements application/problem+json
Java
851
star
16

zalando-howto-open-source

Open Source guidance from Zalando, Europe's largest online fashion platform
799
star
17

gin-oauth2

Middleware for Gin Framework users who also want to use OAuth2
Go
556
star
18

zappr

An agent that enforces guidelines for your GitHub repositories
JavaScript
543
star
19

pg_view

Get a detailed, real-time view of your PostgreSQL database and system metrics
Python
488
star
20

engineering-principles

Our guidelines for building new applications and managing legacy systems
363
star
21

gulp-check-unused-css

A build tool for checking your HTML templates for unused CSS classes
CSS
359
star
22

zmon

Real-time monitoring of critical metrics & KPIs via elegant dashboards, Grafana3 visualizations & more
Shell
355
star
23

expan

Open-source Python library for statistical analysis of randomised control trials (A/B tests)
Python
325
star
24

PGObserver

A battle-tested, flexible & comprehensive monitoring solution for your PostgreSQL databases
Python
315
star
25

riptide

Client-side response routing for Spring
Java
285
star
26

jackson-datatype-money

Extension module to properly support datatypes of javax.money
Java
240
star
27

grafter

Grafter is a library to configure and wire Scala applications
Scala
240
star
28

opentracing-toolbox

Best-of-breed OpenTracing utilities, instrumentations and extensions
Java
178
star
29

elm-street-404

A fun WebGL game built with Elm
Elm
176
star
30

tokens

Java library for conveniently verifying and storing OAuth 2.0 service access tokens
Java
169
star
31

innkeeper

Simple route management API for Skipper
Scala
166
star
32

public-presentations

List of public talks by Zalando Tech: meetup presentations, recorded conference talks, slides
165
star
33

python-nsenter

Enter kernel namespaces from Python
Python
139
star
34

dress-code

The official style guide and framework for all Zalando Brand Solutions products
CSS
129
star
35

faux-pas

A library that simplifies error handling for Functional Programming in Java
Java
128
star
36

beard

A lightweight, logicless templating engine, written in Scala and inspired by Mustache
Scala
121
star
37

friboo

Utility library for writing microservices in Clojure, with support for Swagger and OAuth
Clojure
117
star
38

spring-cloud-config-aws-kms

Spring Cloud Config add-on that provides encryption via AWS KMS
Java
99
star
39

zalando.github.io

Open Source Documentation and guidelines for Zalando developers
HTML
80
star
40

failsafe-actuator

Endpoint library for the failsafe framework
Java
53
star
41

package-build

A toolset for building system packages using Docker and fpm-cookery
Ruby
35
star
42

ghe-backup

Github Enterprise backup at ZalandoTech (Kubernetes, AWS, Docker)
Shell
30
star
43

rds-health

discover anomalies, performance issues and optimization within AWS RDS
Go
18
star
44

backstage-plugin-api-linter

API Linter is a quality assurance tool that checks the compliance of API's specifications to Zalando's API rules.
TypeScript
12
star
45

.github

Standard github health files
1
star