Repository navigation
Feat/federated sharing - #8184
luka-nextcloud wants to merge 12 commits into
Conversation
|
🐢 Performance warning. |
9af44d8 to
e176ad6
Compare
e176ad6 to
1eca4c9
Compare
|
🐢 Performance warning. |
|
@CarlSchwan @come-nc I would need advice from experts of files_sharing app: |
1eca4c9 to
38e34df
Compare
|
🐢 Performance warning. |
|
🐢 Performance warning. |
8c7bc98 to
866cdf7
Compare
|
🐢 Performance warning. |
866cdf7 to
a3bce6f
Compare
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
fdeff1a to
2be9ceb
Compare
benjaminfrueh
left a comment
There was a problem hiding this comment.
@luka-nextcloud thanks for working on this! I left some comments, mostly about the attachment part.
One more general thing: the PR doesn't add tests for the new federation code yet. It would be great to have some.
The PR description is still empty. Could you add a short summary of what's included and how to test it?
| if (count($files) === 0) { | ||
| // Retry later, maybe the share is not yet mounted | ||
| $this->jobList->add(ScanFederatedAttachment::class, [ | ||
| 'cardId' => $cardId, | ||
| 'shareId' => $shareId, | ||
| 'userId' => $userId, | ||
| ]); | ||
|
|
||
| // Scan the files to make sure the share is mounted and the files are available | ||
| exec('php ' . \OC::$SERVERROOT . '/occ files:scan --path="/' . $userId . '/files' . $externalShare->getMountpoint() . '"'); | ||
| return; | ||
| } |
There was a problem hiding this comment.
What's the reason for occ files:scan here? Is it because the share isn't visible yet? I would like to understand the case where getById() comes back empty.
Either way I think we should avoid exec() here as the mount point comes from the remote share name and goes into the shell command unescaped, so a file name could lead to shell injection.
We could run the storage scanner directly and only re-queue the job if the file still isn't found afterwards:
| if (count($files) === 0) { | |
| // Retry later, maybe the share is not yet mounted | |
| $this->jobList->add(ScanFederatedAttachment::class, [ | |
| 'cardId' => $cardId, | |
| 'shareId' => $shareId, | |
| 'userId' => $userId, | |
| ]); | |
| // Scan the files to make sure the share is mounted and the files are available | |
| exec('php ' . \OC::$SERVERROOT . '/occ files:scan --path="/' . $userId . '/files' . $externalShare->getMountpoint() . '"'); | |
| return; | |
| } | |
| if (count($files) === 0) { | |
| $node->getStorage()->getScanner()->scan($node->getInternalPath()); | |
| $files = $userFolder->getById($node->getId()); | |
| } | |
| if (count($files) === 0) { | |
| // Retry later, maybe the share is not yet mounted | |
| $this->jobList->add(ScanFederatedAttachment::class, [ | |
| 'cardId' => $cardId, | |
| 'shareId' => $shareId, | |
| 'userId' => $userId, | |
| ]); | |
| return; | |
| } |
In general it's better not to call occ via exec() from app code, since the php binary might not be available or could be on a different path, exec() may be disabled and failures go unnoticed.
| $qb->select('id', 'accepted', 'user') | ||
| ->from('share_external') | ||
| ->where($qb->expr()->eq('refresh_token', $qb->createNamedParameter($shareToken))) | ||
| ->andWhere($qb->expr()->eq('remote', $qb->createNamedParameter($remote . '/'))) | ||
| ->setMaxResults(1); |
There was a problem hiding this comment.
This only looks up the share by token and remote, not by user. So a remote server could send the token of a share that belongs to another user here and it would get accepted and mounted in that users files even if they are not part of the board.
Could we also check the user? In getRemoteFile() it should be the current user. In acceptRemoteAttachment() we could at least check that the user the share belongs to is part of the board.
| $share->setSharedBy($attachmentShare->getShareOwner()); | ||
| $share->setShareOwner($attachmentShare->getShareOwner()); | ||
|
|
||
| $createdShare = $this->shareManager->createShare($share); |
There was a problem hiding this comment.
These shares are only removed when the attachment is deleted. If a remote participant leaves or is removed from the board they keep access to the files. Could we also remove them in that case?
| // check for users | ||
| foreach ($acls as $acl) { | ||
| if ($acl->getType() === Acl::PERMISSION_TYPE_USER && $acl->getParticipant() === $userId) { | ||
| if (in_array($acl->getType(), [Acl::PERMISSION_TYPE_USER, Acl::PERMISSION_TYPE_REMOTE]) && $acl->getParticipant() === $userId) { |
There was a problem hiding this comment.
This now also matches remote ACLs by participant ID. Since local user IDs can contain @, a local user whose ID is the same as a remote participants cloud ID (e.g. user1@other.server) would get that remote participants permissions. Could we keep remote ACLs out of userCan() and handle the federated case separately?
| $remote = substr($externalShare->getRemote(), 0, strrpos($externalShare->getRemote(), '/')); | ||
| $federatedId = $externalShare->getOwner() . '@' . $remote; |
There was a problem hiding this comment.
This builds the cloud ID as user@https://nextcloud.local (with the protocol), but the board ACL has user@nextcloud.local. So the permission check can fail and it throws Card not found and attachments might not show up. Could we use the cloud ID manager instead?
| $remote = substr($externalShare->getRemote(), 0, strrpos($externalShare->getRemote(), '/')); | |
| $federatedId = $externalShare->getOwner() . '@' . $remote; | |
| $federatedId = $this->cloudIdManager->getCloudId($externalShare->getOwner(), $externalShare->getRemote())->getId(); |
| #[PublicPage] | ||
| public function getAll(int $cardId, ?int $boardId = null): DataResponse { | ||
| $this->ensureLocalBoard($boardId); | ||
| $board = $this->boardService->find($boardId, false); |
There was a problem hiding this comment.
boardId is optional but find() is now always called with it, so requests without boardId fail with a 500. This is potentially a breaking API change and could affect existing clients. Could we keep the if ($boardId) check from ensureLocalBoard() here and in create()/delete()? Same in CardOcsController::update(), where boardId became required.
Since this check is repeated in a lot of controllers now, maybe a small helper like BoardService::findExternalBoard(?int $boardId): ?Board (returning the board only if it's federated) would make this simpler and avoid missing the null check again.
| $this->jobList->add(ScanFederatedAttachment::class, [ | ||
| 'cardId' => $cardId, | ||
| 'shareId' => $shareId, | ||
| 'userId' => $userId, | ||
| ]); |
There was a problem hiding this comment.
This re-queues the job without a limit, so if the file never shows up (e.g. the remote is gone), it would retry on every cron run forever. If the retry is needed, could we add an attempt counter to the arguments and stop after a few tries?
| 'shareToken' => $externalShare ? $externalShare->getRefreshToken() : null, | ||
| ]); | ||
| } else { | ||
| $shareToken = $this->ensureFederatedAttachmentShare($share, $node, $requestUserId); |
There was a problem hiding this comment.
With this the GET for the attachment list creates and accepts shares on the first load and mounts them again on every load (mountExternalShare() in DeckShareProvider::ensureAcceptRemoteShare()). With the 5-second polling this repeats while the card is open.
What do you think about skipping the mount when it's already set up and stopping the polling after a while if an attachment doesn't become available?
| private IL10N $l, | ||
| private ITimeFactory $timeFactory, | ||
| private IMimeTypeLoader $mimeTypeLoader, | ||
| private ExternalShareManager $externalShareManager, |
There was a problem hiding this comment.
Since DeckShareProvider is injected in a lot of places this makes Deck stop working entirely when files_sharing is disabled, even for local boards. Could we move the federated share logic into a separate service thats only loaded when needed?
| return $externalShare; | ||
| } | ||
|
|
||
| public function mountExternalShare(ExternalShare $externalShare, IUser $user): ExternalShareMount { |
There was a problem hiding this comment.
mountExternalShare() builds the mount manually using files_sharing internals so it could break when files_sharing changes. Instead files_sharing could mount the accepted share itself by setting up the users filesystem again with OCP\Files\ISetupManager injected:
$this->setupManager->tearDown();
$this->setupManager->setupForUser($user);
Summary
TODO
Checklist