Skip to content

feat(encryption)!: per-volume LUKS passwords under a master key with several passphrases - #258

Merged
Andrei Kvapil (kvaps) merged 33 commits into
mainfrom
feat/byok-stage1
Nov 16, 2026
Merged

Andrei Kvapil (kvaps) merged 33 commits into
mainfrom
feat/byok-stage1

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

What this changes

Every LUKS replica now gets its own random password, and that password is the only key in its LUKS header. It is stored on the replica's Resource (spec.volumes[].luksKey), wrapped under a cluster master key. The master key sits in a keyring Secret, blockstor-master-key, wrapped once per master passphrase. This is LINSTOR's scheme, with authenticated primitives: Argon2id for the passphrase slots and AES-256-GCM for both wraps.

The master passphrase comes from a Secret in piraeus's shape. ControllerConfig.spec.passphraseSecretRef names it, and the key defaults to MASTER_PASSPHRASE. blockstor only reads that Secret. On first start the controller creates the keyring from it, the way LINSTOR does. Without a reference, linstor encryption create-passphrase enrols the operator's passphrase in a slot and lets the cluster open its master key with a generated passphrase kept in a Secret blockstor owns, blockstor-unlock, so the operator's passphrase is stored nowhere in clear.

On the satellite, a device with no header is formatted only after blkid -p finds it empty and the new password has been stored and read back. A header is opened with the stored password and is never re-formatted. A header with no stored password is refused, unless the volume was restored from a snapshot: then the satellite adopts whichever password the snapshot recorded that opens it. Snapshots copy their source replicas' wrapped passwords when they are created, and a satellite refuses its node's take if its replica's password is not among them. New headers are LUKS2 by name. Each refusal is a Warning Event on the Resource. A replica whose mapper is already open is reconciled without reading its password, so a locked cluster blocks only opening, formatting and resizing.

Changing a master passphrase no longer touches any volume, so modify-passphrase now works while LUKS volumes exist. If the old passphrase is the one the named Secret holds, blockstor cannot write that Secret. It adds a slot for the new passphrase, keeps the old slot marked superseded, and answers with a warning. The controller removes the superseded slot once the Secret holds the new passphrase. The new blockstor-only verbs add-passphrase, remove-passphrase and list-passphrases exist in REST under /v1/encryption/passphrases and in the CLI, which reads their passphrases from a file (byte for byte, a trailing newline included, like the Secret), the terminal or stdin, never from argv. Slot names are lowercase letters, digits and dashes, up to 32 characters, and a name that looks like a slot ID is refused with 400. list-passphrases also prints the master key ID. modify-passphrase keeps linstor-client's --old-passphrase and --new-passphrase and warns that they show in the process list. Removing a slot needs the passphrase of a slot that stays and never removes the last slot whose passphrase came from outside blockstor. Removing and modifying are refused on a locked cluster, and both judge which slot the passphrase Secret opens in the keyring they are about to write, so no sequence of calls can leave the master key with no passphrase anyone holds. Passphrase operations run two at a time, since each wrong guess costs up to eight Argon2id runs, and an enter-passphrase that leaves the cluster locked is an error rather than a success. Status and the view's Suspended column now come from the Secrets, not from a flag each apiserver process kept for itself.

linstor-migrate takes the LINSTOR master passphrase from a file. It decrypts every replica's and every snapshot's password the way LINSTOR does, and re-wraps each one under a blockstor master key. With -keyring-out the new keyring's one slot is the LINSTOR passphrase, so the Secret piraeus used keeps opening the master key. That removes the luksAddKey step from the runbook. A dump with LUKS volumes is refused without the passphrase. A passphrase that is given is always checked against the dump's master key, even with no LUKS volumes, and the run is refused when the dump has no master key to check it against, so a wrong passphrase stops the run before anything is written. The runbook applies the converted keyring before the blockstor controller starts, so the controller does not bootstrap its own, and then compares the key ID list-passphrases prints with the one in the manifests.

The satellite's Secret access shrinks from a cluster-wide get/list/watch to a get of three named Secrets in blockstor's namespace: the keyring, the generated Secret blockstor-unlock and the passphrase Secret under piraeus's name, linstor-passphrase. The controller and apiserver get the same names for get and update, and create on its own. Under Cozystack the namespace is shared with piraeus, whose TLS keys stay unreadable. A passphrase Secret under another name has to be added to those Roles. The one exposure RBAC cannot close, a create that cannot be limited by name, is described in the design with the admission policy that would close it.

The design is docs/encryption-keys.md. Where the code settles something the design left open, it is listed in that document's implementation notes.

Why

Before this change every LUKS volume was formatted with one cluster passphrase. Anyone holding that passphrase could open every disk. Changing it would have meant re-keying every header, so blockstor refused to change it at all. A cluster migrated from piraeus had to add that passphrase to each volume by hand, which does not work for volumes opened through the kernel keyring.

Breaking change

A LUKS volume formatted with the single cluster passphrase before this change is neither opened nor re-formatted. Its replica carries no stored password, so the satellite reports LUKSKeyMissing and leaves the data on disk. Copy such volumes to volumes created after the upgrade. The Secret key passphrase, the default Secret name blockstor-cluster-passphrase and the LuksPassphrase wire property are gone. The cozystack chart has to follow the RBAC here, including the resourceNames, and its passphrase value has to render into passphraseSecretRef. DELETE /v1/encryption/passphrases/{slot} takes a body with the passphrase of a slot that stays.

Testing

  • Unit tests for the keyring use known-answer vectors computed outside Go: OpenSSL for Argon2id, Python's cryptography for HKDF and AES-GCM. They cover round trips, tampering with every byte of both wraps, wrong passphrases, a slot copied in from another keyring, out-of-bounds Argon2id parameters refused before any derivation runs (counted, not timed), slot names, and slot add, remove and supersede.
  • Satellite tests cover each case of the format/open table against a fake cryptsetup: the password is stored before the format, nothing is formatted over data or without a stored password, a mismatched header is never re-formatted, and a restored volume adopts the snapshot password that opens it.
  • envtest covers the set-once CEL rules and the store keeping luksKey through REST rewrites. Snapshots copy their source keys. Opening the master key, the bootstrap and the passphrase operations are tested against fake clients, including the three-step change of the Secret's passphrase and the cleanup of superseded slots.
  • The LINSTOR decryption has known-answer vectors computed in Python from LINSTOR's algorithm and built into the converter's fixture dump, plus vectors a JDK 22 produced running LINSTOR's own steps, one with a Cyrillic passphrase, which pin how a non-ASCII passphrase reaches PBKDF2 and the CFB segment size. The generator is in pkg/linstormigrate/testdata/jdk.
  • A manifest test checks that every Role granting Secrets is bound and names only those three Secrets, and that no ClusterRole grants Secrets.
  • The cleanup of superseded slots is tested against a Secret rolled back between reading the keyring and writing it, the controller's steady-state pass is tested to derive nothing, and an open mapper is tested to reconcile on a locked cluster.
  • Removing the operator's slot from a cluster that has lost access to blockstor-unlock is a test, and it fails without the guard.
  • Every guard and ordering constraint added here was checked by mutation: each one, reverted, fails a named test.
  • make lint reports 0 issues, and go test ./... with envtest passes.
  • Not run: the e2e scenarios (updated to the keyring model, but not executed), the root-only cryptsetup compatibility test, a /CTRLCFG dump from a live controller, and a migration rehearsal on a live piraeus cluster.

Fixes #257

LUKS volumes on blockstor are all formatted with one cluster
passphrase, so changing it means re-keying every header and a single
leaked passphrase opens every disk. LINSTOR avoids both by giving each
volume its own random password, wrapped under a master key that any of
several passphrases unlocks.

pkg/keyring is that key hierarchy: a random 32-byte master key, up to
eight slots that wrap it under Argon2id-derived keys with AES-256-GCM,
and HKDF sub-keys for a public key ID and for wrapping the volume
passwords. Slot parameters are bounded before Argon2id runs, so an
edited keyring can neither make a passphrase cheaper to guess nor make
every component allocate gigabytes. Nothing uses it yet.

docs/encryption-keys.md is the design the rest of the stage follows.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Each LUKS replica is about to get its own random password, the only
key in its header. Losing that value loses the replica's data, so it
is stored on the replica's own Resource, in spec where backups restore
it, as luksKey on the volume entry. The store already carries
spec.volumes across its wire-shaped rewrites, and a CEL rule makes the
field set-once.

A snapshot's bytes are encrypted under the password of the replica
they were taken from, which may be deleted before the snapshot is
restored. The store copies every source replica's wrapped password into
Snapshot.spec.luksKeys when it creates the snapshot, reading the
replicas past the cache, and keeps them across REST modifies.

The passphrase Secret reference gains a key, defaulting to piraeus's
MASTER_PASSPHRASE. The satellite's Secret access shrinks from a
cluster-wide get/list/watch to a get in blockstor's namespace: it
reads two Secrets by name there and nothing else.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Every LUKS volume was formatted with the one cluster passphrase, read
from a Secret and handed to the satellite as a property. A leak of that
passphrase opened every disk, and changing it meant re-keying every
header, which blockstor refused to do.

Now each replica's volume gets a random password, the only key in its
header, stored on its Resource wrapped under the cluster master key.
The satellite unlocks the master key from the passphrase Secret the
ControllerConfig names, in piraeus's shape (MASTER_PASSPHRASE), and
remembers the outcome per pair of Secret versions so a wrong
passphrase does not cost an Argon2id run on every reconcile. On a
device with no header it formats only after blkid finds it empty and
the new password is stored and read back; a header is opened with the
stored password and never re-formatted; a header without a stored
password is refused, except for a volume restored from a snapshot,
which adopts the recorded password that opens it. Each refusal is a
Warning Event on the Resource.

On first start the controller leader creates the keyring from the
passphrase Secret, as LINSTOR does with MASTER_PASSPHRASE, unless a
replica already carries a wrapped password, in which case the keyring
was lost and a new one would orphan it.

New volumes use PBKDF2 at its minimum cost in the LUKS header: the
password is random, and Argon2id would cost seconds and up to a GiB
per open after a reboot.

BREAKING CHANGE: a LUKS volume formatted with the cluster passphrase
before this change is neither opened nor re-formatted; its data stays
on disk and has to be copied to a new volume. The LuksPassphrase wire
property is gone. Until the encryption REST verbs move to the keyring
in the next change, create-passphrase writes a Secret nothing reads.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The encryption verbs worked on one passphrase kept verbatim in a
Secret: create wrote it, enter compared it, modify was refused while
LUKS volumes existed because it was their key. With the master key in
a keyring the passphrases only wrap that key, so they become slots.

create-passphrase with no passphrase Secret named makes the master key
with a slot for the operator's passphrase and one for a generated
passphrase, kept in a Secret blockstor owns, so the cluster unlocks
unattended and the operator's passphrase rests nowhere in clear. With
a Secret named, the keyring comes from it and create is refused.
enter verifies against every slot, and repairs a cluster locked out of
its generated unlock Secret. modify replaces the slot the old
passphrase opens; when that is the passphrase the named Secret holds,
blockstor cannot write the Secret, so it adds the new slot, keeps the
old one superseded so nothing locks, and the controller drops it once
the Secret holds the new passphrase.

New blockstor-only verbs add, remove and list slots, in REST under
/v1/encryption/passphrases and in the CLI. Status and the resource
view's Suspended column come from the Secrets rather than from a flag
each apiserver process kept on its own.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
LINSTOR keeps a password per LUKS replica, encrypted under its master
key, and the converter left them behind: the runbook had operators
read each volume key out of dmsetup and luksAddKey the cluster
passphrase on every replica, which fails for volumes opened through
the kernel keyring.

Given the LINSTOR master passphrase from a file, the converter now
recovers LINSTOR's master key from the controller properties, checks
it against the stored hash before writing anything, decrypts every
replica's and snapshot's password the way LINSTOR does, and re-wraps
it under a blockstor master key into the converted Resources and
Snapshots. -keyring-out writes a new keyring whose one slot is the
LINSTOR passphrase, so the Secret piraeus used keeps unlocking the
cluster; -keyring-in wraps under an existing cluster's keyring. A dump
with LUKS volumes is refused without the passphrase. LINSTOR's
PBKDF2-SHA1 and unauthenticated AES-CFB stay in the importer.

How the JDK hands a non-ASCII passphrase to PBKDF2, and that
AES/CFB/NoPadding means a 128-bit segment, are read off the source;
both need a vector from a live controller.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The design left a few points open that the implementation had to
settle: where a restored volume gets its password, how strict the
luksKey rule is, how refusals reach the operator, the Argon2id bounds,
and what the cozystack chart still has to follow. They are written
down next to the decisions they refine, together with what the branch
does not exercise.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
create-passphrase on a cluster without a keyring minted a new master
key even when replicas already carried passwords wrapped under a
keyring that had been deleted. Those volumes would then never open,
and a later restore of the lost keyring would collide with the new
one. The controller's bootstrap already refused this; create now
refuses it the same way, with 409.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The LUKS scenarios set up a Secret with the key `passphrase`, which
nothing reads any more, and asserted that the cluster passphrase opens
every volume header, which is now exactly what must not happen.

ensure_passphrase_secret now names a piraeus-shaped passphrase Secret
in the ControllerConfig and waits for the controller to create the
keyring from it. The header check asserts one key slot that the master
passphrase does not open, the encryption cleanup drops the keyring,
the generated unlock Secret and the passphrase reference, and the
Bug 023 cell expects modify-passphrase to succeed over a LUKS volume
without touching it. The replay no longer runs the rotation, whose
outcome depends on the passphrase a shared stand already has.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The layer-stack guide, the operations, resources and CLI pages still
described one cluster passphrase that opens every volume, kept under
the key `passphrase` in blockstor-cluster-passphrase, with rotation
refused. They now describe the keyring, the piraeus-shaped passphrase
Secret, the slot verbs, what to back up, and that volumes formatted
with the old cluster passphrase have to be copied.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
remove-passphrase took no passphrase and protected only the slot the
cluster unlocks with. On a cluster locked out of its generated unlock
Secret there is no such slot, so removing the operator's slot left
only the generated one, whose passphrase nobody had any more, and
every LUKS volume became unreadable for good. On an unlocked cluster
the same call left the generated slot alone, one deleted Secret away
from the same end.

Remove now needs the passphrase of a slot that stays, as
cryptsetup luksRemoveKey does, refuses on a cluster that is not
unlocked, and refuses the last slot whose passphrase did not come from
blockstor.

The blockstor-only slot verbs also stop taking passphrases on argv,
where they landed in shell history and /proc/<pid>/cmdline; unlike
create and enter they have no upstream form to stay compatible with.
They read from --passphrase-file, --old-passphrase-file and
--new-passphrase-file, the terminal, or one per line from stdin.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The guard against minting a new master key over a lost keyring looked
only at replicas. Once every LUKS replica of a definition was gone,
its snapshots still carried passwords wrapped under the old key, yet
the bootstrap and create-passphrase made a new one, leaving those
snapshots unrestorable and colliding with a keyring restored from a
backup later. Snapshots now count too.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The store records each source replica's wrapped LUKS password when the
Snapshot is created, and the field is set-once. A replica formatted
after that and before the take left its node's snapshot bytes
encrypted under a password no snapshot entry held, so that snapshot
could never be restored. The satellite now fails its node's take when
its replica carries a password the snapshot does not record.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The satellite's namespaced Secret Role in config/rbac had no binding,
so an install from `make deploy` or `make build-installer` could not
read the keyring or the passphrase Secret and every LUKS volume stayed
locked; the controller's kubebuilder markers for Secrets generate
nothing, so it had none either. Both are now bound.

The Roles also granted a get on every Secret in the namespace, which
under Cozystack is shared with piraeus and its TLS keys. Reads and
updates are now limited to the keyring, the generated unlock Secret
and the passphrase Secret under piraeus's name; a create, which cannot
be limited by name, is granted on its own. The e2e scenarios use that
name.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
luksFormat took the host's default header type, which is LUKS1 on
older distributions. The header then carries LUKS1 key slots and
metadata the rest of the stack, and the e2e slot check, do not
expect. The type is now named.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Every passphrase operation tries the given passphrase against up to
eight slots at 64 MiB of Argon2id each, and nothing limited how many
ran at once, so a burst of wrong guesses could take the apiserver's
memory. They now run two at a time; the others wait for a turn until
their request times out, then answer 503.

enter-passphrase that verified the passphrase but left the cluster
locked answered 200, which the python client printed as success over a
cluster that could not open a volume. It now answers 409 and the CLI
exits non-zero, naming the passphrase Secret to fix.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
How LINSTOR's passphrase reaches PBKDF2 for a byte above 0x7f, and the
CFB segment size behind AES/CFB/NoPadding, are JDK behaviour that the
importer only read off the source. Vectors made by a JDK running
LINSTOR's own steps, one with a Cyrillic passphrase, now pin both,
and the generator sits next to the fixtures.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The argv ban meant for the blockstor-only slot verbs also caught
modify-passphrase, which is LINSTOR's own verb: linstor-client passes
--old-passphrase and --new-passphrase, and the bundled CLI took them
before. They now work again, with a warning that the values show in
the process list, next to the file, terminal and stdin forms. add and
remove still refuse passphrases on the command line.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
TestMasterKeyRunnableCreatesTheKeyring gave the runnable one second to
create a keyring, which costs an Argon2id run at 64 MiB. Under a full
`go test ./...`, with every package competing for the CPU, that was not
always enough and the test failed with the code working. It now waits
up to 30 seconds and still returns as soon as the keyring appears.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
modify-passphrase ran on a locked cluster: with the generated unlock
Secret gone, the generated passphrase could be changed, and the next
enter-passphrase repair dropped that slot, so the passphrase just set
opened nothing. remove-passphrase and modify also took the slot the
passphrase Secret opens from a read before the write, so a Secret
moved to another slot in between could have that slot removed and
the cluster locked.

Both now read the Secret again against the keyring they are about to
write: modify, like remove, refuses when it opens no slot, and the
slot it opens is the one kept.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
A create on Secrets cannot be limited by name, and the controller and
the apiserver both need one, so a compromised pod of either could
create a token Secret for another ServiceAccount under a name it may
read. The passphrase turns are not handed out in arrival order, so a
flood of wrong guesses can delay a legitimate enter. Neither has a
fix worth its cost in this change; both are written down, with the
admission policy that would close the first.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 109 files, which is 9 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 398263af-91b2-4f65-873f-a05a90f23273
Commits

Reviewing files that changed from the base of the PR and between 30a6639 and a38f401.

Files ignored due to path filters: 1

  • go.sum is excluded by !**/*.sum
Files selected for processing: 109

  • .golangci.yml
  • api/v1alpha1/controllerconfig_types.go
  • api/v1alpha1/resource_types.go
  • api/v1alpha1/snapshot_types.go
  • api/v1alpha1/zz_generated.deepcopy.go
  • cmd/controller/main.go
  • cmd/linstor-migrate/main.go
  • cmd/linstor-migrate/main_test.go
  • config/crd/bases/blockstor.org_controllerconfigs.yaml
  • config/crd/bases/blockstor.org_resources.yaml
  • config/crd/bases/blockstor.org_snapshots.yaml
  • config/rbac/kustomization.yaml
  • config/rbac/satellite_role.yaml
  • config/rbac/secrets_role.yaml
  • docs/cli-parity-known-deltas.md
  • docs/encryption-keys.md
  • docs/layer-stack.md
  • docs/linstor-migration.md
  • go.mod
  • internal/cli/command/registry.go
  • internal/cli/command/registry_test.go
  • internal/cli/encryption.go
  • internal/cli/encryption_test.go
  • internal/cli/flags.go
  • internal/cli/handlers.go
  • internal/controller/master_key_runnable.go
  • internal/controller/master_key_runnable_test.go
  • pkg/dispatcher/dispatcher.go
  • pkg/dispatcher/dispatcher_luks_master_passphrase_test.go
  • pkg/dispatcher/dispatcher_luks_wire_prop_test.go
  • pkg/keyring/keyring.go
  • pkg/keyring/keyring_test.go
  • pkg/keyring/masterkey.go
  • pkg/keyring/masterkey_test.go
  • pkg/linstormigrate/convert.go
  • pkg/linstormigrate/convert_test.go
  • pkg/linstormigrate/external_metadata_test.go
  • pkg/linstormigrate/layer_stack_test.go
  • pkg/linstormigrate/luks.go
  • pkg/linstormigrate/luks_fixture_test.go
  • pkg/linstormigrate/luks_test.go
  • pkg/linstormigrate/parent_names_test.go
  • pkg/linstormigrate/testdata/dump/layerluksvolumes.internal.linstor.linbit.com.json
  • pkg/linstormigrate/testdata/dump/propscontainers.internal.linstor.linbit.com.json
  • pkg/linstormigrate/testdata/golden/manifests.yaml
  • pkg/linstormigrate/testdata/golden/report.txt
  • pkg/linstormigrate/testdata/jdk/Vec.java
  • pkg/linstormigrate/unreadable_layer_stack_test.go
  • pkg/linstormigrate/validate_envtest_test.go
  • pkg/luks/luks.go
  • pkg/luks/luks_keys_test.go
  • pkg/passphrase/export_test.go
  • pkg/passphrase/ops.go
  • pkg/passphrase/passphrase.go
  • pkg/passphrase/unlock.go
  • pkg/passphrase/unlock_test.go
  • pkg/rest/encryption.go
  • pkg/rest/encryption_bug_172_test.go
  • pkg/rest/encryption_bug_176_test.go
  • pkg/rest/encryption_rotation_luks_test.go
  • pkg/rest/encryption_secret_reader_test.go
  • pkg/rest/encryption_status_bug_196_test.go
  • pkg/rest/encryption_test.go
  • pkg/rest/encryption_w13_test.go
  • pkg/rest/helpers_test.go
  • pkg/rest/luks_gate_bug023_test.go
  • pkg/rest/rd_clone_validation_test.go
  • pkg/rest/resource_definitions.go
  • pkg/rest/resource_definitions_bug116_test.go
  • pkg/rest/resource_definitions_bug95_test.go
  • pkg/rest/resources.go
  • pkg/rest/security_props_redaction.go
  • pkg/rest/server.go
  • pkg/satellite/controllers/layer_stack_pin_internal_test.go
  • pkg/satellite/controllers/luks_keys.go
  • pkg/satellite/controllers/luks_keys_internal_test.go
  • pkg/satellite/controllers/luks_passphrase.go
  • pkg/satellite/controllers/luks_passphrase_internal_test.go
  • pkg/satellite/controllers/manager.go
  • pkg/satellite/controllers/resource.go
  • pkg/satellite/controllers/snapshot.go
  • pkg/satellite/controllers/snapshot_luks_key_internal_test.go
  • pkg/satellite/luks_keys_fake_test.go
  • pkg/satellite/reconciler.go
  • pkg/satellite/reconciler_drbd_test.go
  • pkg/satellite/reconciler_locale_test.go
  • pkg/satellite/reconciler_luks_holds_data_test.go
  • pkg/satellite/reconciler_luks_keys_test.go
  • pkg/satellite/reconciler_toggle_diskless_test.go
  • pkg/store/k8s/luks_keys_test.go
  • pkg/store/k8s/snapshots.go
  • pkg/store/k8s/typed_field_carry_across_test.go
  • site/content/en/docs/cli.md
  • site/content/en/docs/layer-stack.md
  • site/content/en/docs/migration.md
  • site/content/en/docs/operations.md
  • site/content/en/docs/resources.md
  • stand/blockstor-apiserver-deploy.yaml
  • stand/blockstor-deploy.yaml
  • stand/blockstor-satellite-daemonset.yaml
  • tests/e2e/cli-matrix/encryption-passphrase-luks-rd.sh
  • tests/e2e/cli-matrix/lib.sh
  • tests/e2e/cli-matrix/luks-autoplace-encrypted.sh
  • tests/e2e/cli-matrix/luks-clone-encrypted.sh
  • tests/e2e/cli-matrix/luks-rd-create-encrypted.sh
  • tests/e2e/cli-matrix/luks-snapshot-restore-encrypted.sh
  • tests/e2e/lib.sh
  • tests/manifests/secrets_rbac_test.go
  • tests/operator-harness/replay/encryption-passphrase-luks-rd.yaml

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

The out-of-bounds KDF test inferred that Argon2id did not run from
the refusal taking under 50ms. On a loaded CI runner a refusal that
never reaches Argon2id can still take longer, and a fast machine could
hide a derivation that did run. Pass the derivation into the unlock
path so the test counts the calls and asserts none, with a control
showing the counter sees a slot that is within bounds.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The --*-passphrase-file flags trimmed a trailing newline, while the
passphrase Secret and linstor-migrate take the same bytes verbatim. A
file written from the Secret with `base64 -d` then enrolled a
passphrase one byte short of what the Secret holds, and the slot it
added never opened from the Secret. Read the file as it is; prompts
and stdin lines keep their newline handling, since a line break there
only separates entries.

The CLI page also showed the slot verbs taking passphrases on argv,
which they refuse; it now shows the file flags and says how the file
is read.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
CleanupSuperseded chose the slot to keep from an unlock done before it
read the keyring it writes. An operator who rolled the passphrase
Secret back to the superseded passphrase in that window had the slot
the Secret now opens removed, which locks the cluster. Resolve the
unlock slot inside the write, against the keyring about to be stored,
as Remove and Modify already do. A Secret that opens nothing by then
removes nothing.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Each 30-second pass of the master-key runnable built a fresh Unlocker,
so its cache never held and every pass ran Argon2id at 64 MiB against
the passphrase Secret, on a cluster that had nothing to clean up. Keep
one Unlocker on the runnable, and answer a keyring with no superseded
slot from the keyring alone, before any passphrase is tried. While a
superseded slot waits for the operator to move the Secret, the shared
Unlocker derives once per Secret version.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
applyLUKS fetched every volume's password on each reconcile, mapper
open or not: about six API reads plus a master-key unlock per volume.
That was steady API load for nothing, and on a locked cluster every
reconcile of an open LUKS replica failed, stalling DRBD and the rest
of the apply behind a password the volume did not need.

Probe the mapper with `cryptsetup status` first. When it is active and
the device has not grown past it, leave it as it is and read nothing.
Only opening, formatting and resizing take the password, and a probe
that cannot tell falls back to that path. The design now says what a
locked cluster actually blocks.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
With no LUKS volume in the dump, the import returned before it looked
at the passphrase, and -keyring-out still wrote a keyring whose one
slot was whatever the file held. That keyring is what the cluster then
unlocks with, so a typo surfaced only later, as a locked cluster.

Check a given passphrase against LINSTOR's master key whenever the dump
carries one. A dump with neither LUKS volumes nor a master key gives
nothing to check against, and is refused rather than trusted: LINSTOR
had no master passphrase there, and the runbook needs the LUKS flags
only for a dump with LUKS volumes, so no documented flow depends on it.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Every wrapped LUKS password names the key ID of the master key it is
wrapped under. After a migration the operator has to tell whether the
keyring in place is the converted one or one the controller bootstrapped
on its own, and the key ID is the one value that settles it without
reading the Secret by hand.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The runbook applied the converted keyring with the manifests, after
blockstor was deployed. Under Cozystack the passphrase Secret already
exists when blockstor starts, so the controller bootstraps a keyring
of its own from it on its first pass, with a new master key the
imported passwords are not wrapped under. Applying the converted
keyring afterwards then replaces that one with no check that nothing
was formatted under it in between.

Apply the keyring before the controller starts, say when replacing a
bootstrapped one is still safe, and check with list-passphrases that
the key ID in place is the one the converted Resources name.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Slot names were free text. Slot references resolve an ID before a
name, so a name of eight hex digits could shadow another slot's ID,
and enter-passphrase dropped every slot named "generated" when it
repaired a locked cluster, so an operator's slot under that name was
deleted along with the generated one.

Names are now [a-z0-9-]{1,32} and never read as a slot ID, checked
when a slot is added and when a keyring is parsed; REST answers 400.
The repair drops generated slots by origin and names the new one
without colliding. freshName keeps derived names within the limit.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The controller and REST code carried kubebuilder:rbac markers for
Secrets in blockstor-system. controller-gen emits no Role from them, so
they granted nothing, and if a generator ever honoured them they would
grant every Secret in the namespace, wider than the resourceNames Role
the Secrets are actually accessed under. Point at that Role instead.
`make manifests` is unchanged.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrei Kvapil (@kvaps) NOT LGTM, only because of the E2E helper. The crypto, the LINSTOR import and the fail-closed paths hold up, but E2E lanes 3, 4 and 6 fail on this head because of the new e2e helper (inline on tests/e2e/lib.sh). Every scenario that calls it exits within seconds: drbd-luks-stack and luks-layer (lane 3), luks-layered-toggle-delete-leak (lane 4) and resize-luks (lane 6), all with ControllerConfig "default" is invalid: spec: Required value (run 43666528510). The PR description says the e2e scenarios were not run; once the helper is fixed they need one green run before merge.

Comment thread tests/e2e/lib.sh
if [[ -z "$secret" ]]; then
secret=linstor-passphrase
if ! kubectl get controllerconfigs.blockstor.org default >/dev/null 2>&1; then
printf '%s\n' 'apiVersion: blockstor.org/v1alpha1' 'kind: ControllerConfig' \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates ControllerConfig/default with no spec, and the CRD lists spec as required (config/crd/bases/blockstor.org_controllerconfigs.yaml, required: [spec]). The CI stands have no ControllerConfig, so the apply is rejected with spec: Required value and every LUKS scenario that calls ensure_passphrase_secret dies before it creates anything. That is lanes 3, 4 and 6 in run 43666528510. The helper on main never created a ControllerConfig, which is why only this PR hits it. Fix: create the object with the reference already set, e.g. 'spec: {passphraseSecretRef: {name: linstor-passphrase}}', and drop the separate patch for that case.

- linstor-passphrase
verbs:
- get
- update

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: update here also covers linstor-passphrase, but nothing in blockstor writes the passphrase Secret. The only Secret updates are the keyring and the Secret the node reads its key from (pkg/passphrase/ops.go:604,636). A separate get-only rule for linstor-passphrase would keep the controller from overwriting the operator's Secret. The same applies to the copies in stand/blockstor-deploy.yaml and stand/blockstor-apiserver-deploy.yaml.

The helper created ControllerConfig/default without a spec and then
patched the reference in. The CRD requires spec, so the create was
refused and every LUKS scenario failed within seconds of starting.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>

# Conflicts:
#	cmd/linstor-migrate/main.go
#	cmd/linstor-migrate/main_test.go
#	pkg/linstormigrate/convert.go
The API server's CEL turns a format-byte string into bytes with
go-openapi's URL-safe base64 decoder, while Go writes []byte as
standard base64. Nearly every AES-GCM wrapped password contains '+'
or '/', so the set-once rules on Resource.spec.volumes[].luksKey and
Snapshot.spec.luksKeys fail to evaluate and every update to such an
object is refused, the satellite's finalizer strip included: LUKS
replicas could never be deleted, and the CRs left behind kept their
DRBD ports and broke later port-based e2e scenarios in the lane.

Declare wrapped a plain string with a standard-base64 pattern instead,
so the rules compare the text as stored and malformed values are still
refused. The envtest suite used fill bytes whose encoding happened to
be URL-safe; the new test uses a key that is not.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrei Kvapil (@kvaps) LGTM. The e2e helper now creates the ControllerConfig with its passphrase reference, the wrapped-key schema change holds against the apiserver's own CEL decoding, and every lane is green on this head. The update on linstor-passphrase from my last review is still there; that one stays optional.

@kvaps
Andrei Kvapil (kvaps) merged commit 0a2b5fa into main Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linstor-migrate: decrypt LINSTOR's LUKS volume passwords and re-wrap them under the blockstor master key

2 participants