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