Commit Graph

187 Commits

Author SHA1 Message Date
Ivan Voronchihin 21320ca776 Fix golangci-lint advises
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:31:04 +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
Qi Wang 9c14d60bf5 return resp error message
follow https://github.com/containers/image/pull/709
return and wrap http response message to show server-side error message.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-10-24 14:20:06 -04:00
Valentin Rothberg d51a7cabae docker: handle http 429 status codes
Consolidate checking the http-status codes to allow for a more uniform
error handling.  Also treat code 429 (too many requests) as a known
error instead of an invalid status code.

When hitting 429, perform an exponential back off starting a 2 seconds
for at most 5 iterations.  If the http.Response set the `Retry-Header`
then use the provided value or date to compute the delay until the
next attempt.  Note that the maximum delay is 60 seconds.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-18 11:47:57 +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
Qi Wang 618003c1a9 add http response to log
fix https://github.com/containers/libpod/issues/3884
Add http response message log to show server-side error message.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-09-27 15:14:25 -04:00
Miloslav Trmač a3d69a4a89 Use the same HTTP client for contacting the bearer token server and the registry
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-08-01 21:41:45 +02:00
Valentin Rothberg 00eeb722e1 docker client: error if registry is blocked
Return an error whenever we attempt to create a docker client when the
underlying registry is configured to be blocked in the registries.conf.
Until now, users of the c/image library implemented this behaviour but
it has not been enforced.

Now, it's time to pull the trigger and enforce the configuration.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-07-24 18:07:41 +02:00
Miloslav Trmač 7122bf35ed Only create a http.Client once in a dockerClient
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-05-13 22:28:30 +02:00
Miloslav Trmač 88345c5abd Clean up comments about the detectProperties* members of dockerClient
Primarily remove the misleading reference to makeRequest, which is not
the only caller of detectProperties.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-05-13 22:28:30 +02:00
Miloslav Trmač 373ef43e28 Remove the 'dockerClient.scheme == ""' special case
c.detectPropertiesOnce already ensures detectPropertiesHelper
only executes once, so the documentation and code for indicating this
in c.scheme is now redundant.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-05-13 22:28:25 +02:00
Miloslav Trmač 4533ea01ee Move tlsClientConfig to a more logical place in dockerClient
... to roughly follow the order the members are initialized/used.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-05-13 22:28:25 +02:00
Sascha Grunert a39a6e4c00
Add registry mirror support to docker client
This commit enables private registry mirror support for the docker
client. Major changes and additions related to an image pull are:

- If mirrors are specified via the configuration (registries.conf), then
  the first working (where the manifest is available remotely) mirror
  will be used for the pull.
- The main registry will be the fallback if no mirror works.
- The insecure/skipVerify flags will be used from system context and
  from the corresponding registry/mirror as fallback too.
- Configuring a prefix will be considered, too.
- Update documentation for registry mirror support within
  `registries.conf` as well as the man page.
- Renamed the `url` to `location` within system_registries_v2

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-04-23 14:40:59 +02:00
W. Trevor King 9e941c2a78 docker/docker_client: Drop redundant Domain(ref.ref) call
There have been redundant calls here since two ref.ref.Hostname()
calls were added in aaedc642 (Implement lookaside storage for
signatures for Docker registries, 2016-08-11, #52).  At that point the
two calls were separated by a dockerHostname check which could have
been shifted by two lines to avoid the doubled function calls.  But in
f28367e1 (Add docker/config package to containers/image/pkg,
2017-08-29, #333) the dockerHostname check moved to a separate
function entirely (newDockerClientWithDetails) while the Domain()
calls remained together in newDockerClientFromRef.  So now there is no
longer any reason for the second call, and this commit drops it.

Signed-off-by: W. Trevor King <wking@tremily.us>
2019-03-18 07:20:51 -07:00
Sascha Grunert 160b7af59c
Remove newlines from logging
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-01-22 09:28:22 +01:00
Valentin Rothberg 88168b8f84 docker client: make extraScope a parameter
Make the extra token scope a parameter instead of a struct member.  This
allows a parallel execution of TryReusingBlob without the need to
serialize accesses.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-01-17 14:44:48 +01:00
Valentin Rothberg 15bdf92c0e dockerClient: make tokenCache thread safe
Make tokenCache thread safe by turning it into a `sync.Map` suitable for
concurrent reads and writes.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2018-12-18 17:15:02 +01:00
Valentin Rothberg 18399946bf dockerClient: execute detectProperties at most once
Make detectProperties usable for concurrent usage by executing it at
most once (via sync.Once) and storing its error in a field to make
it accessible to following invocations.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2018-12-18 17:15:02 +01:00
Miloslav Trmač 8ec163b09a Add support for an "extra" temporary scope to dockerClient
This allows using cross-repository mounts, which require
a token for both reading the source and reading and writing to the destination.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač ed248d7fc8 Move computed token expiration from dockerClient to bearerToken
This will make it easier to cache several different tokens in a single client.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 79ae9d1dab Simplify getBearerToken
Now that the code has been moved, integrate it better into its uses.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 6e7bb54a5c Move bearer token parameter setup into from setupRequestAuth to getBearerToken
This is a trivial move, does not change behavior; but it will allow
setupRequestAuth to be a bit more complex about the scopes and token caching
in the future.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Valentin Rothberg 44779983da dockerClient: skip TLS verification if configured in registries
Make dockerClient sensitive to the configured registries by using the
sysregistriesv2 package.  Unless specified in the SystemContext, the TLS
config's InsecureSkipVerify flag now adheres to the registries Insecure
field (if specified in the registries.conf).  Notice, that the default
value remains false (i.e., TLS verification is performed).

SystemContext.DockerInsecureSkipTLSVerify is usually set by users of
this library (e.g., Skopeo and Podman).  To be able to distinguish
between a default value and a user-specified value, introduce a
types.OptionalBool type that is now used for DockerInsecureSkipTLSVerify.

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
2018-11-16 15:01:01 +01:00
Miloslav Trmač 2c3f193e1a In debug logs of Docker v1 ping, only call err.Error() if err != nil
For me, this seems to work and only results in a weird
> Ping https://registry-1.docker.io/v1/_ping err <nil>
(with the last (%#v) element completely lost;

OTOH https://github.com/containers/buildah/issues/1079 reports a crash most likely attributable to this.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-10-10 20:44:01 +02:00
Miloslav Trmač af52ef8460 Don't use %q for HTTP status code (an integer)
It would interpret the integer as an Unicode codepoint and print
a quoted character constant, which is not useful.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-10-10 18:52:36 +02:00
Miloslav Trmač 2166be1d6e Include http.StatusText with every HTTP status code in errors
e.g. 504 (Gateway timeout) instead of just "504".

Note that for unknown status codes this will output "99999 ()"; this
seems not worth worrying about and building a helper for right now.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-10-10 18:52:36 +02:00
Nalin Dahyabhai cb88cfdd15 dockerClient.detectProperties: debug log the error string
When logging a debug message about an error that we get back when trying
to ping a registry, log the error text, too.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-09-28 14:18:21 -04:00
Urvashi Mohnani e874deaea9 Update search for registries
Change the order in which a search happens. Try the v1 endpoint
first without any authentication token and if that fails, get a
token and try the v2 endpoint.
Also add feature to search with an empty query, which only works
with the v2 endpoint. If the query is empty skip the v1 endpoint
and go straight to the v2 endpoint.
This helps fix issues we were seeing when searching quay.io and also
adds the ability to search a whole registry without a specific query
parameter.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2018-09-11 15:48:08 -04:00
Miloslav Trmač 276a91177c Simplify debug log of the /v2/ ping
Successful ping currently looks like:
> DEBU[0000] GET https://registry-1.docker.io/v2/
> DEBU[0000] Ping https://registry-1.docker.io/v2/ err <nil>
> DEBU[0000] Ping https://registry-1.docker.io/v2/ status 401

Skip the second line if there is no error; two lines is quite enough.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-08-29 16:02:26 +02:00
Miloslav Trmač b89c616b28 Log HTTP requests when getting bearer tokens
These were the only requests in c/image/docker which were not logged at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-08-29 16:02:21 +02:00
Flavio Castelli 93ebfa5951
docker client: fix requests made against bearer token services
Previous to this commit the requests made against a bearer token service
would be lacking the `author` field.
That causes the jwt token to have an empty `sub` (Subject) field. [1]

The docker registry relies on the `sub` field to know the author of all
the requests. When a registry is configured to send notifications [2]
the resulting webhooks calls will be missing the author too.

This commit fixes the issue by reproducing the same request made by
the docker client.

[1] https://docs.docker.com/registry/spec/auth/jwt/#getting-a-bearer-token
[2] https://docs.docker.com/registry/configuration/#notifications

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
2018-07-13 15:00:27 +02:00
umohnani8 42a0b320da Search was not looking for credentials in authfile
docker.SearchRegistry was not calling config.GetAuthentication
to get the credentials of a registry from the authfile.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-06-26 09:12:24 -04:00
Miloslav Trmač 8968eb0bc3 Remove a few unused context.context parameters from private functions
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-04-10 19:12:04 +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
Miloslav Trmač 4b8c98b829 Improve docker/* error messages
especially focus on those from client.HandleErrorResponse, which may
be very unhelpful, e.g. "unknown: Not Found".

In general, make sure the error includes an expanded Docker reference,
or a full URL, or a hostname + path.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-03-16 14:41:11 +01:00
umohnani8 bca26783cc Add /etc/containers/certs.d as default certs directory
Adding /etc/containers/certs.d as another default certs directory
The code will first check /etc/containers/certs.d for the certificates
and if not found at this path it will fall back to /etc/docker/certs.dir

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-02-05 12:23:07 -05:00
umohnani8 abca35a4dc Add functionality to search registries
podman search searches a registry for a matching image
this adds the functionality to support that
some registries respond to the v2 endpoint while others
only respond to the v1 endpoint.
This checks both endpoints for a result, and if none is given
the user is informed.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-02-01 10:19:07 -05:00
Tom Godkin c2b9a9b31a Make token parsing compatible with Docker's Token Authentication Specification
See: https://docs.docker.com/registry/spec/auth/token/

Signed-off-by: Ed King <eking@pivotal.io>
Signed-off-by: Will Martin <wmartin@pivotal.io>
Signed-off-by: Julia Nedialkova <julianedialkova@hotmail.com>
2018-01-18 17:28:26 +02:00
umohnani8 4ebdec8de4 Remove duplicate code for setupCertificates
Part of the fixes from #351 got undone

Signed-off-by: umohnani8 <umohnani@redhat.com>
2017-10-11 09:43:45 -04:00
umohnani8 f28367e1ae Add docker/config package to containers/image/pkg
This package is used in authenticating a user for kpod login
and can be used for authentication in kpod push, pull etc.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2017-10-09 21:56:49 -04:00
Tiago Scolari 1ed776ff52 Support for remote OCI layers if they have a URL
* Support for custom certs and keys when downloading OCI layers

Signed-off-by: Will Martin <wmartin@pivotal.io>
2017-10-03 13:40:56 +01:00
dlorenc 23a56b8b90 Add support for credential helpers.
Signed-off-by: dlorenc <lorenc.d@gmail.com>
2017-09-02 12:14:16 -07:00
Aleksa Sarai 17b0b92c72
docker: ignore EPERM when scanning for certificates
Ignore (but log) all permission errors when trying to get the list of
additionally trusted Docker certificates and keys. This should not
result in any security issues, because additional trusted certificates
are additive (and thus the only issue that can occur is that a transport
is not trusted by skopeo when it should be).

Not ignoring permission errors would cause issues when trying to perform
a copy of a Docker image on a machine that has Docker installed (by
default Docker makes /etc/docker/certs.d not accessible). This would
manifest itself like so:

  % ./skopeo copy docker://busybox oci:busybox
  FATA[0000] Error initializing source docker://busybox:latest: open /etc/docker/certs.d/docker.io: permission denied

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-08-25 16:56:57 +10:00
Mrunal Patel 8df46f076f Update and rename the import for logrus v1.0.0
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2017-08-04 10:00:13 -07:00
Michal Fojtik 1ef1350679
pass context.Context to signature retrieval http calls
Signed-off-by: Michal Fojtik <mfojtik@redhat.com>
2017-08-02 21:16:23 +02:00
Miloslav Trmač 1e26e839ab Log the unrecognized challenges if we don’t recognize any of them
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-07-18 20:57:37 +02:00
Antonio Murdaca 76e889c3de
docker: loop auth handlers instead of using just one
As already done docker-side at
https://github.com/moby/moby/blob/master/vendor/github.com/docker/distribution/registry/client/auth/session.go#L98

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-07-18 12:01:28 +02:00
Miloslav Trmač 07ee0424d6 Improve debug output on TLS configuration search
- Say what directory we are checking, even if it doesn't exist.
- Indent the search results to make it related to the directory
  declaration above, and similar to registries.d output:

> Looking for TLS certificates and private keys in /etc/docker/certs.d/registry.access.redhat.com
>  cert: /etc/docker/certs.d/FOO/BAR.cert
>  key: /etc/docker/certs.d/FOO/BAR.key
> Using registries.d directory /etc/containers/registries.d for sigstore configuration
>  Using "default-docker" configuration
>  No signature storage configuration found for FOO/BAZ:latest

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-05-27 23:19:35 +02:00
Miloslav Trmač 3aeae04bfd Add types.SystemContext.DockerPerHostCertDirPath, defaulting to /etc/docker/certs.d
This will make /etc/docker/certs.d/$host[:$port], notably RHEL CDN
certificates, work by default.

types.SystemContext.DockerCertPath, if defined, overrides and disables
DockerPerHostCertDirPath.  We now always look into _some_ (exactly one)
directory.  (This also forces us to explicitly override the default path
in tests because in Travis /etc/docker has mode 0700, causing spurious failures.)

(See also the added comment about handling docker.io in certs.d.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

i
2017-05-27 23:19:30 +02:00
Miloslav Trmač 4f587fa68a Split DockerCertDir determination logic into a separate function
This will make it easier to make the determination more complex without
affecting the consumer.

Also moves the 'certDir != ""' check out of setupCertificates.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-05-27 00:57:42 +02:00
Miloslav Trmač 0ae2be9a99 Always use serverDefault() for docker TLS configuration
Previously we would not use it if there was any other TLS configuration.

If the user specified certificates, this really does not make any sense
(there is no overlap between serverDeafult() and certificates).

If the user disabled TLS verification, skipping serverDefault() is a bit
more sensible (e.g. we may want to allow old ciphers because it doesn’t
matter anyway), but still suspect.  If this turns out to be a problem,
the DockerInsecureTLSSkipVerify case can revert the specific settings,
making the intention explicit.

This also nicely simplifies the code.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-05-27 00:57:42 +02:00
Miloslav Trmač 516cab7287 Be more explicit that setupCertificates does nothing if the dir does not exist
… instead of relying on ReadDir returning an empty list on failure.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-05-27 00:57:42 +02:00
Miloslav Trmač 6c17ca3479 Add support for the X-Registry-Supports-Signatures API extension
This is provided by the OpenShift-integrated registry. This is
equivalent to the atomic: transport (in the “openshift”) subpackage, but
it requires less code and notably does not require an OpenShift login
context to be configured.

See https://github.com/openshift/origin/pull/12504 and
https://github.com/openshift/openshift-docs/pull/3556 for more
information on this API extension.

To preserve compatibility, we always check for a configured lookaside
sigstore first; if that is set up, we use the lookaside and ignore the
registry-native signature storage.  Usually the user would not bother to
set up the lookaside, and use the native mechanism.

The code is mostly trivial; the only non-obvious aspect is the loop in
putSignaturesToAPIExtension, which is a pretty direct translation of
openshiftImageDestination.PutSignatures.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-03-29 21:42:19 +02:00
Miloslav Trmač 66329255ce Turn dockerClient.ping into dockerClient.detectProperties()
This only moves the client.scheme == "" check inside the method; but the
naming will make it more appropriate to call the method from
dockerImagesource / dockerImageDestination when they need to depend on
the results of the properties detection in methods which may be called
before dockerClient.makeRequest is ever called (detecting the properties
as a side effect).

Does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-03-29 21:42:19 +02:00
Miloslav Trmač de53270c6b Make the /v2/ prefix explicit in paths submitted to dockerClient.makeRequest
This will allow using paths starting with /extensions/v2/ in the future.

Also, we can now name the parameter “path” instead of the incorrect
“url”, and the “path” name actually matches (there is no magic
/v2/ adding involved).

Also eliminates duplication of the ping paths (in logging code only).

Does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-03-29 21:42:19 +02:00
Miloslav Trmač ecdd233c84 Copy github.com/docker/distribution/reference to docker/reference
This replaces the copy of github.com/docker/docker/reference in the same
place, which we have just gotten rid of, and allows using this package
even in consumers which insist on an incompatible version of
docker/distribution.

The copy has been edited to drop a reference to
github.com/docker/distribution/digestset .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:27 +01:00
Miloslav Trmač 8cde5543dd API transition: Drop XNamed.XRemoteName
Instead call distreference.Path() in all users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 2f8c595199 API transition: Drop XNamed.XHostname
Instead call distreference.Domain() in all users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač dda360d9ec API separation: Add an 'X' to all public names from c/i/docker/daemon/reference
This is an intermediate step which will eventually go away.

The goal of this PR is to get rid of c/i/docker/daemon/reference and to
replace uses of it by direct calls to docker/distribution/reference.

We can't do that safely and easily, because the two have different
semantics for reference.Named.Name() and reference.Named.String(): we
return a minimized version, e.g. "busybox", upstream returns an expanded
version, e.g. "docker.io/library/busybox".

BEFORE this commit the difference is hidden by using
docker/distribution/reference.WithName, which allows using the minimized
version, and works with it correctly; but because we want to use the
upstream canonicalization code, which will change semantics, we can't
just mix and match.

To make the distinction explicit, this commmit adds an X to ALL public
names from c/i/docker/daemon/reference.  E.g. a reference.XNamed type,
which has methods XName and XString.

This is pretty large, but does not change behavior at all.  By
inspection it is clear to see that reference.XNamed and subtypes does
not expose any of the non-X, conflicting, method names.

Using e.g.
> git diff --word-diff-regex=.|grep -F '{+'|grep -v '^\([^{]\|{+X+}\)*{\?$'
it is possible to see that most lines in this diff only add a single X
letter, and manually inspect the few lines which don't match the regexp.

The only REALLY new code is an explicit definition of namedRef.XName()
and namedRef.XString(), and two newly added casts to namedRef in cases
where we need to use the underlying distreference.Reference within
a reference.XNamed value.  Strictly speaking these changes change
behavior, in that third-party implementations of reference.XNamed are no
longer accepted; but we broke them by renaming at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:24:14 +01:00
Antonio Murdaca 17b50ed9a1
docker: cache bearer tokens
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-02-02 15:33:10 +01:00
Antonio Murdaca 35b00eb317
docker: mimic docker upstream registry authentication
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-01-29 19:35:30 +01:00
Antonio Murdaca 15f6d414bf
docker: fix unauthenticated pulls from gcr.io
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-01-04 19:23:02 +01:00
Antonio Murdaca be41c3d075
docker: set basic auth when requesting bearer token
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-22 17:01:36 +01:00
George Lestaris bda6e4b37f Replace fmt.Errorf with pkg/errors.Wrap
Signed-off-by: George Lestaris <glestaris@pivotal.io>
2016-12-19 14:13:16 +00:00
Nalin Dahyabhai 346966324a Add support for containers/storage
Add containers/storage as a backend type called 'storage'.

The image's blobs are stored either as storage layers (if they look like
archived layers) or (alongside the manifest and signatures) as named big
data items associated with the image.

Inspection data and record-keeping (so that we can remember which blobs
were layers and which weren't) are encoded as a JSON object which is
stored in the storage image's metadata field.

When importing blobs, layer IDs are generated by concatenating the
parent's layer ID (if there is one) with the hex string representation
of the expected digest of the content blob, if one is known.  If there
is no expected digest, the ID is randomly generated.

If we find ourselves importing a layer with the same ID as a layer that
we already have, we digest the incoming stream and compare it to the
cached digest of the already-present layer, and return an error only if
they don't match.  If an expected blob digest is provided, the actual
digest of the blob is compared with it, and if they don't match, an
error is returned.

If we find ourselves importing a blob more than once, we track the IDs
of each of the resulting layers.

If we find ourselves importing an image that wants to be tagged with a
name that is already in use, the name is then assigned to the new image
and the old image remains otherwise unmodified.  If that incoming image
claims to have the same ID as an image which we already have, the import
will fail.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2016-12-13 12:19:39 -05:00
Antonio Murdaca 44e8fda675
docker: check if ctx is nil
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-11 17:05:47 +01:00
Antonio Murdaca 4cf1e88d2e
docker: use registry and system CAs
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-08 17:26:00 +01:00
Antonio Murdaca 0d6c06f076
docker: add an option to disable V1 ping
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-06 17:49:33 +01:00
Antonio Murdaca c341304dc9
docker: remove silly error checks
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-01 22:58:08 +01:00
Antonio Murdaca f8f5e9d946
docker: useful ping error message
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-12-01 18:35:56 +01:00
Antonio Murdaca d54f1156b2
*: support layers federation
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-11-30 18:54:56 +01:00
Antonio Murdaca d03be893fc
docker: cleanup old comment
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-11-25 15:07:00 +01:00
Antonio Murdaca bcaf09226a
docker: set proxy from env for custom transport
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-11-10 17:09:20 +01:00
Antonio Murdaca 20b348e3ba
types: add DockerRegistryUserAgent to SystemContext
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-11 17:33:28 +02:00
Antonio Murdaca 98d6c0073a
types,docker: add DockerAuthConfig
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-07 17:06:19 +02:00
Michal Minář d30079fd26
Be benevolent to .docker/config.json file
Docker can store auth entries with schema prefix or even path suffix.
See an example:

    {
        "auths": {
            "10.3.10.88:5000": {
                ...
            },
            "http://10.3.10.88:5000/v2/": {
                ...
            },
            "https://10.3.10.88:5000": {
                ...
            },
            "https://index.docker.io/v1/": {
                ...
            }
        }
    }

The entries were created using command `docker login` of upstream Docker
1.12. Let's normalize the auth keys before trying to match against
hostname.

Signed-off-by: Michal Minář <miminar@redhat.com>
2016-10-06 15:05:54 +02:00
Miloslav Trmač b62ab85d1e Fix dockerClient use with nil SystemContext
This does not manifest with skopeo because skopeo usually uses
contextFromGlobalOptions() which is never nil, but it still is a
violation of the documented API (and breaks the copy-lookalike I use for
quick debugging).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-26 19:26:45 +02:00
Antonio Murdaca 28702179a0
docker: remove client's timeout
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-09-22 17:57:40 +02:00
Miloslav Trmač 9b3678b5f3 Do not use HTTP for docker registries if ~SystemContext.DockerInsecureSkipTLSVerify
Then document SystemContext.DockerInsecureSkipTLSVerify more precisely.

Also simplify dockerClient.ping() a bit.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-13 18:42:01 +02:00
Miloslav Trmač aaedc64236 Implement lookaside storage for signatures for Docker registries
Allows configuring "sigstore" (for RW) and "sigstore-write" (write-only)
for images/repositories/namespaces/registries in
/etc/containers/repositories.d/*.yaml .

If configured, uses them to store signatures in the docker: transport.

Also includes documentation in docs/registries.d.md.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-12 17:51:26 +02:00
Miloslav Trmač 557dc5d86d Add an expectedSize parameter to PutBlob
Submit this size in docker: destinations, validate it in dir: and oci:.

Preserve the size, if provided by ImageSource, when copying blobs.

Also document that PutBlob must be called before PutManifest and
PutSignatures; this is clearly the necessary ordering if the layer
tarballs are being generated on the fly, or if the manifest destination
wants to reject manifests referring to nonexistent blobs.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-05 22:47:03 +02:00
Miloslav Trmač 8ad0cad4ea Use types.SystemContext in NewImage*
... instead of Docker-specific certPath and tlsVerify.

Also invert the sense of tlsVerify to make the default secure.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-31 21:13:31 +02:00
Miloslav Trmač d75099ff80 Fix Bearer authentication
* Do not consume the Body stream
* Use something closer to a real parser for WWW-Authenticate,
  notably allowing a comman in the "scope" value.
* Allow missing "service" and "scope" parameters, they are not used by
  OpenShift

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-29 17:19:39 +02:00
Antonio Murdaca 940280f647
docker,openshift: create http.Client with Timeout
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-07-18 17:02:01 +02:00
Miloslav Trmač fc761ed74f Fix uploading layer blobs to Docker registry
Implement a client to the chunked API, instead of the nonexistent
one-shot API (per
2a4deee441
).

Adds a FIXME to DELETE the pending upload on failure; the uploads are
supposed to time out so this is not immediately critical.

Fixes #64 .
2016-06-06 23:00:58 +02:00
Antonio Murdaca c661fad3eb provide a way to pass multi values-signle key headers
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-05-18 17:02:53 +02:00
Miloslav Trmač f526328b30 Move directory, docker and openshift from cmd/skopeo to their own subpackages
Does not change behavior.  This is a straightforward move and update of
package references, except for:

- Adding a duplicate definition of manifestSchema1 to
  cmd/skopeo/copy.go.  This will need to be cleaned up later, for now
  preferring to make no design changes in this commit.
- Renaming parseDockerImage to NewDockerImage, to both make it public
  and consistent with common golang conventions.
2016-05-16 18:32:32 +02:00