diff --git a/README.md b/README.md index bd1ce63..36e2170 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ image. - **Namespace** (`valheim` by default, toggle with `namespace.create`) - **StatefulSet** running the game server with a persistent volume for world data (`/config` and `/opt/valheim`) so the world survives restarts/upgrades -- **Secret** holding the server join password (`SERVER_PASS`) +- **ExternalSecret** that pulls the server name, world name and join password + (`SERVER_NAME`, `WORLD_NAME`, `SERVER_PASS`) from OpenBao via the `openbao` + `ClusterSecretStore` into a Secret named `valheim-server` - **Service** (`NodePort` by default) exposing the game (2456/udp), query (2457/udp) and crossplay (2458/udp) ports - Headless **Service** for the StatefulSet @@ -20,18 +22,43 @@ See [`values.yaml`](values.yaml) for all options. Important ones: | Key | Description | Default | |---|---|---| -| `server.name` | Server name shown in the browser | `Valtersheim` | -| `server.worldName` | World save name | `Midgard` | -| `server.password` | Join password (override via `-f secret-values.yaml`, never commit real passwords) | `changeme-please-override` | +| `externalSecret.storeName` / `externalSecret.storeKind` | Secret store the `ExternalSecret` reads from | `openbao` / `ClusterSecretStore` | +| `externalSecret.remoteKey` | Path of the secret in the store's KV v2 mount | `valheim/server` | +| `externalSecret.properties.*` | Property names inside that secret (`password`, `serverName`, `worldName`) | `password`, `server_name`, `world_name` | +| `externalSecret.refreshInterval` | How often ESO re-reads OpenBao | `1h` | | `service.type` | `NodePort` or `LoadBalancer` | `NodePort` | | `persistence.storageClassName` | StorageClass for world data, empty = cluster default | `""` | | `persistence.size` | Size of the world data volume | `10Gi` | +## Secrets (OpenBao) + +Server name, world name and join password are not stored in git. Create them in +OpenBao (KV v2 mount `secret/`) at `valheim/server` with the keys `password`, +`server_name` and `world_name`: + +```sh +bao kv put secret/valheim/server \ + password= server_name= world_name= +``` + +Requirements: the `openbao` `ClusterSecretStore` must be `Ready` (OpenBao unsealed, +see the `openbao` chart) and its role must be allowed to read `secret/data/valheim/*` +(the default `eso-read` policy covers all of `secret/data/*`). + +Environment variables are read when the container starts. After changing a value in +OpenBao, ESO updates the Secret at the next refresh, but you must restart the pod for +the server to pick it up: + +```sh +kubectl -n valheim rollout restart statefulset/valheim +``` + +Note: changing `world_name` makes the server load/create a different world. + ## Usage ```sh -helm upgrade --install valheim . -n valheim --create-namespace \ - --set server.password= +helm upgrade --install valheim . -n valheim --create-namespace ``` ### Deploying via ArgoCD @@ -39,5 +66,4 @@ helm upgrade --install valheim . -n valheim --create-namespace \ This repository is intended to be deployed as an ArgoCD `Application` using this chart as the Helm source (see `apps-in-apps` repo for the bootstrap Application). -> Never commit real passwords in `values.yaml`. Use `--set`, a separate values file -> excluded from git, or a secrets manager (SealedSecrets/ExternalSecrets) for production. +> Never commit real passwords to git - keep them in OpenBao. diff --git a/templates/externalsecret.yaml b/templates/externalsecret.yaml new file mode 100644 index 0000000..33830b7 --- /dev/null +++ b/templates/externalsecret.yaml @@ -0,0 +1,29 @@ +apiVersion: external-secrets.io/v1 +kind: ExternalSecret +metadata: + name: valheim-server + namespace: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim +spec: + refreshInterval: {{ .Values.externalSecret.refreshInterval }} + secretStoreRef: + kind: {{ .Values.externalSecret.storeKind }} + name: {{ .Values.externalSecret.storeName }} + target: + # Name/keys are referenced by the StatefulSet (SERVER_PASS, SERVER_NAME, WORLD_NAME). + name: valheim-server + creationPolicy: Owner + data: + - secretKey: SERVER_PASS + remoteRef: + key: {{ .Values.externalSecret.remoteKey }} + property: {{ .Values.externalSecret.properties.password }} + - secretKey: SERVER_NAME + remoteRef: + key: {{ .Values.externalSecret.remoteKey }} + property: {{ .Values.externalSecret.properties.serverName }} + - secretKey: WORLD_NAME + remoteRef: + key: {{ .Values.externalSecret.remoteKey }} + property: {{ .Values.externalSecret.properties.worldName }} diff --git a/templates/secret.yaml b/templates/secret.yaml deleted file mode 100644 index b04a46e..0000000 --- a/templates/secret.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: valheim-server - namespace: {{ .Values.namespace.name }} - labels: - app.kubernetes.io/name: valheim -type: Opaque -stringData: - SERVER_PASS: {{ .Values.server.password | quote }} diff --git a/templates/statefulset.yaml b/templates/statefulset.yaml index 125e07f..667ccf9 100644 --- a/templates/statefulset.yaml +++ b/templates/statefulset.yaml @@ -5,6 +5,10 @@ metadata: namespace: {{ .Values.namespace.name }} labels: app.kubernetes.io/name: valheim + annotations: + # Stakater Reloader: rolling restart when ESO refreshes the secret from OpenBao + # (env vars are only read at container start). Harmless if Reloader is not installed. + secret.reloader.stakater.com/reload: "valheim-server" spec: serviceName: valheim-headless replicas: 1 @@ -38,9 +42,15 @@ spec: protocol: UDP env: - name: SERVER_NAME - value: {{ .Values.server.name | quote }} + valueFrom: + secretKeyRef: + name: valheim-server + key: SERVER_NAME - name: WORLD_NAME - value: {{ .Values.server.worldName | quote }} + valueFrom: + secretKeyRef: + name: valheim-server + key: WORLD_NAME - name: SERVER_PASS valueFrom: secretKeyRef: diff --git a/values.yaml b/values.yaml index 18ddfbc..a1ec9b0 100644 --- a/values.yaml +++ b/values.yaml @@ -10,13 +10,22 @@ image: tag: latest pullPolicy: IfNotPresent +# Server name, world name and join password are NOT configured here - they are read from +# OpenBao via External Secrets Operator (see `externalSecret` below). +externalSecret: + # ClusterSecretStore (deployed by the openbao chart) to read from. + storeKind: ClusterSecretStore + storeName: openbao + refreshInterval: 1h + # Path of the secret inside the KV v2 mount configured on the store (`secret/`). + remoteKey: valheim/server + # Property names inside that secret. + properties: + password: password + serverName: server_name + worldName: world_name + server: - name: "Valtersheim" - worldName: "Midgard" - # Leave empty to auto-generate a random password on first deploy via the secret below. - # It is strongly recommended to override this via --set or a separate values file that is - # NOT committed to git (or use SealedSecrets/ExternalSecrets in production). - password: "changeme-please-override" public: true # Comma separated SteamIDs allowed to join/admin the server (optional) admins: ""