Git Product home page Git Product logo

vault's Introduction

This repo is deprecated and is now maintained by TeamSnap at TeamSnap/vault-key.

Vault integration with GCP for Golang, NodeJS, and Ruby

This repo makes it easy to use Vault with GCP auth. It uses a GCP service account and JSON web tokens to login to Vault without a password. Then it retrieves the secrets you need and makes them available in your code, hassle free.

Usage

Golang

package main

import (
    "context"
    "fmt"
    "github.com/stevenaldinger/vault/pkg/vault"
)

var env = map[string]map[string]string{}

var envArr = []string{
    "secret-engine/data/secret-name",
    "secret-engine-2/data/another-secret-name",
}

func main() {
    ctx := context.Background()

    vault.GetSecrets(ctx, &env, envArr)

    fmt.Println("Secret values:", env)
    fmt.Println("secret-key value = " + env["secret-engine/data/secret-name"]["secret-key"])
    fmt.Println("secret-key-2 value = " + env["secret-engine-2/data/another-secret-name"]["secret-key-2"])
}

NodeJS

const vault = require('@aldinger/vault')

const secrets = [
  'secret-engine/data/secret-name',
  'secret-engine-2/data/another-secret-name'
]

const secretData = vault.getSecrets(secrets)

console.log('Secret values:', JSON.stringify(secretData, null, 4))
console.log(`secret-key value = ${secretData['secret-engine/data/secret-name']['secret-key']}`)
console.log(`secret-key-2 value = ${secretData['secret-engine-2/data/another-secret-name']['secret-key-2']}`)

Ruby

require 'vault'

secrets = [
  "secret-engine/data/secret-name",
  "secret-engine-2/data/another-secret-name"
]

secretData = Vault.getSecrets(secrets)

puts secretData

puts secretsData["secret-engine/data/secret-name"]["secret-key"]
puts secretsData["secret-engine-2/data/another-secret-name"]["secret-key-2"]

Environment Variable Configuration

Environment Variable Default Required (GCP) Required (other environments) Example Description
ENVIRONMENT "development" No No production If set to anything but production, prints trace level logs
FUNCTION_IDENTITY "" No Yes [email protected] Email address associated with service account
GCLOUD_PROJECT "" No Yes my-project-123 Project ID the service account belongs to
GOOGLE_APPLICATION_CREDENTIALS "" No Yes service-account/my-project-123.serviceaccount.json Path to service account credentials file
TRACE_ENABLED "false" No No true Whether or to enable opencensus tracing
TRACE_PREFIX "vault" No No my-company Prefix added to name of tracing spans
VAULT_ADDR "" Yes Yes https://vault.my-company.com Vault address including protocol
VAULT_ROLE "" Yes Yes vault-role-cloud-functions Name of role created in Vault for GCP auth

Google Cloud Auth Method

Because this project uses the Google Cloud auth method for Vault, you'll need to configure a role for the service account you're using. By default, for Google Cloud Functions that will be <project-id>@appspot.gserviceaccount.com. You can use the Terraform example to get you started.

Kubernetes

Integrating Vault with Kubernetes is easy to do with this project.

There are examples of two different strategies.

  1. Using an init container and a shared volume to write a secret to a .env file that your app can read in when it's container starts
  2. Running a job or cronjob to sync Vault secrets with Kubernetes secrets that your deployments can read in like they would any other k8s secrets.

References

vault's People

Contributors

stevenaldinger avatar

Stargazers

Cass Outlaw avatar

Watchers

James Cloos avatar  avatar  avatar

vault's Issues

Assignment to entry in nil map

Hi, Thanks for a great package

I have an issue when running getSecrets() on nodejs

INFO[0000] TRACE_ENABLED=false
INFO[0000] TRACE_PREFIX=vault
INFO[0000] VAULT_ROLE=secret-readonly
INFO[0000] GCLOUD_PROJECT=xxxx
INFO[0000] FUNCTION_IDENTITY=vault-user-svc-account@xxx.iam.gserviceaccount.com
DEBU[0000] Successfully created IAM client
DEBU[0001] Successfully generated signed JWT
DEBU[0004] Successfully logged into Vault with auth/gcp/login
DEBU[0004] secret, err := GetSecret(c, secrets/data/api/api-customer-feedback/env)
panic: assignment to entry in nil map

goroutine 17 [running, locked to thread]:
github.com/teamsnap/vault-key/pkg/vault.(*vault).getSecrets(0xc000280200, 0x0, 0x0, 0xc000280258, 0xc000038180, 0x1, 0x4, 0x0, 0x0)
	/Users/stevenaldinger/go/pkg/mod/github.com/teamsnap/vault-key/pkg/[email protected]/vault.go:76 +0x22e
github.com/teamsnap/vault-key/pkg/vault.Loot(0xc0000ba210, 0x2e, 0x2e, 0xc00006ce30, 0x1078081c5, 0xc000082060)
	/Users/stevenaldinger/go/pkg/mod/github.com/teamsnap/vault-key/pkg/[email protected]/vault.go:43 +0x190
main.GetSecrets(0x1040152c0, 0x0)
	/Users/stevenaldinger/Development/github/teamsnap/vault-key/build/package/nodejs/main.go:14 +0x47
main._cgoexpwrap_e70b38f9d402_GetSecrets(0x1040152c0, 0x0)
	_cgo_gotypes.go:71 +0x64

is it related to this issue? hashicorp/vault#5640
Thanks @stevenaldinger !

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.