GithubHelp home page GithubHelp logo

isabella232 / vault-plugin-database-k8s-controller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from monzo/vault-plugin-database-k8s-controller

0.0 0.0 0.0 10.95 MB

A fork of Vault's database credential plugin allowing the use of annotations on service accounts as parameters in statements

License: Mozilla Public License 2.0

Go 99.66% Makefile 0.34%

vault-plugin-database-k8s-controller's Introduction

vault-plugin-database-k8s-controller

A fork of Vault's database credential plugin allowing the use of an annotation on service accounts to dynamically specify user creation statements. Essentially, you can have many virtual 'roles' which each have tightly scoped database user creation statements, where the roles are in fact defined in Kubernetes. At Monzo we use this to allow for hundreds of Cassandra clients which each are allowed access to a single independent keyspace. Vault is not aware of individual services; simply logging in with your Kubernetes service account token is enough to get permission to issue the correct database credentials.

Non-builtin database plugins are not supported, as sadly custom plugins cannot call out to other custom plugins. However, all of Vault's builtin database plugins are bundled into this binary and should work as normal.

Currently based on https://github.com/hashicorp/vault/tree/v1.3.0/builtin/logical/database

To rebase:

make rebase

Instructions

This plugin differs from the default database plugin only if kubernetes config is provided

# if your plugin is registered as database-k8s
vault secrets enable -path=database -plugin-name=database-k8s database-k8s
vault write database/kubeconfig kubernetes_host=https://127.0.0.1 kubernetes_ca_cert=@cert jwt=@jwt

If this is provided, the plugin will attempt to maintain an in memory cache of all service accounts in Kubernetes. If any service accounts contain an annotation monzo.com/keyspace, the mapping from service account name to the annotation is also stored in Vault. This is so that the mapping can be used before the cache is built from the k8s API.

The purpose of this is to interpolate this annotation into any creation statements of a role, to create essentially a dynamic role for every service account. If you provide a role named like k8s_rw_s-ledger_default and this role does not explicitly exist then instead the plugin will look up the concrete role named rw, and will look up the service account s-ledger in the namespace default.

It will then replace all instances of {{annotation}} in the creation statements of the concrete rw role with the value of the annotation on that service account.

You can also set an annotation monzo.com/cluster which allows you to override the db name of the concrete rw role with the value of the annotation.

Annotation keys can be overridden with the kubeconfig endpoint, using keyspace_annotation and db_name_annotation.

The role names are designed such that they can support a vault policy as follows:

path "database/creds/k8s_rw_{{identity.entity.aliases.kubernetes.metadata.service_account_name}}_{{identity.entity.aliases.kubernetes.metadata.service_account_namespace}}"
{
  capabilities = ["read"]
}

The role name is used for these parameters so that the plugin has the same API as its upstream.

Example

$ vault write database/roles/rw \
    db_name=my-cassandra-database \
    creation_statements="CREATE USER '{{username}}' WITH PASSWORD '{{password}}' NOSUPERUSER;" \
    creation_statements="GRANT ALL PERMISSIONS ON KEYSPACE \"{{annotation}}\" TO {{username}};" \
    default_ttl="1h" \
    max_ttl="24h"
Success! Data written to: database/roles/rw

kubectl create serviceaccount s-ledger
kubectl annotate serviceaccount s-ledger monzo.com/keyspace='ledger'

$ vault read database/roles/k8s_rw_s-ledger_default
Key                      Value
---                      -----
creation_statements      [CREATE USER '{{username}}' WITH PASSWORD '{{password}}' NOSUPERUSER; GRANT ALL PERMISSIONS ON KEYSPACE "ledger" TO {{username}};]
db_name                  my-cassandra-database
default_ttl              1h
max_ttl                  24h
renew_statements         []
revocation_statements    []
rollback_statements      []

vault-plugin-database-k8s-controller's People

Contributors

briankassouf avatar calvn avatar catsby avatar chrishoffman avatar jackkleeman avatar jefferai avatar jsoref avatar kalafut avatar ncabatoff avatar nickrmc83 avatar vishalnayak avatar

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.