Code Monkey home page Code Monkey logo

aws-secrets's Introduction

aws-secrets

Manage secrets on AWS instances with KMS encryption, IAM roles and S3 storage.

Synopsis

aws-secrets requires aws-cli version 1.8 or later.

Installation:

git clone -o github https://github.com/promptworks/aws-secrets
cd aws-secrets
make install
# (or just copy `bin/*` to somewhere in your PATH)

Set up AWS resources for an application named quizzo:

aws-secrets-init-resources quizzo

Make some secrets, send them to the cloud and the AWS S3 bucket:

echo "SECRET=xyzzy" > quizzo-env
aws-secrets-send quizzo quizzo-env

Each send overwrites the existing secrets in the store.

Retrieve the secrets and print them to STDOUT:

aws-secrets-get quizzo

The last one can be run by:

  • users in the quizzo-manage-secrets group
  • programs on EC2 instances which have been started with the quizzo-secrets IAM profile

To start an EC2 instance with the quizzo-secrets IAM profile from the CLI:

aws ec2 run-instances ...--iam-instance-profile Name=quizzo-secrets

To start an ECS cluster with the quizzo IAM profile, select quizzo-secrets-instances from the Container Instance IAM Role selection on the Create Cluster screen. Or you could also start an ECS task with the quizzo IAM role by selecting it in your Task Definition.

Description

This repository contains a handful of scripts:

  • aws-secrets-init-resources
  • aws-secrets-send
  • aws-secrets-get
  • aws-secrets-run-in-env
  • aws-secrets-purge-resources

They can be used to set up and maintain a file containing environment variables which can then be used by an application running on an Amazon EC2 instance. They can also be used when running an application in a docker container on an EC2 instance.

aws-secrets-init-resources creates the following AWS resources:

  • A customer master key (CMK).
  • An alias for the key.
  • An S3 bucket.
  • A few roles to be used by an instance profile: one for S3 access, one for decryption with the CMK.
  • A group with access policies to get/put to S3 and encrypt/decrypt with the CMK.

aws-secrets-send takes an app name and a filename as input and uses the CMK to encrypt it, then sends it to an object in the S3 bucket.

aws-secrets-get take an app name as input, and uses it to construct the name of the S3 bucket and object. It then retrieves and decrypts the file and prints it to stdout.

If the file contains lines of the form:

X=yyyy

then exporting the output will put those variables into the current environment. i.e.

export `aws-secrets-get quizzo`

aws-secrets-run-in-env is a short script that does the above and then executes another program, with its arguments.

aws-secrets-purge-resources removes the resources associated with this app which were created by aws-secrets-init-resources.

Examples

To use this in a docker file, add a line like this:

CMD ["aws-secrets-run-in-env", "quizzo", "start-quizzo"]

where "quizzo" is the name of your app, and "start-quizzo" is the script that starts the app.

Notes

  • These scripts depend on having the AWS CLI installed. (See references below)

  • Changing AWS_DEFAULT_REGION (or the aws-cli configuration) will effect the region used for API calls.

  • Changing AWS_SECRETS_BUCKET_REGION will specify the region in which the S3 bucket is created.

References

aws-secrets's People

Contributors

bduggan avatar di avatar gsterndale avatar jamtur01 avatar jgarber 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

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

aws-secrets's Issues

Support multiple regions for init

When executing the following with AWS_DEFAULT_REGION or the profile region either empty or anything other than us-east-1 I receive the error below.

aws-secrets-init-resources promptworks_test

An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

Check for awscli version

This depends on a specific version of awscli, otherwise we get a "bad jmespath expression" due to single quotes:

$ ./bin/aws-secrets-init-resources quizzo
Initializing resources for quizzo.

Bad value for --query Aliases[?AliasName == 'alias/quizzo-secrets'] | [0].TargetKeyId: Bad jmespath expression: Unknown character:
Aliases[?AliasName == 'alias/quizzo-secrets'] | [0].TargetKeyId

We should explicitly check the awscli version before trying to perform any actions.

After some testing, it seems like awscli>=1.8.0 is fine.

License

Hi - is there a license associated with this?
(just writing an arch PKGBUILD)

Service trusts assume EC2 only

Currently the IAM role is hardcoded for:

	{
	  "Id": "key-$app-secrets-instance-trust-policy",
	  "Version": "2012-10-17",
	  "Statement": [
	    {
	      "Effect": "Allow",
	      "Principal": { "Service" : "ec2.amazonaws.com" },
	      "Action": "sts:AssumeRole"
	    }
	  ]
	}

This means it can't be attached to an ECS task definition which requires:

	{
	  "Id": "key-$app-secrets-instance-trust-policy",
	  "Version": "2012-10-17",
	  "Statement": [
	    {
	      "Effect": "Allow",
	      "Principal": { "Service" : "ecs-tasks.amazonaws.com" },
	      "Action": "sts:AssumeRole"
	    }
	  ]
	}

This should probably be configurable or addititive.

base64 varies on different platforms

The base64 binary that ships with alpine linux considers --decode an invalid option. Instead, it prefers the short flag: -d.

Simply changing to -d would make the script incompatible with Mac OS, which prefers --decode or -D.

Support multiple profiles

The awscli utility allows for multiple profiles to be configured via the ~/.aws/credentials file.

Currently, aws-secrets assumes the user wants to use the [default] profile.

It should allow for a --profile={profile_name} argument, and pass this along wherever it uses the aws command.

Required AWS permissions

A number of permissions are required for the user to be able to use aws-secrets:

  • kms:CreateKey
  • kms:ListAliases
  • iam:DeleteGroupPolicy
  • s3:ListBuckets
  • kms:Encrypt (not available via a managed policy)
  • (there may be more)

These mostly can be added by adding the following managed policies:

  • IAMFullAccess
  • AWSKeyManagementServicePowerUser
  • AmazonS3FullAccess

We should:

  • specify exactly which policies are required;
  • check if a user has a given policy before attempting to use it.

Env file is larger than 4096 bytes

Hi,

Not really directly related to this useful repo, but KMS has a limit of 4KB, and my env file has exceeded this now. Has this happened to anyone else? Is the next step storing it in S3?

Remove sudo

It's not necessary. Users can figure out if they need sudo in order to write to /usr/local.

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.