Skip to content

Ensure content digest exists when pulling bundle via tag#1306

Merged
vdice merged 3 commits intogetporter:mainfrom
vdice:feat/ensure-content-digest
Oct 19, 2020
Merged

Ensure content digest exists when pulling bundle via tag#1306
vdice merged 3 commits intogetporter:mainfrom
vdice:feat/ensure-content-digest

Conversation

@vdice
Copy link
Copy Markdown
Member

@vdice vdice commented Sep 30, 2020

What does this change

  • adds logic to fail bundle pull (for main and any dependency bundle(s)) if a given bundle's invocation image is missing a content digest value

What issue does it fix

Closes #1305

Note that the other items mentioned in #1305 are already present in the code base, namely:

  • When you run a bundle locally, we should allow the content digest to not be set
  • Ensure that the digest is always set when porter publishes a bundle (Porter does so here and here)

Notes for the reviewer

n/a

Checklist

  • Unit Tests
  • Documentation
  • Schema (porter.yaml)

If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

…via tag

Signed-off-by: Vaughn Dice <vadice@microsoft.com>
Comment thread pkg/porter/dependencies.go Outdated
dep.CNABFile = cachedDep.BundlePath
dep.RelocationMapping = cachedDep.RelocationFilePath

invocationImage := cachedDep.Bundle.InvocationImages[0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think we could check the digest when we pull the bundle, instead of later when we try to run it? That way the logic would be in a single spot instead of split across dependencies and the other code paths?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, thank you. Updated.

Comment thread pkg/porter/dependencies.go Outdated

invocationImage := cachedDep.Bundle.InvocationImages[0]
if invocationImage.Digest == "" {
return fmt.Errorf("no content digest is present for dependency image %s", invocationImage.Image)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So if I saw this error, I would have no idea what to do about it or what the problem is. Let's try to explain the security issue and how the invocation image for the bundle doesn't have a digest so we can't verify that it is is the image referenced by the bundle and hasn't been tampered with. Or something like that.

Basically we need to throw the bundle under the bus, say it's invalid and could be compromised.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🚌 💨

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Error text has been updated to better convey the issue around this scenario. Thank you!

"images": null,
"invocationImages": [{
"digest": "sha256:f858bc025ad34099fe67ebe6152e03b4c91b34cc7a77d1aa10aaf1dc1389c2c2",
"contentDigest": "sha256:f858bc025ad34099fe67ebe6152e03b4c91b34cc7a77d1aa10aaf1dc1389c2c2",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you see this same mistake anywhere else in our repo? Would you mind taking a quick look?

Copy link
Copy Markdown
Member Author

@vdice vdice Sep 30, 2020

Choose a reason for hiding this comment

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

Ooh, yea, there are def other spots. Good call. In fact, for the images/ImageMap part of a manifest, the yaml tag is still digest, so there will be quite a few changes. Do we want to add these as an additional commit to this PR or as a follow-up?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up please! 🙇‍♀️

Comment thread pkg/porter/testdata/cache/README.md Outdated
* deislabs/kubekahn:1.0 -> 887e7e65e39277f8744bd00278760b06
* getporter/mysql:v0.1.2 -> 972978d3b715212b783a70fdc3449584
* getporter/wordpress:v0.1.2 -> bfa9f2b528338f9ac1bc9b8b984c3997
* getporter/mysql:v0.1.3 -> 4f17468b1ad86cb50cd76d9b8148d249
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for updating my beloved cheat sheet!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I backed out the changes in this directory now that we've placed the logic in PullBundle (and, hence, cached bundles wouldn't hit this case). For another day!

Signed-off-by: Vaughn Dice <vadice@microsoft.com>
@vdice vdice changed the title feat(lifecycle.go): ensure content digest exists when pulling bundle via tag Ensure content digest exists when pulling bundle via tag Oct 1, 2020
Signed-off-by: Vaughn Dice <vadice@microsoft.com>
@vdice vdice force-pushed the feat/ensure-content-digest branch from f1206bb to ca87a05 Compare October 1, 2020 14:02
@vdice vdice requested a review from carolynvs October 1, 2020 14:23
@carolynvs carolynvs self-assigned this Oct 6, 2020
Copy link
Copy Markdown
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Looks great! 💯

@vdice vdice merged commit 16b1b8b into getporter:main Oct 19, 2020
@vdice vdice deleted the feat/ensure-content-digest branch October 19, 2020 23:06
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.

Ensure content digest is populated for all published bundles

2 participants