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

Allow notebooks to be trusted without triggering a save #2718

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

Madhu94
Copy link
Contributor

@Madhu94 Madhu94 commented Aug 1, 2017

Closes #195.

Trust should now add the notebook's signature without needing to trigger a save. Save will still trust the notebook, after checking and if it has not already been trusted.

I have not added an automatic refresh after trust, let me know if you think this would be a good idea.

@Madhu94 Madhu94 closed this Aug 2, 2017
@Madhu94 Madhu94 reopened this Aug 2, 2017
Copy link
Member

@minrk minrk left a comment

Choose a reason for hiding this comment

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

Thanks! I left a few comments inline.

# We need this check in case the notebook is
# trusted before save
if not self.notary.check_signature(nb):
self.check_and_sign(nb, path)
Copy link
Member

Choose a reason for hiding this comment

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

check_signature shouldn't be called before check_and_sign, which consumes trust metadata. I think .save probably doesn't need to change at all.

@json_errors
@web.authenticated
@gen.coroutine
def put(self,path=''):
Copy link
Member

Choose a reason for hiding this comment

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

POST is probably more appropriate for a request with no content.

@@ -443,7 +443,7 @@ def check_and_sign(self, nb, path=''):
if self.notary.check_cells(nb):
self.notary.sign(nb)
else:
self.log.warning("Saving untrusted notebook %s", path)
self.log.warning("Signing notebook %s", path)
Copy link
Member

Choose a reason for hiding this comment

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

This message is backwards. In this event, the notebook is not signed. It is still untrusted.

window.location.reload();
nb.contents.trust(nb.notebook_path)
.then(function(res) {
nb.events.trigger("trust_changed.Notebook", true)
Copy link
Member

Choose a reason for hiding this comment

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

it should still trigger reload to get the newly trusted notebook without sanitized output.

And .save should only be avoided when the notebook is read-only. We should still save & reload for non-read-only notebooks to avoid losing unsaved changes (which is unavoidable for read-only).

@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 2, 2017

@minrk Thanks for the feedback! Took care of those comments.

Copy link
Member

@minrk minrk left a comment

Choose a reason for hiding this comment

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

Thanks for the quick turnaround!

@@ -443,7 +443,9 @@ def check_and_sign(self, nb, path=''):
if self.notary.check_cells(nb):
self.notary.sign(nb)
else:
self.log.warning("Saving untrusted notebook %s", path)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe leave this at "Notebook %s is not trusted."

});
nb.save_notebook();
Copy link
Member

Choose a reason for hiding this comment

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

Can you still trigger save here if the notebook is not read-only? That way we can avoid losing unsaved changes when the notebook is editable.

var p;
if (nb.writable and nb.dirty) {
    p = nb.save_notebook();
} else {
    p = Promise.resolve();
}
p.then(function () {
    return nb.contents.trust...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if its read-only, we save it and then trust..Thanks, never noticed the dirty attribute.

@Madhu94 Madhu94 closed this Aug 2, 2017
@Madhu94 Madhu94 reopened this Aug 2, 2017
@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 2, 2017

@minrk In addition to the changes you requested, I added this, I think the check makes sense here.

@gnestor
Copy link
Contributor

gnestor commented Aug 4, 2017

@minrk Do you think this ready to merge?

self.notary.sign(nb)
# We're checking the signature *after* the
# trusted keys have been removed
if not self.notary.check_signature(nb):
Copy link
Member

Choose a reason for hiding this comment

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

I think this entire method should be left exactly as it was. Adding this check here is not correct because it prevents updating the signatures of trusted notebooks.

@minrk
Copy link
Member

minrk commented Aug 4, 2017

@gnestor almost. There's one addition in check_and_sign that should be reverted, but the rest should be set.

@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 4, 2017

@minrk The way store_signature for the signature store is implemented, the signatures don't get updated.
I logged an issue with nbformat, please let me know if I'm wrong here

@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 4, 2017

I think this is a bug even on master. I noticed that without the check, the same signature was re-inserted each time the notebook was trusted.

@minrk, I probably shouldn't check this here - the issue should be fixed in nbformat. So, I'll revert that change, squash my commits and then we're good to go?

@minrk
Copy link
Member

minrk commented Aug 5, 2017

@Madhu94 exactly right. This shouldn't be changed here, but fixed in nbformat itself. Thanks for digging in!

@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 5, 2017

@minrk I rebased and squashed my commits and reverted that check in manager.py. Let me know if there's anything else left?

@takluyver
Copy link
Member

@minrk this is, I think, the last remaining PR for 5.1. Is it ready to go?

@minrk minrk merged commit da2d54f into jupyter:master Aug 7, 2017
@minrk
Copy link
Member

minrk commented Aug 7, 2017

Yes, indeed.

@minrk
Copy link
Member

minrk commented Aug 7, 2017

Thanks, @Madhu94!

@Madhu94 Madhu94 deleted the trust_without_save branch August 13, 2017 19:55
@Madhu94
Copy link
Contributor Author

Madhu94 commented Aug 18, 2017

Can I add this to the 5.1 changelog ?

@takluyver
Copy link
Member

Yes, please do!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trust from menu not working for readonly ipy notebook
4 participants