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