ab079c
% container-signature(5) Container signature format
ab079c
% Miloslav Trmač
ab079c
% March 2017
ab079c
ab079c
# Container signature format
ab079c
ab079c
This document describes the format of container signatures,
ab079c
as implemented by the `github.com/containers/image/signature` package.
ab079c
ab079c
Most users should be able to consume these signatures by using the `github.com/containers/image/signature` package
ab079c
(preferably through the higher-level `signature.PolicyContext` interface)
ab079c
without having to care about the details of the format described below.
ab079c
This documentation exists primarily for maintainers of the package
ab079c
and to allow independent reimplementations.
ab079c
ab079c
## High-level overview
ab079c
ab079c
The signature provides an end-to-end authenticated claim that a container image
ab079c
has been approved by a specific party (e.g. the creator of the image as their work,
ab079c
an automated build system as a result of an automated build,
ab079c
a company IT department approving the image for production) under a specified _identity_
ab079c
(e.g. an OS base image / specific application, with a specific version).
ab079c
ab079c
A container signature consists of a cryptographic signature which identifies
ab079c
and authenticates who signed the image, and carries as a signed payload a JSON document.
ab079c
The JSON document identifies the image being signed, claims a specific identity of the
ab079c
image and if applicable, contains other information about the image.
ab079c
ab079c
The signatures do not modify the container image (the layers, configuration, manifest, …);
ab079c
e.g. their presence does not change the manifest digest used to identify the image in
ab079c
docker/distribution servers; rather, the signatures are associated with an immutable image.
ab079c
An image can have any number of signatures so signature distribution systems SHOULD support
ab079c
associating more than one signature with an image.
ab079c
ab079c
## The cryptographic signature
ab079c
ab079c
As distributed, the container signature is a blob which contains a cryptographic signature
ab079c
in an industry-standard format, carrying a signed JSON payload (i.e. the blob contains both the
ab079c
JSON document and a signature of the JSON document; it is not a “detached signature” with
ab079c
independent blobs containing the JSON document and a cryptographic signature).
ab079c
ab079c
Currently the only defined cryptographic signature format is an OpenPGP signature (RFC 4880),
ab079c
but others may be added in the future.  (The blob does not contain metadata identifying the
ab079c
cryptographic signature format. It is expected that most formats are sufficiently self-describing
ab079c
that this is not necessary and the configured expected public key provides another indication
ab079c
of the expected cryptographic signature format. Such metadata may be added in the future for
ab079c
newly added cryptographic signature formats, if necessary.)
ab079c
ab079c
Consumers of container signatures SHOULD verify the cryptographic signature
ab079c
against one or more trusted public keys
ab079c
(e.g. defined in a [policy.json signature verification policy file](policy.json.md))
ab079c
before parsing or processing the JSON payload in _any_ way,
ab079c
in particular they SHOULD stop processing the container signature
ab079c
if the cryptographic signature verification fails, without even starting to process the JSON payload.
ab079c
ab079c
(Consumers MAY extract identification of the signing key and other metadata from the cryptographic signature,
ab079c
and the JSON payload, without verifying the signature, if the purpose is to allow managing the signature blobs,
ab079c
e.g. to list the authors and image identities of signatures associated with a single container image;
ab079c
if so, they SHOULD design the output of such processing to minimize the risk of users considering the output trusted
ab079c
or in any way usable for making policy decisions about the image.)
ab079c
ab079c
### OpenPGP signature verification
ab079c
ab079c
When verifying a cryptographic signature in the OpenPGP format,
ab079c
the consumer MUST verify at least the following aspects of the signature
ab079c
(like the `github.com/containers/image/signature` package does):
ab079c
ab079c
- The blob MUST be a “Signed Message” as defined RFC 4880 section 11.3.
ab079c
  (e.g. it MUST NOT be an unsigned “Literal Message”, or any other non-signature format).
ab079c
- The signature MUST have been made by an expected key trusted for the purpose (and the specific container image).
ab079c
- The signature MUST be correctly formed and pass the cryptographic validation.
ab079c
- The signature MUST correctly authenticate the included JSON payload
ab079c
  (in particular, the parsing of the JSON payload MUST NOT start before the complete payload has been cryptographically authenticated).
ab079c
- The signature MUST NOT be expired.
ab079c
ab079c
The consumer SHOULD have tests for its verification code which verify that signatures failing any of the above are rejected.
ab079c
ab079c
## JSON processing and forward compatibility
ab079c
ab079c
The payload of the cryptographic signature is a JSON document (RFC 7159).
ab079c
Consumers SHOULD parse it very strictly,
ab079c
refusing any signature which violates the expected format (e.g. missing members, incorrect member types)
ab079c
or can be interpreted ambiguously (e.g. a duplicated member in a JSON object).
ab079c
ab079c
Any violations of the JSON format or of other requirements in this document MAY be accepted if the JSON document can be recognized
ab079c
to have been created by a known-incorrect implementation (see [`optional.creator`](#optionalcreator) below)
ab079c
and if the semantics of the invalid document, as created by such an implementation, is clear.
ab079c
ab079c
The top-level value of the JSON document MUST be a JSON object with exactly two members, `critical` and `optional`,
ab079c
each a JSON object.
ab079c
ab079c
The `critical` object MUST contain a `type` member identifying the document as a container signature
ab079c
(as defined [below](#criticaltype))
ab079c
and signature consumers MUST reject signatures which do not have this member or in which this member does not have the expected value.
ab079c
ab079c
To ensure forward compatibility (allowing older signature consumers to correctly
ab079c
accept or reject signatures created at a later date, with possible extensions to this format),
ab079c
consumers MUST reject the signature if the `critical` object, or _any_ of its subobjects,
ab079c
contain _any_ member or data value which is unrecognized, unsupported, invalid, or in any other way unexpected.
ab079c
At a minimum, this includes unrecognized members in a JSON object, or incorrect types of expected members.
ab079c
ab079c
For the same reason, consumers SHOULD accept any members with unrecognized names in the `optional` object,
ab079c
and MAY accept signatures where the object member is recognized but unsupported, or the value of the member is unsupported.
ab079c
Consumers still SHOULD reject signatures where a member of an `optional` object is supported but the value is recognized as invalid.
ab079c
ab079c
## JSON data format
ab079c
ab079c
An example of the full format follows, with detailed description below.
ab079c
To reiterate, consumers of the signature SHOULD perform successful cryptographic verification,
ab079c
and MUST reject unexpected data in the `critical` object, or in the top-level object, as described above.
ab079c
ab079c
```json
ab079c
{
ab079c
    "critical": {
ab079c
        "type": "atomic container signature",
ab079c
        "image": {
ab079c
            "docker-manifest-digest": "sha256:817a12c32a39bbe394944ba49de563e085f1d3c5266eb8e9723256bc4448680e"
ab079c
        },
ab079c
        "identity": {
ab079c
            "docker-reference": "docker.io/library/busybox:latest"
ab079c
        }
ab079c
    },
ab079c
    "optional": {
ab079c
        "creator": "some software package v1.0.1-35",
ab079c
        "timestamp": 1483228800,
ab079c
    }
ab079c
}
ab079c
```
ab079c
ab079c
### `critical`
ab079c
ab079c
This MUST be a JSON object which contains data critical to correctly evaluating the validity of a signature.
ab079c
ab079c
Consumers MUST reject any signature where the `critical` object contains any unrecognized, unsupported, invalid or in any other way unexpected member or data.
ab079c
ab079c
### `critical.type`
ab079c
ab079c
This MUST be a string with a string value exactly equal to `atomic container signature` (three words, including the spaces).
ab079c
ab079c
Signature consumers MUST reject signatures which do not have this member or this member does not have exactly the expected value.
ab079c
ab079c
(The consumers MAY support signatures with a different value of the `type` member, if any is defined in the future;
ab079c
if so, the rest of the JSON document is interpreted according to rules defining that value of `critical.type`,
ab079c
not by this document.)
ab079c
ab079c
### `critical.image`
ab079c
ab079c
This MUST be a JSON object which identifies the container image this signature applies to.
ab079c
ab079c
Consumers MUST reject any signature where the `critical.image` object contains any unrecognized, unsupported, invalid or in any other way unexpected member or data.
ab079c
ab079c
(Currently only the `docker-manifest-digest` way of identifying a container image is defined;
ab079c
alternatives to this may be defined in the future,
ab079c
but existing consumers are required to reject signatures which use formats they do not support.)
ab079c
ab079c
### `critical.image.docker-manifest-digest`
ab079c
ab079c
This MUST be a JSON string, in the `github.com/opencontainers/go-digest.Digest` string format.
ab079c
ab079c
The value of this member MUST match the manifest of the signed container image, as implemented in the docker/distribution manifest addressing system.
ab079c
ab079c
The consumer of the signature SHOULD verify the manifest digest against a fully verified signature before processing the contents of the image manifest in any other way
ab079c
(e.g. parsing the manifest further or downloading layers of the image).
ab079c
ab079c
Implementation notes:
ab079c
* A single container image manifest may have several valid manifest digest values, using different algorithms.
ab079c
* For “signed” [docker/distribution schema 1](https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md) manifests,
ab079c
the manifest digest applies to the payload of the JSON web signature, not to the raw manifest blob.
ab079c
ab079c
### `critical.identity`
ab079c
ab079c
This MUST be a JSON object which identifies the claimed identity of the image (usually the purpose of the image, or the application, along with a version information),
ab079c
as asserted by the author of the signature.
ab079c
ab079c
Consumers MUST reject any signature where the `critical.identity` object contains any unrecognized, unsupported, invalid or in any other way unexpected member or data.
ab079c
ab079c
(Currently only the `docker-reference` way of claiming an image identity/purpose is defined;
ab079c
alternatives to this may be defined in the future,
ab079c
but existing consumers are required to reject signatures which use formats they do not support.)
ab079c
ab079c
### `critical.identity.docker-reference`
ab079c
ab079c
This MUST be a JSON string, in the `github.com/docker/distribution/reference` string format,
ab079c
and using the same normalization semantics (where e.g. `busybox:latest` is equivalent to `docker.io/library/busybox:latest`).
ab079c
If the normalization semantics allows multiple string representations of the claimed identity with equivalent meaning,
ab079c
the `critical.identity.docker-reference` member SHOULD use the fully explicit form (including the full host name and namespaces).
ab079c
ab079c
The value of this member MUST match the image identity/purpose expected by the consumer of the image signature and the image
ab079c
(again, accounting for the `docker/distribution/reference` normalization semantics).
ab079c
ab079c
In the most common case, this means that the `critical.identity.docker-reference` value must be equal to the docker/distribution reference used to refer to or download the image.
ab079c
However, depending on the specific application, users or system administrators may accept less specific matches
ab079c
(e.g. ignoring the tag value in the signature when pulling the `:latest` tag or when referencing an image by digest),
ab079c
or they may require `critical.identity.docker-reference` values with a completely different namespace to the reference used to refer to/download the image
ab079c
(e.g. requiring a `critical.identity.docker-reference` value which identifies the image as coming from a supplier when fetching it from a company-internal mirror of approved images).
ab079c
The software performing this verification SHOULD allow the users to define such a policy using the [policy.json signature verification policy file format](policy.json.md).
ab079c
ab079c
The `critical.identity.docker-reference` value SHOULD contain either a tag or digest;
ab079c
in most cases, it SHOULD use a tag rather than a digest.  (See also the default [`matchRepoDigestOrExact` matching semantics in `policy.json`](policy.json.md#signedby).)
ab079c
ab079c
### `optional`
ab079c
ab079c
This MUST be a JSON object.
ab079c
ab079c
Consumers SHOULD accept any members with unrecognized names in the `optional` object,
ab079c
and MAY accept a signature where the object member is recognized but unsupported, or the value of the member is valid but unsupported.
ab079c
Consumers still SHOULD reject any signature where a member of an `optional` object is supported but the value is recognized as invalid.
ab079c
ab079c
### `optional.creator`
ab079c
ab079c
If present, this MUST be a JSON string, identifying the name and version of the software which has created the signature.
ab079c
ab079c
The contents of this string is not defined in detail; however each implementation creating container signatures:
ab079c
ab079c
- SHOULD define the contents to unambiguously define the software in practice (e.g. it SHOULD contain the name of the software, not only the version number)
ab079c
- SHOULD use a build and versioning process which ensures that the contents of this string (e.g. an included version number)
ab079c
  changes whenever the format or semantics of the generated signature changes in any way;
ab079c
  it SHOULD not be possible for two implementations which use a different format or semantics to have the same `optional.creator` value
ab079c
- SHOULD use a format which is reasonably easy to parse in software (perhaps using a regexp),
ab079c
  and which makes it easy enough to recognize a range of versions of a specific implementation
ab079c
  (e.g. the version of the implementation SHOULD NOT be only a git hash, because they don’t have an easily defined ordering;
ab079c
  the string should contain a version number, or at least a date of the commit).
ab079c
ab079c
Consumers of container signatures MAY recognize specific values or sets of values of `optional.creator`
ab079c
(perhaps augmented with `optional.timestamp`),
ab079c
and MAY change their processing of the signature based on these values
ab079c
(usually to acommodate violations of this specification in past versions of the signing software which cannot be fixed retroactively),
ab079c
as long as the semantics of the invalid document, as created by such an implementation, is clear.
ab079c
ab079c
If consumers of signatures do change their behavior based on the `optional.creator` value,
ab079c
they SHOULD take care that the way they process the signatures is not inconsistent with
ab079c
strictly validating signature consumers.
ab079c
(I.e. it is acceptable for a consumer to accept a signature based on a specific `optional.creator` value
ab079c
if other implementations would completely reject the signature,
ab079c
but it would be very undesirable for the two kinds of implementations to accept the signature in different
ab079c
and inconsistent situations.)
ab079c
ab079c
### `optional.timestamp`
ab079c
ab079c
If present, this MUST be a JSON number, which is representable as a 64-bit integer, and identifies the time when the signature was created
ab079c
as the number of seconds since the UNIX epoch (Jan 1 1970 00:00 UTC).