Skip to content

Commit 61c0dc4

Browse files
jfroyfrezbo
authored andcommitted
feat: add zfs-service to zfs extension (unmount, encryption)
This patch adds a new service to the zfs extension (`zfs-service`) that handles pool import and unmount. These operations are tied to the service lifecycle: the service imports all pools when it starts, waits for an exit signal, then unmounts all pools before exiting. As a subtle additional benefit, the service passes the `-l` flag to `zpool-import`[^1], which instructs it to request encryption keys for all encrypted datasets. Using the zfs `keylocation`[^2] property and Talos secure boot and TPM disk encryption, a ZFS encryption key file can be safely stored on the EPHEMERAL partition to import encrypted datasets at boot. Alternatively, a key can be stored on an https server. [^1]: https://openzfs.github.io/openzfs-docs/man/master/8/zpool-import.8.html [^2]: https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#keylocation Signed-off-by: Jean-Francois Roy <[email protected]> Signed-off-by: Noel Georgi <[email protected]>
1 parent c08262d commit 61c0dc4

File tree

7 files changed

+78
-13
lines changed

7 files changed

+78
-13
lines changed

Diff for: storage/zfs/manifest.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
version: "$VERSION"
55
author: Andrei Kvapil, Aenix
66
description: |
7-
This system extension provides kernel module driver for ZFS built against a specific Talos version.
7+
This system extension provides the ZFS kernel module, the ZFS utilities, and a service to import all ZFS pools on start and unmount all pools on stop.
88
compatibility:
99
talos:
1010
version: ">= v1.6.0"

Diff for: storage/zfs/pkg.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ dependencies:
99
- stage: libtirpc-zfs
1010
- stage: zlib-zfs
1111
- stage: zfs-tools
12+
- stage: zfs-service
1213
steps:
1314
- prepare:
1415
- |
1516
sed -i 's#$VERSION#{{ .VERSION }}#' /pkg/manifest.yaml
1617
- install:
1718
- |
18-
mkdir -p /rootfs/lib/modules /rootfs/usr/local/lib/containers/zpool-importer
19-
20-
cp -R /lib/modules/* /rootfs/lib/modules
19+
mkdir -p /rootfs/lib/modules
20+
cp -R /lib/modules/* /rootfs/lib/modules/
2121
- |
2222
mkdir -p /rootfs/usr/local/etc/containers
23-
24-
cp /pkg/zpool-importer.yaml /rootfs/usr/local/etc/containers/zpool-importer.yaml
23+
cp /pkg/zfs-service.yaml /rootfs/usr/local/etc/containers/
2524
test:
2625
- |
2726
mkdir -p /extensions-validator-rootfs

Diff for: storage/zfs/zpool-importer.yaml renamed to storage/zfs/zfs-service.yaml

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
name: zpool-importer
1+
name: zfs-service
22
depends:
33
- service: udevd
44
- service: cri
55
- path: /dev/zfs
66
container:
7-
security:
8-
rootfsPropagation: shared
9-
entrypoint: /usr/local/sbin/zpool
10-
args:
11-
- import
12-
- -fa
7+
entrypoint: /zfs-service
138
mounts:
149
# ld-musl-x86_64.so.1
1510
- source: /lib
@@ -44,11 +39,20 @@ container:
4439
- rshared
4540
- rbind
4641
- rw
42+
- source: /run
43+
destination: /run
44+
type: bind
45+
options:
46+
- rshared
47+
- rbind
48+
- rw
4749
- source: /var
4850
destination: /var
4951
type: bind
5052
options:
5153
- rshared
5254
- rbind
5355
- rw
56+
security:
57+
rootfsPropagation: shared
5458
restart: untilSuccess

Diff for: storage/zfs/zfs-service/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module zfs-service
2+
3+
go 1.22
4+
5+
require golang.org/x/sys v0.24.0

Diff for: storage/zfs/zfs-service/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
2+
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

Diff for: storage/zfs/zfs-service/main.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package main
6+
7+
import (
8+
"log"
9+
"os"
10+
"os/exec"
11+
"os/signal"
12+
13+
"golang.org/x/sys/unix"
14+
)
15+
16+
func main() {
17+
cmd := exec.Command("/usr/local/sbin/zpool", "import", "-fal")
18+
cmd.Stdout = os.Stdout
19+
cmd.Stderr = os.Stderr
20+
if err := cmd.Run(); err != nil {
21+
log.Fatalf("zfs-service: zpool import error: %v\n", err)
22+
}
23+
24+
ch := make(chan os.Signal, 1)
25+
signal.Notify(ch, unix.SIGINT, unix.SIGTERM)
26+
<-ch
27+
28+
cmd = exec.Command("/usr/local/sbin/zfs", "unmount", "-au")
29+
cmd.Stdout = os.Stdout
30+
cmd.Stderr = os.Stderr
31+
if err := cmd.Run(); err != nil {
32+
log.Fatalf("zfs-service: zfs unmount error: %v\n", err)
33+
}
34+
}

Diff for: storage/zfs/zfs-service/pkg.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: zfs-service
2+
variant: scratch
3+
shell: /toolchain/bin/bash
4+
dependencies:
5+
- stage: base
6+
steps:
7+
- cachePaths:
8+
- /.cache/go-build
9+
- /go/pkg
10+
build:
11+
- |
12+
export PATH=${PATH}:${TOOLCHAIN}/go/bin
13+
cp -r /pkg/* .
14+
CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o zfs-service main.go
15+
install:
16+
- |
17+
mkdir -p /rootfs/usr/local/lib/containers/zfs-service
18+
cp zfs-service /rootfs/usr/local/lib/containers/zfs-service/
19+
finalize:
20+
- from: /rootfs
21+
to: /rootfs

0 commit comments

Comments
 (0)