From 04616dcf07f25627c592f68060508f9ba3a269cc Mon Sep 17 00:00:00 2001 From: Max Xing Date: Fri, 24 Jul 2026 11:27:46 -0700 Subject: [PATCH] fix(worker-llm-credentials): write worker-token 0644 so pylon can read it Pylon (llm-router-client) reads /var/run/llm/worker-token to authenticate its router registration, but it runs as a different non-root UID than the credential-manager (root) on the shared emptyDir, so it could not read the 0600 token. Registration failed and gateway invokes returned no_eligible_candidates. Write the token 0644 and chmod the tmp file to force the mode: os.WriteFile honors umask and skips the mode when tmp already exists, so a restrictive container umask or a stale tmp could otherwise leave it 0600. The llm emptyDir is mounted only by the two infra sidecars, not the customer workload container. NO-REF --- .../internal/worker/worker.go | 12 +++++++++++- .../internal/worker/worker_coverage_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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