Repository navigation
Refuse to push encrypted files the given key cannot decrypt - #773
Conversation
A project whose files are already encrypted keeps them as they are when pushed with --encrypt, but the push never checked that the given key is the one they were encrypted with. Pushing files encrypted with one key with --encrypt --key of another, on a project with no cloud project or stored key path to compare with, uploaded the old ciphertext under the other key's hash: the push reported success and the cloud project could not be decrypted with the key it names. The push now checks that the given key decrypts each already encrypted file before uploading, and stops with an error naming the file and key otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Approving. The push now decrypts every file marked encrypted with the given key before it uploads anything, and rejects the push when a file fails. That fixes the case where ciphertext was uploaded under the wrong key's hash. The new test fails on master and passes with the change (I ran it locally against both). The described end-to-end run covers the failing push, a push with the right key and a --decrypt push.
Behavior to be aware of: the check also runs on a normal push of an encrypted project with its stored key. So a plain or empty file added to such a project after it was encrypted now stops the push with File <file> is not encrypted with the encryption key <key>. On master, that file was uploaded as plain text into the encrypted cloud project, where lean decrypt and pulls with --decrypt already fail on it. Rejecting it fits what the fix is for.
One small, non-blocking point is inline: an unreadable source file's error no longer names the file.
I set risk:low. The change is small and easy to revert, and it has a regression test, green CI and an end-to-end run.
There was a problem hiding this comment.
Changes requested: delete the first description revision from the edit history.
Please also correct ‘unencrypted and without files’: tested end to end, a rejected new-project push retains the default template files. No local ciphertext is uploaded. A correct-key retry and --decrypt both succeed; rejecting an invalid later file also preserves all existing cloud files.
I found no blocking code defect. Local verification: PYTHONPATH="$PWD" python -m pytest -q passed (2,907 passed, 81 skipped); static analysis passed. The initial run without PYTHONPATH hit the unrelated subprocess-version test fixed in #774.
Set risk:high pending the description-history removal.
|
Corrected the description: a rejected push to a new cloud project leaves it unencrypted with only the files a new cloud project starts with, and none of the local files are uploaded. I also added the case you tested, a later file the key can't decrypt, which leaves every existing cloud file as it was. No new commit: the code is unchanged. Deleting the first description revision from the edit history needs a maintainer: the API offers no way to do it, and I've asked one. |
There was a problem hiding this comment.
Approved. The corrected description resolves my remaining concern. My earlier request to delete a description revision was unnecessary and should not have blocked approval.
Set risk:low: this is a small fix backed by regression coverage and verified end-to-end behavior. The 39 push/encryption/decryption tests pass again, and static analysis passes.
What changed and why
A local project whose files are already encrypted (
encrypted: true) keeps them as they are when pushed with--encrypt --key <key>, but nothing checked that<key>is the key they were encrypted with. When the project has neither acloud-idnor anencryption-key-path(and the cloud project is new, or not yet encrypted), there is nothing else to compare against. So files encrypted with key A, pushed with--encrypt --key B(both keys registered), were uploaded unchanged under B's hash. The push reported success, and B could not decrypt the cloud project.get_encrypted_file_content_for_local_projectnow decrypts each already encrypted file with the given key before keeping it. A file the key can't decrypt stops the push withFile <file> is not encrypted with the encryption key <key>, before the cloud project's files are updated. Pushes that encrypt plain files, pushes with the right key and--decryptpushes are unchanged.lean encryptnever reaches this path, because it returns early for a project that is already encrypted.On a project with no
cloud-id, the cloud project is still created before the files are checked, as before this change. The rejected push leaves it unencrypted with only the files a new cloud project starts with: none of the local files are uploaded. The next push with the right key updates it.Tests
test_cloud_push_aborts_when_local_files_encrypted_with_key_x_and_new_cloud_project_given_key_y: files encrypted with key X, two registered keys, nocloud-idand noencryption-key-path, pushed with--encrypt --key Y. The push must not callprojects.update, and its output must name the error. The test fails onmasterand passes with this change.encrypted: trueover plain-text files. They now write real encrypted files, as an encrypted project has.python -m pytest -s -rs: 2907 passed, 81 skipped (macOS-only and API-credential tests).python static_analysis.py: BUILD PASSED.Tested end to end with two registered keys:
--encrypt --key B:master, the push reported success. The cloud project named key B but held A's ciphertext: key B failed to decrypt it and key A decrypted it.Cannot push '<project>': File .../main.py is not encrypted with the encryption key .../keyB.txt. The cloud project's files were not updated: it stayed unencrypted, with only the files a new cloud project starts with. A file the key can't decrypt, added to a project whose cloud project already has files, also stops the push and leaves every existing cloud file as it was.--encrypt --key Athen succeeded: the cloud project named key A, its files matched the local ciphertext, and key A decrypted them.--decrypt --key Apush then uploaded the plain source.