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

[stable9] Setupfs before access a users keys #26820

Merged
merged 7 commits into from
Jan 20, 2017

Conversation

DeepDiver1975
Copy link
Member

@DeepDiver1975 DeepDiver1975 commented Dec 13, 2016

alternative approach for #26818

@PVince81 @felixboehm

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…he keys

@DeepDiver1975 DeepDiver1975 added this to the 9.0.7 milestone Dec 13, 2016
@PVince81
Copy link
Contributor

original issue confirmed with your hack and also LDAP + homeDirectory on stable9

@PVince81
Copy link
Contributor

This PR works for newly created shared files. Old files don't have the correct keys and can't be repaired without recreating or resharing (there is no other way).

I think setupFS and tearDown here is risky, because it removes all mount points and subsequent code might expect these to still exist. Let's try with initMountPoints instead.

}
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
$key = $this->getKey($path);
if (!empty($uid) && $uid !== $currentUser) {
\OC_Util::tearDownFS();
\OC_Util::setupFS($currentUser);
\OC\Files\Filesystem::initMountPoints($uid);
Copy link
Member Author

Choose a reason for hiding this comment

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

$currentUser

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, really? The FS of the current user is usually already setup.
What we need is setup the FS for the target user $uid. Strangely this fix works for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

To put it into perspective: let's say "user1" is logged in, so usually setupFS("user1") was already called early on. But "user1" shares a file with "user2" (or creates a file in a shared folder), so we also need to mount the home folder of "user2" to have proper access to the keys and files.

I suspect that the mounting already happens later in the sharing code, but if this enc code runs earlier than the sharing code then we need to do it too.

Copy link
Member Author

Choose a reason for hiding this comment

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

wrong turn in my brain
I guess we don't need the second block - this was used for teardowns

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll also replace empty($uid), remember that empty("0") evaluates to true...

@PVince81
Copy link
Contributor

@DeepDiver1975 I redid a test run with folder shares, file shares and also creating a file inside an already shared folder and this fix as per my modification does work. This is with LDAP and an alternative home folder.

@PVince81
Copy link
Contributor

Also retested with the hash folder hack, my fix makes it work too.

@PVince81 PVince81 modified the milestones: 9.0.8, 9.0.7 Dec 13, 2016
@PVince81 PVince81 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from 0f85d39 to bdfe726 Compare December 13, 2016 18:11
@PVince81
Copy link
Contributor

Fixed and retested with the md5 hack variant, still works.

Squash ?

@DeepDiver1975
Copy link
Member Author

Yes. Squash, merge at will and port it all around :party:

@DeepDiver1975 DeepDiver1975 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from bdfe726 to af1d6dd Compare December 14, 2016 15:16
@DeepDiver1975
Copy link
Member Author

@PVince81 squashed - merge now or later? Your call.
Will prepare ports ...

@PVince81
Copy link
Contributor

Rebase to resurrect Jenkins then squash+merge now and keep the "backport-request" label

@DeepDiver1975
Copy link
Member Author

👻

Test\Encryption\Keys\StorageTest::testGetUserKey
OC\User\NoUserException: Backends provided no user object for user1

/var/lib/jenkins/workspace/owncloud-core_core_PR-26820-5ZSS3Y2GKGCIYIEECAW4OPVKEEWW4OIQOCEPDCFQAP5744QLCREA/lib/private/files/filesystem.php:391
/var/lib/jenkins/workspace/owncloud-core_core_PR-26820-5ZSS3Y2GKGCIYIEECAW4OPVKEEWW4OIQOCEPDCFQAP5744QLCREA/lib/private/encryption/keys/storage.php:75
/var/lib/jenkins/workspace/owncloud-core_core_PR-26820-5ZSS3Y2GKGCIYIEECAW4OPVKEEWW4OIQOCEPDCFQAP5744QLCREA/tests/lib/encryption/keys/storage.php:236

@@ -70,6 +70,10 @@ public function __construct(View $view, Util $util) {
* @inheritdoc
*/
public function getUserKey($uid, $keyId, $encryptionModuleId) {
$currentUser = \OC_User::getUser();
if (!is_null($uid) && $uid !== '' && $uid !== $currentUser) {
\OC\Files\Filesystem::initMountPoints($uid);
Copy link
Member Author

Choose a reason for hiding this comment

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

@PVince81 I guess we should apply this patch to all other methods which call constructUserKeyPath with a user ....

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at the other code path within that class and it seems it would indeed be needed there.
It is not clear whether initMountPoints was already called from outside there, it's not a guarantee.
I'll add something in all the methods.

@PVince81
Copy link
Contributor

PVince81 commented Dec 16, 2016

  • add it to other code paths as well

@PVince81
Copy link
Contributor

@DeepDiver1975 I've added the init mount points in the other code paths, please check it out: 4b602f6

A quick manual test with LDAP + homeDirectory shows that it still works.

Now I don't feel comfortable merging this without having automated tests... this would require to finish/solve #26586 and also introduce a new user backend that md5's the user home to simulate this situation. Maybe that backend could be part of the "testing" app ? Or do we make it an official feature configurable in config.php ?

@PVince81
Copy link
Contributor

For now I made this PR with the md5 hack to see if the current test coverage would catch the issue: #26844

@PVince81
Copy link
Contributor

Let's first get the automated tests sorted out, I want proper coverage for this: #26844

@felixboehm
Copy link
Contributor

@PVince81 please provide this patch for 9.1

@PVince81
Copy link
Contributor

PVince81 commented Jan 9, 2017

@felixboehm here you go: #26824 (updated with the latest commit).
I retested it with the md5 hack and the fix works.

@PVince81 PVince81 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from 7312623 to 5554dc4 Compare January 11, 2017 10:13
@PVince81
Copy link
Contributor

Jenkins passed.

Since most of the code is now modified by me, need review from someone else please @jvillafanez @DeepDiver1975 @VicDeo @butonic

@jvillafanez
Copy link
Member

Same comments as #26917

@PVince81
Copy link
Contributor

Cherry-picked the test from master and replace createMock with getMock.

@jvillafanez please re-review. Thanks

@PVince81 PVince81 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from 08c45c7 to 76b1b79 Compare January 13, 2017 09:02
@PVince81
Copy link
Contributor

forgot to git add ☕️

NOW it should be ok

@jvillafanez
Copy link
Member

👍

@PVince81
Copy link
Contributor

Let's wait before merging. Need to investigate this (not-so-critical-but-still) regression #26935

@PVince81
Copy link
Contributor

Yeah, syntax error in PHP 5.4.
Will adjust when rebasing later.

@PVince81
Copy link
Contributor

PVince81 commented Jan 13, 2017

@PVince81 PVince81 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from 76b1b79 to a7882b0 Compare January 16, 2017 18:24
@PVince81
Copy link
Contributor

Need rereview, I cherry-picked backports of master to fix a regression and incomplete cases.

Vincent Petry and others added 6 commits January 19, 2017 09:57
When encryption keys are stored outside the user's homes, there is no
need to mount said homes.
Whenever a user was deleted for encryption where the keys are stored in
the home, we can ignore user existence exceptions because it means the
keys are already gone.
@PVince81 PVince81 force-pushed the setupfs-before-access-a-users-keys-stable9 branch from a7882b0 to 2ed1bc7 Compare January 19, 2017 08:57
@PVince81
Copy link
Contributor

PVince81 commented Jan 19, 2017

Rebased and removed the "preDelete" commit and cherry-picked the better fix from #26968

After all these additions, let's retest this:

  • TEST: sharing with alt home works
  • TEST: delete user works with no warnings
  • TEST: delete user works with no warnings when using alternative key storage

@PVince81
Copy link
Contributor

@PVince81
Copy link
Contributor

Integratin tests backport pending to be merged: #26985

@jvillafanez
Copy link
Member

Changes look good 👍

@PVince81 PVince81 merged commit 75c96fe into stable9 Jan 20, 2017
@PVince81 PVince81 deleted the setupfs-before-access-a-users-keys-stable9 branch January 20, 2017 09:12
@lock
Copy link

lock bot commented Aug 4, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 4, 2019
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.

4 participants