-
Notifications
You must be signed in to change notification settings - Fork 2.6k
pkg/machine: add custom policy.json logic #21765
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
Changes from all commits
a02aa8f
f5a2683
bed6180
1e5b5a8
e32c9bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ LDFLAGS_PODMAN ?= \ | |
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \ | ||
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \ | ||
-X $(PROJECT)/v5/pkg/systemd/quadlet._binDir=$(BINDIR) \ | ||
-X $(PROJECT)/v5/pkg/machine/ocipull.DefaultPolicyJSONPath=$(MACHINE_POLICY_JSON_DIR) \ | ||
-X github.com/containers/common/pkg/config.additionalHelperBinariesDir=$(HELPER_BINARIES_DIR)\ | ||
$(EXTRA_LDFLAGS) | ||
LDFLAGS_PODMAN_STATIC ?= \ | ||
|
@@ -762,10 +763,10 @@ podman-remote-release-%.zip: test/version/version ## Build podman-remote for %=$ | |
$(MAKE) GOOS=$(GOOS) GOARCH=$(GOARCH) \ | ||
clean-binaries podman-remote-$(GOOS)-docs | ||
if [[ "$(GOARCH)" != "$(NATIVE_GOARCH)" ]]; then \ | ||
$(MAKE) CGO_ENABLED=0 $(GOPLAT) BUILDTAGS="$(BUILDTAGS_CROSS)" \ | ||
$(MAKE) CGO_ENABLED=0 $(GOPLAT) BUILDTAGS="$(BUILDTAGS_CROSS)" MACHINE_POLICY_JSON_DIR="." \ | ||
clean-binaries podman-remote; \ | ||
else \ | ||
$(MAKE) $(GOPLAT) podman-remote; \ | ||
$(MAKE) $(GOPLAT) MACHINE_POLICY_JSON_DIR="." podman-remote; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this is going to apply this setting to all machine zip archives whether darwin/win/linux etc, which is probably not what you want. One other approach that could make the Makefile approach a bit easier is to move LDFLAGS_PODMAN down to be after the os check area where SRCBINDIR is defined, and use that to also set MACHINE_POLICY_JSON_DIR defaults. Or you could this code wise and just change the logic in policyPath with a func in _windows.go that ignores the build flag and just uses a hard coded constant. If you prefer I can also just address this aspect in the follow-up PR change that also updates the installer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why not? If you run from the zip we should not assume any hard coded locations so I think that is fine regardless of the OS that they are used on. I rather not hard code the default into the binary only for windows as this should really left to packagers IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok fair enough, I assumed you wanted something like ../../conf on linux but I agree no reason it can't all be the same. There is one remaining issue which is that right now the policy is placed in the root, yet the binary is placed in usr/bin. For this strategy to work with the zips we would need to put the policy in /usr/bin, or alternatively we could do a search order, first check same dir, then fall back to ../.. |
||
fi | ||
if [[ "$(GOOS)" == "windows" ]]; then \ | ||
$(MAKE) $(GOPLAT) TMPDIR="" win-gvproxy; \ | ||
|
@@ -775,6 +776,7 @@ podman-remote-release-%.zip: test/version/version ## Build podman-remote for %=$ | |
fi | ||
cp -r ./docs/build/remote/$(GOOS) "$(tmpsubdir)/$(releasedir)/docs/" | ||
cp ./contrib/remote/containers.conf "$(tmpsubdir)/$(releasedir)/" | ||
cp ./pkg/machine/ocipull/policy.json "$(tmpsubdir)/$(releasedir)/" | ||
$(MAKE) $(GOPLAT) $(_dstargs) SELINUXOPT="" install.remote | ||
cd "$(tmpsubdir)" && \ | ||
zip --recurse-paths "$(CURDIR)/$@" "./$(releasedir)" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ocipull | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// DefaultPolicyJSONPath should be overwritten at build time with the real path to the directory where | ||
// the shipped policy.json file is located. This can either be absolute path or a relative path. If it | ||
// is relative it will be resolved relative to the podman binary and NOT the CWD. | ||
// | ||
// use "-X github.com/containers/podman/v5/pkg/machine/ocipull.DefaultPolicyJSONPath=/somepath" in go ldflags to overwrite this | ||
var DefaultPolicyJSONPath = "" | ||
|
||
const policyfile = "policy.json" | ||
|
||
type defaultPolicyError struct { | ||
errs []error | ||
} | ||
|
||
func (e *defaultPolicyError) Error() string { | ||
return fmt.Sprintf("no DefaultPolicyJSONPath defined and no local overwrites found: %q", e.errs) | ||
} | ||
|
||
func policyPath() (string, error) { | ||
paths := localPolicyOverwrites() | ||
errs := make([]error, 0, len(paths)) | ||
for _, path := range paths { | ||
_, err := os.Stat(path) | ||
if err == nil { | ||
return path, nil | ||
} | ||
errs = append(errs, err) | ||
} | ||
if DefaultPolicyJSONPath != "" { | ||
if filepath.IsAbs(DefaultPolicyJSONPath) { | ||
return filepath.Join(DefaultPolicyJSONPath, policyfile), nil | ||
} | ||
p, err := os.Executable() | ||
if err != nil { | ||
return "", fmt.Errorf("could not resolve relative path to binary: %w", err) | ||
} | ||
return filepath.Join(p, DefaultPolicyJSONPath, policyfile), nil | ||
} | ||
return "", &defaultPolicyError{errs: errs} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"default": [ | ||
{ | ||
"type": "insecureAcceptAnything" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ocipull | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func localPolicyOverwrites() []string { | ||
return []string{filepath.Join(os.Getenv("APPDATA"), "containers", policyfile)} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like during the pkginstaller build, $(MACHINE_POLICY_JSON_DIR) isn't passed from package.sh for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for checking, yes the quoting in package.sh was incorrect please retry