Giter Site home page Giter Site logo

adikari / safebox Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 127 KB

SafeBox is a command line tool for managing secrets for your application.

Go 86.29% Shell 8.47% JavaScript 5.24%
configuration-management secret-management ssm aws-parameter-store aws-secrets-manager aws-ssm aws-ssm-parameter-store

safebox's Introduction

๐Ÿ“ฆ SafeBox

SafeBox is a command line tool for managing secrets for your application. Currently it supports AWS Parameter Store and AWS Secrets Manager.

Installation

SafeBox is available for many Linux distros and Windows.

# Via brew (OSX)
$ brew install adikari/taps/safebox

# Via curl
$ curl -sSL https://raw.githubusercontent.com/monebag/safebox/main/scripts/install.sh | sh

# Via npm
$ npm install @adikari/safebox

# Via yarn
$ yarn add @adikari/safebox

To install it directly find the right version for your machine in releases page. Download and un-archive the files. Copy the safebox binary to the PATH or use it directly.

Usage

  1. Create a configuration file called safebox.yml.
service: my-service
provider: ssm

# Optional: generate the given files based on the parameters
generate:
    - type: types-node
      path: types/env.d.ts
    - type: dotenv
      path: .env

config:
  defaults:
    DB_NAME: "database name updated"
    API_ENDPOINT: "http://some-endpoint-{{ .stage }}.com" # stage is only available when passed through the cli flag

  prod:
    DB_NAME: "production db name"

  shared:
    SHARED_VARIABLE: "some shared config"

secret:
  defaults:
    API_KEY: "key of the api endpoint"
    DB_SECRET: "database secret"

  shared:
    SHARED_KEY: "shared key"
  1. Use safebox CLI tool to deploy your configuration.
$ safebox deploy --config path/to/safebox.yml --prompt="missing"

# staged deployment when you want to have separate config per environment. 
# eg. prod, dev
$ safebox deploy --stage <stage> --config path/to/safebox.yml --prompt="missing"

You can then run list command to view the pushed configurations.

The variables under

  1. defaults is deployed with path prefix of /<stage>/<service> or /<service>
  2. shared is deployed with path prefix of /<stage>/shared/ or /shared>

CLI Reference

Following are all options available in safebox CLI.

A Fast and Flexible secret manager built with love by adikari in Go.

Usage:
  safebox [flags]
  safebox [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  deploy      Deploys all configurations specified in config file
  export      Exports all configuration to a file
  help        Help about any command
  import      Imports all configuration from a file
  list        Lists all the configs available

Flags:
  -c, --config string   path to safebox configuration file (default "safebox.yml")
  -h, --help            help for safebox
  -s, --stage string    stage to deploy to 
  -v, --version         version for safebox

Use "safebox [command] --help" for more information about a command.

Using in scripts

#!/bin/bash

set -euo pipefail

echo "๐Ÿ“ฆ  deploying configs to ssm"
safebox deploy --stage $STAGE # ensures all configs are deployed. throws error if ay configs are missings

configs=$(safebox export --stage $STAGE)
CONFIG1=$(echo "$configs" | jq -r ".CONFIG1")
CONFIG2=$(echo "$configs" | jq -r '.CONFIG2')

echo $CONFIG1
echo $CONFIG2

Generating dotenv files

This is quite handy when your build process or application requires configuration in a dotenv file. The command reads all your configs defined in safebox.yml and outputs the dotenv file.

safebox export --stage <stage> --format="dotenv" --output-file=".env"

Replacing existing configuration

To replace the configuration simply update the value in the safebox.yml file and redeploy. To replace the existing secrets run the following command

safebox deploy --stage <stage> --prompt="all"

This will display a prompt with the secret and its existing values. You can press enter to retain the old value for secrets that you don't want to update. For the secret that you want to replace, remove the old value from the prompt then provide the new value.

Deploy new configuration

To deploy the new configuration, simply add the new key value in safebox.yml To deploy new secret value, run the following command

safebox deploy --stage <stage> --prompt="missing"

The missing flag will only prompt you for the new secrets.

Configuration File Reference

Following is the configuration file will all possible options:

service: my-service
provider: secrets-manager                     # ssm OR secrets-manager 
prefix: "/custom/prefix/{{.stage}}/"          # Optional. Defaults to /<stage>/<service>/. Prefix all parameters. Does not apply for shared

stacks:                                       # Outputs from cloudformation stacks that needs to be interpolated.
  - some-cloudformation-stack

config:
  defaults:                                   # Default parameters. Can be overwritten in different environments.
    DB_NAME: my-database
    DB_HOST: 3200
    KEY_VALUE_SECRET: '{"hello": "world"}'    # JSON body can be passed when provider is secrets-manager. This will create key value secret
  production:                                 # If keys are deployed to production stage, its value will be overwritten by following
    DB_NAME: my-production-database
  shared:                                     # shared configuartions deployed under /<stage>/shared/ path
    DB_TABLE: "table-{{.stage}}"

secret:
  defaults:
    DB_PASSWORD: "secret database password"   # Value in quote is deployed as description of the ssm parameter.

Variables available for interpolation

  • stage - Stage used for deployment
  • service - Name of service as configured in the config file
  • account - AWS Account number
  • region - AWS Region

If using stacks then the outputs of that Cloudformation stack is also available for interpolation.

Release

  1. Update version number npm/package.json.
  2. Merge the changes to main branch.
  3. Create a git tag that matches the same version number as npm package version.
  4. Push the tag to github. Tag must follow semversion and prefixed with v. Eg. v.1.2.3.
  5. Pushing the tag triggers github workflow that will automatically release new version.

License

Feel free to use the code, it's released using the MIT license.

safebox's People

Contributors

adikari avatar aweraw avatar goreleaserbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

safebox's Issues

ability to use combination of stores

I want to deploy some configurations to a different store

For example, I want to deploy all my secrets to "ssm". I want to deploy 1 secret to "secrets-manager"

safebox via npm constantly fails



โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDOUT downloading safebox binary
--
15:14:08.384 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR
15:14:08.384 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR gzip: stdin: unexpected end of file
15:14:08.384 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Unexpected EOF in archive
15:14:08.385 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Unexpected EOF in archive
15:14:08.385 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Error is not recoverable: exiting now
15:14:08.388 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR node:child_process:946
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     throw err;
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     ^
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR Error: Command failed: tar -xf /tmp/safebox.tar.gz -C /tmp
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR
15:14:08.389 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR gzip: stdin: unexpected end of file
15:14:08.390 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Unexpected EOF in archive
15:14:08.390 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Unexpected EOF in archive
15:14:08.390 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR tar: Error is not recoverable: exiting now
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at checkExecSyncError (node:child_process:871:11)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Object.execSync (node:child_process:943:15)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Request.<anonymous> (/vercel/path0/node_modules/@adikari/safebox/install.js:44:8)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Request.emit (node:events:513:28)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Request.<anonymous> (/vercel/path0/node_modules/request/request.js:1091:14)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Request.emit (node:events:525:35)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at IncomingMessage.<anonymous> (/vercel/path0/node_modules/request/request.js:1076:12)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at Object.onceWrapper (node:events:627:28)
15:14:08.391 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     at IncomingMessage.emit (node:events:525:35) {
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   status: 2,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   signal: null,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   output: [
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     null,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     Buffer(0) [Uint8Array] [],
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     Buffer(142) [Uint8Array] [
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        10, 103, 122, 105, 112,  58,  32, 115, 116, 100, 105, 110,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        58,  32, 117, 110, 101, 120, 112, 101,  99, 116, 101, 100,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        32, 101, 110, 100,  32, 111, 102,  32, 102, 105, 108, 101,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        10, 116,  97, 114,  58,  32,  85, 110, 101, 120, 112, 101,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        99, 116, 101, 100,  32,  69,  79,  70,  32, 105, 110,  32,
15:14:08.392 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        97, 114,  99, 104, 105, 118, 101,  10, 116,  97, 114,  58,
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        32,  85, 110, 101, 120, 112, 101,  99, 116, 101, 100,  32,
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR        69,  79,  70,  32, 105, 110,  32,  97, 114,  99, 104, 105,
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR       118, 101,  10, 116,
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR       ... 42 more items
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     ]
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   ],
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   pid: 391,
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   stdout: Buffer(0) [Uint8Array] [],
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   stderr: Buffer(142) [Uint8Array] [
15:14:08.393 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      10, 103, 122, 105, 112,  58,  32, 115, 116, 100, 105, 110,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      58,  32, 117, 110, 101, 120, 112, 101,  99, 116, 101, 100,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      32, 101, 110, 100,  32, 111, 102,  32, 102, 105, 108, 101,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      10, 116,  97, 114,  58,  32,  85, 110, 101, 120, 112, 101,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      99, 116, 101, 100,  32,  69,  79,  70,  32, 105, 110,  32,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      97, 114,  99, 104, 105, 118, 101,  10, 116,  97, 114,  58,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      32,  85, 110, 101, 120, 112, 101,  99, 116, 101, 100,  32,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR      69,  79,  70,  32, 105, 110,  32,  97, 114,  99, 104, 105,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     118, 101,  10, 116,
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR     ... 42 more items
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR   ]
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR }
15:14:08.394 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR
15:14:08.395 | โžค YN0000: โ”‚ @adikari/safebox@npm:1.2.0 STDERR Node.js v18.12.1
15:14:08.396 | โžค YN0009: โ”‚ @adikari/safebox@npm:1.2.0 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-ea208742/build.log)

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.