You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
942 B
Go
33 lines
942 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAgentSystemdSandboxOnlyGrantsStateAndManagedNVRAMWrites(t *testing.T) {
|
|
servicePath := filepath.Join("..", "..", "deploy", "virt-cloud-agent.service")
|
|
contents, err := os.ReadFile(servicePath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
service := string(contents)
|
|
for _, required := range []string{
|
|
"ProtectSystem=strict",
|
|
"StateDirectory=virt-agent",
|
|
"ReadWritePaths=/var/lib/virt-agent -/var/lib/libvirt/qemu/nvram",
|
|
"If nvram_directory is configured elsewhere, replace this path in a drop-in.",
|
|
} {
|
|
if !strings.Contains(service, required) {
|
|
t.Fatalf("agent service is missing %q", required)
|
|
}
|
|
}
|
|
for _, forbidden := range []string{"ReadWritePaths=/var/lib/libvirt", "ReadWritePaths=/srv", "ProtectSystem=false"} {
|
|
if strings.Contains(service, forbidden) {
|
|
t.Fatalf("agent service broadens its write namespace with %q", forbidden)
|
|
}
|
|
}
|
|
}
|