add autovault helm chart
This commit is contained in:
62
autovault/templates/_helpers.tpl
Normal file
62
autovault/templates/_helpers.tpl
Normal file
@@ -0,0 +1,62 @@
|
||||
{{/*
|
||||
Expand the name of the chart.
|
||||
*/}}
|
||||
{{- define "autovault.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create a default fully qualified app name.
|
||||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
||||
If release name contains chart name it will be used as a full name.
|
||||
*/}}
|
||||
{{- define "autovault.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create chart name and version as used by the chart label.
|
||||
*/}}
|
||||
{{- define "autovault.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Common labels
|
||||
*/}}
|
||||
{{- define "autovault.labels" -}}
|
||||
helm.sh/chart: {{ include "autovault.chart" . }}
|
||||
{{ include "autovault.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Selector labels
|
||||
*/}}
|
||||
{{- define "autovault.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "autovault.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create the name of the service account to use
|
||||
*/}}
|
||||
{{- define "autovault.serviceAccountName" -}}
|
||||
{{- if .Values.serviceAccount.create }}
|
||||
{{- default (include "autovault.fullname" .) .Values.serviceAccount.name }}
|
||||
{{- else }}
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
68
autovault/templates/configmap.yaml
Normal file
68
autovault/templates/configmap.yaml
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: {{ include "autovault.fullname" . }}-scripts
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
data:
|
||||
autovault.sh: |
|
||||
#!/bin/bash
|
||||
|
||||
HOME=/vault/data
|
||||
while [[ "$(curl -L -s -o /dev/null -w ''%{http_code}'' {{ .Values.vaultUrl }})" != "200" ]]; do sleep 5; done
|
||||
|
||||
export VAULT_ADDR={{ .Values.vaultUrl }}
|
||||
|
||||
INITIALIZED=$(vault status -format=json | jq -r '.initialized')
|
||||
|
||||
SEALED=$(vault status -format=json | jq -r '.sealed')
|
||||
|
||||
if [[ "$INITIALIZED" == "false" ]] ; then
|
||||
vault operator init -key-threshold=1 -key-shares=1 -format=json > /vault/data/keys.json
|
||||
fi
|
||||
|
||||
if [[ "$SEALED" == "true" ]] ; then
|
||||
KEY=$(cat /vault/data/keys.json | jq -r '.unseal_keys_b64[0]')
|
||||
vault operator unseal $KEY
|
||||
fi
|
||||
|
||||
export VAULT_TOKEN=$(cat /vault/data/keys.json | jq -r '.root_token')
|
||||
|
||||
KV_ENABLED=$(vault secrets list | grep -i kv)
|
||||
if [[ -z "$KV_ENABLED" ]] ; then
|
||||
vault secrets enable -version=2 kv
|
||||
fi
|
||||
|
||||
USERPASS_ENABLED=$(vault auth list | grep -i userpass)
|
||||
if [[ -z "$USERPASS_ENABLED" ]] ; then
|
||||
vault auth enable userpass
|
||||
fi
|
||||
|
||||
APPROLE_ENABLED=$(vault auth list | grep -i approle)
|
||||
if [[ -z "$APPROLE_ENABLED" ]] ; then
|
||||
vault auth enable approle
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "----------------------------------------------------------------"
|
||||
echo
|
||||
echo "Vault root token: ${VAULT_TOKEN}"
|
||||
echo
|
||||
echo "----------------------------------------------------------------"
|
||||
echo
|
||||
|
||||
for APPROLE in {{ join " " .Values.autovaultGenSecretsApps }}; do
|
||||
APPROLE_CREATED=$(vault read auth/approle/role/"$APPROLE"/role-id)
|
||||
if [[ -z "$APPROLE_CREATED" ]] ; then
|
||||
vault write -f auth/approle/role/"$APPROLE"
|
||||
fi
|
||||
kubectl get secret vault-secret-"$APPROLE" || \
|
||||
{ APPROLE_ROLE_ID=$(vault read auth/approle/role/"$APPROLE"/role-id | grep "role_id\s" | awk '{print $2}') ; \
|
||||
APPROLE_SECRET_ID=$(vault write -f auth/approle/role/"$APPROLE"/secret-id | grep "secret_id\s" | awk '{print $2}') ; \
|
||||
kubectl create secret generic vault-secret-"$APPROLE" --from-literal=rootToken="$VAULT_TOKEN" --from-literal=roleId="$APPROLE_ROLE_ID" --from-literal=secretId="$APPROLE_SECRET_ID" ;
|
||||
echo "$APPROLE role-id = $APPROLE_ROLE_ID" ; }
|
||||
done
|
||||
|
||||
vault auth list
|
||||
|
||||
54
autovault/templates/cronjob.yaml
Normal file
54
autovault/templates/cronjob.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: {{ include "autovault.fullname" . }}
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
spec:
|
||||
concurrencyPolicy: Forbid
|
||||
schedule: {{ .Values.autovaultSchedule | quote }}
|
||||
successfulJobsHistoryLimit: 1
|
||||
failedJobsHistoryLimit: 1
|
||||
jobTemplate:
|
||||
spec:
|
||||
backoffLimit: 2
|
||||
activeDeadlineSeconds: 300
|
||||
template:
|
||||
spec:
|
||||
serviceAccountName: {{ include "autovault.fullname" . }}
|
||||
restartPolicy: Never
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: autovault
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
volumeMounts:
|
||||
- name: {{ include "autovault.fullname" . }}-data
|
||||
mountPath: /vault/data
|
||||
- name: {{ include "autovault.fullname" . }}-scripts
|
||||
mountPath: /vault/scripts
|
||||
command: [ "/bin/bash", "-c", "/vault/scripts/autovault.sh" ]
|
||||
volumes:
|
||||
- name: {{ include "autovault.fullname" . }}-data
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ include "autovault.fullname" . }}-data
|
||||
- name: {{ include "autovault.fullname" . }}-scripts
|
||||
configMap:
|
||||
name: {{ include "autovault.fullname" . }}-scripts
|
||||
defaultMode: 0777
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
26
autovault/templates/pvc.yaml
Normal file
26
autovault/templates/pvc.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
|
||||
kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: {{ template "autovault.fullname" . }}-data
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
{{- if .Values.persistence.annotations }}
|
||||
annotations:
|
||||
{{ toYaml .Values.persistence.annotations | indent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
accessModes:
|
||||
- {{ .Values.persistence.accessMode | quote }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.persistence.size | quote }}
|
||||
{{- if .Values.persistence.storageClass }}
|
||||
{{- if (eq "-" .Values.persistence.storageClass) }}
|
||||
storageClassName: ""
|
||||
{{- else }}
|
||||
storageClassName: "{{ .Values.persistence.storageClass }}"
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
26
autovault/templates/role.yaml
Normal file
26
autovault/templates/role.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: {{ include "autovault.fullname" . }}
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["list", "get", "watch", "create", "delete"]
|
||||
- apiGroups: [""]
|
||||
resources: ["pods/exec"]
|
||||
verbs: ["create"]
|
||||
- apiGroups: [""]
|
||||
resources: ["pods/log"]
|
||||
verbs: ["get"]
|
||||
- apiGroups: [""]
|
||||
resources: ["pods/attach"]
|
||||
verbs: ["list", "get", "create", "delete", "update"]
|
||||
- apiGroups: [""]
|
||||
resources: ["secrets"]
|
||||
verbs: ["list", "get", "create", "delete", "update"]
|
||||
- apiGroups: [""]
|
||||
resources: ["configmaps"]
|
||||
verbs: ["list", "get", "create", "delete", "update"]
|
||||
15
autovault/templates/rolebinging.yaml
Normal file
15
autovault/templates/rolebinging.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: {{ include "autovault.fullname" . }}
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
name: {{ include "autovault.fullname" . }}
|
||||
kind: Role
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: {{ include "autovault.fullname" . }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
13
autovault/templates/serviceaccount.yaml
Normal file
13
autovault/templates/serviceaccount.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
{{- if .Values.serviceAccount.create -}}
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: {{ include "autovault.serviceAccountName" . }}
|
||||
labels:
|
||||
{{- include "autovault.labels" . | nindent 4 }}
|
||||
{{- with .Values.serviceAccount.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user