Skip to content

Commit 6987101

Browse files
committed
feat(openbao): refuse seal changes on an existing instance, mirror HA seal assertions
Review follow-up for the static seal: - fail when seal.previousSecretName is set with seal.type shamir instead of silently ignoring it. - read the seal in use from the config ConfigMap the previous release rendered (<release>-config, extraconfig-from-values.hcl) and refuse a seal.type that differs. A plain config change on an initialized instance leaves a barrier nobody can decrypt; the operator has to run bao operator unseal -migrate. seal.allowMigration acknowledges that for the one upgrade in which the migration is performed. lookup is empty on first install and dry-run, so the check is a no-op there. - assert the absence of a seal stanza in ha.raft.config with replicas 3, not only in standalone.config. Assisted-by: LLM Signed-off-by: txmazing <[email protected]>
1 parent 19b269d commit 6987101

7 files changed

Lines changed: 189 additions & 3 deletions

File tree

‎api/apps/v1alpha1/openbao/types.go‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/openbao/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ By default OpenBAO uses Shamir key shares: after every pod restart an operator h
2929

3030
To rotate the key, create a second Secret, move the current pair to `previousSecretName`/`previousKeyId` and put the new pair in `secretName`/`keyId`. This is the n-1 rotation the static seal documents: `current_key` is used for new seal operations while `previous_key` still decrypts what was written before. Keep both Secrets in place until OpenBAO has re-wrapped storage with the new key, then drop the `previous*` values and delete the old Secret.
3131

32-
> Switching an existing Shamir-sealed instance to `static` (or back) is a seal migration and needs `bao operator unseal -migrate`; see the OpenBAO [seal migration](https://openbao.org/docs/concepts/seal/#seal-migration) documentation. The chart does not run the migration for you.
32+
> Switching an existing Shamir-sealed instance to `static` is a seal migration and needs `bao operator unseal -migrate`; see the OpenBAO [seal migration](https://openbao.org/docs/concepts/seal/#seal-migration) documentation. The chart does not run the migration for you. It does refuse to change `seal.type` on an instance that already runs with another seal, because a plain config change would leave a barrier nobody can decrypt. Set `seal.allowMigration: true` only for the upgrade in which you run the migration, then remove it. Migrating away from `static` needs the old stanza kept with `disabled = "true"`, which this chart does not render.
3333

3434
Keep a copy of the key outside the cluster: a Raft snapshot or a data PVC is unreadable without it.
3535

@@ -66,4 +66,5 @@ Keep a copy of the key outside the cluster: a Raft snapshot or a data PVC is unr
6666
| `seal.keyId` | Permanent identifier of the current key. Change it whenever the key material changes; OpenBAO refuses a key whose identifier it has already seen with different material. Required when `type` is `static`. | `string` | `""` |
6767
| `seal.previousSecretName` | Secret holding the previous key during an n-1 key rotation. | `string` | `""` |
6868
| `seal.previousKeyId` | Identifier of the previous key. Required when `previousSecretName` is set. | `string` | `""` |
69+
| `seal.allowMigration` | Acknowledge a seal migration. The chart refuses to change `type` on an existing instance unless this is `true`; set it only while running `bao operator unseal -migrate`, then remove it. | `bool` | `false` |
6970

‎packages/apps/openbao/templates/openbao.yaml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
{{- if and $seal.previousSecretName (not $seal.previousKeyId) }}
1010
{{- fail "seal.previousKeyId is required when seal.previousSecretName is set" }}
1111
{{- end }}
12+
{{- if and $seal.previousSecretName (not $static) }}
13+
{{- fail "seal.previousSecretName only applies to seal.type \"static\"" }}
14+
{{- end }}
15+
{{- /*
16+
Refuse a silent seal change on an existing instance. Changing the seal of an
17+
initialized OpenBAO is a seal migration (`bao operator unseal -migrate`); a
18+
plain config change instead leaves a barrier nobody can decrypt. The seal in
19+
use is visible in the config ConfigMap the previous release rendered. `lookup`
20+
returns nothing on first install and on dry-run, so the check is a no-op there.
21+
*/}}
22+
{{- $cm := lookup "v1" "ConfigMap" .Release.Namespace (printf "%s-config" .Release.Name) }}
23+
{{- if $cm }}
24+
{{- $hcl := index ($cm.data | default dict) "extraconfig-from-values.hcl" | default "" }}
25+
{{- $stanza := regexFind `seal "[a-z]+"` $hcl }}
26+
{{- $liveSeal := ternary (trimAll "\"" (trimPrefix "seal " $stanza)) "shamir" (ne $stanza "") }}
27+
{{- if and (ne $liveSeal $seal.type) (not $seal.allowMigration) }}
28+
{{- fail (printf "seal.type %q differs from the seal in use (%q). Changing the seal of an existing instance is a seal migration (bao operator unseal -migrate); set seal.allowMigration: true only while performing it." $seal.type $liveSeal) }}
29+
{{- end }}
30+
{{- end }}
1231
apiVersion: helm.toolkit.fluxcd.io/v2
1332
kind: HelmRelease
1433
metadata:

‎packages/apps/openbao/tests/seal_test.yaml‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ tests:
4040
path: spec.values.openbao.server.standalone.config
4141
pattern: 'seal "static"'
4242

43+
- it: "keeps shamir by default in HA mode: no seal stanza in the raft config either"
44+
set:
45+
replicas: 3
46+
documentSelector:
47+
path: kind
48+
value: HelmRelease
49+
asserts:
50+
- notExists:
51+
path: spec.values.openbao.server.extraVolumes
52+
- notMatchRegex:
53+
path: spec.values.openbao.server.ha.raft.config
54+
pattern: 'seal "'
55+
4356
- it: "renders the static seal stanza and the key volume in HA mode"
4457
set:
4558
replicas: 3
@@ -129,3 +142,146 @@ tests:
129142
asserts:
130143
- failedTemplate:
131144
errorMessage: "seal.previousKeyId is required when seal.previousSecretName is set"
145+
146+
- it: "rejects previousSecretName with seal.type shamir"
147+
set:
148+
seal:
149+
type: shamir
150+
previousSecretName: openbao-unseal-old
151+
previousKeyId: key-1
152+
asserts:
153+
- failedTemplate:
154+
errorMessage: 'seal.previousSecretName only applies to seal.type "static"'
155+
156+
# The seal in use is read from the config ConfigMap the previous release
157+
# rendered (<release>-config, key extraconfig-from-values.hcl). A ConfigMap
158+
# without a seal stanza means Shamir.
159+
- it: "refuses to switch an existing Shamir instance to static without allowMigration"
160+
kubernetesProvider:
161+
scheme:
162+
"v1/ConfigMap":
163+
gvr:
164+
version: "v1"
165+
resource: "configmaps"
166+
namespaced: true
167+
objects:
168+
- kind: ConfigMap
169+
apiVersion: v1
170+
metadata:
171+
name: openbao-test-config
172+
namespace: tenant-test
173+
data:
174+
extraconfig-from-values.hcl: |-
175+
ui = true
176+
storage "raft" {
177+
path = "/openbao/data"
178+
}
179+
service_registration "kubernetes" {}
180+
set:
181+
replicas: 3
182+
seal:
183+
type: static
184+
secretName: openbao-unseal
185+
keyId: key-1
186+
asserts:
187+
- failedTemplate:
188+
errorPattern: 'seal.type "static" differs from the seal in use \("shamir"\)'
189+
190+
- it: "refuses to switch an existing static instance back to shamir"
191+
kubernetesProvider:
192+
scheme:
193+
"v1/ConfigMap":
194+
gvr:
195+
version: "v1"
196+
resource: "configmaps"
197+
namespaced: true
198+
objects:
199+
- kind: ConfigMap
200+
apiVersion: v1
201+
metadata:
202+
name: openbao-test-config
203+
namespace: tenant-test
204+
data:
205+
extraconfig-from-values.hcl: |-
206+
storage "raft" {
207+
path = "/openbao/data"
208+
}
209+
seal "static" {
210+
current_key_id = "key-1"
211+
current_key = "file:///openbao/userconfig/openbao-unseal/key"
212+
}
213+
set:
214+
replicas: 3
215+
asserts:
216+
- failedTemplate:
217+
errorPattern: 'seal.type "shamir" differs from the seal in use \("static"\)'
218+
219+
- it: "renders when the requested seal matches the seal in use"
220+
kubernetesProvider:
221+
scheme:
222+
"v1/ConfigMap":
223+
gvr:
224+
version: "v1"
225+
resource: "configmaps"
226+
namespaced: true
227+
objects:
228+
- kind: ConfigMap
229+
apiVersion: v1
230+
metadata:
231+
name: openbao-test-config
232+
namespace: tenant-test
233+
data:
234+
extraconfig-from-values.hcl: |-
235+
seal "static" {
236+
current_key_id = "key-1"
237+
current_key = "file:///openbao/userconfig/openbao-unseal/key"
238+
}
239+
set:
240+
replicas: 3
241+
seal:
242+
type: static
243+
secretName: openbao-unseal
244+
keyId: key-2
245+
previousSecretName: openbao-unseal-old
246+
previousKeyId: key-1
247+
documentSelector:
248+
path: kind
249+
value: HelmRelease
250+
asserts:
251+
- matchRegex:
252+
path: spec.values.openbao.server.ha.raft.config
253+
pattern: 'current_key_id = "key-2"'
254+
255+
- it: "renders a seal change when allowMigration acknowledges the migration"
256+
kubernetesProvider:
257+
scheme:
258+
"v1/ConfigMap":
259+
gvr:
260+
version: "v1"
261+
resource: "configmaps"
262+
namespaced: true
263+
objects:
264+
- kind: ConfigMap
265+
apiVersion: v1
266+
metadata:
267+
name: openbao-test-config
268+
namespace: tenant-test
269+
data:
270+
extraconfig-from-values.hcl: |-
271+
storage "raft" {
272+
path = "/openbao/data"
273+
}
274+
set:
275+
replicas: 3
276+
seal:
277+
type: static
278+
secretName: openbao-unseal
279+
keyId: key-1
280+
allowMigration: true
281+
documentSelector:
282+
path: kind
283+
value: HelmRelease
284+
asserts:
285+
- matchRegex:
286+
path: spec.values.openbao.server.ha.raft.config
287+
pattern: 'seal "static"'

‎packages/apps/openbao/values.schema.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
"type"
143143
],
144144
"properties": {
145+
"allowMigration": {
146+
"description": "Acknowledge a seal migration. The chart refuses to change `type` on an existing instance unless this is `true`; set it only while running `bao operator unseal -migrate`, then remove it.",
147+
"type": "boolean",
148+
"default": false
149+
},
145150
"keyId": {
146151
"description": "Permanent identifier of the current key. Change it whenever the key material changes; OpenBAO refuses a key whose identifier it has already seen with different material. Required when `type` is `static`.",
147152
"type": "string",

‎packages/apps/openbao/values.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ ui: true
9696
## @field {string} keyId - Permanent identifier of the current key. Change it whenever the key material changes; OpenBAO refuses a key whose identifier it has already seen with different material. Required when `type` is `static`.
9797
## @field {string} [previousSecretName] - Secret holding the previous key during an n-1 key rotation.
9898
## @field {string} [previousKeyId] - Identifier of the previous key. Required when `previousSecretName` is set.
99+
## @field {bool} [allowMigration] - Acknowledge a seal migration. The chart refuses to change `type` on an existing instance unless this is `true`; set it only while running `bao operator unseal -migrate`, then remove it.
99100

100101
## @param {Seal} seal - Seal configuration. Defaults to Shamir key shares; set `type: static` for auto-unseal.
101102
seal:
@@ -104,3 +105,4 @@ seal:
104105
keyId: ""
105106
previousSecretName: ""
106107
previousKeyId: ""
108+
allowMigration: false

0 commit comments

Comments
 (0)