Skip to content
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

Remove UID/GID hack script #93

Merged
merged 4 commits into from
Jan 25, 2017
Merged

Remove UID/GID hack script #93

merged 4 commits into from
Jan 25, 2017

Conversation

zachmullen
Copy link
Member

This is a better cleanup solution; we run a very small container
to clean up the temp directory for us as root.

tmpdir = e.info['kwargs']['_tempdir']
cmd = [
'docker', 'run', '--rm', '-v', '%s:%s' % (tmpdir, DATA_VOLUME),
'busybox', 'rm', '-rf', DATA_VOLUME
Copy link
Contributor

Choose a reason for hiding this comment

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

I know generally we want to avoid replicating information, but it seems like hard coding '/mnt/girder_worker/data' would avoid potential attack vectors here

Copy link
Member Author

@zachmullen zachmullen Jan 25, 2017

Choose a reason for hiding this comment

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

What sort of attack? So long as DATA_VOLUME is only ever a string constant, wouldn't this be fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe i'm not reading the right, but if I can modify _tempdir so it is equal to '/' and DATA_VOLUME so it is equal to "/" won't I blow away your whole OS?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think if anyone managed to change the value of these variables, we have already been compromised to the point that an attacker could likely do whatever they want on the filesystem within the constraints of the worker user.

Choose a reason for hiding this comment

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

I would say the problem is less about an attacker changing it than a user or developer accidentally doing something wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Either way, the tmpdir variable is the one that presents the danger more than the DATA_VOLUME since that's the one referring to the host filesystem.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of rm -rf DATA_VOLUME, we could chmod -R a+x DATA_VOLUME, and then let the temp directory get cleaned up via the normal job cleanup. This has the virtue that the cleanup flag would be honored.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, if that got compromised in the same way, then instead of deleting our root filesystem, we've just given write permission to every user on every file... I'd rather just have them delete the files since it's an ephemeral processing node.

Copy link
Member

Choose a reason for hiding this comment

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

I was suggesting it to preserve the cleanup flag behavior, rather than as a security measure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, right, that makes sense. I'll change to set o+w.

This is a better cleanup solution; we run a very small container
to clean up the temp directory for us as root.
Otherwise it ignores the "cleanup" argument to run().
tmpdir = e.info['kwargs']['_tempdir']
cmd = [
'docker', 'run', '--rm', '-v', '%s:%s' % (tmpdir, DATA_VOLUME),
'busybox', 'chmod', '-R', 'o+rw', DATA_VOLUME
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 a+rw rather than o+rw? If the docker container happens to be the same UID or GID as girder_worker and leaves the files unwritable or unreadable, then wouldn't we fail to remove them otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is that true? I assumed o meant any user, regardless of whether they are the owner or in the owning group

Copy link
Member Author

Choose a reason for hiding this comment

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

(Just tested, turns out you are right! I learned something new today)

Copy link
Member

Choose a reason for hiding this comment

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

I thought so (but I was testing it myself to make sure).

@zachmullen
Copy link
Member Author

@cjh1 this is the branch I mentioned earlier that will conflict with the docker-py transition. Once you create the integration testing for docker mode, a lot of this testing mock stuff should go away since it's mostly testing mocked internal details and is a pain to maintain.

@cjh1
Copy link
Contributor

cjh1 commented Jan 25, 2017

@zachmullen Working on that at the moment, for now I am adding an additional test, rather the converting over the mocked version.

Copy link
Member

@manthey manthey left a comment

Choose a reason for hiding this comment

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

This works nicely with my docker-in-docker case now.

@zachmullen zachmullen merged commit dc219e2 into master Jan 25, 2017
@zachmullen zachmullen deleted the remove-docker-uid-hack branch January 25, 2017 20:07
@zachmullen
Copy link
Member Author

Thanks @manthey

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.

None yet

5 participants