Skip to content

Commit a8000d8

Browse files
committed
feat(devel): enable vault persistence in dev mode
Switch Vault to server mode with file backend to persist data across restarts while maintaining auto-unseal and dev token convenience. Fixes #2574 Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent c7c273b commit a8000d8

2 files changed

Lines changed: 106 additions & 11 deletions

File tree

deployment/chainloop/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ vault:
7777
{{- if $tokenEnvVar }}
7878
token: {{ $tokenEnvVar | quote }}
7979
{{- else }}
80-
{{- required "VAULT_DEV_ROOT_TOKEN_ID environment variable is required when development mode is enabled" (index $.Values.vault.server.extraEnvVars "VAULT_DEV_ROOT_TOKEN_ID") }}
80+
token: "notasecret"
8181
{{- end }}
8282
{{- else if (required "vault backend selected but configuration not provided" .vault ) }}
8383
address: {{ required "vault address required" .vault.address | quote }}

deployment/chainloop/values.yaml

Lines changed: 105 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,14 +1690,109 @@ postgresql:
16901690
## @param vault.server.extraEnvVars[1].name Address to listen on development mode
16911691
## @param vault.server.extraEnvVars[1].value The address to listen on. Default: [::]:8200
16921692
vault:
1693+
extraDeploy:
1694+
- |
1695+
apiVersion: v1
1696+
kind: ConfigMap
1697+
metadata:
1698+
name: {{ include "vault.server.fullname" . }}-init
1699+
namespace: {{ include "common.names.namespace" . | quote }}
1700+
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
1701+
app.kubernetes.io/part-of: vault
1702+
app.kubernetes.io/component: server
1703+
data:
1704+
vault-init.sh: |
1705+
#!/bin/sh
1706+
#
1707+
# Copyright 2025 The Chainloop Authors.
1708+
#
1709+
# Licensed under the Apache License, Version 2.0 (the "License");
1710+
# you may not use this file except in compliance with the License.
1711+
# You may obtain a copy of the License at
1712+
#
1713+
# http://www.apache.org/licenses/LICENSE-2.0
1714+
#
1715+
# Unless required by applicable law or agreed to in writing, software
1716+
# distributed under the License is distributed on an "AS IS" BASIS,
1717+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1718+
# See the License for the specific language governing permissions and
1719+
# limitations under the License.
1720+
1721+
set -e
1722+
1723+
# Start Vault in background
1724+
vault server -config /bitnami/vault/config/config.hcl &
1725+
PID=$!
1726+
1727+
# Wait for Vault to start
1728+
echo "Waiting for Vault to start..."
1729+
until vault status > /dev/null 2>&1; STATUS=$?; [ $STATUS -eq 0 ] || [ $STATUS -eq 2 ]; do
1730+
sleep 1
1731+
done
1732+
1733+
export VAULT_ADDR='http://127.0.0.1:8200'
1734+
1735+
# Initialize if not already initialized or if init.txt is invalid
1736+
if [ ! -f /bitnami/vault/data/init.txt ] || ! grep -q "Unseal Key 1:" /bitnami/vault/data/init.txt; then
1737+
echo "Initializing Vault..."
1738+
vault operator init -key-shares=1 -key-threshold=1 > /bitnami/vault/data/init.txt
1739+
echo "Vault initialized successfully"
1740+
else
1741+
echo "Vault already initialized, using existing keys"
1742+
fi
1743+
1744+
# Unseal
1745+
echo "Reading unseal key..."
1746+
UNSEAL_KEY=$(grep 'Unseal Key 1:' /bitnami/vault/data/init.txt | awk '{print $NF}')
1747+
if [ -z "$UNSEAL_KEY" ]; then
1748+
echo "ERROR: Failed to read unseal key from init.txt"
1749+
echo "Contents of init.txt:"
1750+
cat /bitnami/vault/data/init.txt || echo "Cannot read init.txt"
1751+
exit 1
1752+
fi
1753+
echo "Unsealing Vault..."
1754+
vault operator unseal "$UNSEAL_KEY"
1755+
1756+
# Login
1757+
ROOT_TOKEN=$(grep 'Initial Root Token:' /bitnami/vault/data/init.txt | awk '{print $NF}')
1758+
export VAULT_TOKEN=$ROOT_TOKEN
1759+
1760+
# Create 'notasecret' token if it doesn't exist
1761+
if ! vault token lookup notasecret > /dev/null 2>&1; then
1762+
echo "Creating 'notasecret' token..."
1763+
vault token create -id="notasecret" -policy="root"
1764+
fi
1765+
1766+
# Enable KV v2 secrets engine (required by controlplane)
1767+
if ! vault secrets list | grep -q "^secret/"; then
1768+
echo "Enabling KV v2 secrets engine at secret/..."
1769+
vault secrets enable -path=secret kv-v2
1770+
else
1771+
echo "Secrets engine already exists at secret/"
1772+
fi
1773+
1774+
# Keep container running
1775+
wait $PID
16931776
server:
1694-
args: [
1695-
"server",
1696-
"-dev"
1697-
]
1698-
extraEnvVars:
1699-
- name: VAULT_DEV_ROOT_TOKEN_ID
1700-
value: "notasecret"
1701-
- name: VAULT_DEV_LISTEN_ADDRESS
1702-
value: "[::]:8200"
1703-
config: "storage \"inmem\" {}\ndisable_mlock = true\nui = true\nservice_registration \"kubernetes\" {}"
1777+
command: ["/vault-init.sh"]
1778+
args: [""]
1779+
config: |
1780+
disable_mlock = true
1781+
ui = true
1782+
listener "tcp" {
1783+
tls_disable = 1
1784+
address = "[::]:8200"
1785+
cluster_address = "[::]:8201"
1786+
}
1787+
storage "file" {
1788+
path = "/bitnami/vault/data"
1789+
}
1790+
extraVolumes:
1791+
- name: vault-init
1792+
configMap:
1793+
name: '{{ include "vault.server.fullname" . }}-init'
1794+
defaultMode: 0755
1795+
extraVolumeMounts:
1796+
- name: vault-init
1797+
mountPath: /vault-init.sh
1798+
subPath: vault-init.sh

0 commit comments

Comments
 (0)