Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39d3e6cb6f | ||
|
|
967bbeadc6 | ||
|
|
99cf885600 | ||
|
|
01999ce28f | ||
|
|
8e87e33937 | ||
|
|
1c1a1b2441 |
No files matched your search
@@ -0,0 +1,99 @@
|
||||
name: Deploy Openbao
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "06-openbao/**"
|
||||
- ".gitea/workflows/06-deploy-openbao.yaml"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "06-openbao/**"
|
||||
- ".gitea/workflows/**"
|
||||
|
||||
jobs:
|
||||
preview:
|
||||
name: Pulumi Preview
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'pull_request'
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
|
||||
- name: Checkout Stack Config
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: kasun/homelab-pulumi-config
|
||||
ref: main
|
||||
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||
path: .pulumi-config
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
working-directory: 06-openbao
|
||||
|
||||
- name: Preview
|
||||
uses: pulumi/actions@v5
|
||||
with:
|
||||
command: preview
|
||||
stack-name: dev
|
||||
work-dir: 06-openbao
|
||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||
env:
|
||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||
|
||||
deploy:
|
||||
name: Pulumi Deploy
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
|
||||
- name: Checkout Stack Config
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: kasun/homelab-pulumi-config
|
||||
ref: main
|
||||
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||
path: .pulumi-config
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
working-directory: 06-openbao
|
||||
|
||||
- name: Refresh State
|
||||
uses: pulumi/actions@v5
|
||||
with:
|
||||
command: refresh
|
||||
stack-name: dev
|
||||
work-dir: 06-openbao
|
||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||
env:
|
||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||
|
||||
- name: Deploy
|
||||
uses: pulumi/actions@v5
|
||||
with:
|
||||
command: up
|
||||
stack-name: dev
|
||||
work-dir: 06-openbao
|
||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||
env:
|
||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||
@@ -74,10 +74,11 @@ function k3sInstallScript(
|
||||
return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`;
|
||||
}
|
||||
|
||||
// Kubernetes API address (port 6443), used by kubectl, Pulumi and joining nodes.
|
||||
// pfSense holds this IP, and HAProxy forwards connections to the masters, so
|
||||
// the API doesn't depend on a single master.
|
||||
// This isn't kubeVipAddress in 03-k8s-infra, which is Traefik's IP for web apps.
|
||||
// Control-plane VIP — floating IP for API server access, ARP-announced by
|
||||
// kube-vip on whichever master is alive. Added as a TLS SAN on master-1's
|
||||
// cert below, then used (instead of master1Ip) for every other node's join
|
||||
// URL and for the exported kubeconfig, so the cluster stays reachable
|
||||
// through the loss of any single master.
|
||||
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
|
||||
|
||||
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
|
||||
|
||||
@@ -16,10 +16,6 @@ const truenasNfsPath = config.requireSecret("truenasNfsPath");
|
||||
const cloudflareToken = config.requireSecret("cloudflareApiToken");
|
||||
const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
||||
|
||||
// Traefik's IP for web apps (ports 80 and 443). kube-vip announces it on the
|
||||
// LAN, and the app domains in pfSense's DNS Resolver must point to it.
|
||||
// This isn't the Kubernetes API address. That's controlPlaneVipAddress in
|
||||
// 02-k8s-bootstrap, which is provided by pfSense and HAProxy.
|
||||
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
||||
const kubeVipInterface = config.require("kubeVipInterface");
|
||||
|
||||
@@ -551,7 +547,6 @@ const kubeVipCloudProvider = new k8s.apps.v1.Deployment(
|
||||
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
|
||||
);
|
||||
|
||||
// Assigns kubeVipAddress to the Traefik Service that k3s creates.
|
||||
new k8s.core.v1.ServicePatch(
|
||||
"traefik-vip",
|
||||
{
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
name: openbao
|
||||
description: Openbao stack for centralized ha secret management
|
||||
runtime:
|
||||
name: nodejs
|
||||
options:
|
||||
packagemanager: npm
|
||||
stackConfigDir: ../.pulumi-config/06-openbao
|
||||
@@ -0,0 +1,260 @@
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as k8s from "@pulumi/kubernetes";
|
||||
|
||||
const bootstrapRef = new pulumi.StackReference(
|
||||
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
|
||||
);
|
||||
const appsRef = new pulumi.StackReference(
|
||||
`${pulumi.getOrganization()}/k8s-apps/dev`,
|
||||
);
|
||||
|
||||
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
|
||||
const domain = appsRef.requireOutput("domain");
|
||||
const openbaoHost = pulumi.interpolate`bao.${domain}`;
|
||||
|
||||
const k8sProvider = new k8s.Provider("k3s", {
|
||||
kubeconfig,
|
||||
clusterIdentifier: "homelab-k3s",
|
||||
});
|
||||
|
||||
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
||||
provider: k8sProvider,
|
||||
...extras,
|
||||
});
|
||||
|
||||
const openbaoNs = new k8s.core.v1.Namespace(
|
||||
"openbao",
|
||||
{ metadata: { name: "openbao" } },
|
||||
{ provider: k8sProvider, protect: true },
|
||||
);
|
||||
|
||||
const selfsigned = new k8s.apiextensions.CustomResource(
|
||||
"openbao-selfsigned",
|
||||
{
|
||||
apiVersion: "cert-manager.io/v1",
|
||||
kind: "Issuer",
|
||||
metadata: {
|
||||
name: "openbao-selfsigned",
|
||||
namespace: openbaoNs.metadata.name,
|
||||
},
|
||||
spec: {
|
||||
selfSigned: {},
|
||||
},
|
||||
},
|
||||
opts(),
|
||||
);
|
||||
|
||||
const caCert = new k8s.apiextensions.CustomResource(
|
||||
"openbao-ca",
|
||||
{
|
||||
apiVersion: "cert-manager.io/v1",
|
||||
kind: "Certificate",
|
||||
metadata: { name: "openbao-ca", namespace: openbaoNs.metadata.name },
|
||||
spec: {
|
||||
secretName: "openbao-ca",
|
||||
commonName: "openbao-ca",
|
||||
isCA: true,
|
||||
issuerRef: { name: "openbao-selfsigned", kind: "Issuer" },
|
||||
duration: "87600h",
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [selfsigned] }),
|
||||
);
|
||||
|
||||
const caIssuer = new k8s.apiextensions.CustomResource(
|
||||
"openbao-ca-issuer",
|
||||
{
|
||||
apiVersion: "cert-manager.io/v1",
|
||||
kind: "Issuer",
|
||||
metadata: { name: "openbao-ca", namespace: openbaoNs.metadata.name },
|
||||
spec: {
|
||||
ca: { secretName: "openbao-ca" },
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [caCert] }),
|
||||
);
|
||||
|
||||
const serverCert = new k8s.apiextensions.CustomResource(
|
||||
"openbao-server-tls",
|
||||
{
|
||||
apiVersion: "cert-manager.io/v1",
|
||||
kind: "Certificate",
|
||||
metadata: {
|
||||
name: "openbao-server-tls",
|
||||
namespace: openbaoNs.metadata.name,
|
||||
},
|
||||
spec: {
|
||||
secretName: "openbao-server-tls",
|
||||
dnsNames: [
|
||||
"openbao-0.openbao-internal",
|
||||
"openbao-1.openbao-internal",
|
||||
"openbao-2.openbao-internal",
|
||||
"openbao-active.openbao.svc",
|
||||
"localhost",
|
||||
],
|
||||
ipAddresses: ["127.0.0.1"],
|
||||
issuerRef: { name: "openbao-ca", kind: "Issuer" },
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [caIssuer] }),
|
||||
);
|
||||
|
||||
const serversTransport = new k8s.apiextensions.CustomResource(
|
||||
"openbao-servers-transport",
|
||||
{
|
||||
apiVersion: "traefik.io/v1alpha1",
|
||||
kind: "ServersTransport",
|
||||
metadata: {
|
||||
name: "openbao-servers-transport",
|
||||
namespace: openbaoNs.metadata.name,
|
||||
},
|
||||
spec: {
|
||||
serverName: "openbao-active.openbao.svc",
|
||||
rootCAs: [{ secret: "openbao-server-tls" }],
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [serverCert] }),
|
||||
);
|
||||
|
||||
new k8s.helm.v3.Release(
|
||||
"openbao",
|
||||
{
|
||||
name: "openbao",
|
||||
chart: "openbao",
|
||||
repositoryOpts: { repo: "https://openbao.github.io/openbao-helm" },
|
||||
namespace: "openbao",
|
||||
version: "0.30.8",
|
||||
// Pods stay unready until they are initialised and unsealed by hand.
|
||||
skipAwait: true,
|
||||
values: {
|
||||
global: {
|
||||
tlsDisable: false,
|
||||
},
|
||||
injector: {
|
||||
enabled: false,
|
||||
},
|
||||
server: {
|
||||
podManagementPolicy: "Parallel",
|
||||
resources: {
|
||||
requests: { cpu: "100m", memory: "256Mi" },
|
||||
limits: { memory: "512Mi" },
|
||||
},
|
||||
volumes: [
|
||||
{ name: "server-tls", secret: { secretName: "openbao-server-tls" } },
|
||||
],
|
||||
volumeMounts: [
|
||||
{
|
||||
name: "server-tls",
|
||||
mountPath: "/openbao/userconfig/openbao-server-tls",
|
||||
readOnly: true,
|
||||
},
|
||||
],
|
||||
extraEnvironmentVars: {
|
||||
BAO_CACERT: "/openbao/userconfig/openbao-server-tls/ca.crt",
|
||||
},
|
||||
service: {
|
||||
active: {
|
||||
annotations: {
|
||||
"traefik.ingress.kubernetes.io/service.serverstransport":
|
||||
"openbao-openbao-servers-transport@kubernetescrd",
|
||||
},
|
||||
},
|
||||
},
|
||||
ingress: {
|
||||
enabled: true,
|
||||
ingressClassName: "traefik",
|
||||
annotations: { "cert-manager.io/cluster-issuer": "letsencrypt-prod" },
|
||||
hosts: [{ host: openbaoHost, paths: ["/"] }],
|
||||
tls: [{ secretName: "openbao-ingress-tls", hosts: [openbaoHost] }],
|
||||
},
|
||||
networkPolicy: {
|
||||
enabled: true,
|
||||
ingress: [
|
||||
{
|
||||
from: [
|
||||
{
|
||||
namespaceSelector: {
|
||||
matchLabels: {
|
||||
"kubernetes.io/metadata.name": "kube-system",
|
||||
},
|
||||
},
|
||||
podSelector: {
|
||||
matchLabels: { "app.kubernetes.io/name": "traefik" },
|
||||
},
|
||||
},
|
||||
],
|
||||
ports: [{ port: 8200, protocol: "TCP" }],
|
||||
},
|
||||
{
|
||||
from: [
|
||||
{
|
||||
podSelector: {
|
||||
matchLabels: {
|
||||
"app.kubernetes.io/name": "openbao",
|
||||
"app.kubernetes.io/instance": "openbao",
|
||||
component: "server",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
ports: [
|
||||
{ port: 8200, protocol: "TCP" },
|
||||
{ port: 8201, protocol: "TCP" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
ha: {
|
||||
enabled: true,
|
||||
replicas: 3,
|
||||
apiAddr: "https://$(BAO_K8S_POD_NAME).openbao-internal:8200",
|
||||
raft: {
|
||||
enabled: true,
|
||||
setNodeId: true,
|
||||
config: `ui = true
|
||||
|
||||
listener "tcp" {
|
||||
address = "[::]:8200"
|
||||
cluster_address = "[::]:8201"
|
||||
tls_cert_file = "/openbao/userconfig/openbao-server-tls/tls.crt"
|
||||
tls_key_file = "/openbao/userconfig/openbao-server-tls/tls.key"
|
||||
tls_auto_reload = true
|
||||
}
|
||||
|
||||
storage "raft" {
|
||||
path = "/openbao/data"
|
||||
|
||||
retry_join {
|
||||
leader_api_addr = "https://openbao-0.openbao-internal:8200"
|
||||
leader_ca_cert_file = "/openbao/userconfig/openbao-server-tls/ca.crt"
|
||||
}
|
||||
retry_join {
|
||||
leader_api_addr = "https://openbao-1.openbao-internal:8200"
|
||||
leader_ca_cert_file = "/openbao/userconfig/openbao-server-tls/ca.crt"
|
||||
}
|
||||
retry_join {
|
||||
leader_api_addr = "https://openbao-2.openbao-internal:8200"
|
||||
leader_ca_cert_file = "/openbao/userconfig/openbao-server-tls/ca.crt"
|
||||
}
|
||||
}
|
||||
|
||||
service_registration "kubernetes" {}
|
||||
|
||||
audit "file" "stdout" {
|
||||
options {
|
||||
file_path = "stdout"
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
},
|
||||
dataStorage: {
|
||||
enabled: true,
|
||||
storageClass: "local-path",
|
||||
size: "2Gi",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
opts({ dependsOn: [serversTransport], protect: true }),
|
||||
);
|
||||
Generated
+1499
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "openbao",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.19.4",
|
||||
"typescript": "^6.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pulumi/kubernetes": "^4.31.1",
|
||||
"@pulumi/pulumi": "^3.278.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"outDir": "bin",
|
||||
"target": "es2024",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
@@ -7,17 +7,17 @@ Use this to rebuild the k3s cluster from new VMs. **It destroys everything store
|
||||
## Why a normal `pulumi up` isn't enough
|
||||
|
||||
- **`02-k8s-bootstrap` commands run once.** They are recorded as done in state, so after new VMs appear, `pulumi up` would report them unchanged and install nothing.
|
||||
- **`03`–`05` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist.
|
||||
- **`03`–`06` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist.
|
||||
|
||||
## Before you start
|
||||
|
||||
1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected.
|
||||
2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04` and `05` workflows, and don't merge anything until the last step.
|
||||
1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected. OpenBao's data is lost too, so [save a snapshot](openbao.md#save-a-snapshot) outside the cluster and keep its unseal key and admin password.
|
||||
2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04`, `05` and `06` workflows, and don't merge anything until the last step.
|
||||
3. **Back up all state.** Run this from the repo root:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/state-backups/rebuild
|
||||
for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring; do
|
||||
for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring 06-openbao; do
|
||||
pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json
|
||||
done
|
||||
```
|
||||
@@ -57,17 +57,17 @@ Use this to rebuild the k3s cluster from new VMs. **It destroys everything store
|
||||
pulumi up --stack dev --cwd 01-proxmox-infra
|
||||
```
|
||||
|
||||
## 2. Clear the state of `02`–`05`
|
||||
## 2. Clear the state of `02`–`06`
|
||||
|
||||
Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or `Pulumi.dev.yaml`. `--force` is needed because `05-monitoring` protects its namespace and Helm release, so check that the old cluster is really gone before running it.
|
||||
Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or `Pulumi.dev.yaml`. `--force` is needed because `05-monitoring` and `06-openbao` protect their namespaces and Helm releases, so check that the old cluster is really gone before running it.
|
||||
|
||||
```bash
|
||||
for S in 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do
|
||||
for S in 06-openbao 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do
|
||||
pulumi state delete --all --force --yes --stack dev --cwd "$S"
|
||||
done
|
||||
```
|
||||
|
||||
Previews of `03`–`05` fail until step 3 is done, because `02` has no `kubeconfig` output yet.
|
||||
Previews of `03`–`06` fail until step 3 is done, because `02` has no `kubeconfig` output yet.
|
||||
|
||||
## 3. Bootstrap k3s (`02-k8s-bootstrap`)
|
||||
|
||||
@@ -89,13 +89,14 @@ Secret encryption is configured with `secretbox`.
|
||||
|
||||
**Checkpoint:** all six nodes are `Ready`. Then replace your normal kubeconfig with this file, because the old one no longer works.
|
||||
|
||||
## 4. Deploy `03`, `04` and `05`
|
||||
## 4. Deploy `03`–`06`
|
||||
|
||||
Deploy these through Gitea, because the runners have the `helm` CLI that `03` needs. Re-enable each workflow as you reach it, and wait for each run to finish.
|
||||
|
||||
1. Run the **Deploy k8s Infra** workflow manually.
|
||||
2. Run the **Deploy k8s Apps** workflow manually.
|
||||
3. Run the **Deploy Monitoring** workflow manually.
|
||||
4. Run the **Deploy Openbao** workflow manually, then [restore the OpenBao snapshot](openbao.md#restore-into-a-new-openbao).
|
||||
|
||||
## 5. Verify
|
||||
|
||||
@@ -109,4 +110,4 @@ kubectl get certificates -A
|
||||
|
||||
**Checkpoint:** nodes are `Ready`, no pods are unhealthy, PVCs are `Bound`, and certificates become `Ready`. New certificates come from Let's Encrypt, which rate-limits repeated requests for the same hostnames, so avoid repeated rebuilds in a short period.
|
||||
|
||||
Run `pulumi preview --stack dev --cwd <stack>` for all five stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`.
|
||||
Run `pulumi preview --stack dev --cwd <stack>` for all six stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`.
|
||||
@@ -0,0 +1,389 @@
|
||||
# OpenBao
|
||||
|
||||
Use this to set up OpenBao after its first deploy, unseal it after restarts, and back it up or recover it. `06-openbao` runs three pods that copy their data to each other using Raft. Unsealing is manual, with one unseal key.
|
||||
|
||||
> The main commands were tested on local OpenBao 2.7.3 servers without Kubernetes or TLS, not on the cluster. **If a checkpoint doesn't match, stop.**
|
||||
|
||||
## Rules
|
||||
|
||||
- **Only run `init` once, during first setup or on a new, empty OpenBao before a restore.** After a restart, you only need to unseal.
|
||||
- **Keep the unseal key in Bitwarden, plus a copy outside Bitwarden** (on paper or an offline USB stick). If all pods restart and the key is lost, the data can't be recovered, even from snapshots.
|
||||
- Never put keys, tokens or passwords in Git, chats, tickets or commands. Enter them only when prompted, in a terminal that isn't being recorded.
|
||||
- **Don't delete the `data-openbao-*` PVCs**, except when [replacing a lost worker](#replace-a-lost-worker). Deleting one deletes that pod's data.
|
||||
|
||||
Run the commands in Bash on your workstation. Replace `<domain>` with your domain. In steps that use `$POD`, set it to the active pod first, and again whenever you open a new terminal or a pod restarts:
|
||||
|
||||
```bash
|
||||
POD=$(kubectl -n openbao get pod -l openbao-active=true -o name); echo "$POD"
|
||||
```
|
||||
|
||||
**Checkpoint:** it prints exactly one pod.
|
||||
|
||||
## First setup
|
||||
|
||||
### 1. Check the deployment
|
||||
|
||||
1. In pfSense's DNS Resolver, point `bao.<domain>` to Traefik's IP (`kubeVipAddress`), not the Kubernetes API address.
|
||||
2. Check the pods, volumes and certificates:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get pods,pvc,certificates
|
||||
```
|
||||
|
||||
**Checkpoint:** all three pods are `Running` but show `0/1`, the PVCs are `Bound` and the certificates are `Ready`. The web UI doesn't work until OpenBao is unsealed.
|
||||
|
||||
### 2. Initialise
|
||||
|
||||
Run this **once, only on `openbao-0`**:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it openbao-0 -- bao operator init -key-shares=1 -key-threshold=1
|
||||
```
|
||||
|
||||
It shows the **unseal key** and **initial root token** only once. Save both in Bitwarden and make the second copy of the unseal key. Then clear the terminal and its scrollback. You'll delete the root token in step 7.
|
||||
|
||||
### 3. Unseal
|
||||
|
||||
1. Unseal `openbao-0`, and paste the key when prompted:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it openbao-0 -- bao operator unseal
|
||||
kubectl -n openbao exec openbao-0 -- bao status
|
||||
```
|
||||
|
||||
**Checkpoint:** after a few seconds, `bao status` shows `Sealed false` and `HA Mode active`.
|
||||
|
||||
2. Check that `openbao-1` has found `openbao-0`, then unseal it with the same key:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec openbao-1 -- bao status
|
||||
kubectl -n openbao exec -it openbao-1 -- bao operator unseal
|
||||
```
|
||||
|
||||
**Checkpoint:** `bao status` shows `Initialized true` before you unseal. Exit code 2 is normal because the pod is still sealed. If it shows `Initialized false`, don't run `init`. Check `kubectl -n openbao logs openbao-1` instead.
|
||||
|
||||
3. Do the same for `openbao-2`, then check all three:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get pods -L openbao-active,openbao-sealed
|
||||
```
|
||||
|
||||
**Checkpoint:** all pods show `1/1` and `openbao-sealed=false`, and only one has `openbao-active=true`.
|
||||
|
||||
### 4. Create the admin login
|
||||
|
||||
1. Set [`$POD`](#rules), then log in with the root token when prompted:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft list-peers
|
||||
```
|
||||
|
||||
**Checkpoint:** there's one `leader` and two `follower`s. All three show `Voter true`, which can take a moment.
|
||||
|
||||
2. Create a policy with **full access**. Only use it for your admin login, never for apps:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -i "$POD" -- bao policy write admin - <<'EOF'
|
||||
path "*" {
|
||||
capabilities = ["create", "read", "update", "patch", "delete", "list", "scan", "sudo"]
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
3. Turn on username and password logins:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao auth enable userpass
|
||||
```
|
||||
|
||||
4. Generate a strong password in Bitwarden and create the `admin` user. Run these lines one at a time, and paste the password after the first one:
|
||||
|
||||
```bash
|
||||
read -rsp 'Admin password: ' PW; echo
|
||||
printf %s "$PW" | kubectl -n openbao exec -i "$POD" -- bao write auth/userpass/users/admin password=- token_policies=admin token_ttl=1h token_max_ttl=8h
|
||||
unset PW
|
||||
```
|
||||
|
||||
5. Turn on a KV v2 secrets engine, which stores passwords and API keys:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao secrets enable -path=secret -version=2 kv
|
||||
```
|
||||
|
||||
### 5. Test the admin login
|
||||
|
||||
Open `https://bao.<domain>` in a private window. Choose **Username** as the login method and log in as `admin`. Then:
|
||||
|
||||
1. Create a fake secret in `secret/`, read it, then delete it.
|
||||
2. Create a test policy, then delete it.
|
||||
|
||||
**Checkpoint:** everything works, and the browser shows no certificate warning.
|
||||
|
||||
### 6. Save the first snapshot
|
||||
|
||||
Follow [Save a snapshot](#save-a-snapshot). This also checks that the admin login can make backups. Before storing real secrets, test the [restore steps](#restore-into-a-new-openbao) on a separate test cluster.
|
||||
|
||||
### 7. Revoke the root token
|
||||
|
||||
Only do this once steps 5 and 6 have worked. Check that Bitwarden has the admin password and that you have a copy outside it.
|
||||
|
||||
1. Set [`$POD`](#rules), then log in with the **root token**. Log in again even if you did so earlier, because the snapshot steps replaced the saved login:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print
|
||||
kubectl -n openbao exec "$POD" -- bao read -field=policies auth/token/lookup-self
|
||||
```
|
||||
|
||||
**Checkpoint:** it prints `[root]`. If it prints anything else, **don't continue**, because the next command revokes whichever token is logged in.
|
||||
|
||||
2. Revoke it and remove the saved login:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao token revoke -self
|
||||
kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token
|
||||
```
|
||||
|
||||
3. Check that you can still log in to the UI as `admin`. Then delete the root token from Bitwarden, but **keep the unseal key**.
|
||||
|
||||
## Unseal after a restart
|
||||
|
||||
| What restarted | What to do |
|
||||
|---|---|
|
||||
| One OpenBao pod or its node | Unseal that pod. The other two keep OpenBao running. |
|
||||
| All three pods | Unseal all three. OpenBao works again once two are unsealed. |
|
||||
| A node without an OpenBao pod | Nothing |
|
||||
|
||||
1. Find the sealed pods, which show `0/1`:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get pods -L openbao-active,openbao-sealed
|
||||
```
|
||||
|
||||
2. Unseal each one, replacing `<n>` with its number:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it openbao-<n> -- bao operator unseal
|
||||
```
|
||||
|
||||
3. Run the first command again.
|
||||
|
||||
**Checkpoint:** all pods show `1/1`, and only one is active.
|
||||
|
||||
## Restart pods after a change
|
||||
|
||||
Changes to the OpenBao version or its config only take effect after you restart the pods. Before an upgrade, read the release notes and [save a snapshot](#save-a-snapshot).
|
||||
|
||||
1. Check that all three pods show `1/1`, and note which one is active:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get pods -L openbao-active
|
||||
```
|
||||
|
||||
2. Restart one **non-active** pod, then [unseal it](#unseal-after-a-restart):
|
||||
|
||||
```bash
|
||||
kubectl -n openbao delete pod openbao-<n>
|
||||
```
|
||||
|
||||
**Checkpoint:** all three pods show `1/1` before you restart the next one.
|
||||
|
||||
3. Do the same for the other non-active pod, then restart the active pod **last**. Another pod takes over, which can cause a short interruption.
|
||||
|
||||
## Save a snapshot
|
||||
|
||||
Do this before upgrades and after important changes. Snapshots aren't automatic yet.
|
||||
|
||||
1. Set [`$POD`](#rules), then log in as `admin`:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin
|
||||
```
|
||||
|
||||
2. Save a snapshot and copy it to your workstation:
|
||||
|
||||
```bash
|
||||
SNAP=~/openbao-$(date +%F-%H%M).snap
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft snapshot save /home/openbao/openbao.snap
|
||||
(umask 077; kubectl -n openbao exec "$POD" -- cat /home/openbao/openbao.snap > "$SNAP")
|
||||
kubectl -n openbao exec "$POD" -- sha256sum /home/openbao/openbao.snap
|
||||
sha256sum "$SNAP"
|
||||
```
|
||||
|
||||
**Checkpoint:** both checksums match.
|
||||
|
||||
3. Remove the copy and saved login from the pod:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao token revoke -self
|
||||
kubectl -n openbao exec "$POD" -- rm -f /home/openbao/openbao.snap /home/openbao/.vault-token
|
||||
```
|
||||
|
||||
4. Move the snapshot to storage outside the cluster and restrict access to it. **Don't store it with the unseal key**, because someone with both can read your secrets. Note which unseal key it needs.
|
||||
|
||||
## Restore into a new OpenBao
|
||||
|
||||
Use this on a separate test cluster, or if all three pods have lost their data. **It replaces everything in the new OpenBao.** Don't use it for a single lost pod or node. If the cluster being restored to has any working OpenBao data, stop and plan the recovery first.
|
||||
|
||||
You need the snapshot, the **original unseal key** and an admin password that was valid when the snapshot was taken. Use the same OpenBao version as the snapshot.
|
||||
|
||||
1. Deploy a new, empty OpenBao. Follow [First setup](#first-setup) steps 1–3, but save the new unseal key and root token as **temporary**. Don't replace the original key in Bitwarden.
|
||||
2. Set [`$POD`](#rules), then log in with the **temporary root token**:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print
|
||||
```
|
||||
|
||||
3. Check your `kubectl` context, because `-force` overwrites the data and skips the unseal key check:
|
||||
|
||||
```bash
|
||||
kubectl config current-context
|
||||
```
|
||||
|
||||
**Checkpoint:** it's the cluster you want to restore to. Also check that its API address is correct, because different clusters can use the same context name:
|
||||
|
||||
```bash
|
||||
kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'; echo
|
||||
```
|
||||
|
||||
4. Copy the snapshot to the pod and restore it:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -i "$POD" -- sh -c 'cat > /home/openbao/restore.snap' < <snapshot-file>
|
||||
sha256sum <snapshot-file>
|
||||
kubectl -n openbao exec "$POD" -- sha256sum /home/openbao/restore.snap
|
||||
```
|
||||
|
||||
**Checkpoint:** both checksums match. Then run:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft snapshot restore -force /home/openbao/restore.snap
|
||||
```
|
||||
|
||||
5. Wait 10 seconds, then restart **all three** pods. Otherwise, the non-active pods keep using the temporary key and get stuck:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao delete pod openbao-0 openbao-1 openbao-2
|
||||
```
|
||||
|
||||
6. Once all three are running, [unseal them](#unseal-after-a-restart) with the **original key**. The temporary key and root token no longer work, so delete them.
|
||||
7. Set [`$POD`](#rules) again, log in as `admin` and check the cluster:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft list-peers
|
||||
```
|
||||
|
||||
**Checkpoint:** there's one leader and two followers, and your secrets are there. All three should show `Voter true`, but this can take a moment.
|
||||
|
||||
8. Remove the saved login:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao token revoke -self
|
||||
kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token
|
||||
```
|
||||
|
||||
## Replace a lost worker
|
||||
|
||||
Only use this if the worker **can't be recovered** and the other two OpenBao pods are working. If it's only offline, bring it back and unseal its pod. `local-path` data can't move to another node, and each OpenBao pod needs its own node.
|
||||
|
||||
1. [Save a snapshot](#save-a-snapshot). Make sure the old worker can't come back online, then add its replacement to the cluster and remove the old node from Kubernetes. Wait until the replacement is `Ready`.
|
||||
2. Set [`$POD`](#rules), log in as `admin`, then remove the lost pod from the Raft cluster. Replace `<n>` with its number:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft remove-peer openbao-<n>
|
||||
kubectl -n openbao exec "$POD" -- bao operator raft list-peers
|
||||
```
|
||||
|
||||
**Checkpoint:** only the two working pods are listed.
|
||||
|
||||
3. Delete **only the lost pod** and its PVC. Check the number first:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao delete pvc data-openbao-<n> --wait=false
|
||||
kubectl -n openbao delete pod openbao-<n>
|
||||
```
|
||||
|
||||
If the pod gets stuck in `Terminating`, stop and check that the old node was removed. Don't force-delete the pod while its node could still be running.
|
||||
|
||||
4. Wait for the new pod to show `Running` and `Initialized true`. Don't run `init`. [Unseal it](#unseal-after-a-restart) and run `list-peers` again.
|
||||
|
||||
**Checkpoint:** all three pods are listed with `Voter true`, which can take a moment.
|
||||
|
||||
5. Remove the saved login:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec "$POD" -- bao token revoke -self
|
||||
kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token
|
||||
```
|
||||
|
||||
## If you lose the admin login
|
||||
|
||||
By default, **the unseal key alone can't create a new root token**. You need to temporarily turn on an older endpoint that doesn't need a login. While it's on, anyone who has the unseal key and can reach OpenBao can get full access.
|
||||
|
||||
1. In `06-openbao/index.ts`, add this to the `listener "tcp"` block. Preview the change, then deploy it:
|
||||
|
||||
```hcl
|
||||
disable_unauthed_generate_root_endpoints = false
|
||||
```
|
||||
|
||||
2. [Restart all three pods](#restart-pods-after-a-change), one at a time.
|
||||
3. Run this on your workstation. The `bao` command doesn't work for this without a login. Enter `https://bao.<domain>` and the unseal key when prompted. It cancels any unfinished attempt first:
|
||||
|
||||
```bash
|
||||
cat > /tmp/openbao-root.py <<'EOF'
|
||||
import base64, getpass, json, urllib.request
|
||||
|
||||
url = input("OpenBao URL: ").rstrip("/")
|
||||
|
||||
def call(method, path, data=None):
|
||||
body = None if data is None else json.dumps(data).encode()
|
||||
req = urllib.request.Request(f"{url}/v1/sys/generate-root/{path}", body, method=method)
|
||||
with urllib.request.urlopen(req) as res:
|
||||
return json.loads(res.read() or b"{}")
|
||||
|
||||
call("DELETE", "attempt")
|
||||
start = call("PUT", "attempt", {})
|
||||
key = getpass.getpass("Unseal key: ")
|
||||
done = call("PUT", "update", {"key": key, "nonce": start["nonce"]})
|
||||
encoded = done["encoded_root_token"]
|
||||
raw = base64.b64decode(encoded + "=" * (-len(encoded) % 4))
|
||||
print("Root token:", bytes(a ^ b for a, b in zip(raw, start["otp"].encode())).decode())
|
||||
EOF
|
||||
python3 /tmp/openbao-root.py
|
||||
rm /tmp/openbao-root.py
|
||||
```
|
||||
|
||||
Save the token in Bitwarden for now, then clear the terminal and its scrollback. If the script shows `405 Method Not Allowed`, the setting isn't active on the pod that answered.
|
||||
|
||||
4. Set [`$POD`](#rules) and log in with the new root token:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao exec -it "$POD" -- bao login -no-print
|
||||
```
|
||||
|
||||
Set a new password with step 4.4 of [First setup](#4-create-the-admin-login). Then [test the login](#5-test-the-admin-login) and [revoke the root token](#7-revoke-the-root-token).
|
||||
|
||||
5. **Remove the setting**, deploy again and restart all three pods, one at a time. Run the script again and enter any text as the key.
|
||||
|
||||
**Checkpoint:** it fails with `405 Method Not Allowed`.
|
||||
|
||||
## Certificates
|
||||
|
||||
cert-manager renews both the browser certificate (`openbao-ingress-tls`) and OpenBao's internal one (`openbao-server-tls`). OpenBao loads its new internal certificate without a restart, so you don't need to unseal it.
|
||||
|
||||
**Don't delete the `openbao-ca` Secret.** It holds the key for our internal CA. Renewing or replacing the CA doesn't immediately renew OpenBao's internal certificate. We haven't tested this, so plan and test it first. Check the certificates with:
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get certificates
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- [OpenBao: Running on Kubernetes](https://openbao.org/docs/platform/k8s/helm/run/)
|
||||
- [OpenBao: Raft commands](https://openbao.org/docs/commands/operator/raft/)
|
||||
- [OpenBao: Raft API](https://openbao.org/docs/api/system/storage/raft/)
|
||||
- [OpenBao: Username and password login](https://openbao.org/docs/auth/userpass/)
|
||||
- [OpenBao: Generate a root token](https://openbao.org/docs/commands/operator/generate-root/)
|
||||
- [OpenBao: Listener settings](https://openbao.org/docs/configuration/listener/tcp/)
|
||||
Reference in new issue
Block a user