kubevaulter

package module
v0.0.0-...-aee7741 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

README

kubevaulter

Warning: This project is in alpha phase and breaking changes are usual.

Kubevaulter are helper tools to handle secrets stored in vault inside your kubernetes cluster.

Authentication

For authentication against vault, kubevaulter-init uses the Kubernetes service account token mounted by default into each pod by Kubernetes automatically. The token should reside under /var/run/secrets/kubernetes.io/serviceaccount/token and is signed by the Kubernetes signing CA

Prerequisites

To use these tools vault must be correctly configured and
reachable from within the kubernetes cluster. kubernetes must support RBAC

Kubernetes with RBAC

and the api-server must be started with the flags --authorization-mode=RBAC and --service-account-lookup.

Also the correct service accounts and clusterRoles and RoleBindings must exist

Kubernetes ClusterRole

This ClusterRole should exist by default, if not it has to be created.

- apiVersion: rbac.authorization.k8s.io/v1
  kind: ClusterRole
  metadata:
    annotations:
      rbac.authorization.kubernetes.io/autoupdate: "true"
    creationTimestamp: null
    labels:
      kubernetes.io/bootstrapping: rbac-defaults
    name: system:auth-delegator
  rules:
  - apiGroups:
    - authentication.k8s.io
    resources:
    - tokenreviews
    verbs:
    - create
  - apiGroups:
    - authorization.k8s.io
    resources:
    - subjectaccessreviews
    verbs:
    - create
Create Service Accounts

One service account need to exist with which vault authenticates against the kubernetes api.

apiVersion: v1
kind: ServiceAccount
metadata:
 name: vault-auth

For each pod that accesses secrets in vault, a service account should exist to authenticate against vault. This can also be the default namespace service account, depending on the needs.

Create Role Binding
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
 name: role-tokenreview-binding
 namespace: default
roleRef:
 apiGroup: rbac.authorization.k8s.io
 kind: ClusterRole
 name: system:auth-delegator
subjects:
- kind: ServiceAccount
 name: vault-auth
 namespace: default
Vault

To use authentication via service account tokens, the Kubernetes Auth Backend must be enabled and configured correctly. Also policies must exist to manage access of the role to vault secret paths

Enable Kubernetes Auth in Vault
$ vault auth-enable kubernetes
Successfully enabled 'kubernetes' at 'kubernetes'!
Create Role
vault write auth/kubernetes/role/DEMO \
    bound_service_account_names=DEMO-SA\
    bound_service_account_namespaces=DEMO-NS \
    policies=DEMO-POLICY \
    ttl=1h
Example Policy
path "secret/*" {
  capabilities = ["create"]
}

path "secret/foo" {
  capabilities = ["read"]
}

path "auth/token/lookup-self" {
  capabilities = ["read"]
}
General Kubevaulter Config

To configure Kubevaulter, a config file called config in yaml, toml or json format must exist in . or ./config folder of the containers. The location could be overwritten by specifying the environment variable KV_ the general config looks like this

logging:
  logLevel: "debug" #defaults to "info"
  logFormat: "json" #default to "text"
  
vault:
  endpointUrl: "http://localhost:8200"
  secretBackend: "demo-secret" # defaults to "secret" 
  role: "DEMO"
  jwtPath:  "/var/run/secrets/kubernetes.io/serviceaccount/token"  # defaults to "/var/run/secrets/kubernetes.io/serviceaccount/token" 
  failOnEmptySecret: true
  authPath: auth/foo/login # defaults to auth/kubernetes/login
  caCert:

Available tools

  • kubevaulter-init an init container to render vault secrets into templates from specific path in the pod filesystem
  • kubevaulter-recursive an init container to recursively traverse through a folder structure and rendereing templates with secret values from vault
  • kubevaulter-generator creates random strings and stores them in specified vault paths
  • kubevaulter-executor executing applications inside the container while providing secret values from vault as parameters to this application

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiWrapper

type ApiWrapper struct {
	// contains filtered or unexported fields
}

ApiWrapper is a wrapper around the official vault raw client as well as the more abstract logical api. It also holds a login forge for creating login requests to authenticate against a vault auth backend.

func NewApiWrapper

func NewApiWrapper(loginForger LoginForge, addr string) (*ApiWrapper, error)

NewApiWrapper creates an ApiWrapper with the specified LoginForge and vault server address.

func (*ApiWrapper) KubeAuth

func (aw *ApiWrapper) KubeAuth() (*vault.Secret, error)

KubeAuth performs

func (*ApiWrapper) Populate

func (aw *ApiWrapper) Populate()

func (*ApiWrapper) Read

func (aw *ApiWrapper) Read(path string) (*vault.Secret, error)

func (*ApiWrapper) Write

func (aw *ApiWrapper) Write(path string, data map[string]interface{}) (*vault.Secret, error)

type JwtLoginForge

type JwtLoginForge struct {
	Payload map[string]interface{}
	// contains filtered or unexported fields
}

func NewJwtLoginForge

func NewJwtLoginForge(k8sAuthPath, path, role, caCert string) (*JwtLoginForge, error)

func (*JwtLoginForge) CaCert

func (ka *JwtLoginForge) CaCert() string

func (*JwtLoginForge) ForgeRequest

func (ka *JwtLoginForge) ForgeRequest() map[string]interface{}

func (*JwtLoginForge) GetPath

func (ka *JwtLoginForge) GetPath() string

func (*JwtLoginForge) ReadToken

func (ka *JwtLoginForge) ReadToken(path string) error

func (*JwtLoginForge) SetRole

func (ka *JwtLoginForge) SetRole(role string)

type LoginForge

type LoginForge interface {
	SetRole(role string)
	GetPath() string
	CaCert() string
	ForgeRequest() map[string]interface{}
}

type Secret

type Secret struct {
	Name string
	Path string
	Data SecretData
}

type SecretData

type SecretData map[string]interface{}

type SecretDataMap

type SecretDataMap map[string]Secret

Directories

Path Synopsis
cmd
gen
rec

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL