Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"os"
"path/filepath"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading