• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    Shell
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

[DEPRECATED] Simple local encrypted credential management with GPG 🔐

creds

Circle CI

Simple encrypted credential management with GPG.

Rationale

I have a lot of different sensitive environment variables to juggle. API keys, tokens, usernames, passwords, etc. I had been using simple shell scripts to set environment variables when needed, eg:

$ cat ~/Dropbox/creds/aws-work.sh
export AWS_ACCESS_KEY_ID=foo
export AWS_SECRET_ACCESS_KEY=bar

$ source ~/Dropbox/creds/aws-work.sh
$ echo $AWS_ACCESS_KEY_ID
foo

$ s3cmd ...

But I don't like storing these in plaintext on Dropbox.

Thus, how about a simple way to encrypt/decrypt these as needed with GPG?

Requirements

  • bash >= 3.2
  • gpg (tested with 2.0 and 2.1 but might work with 1.4)

Tested on Mac OSX 10.11 with gpg2 installed from homebrew, but should work on most platforms with the above requirements.

Install

Several options for installation, in order of recommendation:

  • Using homebrew, install latest tagged release:
$ brew install joemiller/taps/creds
  • Using homebrew, install master branch:
$ brew install joemiller/taps/creds --HEAD
  • Or, clone and run make install:
$ git clone https://github.com/joemiller/creds.git
$ cd creds ; make install
  • Or, curl install!
$ curl https://raw.githubusercontent.com/joemiller/creds/master/creds >./creds
$ chmod +x ./creds

If you're on OSX you may need to install GPG and create a keypair. You have a few options:

Run gpg2 --gen-key to generate a new keypair if you don't already have one.

Uninstall

  • If installed via homebrew: brew uninstall creds
  • If installed from make install: Run make uninstall

Usage

$ creds -h
usage: creds [-h|--help] [-v|--version] <subcommand> [arguments]

Simple encrypted credential file management with GPG.

The most commonly used subcommands are:

  list                  list available credential stores
  edit                  edit a credential store
  import                import an existing file into a new credential store
  set                   display commands to set credentials from a credential store
  unset                 display commands to unset credentials from a credential store

Configuration

creds reads configuration from ~/.credsrc file, eg:

CREDS_DIR="$HOME/Dropbox/creds"
[email protected]

Required variables:

  • CREDS_DIR: A directory where encrypted credentials files will be stored.
  • GPG_KEY: The GPG key to use for encrypting credentials. Use gpg -K to list keys.

Optional variables:

  • GPG_BIN: Path to GPG bin to use. If not set, creds will look for gpg2 and gpg in the path, preferring gpg2 if found.

Creating a new credential store / Editing existing credential store

The edit command will create a new credential store if one does not exist yet.

The format of credential stores is single line KEY=val environment variable style lines. All other lines will be ignored when using the set and unset commands.

$ creds edit aws-work

< .. $EDITOR launches .. >
AWS_ACCESS_KEY_ID=foo
AWS_SECRET_ACCESS_KEY=bar

Listing credential stores

$ creds list
Credential storage dir: /Users/joe/Dropbox/creds
- aws-work
- misc
- digitalocean

Setting/Loading

Use the set command to print the contents of a credential store.

Usually you will wrap this with eval to set the credentials in your shell's environment.

$ creds set aws-work
 export AWS_ACCESS_KEY_ID=foo
 export AWS_SECRET_ACCESS_KEY=bar

You can then copy and paste to set these vars in your current shell or do it in one comand:

$ eval "$(creds set aws-work)"
$ echo $AWS_ACCESS_KEY_ID
foo

The export VAR commands generated by creds set will be prefixed with a single whitespace character. If you're using zsh or bash as your shell and HISTCONTROL= env var contains ignorespace this will prevent the export statements (and your secrets) from being stored in the command history. This is the default setting in bash and zsh so it's probably already set correctly.

Running a command with environment vars from a credential store

Use the run command to load environment vars from a credential store and execute a command with that environment.

Environment vars are added to the current environment so existing vars will also be available to the command.

$ creds run aws-work env | grep AWS
AWS_ACCESS_KEY_ID=foo
AWS_SECRET_ACCESS_KEY=bar

$ creds run aws-work s3cmd ls s3://some-bucket

Similar to, and inspired by, the excellent envchain util.

Unsetting

Use the unset command to unset the credentials. This should also be used with eval.

$ creds unset aws-work
unset AWS_ACCESS_KEY_ID

$ eval $(creds unset aws-work)

Importing an existing plaintext file

$ cat ./circleci.keys
CIRCLE_TOKEN=foo

$ creds import ./circleci.keys
Encrypting './circleci.keys' to '/Users/joe/Dropbox/creds/circleci.keys.gpg'

Integration with direnv

creds is a great companion to direnv.

Place one or more eval statements in your .envrc file:

$ mkdir some-aws-project
$ echo 'eval "$(creds set aws-personal)"' >some-aws-project/.envrc

$ cd some-aws-project
direnv: loading .envrc
direnv: export +AMAZON_ACCESS_KEY_ID +AMAZON_SECRET_KEY_ID

$ echo $AMAZON_ACCESS_KEY_ID
ABCDEFGHIJKLMNOP

$ cd ..
direnv: unloading

$ echo $AMAZON_ACCESS_KEY_ID
$

direnv is able to follow all of the env vars set by creds so when you leave the directory they will be automatically unloaded.

Troubleshooting

  • If you see an error such as the following (ambiguous) error during creds edit:
   gpg: [stdin]: encryption failed: Unusable public key

try using gpg --edit <key_id> (or gpg2 --edit-key <key_id for GPG 2.1+) and marking the key as "ultimately trusted".

  • You may use variables in assignment for other variables in a cred set but you will need to enclose the eval statement with double quotes, example:
# creds edit foo
AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOP
AMAZON_KEY_ID=$AWS_ACCESS_KEY_ID

$ eval $(creds set foo)
$ env | grep KEY_ID
AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOP
AMAZON_KEY_ID=

$ eval "$(creds set foo)"
$ env | grep KEY_ID
AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOP
AMAZON_KEY_ID=ABCDEFGHIJKLMNOP

Developing & Testing

Requirements:

  • bats - (brew install bats)
  • shellcheck - (brew install shellcheck)

Run make help to get a list of tasks.

TODO

  • maybe make it work with the keybase commands too? but don't introduce a dependency on keybase.
  • Rewrite in go, optionally using gpg library? Unlikely as this is intended to be a simple tool and already has very few external dependencies (only bash 3.2+ and gpg) but it would be a fun rewrite.

Author

joe miller, 2016

More Repositories

1

collectd-graphite

collectd plugin for sending data to graphite
Perl
131
star
2

vault-token-helper

@Hashicorp Vault Token Helper for macOS, Linux and Windows with support for secure token storage and multiple Vault servers 🔐
Go
104
star
3

bunchr

A Ruby/Rake DSL for building and packaging software into omnibus-style packages
Ruby
86
star
4

dns_compare

Testing tool for DNS migrations. Compare data from a BIND zone file to data returned by a DNS server.
Python
61
star
5

puppet-graphite_event

A puppet report processor for sending event data to graphite whenever puppet modifies a resource on a host.
Ruby
38
star
6

puppet-newrelic

puppet module for installing the New Relic server monitor
Puppet
33
star
7

chef-handler-profiler

a simple Chef profiler for reporting how long each recipe took to execute
Ruby
32
star
8

git-flux

a Git workflow designed with "infrastructure as code repositories" in mind (EXPERIMENTAL!)
Shell
32
star
9

amqpcat

Netcat-like tool for reading and writing messages to AMQP message brokers
Ruby
30
star
10

spark-ping

a ping "GUI" for the command line that prints sparkline graphs
Ruby
30
star
11

jenkins-statsd-plugin

send results and durations from jenkins jobs to a statsd server
Java
29
star
12

go-init-sentinel

A minimal init system for containers capable of watching files for changes and sending signals for reload, shutdown, etc
Go
22
star
13

docker-htpc

my dockerized htpc apps
Shell
20
star
14

workstation-bootstrap

chef-solo recipes for bootstrapping my mac osx workstations
Ruby
20
star
15

yk-attest-verify

Verify and assert policy on YubiKey attestation certificates
Go
17
star
16

docker-tail

A pretty tail -f for docker logs from multiple containers
Shell
17
star
17

dotfiles

my dotfiles
Shell
16
star
18

gitosis-ng

Yet another gitosis fork with some new features allowing admins and users to manage the repos via simple commands (no longer active, use gitolite instead!!!)
Python
15
star
19

aws-cf-private-streaming-tools

Ruby CLI tools for creating and modifying Amazon Cloudfront Private Streaming Distrubitions and Origin-Access-IDs
Ruby
15
star
20

chef-openbsd

Chef LWRPs (package, service) for OpenBSD
Ruby
14
star
21

hudson_wrapper

Shell script for wrapping External Hudson jobs (eg: cron jobs) and posting their results to Hudson
Shell
12
star
22

kubits

a collection of small utilities for working with kubernetes clusters
Shell
11
star
23

certin

Go lib (and CLI) for quick creation of TLS keys and certificates for use in tests
Go
10
star
24

joemiller.me-intro-to-sensu

files related to 'intro to sensu' article on joemiller.me
Shell
10
star
25

taskhammer

Hammerspoon module ("Spoon") for running scripts from the macOS menu bar
Lua
6
star
26

sensu-tests

Integration test suite for Sensu CM and packages
Ruby
6
star
27

mac-to-vendor

Simple, curl'able service for resolving MAC addresses to vendor names
Ruby
6
star
28

xbmc-script-sort-movies-by-file-date

XBMC addon for sorting your Movie Library by the creation date from the movie files
Python
6
star
29

vault-gpg-token-helper

[DEPRECATED. See joemiller/vault-token-helper instead] 🗝A @hashicorp Vault token helper for encrypting tokens with GPG (+ yubikey)
Go
6
star
30

twitter-tools-wordpress

twitter-tools plugin for wordpress (this fork adds support for native Retweets)
PHP
5
star
31

gbookmarks-to-delicious

simple script to help import Google Bookmark's into Del.icio.us, including _all_ tag data
Ruby
4
star
32

vault-gcp-cloud-kms-pki

Fork of the Vault PKI Secrets plugin with support for CA keys backed by Google Cloud KMS
Go
4
star
33

groovy-statsdclient

A statsd client written in groovy
Groovy
4
star
34

bats-chef-handler

Similar to minitest-chef-handler, find and execute BATS tests at the end of a chef run. http://joemiller.me
Ruby
3
star
35

sensu-cli

command-line interface to the Sensu REST API
Ruby
3
star
36

chef-sensu_repo

chef recipes for managing sensu apt and yum repos
Ruby
3
star
37

go-jail

[experiment] simple wrapper for executing sandboxed processes using Seccomp and capabilities filters
Go
2
star
38

git-hooks

various git hooks
2
star
39

logstash-filter-hex_to_ascii

logstash plugin for converting hex-encoded ascii strings back to ascii (eg: auditd logs)
Ruby
2
star
40

goreleaser-gon-poc

experiment using goreleaser with gon for codesigning and notarizing macOS Go apps
HCL
2
star
41

dugar

Get the total size of images in a Google Artifact Registry docker repository.
Go
2
star
42

chef-vagrant

chef cookbook for installing vagrant and virtualbox
Ruby
1
star
43

openvpn-notifier

send pushover.net notification when openvpn clients connect
Go
1
star
44

simple-uptime-checker

WIP. simple http uptime checker experiment, implemented as aws lambdas
HCL
1
star
45

sinatra-template

a simple template for sinatra apps that I like to use. Your mileage may vary.
Ruby
1
star
46

chef-sensu_jenkins

chef recipes for managing sensu jenkins build/test server
Ruby
1
star
47

sensu-build-box

scripts for managing sensu build/CI box via chef-solo
Ruby
1
star
48

gcp-iam-lookup

Search Google Cloud IAM roles that contain specific permissions.
Go
1
star
49

prefixed-api-key

Go implementation of seamapi/prefixed-api-key
Go
1
star
50

r509-validity-cadb

A Validity::Checker for r509, implemented with an OpenSSL CA DB loader backend
Ruby
1
star
51

puppet-url-functions

custom functions for manipulating URLs in puppet manifests and templates
Ruby
1
star
52

suicide-sidecar

kubernetes sidecar to watch for file changes (such as secretVolumes) and trigger pod restarts
Shell
1
star
53

thin-benchmarks

some benchmarks with thin and sinatra
Shell
1
star
54

blog

blog source (hugo)
CSS
1
star
55

openssh-u2f

openssh docker image built with U2F support for testing out the new key type
Dockerfile
1
star