Commit Graph

49 Commits

Author SHA1 Message Date
Sainath Sativar 33f8c94fe1 fixing missed override path
Signed-off-by: Sainath Sativar <Sativar.sainath@gmail.com>
2024-10-01 15:25:53 +01:00
Sainath Sativar 80c4d68f5e Fix: Improving error log message for missing policy.json file.
Signed-off-by: Sainath Sativar <Sativar.sainath@gmail.com>
2024-09-28 04:55:31 +01:00
Miloslav Trmač c936932f2a Use "maps" and "slices" from the standard library
... except where we need maps.Keys().

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-22 20:24:31 +02:00
Miloslav Trmač 976a6e7ec3 Use bytes.CutSuffix
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-03-09 21:14:09 +01:00
Miloslav Trmač f43fe85e9e Remove duplicate words in comments
golangci-lint linter: dupword

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:22:09 +01:00
Miloslav Trmač 9536626e05 Make policyJSONUmarshallerTests generic over the used type/interface
This avoid some unnecessary uses of interface{}, and allows us to
pass existing functions to otherJSONParser without needing an extra
type conversion thunk.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:34:43 +01:00
Miloslav Trmač 24359e09d1 s/interface{}/any/g
... in almost all cases.

Also rename mSI (map[string]interface{}) to mSA (map[string]any).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:34:11 +01:00
Miloslav Trmač 23a22f1f93 Use golang.org/x/exp to avoid open-coded loops.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:33:34 +01:00
Miloslav Trmač 515807635a Add functional-option NewPRSigstoreSigned
Possibly reject nil values of pointer fields at input?

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-01-21 22:03:20 +01:00
Miloslav Trmač ab3bfee37d Split sigstore configuration parsing and API into separate files
... to make policy_config*.go a bit smaller, and to allow sigstore
logic expansion.

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-01-21 22:02:46 +01:00
Daniel J Walsh cf6ccb96b6
Merge pull request #1609 from mtrmac/keyFiles
Allow accepting multiple GPG keyrings via signedBy.keyPaths
2022-07-13 14:51:56 -04:00
Sascha Grunert 849dd70143 Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-13 16:50:50 +02:00
Miloslav Trmač d218ff3d46 Allow accepting multiple GPG keyrings via signedBy.keyPaths
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:34:30 +02:00
Miloslav Trmač f17fc55b81 Add context to some test failures
... to make it easier to figure out which of breakFns failed.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:33:44 +02:00
Miloslav Trmač db58334da6 Remove a copy&pasted test entry
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:33:44 +02:00
Miloslav Trmač f90c9a7664 Beautify test data
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-12 13:11:30 +02:00
Miloslav Trmač df1b3a7d24 Refer to sigstore instead of cosign in most places
Note that this involves an incompatible signature binary format change.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-12 13:11:29 +02:00
Miloslav Trmač 64756915ba Add Cosign verification support
type: cosignSigned, with the usual keyData/keyPath.
Fulcio/Rekor is not currently implemented.

NOTE: This only allows a single public key, not a keyring,
unlike simple signing. That seems problematic, there are
known users of that. But we can fix that later by adding
keyDirectory and the like.

NOTE: Cosign interoperability requires use of
signedIdentity: matchRepository. The fairly useful
signedIdentity: remapIdentity has no repository-match
functionality.

NOTE: Multi-arch images need to be signed by cosign
with --recursive to be accepted; c/image enforces
signatures per platform.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-08 18:38:45 +02:00
Miloslav Trmač 103fb71482 Move signature/json.go to signature/internal/json.go
We are going to need it in signature/internal .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-06 17:08:12 +02:00
Miloslav Trmač 72550dd582 Always refer to pkg/errors as perrors
This will allow imports of errors and pkg/errors to
coexist in a single package, avoid adding accidental
new uses via errors.New(), make any potential new
additions more visible in reviews.

Files that can import errors only (typically
because they only use errors.New) have been updated to
that import instead of renaming.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 22:04:10 +02:00
Miloslav Trmač 7152f888b9 Update users of deprecated io/ioutil
Mostly just name changes that should not change behavior,
apart from ioutil.ReadDir -> os.ReadDir avoiding per-item
lstat(2) in some cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 20:46:48 +02:00
Miloslav Trmač 9a9904944d Use testing.T.TempDir()
... to simplify tests.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Chris Evich ab71da93ed
Fix unformatted source files
Signed-off-by: Chris Evich <cevich@redhat.com>
2021-06-14 16:59:13 -04:00
Josh Soref 111bf164be Spelling
* about
* appropriate
* busybox
* candidate
* candidates
* certificate
* config
* configuration
* containers
* decompression
* directory
* does-not/match
* does/not/exist
* doesnot
* doesnotexist
* exemplary
* garbage
* gzipped
* identify
* initially
* kubernetes
* length
* marshaling
* maximum
* mybetaproduct
* overridden
* parameter
* permissive
* policyconfiguration
* protocols
* reference
* referenceable
* requirement
* response
* simultaneously
* slashes
* subobject
* successfully
* this
* uncompressed
* unmarshaled
* unmarshaler
* unmarshaling it
* unmarshaller
* valid

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-23 14:37:37 -04:00
Lokesh Mandvekar f541c8245e Enable subdomain matching in policy.json
DockerReferenceNamespaces will also append wildcarded expressions for
subdomain matching in policy.json.

For example: [foo.example.com *.example.com *.com]

Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
2021-01-14 10:10:12 -05:00
Miloslav Trmač 9ae01c50df Fix signature tests with recent c/storage
Split defaultPolicyPathWithHomeDir from defaultPolicyPath to allow
testing it without overriding $HOME now that that does not have
an effect during the lifetime of a process.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-01-09 14:31:57 +01:00
Miloslav Trmač 9dd2c4d959 Add a signedIdentity choice "type": "remapIdentity"
This allows accepting signatures for a complete or partial
mirror of some other repository namespace in a single step,
similar in signing effect to setting up mirrors in registries.conf,
but letting image consumers to refer to the mirrors directly.

For tag/digest matching, this currently only implemnents the
default matchRepoDigestOrExact-like semantics; it's the right
choice for almost all users, and we can add other alternatives
later if it turned out to be necessary.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-12-04 17:57:34 +01:00
Miloslav Trmač 918e4ffaa6 Add a sanity check to extraJSONMember
... to ensure we are testing what we want to be testing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-12-04 17:57:34 +01:00
Miloslav Trmač 507e3f113e Fix copy&pasted field names in duplicate field tests
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-12-04 17:57:34 +01:00
Miloslav Trmač 4cd3bce93d Eliminate more duplication in signature/policy_config_tests.go
Add jsonUnmarshalFromObject and assertJSONUnmarshalFromObjectFails
to handle the common pattern of manufacturing a JSON and testing
how it unmarshals.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-08-28 23:20:31 +02:00
Miloslav Trmač 12fcbde822 Reduce duplication in policy_config_test.go
Most of the UnmarshalJSON tests follow the same structure,
copy&pasting boilerplate all over.  Consolidate them into a single
function with named parameters for the specifics.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-08-28 23:20:31 +02:00
Miloslav Trmač 57846c31ae Move TestInvalidPolicyFormatError
... to more closely match the position of the tested code in
policy_config.go.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-08-28 23:20:31 +02:00
Qi Wang 8cdf27d93a Add defaults for using the rootless policy path
Add support for default rootless policy path of $HOME/.config/containers/policy.json.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-05-14 12:13:03 -04:00
Ivan Voronchihin 4d6079501f Fix this value is never used
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:47:55 +04:00
Miloslav Trmač 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
Mike Lundy 369c44212b Put context.Context arguments on almost everything
- Network IO paths should react to cancels now.
- File IO paths generally still won't.
- `SystemContext` objects have been renamed to `sys` to leave `ctx`
  available for the stdlib context objects.

Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
2018-04-07 04:34:51 -07:00
Antonio Murdaca 0f9c61b702
signature: log policy path on error
Be more verbose when erroring out in case we have invalid data in the
policy json file.
Before this patch:

./skopeo copy docker://busybox oci:busybox
FATA[0000] Error loading trust policy: unexpected end of JSON input

After:

./skopeo copy docker://busybox oci:busybox
FATA[0000] Error loading trust policy: invalid policy data in
"/etc/containers/policy.json": unexpected end of JSON input

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-11-08 15:38:11 +01:00
Miloslav Trmač b6cea84639 Fix TestPolicyUnmarshalJSON
A test was referring to the old "specific" name for the "transports"
member.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-03-13 18:14:59 +01:00
Antonio Murdaca 29da2bc6d1
*: pluggable transports
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-03-02 12:25:17 +01:00
Miloslav Trmač 322058e563 Add signedIdentity type:matchRepoDigestOrExact, make it the default
This is the new default: tag references require a signature with a
matching repo:tag, digest references require a signature with a matching
repo (and any tag [or digest]), with the digest itself still being
validated in image.UnparsedImage, independently of signature processing.

Users can still opt into strict checking by specifying matchExact
in signedIdentity.

Also update most tests to use matchExactOrSignedDigest, to match
the default.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-11-08 15:04:53 +01:00
Miloslav Trmač c5fd291e7e Add SystemContext.RootForImplicitAbsolutePaths
As we add more config files, having a single knob to override them all
may simplify usage.

Note that this is not a chroot; it will override e.g. hard-coded /etc,
but $HOME is unaffected.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-31 21:13:31 +02:00
Miloslav Trmač 96c78066fd Add signature.DefaultPolicy()
This is the API most applications should use to get the policy for the
current host.

Also adds a types.SystemContext per discussions in
https://github.com/containers/image/pull/41 and elsewhere, to make the
functions testable and usable in special situations like chroots.

(Though, signature.DefaultPolicy() with an override is not that
different from signature.NewPolicyFromFile().)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-25 18:21:48 +02:00
Miloslav Trmač f11f6230bd Remove some redundancies in policy_config_test.go
Use a helper function for testing unmarshaling of obviously invalid
JSON.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:48:47 +02:00
Miloslav Trmač 55bcc37672 Add policy configuration scope validation
This e.g. rejects relative paths for directories.

Notably docker: transport is the only one which does not do any real
validation; we could copy&paste the character ranges and lengths
directly from docker/distribution/reference, which feels fairly ugly.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:07:28 +02:00
Miloslav Trmač 3bf59a68cd Use PolicyConfigurationIdentity for all transports
Implement PolicyConfigurationIdentity and PolicyConfigurationNamespaces
for all transports, which makes them all possible to use in policy
configurations.

Then use Transport().Name instead of hard-coded "docker" in policy
transport lookup.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:07:28 +02:00
Miloslav Trmač 39fadb0a38 Change policy format for Docker-independent namespaces
Instead of specific/$dockerreference, use transports/$transport/$policyconfigurationscope

This will allow transport-specific policies in the future.

This changes the data structures and parsing code, but mostly not yet the
functionality; everything is looked up through transports/"docker"/... ,
and Docker-reference-less transports are not yet supported.

The only new functionality is that there is a transport-level default
scope (transports/docker/""); at the moment it is redundant with the
global default, but soon it will not be so.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 20:56:13 +02:00
Miloslav Trmač 677f711c6c Redefine Policy.Specific scopes to use fully expanded hostname/namespace/repo format
Using the canonical minimized format of Docker references introduces too
many ambiguities.

This also removes some validation of the scope string, but all that was
really doing was rejecting completely invalid input like uppercase.

Sadly it is not qutie obvious that we can detect and reject mistakes like
using "busybox" as a scope instead of the correct
"docker.io/library/busybox".  Perhaps require at least one dot or port
number in the host name?
2016-06-02 16:12:10 +02:00
Miloslav Trmač d9b1c229e5 Add policy configuration data structures, construction and parsing 2016-05-24 20:24:15 +02:00