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