webhooks: Handle the case where a signature arrives after an unsigned artifact had been stored #919
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It appears that there can be a race condition when we listen to GH
webhook messages that notify about new packages. First, an unsigned
package would be delivered and then a package signature, manifesting as
a package whose name corresponds to the digest of the package being signed.
As a result, we would first store the unsigned package but then receive
the signature separately but wouldn't link the two or even process the
signature message.
As a result, github actions that produced signed packages would sometimes fail
our policies, seemingly at random. Even more confusingly, if the developer
tried to just redeliver the message payload, the code would have worked because
at that point the signature would have been published and mediator would
process it.
In order to handle it, this patch, upon receiving a signature package
notification tries to find an artifact version with the same SHA as the
signature and instead of processing the signature, re-evalute the
package that corresponds to the signature again.
The first patch in this PR just modifies the GetVersionBySHA call
to only search by SHA, that is always unique anyway and at the point we
need to call this query we might not have the artifact ID anyway.