Skip to content

Commit d268ccf

Browse files
committed
landlock: ensure dirs used on policy
Ensure the directories references on the landlock policy exist, so that no errors are returned when running slsactl in an environment where they don't exist. Signed-off-by: Paulo Gomes <[email protected]>
1 parent c5e0976 commit d268ccf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

internal/landlock/landlock.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/landlock-lsm/go-landlock/landlock"
1111
)
1212

13+
const dirMode = 0o700
14+
1315
// EnforceOrDie checks whether or not to enforce the landlock policy, and if so,
1416
// apply it. Any error will result in os.Exit.
1517
func EnforceOrDie() {
@@ -41,6 +43,7 @@ func EnforceOrDie() {
4143
filepath.Join(home, ".sigstore"), // Sigstore TUF DB.
4244
filepath.Join(home, ".docker", "buildx"), // Image artefacts handling.
4345
}
46+
ensureDirs(rwDirs)
4447

4548
cwd, err := os.Getwd()
4649
if err == nil {
@@ -52,17 +55,26 @@ func EnforceOrDie() {
5255
landlock.RWDirs(rwDirs...),
5356
landlock.RODirs(
5457
"/proc/self",
58+
"/etc/ssl", // Root CA bundles to establish TLS.
59+
filepath.Join(home, ".docker"), // Docker config to access OCI/registries.
5560
),
5661
landlock.ROFiles(
57-
"/etc/resolv.conf", // DNS resolution.
58-
"/etc/ssl/ca-bundle.pem", // Root CA bundles to establish TLS.
59-
filepath.Join(home, ".docker/config.json"), // Docker config to access OCI/registries.
62+
"/etc/resolv.conf", // DNS resolution.
6063
),
6164
)
6265
if err != nil {
63-
fmt.Printf("failed to enforce landlock policies (requires Linux 5.13+): %v", err)
66+
fmt.Printf("failed to enforce landlock policies (requires Linux 5.13+): %v\n", err)
6467
if val == "on" {
6568
os.Exit(2)
6669
}
6770
}
6871
}
72+
73+
func ensureDirs(dirs []string) {
74+
for _, dir := range dirs {
75+
err := os.MkdirAll(dir, dirMode)
76+
if err != nil {
77+
slog.Error("failed to ensure dir", "path", dir, "error", err)
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)