-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 signature verification for oci hosted bundles #6145
fix signature verification for oci hosted bundles #6145
Conversation
@gitu it would be helpful if you could explain why this change is needed. It's not clear from the comment. Thanks. |
@ashutosh-narkar sure, when downloading a signed image from oci, the path, where the persisted bundle is stored, gets added to verify the signature. Here an example with a signed bundle containing a data.json file it it's root, and persistence_directory:
when downloading the same bundle via oras manually and loading it directly the signature comes out as valid. the base path gets added here to the verification: Lines 544 to 548 in cca8197
|
Thanks for the context. It would good to have some tests to ensure we don't break anything. The base dir would be set on modules iirc so a test or some would be useful. |
The only other usage of basedir I could find is when loading the bundle from a folder, even there it only seems to be added for debugging purposes. Lines 253 to 257 in cca8197
The question I know have maybe the verifier is wrong and it might be sensible to remove the adding of the baseDir for getting the right hash from the signature: Lines 543 to 549 in cca8197
|
after a bit playing that further, can a signature as such ever exist: Lines 462 to 470 in cca8197
decoded signature:
when reading: https://www.openpolicyagent.org/docs/latest/management-bundles/#signature-format my understanding would be that the filename should be relative to the |
That is not necessary. They could be absolute paths as well. So #6147 would possibly break existing bundle checks and loading as well. Hence for backwards compatibility let's not change that. If this is a concern for OCI bundles, we should address that in this PR. |
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@ashutosh-narkar took me a while to get to write a proper test for only changing the behaviour for the oci downloader please have another look |
364102d
to
b42b2fd
Compare
@@ -271,7 +271,7 @@ func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downl | |||
return nil, err | |||
} | |||
loader := bundle.NewTarballLoaderWithBaseURL(fileReader, d.localStorePath) | |||
reader := bundle.NewCustomReader(loader).WithBaseDir(d.localStorePath). | |||
reader := bundle.NewCustomReader(loader). |
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.
Wouldn't this break verification for some existing OCI bundles?
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.
As there was no test for it I assume that it didn't work before.
If you want to try that just add revert the line you mentioned and rerun the test.
The test uses a bundle that is signed directly via opa:
opa/download/oci_download_test.go
Line 21 in c66511f
//go:generate go run github.com/open-policy-agent/opa build -b --signing-alg HS256 --signing-key secret testdata/signed_bundle_data --output testdata/signed.tar.gz |
I still consider the #6147 the more correct thing to do, although I see that might lead to not backward compatible changes. As my assumption is that I could sign a bundle in one folder for example: /home/userx/bundles/myBundle
then copy that to another system into /data/bundles/myBundle
and verify the signature without having to move to bundle to a specific folder. Besides that point the other usages of the bundle reader do not seem to us the WithBaseDir
option.
Lines 331 to 338 in de896d9
reader := bundle.NewCustomReader(loader). | |
WithMetrics(m). | |
WithBundleVerificationConfig(d.bvc). | |
WithBundleEtag(etag). | |
WithLazyLoadingMode(d.lazyLoadingMode). | |
WithBundleName(d.bundleName). | |
WithBundlePersistence(d.persist) | |
if d.sizeLimitBytes != nil { |
or
Lines 101 to 110 in de896d9
r := bundle.NewCustomReader(bundle.NewTarballLoaderWithBaseURL(f, "")) | |
if bvc != nil { | |
r = r.WithBundleVerificationConfig(bvc) | |
} | |
b, err := r.Read() | |
if err != nil { | |
return nil, err | |
} |
@DerGut if you have sometime to review these changes especially anything you think that affects current behavior that would be great! |
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.
Few nits and comments inline. Thanks for working on this!
download/testdata/latest.tar.gz
Outdated
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.
What is this file?
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.
my bad, that went lost while rebasing now it should be clear that is just a rename of the existing tar.layer file
44e8d08
to
b278d01
Compare
@ashutosh-narkar thanks for the review, now this small stuff is also still easy to change :D |
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.
Thanks @gitu! Can you please squash your commits and we can get this in.
…ature verification Signed-off-by: Florian Schrag <[email protected]>
0506d01
to
6c9f860
Compare
@ashutosh-narkar done, thanks for you review |
Why the changes in this PR are needed?
Verification of bundles downloaded via OCI fail.
What are the changes in this PR?
Removes double usage of base dir.