-
Notifications
You must be signed in to change notification settings - Fork 547
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
fix: fix fetching updated targets from TUF root (based off of #1921) #1932
Conversation
Signed-off-by: Asra Ali <asraa@google.com> add comment Signed-off-by: Asra Ali <asraa@google.com> update Signed-off-by: Asra Ali <asraa@google.com> update Signed-off-by: Asra Ali <asraa@google.com> possible fix windows Signed-off-by: Asra Ali <asraa@google.com> lint Signed-off-by: Asra Ali <asraa@google.com> fix windows maybe Signed-off-by: Asra Ali <asraa@google.com> fix close Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com> update fix Signed-off-by: Asra Ali <asraa@google.com> update and add some debug Signed-off-by: Asra Ali <asraa@google.com> add debug Signed-off-by: Asra Ali <asraa@google.com> no cache Signed-off-by: Asra Ali <asraa@google.com> remove debug Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
Codecov Report
@@ Coverage Diff @@
## main #1932 +/- ##
==========================================
- Coverage 34.01% 33.97% -0.04%
==========================================
Files 153 153
Lines 9977 9974 -3
==========================================
- Hits 3394 3389 -5
- Misses 6202 6206 +4
+ Partials 381 379 -2
Continue to review full report at Codecov.
|
Makefile
Outdated
@@ -118,7 +118,7 @@ cross: | |||
golangci-lint: | |||
rm -f $(GOLANGCI_LINT_BIN) || : | |||
set -e ;\ | |||
GOBIN=$(GOLANGCI_LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0 ;\ | |||
GOBIN=$(GOLANGCI_LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0 ;\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can bump to 1.46.2
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
605175c
to
527f95f
Compare
Looks like the Windows tests are unhappy with this:
Maybe a path separator issue? Seems to work on everything else just fine. |
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
@@ -380,6 +385,17 @@ func VerifyTLogEntry(ctx context.Context, rekorClient *client.Rekor, e *models.L | |||
rekorPubKeys[keyID] = RekorPubKey{PubKey: pubFromAPI, Status: tuf.Active} | |||
} | |||
|
|||
rekorPubKeysTuf, err := GetRekorPubs(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be cleaner to have all the override behaviour in one place, and move L371-386 to GetRekorPubs and have everything there. But, that would mean plumbing RekorClient through to GetRekorPubs, so wasn't sure if we wanted to do that. One thing that we might want to consider is plumbing the RekorClient into the ctx passed in and pull it from there so we wouldn't have to change the signature. I'd be happy to do that if we think that makes sense.
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
I cribbed the PR subject / description from #1921 here in case this is what we end up merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for the time being, appears to fix the relevant bug.
I have some apprehensions about this whole chunk of code generally (that predate this PR), I'm going to file a cleanup bug to come back and address this because this code is pretty important and should be easy to understand/test.
// It should theoretically be safe to do this everywhere - but the files only seem to get mutated on Windows so | ||
// let's only change them back there. | ||
if runtime.GOOS == "windows" { | ||
return bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n")), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 410d6cf
Actually can we hold off a day on merging this? I think #1921 is pretty close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried that this doesn't solve the problem: Does GetRekorPubs
still fail in the e2e test? It seems like the error in getting the TUF root Rekor public key is going "silent" now to allow the test to pass, so I just want to double check the logs and make sure that we could retrieve the TUF keys in that environment
I don't see "unable to fetch" anymore, so I will assume it's stable for now -- but AI to track/add a test whether verification failure will cause a some path to not close the TUF object and cause the "resource unavailable" error. |
This PR does a lot, and I don't want to submit this without submitting #1921 first. We can't rush this large PR through to unblock tests, there's a risk with breaking something else accidentally. |
Yep - we only need to merge one of them. We do need to get one of them merged though as this is holding up a pretty large release. |
Totally fair, but I also want to make sure we take our time reviewing the PR to not introduce other subtle bugs. |
Some folks are concerned that this might be just hiding a test failure, let's take the time to review this in depth in the original PR #1921. @lukehinds @bobcallaway for another pair of eyes. What is the release timeline, we should be able to make that one. |
Summary
This change refactors the cosign TUF client and hopefully aims to simplify the logic behind embedded TUF repository and targets, and the writeable on-disk/in-memory repository and targets. Roughly, I structured this so that the cosign TUF client contains (1) A
client.LocalStore
to hold TUF repository metadata updates and (2) AtargetImpl
to hold downloaded and cached target files.Previously, the two were "out of sync" -- when starting with an embedded workflow, we would create an embedded root repository and an embedded targetImpl. However, the embedded targetImpl ONLY retrieved embedded targets, not the updated ones!
cosign/pkg/cosign/tuf/client.go
Line 548 in 5f09c42
Embedded workflows never used their updated targets, despite writing them to the underlying storage, and failed to retrieve new targets referenced by updated metadata.
Conceptually now, there are 4 main objects in the TUF client:
memoryCache
targetImpl: A map that stores target files by name.diskCache
targetImpl: Stores targets on disk.embeddedWrapper
targetImpl: This wraps the underlying (memory, disk) cache. By default itGet
s embedded targets. If any targets were downloaded andSet
, thenGet
transfers to retrieving from the underlying cache.embeddedLocalStore
that wraps either aMemoryLocalStore
orFileLocalStore
. Similar to above, by default it gets embedded repo metadata, until any new metadata needed to be downloaded and set. Then anyGetMeta
operations get the cached metadata.Other:
brokenv3
's GCS bucket and it successfully found the new targetfulcio_interemediate_v1.crt.pem
If this design looks good, I will continue to add testing and clean-up test code. It's a pain to manually write out TUF updates, so I'd like to unify those functions and also add testing for consistent snapshotting (note brokenv3 enabled that so I'm 90% sure that works with this fix).
Ticket Link
Fixes #1899
Release Note