GithubHelp home page GithubHelp logo

hmuendel / kubevaulter Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 21.53 MB

Helper containers for k8s to authenticate via the service account token and prepare the secrets for usage in pods

License: Apache License 2.0

Go 95.88% Shell 4.12%

kubevaulter's Introduction

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

kubevaulter's People

Contributors

hmuendel avatar

Stargazers

 avatar Viacheslav Vasilyev avatar

Watchers

 avatar

kubevaulter's Issues

vaultexec is missing

Hi Hans,

It seems vaultexec is missing. Could you please check where it's gone? :)

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.