Skip to content

Reject null manifests during tar import#41842

Merged
thaJeztah merged 1 commit into
moby:masterfrom
jchorl:master
Feb 9, 2021
Merged

Reject null manifests during tar import#41842
thaJeztah merged 1 commit into
moby:masterfrom
jchorl:master

Conversation

@jchorl
Copy link
Copy Markdown
Contributor

@jchorl jchorl commented Dec 26, 2020

- What I did

I was using kaniko to build images, which erroneously produced a tarball with a manifest containing null. Surprisingly, docker accepted the manifest but... didn't do anything.

This is not outlined in the docker spec, but I believe null manifests should be rejected ([] is okay!). It would have saved me a bunch of time, and I can't imagine anyone intentionally importing null as an image (even [] is questionable).

This change rejects null manifests. For a quick brief on how go JSON decodes null and [], see:
https://play.golang.org/p/kGuoI0x1xyc

- How I did it

I just added a check for a nil manifest

- How to verify it

I followed the guide to get a dev env running, then:

$ printf 'null' > manifest.json
$ tar -czf invalid.tar manifest.json
$ root@31d06c589959:/go/src/github.com/docker/docker# docker load -i invalid.tar 
invalid manifest, manifest cannot be null (but can be [])

- Description for the changelog
reject tarballs with null manifests on import

- A picture of a cute animal (not mandatory but encouraged)
Screenshot_2020-12-26 Messenger

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

SGTM

@tonistiigi @tianon PTAL

@thaJeztah thaJeztah added area/distribution Image Distribution area/images Image Service kind/bugfix PR's that fix bugs status/2-code-review labels Jan 21, 2021
@tianon
Copy link
Copy Markdown
Member

tianon commented Jan 21, 2021

This feels conceptually really similar to #41701 - does it make sense to add a unit test for this one? 😇 🙏

@jchorl
Copy link
Copy Markdown
Contributor Author

jchorl commented Feb 2, 2021

PTAL @tianon

I parted out validation into it's own function - testing Load(...) is actually quite hard because it requires a tarred up manifest and a store. Hopefully this is sufficient for now.

@thaJeztah
Copy link
Copy Markdown
Member

Looks like you forgot to sign-off the second commit, causing CI to fail. Feel free to squash the commits (probably makes sense to combine them in a single commit)

Signed-off-by: Josh Chorlton <[email protected]>
@jchorl
Copy link
Copy Markdown
Contributor Author

jchorl commented Feb 2, 2021

Done!

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@tianon @cpuguy83 ptal

Copy link
Copy Markdown
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@thaJeztah thaJeztah merged commit 1c39b1c into moby:master Feb 9, 2021
@thaJeztah thaJeztah added this to the 21.xx milestone Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants