-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
7 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module zfs-service | ||
|
||
go 1.22 | ||
|
||
require golang.org/x/sys v0.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= | ||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
"os/signal" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func main() { | ||
cmd := exec.Command("/usr/local/sbin/zpool", "import", "-fal") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
log.Fatalf("zfs-service: zpool import error: %v\n", err) | ||
} | ||
|
||
ch := make(chan os.Signal, 1) | ||
signal.Notify(ch, unix.SIGINT, unix.SIGTERM) | ||
<-ch | ||
|
||
cmd = exec.Command("/usr/local/sbin/zfs", "unmount", "-au") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
log.Fatalf("zfs-service: zfs unmount error: %v\n", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: zfs-service | ||
variant: scratch | ||
shell: /toolchain/bin/bash | ||
dependencies: | ||
- stage: base | ||
steps: | ||
- cachePaths: | ||
- /.cache/go-build | ||
- /go/pkg | ||
build: | ||
- | | ||
export PATH=${PATH}:${TOOLCHAIN}/go/bin | ||
cp -r /pkg/* . | ||
CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o zfs-service main.go | ||
install: | ||
- | | ||
mkdir -p /rootfs/usr/local/lib/containers/zfs-service | ||
cp zfs-service /rootfs/usr/local/lib/containers/zfs-service/ | ||
finalize: | ||
- from: /rootfs | ||
to: /rootfs |