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

Remove Chamber from Docker #3249

Merged
merged 27 commits into from Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0143b28
Instead of using chamber in Docker call out directly to SSM to get th…
Dec 20, 2019
2920a8e
Remove extra curly
Dec 20, 2019
8ed0216
Remove echo lines
Dec 20, 2019
f3bfa3b
Get secrets to migration file
Dec 20, 2019
d672b15
Merge branch 'master' into cg_remove_chamber
Dec 31, 2019
f2b05b2
Deploy to experimental
Dec 31, 2019
2c1e1b7
Only allow circleci to describe parameters. Fix issue with service re…
Dec 31, 2019
c0b99f5
Fix quotes used so variables can be detected
Dec 31, 2019
d4dadf1
Remove chamber from task def
Dec 31, 2019
60676d0
Set the Name to the env var we want to use
Jan 1, 2020
32395d8
Fix ssm
Jan 1, 2020
f7cb7a8
Fix vault.go so that it only checks for vault keychain name and profi…
Jan 2, 2020
bebe568
De-duplicate env vars and secrets
Jan 2, 2020
7349d7e
Remove extra colon
Jan 2, 2020
c4cc6d5
Remove duplicated DB_REGION
Jan 2, 2020
f430cda
Paginate requests to service
Jan 2, 2020
f108790
Move DB_IAM_ROLE to SSM via chamber
Jan 2, 2020
7ae9392
Remove DB_IAM_ROLE from environment because it moved to secrets
Jan 2, 2020
3a4e8ef
Remove chamber vars
Jan 2, 2020
a31d217
Split migration secrets env vars out
Jan 2, 2020
3adaae1
Clean up DB env vars
Jan 2, 2020
8b3885c
Add template validation to make up for not doing pre-commit check
Jan 2, 2020
cd12deb
Remove DB_REGION from other .env files
Jan 2, 2020
20c6a4e
Better error checking when reading template and variables files. Fix …
Jan 2, 2020
e2b6c62
Fix name
Jan 2, 2020
d8423ec
Revert "Deploy to experimental"
Jan 2, 2020
343e079
Merge master
Jan 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions .circleci/config.yml
Expand Up @@ -482,7 +482,6 @@ jobs:
- restore_cache:
keys:
- v2-mymove-node-modules-{{ checksum "yarn.lock" }}
- run: make bin/chamber
- run: make bin/rds-combined-ca-bundle.pem
- run: make bin/rds-ca-2019-root.pem
- run: make client_build
Expand Down Expand Up @@ -518,7 +517,6 @@ jobs:
- checkout
- setup_remote_docker:
docker_layer_caching: false
- run: make bin/chamber
- run: make bin/rds-combined-ca-bundle.pem
- run: make bin/rds-ca-2019-root.pem
- run: make server_build
Expand All @@ -538,7 +536,6 @@ jobs:
- restore_cache:
keys:
- go-mod-sources-v2-{{ checksum "go.sum" }}-{{ checksum "scripts/check-go-version" }}}
- run: make bin/chamber
- run: make bin/rds-combined-ca-bundle.pem
- run: make bin/rds-ca-2019-root.pem
- run: make tasks_build
Expand Down Expand Up @@ -768,23 +765,23 @@ workflows:
# if testing on experimental, you can disable these tests by using the commented block below.
filters:
branches:
ignore: placeholder_branch_name
ignore: cg_remove_chamber

- client_test:
requires:
- pre_deps_yarn
# if testing on experimental, you can disable these tests by using the commented block below.
filters:
branches:
ignore: placeholder_branch_name
ignore: cg_remove_chamber

- server_test:
requires:
- pre_deps_golang
# if testing on experimental, you can disable these tests by using the commented block below.
filters:
branches:
ignore: placeholder_branch_name
ignore: cg_remove_chamber

- build_app:
requires:
Expand Down Expand Up @@ -825,28 +822,28 @@ workflows:
- build_migrations
filters:
branches:
only: placeholder_branch_name
only: cg_remove_chamber

- deploy_experimental_tasks:
requires:
- deploy_experimental_migrations
filters:
branches:
only: placeholder_branch_name
only: cg_remove_chamber

- deploy_experimental_app:
requires:
- deploy_experimental_migrations
filters:
branches:
only: placeholder_branch_name
only: cg_remove_chamber

- deploy_experimental_app_client_tls:
requires:
- deploy_experimental_migrations
filters:
branches:
only: placeholder_branch_name
only: cg_remove_chamber

- check_circle_against_staging_sha:
requires:
Expand Down
1 change: 1 addition & 0 deletions .envrc
Expand Up @@ -155,6 +155,7 @@ export TZ="UTC"
# aws-vault. They will be detected and used by the app automatically.
export AWS_S3_BUCKET_NAME="transcom-ppp-app-devlocal-us-west-2"
export AWS_S3_REGION="us-west-2"
export AWS_DEFAULT_REGION="us-west-2"
export AWS_VAULT_KEYCHAIN_NAME=login
export AWS_PROFILE=transcom-ppp
export AWS_S3_KEY_NAMESPACE=$USER
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -12,6 +12,12 @@ repos:
rev: v2.3.0
hooks:
- id: check-json
exclude: >
(?x)^(
config/app-client-tls.container-definition.json|
config/app-migrations.container-definition.json|
config/app.container-definition.json|
)$
- id: check-merge-conflict
- id: check-yaml
exclude: config/database.yml # database.yml is not a valid yaml file, it contains go templating
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Expand Up @@ -2,7 +2,6 @@ FROM gcr.io/distroless/base:latest

COPY bin/rds-combined-ca-bundle.pem /bin/rds-combined-ca-bundle.pem
COPY bin/rds-ca-2019-root.pem /bin/rds-ca-2019-root.pem
COPY bin/chamber /bin/chamber
COPY bin/milmove /bin/milmove

COPY config/tls/Certificates_PKCS7_v5.4_DoD.der.p7b /config/tls/Certificates_PKCS7_v5.4_DoD.der.p7b
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.migrations
Expand Up @@ -2,7 +2,6 @@ FROM alpine:3.10.3

COPY bin/rds-combined-ca-bundle.pem /bin/rds-combined-ca-bundle.pem
COPY bin/rds-ca-2019-root.pem /bin/rds-ca-2019-root.pem
COPY bin/chamber /bin/chamber
COPY bin/milmove /bin/milmove

COPY migrations /migrate/migrations
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.tasks
Expand Up @@ -2,7 +2,6 @@ FROM gcr.io/distroless/base:latest

COPY bin/rds-combined-ca-bundle.pem /bin/rds-combined-ca-bundle.pem
COPY bin/rds-ca-2019-root.pem /bin/rds-ca-2019-root.pem
COPY bin/chamber /bin/chamber
COPY bin/milmove-tasks /bin/milmove-tasks

WORKDIR /bin
110 changes: 51 additions & 59 deletions cmd/ecs-deploy-task-container/main.go
Expand Up @@ -5,7 +5,6 @@ import (
"io/ioutil"
"log"
"os"
"strconv"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -85,19 +85,15 @@ func (e *errInvalidFile) Error() string {
}

const (
awsAccountIDFlag string = "aws-account-id"
chamberBinaryFlag string = "chamber-binary"
chamberRetriesFlag string = "chamber-retries"
chamberKMSKeyAliasFlag string = "chamber-kms-key-alias"
chamberUsePathsFlag string = "chamber-use-paths"
serviceFlag string = "service"
environmentFlag string = "environment"
repositoryNameFlag string = "repository-name"
imageTagFlag string = "image-tag"
commandFlag string = "command"
commandArgsFlag string = "command-args"
variablesFileFlag string = "variables-file"
dryRunFlag string = "dry-run"
awsAccountIDFlag string = "aws-account-id"
serviceFlag string = "service"
environmentFlag string = "environment"
repositoryNameFlag string = "repository-name"
imageTagFlag string = "image-tag"
commandFlag string = "command"
commandArgsFlag string = "command-args"
variablesFileFlag string = "variables-file"
dryRunFlag string = "dry-run"
)

func initFlags(flag *pflag.FlagSet) {
Expand All @@ -111,12 +107,6 @@ func initFlags(flag *pflag.FlagSet) {
// Vault Flags
cli.InitVaultFlags(flag)

// Chamber Settings
flag.String(chamberBinaryFlag, "/bin/chamber", "Chamber Binary")
flag.Int(chamberRetriesFlag, 20, "Chamber Retries")
flag.String(chamberKMSKeyAliasFlag, "alias/aws/ssm", "Chamber KMS Key Alias")
flag.Int(chamberUsePathsFlag, 1, "Chamber Use Paths")

// Task Definition Settings
flag.String(serviceFlag, "", fmt.Sprintf("The service name (choose %q)", services))
flag.String(environmentFlag, "", fmt.Sprintf("The environment name (choose %q)", environments))
Expand Down Expand Up @@ -147,38 +137,27 @@ func checkConfig(v *viper.Viper) error {
}

if err := cli.CheckAWSRegionForService(region, cloudwatchevents.ServiceName); err != nil {
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ecs.ServiceName))
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, cloudwatchevents.ServiceName))
}

if err := cli.CheckAWSRegionForService(region, ecs.ServiceName); err != nil {
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ecs.ServiceName))
}

if err := cli.CheckAWSRegionForService(region, ecr.ServiceName); err != nil {
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ecs.ServiceName))
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ecr.ServiceName))
}

if err := cli.CheckAWSRegionForService(region, rds.ServiceName); err != nil {
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ecs.ServiceName))
}

if err := cli.CheckVault(v); err != nil {
return err
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, rds.ServiceName))
}

chamberRetries := v.GetInt(chamberRetriesFlag)
if chamberRetries < 1 && chamberRetries > 20 {
return errors.New("Chamber Retries must be greater than or equal to 1 and less than or equal to 20")
if err := cli.CheckAWSRegionForService(region, ssm.ServiceName); err != nil {
return errors.Wrap(err, fmt.Sprintf("'%q' is invalid for service %s", cli.AWSRegionFlag, ssm.ServiceName))
}

chamberKMSKeyAlias := v.GetString(chamberKMSKeyAliasFlag)
if len(chamberKMSKeyAlias) == 0 {
return errors.New("Chamber KMS Key Alias must be set")
}

chamberUsePaths := v.GetInt(chamberUsePathsFlag)
if chamberUsePaths < 1 && chamberUsePaths > 20 {
return errors.New("Chamber Use Paths must be greater than or equal to 1 and less than or equal to 20")
if err := cli.CheckVault(v); err != nil {
return err
}

serviceName := v.GetString(serviceFlag)
Expand Down Expand Up @@ -263,6 +242,38 @@ func varFromCtxOrEnv(varName string, ctx map[string]string) string {
return os.Getenv("DB_PORT")
}

func buildSecrets(serviceSSM *ssm.SSM, awsRegion, registryID, serviceName, environmentName string) []*ecs.Secret {

var secrets []*ecs.Secret

var describeParametersNextToken *string

for {
parametersOutput, err := serviceSSM.DescribeParameters(&ssm.DescribeParametersInput{
MaxResults: aws.Int64(50),
NextToken: describeParametersNextToken,
})
if err != nil {
log.Fatal(errors.Wrap(err, "error reading secrets from SSM"))
}

for _, parameter := range parametersOutput.Parameters {
if strings.HasPrefix(*parameter.Name, fmt.Sprintf("/%s-%s", serviceName, environmentName)) {
secrets = append(secrets, &ecs.Secret{
Name: parameter.Name,
ValueFrom: aws.String(fmt.Sprintf("arn:aws:ssm:%s:%s:parameter:%s", awsRegion, registryID, *parameter.Name)),
})
}
}
describeParametersNextToken = parametersOutput.NextToken

if describeParametersNextToken == nil || *describeParametersNextToken == "" {
break
}
}
return secrets
}

func buildContainerEnvironment(v *viper.Viper, environmentName string, dbHost string, variablesFile string) []*ecs.KeyValuePair {

// Construct variables from a file for the task def
Expand All @@ -286,17 +297,7 @@ func buildContainerEnvironment(v *viper.Viper, environmentName string, dbHost st
}
}

chamberKMSKeyAlias := v.GetString(chamberKMSKeyAliasFlag)
chamberUsePaths := v.GetInt(chamberUsePathsFlag)
return []*ecs.KeyValuePair{
{
Name: aws.String("CHAMBER_KMS_KEY_ALIAS"),
Value: aws.String(chamberKMSKeyAlias),
},
{
Name: aws.String("CHAMBER_USE_PATHS"),
Value: aws.String(strconv.Itoa(chamberUsePaths)),
},
{
Name: aws.String("DB_ENV"),
Value: aws.String(cli.DbEnvContainer),
Expand Down Expand Up @@ -401,6 +402,7 @@ func main() {
serviceECS := ecs.New(sess)
serviceECR := ecr.New(sess)
serviceRDS := rds.New(sess)
serviceSSM := ssm.New(sess)

// Get the current task definition (for rollback)
commandName := v.GetString(commandFlag)
Expand Down Expand Up @@ -480,18 +482,7 @@ func main() {
awsLogsGroup := fmt.Sprintf("ecs-tasks-%s-%s", serviceName, environmentName)
awsLogsStreamPrefix := fmt.Sprintf("%s-tasks", serviceName)

// Chamber Settings
chamberBinary := v.GetString(chamberBinaryFlag)
chamberRetries := v.GetInt(chamberRetriesFlag)
chamberStore := fmt.Sprintf("%s-%s", serviceName, environmentName)

entryPoint := []string{
chamberBinary,
"-r",
strconv.Itoa(chamberRetries),
"exec",
chamberStore,
"--",
fmt.Sprintf("/bin/%s", cmds[0]),
}
if len(cmds) > 1 {
Expand All @@ -511,6 +502,7 @@ func main() {
Essential: aws.Bool(true),
EntryPoint: aws.StringSlice(entryPoint),
Command: []*string{},
Secrets: buildSecrets(serviceSSM, awsRegion, registryID, serviceName, environmentName),
Environment: buildContainerEnvironment(v, environmentName, dbHost, variablesFile),
LogConfiguration: &ecs.LogConfiguration{
LogDriver: aws.String("awslogs"),
Expand Down
15 changes: 1 addition & 14 deletions config/app-client-tls.container-definition.json
Expand Up @@ -3,12 +3,6 @@
"image": "{{ .image }}",
"essential": true,
"entryPoint": [
"/bin/chamber",
"-r",
"{{ .CHAMBER_RETRIES }}",
"exec",
"app-{{ .environment }}",
"--",
"/bin/milmove",
"serve",
"--db-env",
Expand All @@ -29,6 +23,7 @@
}
],
"command": [],
"secrets": {{ .secrets }},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonky I know. Because now the file isn't proper JSON. For now its excluded from the pre-commit check, which may bite us while we replace the template.

"environment": [
{
"name": "DB_IAM",
Expand Down Expand Up @@ -74,14 +69,6 @@
"name": "DEVLOCAL_AUTH",
"value": "{{ .DEVLOCAL_AUTH }}"
},
{
"name": "CHAMBER_KMS_KEY_ALIAS",
"value": "alias/aws/ssm"
},
{
"name": "CHAMBER_USE_PATHS",
"value": "1"
},
{
"name": "MOVE_MIL_DOD_CA_CERT",
"value": "{{ .move_mil_dod_ca_cert }}"
Expand Down
7 changes: 1 addition & 6 deletions config/app-migrations.container-definition.json
Expand Up @@ -4,12 +4,6 @@
"portMappings": [],
"essential": true,
"entryPoint": [
"/bin/chamber",
"-r",
"{{ .CHAMBER_RETRIES }}",
"exec",
"app-{{ .environment }}",
"--",
"/bin/milmove",
"migrate",
"--db-env",
Expand All @@ -18,6 +12,7 @@
"production"
],
"command": [],
"secrets": {{ .secrets }},
"environment": [
{
"name": "DB_IAM",
Expand Down