Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure Key Vault provider #6

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
azure.auth
bin
coverage.txt
main
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM amazonlinux:2

COPY ./bin/exec-with-secrets-linux-amd64 /usr/local/bin/exec-with-secrets
ADD https://github.com/s12v/exec-with-secrets/releases/download/v0.3.0/exec-with-secrets-linux-amd64 /exec-with-secrets

CMD exec-with-secrets
RUN chmod +x /exec-with-secrets

ENTRYPOINT ["/exec-with-secrets"]

CMD env
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all
all: clean test build
TAGS = awskms awssecretsmanager awsssm
TAGS = awskms awssecretsmanager awsssm azurekeyvault

clean:
rm -rf ./bin || true
Expand All @@ -13,4 +13,4 @@ build:
GOOS=darwin GOARCH=amd64 go build -i -tags '$(TAGS)' -ldflags='-s -w' -o "bin/exec-with-secrets-darwin-amd64"

docker:
docker build -t exec-with-secrets-example .
docker build --no-cache -t exec-with-secrets-example .
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
[![Build Status](https://travis-ci.com/s12v/exec-with-secrets.svg?branch=master)](https://travis-ci.com/s12v/exec-with-secrets)
[![codecov](https://codecov.io/gh/s12v/exec-with-secrets/branch/master/graph/badge.svg)](https://codecov.io/gh/s12v/exec-with-secrets)

Populate secrets from AWS KMS, SSM or Secrets Manager into your app environment
# Pass secrets from AWS KMS/SSM/Secrets Manager or Azure Key Vault into your app environment

`exec-with-secrets` passes secrets from AWS KMS, SSM, or Secrets Manager into your app environment in a secure way.

It supports the following services as secrets providers:
`exec-with-secrets` it supports the following services as secrets providers:
- [AWS Key Management (KMS)](https://aws.amazon.com/kms/)
- [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html)
- [AWS Systems Manager Parameter Store (SSM)](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html)
- [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/)
- [Azure Key Vault](https://azure.microsoft.com/en-in/services/key-vault/)

This small utility looks for prefixed variables in environment and replaces them with the secret value:
- `{aws-kms}AQICAHjA3mwbmf...` - decrypts the value using AWS KMS
- `{aws-ssm}/app/staging/param` - loads parameter `/app/staging/param` from AWS Systems Manager Parameter Store
- `{aws-sm}/app/staging/param` - loads secret `/app/staging/param` from AWS Secrets Manager
- `{aws-sm}/app/staging/param{prop1}` - loads secret `/app/staging/param` from AWS Secrets Manager and takes `prop1` property
- `{az-kv}vault/name` - loads secret `name` from Azure Key Vault `vault`

Then it runs `exec` system call and replaces itself with your app.
The secrets are only available to your application and not accessible with `docker inspect`.

The default credentials chain is used for AWS access.
Access:
- The default credentials chain is used for AWS access
- Azure authorizer from environment variables/MSI
- Azure authorizer from configuration file, if the file is set using `AZURE_AUTH_LOCATION` variable

## Examples

### Wrap an executable

```
PARAM="{aws-kms}AQICAHjA3mwvsfng346vnbmf..." exec-with-secrets app
# Download the latest binary
curl -L https://github.com/s12v/exec-with-secrets/releases/download/v0.3.0/exec-with-secrets-darwin-amd64 -o exec-with-secrets
chmod +x ./exec-with-secrets

# Wrap /bin/sh
PARAM="{aws-kms}c2VjcmV0" ./exec-with-secrets /bin/sh -c 'echo $PARAM'
```

`PARAM` will be decrypted and passed to `app` via environment.
`PARAM` will be decrypted and passed to `/bin/sh` via environment.

### Docker example

Build an image:
Build the [example Docker image](Dockerfile):

```
FROM amazonlinux:2

ADD https://github.com/s12v/exec-with-secrets/releases/download/v0.3.0/exec-with-secrets-linux-amd64 /exec-with-secrets

COPY app.jar /app.jar

CMD exec-with-secrets java -jar /app.jar
make docker
```

Run:
Expand All @@ -51,16 +53,19 @@ docker run \
-e PLAINTEXT_PARAM="text" \
-e KMS_PARAM="{aws-kms}AQICAHjA3mwvsfng346vnbmf..." \
-e SSM_PARAM="{aws-ssm}/myapp/param" \
myappimage
exec-with-secrets-example \
/bin/env
```

`KMS_PARAM` and `SSM_PARAM` will be decrypted and passed to `app.jar` environment.
`docker inspect` will still see the encrypted values
`KMS_PARAM` and `SSM_PARAM` will be decrypted and passed to `/bin/env` as environment variables.


## Build

`make` builds Linux and Mac binaries with all providers.

### Choose providers

To chose providers (for example only AWS SSM), run:
```
make TAGS=awsssm
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/s12v/exec-with-secrets

require github.com/aws/aws-sdk-go-v2 v0.8.0

require (
github.com/Azure/azure-sdk-for-go v30.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.2.0
github.com/Azure/go-autorest/autorest/azure/auth v0.1.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.2.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect
)
Loading