Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

containers: Suppress error message when trying to fetch signatures #811

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Aug 31, 2023

When fetching container signatures, we attempt to do that for all
container versions and their digests we receive. In case the container
is not signed, we would throw a scary-looking message. The error itself
is handled well in the code by returning an empty signature object, we should
just make the message in the logs more friendly than:

{"Timestamp":1693470050051776000,"message":"2023/08/31 10:20:50 error
getting manifest: error getting image: GET
https://ghcr.io/v2/jakubtestorg/testrepo/manifests/sha256-729d8897773756c0c84f785aa2b44f05174fdf19de12a4497ecec042ecd31934.sig:
MANIFEST_UNKNOWN: manifest unknown"}

log.Printf("error getting manifest: %v", err)
} else {
log.Printf("no signature found for %s", package_url)
}
Copy link
Contributor

@JAORMX JAORMX Aug 31, 2023

Choose a reason for hiding this comment

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

nit: can we move this block to it's own function? This whole thing is already quite hairy so it would be a little nicer to keep any changes done here small. This whole thing also merits some refactoring but we can do that in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be more inclined to move the block with ExtractIdentityFromCertificate to a separate function, rather than this one, but VerifyFromIdentity does take a large number of parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did kinda both. The function is split out, even with a large number of parameters the code reads better now IMO, plus I changed the handling of the errors after calling the new functions extractAndValidateSignature to keep the happy path on a single indentation level which would hopefully address the comment Ozz had.

btw I agree that this whole module is ripe for refactoring. I filed issue #817 to get rid of the unsafe type casts at least, especially since they are coming from a potentially untrusted source.

JAORMX
JAORMX previously approved these changes Aug 31, 2023
Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Approving so you're not blocked on my comment.

evankanderson
evankanderson previously approved these changes Aug 31, 2023
log.Printf("error getting manifest: %v", err)
} else {
log.Printf("no signature found for %s", package_url)
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd be more inclined to move the block with ExtractIdentityFromCertificate to a separate function, rather than this one, but VerifyFromIdentity does take a large number of parameters.

pkg/container/container.go Show resolved Hide resolved
…plit extractAndValidateSignature into a separate function

When fetching container signatures, we attempt to do that for all
container versions and their digests we receive. In case the container
is not signed, we would throw a scary-looking message. The error itself
is handled well in the code by returning an empty signature object, we should
just make the message in the logs more friendly than:

```
{"Timestamp":1693470050051776000,"message":"2023/08/31 10:20:50 error
getting manifest: error getting image: GET
https://ghcr.io/v2/jakubtestorg/testrepo/manifests/sha256-729d8897773756c0c84f785aa2b44f05174fdf19de12a4497ecec042ecd31934.sig:
MANIFEST_UNKNOWN: manifest unknown"}
```

Also splits out the extraction and validation of a signature into
its own function.
Comment on lines +175 to +177
zerolog.Ctx(ctx).Info().
Str("packageUrl", package_url).
Msg("no manifest found")
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@jhrozek jhrozek merged commit 7721dd6 into mindersec:main Sep 1, 2023
13 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.

3 participants