From 94a76f9c5c8439bae3bd5612b6f919611ede74fd Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 9 Oct 2026 00:44:52 +0100 Subject: [PATCH] Fix systemd WorkingDirectory syntax and verify with native validator --- docs/installation-verification.md | 6 ++++++ internal/installation/service.go | 4 +++- internal/installation/service_test.go | 30 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/installation-verification.md b/docs/installation-verification.md index 269fc352..5aa17269 100644 --- a/docs/installation-verification.md +++ b/docs/installation-verification.md @@ -37,3 +37,9 @@ An isolated installed-CLI check started the server in one directory and invoked runs completed and recorded/executed in the client invocation directory. The autostart preview required no repository configuration and passed `plutil -lint`. CLI and dashboard regression tests also check invocation-directory selection. + +The installation tests were also executed as a Linux binary in Debian with +systemd installed. The native `systemd-analyze verify` regression passed for the +generated unit, including a directory containing spaces, quotes, and `%`/`$`. +This reproduced and fixed the invalid quoted `WorkingDirectory` setting. A +container syntax check does not prove live user-service startup or login restart. diff --git a/internal/installation/service.go b/internal/installation/service.go index 183440b1..69ed95b8 100644 --- a/internal/installation/service.go +++ b/internal/installation/service.go @@ -43,7 +43,9 @@ func (d serviceDefinition) render(platform string) (string, error) { } if platform == "linux" { var b strings.Builder - fmt.Fprintf(&b, "# %s\n[Unit]\nDescription=Pipelines server\n\n[Service]\nType=simple\nWorkingDirectory=%s\nExecStart=%s", serviceMarker, unitQuote(d.Directory), unitQuote(strings.ReplaceAll(d.Binary, "$", "$$"))) + // WorkingDirectory is a path setting, not a shell-style argument list. + // Quotes become literal path characters and make an absolute path invalid. + fmt.Fprintf(&b, "# %s\n[Unit]\nDescription=Pipelines server\n\n[Service]\nType=simple\nWorkingDirectory=%s\nExecStart=%s", serviceMarker, strings.ReplaceAll(d.Directory, "%", "%%"), unitQuote(strings.ReplaceAll(d.Binary, "$", "$$"))) for _, arg := range d.Args { fmt.Fprintf(&b, " %s", unitQuote(strings.ReplaceAll(arg, "$", "$$"))) } diff --git a/internal/installation/service_test.go b/internal/installation/service_test.go index 495a951f..51556f29 100644 --- a/internal/installation/service_test.go +++ b/internal/installation/service_test.go @@ -6,12 +6,39 @@ import ( "encoding/xml" "io" "os" + "os/exec" "path/filepath" "runtime" "strings" "testing" ) +func TestSystemdDefinitionAcceptedByNativeValidator(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("systemd validation requires Linux") + } + validator, err := exec.LookPath("systemd-analyze") + if err != nil { + t.Skip("systemd-analyze is not installed") + } + dir := filepath.Join(t.TempDir(), `directory with "quotes" 100% $USER`) + if err := os.Mkdir(dir, 0700); err != nil { + t.Fatal(err) + } + d := serviceDefinition{Binary: "/bin/true", Directory: dir, Args: []string{"-db", filepath.Join(dir, "data.db")}, Environment: map[string]string{"PATH": "/usr/bin:/bin"}} + text, err := d.render("linux") + if err != nil { + t.Fatal(err) + } + path := filepath.Join(t.TempDir(), "pipelines.service") + if err := os.WriteFile(path, []byte(text), 0600); err != nil { + t.Fatal(err) + } + if output, err := exec.Command(validator, "verify", path).CombinedOutput(); err != nil { + t.Fatalf("systemd rejected generated definition: %v\n%s\n%s", err, output, text) + } +} + func TestServiceDefinitionsQuotePathsAndKeepEnvironmentLimited(t *testing.T) { d := serviceDefinition{Binary: `/some bin/server`, Directory: `/repo "quoted" 100% $USER`, Args: []string{"-db", `/repo "quoted" 100% $USER/data.db`}, Environment: map[string]string{"PATH": "/usr/bin:/custom bin", "PIPELINES_NTFY_TOKEN_FILE": "/secret & token", "PROVIDER_SECRET": "must-not-export"}} for _, platform := range []string{"linux", "darwin"} { @@ -23,6 +50,9 @@ func TestServiceDefinitionsQuotePathsAndKeepEnvironmentLimited(t *testing.T) { t.Fatal("unexpected credentials or missing marker", text) } if platform == "linux" { + if !strings.Contains(text, "\nWorkingDirectory=/repo \"quoted\" 100%% $USER\n") { + t.Fatal("WorkingDirectory must be an unquoted absolute path", text) + } if !strings.Contains(text, `"/some bin/server"`) || !strings.Contains(text, `100%% $$USER`) || !strings.Contains(text, `Environment="PATH=/usr/bin:/custom bin"`) { t.Fatal("unsafe systemd escaping", text) }