owned this note
owned this note
Published
Linked with GitHub
---
title: Container signing/verification support
tags: Container plugin
---
# Container signing/verification support
- #### Container signing and verification EPIC https://pulp.plan.io/issues/9502
## Container Signature usecases (Treat signature as a content in pulp)
### Signature sync https://pulp.plan.io/issues/9507
**(MVP)** As a user I want to sync containers with its original signatures
* from sigstore
* **from extentions API**
**(MVP)** As a user on re-sync I want to sync new signatures
### Signature removal https://pulp.plan.io/issues/9512
**(MVP)** As a user, I have signatures garbage collected with manifest deletion(from pulp)
**(MVP)** As a user when I remove manifest from a repo its signatures are removed as well https://pulp.plan.io/issues/9582
### Content signing https://pulp.plan.io/issues/9509
As a user I want to sign content:
- **What is the criteria?**
- **(MVP)** per repo: sign every manifest in this repo (signing service has a relation to a repo) and add those signatures to the repo
- POST /v3/repositories/container/container/<id>/sign/
- **(MVP)** per content/list of content in the repo - sign specific content from this repo (signing service has a relation to a repo) and add signature(s) to it
- POST /v3/repositories/container/container/<id>/sign/ list_of_content_hrefs=[]
- *per content/list of content in pulp - sign specific content and create signature for it. Signature will not be part of any repo, it can be deleted from pulp since it is an orphan. Signature can be added to a repo.Does this usecase make sense?*
- *POST /v3/content/container/manifest/<manifest-id>/sign/ signing_service_href*
### Signature invalidation - https://pulp.plan.io/issues/9557
As a user I want to invalidate(remove from repo) existing signatures:
- API TBD
- **What is the criteria?**
- **(MVP) invalidate per key**(due to the key rotation, key leakage): find all content that was signed with this key, lock on the repos that has this content, remove signatures, create new repo-versions
- add a field on signature model that contains info about the key(fingerprint) or signing service?
- https://en.wikipedia.org/wiki/Certificate_revocation_list /OCSP protocol TODO read more on this
- **per repo**: lock on the repo, remove all signatures from repo, create new repo-version
- **per content in repo**: lock on the repo, remove the content signatures from repo, create new repo-version
- **per content in pulp** - find all repos it is present in, lock repos, remove signatures, create new repo-versions. **Does this usecase make sense?**
### Signature import/export - https://pulp.plan.io/issues/9558
**(MVP)** As a user, I have my signatures imported/exported together with the content
- will work out of the box, just add new signature content entry to the modelresources list( valid for synced repos only)
### Signature push/pull via Container Registry API
**(MVP)** As a user, I can push(create) signature via docker api extentions https://pulp.plan.io/issues/9511
:::info
Note that container/image(library) code checks for manifest exitense first i.e signature cannot exist without manifest
:::
```bash
$ curl -X PUT --data @signature.json http://<registry_endpoint>:24817/extensions/v2/<namespace>/<repo-name>/signatures/<imagesha256digest>
cat signature.json
{
"version": 2,
"type": "atomic",
"name": "sha256:4028782c08eae4a8c9a28bf661c0a8d1c2fc8e19dbaae2b018b21011197e1484@cddeb7006d914716e2728000746a0b23",
"content": "<base64 encoded signature>",
}
```
**(MVP)** As a user, I can get/list signatures via docker api extentions https://pulp.plan.io/issues/9513
```bash
GET /extensions/v2/<namespace>/<repo-name>/signatures/
GET /extensions/v2/<namespace>/<repo-name>/signatures/<imagesha256digest>
```
### Signature management via pulp API
**(MVP)** As a user, I can get/list signatures via pulp api
- **GET /v3/content/container/signatures/**
- **GET /v3/content/container/signatures/<signature-id>/**
### Post-MVP? (To be discussed)
**As a user I can audit existing content and verify its' signature - https://pulp.plan.io/issues/9581 - wait until December 13 meeting, might get into MVP** -- not going into MVP
As a user when I copy manifest only manifest is copied by default
As a user when I copy signature, its manifest is copied as well
* NOTE: it does not make sense to cope signatures between the repos, docker-refence will stay same while base_path from distribution will differ
As a user I can add signatures to the repo but ensure such manifest is already present in the repo
As a user I can remove signatures from repos
### Testing related to sigstore
#### Repositories
EXD does not want to help with test content, so we are on our own.
Ideally, find repositories on registry.redhat.io which are tiny in size and are deprecated https://catalog.redhat.com/software/containers/search?include_deprecated=1 (so the repositories do not change) with the following content:
* a tagged and signed image with docker-reference as a tag
* a tagged and signed image with docker-reference as a digest (unlikely to be found)
* a manifest list with a signed per-arch images
It would be great to find also:
* a repo with a mixed content (some signed, some not), or wait till we can properly test pulp2pulp sync.
* a repo with no signatures (but registry is supporting sigstore - can be mimicked)
#### High-level test scenarios
* Test that repositories found above are synced successfully:
* if sigstore is not provided, signatures are not synced
* if sigstore is provided, signatures are synced
* Test that repositories with no signatures sync successfully:
* sigstore is provided, registry supports sigstore
* Test signed_only option
* should not work if registry does not support either sigstore or docker API extensions
* syncs all content and their signatures for a repo where all content has signatures
* syncs only signed content and their signatures for a repo with a mix of signed and not signed content
* does not sync any content for a repo where no signatures are available (but registry is supporting sigstore or the docker API extension)
* does not sync a manifest list at all if any of its per-arch images are not signed
* Test bad signature handling
* this requires our own solution, aka simulate/mock that registry returned a bad signature
* sync should skip bad signatures and not fail
* if signed_only=True, and content has only bad signatures, it should not be synced
* if signed_only=True, and a per-arch has only bad signatures, its manifest list and related images should not be synced at all
### Container Signature model
- https://github.com/openshift/openshift-docs/pull/3556/files
```py
class ContainerManifestSignature(Content):
PROTECTED_FROM_RECLAIM = False
TYPE = "signature"
name = models.CharField(max_length=255, db_index=True)
content = Binaryfield()
manifest_digest
type
creator
timestamp
manifest = models.ForeignKey(Manifest, on_delete=models.CASCADE)
key_id = models.CharField(max_length=255, db_index=True)
sha256_encrypted_file =
class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("sha256_encrypted_file", "manifest_digest")
```
uniqueness constraint - name
FK to Manifest
add a field that contains info about the key(fingerprint)?
**Read till here :)**
---
Investigation part:
#### Container image signing workflow
https://www.redhat.com/en/blog/container-image-signing
https://www.redhat.com/en/blog/signed-images-red-hat-container-catalog
https://access.redhat.com/articles/2750891
#### Red Hat container sigstore
https://access.redhat.com/webassets/docker/content/sigstore
https://registry.redhat.io/containers/sigstore
https://access.redhat.com/articles/3116561
https://access.redhat.com/security/team/key
https://registry.redhat.io/containers/sigstore/ubi8/ubi-micro@sha256=43520d9634eaaa007a697be79eb604fcbfd348afe5e620c1407629bf20ced542/signature-1
#### Registry Sigstore config
https://github.com/containers/image/blob/main/docs/containers-registries.d.5.md
https://github.com/containers/image/blob/main/docs/containers-registries.d.5.md#developing-and-signing-containers-staging-signatures
* one can have sigstore per namespace but not multiple sigstores per registry
* "file:/// signature storage can be both read and written, http/https only supports reading."
#### Container Signature specs
https://github.com/containers/image/blob/main/docs/signature-protocols.md
https://github.com/containers/image/blob/main/docs/containers-signature.5.md
* the signatures are associated with an immutable image.
* An image can have any number of signatures so signature distribution systems SHOULD support associating more than one signature with an image.
* is a blob which contains a cryptographic signature in an industry-standard format, carrying a signed JSON payload (i.e. the blob contains both the JSON document and a signature of the JSON document; it is not a “detached signature” with independent blobs containing the JSON document and a cryptographic signature).
* Consumers of container signatures SHOULD verify the cryptographic signature against one or more trusted public keys defined in policy
* "type": "atomic container signature" TODO - ask why only this type?
* * because that's the only supported today
* important note on the schema1 manifests https://github.com/containers/image/blob/main/docs/containers-signature.5.md#criticalimagedocker-manifest-digest
#### Registry Signature API extension
https://docs.openshift.com/container-platform/3.10/admin_guide/image_signatures.html#accessing-image-signatures-using-registry-api
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_atomic_host/7/html/managing_containers/signing_container_images
https://github.com/openshift/origin/pull/12504/files
https://github.com/openshift/openshift-docs/pull/3556/files
https://github.com/mtrmac/image/commit/6c17ca34793b19accc3d278fc93ce68e9943fcb4 `X-Registry-Supports-Signatures`
* it supports only Atomic sig. type
#### Container image verification Policy
Policy should be configured on the client, it gets applied on pull/run commands
https://github.com/containers/image/blob/main/docs/containers-policy.json.5.md
https://github.com/containers/image/blob/main/docs/containers-policy.json.5.md#examples
* condition evaluation? 2 condition as or?
* no lazy evaluation both conditions should be satisfied
```
"hostname:5000/vendor/product": [
{ /* Require the image to be signed by the original vendor, using the vendor's repository location. */
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/path/to/vendor-pubkey.gpg",
"signedIdentity": {
"type": "exactRepository",
"dockerRepository": "vendor-hostname/product/repository"
}
},
{ /* Require the image to _also_ be signed by a local reviewer. */
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/path/to/reviewer-pubkey.gpg"
}
],
```
#### Sign and push sig to the local(not shared) sigstore
https://github.com/containers/podman/blob/main/docs/tutorials/image_signing.md
$ cat /etc/containers/registries.d/default.yaml | tail -10
```
docker:
localhost:24817:
#sigstore: http://inapprivateregistry.com/sigstore/
#sigstore: https://registry.redhat.io/containers/sigstore
sigstore-staging: file:///var/lib/containers/sigstore
registry.redhat.io:
sigstore: https://registry.redhat.io/containers/sigstore
#sigstore-staging: /mnt/nfs/privateregistry/sigstore
(pulp) [vagrant@pulp3-source-fedora34 ~]$
```
gpg2 --gen-key
gpg2 --armor --export --output mysignkey.gpg ipanova@redhat.com
gpg2 --list-keys
sudo -E GNUPGHOME=/home/vagrant/.gnupg podman push --log-level=debug --tls-verify=false --sign-by ipanova@redhat.com localhost:24817/alpine
#### Evaluate skopeo/podman/co-sign
https://github.com/sigstore/cosign
https://github.com/containers/skopeo/blob/main/docs/skopeo-standalone-sign.1.md
https://github.com/containers/skopeo/blob/main/docs/skopeo-standalone-verify.1.md
Cosign stores signatures as manifests, so no additional registry API needs to be created
Skopeo/Podman do not support cosign but there are plans to integrate with
Cosign signatures will not be deleted or garbage-collected when the image is deleted