Skip to content

Commit 00d7c6e

Browse files
author
kendavis2
committed
init
0 parents  commit 00d7c6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+8308
-0
lines changed

.github/shell/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM golang:1.13.7
2+
3+
RUN go get github.com/mitchellh/gox && \
4+
go get github.com/tcnksm/ghr
5+
6+
ADD entrypoint.sh /entrypoint.sh
7+
ENTRYPOINT ["/entrypoint.sh"]

.github/shell/entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
sh -c "$*"

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: BuildNDeploy
2+
on:
3+
push:
4+
tags:
5+
- 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]*'
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
jobs:
8+
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Go
14+
uses: actions/setup-go@v1
15+
with:
16+
go-version: 1.13
17+
18+
- name: Check out Code
19+
uses: actions/checkout@v2
20+
21+
- name: Set Version
22+
run: echo ::set-env name=version::${GITHUB_REF##*v}
23+
24+
- name: Build and Publish Release
25+
uses: ./.github/shell
26+
env:
27+
GOROOT: /usr/local/go
28+
with:
29+
args: |
30+
cd cli
31+
gox -os='darwin' -os='linux' -os='windows' -ldflags '-X main.version=${{ env.version }}.${{ github.run_number }}' -output 'artifacts/stash_{{.OS}}_{{.Arch}}'
32+
ghr -t '${{ secrets.GITHUB_TOKEN }}' -u dabblebox -r stash -c $GITHUB_SHA -delete ${GITHUB_REF##*/} artifacts
33+

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# exe
2+
/stash
3+
/cli/cmd/stash_test
4+
5+
# config
6+
*.env
7+
*.json
8+
*.cert
9+
*.sql
10+
*.js
11+
*.pub
12+
id_rsa
13+
14+
# catalog
15+
stash.yml
16+
17+
# terraform
18+
.terraform
19+
*.tf
20+
*.tfstate*
21+
*.tfvars

AWS_METHODS.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# AWS Configuration Methods
2+
3+
Managing configuration is divided into two processes, [Configuration Management](#configuration-management) which is the process modifying and storing configuration in a cloud storage service, and [Configuration Consumption](#configuration-consumption) which is the process of ingesting the configuration from a cloud storage service into a Fargate container or Lambda function.
4+
5+
## Configuration Management
6+
7+
When using *Stash*, management is consistent accross supported cloud storage services.
8+
9+
```bash
10+
$ stash sync config/dev/.env
11+
```
12+
```bash
13+
$ stash edit -t dev
14+
```
15+
16+
## Configuration Consumption
17+
18+
Consumption has many methods with different benefits. The pupose of this document is to discuss AWS methods for Fargate containers and Lambda functions, but some of the following methods may also apply to other technologies.
19+
20+
#### User and Role Policies
21+
AWS methods require developers and the container execution role or application role to have access to the appropriate cloud storage service and KMS keys.
22+
23+
The following *Stash* command generates Terraform scripts specific to the `dev` configuration. This makes it easier to manage the AWS access policies through Terraform.
24+
25+
```bash
26+
$ stash get -t dev -o terraform
27+
```
28+
29+
### Method 1: Download Configuration File (Stash CLI)
30+
31+
**Supports**: ECS Fargate Containers
32+
33+
On start up containers can call a storage service directly using the *Stash* CLI and create a configuration file inside the container allowing the application to load it into memory.
34+
35+
**Requirement**: The stash.yml file used to sync the configuration must included in the Docker image where *Stash* can find it.
36+
37+
Dockerfile (build)
38+
```bash
39+
FROM golang:1.13
40+
41+
ARG version=0.0.0-unknown.0
42+
43+
# install stash
44+
RUN curl -L -o /usr/local/bin/stash https://github.com/dabblebox/stash/releases/download/v0.1.0-rc/stash_linux_386 && chmod +x /usr/local/bin/stash
45+
46+
47+
COPY . /app/
48+
49+
WORKDIR /app
50+
51+
RUN go build -ldflags '-X main.version='$version -o app
52+
53+
ENTRYPOINT [ "./docker-entrypoint.bash" ]
54+
```
55+
56+
docker-entrypoint.bash (get)
57+
```bash
58+
#!/bin/bash
59+
60+
echo "Getting $CONFIG_ENV configuration."
61+
62+
stash get -l -t $CONFIG_ENV 1> .env
63+
64+
exec ./app
65+
```
66+
67+
### Method 2: File Injection (Stash CLI)
68+
69+
On start up containers can call a storage service directly using the *Stash* CLI and inject secrets into a configuration file inside the container allowing the application to load the file containing the secrets into memory. Secret tokens can be added to a configuration file that is checked into a repository.
70+
71+
The tokens are AWS Secret Manager secret names. Use double colons, `::`, to specify any field in the secret's json object.
72+
73+
.env (config)
74+
```
75+
USER=${app/dev/db::user}
76+
PASSWORD=${app/dev/db::password}
77+
```
78+
79+
Dockerfile (build)
80+
```bash
81+
FROM golang:1.13
82+
83+
ARG version=0.0.0-unknown.0
84+
85+
# install stash
86+
RUN curl -L -o /usr/local/bin/stash https://github.com/dabblebox/stash/releases/download/v0.1.0-rc/stash_linux_386 && chmod +x /usr/local/bin/stash
87+
88+
COPY . /app/
89+
90+
WORKDIR /app
91+
92+
RUN go build -ldflags '-X main.version='$version -o app
93+
94+
ENTRYPOINT [ "./docker-entrypoint.bash" ]
95+
```
96+
97+
docker-entrypoint.bash (inject)
98+
```bash
99+
#!/bin/bash
100+
101+
echo "Injecting $CONFIG_ENV configuration."
102+
103+
stash inject $CONFIG_ENV/.env -l -s secrets-manager 1> secrets.env
104+
105+
exec ./app
106+
```
107+
108+
### Method 3: Environment Injection (AWS)
109+
110+
**Supports**: ECS Fargate Containers
111+
112+
Configuration and secret references to cloud services like Secrets Manager, Parameter Store, and S3 can be listed in ECS task definitions. On container start, AWS injects the configuration and/or secrets from cloud service references into the containers environment variables.
113+
114+
*Stash* provides commands that print the task definition JSON for stashed configuration making it easier to add to a task definition. [Secrets](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html) from AWS Secrets Manager and SSM Parameter Store along with S3 [environment files](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html) are supported.
115+
116+
```bash
117+
$ stash get -t dev -o ecs-task-inject-json
118+
```
119+
120+
```bash
121+
$ stash get -t dev -o ecs-task-inject-env
122+
```
123+
124+
### Method 4: Direct Ingest (Stash Library)
125+
126+
**Supports**: ECS Fargate Containers / Lambda Functions
127+
128+
Code can use the *Stash* Go integration library to load configuration directly into memory.
129+
130+
**Requirement**: The stash.yml file used to sync the configuration must be included in the Docker image or Lambda function where *Stash* can find it.
131+
132+
```go
133+
package main
134+
135+
import (
136+
"log"
137+
138+
"github.com/dabblebox/stash"
139+
"github.com/dabblebox/stash/component/output"
140+
)
141+
142+
config, err := stash.GetMap(stash.GetOptions{})
143+
if err != nil {
144+
log.Fatal(err)
145+
}
146+
147+
for k, v := range config {
148+
log.Printf("%s=%s\n", k, v)
149+
}
150+
```

CATALOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Configuration Catalog
2+
3+
A catalog file, `stash.yml`, is automatically generated after syncing a configuration file with a cloud service. This file catalogs each configuration file stored in the cloud and allows specific actions like `purge` or `edit` to be performed without the user knowing where the data is stored or how the data is encrypted.
4+
5+
| Field | Example | Options | Description |
6+
|-|-|-|-|
7+
|version|0.0.0-local|String|The version of Stash used to sync the configuration.|
8+
|context|my-slick-app|String|The repository or app name for the stored configuration.|
9+
|clean|true|Boolean|Delete local files after updating a cloud service.|
10+
|files[].path| config/dev/.env| String |The local file path where the cofiguration is initially synced from and restored during a get command.||
11+
|files[].service|secrets-manager|secrets-manager, parameter-store, s3| The cloud service where configuration is stored.|
12+
|files[].opt.kms_key_id||Guid|The KMS key id used to encrypt the configuration. Enter alias to create a new KMS key. (default: aws/secretsmanager)|
13+
|files[].opt.secrets|single|single, multiple| Specifies if each key/value pair should be stored in a separate Secrets Manager secret for JSON and ENV file types. |
14+
|files[].keys|| Object{} |The cloud service keys used to get configuration.|
15+
|files[].tags|| Object{} |Local tags used when running Stash commands to target specific configuration stored in the cloud.|

0 commit comments

Comments
 (0)