-
Notifications
You must be signed in to change notification settings - Fork 528
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
Make mutate
constructs immutable.
#1124
Conversation
Weird, this is a legit failure that repros for me locally, but not against |
Ah, we do, but it's a test bug 🤣 go-containerregistry/pkg/legacy/tarball/write_test.go Lines 302 to 303 in 8388fde
|
I noticed that `cosign` was taking advantage of a bug in the mutate package where the `Manifest()` returns a mutable copy of it's internal state, which allowed them to permanently alter the result of `Manifest()`. This mutability violates the philosophy of our abstractions, and should not be allowed, so this change ensures that each of the methods returning state in the `mutate` package return a `.DeepCopy()` instead. In `image` this included the `configFile`, and `manifest`. In `index` this included the `indexManifest`. I have added tests that when the returned copies are mutated, a subsequent invocation of the getter will return a pristine copy. Since I'm not completely heartless, I am also adding a new `mutate.ConfigMediaType` method to enable `cosign` to perform the alteration they want, now that the trick they were using will no longer work. Related: sigstore/cosign#718
1a71d2a
to
43e061d
Compare
Codecov Report
@@ Coverage Diff @@
## main #1124 +/- ##
==========================================
- Coverage 75.16% 75.15% -0.02%
==========================================
Files 108 108
Lines 7724 7732 +8
==========================================
+ Hits 5806 5811 +5
- Misses 1363 1364 +1
- Partials 555 557 +2
Continue to review full report at Codecov.
|
All hail not heartless Matt |
Thanks for fixing this! |
I noticed that
cosign
was taking advantage of a bug in the mutate packagewhere the
Manifest()
returns a mutable copy of it's internal state, whichallowed them to permanently alter the result of
Manifest()
. This mutabilityviolates the philosophy of our abstractions, and should not be allowed, so
this change ensures that each of the methods returning state in the
mutate
package return a
.DeepCopy()
instead. Inimage
this included theconfigFile
, andmanifest
. Inindex
this included theindexManifest
.I have added tests that when the returned copies are mutated, a subsequent
invocation of the getter will return a pristine copy.
Since I'm not completely heartless, I am also adding a new
mutate.ConfigMediaType
method to enablecosign
to perform the alterationthey want, now that the trick they were using will no longer work.
Related: sigstore/cosign#718