Git Product home page Git Product logo

aws-env's Introduction

aws-env

build status

A small library and binary for securely handling secrets in environment variables on AWS. Supports KMS, SSM Parameter store and secrets manager. Inspired by ssm-env.

Usage

Both the library and binary versions of aws-env will loop through the environment and exchange any variables prefixed with sm://, ssm:// and kms:// with their secret value from Secrets manager, SSM Parameter store or KMS respectively. In order for this to work, the instance profile (EC2), task role (ECS), or execution role (Lambda) must have the correct privileges in order to retrive the secret values and/or decrypt the secret using KMS.

For instance:

  • export SECRETSMANAGER=sm://<path>
  • export PARAMETERSTORE=ssm://<path>
  • export KMSENCRYPTED=kms://<encrypted-secret>

Where <path> is the name of the secret in secrets manager or parameter store. aws-env will look up secrets in the region specified in the AWS_REGION or AWS_DEFAULT_REGION environment variables, and if they are both unset/empty it will contact the EC2 Metadata endpoint (if possible) and use the region where it is deployed.

Required IAM privileges:

  • Secrets manager: secretsmanager:GetSecretValue on the resource. And kms:Decrypt if not using the aws/secretsmanager key alias.
  • SSM Parameter store: ssm:GetParameter on the resource. kms:Decrypt on the KMS key used to encrypt the secret.
  • KMS: kms:Decrypt on the key used to encrypt the secret.

Binary

Install using homebrew:

brew install telia-oss/tap/aws-env

Or grab binary from the releases, and start your process with:

aws-env exec -- <command>

This will populate all the secrets in the environment, and hand over the process to your <command> with the same PID. The populated secrets are only made available to the <command> and 'disappear' when the process exits.

Library

Import the library and invoke it prior to parsing flags or reading environment variables:

package main

import (
	"github.com/aws/aws-sdk-go/aws/session"
	environment "github.com/telia-oss/aws-env"
)

func main() {
	// New AWS Session
	sess, err := session.NewSession()
	if err != nil {
		panic(fmt.Errorf("failed to create new aws session: %s", err))
	}

	// Populate secrets using aws-env
	env, err := environment.New(sess)
	if err != nil {
		panic(fmt.Errorf("failed to initialize aws-env: %s", err))
	}
	if err := env.Populate(); err != nil {
		panic(fmt.Errorf("failed to populate environment: %s", err))
	}
}

Security

There are a couple of things to keep in mind when using aws-env:

  • Spawned processes will inherit their parents environment by default. If your <command> spawns new processes they will inherit the environment with the secrets already populated, unless you hand-roll the environment for the new process.
  • The environment for a running process can be read by the root user (and yourself) after secrets have been populated by running cat /proc/<pid>/environ on Linux, and ps eww <pid> on OSX. However, if root or the spawning user is compromised a malicious user can just as easily fetch the secrets directly from the AWS API ¯\(ツ)

aws-env's People

Contributors

itsdalmo avatar

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.