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

Conversation

davidscherer
Copy link

The default path for (rootless) policy.json should respect XDG_CONFIG_HOME if present, as the paths for other configuration files like storage.conf and containers.conf do.

See also containers/common#248

@TomSweeneyRedHat
Copy link
Member

@davidscherer looks like you've some whitespace issues somewhere. gofmt -s -w filename.go and then add/commit/rebase/push should fix it.

The default path for (rootless) policy.json should respect
XDG_CONFIG_HOME if present, as the paths for other configuration
files like storage.conf and containers.conf do.

Signed-off-by: David Scherer <david.scherer@antithesis.com>
@@ -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()

Signed-off-by: David Scherer <david.scherer@antithesis.com>
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

This would currently break non-Linux systems, where GetConfigHome always fails. I don’t know what’s the right thing to do on Windows (probably not hard-coding .config), or whether we care much, but on macOS it really should be possible to use a per-user path, and by now it would break users to change the default.

At a first glance, homedir.GetConfigHome should probably use the hard-coded .config (it does fall back to that path on Linux already!) on non-XDG systems, or at least on non-XDG Unixes — but I haven’t looked at all at any other users to see whether it would be safe.

@rhatdan
Copy link
Member

rhatdan commented Mar 23, 2021

@davidscherer @vrothberg @mtrmac what should we do with this PR?

@davidscherer
Copy link
Author

I have been happily using the patch from the first commit to this PR, which fixes the problem on Linux, is probably better than nothing on OS X, and as far as I know doesn't cause problems on Windows.

I made the requested change to use GetConfigHome, but that function turns out to be unimplemented on Windows.

So the options are, I suppose:

  1. Merge my original change
  2. Implement and test GetConfigHome for Windows

There's a case to be made for (2), but I am not in a great position to do it. IMO (1) is an improvement over the status quo, and the conflicts look easy to resolve.

@wwilson
Copy link

wwilson commented Mar 18, 2022

What are the current obstacles to getting this merged?

@mtrmac
Copy link
Collaborator

mtrmac commented Mar 19, 2022

Thanks for the ping; it turns out that c/storage/pkg/homedir is no longer hard-failing on non-Linux systems, after commit e2cffe5c610054b088029431230d4143a0e6b1e5 , so this might now be possible to do.

Given that, the PR would need to be updated to be testable without relying on external state (i.e. to turn defaultPolicyPathWithHomeDir into something like defaultPolicyPathWithConfigHomeDir), and then to make sure the test coverage is as good as it can get.

@mtrmac mtrmac added the kind/feature A request for, or a PR adding, new functionality label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for, or a PR adding, new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants