All Projects → ukayani → kms-env

ukayani / kms-env

Licence: MIT License
A tool to encrypt and decrypt environment variables using KMS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to kms-env

Py7zr
7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.
Stars: ✭ 110 (+587.5%)
Mutual labels:  encryption, decryption
Padding Oracle Attacker
🔓 CLI tool and library to execute padding oracle attacks easily, with support for concurrent network requests and an elegant UI.
Stars: ✭ 136 (+750%)
Mutual labels:  encryption, decryption
Cryption
In-Browser AES File Encryption 🔐 with Data Integrity Check 🔍
Stars: ✭ 114 (+612.5%)
Mutual labels:  encryption, decryption
Encryptor4j
Strong encryption for Java simplified
Stars: ✭ 92 (+475%)
Mutual labels:  encryption, decryption
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+1387.5%)
Mutual labels:  encryption, decryption
Sharedchamber
Android Secure SharedPreferences Using Facebook Conceal Encryption
Stars: ✭ 96 (+500%)
Mutual labels:  encryption, decryption
Underlock
Underlock makes it dead simple to encrypt and decrypt your data and files. It comes with little to no dependencies and has a very small API surface.
Stars: ✭ 128 (+700%)
Mutual labels:  encryption, decryption
Lazysodium Android
An Android implementation of the Libsodium cryptography library. For the lazy dev.
Stars: ✭ 69 (+331.25%)
Mutual labels:  encryption, decryption
Jsrsasign
The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES JSON Web Signature/Token in pure JavaScript.
Stars: ✭ 2,760 (+17150%)
Mutual labels:  encryption, decryption
Pgsodium
Modern cryptography for PostgreSQL using libsodium.
Stars: ✭ 202 (+1162.5%)
Mutual labels:  encryption, decryption
Hybrid Crypto Js
RSA+AES hybrid encryption implementation for JavaScript. Works with Node.js, React Native and modern browsers.
Stars: ✭ 87 (+443.75%)
Mutual labels:  encryption, decryption
kmstool
Tool for using AWS Kms data keys to encrypt and decrypt large files.
Stars: ✭ 33 (+106.25%)
Mutual labels:  kms, decryption
Cryptr
A simple shell utility for encrypting and decrypting files using OpenSSL.
Stars: ✭ 81 (+406.25%)
Mutual labels:  encryption, decryption
Easycrypt
Android cryptography library with SecureRandom patches.
Stars: ✭ 102 (+537.5%)
Mutual labels:  encryption, decryption
Simon speck ciphers
Implementations of the Simon and Speck Block Ciphers
Stars: ✭ 74 (+362.5%)
Mutual labels:  encryption, decryption
Cross Platform Aes
Simple cross-platform encryption and decryption using AES
Stars: ✭ 127 (+693.75%)
Mutual labels:  encryption, decryption
Simple Polymorphic Engine Spe32
Simple Polymorphic Engine (SPE32) is a simple polymorphic engine for encrypting code and data. It is an amateur project that can be used to demonstrate what polymorphic engines are.
Stars: ✭ 59 (+268.75%)
Mutual labels:  encryption, decryption
Helm Secrets
DEPRECATED A helm plugin that help manage secrets with Git workflow and store them anywhere
Stars: ✭ 1,129 (+6956.25%)
Mutual labels:  encryption, decryption
Helm Secrets
Successor of zendesk/helm-secrets - A helm plugin that help manage secrets with Git workflow and store them anywhere
Stars: ✭ 165 (+931.25%)
Mutual labels:  encryption, decryption
Openssl
TLS/SSL and crypto library
Stars: ✭ 17,157 (+107131.25%)
Mutual labels:  encryption, decryption

KMS Env Build Status

A tool used to encrypt environment and decrypt environment variables using KMS to support passing of encrypted environment variables to docker containers.

If you are looking for a way to pass environment variables to a docker container in a secure manner, this tool aims to help.

Requirements

  • NodeJS v7.x
  • A AWS Customer Master Key in KMS
  • Docker

How it works

AWS Setup

  1. Create a CMK in AWS. IAM > Encryption Keys
  2. Give a user or role access to this key via the key's policy

By default, the tool will use the default credential chain for AWS.

You can specify Access Keys and Secret Access keys via Environment variables, or cli arguments. If you are running the tool on an EC2 instance, the instance profile will be used.

Usage

Usage: kms-env [options] [command]


  Commands:

    init [keyId] [file]      Initialize an environment variable file with provided CMK Id
    add [file] [entries...]  Adds environment variable to file after encrypting the value
    decrypt                  Decrypts secure environment variables and generates a bash export for each. Can be used with bash eval command to do in place decryption of env variables
    show [file]              Show the contents of the env file decrypting all secure vars. Warning: Only use for debugging!

  Options:

    -h, --help                        output usage information
    -V, --version                     output the version number
    -k, --access-key-id <id>          AWS Access key ID. Env: $AWS_ACCESS_KEY_ID
    -s, --secret-access-key <secret>  AWS Secret Access Key. Env: $AWS_SECRET_ACCESS_KEY
    -r, --region <region>             AWS Region. Env: $AWS_REGION
    -p, --profile <name>              AWS Credential profile to use

Exporting AWS Region

An AWS Region must be specified when running kms-env. It can be provided via the --region parameter or with the following export:

export AWS_REGION=us-east-1

The above command will set your region to us-east-1

Initializing an env file

To get started, you must run the init command and specify your KMS CMK ID or alias. You can find this in the AWS console: IAM > Encryption Keys

$ kms-env init [keyid] [filename]

Let's initialize a file called test.env using a CMK with alias mykey

$ kms-env init alias/mykey test.env

After running the init command, a test.env file will be created in your working directory.

It will contain the following:

KMS_DATA_KEY = [encrypted value]

You can now start adding secure environment variables to this file

Adding secure variables

To add secure environment variables to your file you can use:

$ kms-env add [filename] [entries...]

Let's add the following environment variables:

  • DATABASE_PASS = test123
  • DATABASE_USER = alice
$ kms-env add test.env DATABASE_PASS=test123 DATABASE_USER=alice

The new environment variables should be added to your test.env:

KMS_DATA_KEY = [encrypted value]
DATABASE_PASS = secure:[encrypted value]
DATABASE_USER = secure:[encrypted value]

Decrypting secure variables

Once you have exported the above environment variables in your an environment, you can easily have them decrypted

$ export KMS_DATA_KEY = ...
$ export DATABASE_PASS = secure:...
$ export DATABASE_USER = secure:...


$ eval $(kms-env decrypt)
$ echo $DATABASE_PASS
$ test123
$ echo $DATABASE_USER
$ alice

The decrypt command will output export statements which you can run through eval to have the secure environment variables replaced in place.

Example: Secure environment variables to Docker container

The motivation behind creating kms-env was to securely pass sensitive environment variables to an application running in a docker container in AWS

The env file created by kms-env can be used with the docker run command using the --env-file [file] argument.

Step 1: Create a docker image with kms-env installed

To use kms-env to securely pass env vars to a docker container, the container needs kms-env installed.

Example Dockerfile with node + kms-env

An example docker file which has kms-env installed is provided at Dockerfile

You can use this docker file as your base image for your application image if you are building a NodeJs application. If you are using a different platform (eg JVM) then you will also need to install the necessary dependencies for that platform.

How it works The docker file uses an env-decrypt bash entrypoint script, so it will first run kms-env decrypt and then run whatever is supplied as a command to docker run

So, for example:

docker run [image] npm start

Assuming your image has the working directory set to a node project, the npm start command will run after the kms-env decrypt

Step 2: Permissions to the CMK

In order for your container to decrypt environment variables, it will need read access to the CMK used to encrypt the env vars.

To set up permissions, you will need to attach a policy to the role which is assumed by your AWS EC2 instance or the task role (if you are using AWS ECS)

Example IAM Policy Granting Access to a CMK

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "kms:Decrypt"
            ],
            "Resource": [
                "arn:aws:kms:us-east-1:xxxxxxxxxz:key/xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
            ],
            "Effect": "Allow"
        }
    ]
}

The above policy, when attached to a role will give decrypt access for the CMK. You must supply the ARN for your specific key.

ECS Task Role If you are running docker containers using AWS ECS, you would attach the above policy to the Task Role associated with your ECS Task Definition

Step 3: Supplying an env file to your container

Once you have a container image that has kms-env installed and the container is running on an EC2 instance or ECS Task with the correct permissions, you can supply your env files to your container.

Supplying env via docker run

If you are running docker on EC2 directly, you can use supply your env file via:

docker run --env-file [filepath] [image] [command]

The above command will run your container with the supplied env file as environment variables. If the container is using the example base image, it will automatically decrypt the secure env vars in place for your application to read.

Supplying env via ECS Task Definition

To supply environment variables to a container running on ECS you will need to supply them via the task definition JSON

The following is an example task def (with some fields left blank) where we supply the environment variables which would be present in a .env file generated by kms-env

Example Task Def

{
    "family": "",
    "taskRoleArn": "",
    "networkMode": "",
    "containerDefinitions": [
        {
            "name": "",
            "image": "",
            "cpu": 0,
            "memory": 0,
            "memoryReservation": 0,
            "essential": true,
            "environment": [
                {
                    "name": "MY_VAR",
                    "value": "secure:xxxxxxxxx"
                }
            ]
        }
    ]
}

When the above task runs, it would supply the env vars to the docker container similar to the --env or -e argument for the docker run command.

Optional Parameters

AWS Credentials

To supply credentials manually you can use the following parameters:

  • --access-key-id - To specify your access key ID
  • --secret-access-key - To specify your secret
  • --region - To specify the AWS Region

Using Profiles

Alternatively you can supply an AWS credential profile to use via:

  • --profile - To use a credential profile instead of supplying access key and secret
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].