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 all commits
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
11 changes: 7 additions & 4 deletions signature/policy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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")

// InvalidPolicyFormatError is returned when parsing an invalid policy configuration.
type InvalidPolicyFormatError string
Expand All @@ -61,9 +61,12 @@ func defaultPolicyPath(sys *types.SystemContext) string {
if sys != nil && sys.SignaturePolicyPath != "" {
return sys.SignaturePolicyPath
}
userPolicyFilePath := filepath.Join(homedir.Get(), userPolicyFile)
if _, err := os.Stat(userPolicyFilePath); err == nil {
return userPolicyFilePath
configHomeDir, err := homedir.GetConfigHome()
if err == nil {
userPolicyFilePath := filepath.Join(configHomeDir, userPolicyFile)
if _, err := os.Stat(userPolicyFilePath); err == nil {
return userPolicyFilePath
}
}
if sys != nil && sys.RootForImplicitAbsolutePaths != "" {
return filepath.Join(sys.RootForImplicitAbsolutePaths, systemDefaultPolicyPath)
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, ".config", userPolicyFile)

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