Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect XDG_CONFIG_HOME for policy.json #1011

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions signature/policy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ var systemDefaultPolicyPath = builtinDefaultPolicyPath
const builtinDefaultPolicyPath = "/etc/containers/policy.json"

// userPolicyFile is the path to the per user policy path.
var userPolicyFile = filepath.FromSlash(".config/containers/policy.json")
var userPolicyFile = filepath.FromSlash("containers/policy.json")

const defaultConfigHomeDir = ".config"

// InvalidPolicyFormatError is returned when parsing an invalid policy configuration.
type InvalidPolicyFormatError string
Expand All @@ -61,7 +63,11 @@ func defaultPolicyPath(sys *types.SystemContext) string {
if sys != nil && sys.SignaturePolicyPath != "" {
return sys.SignaturePolicyPath
}
userPolicyFilePath := filepath.Join(homedir.Get(), userPolicyFile)
configHomeDir := os.Getenv("XDG_CONFIG_HOME")
Copy link
Member

Choose a reason for hiding this comment

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

Please use containers/storage/pkg/homedir GetConfigHome()

if configHomeDir == "" {
configHomeDir = filepath.Join(homedir.Get(), defaultConfigHomeDir)
}
userPolicyFilePath := filepath.Join(configHomeDir, userPolicyFile)
if _, err := os.Stat(userPolicyFilePath); err == nil {
return userPolicyFilePath
}
Expand Down
2 changes: 1 addition & 1 deletion signature/policy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestDefaultPolicyPath(t *testing.T) {
os.Unsetenv("HOME")
}
}()
userDefaultPolicyPath := filepath.Join(tempHome, userPolicyFile)
userDefaultPolicyPath := filepath.Join(tempHome, defaultConfigHomeDir, userPolicyFile)

for _, c := range []struct {
sys *types.SystemContext
Expand Down