mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-01 20:56:02 +09:00
feat(linstor): unlock blockstor from piraeus's passphrase Secret
From v0.3.0 every blockstor component finds the Secret that unlocks the master key through ControllerConfig/default, in the piraeus shape: linstor-passphrase, key MASTER_PASSPHRASE. Naming it is what lets a cluster migrated from LINSTOR keep its passphrase, and what blockstor's runbook assumes under Cozystack. The field is set by a post-install/post-upgrade Job rather than by a ControllerConfig in the release. Helm resolves every kind of a release before applying any, and the CRD is a template of this release, so the object would fail the first install of the backend. blockstor also creates and writes the same object at runtime, so the Job server-side applies only passphraseSecretRef under its own field manager and leaves the rest to blockstor. The controller does nothing with the keyring until the reference is there, so starting first is harmless. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
3 files changed
+213
No files matched your search
@@ -0,0 +1,115 @@
|
||||
{{- if eq .Values.backend "blockstor" }}
|
||||
{{- $_ := include "blockstor.secretNames" . }}
|
||||
{{- $hook := dict "helm.sh/hook" "post-install,post-upgrade" "helm.sh/hook-delete-policy" "before-hook-creation,hook-succeeded" }}
|
||||
{{- /*
|
||||
Points ControllerConfig/default at the passphrase Secret, which is how
|
||||
every blockstor component finds the Secret that unlocks the master key.
|
||||
|
||||
A Job rather than a ControllerConfig in the release, for two reasons.
|
||||
The CRD is a template of this same release, and Helm resolves every
|
||||
kind in a release before it applies any, so a ControllerConfig here
|
||||
fails the first install of the blockstor backend on a kind that does not
|
||||
exist yet. And blockstor writes the same object at runtime (controller
|
||||
properties, node connections) and creates it on first use, so the chart
|
||||
owns one field, not the object: a server-side apply under its own field
|
||||
manager sets passphraseSecretRef and leaves the rest alone, on a
|
||||
ControllerConfig blockstor or linstor-migrate created as well as on a
|
||||
missing one. --force-conflicts makes the value authoritative over a ref
|
||||
set by hand.
|
||||
|
||||
The controller may start before this runs. That costs nothing: with no
|
||||
ref it unlocks nothing and creates no keyring, and it picks the ref up
|
||||
when it changes. */}}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: blockstor-controllerconfig
|
||||
namespace: {{ .Release.Namespace }}
|
||||
annotations:
|
||||
{{- toYaml $hook | nindent 4 }}
|
||||
helm.sh/hook-weight: "-1"
|
||||
---
|
||||
{{- /*
|
||||
An apply that finds no object creates it, which needs create, and create
|
||||
cannot be limited by name. ControllerConfig is a singleton named
|
||||
default; blockstor reads no other. */}}
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: blockstor-controllerconfig
|
||||
annotations:
|
||||
{{- toYaml $hook | nindent 4 }}
|
||||
helm.sh/hook-weight: "-1"
|
||||
rules:
|
||||
- apiGroups: [blockstor.org]
|
||||
resources: [controllerconfigs]
|
||||
resourceNames: [default]
|
||||
verbs: [get, patch]
|
||||
- apiGroups: [blockstor.org]
|
||||
resources: [controllerconfigs]
|
||||
verbs: [create]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: blockstor-controllerconfig
|
||||
annotations:
|
||||
{{- toYaml $hook | nindent 4 }}
|
||||
helm.sh/hook-weight: "-1"
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: blockstor-controllerconfig
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: blockstor-controllerconfig
|
||||
namespace: {{ .Release.Namespace }}
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: blockstor-controllerconfig
|
||||
namespace: {{ .Release.Namespace }}
|
||||
annotations:
|
||||
{{- toYaml $hook | nindent 4 }}
|
||||
spec:
|
||||
{{- /* The CRD can take a moment to be served after a first install. */}}
|
||||
backoffLimit: 6
|
||||
activeDeadlineSeconds: 300
|
||||
template:
|
||||
spec:
|
||||
serviceAccountName: blockstor-controllerconfig
|
||||
restartPolicy: Never
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65534
|
||||
runAsGroup: 65534
|
||||
seccompProfile: {type: RuntimeDefault}
|
||||
containers:
|
||||
- name: apply
|
||||
image: {{ .Values.kubectl.image.repository }}:{{ .Values.kubectl.image.tag }}
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: [sh, -ec, 'printf "%s\n" "$MANIFEST" | kubectl apply --server-side --field-manager=cozystack-linstor --force-conflicts -f -']
|
||||
env:
|
||||
- name: HOME
|
||||
value: /tmp
|
||||
- name: MANIFEST
|
||||
value: |
|
||||
apiVersion: blockstor.org/v1alpha1
|
||||
kind: ControllerConfig
|
||||
metadata:
|
||||
name: default
|
||||
spec:
|
||||
passphraseSecretRef:
|
||||
name: {{ .Values.blockstorPassphraseSecret }}
|
||||
key: MASTER_PASSPHRASE
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities: {drop: [ALL]}
|
||||
volumeMounts:
|
||||
- {name: tmp, mountPath: /tmp}
|
||||
volumes:
|
||||
- {name: tmp, emptyDir: {}}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,92 @@
|
||||
# Every blockstor component finds the Secret that unlocks the master key
|
||||
# through ControllerConfig/default. The chart sets that one field from a hook,
|
||||
# because the CRD ships in this same release and blockstor writes the rest of
|
||||
# the object at runtime.
|
||||
suite: blockstor ControllerConfig passphrase reference
|
||||
templates:
|
||||
- templates/blockstor-controllerconfig.yaml
|
||||
release:
|
||||
name: linstor
|
||||
namespace: cozy-linstor
|
||||
set:
|
||||
backend: blockstor
|
||||
tests:
|
||||
- it: renders nothing under the LINSTOR backend
|
||||
set:
|
||||
backend: linstor
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: runs after every install and upgrade, and cleans up after itself
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations["helm.sh/hook"]
|
||||
value: post-install,post-upgrade
|
||||
- equal:
|
||||
path: metadata.annotations["helm.sh/hook-delete-policy"]
|
||||
value: before-hook-creation,hook-succeeded
|
||||
|
||||
- it: points passphraseSecretRef at piraeus's Secret, key MASTER_PASSPHRASE
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: Job
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].env
|
||||
content:
|
||||
name: MANIFEST
|
||||
value: |
|
||||
apiVersion: blockstor.org/v1alpha1
|
||||
kind: ControllerConfig
|
||||
metadata:
|
||||
name: default
|
||||
spec:
|
||||
passphraseSecretRef:
|
||||
name: linstor-passphrase
|
||||
key: MASTER_PASSPHRASE
|
||||
|
||||
- it: follows the passphrase Secret value
|
||||
set:
|
||||
blockstorPassphraseSecret: my-passphrase
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: Job
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: spec.template.spec.containers[0].env[1].value
|
||||
pattern: '(?m)^ name: my-passphrase$'
|
||||
|
||||
- it: owns only the fields it applies, and wins over a ref set by hand
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: Job
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: spec.template.spec.containers[0].command[2]
|
||||
pattern: 'kubectl apply --server-side --field-manager=cozystack-linstor --force-conflicts -f -'
|
||||
|
||||
- it: pins its image by digest
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: Job
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: spec.template.spec.containers[0].image
|
||||
pattern: '^[^@]+:[^@]+@sha256:[0-9a-f]{64}$'
|
||||
|
||||
- it: may touch no ControllerConfig but default, and nothing else
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: ClusterRole
|
||||
asserts:
|
||||
- equal:
|
||||
path: rules
|
||||
value:
|
||||
- apiGroups: [blockstor.org]
|
||||
resources: [controllerconfigs]
|
||||
resourceNames: [default]
|
||||
verbs: [get, patch]
|
||||
- apiGroups: [blockstor.org]
|
||||
resources: [controllerconfigs]
|
||||
verbs: [create]
|
||||
@@ -43,6 +43,12 @@ blockstorSatellite:
|
||||
# chart renders it into ControllerConfig.spec.passphraseSecretRef and into
|
||||
# the Secret names the blockstor Roles grant.
|
||||
blockstorPassphraseSecret: linstor-passphrase
|
||||
# Runs the hook Job that writes blockstorPassphraseSecret into
|
||||
# ControllerConfig/default. The same pin the other cozystack hook Jobs use.
|
||||
kubectl:
|
||||
image:
|
||||
repository: docker.io/alpine/k8s
|
||||
tag: 1.33.4@sha256:b0523f0a244ddc4c8e055aa335c040d3d78b3ead5528f4544395f7f9f69c7b68
|
||||
# Talos-specific workarounds (disable for generic Linux like Ubuntu/Debian)
|
||||
talos:
|
||||
enabled: true
|
||||
|
||||
Reference in new issue
Block a user