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

Ignore sticky bit when validating permissions. #177

Merged
merged 3 commits into from
Nov 16, 2019

Conversation

WibbletheDuck
Copy link
Contributor

On Nextjournal we use a standard connection file which is mounted to docker containers in order to support Jupyter runtimes. Since the addition of secure_write we can get an initial startup just fine by setting permissions on the file. However, with some Jupyter kernels it seems the Sticky Bit gets set, and this persists on the mounted file through restarts and resets, causing secure_write to fail:

RuntimeError: Permissions assignment failed for secure file: '/runtimes/jupyter/kernel_connection.json'.Got '0o1600' instead of '0o0600'

I don't think the Sticky Bit is a security risk(?), so I see no reason it shouldn't be ignored. Tested the fork, and this change does clear up our problem.

Copy link
Member

@kevin-bates kevin-bates left a comment

Choose a reason for hiding this comment

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

This looks good - thank you. Just had the one comment (and a couple trivial "fixups").

@@ -388,7 +388,7 @@ def get_file_mode(fname):
# Some filesystems (e.g., CIFS) auto-enable the execute bit on files. As a result, we
# should tolerate the execute bit on the file's owner when validating permissions - thus
# the missing one's bit on the third octet.
return stat.S_IMODE(os.stat(fname).st_mode) & 0o7677 # Use 4 octets since S_IMODE does the same
return stat.S_IMODE(os.stat(fname).st_mode) & 0o6677 # Use 4 octets since S_IMODE does the same
Copy link
Member

Choose a reason for hiding this comment

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

I agree we should ignore the sticky bit. Wondering if we shouldn't just ignore them all in that octet, but that's a larger discussion.

If we're only removing the sticky bit from the mask, then the comment should be updated to state why. I also had a brain cramp when I added the previous comment and we should change the wording of "one's bit" to "least significant bit" while we're here. So perhaps something like...

...thus the missing least significant bit on the third octet. In addition, we also tolerate the sticky bit being set, so the lsb from the fourth octet is also removed.

The other "repair" ask I have (sorry), is to fix the error message at the end of file. Could you please add some spacing before "Got" and put a period at the end of its sentence as well? That's been bugging me in the recent logs I've seen. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 ?

Copy link
Member

Choose a reason for hiding this comment

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

I'm going to go super nitpicky about the comments: I think we're using 'octet' inaccurately. An octet is 8 bits, aka a byte. Digits in octal represent 3 bits each. So I think we should be using the term 'octal digit' instead.

(I know this was already there, but I think it's worth fixing while we're looking at this bit of code anyway)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you're right - my bad. @WibbletheDuck - would you mind fixing up the occurrences of octet as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kevin-bates Done!

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

Fix wording of get_file_mode() comment and add text about allowing the sticky bit.  Fix grammar of secure_write() permissions error message.
Copy link
Member

@kevin-bates kevin-bates left a comment

Choose a reason for hiding this comment

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

LGTM Micah - thanks for the fixups as well.

@takluyver takluyver merged commit b129001 into jupyter:master Nov 16, 2019
@takluyver
Copy link
Member

Thanks

rkdarst added a commit to AaltoSciComp/jupyter-aalto-singleuser that referenced this pull request Jan 16, 2020
- Recent addition in jupyter_client caused this bug.  This should be
  removed later, once a newer version of jupyter_core is released.
  The offending code was added to jupyter_client, moved to
  jupyter_core, then fixed in jupyter_core.
- original patch: jupyter/jupyter_client#469  (2019-09-08)
- fix in jupyter_core: jupyter/jupyter_core#177 (2019-11-16)
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.

3 participants