Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

[merged] verify: validate layers of system image stored on disk#531

Closed
imsteev wants to merge 1 commit intoprojectatomic:masterfrom
imsteev:image_validation
Closed

[merged] verify: validate layers of system image stored on disk#531
imsteev wants to merge 1 commit intoprojectatomic:masterfrom
imsteev:image_validation

Conversation

@imsteev
Copy link

@imsteev imsteev commented Aug 10, 2016

Integrated the gomtree filesystem verification tool into atomic verify -V <system_image>.

The idea behind this integration of a filesystem verification tool is so that when a user pulls an image (for now only system images) using atomic pull ..., a manifest that details a layer (i.e, file ordering, file attributes like mode, size, sha256digest, etc.) will be created and stored in /var/lib/atomic/gomtree-manifests. Then, when a user performs atomic verify -V <system_image>, these manifests will be validated against the local image the user has on disk.

Ideally, we would be able to do this for the rest of the images as well, and implement it in a similar manner to syscontainers._pull_image_to_ostree()

Since gomtree is still being developed, we need to maintain updated versions of the gomtree binary. I wasn't sure if a go get..., go install... was something we wanted to do in the Makefile. For now, I created a local build of the gomtree tool and added it as part of this commit.

For testing, would the program be able to write to a /var/lib/atomic directory? Because that would be the location where these "gomtree manifests" would be stored. If you want to test it by hand, you can go into your ostree repo and change some content of an image you're not using (although this might affect other images as well, so be careful) and then perform verify with the -V flag.

Signed-off-by: Stephen Chung schung@redhat.com

@imsteev
Copy link
Author

imsteev commented Aug 10, 2016

@vbatts here is an integration of gomtree into the atomic CLI

Atomic/verify.py Outdated
continue
tmp_dir = tempfile.mkdtemp()
ref = os.path.join("ociimage", layer)
cmd = ['ostree','checkout','--union','--repo=%s' % "/ostree/repo",ref,tmp_dir]
Copy link
Author

Choose a reason for hiding this comment

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

can we make syscontainers._get_repo_location() a non protected function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure

@imsteev imsteev changed the title verify: validate layers of system image stored on disk (needs some discussion) verify: validate layers of system image stored on disk Aug 11, 2016
os.makedirs(root)
manifestname = os.path.join(root, "%s.mtree" % layer)
if os.path.isfile(manifestname):
util.write_out("validation manifest for layer %s alredy created" % layer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

small typo: already

@giuseppe
Copy link
Collaborator

in prune_ostree_images we should check that for each manifest file the layer still exists. If the layer doesn't exist, then remove the manifest file.

For images stored in an OSTree repository, how does this compare to ostree fsck?

@rhatdan
Copy link
Member

rhatdan commented Aug 11, 2016

@mitr @runcom PTAL

@mitr at some point we would like to get this to be covered by the signing spec.

if not success:
shutil.rmtree(temp_dir)

return temp_dir
Copy link
Member

Choose a reason for hiding this comment

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

Intentional?

@rhatdan
Copy link
Member

rhatdan commented Aug 11, 2016

@baude PTAL

@imsteev
Copy link
Author

imsteev commented Aug 11, 2016

@giuseppe ostree fsck checks for the overall integrity of the image by evaluating only the checksums of a file. If we wanted more details about what exactly about that image has changed, then integrating gomtree would help us do that. Also, being able to have a validation manifest allows us to incorporate this 'consistency check' when we distribute and sign images.

@imsteev
Copy link
Author

imsteev commented Aug 11, 2016

pushed revisions based off feedback. removed the -V flag to make the system validation default behavior.

@imsteev
Copy link
Author

imsteev commented Aug 11, 2016

revised this PR so that now on an atomic verify -g <non-system image>, we can create a validation manifest. Then, when we run atomic verify <non-system image>, the validation manifest will be checked against the docker image (through temporarily mounting the image)


ATOMIC_LIBEXEC = os.environ.get('ATOMIC_LIBEXEC', '/usr/libexec/atomic')
ATOMIC_VAR = '/var/lib/atomic'

Copy link
Member

Choose a reason for hiding this comment

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

Should this be under /var/lib/containers? As used below?

Copy link
Author

Choose a reason for hiding this comment

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

ok I will change this to /var/lib/containers/atomic

@rhatdan
Copy link
Member

rhatdan commented Aug 12, 2016

We need some tests to make sure this works.

@giuseppe
Copy link
Collaborator

when are these files deleted? Shouldn't the manifest be deleted on prune if the layer is not present anymore?

Integrate go-mtree tool into atomic CLI command, `atomic verify -V <imagename>`.
(Note that `gomtree` is still in development and thus we would need some way of
obtaining updated gomtree binaries) When a user does an atomic pull,
validation manifests for that system image's layers are created and stored in
/var/lib/atomic. When user does `atomic verify -V <system image>`, these manifests
are then validated against the image that is on disk (which would be stored in ostree).

Signed-off-by: Stephen Chung <schung@redhat.com>
@imsteev
Copy link
Author

imsteev commented Aug 12, 2016

added a simple test case to check if atomic pull on a system image will create gomtree manifests. will need to figure out how to change a consistent file in a system image so that we can test the output of gomtree validation

@rhatdan
Copy link
Member

rhatdan commented Aug 12, 2016

Ok we can merge this, but @lsm5 is going to have to add gomtree to the atomic build, or we need to get this accepted as a new package into Fedora.

@rh-atomic-bot r+

@rh-atomic-bot
Copy link

📌 Commit d741e92 has been approved by rhatdan

@rh-atomic-bot
Copy link

⌛ Testing commit d741e92 with merge d4728ae...

verifyp.add_argument("-V", "--validate", default=True,
action="store_false",
help=_("disable validating system images"))
verifyp.add_argument("-g", "--generate", default=False,
Copy link
Member

@cgwalters cgwalters Aug 12, 2016

Choose a reason for hiding this comment

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

It seems weird to have this option under verify. I'd expect it to be a system-wide setting one can turn on by default.

Also...I'm a bit concerned about the performance of all of this. Our intent with OSTree BTW is to drive immutability down into the storage stack - then you don't really need verify since the files are truly immutable. See discussion in O_OBJECT

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should move this to another verb
atomic images generate
Which would generate new checksums.

Copy link
Member

Choose a reason for hiding this comment

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

The immutable bit, could be a problem where a user could not remove a file that a hacker had placed on a file system.

Copy link
Member

Choose a reason for hiding this comment

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

That sort of thing is why I'm not using the immutable bit in ostree today. The semantics are annoying. My proposal for O_OBJECT does allow root to unlink the file (and to create new links to it). I.e. the inode can change, but not the contents.

Copy link
Member

Choose a reason for hiding this comment

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

Also, the immutable bit can be removed. With O_OBJECT at least you'd have to have compromised the kernel (or have CAP_SYS_ADMIN to write to the raw disk).

In the bigger picture of course if someone has CAP_SYS_ADMIN on your machine, they can inject code into the kernel to lie to whatever userspace validation tools you have, or things like inject malware into the hard drive controller.

That said, if we did have the mtree data in OCI images we built, one could use them to more efficiently perform offline forensics too. Mount a disk with libguestfs or whatever, download just the mtree metadata from a layer rather than the whole layer tar.

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: rhatdan
Pushing d4728ae to master...

@rh-atomic-bot rh-atomic-bot changed the title verify: validate layers of system image stored on disk [merged] verify: validate layers of system image stored on disk Aug 12, 2016
@imsteev imsteev deleted the image_validation branch August 12, 2016 21:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants