45fa0f8
% CONTAINERS-POLICY.JSON(5) policy.json Man Page
159f87d
% Miloslav Trmač
159f87d
% September 2016
159f87d
159f87d
# NAME
45fa0f8
containers-policy.json - syntax for the signature verification policy file
159f87d
159f87d
## DESCRIPTION
159f87d
159f87d
Signature verification policy files are used to specify policy, e.g. trusted keys,
159f87d
applicable when deciding whether to accept an image, or individual signatures of that image, as valid.
159f87d
159f87d
The default policy is stored (unless overridden at compile-time) at `/etc/containers/policy.json`;
159f87d
applications performing verification may allow using a different policy instead.
159f87d
159f87d
## FORMAT
159f87d
159f87d
The signature verification policy file, usually called `policy.json`,
159f87d
uses a JSON format.  Unlike some other JSON files, its parsing is fairly strict:
159f87d
unrecognized, duplicated or otherwise invalid fields cause the entire file,
159f87d
and usually the entire operation, to be rejected.
159f87d
159f87d
The purpose of the policy file is to define a set of *policy requirements* for a container image,
159f87d
usually depending on its location (where it is being pulled from) or otherwise defined identity.
159f87d
159f87d
Policy requirements can be defined for:
159f87d
159f87d
- An individual *scope* in a *transport*.
159f87d
  The *transport* values are the same as the transport prefixes when pushing/pulling images (e.g. `docker:`, `atomic:`),
159f87d
  and *scope* values are defined by each transport; see below for more details.
159f87d
159f87d
  Usually, a scope can be defined to match a single image, and various prefixes of
159f87d
  such a most specific scope define namespaces of matching images.
159f87d
- A default policy for a single transport, expressed using an empty string as a scope
159f87d
- A global default policy.
159f87d
159f87d
If multiple policy requirements match a given image, only the requirements from the most specific match apply,
159f87d
the more general policy requirements definitions are ignored.
159f87d
159f87d
This is expressed in JSON using the top-level syntax
159f87d
```js
159f87d
{
159f87d
    "default": [/* policy requirements: global default */]
159f87d
    "transports": {
159f87d
        transport_name: {
159f87d
            "": [/* policy requirements: default for transport $transport_name */],
159f87d
            scope_1: [/* policy requirements: default for $scope_1 in $transport_name */],
159f87d
            scope_2: [/*…*/]
159f87d
            /*…*/
159f87d
        },
159f87d
        transport_name_2: {/*…*/}
159f87d
        /*…*/
159f87d
    }
159f87d
}
159f87d
```
159f87d
159f87d
The global `default` set of policy requirements is mandatory; all of the other fields
159f87d
(`transports` itself, any specific transport, the transport-specific default, etc.) are optional.
159f87d
159f87d
159f87d
## Supported transports and their scopes
159f87d
159f87d
### `atomic:`
159f87d
159f87d
The `atomic:` transport refers to images in an Atomic Registry.
159f87d
159f87d
Supported scopes use the form _hostname_[`:`_port_][`/`_namespace_[`/`_imagestream_ [`:`_tag_]]],
159f87d
i.e. either specifying a complete name of a tagged image, or prefix denoting
159f87d
a host/namespace/image stream.
159f87d
159f87d
*Note:* The _hostname_ and _port_ refer to the Docker registry host and port (the one used
159f87d
e.g. for `docker pull`), _not_ to the OpenShift API host and port.
159f87d
159f87d
### `dir:`
159f87d
159f87d
The `dir:` transport refers to images stored in local directories.
159f87d
159f87d
Supported scopes are paths of directories (either containing a single image or
159f87d
subdirectories possibly containing images).
159f87d
159f87d
*Note:* The paths must be absolute and contain no symlinks. Paths violating these requirements may be silently ignored.
159f87d
159f87d
The top-level scope `"/"` is forbidden; use the transport default scope `""`,
159f87d
for consistency with other transports.
159f87d
159f87d
### `docker:`
159f87d
159f87d
The `docker:` transport refers to images in a registry implementing the "Docker Registry HTTP API V2".
159f87d
159f87d
Scopes matching individual images are named Docker references *in the fully expanded form*, either
159f87d
using a tag or digest. For example, `docker.io/library/busybox:latest` (*not* `busybox:latest`).
159f87d
159f87d
More general scopes are prefixes of individual-image scopes, and specify a repository (by omitting the tag or digest),
159f87d
a repository namespace, or a registry host (by only specifying the host name).
159f87d
159f87d
### `oci:`
159f87d
159f87d
The `oci:` transport refers to images in directories compliant with "Open Container Image Layout Specification".
159f87d
159f87d
Supported scopes use the form _directory_`:`_tag_, and _directory_ referring to
159f87d
a directory containing one or more tags, or any of the parent directories.
159f87d
159f87d
*Note:* See `dir:` above for semantics and restrictions on the directory paths, they apply to `oci:` equivalently.
159f87d
159f87d
### `tarball:`
159f87d
159f87d
The `tarball:` transport refers to tarred up container root filesystems.
159f87d
159f87d
Scopes are ignored.
159f87d
159f87d
## Policy Requirements
159f87d
159f87d
Using the mechanisms above, a set of policy requirements is looked up.  The policy requirements
159f87d
are represented as a JSON array of individual requirement objects.  For an image to be accepted,
159f87d
*all* of the requirements must be satisfied simulatenously.
159f87d
159f87d
The policy requirements can also be used to decide whether an individual signature is accepted (= is signed by a recognized key of a known author);
159f87d
in that case some requirements may apply only to some signatures, but each signature must be accepted by *at least one* requirement object.
159f87d
159f87d
The following requirement objects are supported:
159f87d
159f87d
### `insecureAcceptAnything`
159f87d
159f87d
A simple requirement with the following syntax
159f87d
159f87d
```json
159f87d
{"type":"insecureAcceptAnything"}
159f87d
```
159f87d
159f87d
This requirement accepts any image (but note that other requirements in the array still apply).
159f87d
159f87d
When deciding to accept an individual signature, this requirement does not have any effect; it does *not* cause the signature to be accepted, though.
159f87d
159f87d
This is useful primarily for policy scopes where no signature verification is required;
159f87d
because the array of policy requirements must not be empty, this requirement is used
159f87d
to represent the lack of requirements explicitly.
159f87d
159f87d
### `reject`
159f87d
159f87d
A simple requirement with the following syntax:
159f87d
159f87d
```json
159f87d
{"type":"reject"}
159f87d
```
159f87d
159f87d
This requirement rejects every image, and every signature.
159f87d
159f87d
### `signedBy`
159f87d
159f87d
This requirement requires an image to be signed with an expected identity, or accepts a signature if it is using an expected identity and key.
159f87d
159f87d
```js
159f87d
{
159f87d
    "type":    "signedBy",
159f87d
    "keyType": "GPGKeys", /* The only currently supported value */
159f87d
    "keyPath": "/path/to/local/keyring/file",
159f87d
    "keyData": "base64-encoded-keyring-data",
159f87d
    "signedIdentity": identity_requirement
159f87d
}
159f87d
```
159f87d
159f87d
159f87d
Exactly one of `keyPath` and `keyData` must be present, containing a GPG keyring of one or more public keys.  Only signatures made by these keys are accepted.
159f87d
159f87d
The `signedIdentity` field, a JSON object, specifies what image identity the signature claims about the image.
159f87d
One of the following alternatives are supported:
159f87d
159f87d
- The identity in the signature must exactly match the image identity.  Note that with this, referencing an image by digest (with a signature claiming a _repository_`:`_tag_ identity) will fail.
159f87d
159f87d
  ```json
159f87d
  {"type":"matchExact"}
159f87d
  ```
159f87d
- If the image identity carries a tag, the identity in the signature must exactly match;
159f87d
  if the image identity uses a digest reference, the identity in the signature must be in the same repository as the image identity (using any tag).
159f87d
159f87d
  (Note that with images identified using digest references, the digest from the reference is validated even before signature verification starts.)
159f87d
159f87d
  ```json
159f87d
  {"type":"matchRepoDigestOrExact"}
159f87d
  ```
159f87d
- The identity in the signature must be in the same repository as the image identity.  This is useful e.g. to pull an image using the `:latest` tag when the image is signed with a tag specifing an exact image version.
159f87d
159f87d
  ```json
159f87d
  {"type":"matchRepository"}
159f87d
  ```
159f87d
- The identity in the signature must exactly match a specified identity.
159f87d
  This is useful e.g. when locally mirroring images signed using their public identity.
159f87d
159f87d
  ```js
159f87d
  {
159f87d
      "type": "exactReference",
159f87d
      "dockerReference": docker_reference_value
159f87d
  }
159f87d
  ```
159f87d
- The identity in the signature must be in the same repository as a specified identity.
159f87d
  This combines the properties of `matchRepository` and `exactReference`.
159f87d
159f87d
  ```js
159f87d
  {
159f87d
      "type": "exactRepository",
159f87d
      "dockerRepository": docker_repository_value
159f87d
  }
159f87d
  ```
159f87d
159f87d
If the `signedIdentity` field is missing, it is treated as `matchRepoDigestOrExact`.
159f87d
159f87d
*Note*: `matchExact`, `matchRepoDigestOrExact` and `matchRepository` can be only used if a Docker-like image identity is
159f87d
provided by the transport.  In particular, the `dir:` and `oci:` transports can be only
159f87d
used with `exactReference` or `exactRepository`.
159f87d
159f87d
159f87d
159f87d
## Examples
159f87d
159f87d
It is *strongly* recommended to set the `default` policy to `reject`, and then
159f87d
selectively allow individual transports and scopes as desired.
159f87d
159f87d
### A reasonably locked-down system
159f87d
159f87d
(Note that the `/*`…`*/` comments are not valid in JSON, and must not be used in real policies.)
159f87d
159f87d
```js
159f87d
{
159f87d
    "default": [{"type": "reject"}], /* Reject anything not explicitly allowed */
159f87d
    "transports": {
159f87d
        "docker": {
159f87d
            /* Allow installing images from a specific repository namespace, without cryptographic verification.
159f87d
               This namespace includes images like openshift/hello-openshift and openshift/origin. */
159f87d
            "docker.io/openshift": [{"type": "insecureAcceptAnything"}],
159f87d
            /* Similarly, allow installing the “official” busybox images.  Note how the fully expanded
159f87d
               form, with the explicit /library/, must be used. */
159f87d
            "docker.io/library/busybox": [{"type": "insecureAcceptAnything"}]
159f87d
            /* Other docker: images use the global default policy and are rejected */
159f87d
        },
159f87d
        "dir": {
159f87d
            "": [{"type": "insecureAcceptAnything"}] /* Allow any images originating in local directories */
159f87d
        },
159f87d
        "atomic": {
159f87d
            /* The common case: using a known key for a repository or set of repositories */
159f87d
            "hostname:5000/myns/official": [
159f87d
                {
159f87d
                    "type": "signedBy",
159f87d
                    "keyType": "GPGKeys",
159f87d
                    "keyPath": "/path/to/official-pubkey.gpg"
159f87d
                }
159f87d
            ],
159f87d
            /* A more complex example, for a repository which contains a mirror of a third-party product,
159f87d
               which must be signed-off by local IT */
159f87d
            "hostname:5000/vendor/product": [
159f87d
                { /* Require the image to be signed by the original vendor, using the vendor's repository location. */
159f87d
                    "type": "signedBy",
159f87d
                    "keyType": "GPGKeys",
159f87d
                    "keyPath": "/path/to/vendor-pubkey.gpg",
159f87d
                    "signedIdentity": {
159f87d
                        "type": "exactRepository",
159f87d
                        "dockerRepository": "vendor-hostname/product/repository"
159f87d
                    }
159f87d
                },
159f87d
                { /* Require the image to _also_ be signed by a local reviewer. */
159f87d
                    "type": "signedBy",
159f87d
                    "keyType": "GPGKeys",
159f87d
                    "keyPath": "/path/to/reviewer-pubkey.gpg"
159f87d
                }
159f87d
            ]
159f87d
        }
159f87d
    }
159f87d
}
159f87d
```
159f87d
159f87d
### Completely disable security, allow all images, do not trust any signatures
159f87d
159f87d
```json
159f87d
{
159f87d
    "default": [{"type": "insecureAcceptAnything"}]
159f87d
}
159f87d
```
7c8484c
## SEE ALSO
159f87d
  atomic(1)
159f87d
7c8484c
## HISTORY
45fa0f8
August 2018, Rename to containers-policy.json(5) by Valentin Rothberg <vrothberg@suse.com>
45fa0f8
159f87d
September 2016, Originally compiled by Miloslav Trmač <mitr@redhat.com>