-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Moving files/folders from/to shared folders causes Encryption Errors #16419
Comments
It seems that we have the same issue (see nextcloud/desktop#1168). We're currently looking into this issue as the corresponding restores take a long time and we'd like to have this issue resolved. We're trying to reproduce this problem by creating two shared folders and moving huge subfolders between those two shared folders. One thing we've seen is that at some point the web UI issues as warning message that moving the subfolder failed. However, when watching the target folder we see that files are still moved after this message has been issued. Even after all files seem to have been moved on disk, the corresponding PHP process is still hard at work and the database is active as well. (As long as this task isn't finished, the moved files don't show up in the web UI.) As we've learned, when moving files around the Furthermore, it seems as if files get completely re-encrypted when copying or moving them between shared folder. In contrast, they "only" get re-encrypted when being copied within the same shared folder. |
We now found a reliable way that breaks the signature in 100% of our test cases. Howto:
There are some more things we found out in the meantime: We were wondering why the files got re-encrypted when moving them from one shared folder to another shared folder. The reason for the re-encryption is that the file is not really moved but it is rather copied over and then deleted. This leads to several things happening:
|
Final revelation: Encrypted files must have an We found out that Nextcloud stores the value The problem persists that moved files may be signed with other |
To be able to debug all this we have written two helpful tools by reimplementing the signature checks (and updates) of Nextcloud and by reimplementing the decryption process of Nextcloud. These are standalone scripts that need some configuration information of Nextcloud, but not the Nextcloud codebase itself:
|
Thanks for the extensive debugging, that will sure help finding and fixing the issue! |
cc @icewind1991 |
I just wanted to document some more thoughts on the design of the encryption and signature scheme:
|
To get a complete understanding of the inner workings of the default encryption module we now also implemented the support for public sharing keys, recovery keys and user keys in our nextcloud-tools. Our goal is to create a document containing our newly-gained knowledge about how the encryption works. |
We're currently in the process of testing our Nextcloud dataset with the written tools. We stumbled upon lots of files that seemingly have an
We're not sure yet where these duplicate entries come from. Even in our test installation some files have duplicate entries in the mentioned formats. |
We also found that you should not use |
Uff, yeah files:scan should be really used with care. I would argue to even disable it when encryption is on. |
It's hard to know when a file is encrypted ... it could also be just a normal file with similar headers. Thus the file:scan can't do much here. Also moving files on the hard disk is just not supported. Doing so causes always (also non-encrypted) issues, because it is from our side just guessing and files are simply just removed and newly added and thus shares are also lost. Long story short: don't move files on filesystem level if you do not want to loose metadata (like shares, encryption state, tags, activities, versions, ...). |
@MorrisJobke Don't misunderstand. This is just one thing we noticed while testing how the encryption module reacts. The problem with bad signature checks also occurs when moving files on the application level (see the mentioned text file example above). As there doesn't seem to be an extensive description of how the encryption works we have to find this out ourselves. |
@MorrisJobke @nextcloud/encryption @nickvergessen @rullzer Due to this issue why dug pretty deep into the default encryption module and gathered at lot of knowledge about the inner workings of the encryption and signature processes. We created a document called server-side-encryption.md that contains the general knowledge and tiny details that we learned. Is there the possibility to add this to the official documentation of the encryption module so that this knowledge is easier to find for others? |
I guess it could either go into https://github.com/nextcloud/documentation/blob/master/admin_manual/configuration_files/encryption_configuration.rst or in a new page next to it. |
Now that we know how to calculate the MACs and decrypt files we started looking into the actual problems of the encryption module more closely: We started by creating a reproducible failure again. To do this we created three files called
Fileid Now we try to move
Fileid Fileid Fileids The actual file containing
As you can see the actual file containing |
Some more things we learned about copying and moving files around:
This leads us to the conclusion that files seem to be handled differently depending on whether they are handled by the owner of the shared folder or by the recipient of a shared folder. Putting broken files in the trashbin and failing to properly move a file to a shared folder seem to be two different problems. One seems to be related with the ownership of the source folder while the other seems to be related to the ownership of the target folder. There are also some database inconsistencies that we saw during our tests:
|
@yahesh could you please see and mention the persons did these changes in the codebase which breaks your code? We have to ping them so that they fix what they broke asap else your hard work will just be useless :( |
Same problem here. Dataloss with moving encrypted files/folders occurred first with owncloud, years ago, and still occurs with nextcloud (we're stuck with NC 15, but as far as I can see there's no progress in newer versions). |
We started on 15 with the server side encryption and are now on 20. On our side the issue still exists. Some weeks ago a user crashed roughly 25% of all data in one moment. Luckily I could restore full file system and db backups which took me about 48 hrs restless work. But especially with this experience I fear to deactivate the server side encryption or to fresh install. Our system is hosting millions of files of like 10 years. The good thing of this event was that I now know that my backup strategy works and where to optimize it. |
I've looked into Roeland's fix in #25249 and discovered that the problem is not reproducible any more in recent Nextcloud versions, so it is likely that the fix is not needed any more as it was fixed through a different way. If you do have files with "bad signature", please run the command mentioned in https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#problems-when-downloading-or-decrypting-files for the affected files/folders to repair their signature. After that, I expect that move operations won't cause any troubles. After that, please let me know if anyone is still experiencing "bad signature" errors on files after moving. |
moving a folder structure worked fine for me in NC 20.0.10 and 21.0.4, but it used to be broken. I'll close this for now. |
Hi, I don't fully understand why this has been closed, as the issue is still there. Are you saying it has been fixed for the latest release only? If so the issue should be kept open until the patch has been backported for older (but still supported) releases. Thank you! |
NC 20.0.12 is the latest supported version and in my tests I couldn't reproduce the issue there (but could on older NC 20.0 versions), so the fix must be there already. @redtux what version are you on ? |
Hi @PVince81, thank you for your quick reply! I am using NC 21.0.3 on a Hetzner instance - apart from Nextcloud GmbH probably the biggest provider of NC instances atm. When trying to open an affected PDF inside the browser (I have kept them untouched for the last years just in case this gets fixed some day, so I could test the patch with the affected files), I get the following error:
Or are those files just unrecoverable crypto junk now that can be deleted? |
see https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#problems-when-downloading-or-decrypting-files and run it on the file in question this is only if the error in log is "bad signature", for anything else it could be a different issue |
Hi, I already tried - but it is not working…
Verifying the content of whole directory shows for every single file status The file is listed when connecting via WebDAV, but accessing (opening/downloading) it results in an error 500… |
@redtux can you check:
Depending what you find, a manual repair might be necessary as the "fix-encrypted-version" command didn't seem to work. |
Seemingly just hit the same issue on 22.2.7, seems mostly documents (and not graphic files) were affected. Will try to recover based on the answers here and update. |
I seem unable to retrieve the files, so nextcloud basically shredded a month of my teams work while moving a bunch of files from a normal (encrypted) directory to a shared one. I'd say this is rather critical, as it undermines any trust in this solution and fails at it's core functionality, |
I agree. Concerning the lost work: In case you have no external backup (you could use a service user with access to the respective folders), I hope that at least one device has not synced the data chunk (or that at least one team member has a backup) so that you can recover the files. |
@harcesz You could try to recover your files using our rescue tool. |
@harcesz This looks nice, did not know about that. The problem with this PHP script or with the SQL statement provided by @PVince81 is that those solutions only work with on-premise installations, not with hosted NextCloud instances (like Hetzner's Storage Share). In those (not so rare) cases the hoster normally just tells you not to use encryption, which IMHO really is a shame - and negatively impacts the reputation of NextCloud. |
Unfortunately this reputation is well deserved. There's a long history of new features that were announced with great fanfare upon (pre-)release (such as end-to-end encryption, virtual drive) and which receive little or no attention afterwards. When they break upon an upgrade the devs often don't react at all (even when you take the effort of identifying the author of the PR that broke the feature). I guess it has to do with the business model where paying customers do not use these features. It makes perfect sense not to dedicate paid dev time to such issues. But it would be better if Nextcloud made a clear statement about which features are deprecated so that users know what to reasonably expect. As one of the authors of the encryption stream wrapper I already indicated that I am no longer supporting any code I contributed to the encryption feature of Nextcloud. In current circumstances it's simply not possible to fix any issues that arise (I tried to but hit the wall when I needed feedback from the devs). |
Why is this issue closed when people are still reporting it as a reproduce-able bug? |
@shibacomputer Who reported this as a reproducible bug? The last comments in this issue are one year old now. Files that broke due to this bug aren't fixed automagically but need to be fixed through the introduced |
Under Nextcloud official policy, is advising users to use system scripts to mitigate data loss considered a successful bugfix?
Yes, and the issue was reproducible a year ago. Outside of a bunch of php scripts, has the actual underlying issue been fixed? Because the comments from a year ago suggest that Nextcloud encryption should not be enabled. |
From personal experience the issue discussed here is not reproducible anymore. The mentioned solutions were developed to help those people who encountered the issue before it was fixed. |
Hi @yahesh, could you elaborate a bit on this? It might help others stumbling through this issue. Are you referring to new installations? As has been explained by the issue closer before, the issue is not automatically fixed for old files, and there is no UI element for doing so (nor is such a tool or app planned upstream from what I understand). In case your files are being stored on an external cloud hosted by a third party like Hetzner, you might ask them to run an occ script or to make manual changes to the database, but I am afraid they will just say no (for understandable reasons). So while the bug might have been fixed for newly created files, I cannot confirm that the issue is not reproducible anymore - nor did the issue closer claim so. Therefore I'd be interested in your experience, as this might help others - and as such could increase the user experience with Nextcloud for a lot of people and enterprises that ran into this issue in the past. Thank you a lot in advance! |
@redtux Reproducibility refers to that moving files between shared folders doesn't break them anymore. If it still does, then please say so. Never in my life as a software developer did non-reproducibility mean that already-broken data are magically fixed. How those data can be fixed has been mentioned several times now. If your supplier is unwilling to do it, then you probably want to choose a different one or operate your critical applications yourself. As I'm not paid to provide Nextcloud support, I don't feel obliged to elaborate much more on this topic. There are enough of my comments in this issue that go into great detail how this bug was tracked down and fixed as well as how broken files can be recovered. |
Okay, this might have been a misunderstanding on my side then. I can confirm that encrypted files are not "broken" anymore when moved as explained. NB: The remaining "issue" is (or might be) that old files can only be repaired if you have an on-premise installation or can convince the admin to do a risky operation on their system. Maybe sharing the files via federation and running the script on the remote Nextcloud instance might work. I shall try this out. Btw I fully understand the situation and I am not complaining that the issue has been closed. I just misunderstood your claim I guess, so thank you for the clarification. |
Steps to reproduce
Expected behaviour
Folder should move without errors
Actual behaviour
Encryption errors
Server configuration
Operating system: Debian 9
Web server: NGINX
Database: MariaDB, Redis
PHP version: 7.3
Nextcloud version: 16.0.3
Updated from an older Nextcloud/ownCloud or fresh install: fresh
Where did you install Nextcloud from: latest archive
Signing status:
Signing status
List of activated apps:
App list
Nextcloud configuration:
Config report
Are you using external storage, if yes which one: no
Are you using encryption: yes
Are you using an external user-backend, if yes which one: no
Client configuration
Browser: Chrome
Operating system: Ubuntu 19.04
Logs
Nextcloud log GUI
Nextcloud log
The text was updated successfully, but these errors were encountered: