Repository navigation
bug: keep an encrypted library encrypted when it is pushed with the project that uses it - #791
quantconnect-kronos[bot] wants to merge 6 commits into
Conversation
…roject that uses it `lean cloud push --project <project>` pushes the project's libraries too, without an encryption key. A library whose cloud project is encrypted and whose local files are plain, such as one pulled with --decrypt --key, was pushed with an empty key, which turned its cloud encryption off and stored its plain source. Such a library now isn't pushed: the push warns with how to push it on its own and goes on with the project, as for any library that can't be pushed. A push no longer sends an encryption key the cloud project already has. The cloud refuses to set a key on a project used as a library or shared with collaborators, even its current key, so an encrypted library could not be pushed while staying encrypted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The |
There was a problem hiding this comment.
Requesting changes: in a common workflow, the library guard now leaves the project that uses the library broken in the cloud.
1. A project pushed without encryption, still linked to a library the push kept encrypted, gets half-written and stops compiling. Setup: a project and its library, both encrypted in the cloud with the same key and linked. Run lean cloud pull --project P --decrypt --key key.txt, which pulls the library decrypted too. Make a local change, then run lean cloud push --project P. I tested this end to end:
| master | this branch | |
|---|---|---|
| library | pushed, cloud encryption removed | Cannot push 'Library/…' warning, stays encrypted |
| project | pushed, decrypted | Cannot push 'P': Encrypted libraries can not be added to a unencrypted project, yet its encryption is already removed and its plain source written |
| cloud compile of the project | BuildSuccess |
BuildError: SyntaxError in the library's Library.py (its ciphertext is compiled as source) |
projects/update removes the key and writes the files before it validates the library list, so the request fails only after it has written the project. The user is told nothing was pushed, but the project no longer compiles, and every retry fails the same way. On master this flow worked, but it removed the library's encryption.
What a fix must achieve: when the push would leave the project unencrypted (an empty key sent, or no key on the cloud project) while it references a library this push kept encrypted, the project's push writes nothing. Its warning says how to go on: push the project with --encrypt --key, or decrypt the library on its own first. For example, record the cloud ids the new guard skips and check them against update_args["libraries"] before projects.update. That is about 5 lines, plus a test for this flow. Don't use the cached encrypted flag of every library cloud project for this check: under lean cloud push with no --project, a library pushed earlier in the same run may already have been decrypted. Please also add this flow to the end-to-end table in the description.
Everything else checks out. The cloud reports encryptionKey.id as the key hash, and setting a key the project already has only re-validates it and upserts the same row. Leaving that key out therefore changes nothing in the cloud and avoids the library/collaborator refusal. I also ran the push tests locally: 215 passed.
CI: no test ran on this commit. test (windows-latest, 3.14) fails while installing lxml 6.2.1, which has no Windows wheel for Python 3.14, and GitHub then cancelled the rest of the matrix. This change didn't cause that failure (#792). The Regression Testing run is still in progress.
Label: risk:high. The change alters what pushes send for encrypted projects, it breaks the flow above, and it has no green CI yet.
…ept encrypted The cloud removes the project's key and writes its files before it refuses an encrypted library in an unencrypted project, so the push left the project half-written and failing to compile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Approving. The finding about a project pushed unencrypted that uses a library the push kept encrypted is resolved. That push now stops before projects/update, so it writes nothing.
I tested c730588 end to end. Setup: a project and its library, both encrypted in the cloud with the same key, pulled with --decrypt --key and given a local change. Running lean cloud push --project P with no options gives a Cannot push warning for both. The cloud state of both is the same before and after: encryption, key, library link and file contents. Pushing the project with --encrypt --key after that updates it, and it keeps its key and its library link. The library is warned about and left unchanged. The full test suite passes locally: 2940 passed, 81 skipped.
CI: test (windows-latest, 3.14) fails in both Build and Regression Testing while installing lxml 6.2.1, which has no Windows wheel for Python 3.14 (#792). This change didn't cause that. In Build, GitHub cancelled the rest of the matrix after that failure. Regression Testing passed on Ubuntu and macOS.
Label: stays risk:high. The change alters what every push of an encrypted project sends, and it refuses pushes of a decrypted project that go through on master. Also, the Build test matrix hasn't run on this commit.
There was a problem hiding this comment.
Requesting changes. The same-key path now leaves both cloud projects untouched when a push would decrypt the parent, and the encrypted retry works. I verified four other outcomes end to end:
- A bulk push can report success while storing ciphertext as unencrypted source. Two local copies share one cloud ID. The plain copy pushes first and clears the key; the encrypted copy pushes second. Master restores the key with the second upload. This branch omits it based on the cached read, so the cloud ends up with the encrypted copy's files and no key.
- A differently keyed library can make the parent impossible to pull with its own key. A push with
--encrypt --keysucceeded and linked the retained library even though the two keys differed. The nextlean cloud pull --decrypt --keycould not decrypt the project. Check for the same key, not just for a nonempty parent key, before updating the parent. - Skipping a library can break its local reference. On Linux, a library directory with a trailing period was renamed before the skip. Master repaired the reference; this branch left it pointing to the old directory, and the same-key parent push failed.
- A nested refusal can publish a reference to a library whose files never uploaded. With
App → new local library → retained encrypted library, the new library was created but its update was refused. The app still pushed and linked to the cloud template, without the module it imports. Continue with existing compatible cloud copies, but not with a newly created placeholder whose first upload was blocked.
Please cover these paths with regression tests and add their end-to-end outcomes to the description. The current full suite passed locally (2,940 passed, 81 skipped). CI's Windows Python 3.14 job fails during dependency installation (#792); I verified the same lxml build error on an unrelated branch. risk:high remains warranted because a reported successful push can leave unusable cloud code.
…f skipping the library Skipping a library whose cloud project is encrypted and whose local files are not, while pushing the rest, could leave projects the cloud can't use: an unencrypted or differently keyed project linked to the encrypted library, a new intermediate library created but never uploaded, or a renamed library's reference left stale. push_project now checks the libraries it would push before it renames, creates or writes anything, and fails with how to keep or remove the library's encryption. An update that sends an encryption key can change the cloud project's key even when it fails, so the cached cloud project is read again before a later push to it: a second local copy of the same cloud project pushed in the same command no longer leaves out a key the first copy removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. 941baf1 changes the approach instead of patching each case. Three of the four findings came from skipping the library and pushing the rest. Now a project push that would decrypt any of its libraries, nested ones included, fails before anything is renamed, created or written. The error says how to keep the library encrypted ( |
There was a problem hiding this comment.
Requesting changes. The round trip from my last review now works. I tested it end to end: a project and its library pulled with --decrypt --key, edited, and pushed with --encrypt --key both stay encrypted with the key and linked, and a fresh lean cloud pull --decrypt --key shows the library's edit. The push tests pass locally (117 passed, 3 skipped). One new finding comes from the same-key path.
1. A plain library that uses a library pushed with the command's key is left unlinked in the cloud, and the command exits 0. Setup: library A is encrypted in the cloud with key k and plain locally (pushed on its own with --encrypt --key k). A new library B uses A, and project P uses B. I ran lean cloud push --project P --encrypt --key k end to end:
| master | this branch | |
|---|---|---|
| A | decrypted in the cloud (the bug this PR fixes) | stays encrypted with k |
| B | created and linked to A | created and its files written, then Cannot push 'Library/B': Encrypted libraries can not be added to a unencrypted project; not linked to A |
| P | encrypted with k, linked to B | encrypted with k, linked to B |
| exit code | 0 | 0 |
So P now uses a cloud library whose code imports a module the cloud doesn't link to it. On the previous commit this push failed before writing anything. The cause is the one fixed earlier for the project itself: something pushed without a key references a library pushed encrypted, and the cloud writes before it refuses the link. Master leaves the same state when A is encrypted locally with lean encrypt instead. I ran that too: B created but not linked to A, P linked to B, exit 0. So one check covers both.
What a fix must achieve: before anything is renamed, created or written, refuse a project or library this push sends without a key when its libraries include one the push sends encrypted, either kept with the command's key or encrypted locally. The error should say how to go on, such as encrypting the referencing library too, or decrypting the referenced one on its own. That is about 5 to 8 lines next to the check at line 92. Please add a test for this nested case pushed with the library's own key, asserting that nothing is created or updated, and add the case to the end-to-end table.
CI: in both Build runs, test (windows-latest, 3.14) fails while installing lxml 6.2.1 (#792), and GitHub cancelled the rest of the matrix, so no unit test ran in CI on this commit. This change didn't cause that failure. Regression Testing is still queued.
…pushed without encryption Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Addressed the review in 514b20e. 1. A plain library using a library pushed encrypted. Before anything is renamed, created or written, the push now refuses any project or library it would send without encryption that uses a library it sends encrypted. That covers a library kept with the command's key and one encrypted locally with New test: Tested end to end, project → new library → library, pushed with
The end-to-end table in the description has the new rows. Its master column for the nested case is from your run.
|
There was a problem hiding this comment.
Approving. My last finding is resolved: a plain library that uses a library pushed encrypted is no longer created and left unlinked. The push now stops before anything is renamed, created or written.
I tested 514b20e end to end. Setup: library A is encrypted in the cloud with key k and plain locally, a new library B uses A, and project P uses B.
| Push | Outcome |
|---|---|
lean cloud push --project P --encrypt --key k |
exit 1 with the new error naming Library/B; neither B nor P created |
the same, after lean encrypt Library/B --key k |
exit 0; A, B and P all encrypted with k, P linked to B and B linked to A |
a project that uses A directly, pushed with --encrypt --key k |
exit 0; encrypted with k and linked to A (no false refusal) |
The new test fails on the previous commit in both of its cases and passes now. The full suite passes locally: 2947 passed, 81 skipped.
CI: in both Build runs, test (windows-latest, 3.14) fails while installing lxml 6.2.1 (#792), and GitHub cancelled every other test job, so no unit test ran in CI on this commit. This change didn't cause that failure. Regression Testing is still queued.
|
The review of 514b20e failed. It's requested again. |
There was a problem hiding this comment.
Requesting changes: the library encryption check must stop the push if it cannot verify an associated library’s cloud state. It also needs to stay out of bulk pushes that have no implicit libraries to validate.
I verified end to end that a bulk push with one unrelated config.json containing "libraries": null uploads the valid project on master, but exits 1 before uploading it on this branch. The same-key pull/decrypt → edit → push/encrypt round trip worked: both projects stayed encrypted and linked, and a fresh pull included both edits. The full suite passed locally (2,947 passed, 81 skipped).
CI: Windows Python 3.14 still fails installing lxml before tests (#792), which is unrelated to this change. The remaining Build jobs were cancelled; Regression Testing passed on Ubuntu and macOS.
| cloud_project = self._get_cloud_project(cloud_id, organization_id) | ||
| except RequestFailedError: | ||
| # the push of the project reports the cloud project it can't read | ||
| return None |
There was a problem hiding this comment.
A failed lookup does not establish that the library is unencrypted. Returning None lets the push proceed without having verified that it will preserve encryption. Stop before any changes if this lookup fails, and add a regression test asserting no writes when the encryption check cannot complete.
| encrypted = {path for path in all_projects_to_push if associated_libraries_to_push and is_pushed_encrypted(path)} | ||
| unencrypted_users = "', '".join( | ||
| path.relative_to(Path.cwd()).as_posix() for path in all_projects_to_push | ||
| if path not in encrypted and any(LeanLibraryReference(**library).path.expanduser().resolve() in encrypted |
There was a problem hiding this comment.
When there are no associated libraries, encrypted is empty but this still parses every project’s references outside the per-project error handler. That turns one bad config into a failure for the whole workspace. Skip this scan when there are no encrypted targets to check, and test that a bulk push still uploads unrelated valid projects.
|
@Martin-Molinero Decision needed: should this PR keep checking the cloud's encryption rules before a push and fix the two latest findings, or shrink to a smaller change? The PR stops The two latest findings, on 514b20e:
Reply with the option you choose, or another way to go. Reviews asked for changes 5 times since a person last commented, so the developer stopped: a comment, or adding |
Problem
lean cloud push --project <project>also pushes every library the project uses. Those library pushes never get the command's encryption options, so each one goes out without an encryption key. Take a library whose cloud project is encrypted but whose local files are plain, for example one pulled withlean cloud pull --decrypt --key. Pushing a project that uses it sends the library's plain source with an empty key, and the cloud turns off the library's encryption and stores the plain source. The command never asked to decrypt that library.Change
A push no longer decrypts a library implicitly. Before it pushes anything,
push_projectchecks the libraries it would push along with the project, including nested ones, whose cloud project is encrypted while their local files are not.--encrypt --keywith the key such a library is encrypted with in the cloud, the library is pushed with that key too. Its files go up encrypted and its cloud key stays as it is, so a project and its library pulled with--decrypt --keycan be edited and pushed back with--encrypt --key.--decrypt --keyor without options, the command fails with this error, and nothing is renamed, created or written:Libraries encrypted in the cloud but not locally would lose their cloud encryption if pushed with the project: 'Library/<name>'. Encrypt each of them locally with 'lean encrypt <library> --key' to keep it encrypted, or push it on its own with --decrypt --key to decrypt itThe cloud also refuses to link an encrypted library to a project or library pushed without encryption, but only after it has written that project's files. So the same check also refuses a push that sends a project or library without encryption when it uses a library this push sends encrypted, whether kept with the command's key or encrypted locally. Again nothing is renamed, created or written:
The cloud doesn't let projects and libraries pushed without encryption use the encrypted libraries pushed with them: 'Library/<name>'. Encrypt each of them locally with 'lean encrypt <project> --key' to push it encrypted too, or decrypt the encrypted libraries they useThis applies only to libraries pushed along with a project. Pushing a project explicitly works as before:
lean cloud push --project Library/<name>without options still writes the local state, as for any other project, and so does alean cloud pushof all projects.A push no longer sends a key the cloud project already has.
projects/updaterefuses to set a key on a project used as a library or shared with collaborators (A project used as library by other projects can not be encrypted), even the key the project already has. So the CLI couldn't push an encrypted library while keeping it encrypted, for example a library encrypted locally withlean encrypt. When the key the push would send equals the cloud project's key, the key is now left out, and the cloud keeps the project's encryption as it is. Turning encryption on (a new key) or off (an empty key) still sends the key as before. The existing check before the file-by-file push of a too-large project still compares against the cloud key.An update that sends a key, even one that fails, can change the cloud project's key. So the push now reads that cloud project again before any later push to it in the same command. This matters when two local copies share one cloud project in one
lean cloud push: the second copy now compares against the key the first one left, not the key read before.Backwards compatible: libraries that aren't encrypted in the cloud, libraries encrypted locally, and projects pushed explicitly are pushed as before.
The
--pushoption of the cloud commands in #725 pushes libraries through this samepush_projectpath, so it gets the check too.Tests
New, in
tests/components/util/test_push_manager.py:--decrypt --key, or with--encrypt --keyand another key: the push raises and makes no update. Fails without the change.--encrypt --keyand the library's key: the library's files are sent encrypted with that key, and neither update sends the key.projects.createnorprojects.updateis called, and the new library gets no cloud id.--encrypt --keyand that key: the push raises, and neitherprojects.createnorprojects.updateis called. Fails without the change.Updated:
test_cloud_push_pushes_files_one_by_one_when_a_too_large_project_keeps_its_encryption_keyandtest_cloud_push_keeps_cloud_project_encrypted_when_project_pulled_encrypted_without_key_and_encrypted_flag_givennow assert that the unchanged key isn't sent.python -m pytest -s -rs: 2947 passed, 81 skipped, 0 failedpython static_analysis.py: BUILD PASSED (the 5 unused-import warnings are the same as on master)End to end
Tested end to end against the cloud API. In each case a library is encrypted in the cloud and plain locally, for example after a push of the library on its own with
--encrypt --key, or alean cloud pull --project <project> --decrypt --key.--encrypt --key, then a project using it pushed with--encrypt --keyand the same key--decrypt --key, both edited, the project pushed with--encrypt --keyand the same keylean cloud pull --decrypt --keyshows both edits--encrypt --keyand another registered key, with--decrypt --key, or without options--encrypt --keyand the library's key, the library plain locally or encrypted locally withlean encryptlean encrypt Library/<new library> --keylean encrypt Library/<name> --key, then the project pushed with--encrypt --keylean cloud pull --project <project> --decrypt --keyrestores the library's local changelean cloud push --project Library/<name> --decrypt --key, then the project without optionsA library directory renamed to end with a period, in a project pushed without options, is refused before the directory is renamed; a unit test covers it.
A bulk
lean cloud pushof two local copies of one cloud project encrypted with a key, the plain copy first and the copy encrypted locally with the same key second:A library encrypted locally with a different key from the project's, pushed with the project using
--encrypt --key, behaves the same on master and on this branch. Both projects are pushed and linked, each with its own key, andlean cloud pull --decrypt --keywith the project's key can't decrypt the library.The case of a project shared with collaborators, which the second change also covers, wasn't run end to end. It goes through the same check in
projects/update.This change was prepared with the help of an AI assistant (Claude).