pkg/machine/ocipull: add custom policy.json location

The default policy file /etc/containers/policy.json location does not
work on windows and for packages that ship a default.

Now we search for the policy.json in the following overwrite locations:
macos and linux:
 - ~/.config/containers/policy.json
 - /etc/containers/policy.json
windows:
 - %APPDATA%\containers\policy.json

Also it offers an additional DefaultPolicyJSONPath var that should be
overwritten at built time with the path of the file that is shipped by
packagers. Thile file is used when none of the overwrite paths exist.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-02-20 14:47:22 +01:00
parent 6dd8454a54
commit a02aa8f6a2
4 changed files with 83 additions and 2 deletions

View File

@ -0,0 +1,19 @@
//go:build !windows
package ocipull
import (
"path/filepath"
"github.com/containers/common/pkg/config"
"github.com/containers/storage/pkg/homedir"
)
func localPolicyOverwrites() []string {
var dirs []string
if p, err := homedir.GetConfigHome(); err == nil {
dirs = append(dirs, filepath.Join(p, "containers", policyfile))
}
dirs = append(dirs, config.DefaultSignaturePolicyPath)
return dirs
}