Coder Social home page Coder Social logo

envsec's Introduction

Envsec

Build Status

Envsec (es) encrypts and decrypts environment variables using AWS KMS. When encrypting it passes the variable values to KMS, let's the service encrypt them and prefixes the variables with a configurable prefix (default: ENVSEC_). When decrypting, it executes a given process and passes the decrypted environment variables (without the prefix) to the new process.

The usage of KMS allows authorized operators to encrypt configuration secrets and submit them to version control, ECS task definitions and other sources of configuration truths while the decryption operation can be bound to different principals, e.g. the role of an EC2 instance's instance profile.

Formats

es can output several formats when encrypting environment variables.

CloudFormation

Triggered with -f cloudformation, this exports variables in a form suitable for AWS CloudFormation stacks.

Example:

"foo": {
  "Default": "bar",
  "Type": "String"
}

Terraform

Triggered with -f terraform, this exports variables in a form suitable for Hashicorp's Terraform.

Example:

variable "foo" {
  type    = "string"
  default = "bar"
}

Shell

Triggered with -f shell (the default), this exports variables in a form suitable for shell exports.

Example:

foo=bar

Example

This example uses es in combination with envplate to replace confidential variable references in the following config file:

secret1 = "${SECRET1}"
secret2 = "${SECRET2}"

The demo script examples/test.sh now

  1. exports the secrets in plaintext to the environment
  • calls es with the ARN of an AWS KMS key which exports the now encrypted variables as key-value-pairs, prepends an export to each key-value pair and writes the result to a temporary file called test.envs
  • unsets the plaintext secrets from the environment
  • exports the encrypted environment variables into the environment
  • calls es which decrypts the environment variables, execs envplate which replaces the variable references with the correct values and eventually execs cat test.config
BINARY=../build/darwin_amd64/es-bin

export SECRET1=opensesame
export SECRET2=foreyesonly

$BINARY enc --arn=arn:aws:kms:eu-west-1:1234:key/e17e953c-d06e-4a4e-916b-54c681ca80d4 SECRET1 SECRET2 | sed  "s/^/export /g" > test.envs

unset SECRET1
unset SECRET2

eval $(cat test.envs)

$BINARY dec --region eu-west-1 -- /usr/local/bin/ep -- cat test.envs

The result is the following config file:

secret1 = "opensesame"
secret2 = "foreyesonly"

Integration test and CloudFormation template

The integration tests in kms_test.go utilize a test environment described using a tacks template. At it's core (starting at line 14) the file example/cloudformation.yml contains:

  1. two roles (encrypt and decrypt)
  • a user that can assume those roles
  • a keypair for that user
  • a KMS key with a key policy that ties encryption and decryption rights to the two roles; in order to be able to delete the key together with the stack, full access is given to the account the key was created in

In a production setup the roles (or rather the underlying policies) would be tied to an instance profile of an EC2 instance (for decrypting) and potentially to the group of developers / operators relevant to this project (for encrypting).

envsec's People

Contributors

brotbert avatar mavogel avatar willejs avatar yawn 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

Watchers

 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

envsec's Issues

CloudFormation parameter length limit

We should check that the encrypted value using the CloudFormation formatter does not exceed 4096 bytes causing an runtime error.

Another solution: Splitting the value into multiple parameters of the maximum size (recommended by CloudFormation) and envsec handling the join transparently.

Include better help messages

They should include an explination of the format for running commands (eg. where does the -- ep -- cat filename come from, and how do you change this)

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.