Sign inSign up

ogulcanaydogan/vault-init

By ogulcanaydogan

Updated 7 months ago

HashiCorp Vault secret injector for Kubernetes init containers

Image
0

1.2K

ogulcanaydogan/vault-init repository overview

Vault Init

Kubernetes init container that fetches secrets from HashiCorp Vault and writes them to a shared volume.

Quick Start

docker run \
  -e VAULT_ADDR=http://vault:8200 \
  -e VAULT_TOKEN=hvs.xxx \
  -e VAULT_SECRET_PATH=secret/myapp \
  -v $(pwd)/secrets:/secrets \
  ogulcanaydogan/vault-init

Authentication Methods

Token
-e VAULT_AUTH_METHOD=token -e VAULT_TOKEN=hvs.xxx
AppRole
-e VAULT_AUTH_METHOD=approle -e VAULT_ROLE_ID=xxx -e VAULT_SECRET_ID=xxx
Kubernetes (auto-detects service account)
-e VAULT_AUTH_METHOD=kubernetes -e VAULT_ROLE=myapp

Environment Variables

VariableDescriptionDefault
VAULT_ADDRVault server addresshttp://vault:8200
VAULT_AUTH_METHODAuth method (token/approle/kubernetes)token
VAULT_TOKENVault token-
VAULT_ROLE_IDAppRole role ID-
VAULT_SECRET_IDAppRole secret ID-
VAULT_ROLEK8s auth role name-
VAULT_SECRET_PATHSecret path (required)-
VAULT_KV_VERSIONKV engine version (1 or 2)2
OUTPUT_FORMATOutput format (env/json/yaml)env
OUTPUT_FILEOutput file path/secrets/.env
TEMPLATE_FILETemplate file for custom output-
SECRET_PREFIXPrefix for env variable names-

Docker Compose Example

services:
  vault-init:
    image: ogulcanaydogan/vault-init
    environment:
      - VAULT_ADDR=http://vault:8200
      - VAULT_TOKEN=${VAULT_TOKEN}
      - VAULT_SECRET_PATH=secret/myapp
    volumes:
      - secrets:/secrets

  app:
    image: myapp
    depends_on:
      vault-init:
        condition: service_completed_successfully
    volumes:
      - secrets:/secrets:ro
    env_file:
      - /secrets/.env

volumes:
  secrets:

Kubernetes Example

initContainers:
  - name: vault-init
    image: ogulcanaydogan/vault-init
    env:
      - name: VAULT_ADDR
        value: "http://vault.vault:8200"
      - name: VAULT_AUTH_METHOD
        value: "kubernetes"
      - name: VAULT_ROLE
        value: "myapp"
      - name: VAULT_SECRET_PATH
        value: "secret/myapp/config"
    volumeMounts:
      - name: secrets
        mountPath: /secrets

License

MIT

Tag summary

Content type

Image

Digest

sha256:83ff6b8c0

Size

129.2 MB

Last updated

7 months ago

docker pull ogulcanaydogan/vault-init