diff --git a/src/compute-plane-services/worker-llm-credentials/internal/worker/worker.go b/src/compute-plane-services/worker-llm-credentials/internal/worker/worker.go index 7b287a285..86b6c7b80 100644 --- a/src/compute-plane-services/worker-llm-credentials/internal/worker/worker.go +++ b/src/compute-plane-services/worker-llm-credentials/internal/worker/worker.go @@ -98,7 +98,17 @@ func (w *Worker) Run(ctx context.Context) error { } } tmp := w.config.WorkerTokenPath + ".tmp" - if err := os.WriteFile(tmp, []byte(t.Token), 0600); err != nil { + // 0644 so the pylon sidecar (a different non-root UID) can read the + // token from the shared emptyDir; only these two infra sidecars + // mount it, not the customer workload container. + //nolint:gosec // G306: intentionally readable by the pylon sidecar + if err := os.WriteFile(tmp, []byte(t.Token), 0644); err != nil { + return err + } + // WriteFile honors umask and skips the mode when tmp already exists; + // chmod guarantees 0644 so the sidecar can read it. + //nolint:gosec // G302: intentionally readable by the pylon sidecar + if err := os.Chmod(tmp, 0644); err != nil { return err } return os.Rename(tmp, w.config.WorkerTokenPath) diff --git a/src/compute-plane-services/worker-llm-credentials/internal/worker/worker_coverage_test.go b/src/compute-plane-services/worker-llm-credentials/internal/worker/worker_coverage_test.go index 2829bf54a..f1dc64519 100644 --- a/src/compute-plane-services/worker-llm-credentials/internal/worker/worker_coverage_test.go +++ b/src/compute-plane-services/worker-llm-credentials/internal/worker/worker_coverage_test.go @@ -21,6 +21,7 @@ import ( "context" "os" "path/filepath" + "syscall" "testing" "time" @@ -134,6 +135,11 @@ func TestNew_DefaultsSharedConfigDir(t *testing.T) { // subdirectory that does not yet exist, so os.Stat returns ErrNotExist and the // callback must create the directory tree before writing the token. func TestRun_CreatesMissingTokenDir(t *testing.T) { + // A restrictive umask must not strip the token's read bits: Run chmods the + // file after writing so the pylon sidecar can always read it. + oldUmask := syscall.Umask(0o077) + defer syscall.Umask(oldUmask) + addr := startMockNVCFServer(t) tmpDir := t.TempDir() // Nested, non-existent subdirectory of the temp dir. @@ -198,6 +204,16 @@ func TestRun_CreatesMissingTokenDir(t *testing.T) { if string(content) != testWorkerToken { t.Fatalf("expected token %q, got %q", testWorkerToken, string(content)) } + + // The token must be readable by the pylon sidecar, which runs as a + // different UID on the shared emptyDir. + tokenInfo, err := os.Stat(workerTokenPath) + if err != nil { + t.Fatalf("token file not found: %v", err) + } + if got := tokenInfo.Mode().Perm(); got != 0644 { + t.Fatalf("expected token file mode 0644, got %o", got) + } } // TestRun_TokenDirCreateFails exercises the error-return of the directory