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

Fix encryption wrapper not seen by groupfolder cache #2942

Merged
merged 3 commits into from
Aug 22, 2024

Conversation

danxuliu
Copy link
Member

Fixes #2909

Besides the fix itself this pull request also adds E2E tests related to the issue (although it would have been better if they were integration tests, but those were not setup yet in the groupfolders app).

Jail wrappers reuse the cache of the wrapped storage even if another storage is explicitly given. Due to that, when the cache is got from an storage and that storage has a Jail all the wrappers above it are not known to the cache, and only those wrapped by the Jail are taken into account.

In general that works fine, as in most cases the cache does not need to know the details of a storage. However, it needs to know if an Encryption wrapper is present in the storage when moving files into it, as the file cache explicitly clears the encrypted flag when moving a file from an encrypted storage to a non encrypted storage.

When encryption is enabled the Encryption wrapper is applied on the storage of the GroupMountPoint. As that storage internally has a Jail, even if the cache is got on the outer storage wrapper the cache does not know about the Encryption wrapper, only about the storage wrapped by the Jail, so all files moved from an encrypted storage to an encrypted groupfolder ended wrongly marked as not encrypted.

To solve that now the Jail used by groupfolders does not reuse the inner cache when encryption is enabled, and instead passes the given storage. This is applied only when encryption is enabled, as reusing the inner cache was done as a performance optimization.

Note that it does not seem to be possible to move the Encryption wrapper below the Jail, as the Encryption constructor requires a mount point, and the GroupMountPoint storage includes the Jail (but maybe I am missing something :-) ).

An alternative fix would be, in server, adding an optional parameter to Jail wrappers to not reuse the internal cache and then, in groupfolders app, disable reusing the internal cache when encryption is enabled. This would make possible to easily adjust the behaviour if problematic also in other Jail uses.

However, note that reusing the inner cache when encryption is enabled does not seem to be a problem when using shared folders (at least when trying with just a folder shared by another user, maybe there are some fancy scenarios in which it fails too, I do not know 🤷), as in that case, although SharedStorage is a Jail, it is created with a null storage and then initialized when needed to wrap the storage of the shared file owner, which is already fully setup and therefore already includes an Encryption wrapper.

Independently of that, it is worth noting that, unlike other storage wrappers, GroupFolderStorage persists the Cache object once got (by default storage wrappers get it from the wrapped storage every time). Therefore, if a cache was got on the GroupFolderStorage before it was wrapped with the Encryption wrapper that cache would not seen the Encryption wrapper even with neither of the fixes.

However, as the storage passed to the GroupMountPoint constructor will be wrapped as needed (for example, to add the Encryption wrapper) and the outer wrapper will be the storage set in the GroupMountPoint that should not be a problem (unless the constructor of GroupMountPoint or MountPoint is eventually modified to explicitly or implicitly get the cache before wrapping the storage).

@danxuliu danxuliu added bug 3. to review Items that need to be reviewed labels Apr 30, 2024
@danxuliu danxuliu requested a review from come-nc April 30, 2024 11:42
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Awesome work and investigation, thank you!

I’m pondering just reverting the perf optimisation on jail if it was the source of the problem, but I’ll let @icewind1991 decide on that.

@come-nc come-nc force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch from e91aae1 to 51ab0c3 Compare May 2, 2024 12:58
@danxuliu
Copy link
Member Author

While it is decided whether this should be fixed instead in server or not, would it be possible to merge the fix in groupfolders (including backports) and release new versions? :-)

Note that if in the end it is fixed in server that should not be a problem, as the fix here should also work without problems with the fix in server; it would just need to be reverted once no longer needed, but it should not cause an incompatibility due to having a non-reverted groupfolders version on a fixed server version, so it would not require an immediate groupfolders release once/if the fix is applied on server.

@icewind1991 icewind1991 force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch from 51ab0c3 to ab2e25b Compare June 19, 2024 14:28
@come-nc
Copy link
Contributor

come-nc commented Jun 20, 2024

Error: lib/Mount/GroupFolderEncryptionJail.php:42:14: UndefinedClass: Class, interface or enum named OC\Files\Cache\Wrapper\CacheJail does not exist (see https://psalm.dev/019)
-----------------------------
1 errors found
------------------------------

You need to add CacheJail to the stubs because it’s not part of OCP.

@danxuliu
Copy link
Member Author

You need to add CacheJail to the stubs because it’s not part of OCP.

Done, thanks for the clarification.

The Cypress failures are unrelated to this pull request, so I opened another one to adjust the sidebar data attribute name to changes in server.

@danxuliu
Copy link
Member Author

/backport to stable29

@danxuliu
Copy link
Member Author

/backport to stable28

@come-nc come-nc force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch from 2194ebb to 1bcae43 Compare June 24, 2024 07:39
@icewind1991 icewind1991 force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch 2 times, most recently from 6e4377b to ef1a767 Compare July 26, 2024 15:44
@icewind1991 icewind1991 force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch from ef1a767 to ecc780e Compare August 8, 2024 16:43
These tests should be written as integration tests instead, but for
practical reasons, as the integration tests have not been setup yet in
the groupfolders app, they were written as E2E tests.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Jail wrappers reuse the cache of the wrapped storage even if another
storage is explicitly given. Due to that, when the cache is got from an
storage and that storage has a Jail all the wrappers above it are not
known to the cache, and only those wrapped by the Jail are taken into
account.

In general that works fine, as in most cases the cache does not need to
know the details of a storage. However, it needs to know if an
Encryption wrapper is present in the storage when moving files into it,
as the file cache explicitly clears the "encrypted" flag when moving a
file from an encrypted storage to a non encrypted storage.

As the Encryption wrapper of groupfolders was not known to the cache all
files moved from an encrypted storage to an encrypted groupfolder ended
wrongly marked as not encrypted.

To solve that now the Jail used by groupfolders does not reuse the inner
cache when encryption is enabled, and instead passes the given storage.
This is applied only when encryption is enabled, as reusing the inner
cache was done as a performance optimization.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
@danxuliu danxuliu force-pushed the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch from ecc780e to f56662d Compare August 19, 2024 11:12
@danxuliu
Copy link
Member Author

I have rebased on latest master, adjusted the license headers and changed some quotes in the tests from ` to ' (as no substitution was needed).

The E2E encryption failures are unrelated to this pull request (they can be reproduced on master). They are a regression introduced in nextcloud/server#47044.

@danxuliu
Copy link
Member Author

/backport to stable30

@danxuliu
Copy link
Member Author

After the fix in nextcloud/server#47346 CI is finally green 🎉 Would it be OK to merge it? :-)

@come-nc come-nc merged commit a0a34e5 into master Aug 22, 2024
49 checks passed
@come-nc come-nc deleted the fix-encryption-wrapper-not-seen-by-groupfolder-cache branch August 22, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Items that need to be reviewed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Files moved into an encrypted groupfolder are no longer decrypted when needed
3 participants