Giter VIP home page Giter VIP logo

shush's Introduction

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.5/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.5 to whichever version you want:

sudo curl -fsSL -o /usr/local/bin/shush \
    "https://github.com/realestate-com-au/shush/releases/download/v1.5.5/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.

shush's People

Contributors

ajc avatar blankll avatar gazwald avatar grantbeattie avatar janaz avatar lukeck avatar mdub avatar nadnerb avatar rbvigilante avatar spjwebster avatar thetaylorhicks avatar tigris avatar toothbrush avatar trembylene avatar wjlow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shush's Issues

Arguments to the command after `shush exec` are parsed by shush instead

When I do this:

shush exec ls -la

I get

Incorrect Usage: flag provided but not defined: -la

NAME:
   shush exec - Execute a command

USAGE:
   shush exec [command options] [arguments...]

OPTIONS:
   --prefix value  environment variable prefix (default: "KMS_ENCRYPTED_")

I would expect shush to know that any command-line options passed after the command belong to the command and not to shush itself.

i.e. I would expect shush exec ls -la to do the same as shush exec -- ls -la

Shush lacks support for ECS task roles

Hi @mdub we are using shush inside a ecs task container and it does not seem to be able to get access to what that ecs task role allows.

I know from previous attempts that if the AWS SDK is not new enough, ecs task roles are not supported. Do you know if the go AWS SDK support ecs tasks roles? Have you or anyone else had luck with sush 1.3.0 and ecs task roles?

KMS ARN key syntax broken in version 1.4.0

Version 1.4.0 added the feature 'Allows aliases to be specified without alias/, saving those precious key-strokes'. The documentation says 'KEY-ID-OR-ALIAS can be the id or ARN of a KMS master key'. However, now the syntax that I am using in version 1.3.4, arn:aws:kms:<region>:<accid>:key/<key-id> no longer works, saying it is an invalid alias. <key-id> by itself works fine but I prefer to just copy the whole ARN from the KMS console. This means that key now can be id or alias but not ARN so this must be a regression.

I think the problem is that the newly added line main.go/50 assumes the key is either a UUID or alias but forgets about ARN.

Provide arm64 build

Hey folks, i'm investigating moving some of our workload to AWS Graviton (aka arm64) instances, and we use Dockerised shush a lot.

I grabbed a checkout this repo master and did a docker build . on an arm64 instance, and it all worked perfectly. I could contribute a patch at some point but i thought i'd make this issue as a reminder/placeholder. Also, i'm unfamiliar with REA's build pipeline which makes it a bit harder since i think the big change will be there.

Thanks for providing this tool! πŸ™Œ

Checksums for Shush binaries.

Hi there,

I was wondering whether it would be possible for checksums to be provided with Shush releases so that we're able to verify the contents before using the binary.

Kind of similar to this project: https://github.com/weaveworks/eksctl/releases

Our security team gave us a recommendation that we should verify the contents of binaries prior to making them widely available within our organisation.

Thank you so much for Shush, we use it everyday and we love it ❀️

Usage error describes `--region` but `--region` flag doesn't work

# shush --version
shush version 1.3.1

# shush encrypt alias/app-secrets
ERROR: please specify region (--region or $AWS_DEFAULT_REGION)

# shush encrypt --region ap-southeast-2 alias/app-secrets
Incorrect Usage: flag provided but not defined: -region

NAME:
   shush encrypt - Encrypt with a KMS key

USAGE:
   shush encrypt [arguments...]

Chomp the input, and warn if something was chomped

It is quite common to pipe a string to shush encrypt via echo and forget the -n. It'd be nice to DWIM in this scenario, perhaps with a warning.

I understand this changes behaviour and it would now be impossible to encrypt a string with a newline on the end. We could cross that bridge when it comes, or add in a flag, or not chomp but just print the warning, or document it and you could put 2 newlines to get 1 newline in there πŸ˜„

Error text is output on STDOUT, not STDERR

When I run the following command:

shush encrypt --region ap-southeast-2 key-id

I get a message on STDOUT informing me my usage is incorrect. This text should go on STDERR.

Also the command returns with a success exit status code, so I didn't pick up the error until later.

shush decryption takes a long time on amazonlinux:latest

Hello,

I'm using shush_linux_amd64 version 1.4.X on the latest amazonlinux:latest docker image and have noticed that decryption takes roughly 20 seconds on a container with 2cpu 4GB memory. Version 1.3.4 returns a result instantly.

Test steps:

  • shush encrypt KEY-ID "Test" > encrypted
  • shush decrypt < encrypted

Timings:

v1.3.4

real	0m0.063s
user	0m0.031s
sys	0m0.004s

v1.4.0

real	0m20.400s
user	0m0.046s
sys	0m0.000s

v1.4.1

real	0m20.394s
user	0m0.037s
sys	0m0.008s

What are shush's core dependencies? Perhaps I need to update those in my docker image.

Thank you

Struggling to compile with Go 1.13 and 1.14

I apologise upfront if i'm being dense, because i'm not much of a Golang programmer. I am on macOS 10.14.6 and used Homebrew to brew install go (gives me Golang 1.14), and when that didn't work, brew install [email protected].

In both cases, running the recommended go get github.com/realestate-com-au/shush gives these errors:

# github.com/realestate-com-au/shush
go/src/github.com/realestate-com-au/shush/main.go:22:22: cannot use cli.StringSliceFlag literal (type cli.StringSliceFlag) as type cli.Flag in array or slice literal:
	cli.StringSliceFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/realestate-com-au/shush/main.go:25:4: unknown field 'EnvVar' in struct literal of type cli.StringSliceFlag
go/src/github.com/realestate-com-au/shush/main.go:27:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/realestate-com-au/shush/main.go:30:4: unknown field 'EnvVar' in struct literal of type cli.StringFlag
go/src/github.com/realestate-com-au/shush/main.go:39:17: cannot use cli.BoolFlag literal (type cli.BoolFlag) as type cli.Flag in array or slice literal:
	cli.BoolFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/realestate-com-au/shush/main.go:44:4: cannot use func literal (type func(*cli.Context)) as type cli.ActionFunc in field value
go/src/github.com/realestate-com-au/shush/main.go:45:11: invalid argument c.Args() (type cli.Args) for len
go/src/github.com/realestate-com-au/shush/main.go:57:7: c.GlobalString undefined (type *cli.Context has no field or method GlobalString)
go/src/github.com/realestate-com-au/shush/main.go:58:7: c.GlobalStringSlice undefined (type *cli.Context has no field or method GlobalStringSlice)
go/src/github.com/realestate-com-au/shush/main.go:63:46: cannot slice c.Args() (type cli.Args)
go/src/github.com/realestate-com-au/shush/main.go:44:4: too many errors

Am i doing something wrong?

Idea: big flashing warning on "dubious" whitespace

G'day! I'm opening this issue as a bit of a straw man discussion spot, because while i'm happy to provide a PR, i'd like to discuss the problem and some potential improvements with maintainers first.

The problem

Basically, colleagues often get bitten by the following (probably extremely well-known) issue:

$ echo "MYT0K3N" | shush encrypt alias/foo

Forgetting echo -n or shush encrypt --trim leaves one with an encrypted token that isn't accepted by a lot of programs, due to the trailing newline. The feedback cycle tends to be slow and annoying because it'll only get noticed when the app is deployed and tries to use the secret.

Some potential improvements

  1. Warn clearly on stderr, when encrypting, if input != trim(input). This might be a spurious warning, but i can't think of many instances where you really need surrounding whitespace.
  2. Be a bit smarter when decrypting. This one might be a bit more controversial because it's a behavioural change – but hear me out πŸ˜…. I believe it'd be reasonable to special-case a trailing \n when decrypting. I would distinguish two cases:
    a. The trailing character is \n, and the string contains no other whitespace characters. In this case, trim the \n.
    b. The trailing character is \n, but there are whitespace characters elsewhere in the string too. In this case, return the string verbatim.

Especially for 2 i could imagine it'd be worth making a clear note in the CHANGELOG and bumping at least the minor version, perhaps also adding a flag to keep old behaviour. My belief is that in 99.99% of cases approach 2 would be perfectly fine, but i'm keen to hear if the maintainers are more creative than i in coming up with edge-cases that make this undesirable.

Option 1 though i imagine could be implemented today with little concern, right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.