51 Commits

Author SHA1 Message Date
56e62948f7 go1.23: use std maps package
With go 1.23 the maps package was added in the std library. The linter
now wants us to use that. However the API chnaged as it returns an
iterator, thus we also have to use slices.Collect().

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-11 17:21:24 +01:00
0e8d1ad811 pkg/trust: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-19 09:52:14 +02:00
522934d5cf Replace strings.SplitN with strings.Cut
Cut is a cleaner & more performant api relative to SplitN(_, _, 2) added in go 1.18

Previously applied this refactoring to buildah:
https://github.com/containers/buildah/pull/5239

Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-11 13:50:15 +00:00
4dd58f226d Move golang requirement from 1.18 to 1.20
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-12-18 07:29:31 -05:00
5c0912b07b Revert the usage of home.GetConfigHome()
Although this might be the correct thing to do,
the idea is to keep the same behaviour across all three locations,
and change all three at once.

See https://github.com/containers/podman/pull/19231#discussion_r1265602832

[NO NEW TESTS NEEDED]

Signed-off-by: Ismael Arias <ismaelariasmn@gmail.com>
2023-07-17 18:29:06 +02:00
47997857ff Replace error check for non-existent file
Previously `os.IsNotExist(err)`, now `errors.Is(err, fs.ErrNotExist)`

[NO NEW TESTS NEEDED]

Signed-off-by: Ismael Arias <ismaelariasmn@gmail.com>
2023-07-17 17:49:05 +02:00
ca9874ab7d Use pkg/homedir to get the home config directory
Also, log a warning if there is an error when reading
the local policy.json file, if the error is other than ENOEXIST

[NO NEW TESTS NEEDED]

Signed-off-by: Ismael Arias <ismaelariasmn@gmail.com>
2023-07-17 14:12:01 +02:00
a3bbc3a2ca Fix trust not using local policy file
When running the `trust` command, only the global policy.json file
was being taken into account.

Fixes #19073

[NO NEW TESTS NEEDED]

Signed-off-by: Ismael Arias <ismaelariasmn@gmail.com>
2023-07-13 22:13:31 +02:00
35165df37b chore: replace github.com/ghodss/yaml with sigs.k8s.io/yaml
At the time of making this commit, the package `github.com/ghodss/yaml`
is no longer actively maintained.

`sigs.k8s.io/yaml` is a permanent fork of `ghodss/yaml` and is actively
maintained by Kubernetes SIG.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-04-06 21:11:17 +08:00
6502b1faa6 pkg/trust: Take the default policy path from c/common/pkg/config
This reduces the number of places default policy path is defined to two.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-11-25 10:14:15 +00:00
d968f3fe09 Replace deprecated ioutil
Package `io/ioutil` was deprecated in golang 1.16, preventing podman from
building under Fedora 37.  Fortunately, functionality identical
replacements are provided by the packages `io` and `os`.  Replace all
usage of all `io/ioutil` symbols with appropriate substitutions
according to the golang docs.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-09-20 15:34:27 -04:00
2c63b8439b Fix stutters
Podman adds an Error: to every error message.  So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-10 07:52:00 -04:00
61fe95bb4f Preserve all unknown PolicyRequirement fields on (podman image trust set)
We are unmarshaling and re-marshaling JSON, which can _silently_ drop data
with the Go design decision.data.

Try harder, by using json.RawMessage at least for the data we care about.

Alternatively, this could use json.Decoder.DisallowUnknownFields.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
ad0c785f8e Reorganize the types in policy.go a bit
... to go from top to bottom.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
a7e88c8dac Add support for showing keyPaths in (podman image trust show)
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
752eceaecc Support (image trust show) for sigstoreSigned entries
sigstoreSigned does not have GPG IDs, so we add N/A in that column.

NOTE: this does not show the use-sigstore-attachments value from
registries.d.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
b36a1d1b79 BREAKING CHANGE: Change how (podman image trust show) represents multiple requirements
Currently
- the output uses the first entry's type, even if the requirements are different
  (notably signedBy + sigstoreSIgned)
- all public keys IDs are collected to a single line, even if some of them
  are interchangeable, and some are required (e.g. two signedBy requirements
  could require an image to be signed by (redhatProd OR redhatBeta) AND (vendor1 OR vendor2)

So, stop collapsing the requirements, and return a separate entry for each one. Multiple
GPG IDs on a single line used to mean AND or OR, now they always mean AND.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
bba306788a Reorganize descriptionsOfPolicyRequirements a bit
Do the registries.d lookup once, separately from building
an entry, so that we can share it across entries.

Also prepare a separate res to allow adding multiple entries.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
2f6c145e86 Use the full descriptionsOfPolicyRequirements for the default scope
... instead of taking a shortcut, e.g. not listing any keys if they are required.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
b15afce551 Rename haveMatchRegistry to registriesDConfigurationForScope
Just so that we don't have a boolean-named function returning a struct.
Also reorder the parameters to have the container first, and the lookup
key second.

Shoud not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
1a97c4d9fa Rename tempTrustShowOutput to entry
Now that it is the primary return value of a small function,
the long name only makes reading harder.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:59 +02:00
51064acc49 Split descriptionsOfPolicyRequirements out of getPolicyShowOutput
This will evetually allow us to use it for the default scope
as well, which currently uses a simplified version.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:52:57 +02:00
d4c5217280 Recognize the new lookaside names for simple signing sigstore
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:51:59 +02:00
4df1e2524b Add a unit test for trust.PolicyDescription
Add at least a basic unit test for the various entry types.

So that we don't have to actually deal with GPG keys and /usr/bin/gpg*,
parametrize the code with a gpgIDReader , and pass a fake one
in the unit test.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:51:58 +02:00
4b2bd1036b Make the output of (podman image trust show) deterministic
Sort map keys instead of iterating in the Go-imposed random order.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
35fa8c16a2 Make most of pkg/trust package-private
We now have only a few entrypoints that are called externally,
so make the rest private.  This will make it more obvious that
we are not breaking any external users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
7723a1ea65 Move most of ImageEngine.ShowTrust into pkg/trust.PolicyDescription
This will allow us to write unit tests without setting up the complete Podman runtime
(and without the Linux dependency).

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
ff3f574fc0 Add support for sigstoreSigned in (podman image trust set)
NOTE: This does not edit the use-sigstore-attachments value
in registries.d, similarly to how (podman image trust set) didn't
set the lookaside paths for simple signing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
9828bc4453 Create new policy entries together with validating input
That way, we don't have to switch over trustType twice.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
e2d1bdd1d8 Improve validation of data in ImageEngine.SetTrust
- Also reject public keys with types that don't use them
- Reject unknown trust types
- And add unit tests

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:43 +02:00
cbdbb025a3 Move most of imageEngine.SetTrust to pkg/trust.AddPolicyEntries
This will allow us to write unit tests without setting up the complete Podman runtime
(and without the Linux dependency).

Also, actually add a basic smoke test of the core functionality.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 01:50:42 +02:00
4c5366ee03 Make trust.CreateTempFile private
Nothing uses it outside the package.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 00:35:59 +02:00
5be00f2270 Reorganize pkg/trust
Split the existing code into policy.go and registries.go,
depending on which files it concerns.

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 00:35:58 +02:00
1d2def8d06 Remove an unused trust.ShowOutput type
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-08-25 00:35:08 +02:00
a46f798831 pkg: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

[NO NEW TESTS NEEDED]

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-08 08:54:47 +02:00
6f7a803d06 Cleanup display of trust with transports
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-02-22 15:08:58 -05:00
1c4e6d8624 standardize logrus messages to upper case
Remove ERROR: Error stutter from logrus messages also.

[ NO TESTS NEEDED] This is just code cleanup.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-22 15:29:34 -04:00
78c8a87362 Enable whitespace linter
Use the whitespace linter and fix the reported problems.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-11 23:01:56 +01:00
cf8f2342a1 image sign using per user registries.d
Support per user ~/.config/containers/registries.d to allow rootless image sign configurations.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-12-07 09:58:38 -05:00
684d0079d2 Lowercase some errors
This commit is courtesy of

```
for f in $(git ls-files *.go | grep -v ^vendor/); do \
	sed -i 's/\(errors\..*\)"Error /\1"error /' $f;
done

for f in $(git ls-files *.go | grep -v ^vendor/); do \
	sed -i 's/\(errors\..*\)"Failed to /\1"failed to /' $f;
done

```

etc.

Self-reviewed using `git diff --word-diff`, found no issues.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 15:56:44 -07:00
4878dff3e2 Remove excessive error wrapping
In case os.Open[File], os.Mkdir[All], ioutil.ReadFile and the like
fails, the error message already contains the file name and the
operation that fails, so there is no need to wrap the error with
something like "open %s failed".

While at it

 - replace a few places with os.Open, ioutil.ReadAll with
   ioutil.ReadFile.

 - replace errors.Wrapf with errors.Wrap for cases where there
   are no %-style arguments.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 15:30:37 -07:00
69ac054ae6 fix bug podman sign storage path
- fix the bud podman not using specified --directory as signature storage.
- use manifest and image referce to set repo@digest.
close #6994
close #6993

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-08-04 15:10:47 -04:00
4bb43b898d Fixup issues found by golint
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-10 05:49:41 -04:00
e9a17da1c5 v2trust set and show
add podman image trust set and show

Signed-off-by: baude <bbaude@redhat.com>
Signed-off-by: bbaude <bbaude@DESKTOP-SH5EG3J.localdomain>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-05-07 09:55:52 -05:00
8d928d525f codespell: spelling corrections
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2019-11-13 08:15:00 +11:00
a4a70b4506 bump containers/image to v5.0.0, buildah to v1.11.4
Move to containers/image v5 and containers/buildah to v1.11.4.

Replace an equality check with a type assertion when checking for a
docker.ErrUnauthorizedForCredentials in `podman login`.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-10-29 13:35:18 -04:00
d3f59bedb3 Update c/image to v4.0.1 and buildah to 1.11.3
This requires updating all import paths throughout, and a matching
buildah update to interoperate.

I can't figure out the reason for go.mod tracking
	github.com/containers/image v3.0.2+incompatible // indirect
((go mod graph) lists it as a direct dependency of libpod, but
(go list -json -m all) lists it as an indirect dependency),
but at least looking at the vendor subdirectory, it doesn't seem
to be actually used in the built binaries.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-04 20:18:23 +02:00
fec1de6ef4 trivial cleanups from golang
the results of a code cleanup performed by the goland IDE.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-03 15:41:33 -05:00
e24167eef9 Fix up image sign in PR 2108
Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-01-15 12:25:10 -05:00
b01b2a78f4 Fix 'image trust' from PR1899
Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-01-09 17:48:47 -05:00