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.
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAgentSystemdUnitMatchesHostDeployment(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{
|
|
"Type=simple",
|
|
"User=root",
|
|
"Group=root",
|
|
"ExecStart=/home/agent/virt-agent -config /home/agent/config.json",
|
|
"Restart=on-failure",
|
|
"RestartSec=5",
|
|
"LimitCORE=0",
|
|
"TimeoutStopSec=30",
|
|
} {
|
|
if !strings.Contains(service, required) {
|
|
t.Fatalf("agent service is missing %q", required)
|
|
}
|
|
}
|
|
for _, forbidden := range []string{
|
|
"ProtectSystem=", "ProtectHome=", "ReadWritePaths=",
|
|
"StateDirectory=", "NoNewPrivileges=", "PrivateTmp=", "UMask=",
|
|
} {
|
|
if strings.Contains(service, forbidden) {
|
|
t.Fatalf("agent service contains retired sandbox setting %q", forbidden)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLibvirtPublicGuardDropInsFailClosedBeforeAgentStartup(t *testing.T) {
|
|
for _, service := range []string{"libvirtd", "virtqemud"} {
|
|
t.Run(service, func(t *testing.T) {
|
|
path := filepath.Join("..", "..", "deploy", service+".service.d", "10-virt-cloud-public-guard.conf")
|
|
contents, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dropIn := string(contents)
|
|
for _, required := range []string{
|
|
"[Unit]",
|
|
"After=firewalld.service nftables.service",
|
|
"Before=virt-cloud-agent.service",
|
|
"[Service]",
|
|
"ExecStartPre=+/home/agent/virt-agent -config /home/agent/config.json -public-guard-preflight",
|
|
} {
|
|
if !strings.Contains(dropIn, required) {
|
|
t.Fatalf("%s drop-in is missing %q", service, required)
|
|
}
|
|
}
|
|
if strings.Count(dropIn, "ExecStartPre=") != 1 {
|
|
t.Fatalf("%s drop-in ExecStartPre count = %d", service, strings.Count(dropIn, "ExecStartPre="))
|
|
}
|
|
for _, forbidden := range []string{"ConditionPathExists=", "-operation-worker", "||", ";"} {
|
|
if strings.Contains(dropIn, forbidden) {
|
|
t.Fatalf("%s drop-in contains fail-open or mixed-mode token %q", service, forbidden)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|