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