Skip to content

Add image signature verification support for images signed by non-default ecdsa cosign keys#1398

Merged
Xynnn007 merged 1 commit intoconfidential-containers:mainfrom
esposem:image_signature
Apr 8, 2026
Merged

Add image signature verification support for images signed by non-default ecdsa cosign keys#1398
Xynnn007 merged 1 commit intoconfidential-containers:mainfrom
esposem:image_signature

Conversation

@esposem
Copy link
Copy Markdown
Contributor

@esposem esposem commented Apr 1, 2026

The goal of this PR is to support image-rs to verify images signed by cosign with a non-Ecdsa default key.

Which means:

  • Support for multiple kind of keys
  • Bug fix for some manifest digest mismatch
  • Support for image signature verification by tag

The concrete example that this PR is based on is to be able to verify registry.access.redhat.com/ubi9/ubi:latest with https://security.access.redhat.com/data/63405576.txt key.

Doing this verification by hand works:

# Fetch RH cosign public key
curl -L https://security.access.redhat.com/data/63405576.txt -o cosign-pub-key.pem

cosign verify --key cosign-pub-key.pem --output json registry.access.redhat.com/ubi9/ubi:latest --insecure-ignore-tlog=true

But with image-rs, it fails first with "Ecdsa-P256 from der bytes to public key failed: unknown/unsupported algorithm OID: 1.2.840.10045.2.1", then it complains about
SigPayload's manifest digest does not match, the input is sha256:.., but in SigPayload it is sha256:...
and after fixing that, it works only by digest and not by tag.

@esposem esposem requested a review from a team as a code owner April 1, 2026 08:31
@esposem esposem force-pushed the image_signature branch 2 times, most recently from 5323148 to c4a7ae3 Compare April 1, 2026 10:58
Copy link
Copy Markdown
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are really two different things being fixed here. I didn't look much at the first one, but the second one is something that I am already working on fixing. The fix here does not seem correct. See comments.

We've got to be really careful with the signature validation code.

Also we've got some unhappy CI jobs.

@esposem
Copy link
Copy Markdown
Contributor Author

esposem commented Apr 1, 2026

Fine for me @fitzthum, your fix is much better. I can drop the last two commits (even though I didn't realize the last is related to the second one). Is that ok?

The main problem is that it seems that image-rs only accepts a RSA key algorithm, so if anything else is being used then it will fail.

Which CI job is unhappy? The only failing I see it's unrelated, and failing in other PRs too.

@fitzthum
Copy link
Copy Markdown
Member

fitzthum commented Apr 1, 2026

Yes, can drop the last two and I will take a look at the first one. CI could be unrelated. Let me see. This PR may actually go beyond what is supported in that crate.

@esposem
Copy link
Copy Markdown
Contributor Author

esposem commented Apr 2, 2026

Ok @fitzthum @rajatchopra I investigated a bit, basically we can figure the key algo using the spki crate, but when it comes to RSA, we need to guess if it's PKCSI or PSS.

Therefore the approach remains the same, but it's cleaner. We only get >1 result in the vector if it's RSA, and we need to try all of them.

@esposem esposem requested a review from fitzthum April 2, 2026 08:43
@fitzthum
Copy link
Copy Markdown
Member

fitzthum commented Apr 2, 2026

Please see this method. Looks like it will detect the key info automatically for the keys that are supported by the sigstore crate.

@Xynnn007
Copy link
Copy Markdown
Member

Xynnn007 commented Apr 7, 2026

Please see this method. Looks like it will detect the key info automatically for the keys that are supported by the sigstore crate.

+1. When we designed sigstore-rs API, we take into consideration that a un-recognized key should be supported. But note that only PEM can be supported as the input.

image-rs should auto-detect and support multiple RSA keys when
verifying the image signature.

When trying to verify a container signed with a RSA PKCSI key, image-rs
fails with

"Ecdsa-P256 from der bytes to public key failed: unknown/unsupported algorithm OID: 1.2.840.10045.2.1"

This allows support for multiple types of keys.
Unfortunately RSA algo cannot be inferred from just the key bytes,
so we need to try all of them.

Signed-off-by: Emanuele Giuseppe Esposito <[email protected]>
Assisted-by: AI
@esposem
Copy link
Copy Markdown
Contributor Author

esposem commented Apr 7, 2026

Done, thanks for the suggestion, much cleaner

Copy link
Copy Markdown
Member

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

seems like the test cases don't exercise all the possible combinations, but as long as you've got what you need it should be ok

@esposem
Copy link
Copy Markdown
Contributor Author

esposem commented Apr 7, 2026

Yeah I tried with the RH public key and it goes into the other error (SigPayload), which means we did all we could do in image-rs. To make it fully work we also need oras-project/rust-oci-client#250 as you pointed.

Copy link
Copy Markdown
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest rand_core is 0.10.0. 0.6 is a very old version. Let me update in a following PR.

@Xynnn007 Xynnn007 merged commit fdcc6cd into confidential-containers:main Apr 8, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants