• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    Go
  • Created over 9 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

It's a secret.

Shush!

"shush" is a small tool that can be used to encrypt and decrypt secrets, using the AWS "Key Management Service" (KMS).

Usage

Encrypting things

Encrypt secrets like this:

shush encrypt KEY-ID-OR-ALIAS < secret.txt > secret.encrypted

The output of encrypt is Base64-encoded ciphertext.

KEY-ID-OR-ALIAS can be the id or ARN of a KMS master key, or alias prefixed by "alias/", or simply just the alias.

Plaintext input can also be provided on the command-line, e.g.

shush encrypt KEY-ID 'this is a secret' > secret.encrypted

With the -t or --trim flag, encrypt will automatically remove leading and trailing whitespace from the plaintext. This can be especially useful when piping input from commands which always leave a trailing newline.

shush encrypt -t KEY_ID ' I don't really need this whitespace ' > secret.encrypted

Decrypting things

Encrypted secrets are easy to decrypt, like this:

shush decrypt < secret.encrypted > secret.txt

There's no need to specify a KEY-ID here, as it's encoded in the ciphertext.

Finding the key that was used

If you want to see the ARN of the key used to encrypt the secret, add the --print-key flag

shush decrypt --print-key < secret.encrypted

Credentials and region

Appropriate AWS credentials must be provided by one of the mechanisms supported by aws-sdk-go, e.g. environment variables, or EC2 instance profile.

When used within EC2, shush selects the appropriate region automatically. Outside EC2, you'll need to specify it, via --region or by setting $AWS_DEFAULT_REGION.

Encryption context

"shush" supports KMS encryption contexts, which may be used to scope use of a key. The same encryption context must be provided when encrypting and decrypting.

shush --context app=myapp encrypt KEY-ID secret.txt > secret.encrypted
shush --context app=myapp decrypt < secret.encrypted > secret.txt

Limitations

"shush" can only encrypt small amounts of data; up to 4 KB.

Use as a command shim

"shush exec" is a command shim that makes it easy to use secrets transported via the (Unix) process environment. It decrypts any environment variables prefixed by "KMS_ENCRYPTED_", and executes a specified command.

For example:

$ export KMS_ENCRYPTED_DB_PASSWORD=$(shush encrypt alias/app-secrets 'seasame')
$ shush exec -- env | grep PASSWORD
KMS_ENCRYPTED_DB_PASSWORD=CiAbQLOo2VC4QTV/Ng986wsDSJ0srAe6oZnLyzRT6pDFWRKOAQEBAgB4G0CzqNlQuEE1fzYPfOsLA0idLKwHuqGZy8s0U+qQxVkAAABlMGMGCSqGSIb3DQEHBqBWMFQCAQAwTwYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAzfFR0tsHRq18JUhMcCARCAImvuMNYuHUut3BT7sZs9a31qWcmOBUBXYEsD+kx2GxUxBPE=
DB_PASSWORD=seasame

In this example, "shush exec":

  • found $KMS_ENCRYPTED_DB_PASSWORD in the environment
  • decrypted the contents
  • put the result in $DB_PASSWORD
  • executed env

"shush exec" works well as an entrypoint for Docker images, e.g.

# Include "shush" to decode KMS_ENCRYPTED_STUFF
ARG TARGETARCH
RUN curl -fsSL -o /usr/local/bin/shush \
    https://github.com/realestate-com-au/shush/releases/download/v1.5.4/shush_linux_${TARGETARCH} \
 && chmod +x /usr/local/bin/shush
ENTRYPOINT ["/usr/local/bin/shush", "exec", "--"]

Installation

Binaries for official releases may be downloaded from the releases page on GitHub.

If you want to compile it from source, try:

$ go get github.com/realestate-com-au/shush

For Unix/Linux users, you can install shush using the following command. You may want to change the version number in the command below from v1.5.4 to whichever version you want:

sudo curl -fsSL -o /usr/local/bin/shush \
    "https://github.com/realestate-com-au/shush/releases/download/v1.5.4/shush_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_/amd/' | sed 's/aarch/arm/')" \
 && sudo chmod +x /usr/local/bin/shush

Examples

Encrypt a password

Encrypt user input:

echo -n "Enter password: "
ENCRYPTED_PASSWORD=$(shush encrypt alias/app-secrets)

and later:

some-command --password $(shush decrypt "$ENCRYPTED_PASSWORD")

Bulk encryption of secrets

Encrypt some environment variables, as though they were arguments to env(1):

shush encrypt alias/app-secrets 'FOO=1 BAR=2' > secrets

and later:

env $(shush decrypt < secrets) some-command

See also

If you dislike 8Gb binary files, and happen to have a Ruby interpreter handy, "ssssh" is a drop-in replacement for "shush":

Or, you can just use bash, base64, and the AWS CLI:

base64 -d < secrets.encrypted > /tmp/secrets.bin
aws kms decrypt --ciphertext-blob fileb:///tmp/secrets.bin --output text --query Plaintext | base64 -d > secrets.txt

Releasing a new version

Please see docs/releasing.md

License

Copyright (c) 2019 REA Group Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributing

Source-code for shush is on Github.

More Repositories

1

stackup

a simple CLI and Ruby API for AWS CloudFormation
Ruby
97
star
2

credulous

AWS Credential management
Go
89
star
3

intro-to-docker

An introduction to Docker
JavaScript
56
star
4

sshephalopod

An SSH certificate authority framework to sign SSH pubkey requests based on SAML assertions
JavaScript
28
star
5

dfresh

Manage Docker image references
Go
24
star
6

akamai-rspec

Test your akamai configuration with rspec
Ruby
24
star
7

pact

This repository has moved to https://github.com/pact-foundation/pact-ruby
23
star
8

json-bourne-sfdx-cli

JSON Bourne (Salesforce CLI plugin). Source control your org reference data.
TypeScript
22
star
9

tagfish

a CLI tool to interact with Docker registries
Ruby
13
star
10

pact-jvm-provider-spring-mvc

A test runner to help to write provider pact tests with spring mvc
Scala
11
star
11

applied-scala

A series of exercises to apply your Scala knowledge
Scala
6
star
12

iso8601parser

Objective-C additions to convert an ISO 8601 string to an NSDate and back
Objective-C
6
star
13

newrelic-sequel

newrelic-sequel integration plugin
Ruby
5
star
14

soya

YAML/JSON file toolkit
Ruby
3
star
15

iam_syncr

CLI command that reads yaml and syncs Amazon roles/policies
Python
3
star
16

lir

Java
2
star
17

PerSectionLayout

Custom collection view layout
Objective-C
2
star
18

walkupinator

Python
1
star
19

blobby

Various ways of storing BLOBs
Ruby
1
star
20

dashmat

A dashboard framework written in Python
Python
1
star
21

pact-init

Generate the files required to use Pact in a consumer or provider project.
Ruby
1
star
22

sshephalopod-go

SSHephalopod v3, Lambda functions implemented in Go
Shell
1
star
23

json-bourne-sfdx-pkg

JSON Bourne (Salesforce Package). Source control your org reference data.
Apex
1
star
24

flux-examples

Some example of our usage of flux
JavaScript
1
star
25

cartodb-dashboard-python

Python API for CartoDB Dashboard
Python
1
star