Commit Graph

187 Commits

Author SHA1 Message Date
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