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
7 changes: 0 additions & 7 deletions x/api/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ func DefaultSocketPath() string {
return filepath.Join(os.TempDir(), "docker-secrets-engine", "engine.sock")
}

func DaemonSocketPath() string {
if dir, err := os.UserCacheDir(); err == nil {
return filepath.Join(dir, "docker-secrets-engine", "daemon.sock")
}
return filepath.Join(os.TempDir(), "docker-secrets-engine", "daemon.sock")
}

func DefaultSecretsEngineDirectory() (string, error) {
dir, err := os.UserConfigDir()
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions x/api/defaults_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2025-2026 Docker, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows

package api

import (
"os"
"path/filepath"
)

func DaemonSocketPath() string {
if dir, err := os.UserCacheDir(); err == nil {
return filepath.Join(dir, "docker-secrets-engine", "daemon.sock")
}
return filepath.Join(os.TempDir(), "docker-secrets-engine", "daemon.sock")
}
30 changes: 30 additions & 0 deletions x/api/defaults_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2025-2026 Docker, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows

package api

import (
"os"
"path/filepath"
)

func DaemonSocketPath() string {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permission Issue: Non-elevated processes cannot access ProgramData

The Windows implementation unconditionally returns a path under C:\ProgramData, which requires elevated privileges for write access. When a user-level application calls DaemonSocketPath(), it will attempt to connect to a socket that it cannot create or access without elevation.

The Unix implementation uses os.UserCacheDir() with a fallback to os.TempDir(), providing a resilient approach that works in both user and system contexts. The Windows version should implement a similar strategy:

func DaemonSocketPath() string {
    if dir, err := os.UserCacheDir(); err == nil {
        return filepath.Join(dir, "docker-secrets-engine", "daemon.sock")
    }
    return filepath.Join(os.TempDir(), "docker-secrets-engine", "daemon.sock")
}

Or, if a system-wide path is truly required for Windows service scenarios, consider detecting the execution context and choosing the appropriate location accordingly.

base := os.Getenv("ProgramData")
if base == "" {
base = `C:\ProgramData`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing fallback mechanism

The Windows implementation hardcodes C:\ProgramData without any fallback or validation. If the ProgramData environment variable is not set and C:\ProgramData is inaccessible (non-standard Windows installations, restricted environments), the function returns a path that may be invalid or unusable.

The Unix version (defaults_unix.go) properly falls back to os.TempDir() if os.UserCacheDir() fails. The Windows implementation should follow the same pattern to ensure robustness across different Windows environments.

}
return filepath.Join(base, "Docker", "SecretsEngine", "daemon.sock")
}
Loading