All Projects → dsa0x → sicher

dsa0x / sicher

Licence: MIT License
Sicher is a go module that allows secure storage of encrypted credentials in a version control system.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to sicher

secret config
Centralized Configuration and Secrets Management for Ruby and Rails applications.
Stars: ✭ 15 (-44.44%)
Mutual labels:  secret-keys, secrets-management
env-dot-prop
♻️ Get, set, or delete nested properties of process.env using a dot path
Stars: ✭ 31 (+14.81%)
Mutual labels:  environment-variables, env
envyable
The simplest yaml to ENV config loader.
Stars: ✭ 78 (+188.89%)
Mutual labels:  environment-variables, env
envclasses
envclasses is a library to map fields on dataclass object to environment variables.
Stars: ✭ 26 (-3.7%)
Mutual labels:  environment-variables, env
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+196.3%)
Mutual labels:  environment-variables, env
webpack-dotenv-plugin
Use dotenv with webpack.
Stars: ✭ 53 (+96.3%)
Mutual labels:  environment-variables, env
envman
Manage your .env configuration easily
Stars: ✭ 20 (-25.93%)
Mutual labels:  environment-variables, env
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (+14.81%)
Mutual labels:  environment-variables, env
envset
Set env vars before running your program, manage environment and secrets.
Stars: ✭ 34 (+25.93%)
Mutual labels:  environment-variables, env
vite-plugin-environment
Easily expose environment variables in Vite.js
Stars: ✭ 57 (+111.11%)
Mutual labels:  environment-variables, env
tfenv
Transform environment variables for use with Terraform (e.g. `HOSTNAME` ⇨ `TF_VAR_hostname`)
Stars: ✭ 120 (+344.44%)
Mutual labels:  environment-variables, env
fuck-env
Fuck environment variables everywhere
Stars: ✭ 14 (-48.15%)
Mutual labels:  environment-variables, env
envsafe
🔒 Makes sure you don't accidentally deploy apps with missing or invalid environment variables.
Stars: ✭ 705 (+2511.11%)
Mutual labels:  environment-variables, env
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (+122.22%)
Mutual labels:  environment-variables, env
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+166.67%)
Mutual labels:  environment-variables, env
checkdotenv
Verify environment variables presence for Node JS.
Stars: ✭ 12 (-55.56%)
Mutual labels:  environment-variables, env
envy
Use envy to manage environment variables with your OS keychain
Stars: ✭ 23 (-14.81%)
Mutual labels:  environment-variables, secrets-management
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+6770.37%)
Mutual labels:  environment-variables, env
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (+29.63%)
Mutual labels:  environment-variables, env
php-env
A small and fast .env loader for PHP
Stars: ✭ 19 (-29.63%)
Mutual labels:  environment-variables, env

Sicher

Sicher is a Go implementation of the secret management system that was introduced in Ruby on Rails 6.

Sicher is a go package that allows the secure storage of encrypted credentials in a version control system. The credentials can only be decrypted by a key file, and this key file is not added to the source control. The file is edited in a temp file on a local system and destroyed after each edit.

Using sicher in a project creates a set of files

  • environment.enc
    • This is an encrypted file that stores the credentials. Since it is encrypted, it is safe to store these credentials in source control.
    • It it is encrypted using the AES encryption system.
  • environment.key
    • This is the master key used to decrypt the credentials. This must not be committed to source control.

Installation

To use sicher in your project, you need to install the go module as a library and also as a CLI tool.

Installing the library,

go get github.com/dsa0x/sicher

Installing the command line interface,:

go install github.com/dsa0x/sicher/cmd/sicher

Usage

To initialize a new sicher project

sicher init

Optional flags:

flag description default options
-env set the environment name dev
-path set the path to the credentials file .
-style set the style of the decrypted credentials file dotenv dotenv or yaml
-gitignore path to the gitignore file. the key file will be added here, if given

This will create a key file {environment}.key and an encrypted credentials file {environment}.enc in the current directory. The environment name is optional and defaults to dev, but can be set to anything else with the -env flag.

To edit the credentials:

sicher edit

OR

to use the key from environment variable:

env SICHER_MASTER_KEY=`{YOUR_KEY_HERE}` sicher edit

Optional flags:

flag description default options
-env set the environment name dev
-path set the path to the credentials file .
-editor set the editor to use vim vim, nano, vi, code
-style set the style of the decrypted credentials file dotenv dotenv or yaml

This will create a temporary file, decrypt the credentials into it, and open it in your editor. The editor defaults to vim, but can be also set to other editors with the -editor flag. The temporary file is destroyed after each save, and the encrypted credentials file is updated with the new content.

Then in your app, you can use the sicher library to load the credentials:

package main
import (
	"fmt"

	"github.com/dsa0x/sicher/sicher"
)

type Config struct {
	Port        string `required:"true" env:"PORT"`
	MongoDbURI  string `required:"true" env:"MONGO_DB_URI"`
	MongoDbName string `required:"true" env:"MONGO_DB_NAME"`
	AppUrl   string `required:"false" env:"APP_URL"`
}

func main() {
	var config Config

	s := sicher.New("dev", ".")
	s.SetEnvStyle("yaml") // default is dotenv
	err := s.LoadEnv("", &cfg)
	if err != nil {
		fmt.Println(err)
		return
	}
}

The LoadEnv function will load the credentials from the encrypted file {environment.enc}, decrypt it with the key file {environment.key} or the environment variable SICHER_MASTER_KEY, and then unmarshal the result into the given config object. The example above uses a struct, but the object can be of type struct or map[string]string.

LoadEnv Parameters:

name description type
prefix the prefix of the environment variables string
config the config object struct or map

The key also be loaded from the environment variable SICHER_MASTER_KEY. In production, storing the key in the environment variable is recommended.

All env files should be in the format like the example below:

For dotenv:

PORT=8080
MONGO_DB_URI=mongodb://localhost:27017
MONGO_DB_NAME=sicher
APP_URL=http://localhost:8080

For yaml:

PORT:8080
MONGO_DB_URI:mongodb://localhost:27017
MONGO_DB_NAME:sicher
APP_URL:http://localhost:8080

If the object is a struct, the env tag must be attached to each variable. The required tag is optional, but if set to true, it will be used to check if the field is set. If the field is not set, an error will be returned. An example of how the struct will look like:

type Config struct {
	Port        string `required:"true" env:"PORT"`
	MongoDbURI  string `required:"true" env:"MONGO_DB_URI"`
	MongoDbName string `required:"true" env:"MONGO_DB_NAME"`
	AppUrl   string `required:"false" env:"APP_URL"`
}

If object is a map, the keys are the environment variables and the values are the values.

Note

  • Not tested with Windows.

Todo or not todo

  • Add a -force flag to sicher init to overwrite the encrypted file if it already exists
  • Enable support for nested yaml env files
  • Add support for other types of encryption
  • Test on windows

License

MIT License

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].