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

OCM Services #39574

Merged
merged 3 commits into from
Sep 20, 2023
Merged

OCM Services #39574

merged 3 commits into from
Sep 20, 2023

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Jul 26, 2023

Resolves #39001

  • models IOCMProvider and IOCMResource to manage the OCM discovery API,
  • replacing PHP file ocm-provider/index.php with the integration of OCMController in core/routes.php,
  • Local OCM Provider can be set [1]
  • cloud_federation_ali's capabilities updated to use OCMProvider,
  • OCMDiscoveryService to centralize OCM Discovery Services,
  • switching old call to ocm endpoint's using OCMDiscoveryService
  • adding ocm discovery to the background job FederatedSharesDiscoverJob
  • allow federation to accept self-signed certificates [2]
  • compat 1.0-proposal1 and 1.0
  • tests

[1] ./occ config:app:set core ocm_providers --value '\OCA\CloudFederationAPI\Capabilities' (default)
[2] 'sharing.federation.allowSelfSignedCertificates' => true, in config/config.php

lib/private/OCM/Model/OCMProvider.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMProvider.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the fix/noid/ocm-controller branch 3 times, most recently from 272c067 to 457cce5 Compare July 27, 2023 17:06
@ArtificialOwl ArtificialOwl changed the title [wip] ocm controller OCM Services Jul 27, 2023
@ArtificialOwl ArtificialOwl marked this pull request as ready for review July 27, 2023 17:52
@AndyScherzinger
Copy link
Member

also looping in @glpatcern

@AndyScherzinger
Copy link
Member

/backport to stable27

@AndyScherzinger
Copy link
Member

/backport to stable26

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.

I also agree with @Altahrim that json_* calls should throw on error.

lib/public/OCM/IOCMResource.php Outdated Show resolved Hide resolved
lib/public/OCM/IOCMResource.php Outdated Show resolved Hide resolved
lib/public/OCM/IOCMResource.php Outdated Show resolved Hide resolved
core/Controller/OCMController.php Outdated Show resolved Hide resolved
lib/private/OCM/Model/OCMProvider.php Outdated Show resolved Hide resolved
lib/private/OCM/Model/OCMProvider.php Outdated Show resolved Hide resolved
Comment on lines 138 to 139
&& parse_url($this->url, PHP_URL_HOST) !==
parse_url($this->getEndPoint(), PHP_URL_HOST)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

it confirms the generated object fit the documentation, based on required values on some parameters.

lib/private/OCM/Model/OCMProvider.php Outdated Show resolved Hide resolved
lib/private/OCM/Model/OCMProvider.php Outdated Show resolved Hide resolved
lib/private/OCM/OCMDiscoveryService.php Outdated Show resolved Hide resolved
apps/cloud_federation_api/lib/Capabilities.php Fixed Show resolved Hide resolved
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
apps/cloud_federation_api/lib/Capabilities.php Outdated Show resolved Hide resolved
lib/private/OCM/Model/OCMProvider.php Outdated Show resolved Hide resolved
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
lib/private/OCM/Model/OCMResource.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the fix/noid/ocm-controller branch 3 times, most recently from a9c93d4 to 88a5fc3 Compare August 11, 2023 10:52
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
@ArtificialOwl ArtificialOwl added the 4. to release Ready to be released and/or waiting for tests to finish label Sep 20, 2023
@blizzz blizzz merged commit 4954c9f into master Sep 20, 2023
39 checks passed
@blizzz blizzz deleted the fix/noid/ocm-controller branch September 20, 2023 18:16
@glpatcern
Copy link

Glad to see this was merged. What are your plans for a backport to Nextcloud 27 and 26?

@backportbot-nextcloud
Copy link

The backport to stable27 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable27
git pull origin stable27

# Create the new backport branch
git checkout -b fix/foo-stable27

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123

# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable27

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

@backportbot-nextcloud
Copy link

The backport to stable26 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable26
git pull origin stable26

# Create the new backport branch
git checkout -b fix/foo-stable26

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123

# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable26

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

@provokateurin provokateurin mentioned this pull request Sep 22, 2023
4 tasks
This was referenced Sep 22, 2023
@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label Sep 29, 2023
@ChristophWurst
Copy link
Member

Adds new APIs to lib/public so we need documentation.

@nickvergessen
Copy link
Member

Seems like

$content .= "\n RewriteCond %{REQUEST_FILENAME} !/(ocm-provider|ocs-provider|updater)/";
should have been adjusted as well and we need to trigger it during the update.

Additionally this breaks servers with index.php/… routes (default) ❓
The endpoint used to be /ocm-provider and with clean urls it still is. But when the server uses index.php/… routes, it is now actually moved to index.php/ocm-provider ?

Also https://docs.nextcloud.com/server/stable/admin_manual/installation/nginx.html need adjusting (and therefore needs to be mentioned in https://docs.nextcloud.com/server/stable/admin_manual/release_notes/upgrade_to_27.html

Since this was also backported to 26 (😕 ) also https://docs.nextcloud.com/server/stable/admin_manual/release_notes/upgrade_to_26.html needs to be adjusted.
It's very unfortunate to have a huge massive change like this in a normal patch release.

cc @sorbaugh

@sorbaugh
Copy link
Contributor

@nickvergessen huge appreciation for leading the debugging effort 🙏 Will align with @ArtificialOwl to get this dealt with.

@ArtificialOwl
Copy link
Member Author

Seems like

$content .= "\n RewriteCond %{REQUEST_FILENAME} !/(ocm-provider|ocs-provider|updater)/";

should have been adjusted as well and we need to trigger it during the update.

If #40745 resolves the issue, as it add a line to the original .htaccess, we might not need to trigger anything.

Additionally this breaks servers with index.php/… routes (default) ❓ The endpoint used to be /ocm-provider and with clean urls it still is. But when the server uses index.php/… routes, it is now actually moved to index.php/ocm-provider ?

I were not able to reproduce this issue with patched instance.
Previously, default setup were fine and I could only reproduce the reported issue on an instance with configured htaccess.RewriteBase

Also https://docs.nextcloud.com/server/stable/admin_manual/installation/nginx.html need adjusting (and therefore needs to be mentioned in https://docs.nextcloud.com/server/stable/admin_manual/release_notes/upgrade_to_27.html

I am not even a user of nginx, i require help on this task; but it might just be an adjustment on a comment section.

@nickvergessen
Copy link
Member

I am not even a user of nginx, i require help on this task; but it might just be an adjustment on a comment section.

Me neither, but basically you replicate the change from htaccess and the Setup class into the docs. All needed patterns should be there already.

@kesselb
Copy link
Contributor

kesselb commented Nov 1, 2023

Additionally this breaks servers with index.php/… routes (default) ❓
The endpoint used to be /ocm-provider and with clean urls it still is. But when the server uses index.php/… routes, it is now actually moved to index.php/ocm-provider ?

Yep, also reported via support.

I fear this pull request unintentional added hard requirement for apache's mod_rewrite.

@kesselb
Copy link
Contributor

kesselb commented Nov 1, 2023

Yep, also reported via support.

I fear this pull request unintentional added hard requirement for apache's mod_rewrite.

Sorry, I mixed something up.

The new ocm-provider should also work without mod_rewrite.
That's done by using ErrorDocument 404 /index.php/error/404.
To allow overriding ErrorDocument in .htaccess we need at least AllowOverride FileInfo.

@AndyScherzinger
Copy link
Member

So ignore your comment or something we need to take action on @kesselb

@nickvergessen
Copy link
Member

I have the issue every time on my dev instance. federation is not working until I ran occ maintenance:update:htaccess after installing the server.

@nickvergessen
Copy link
Member

The following patch makes it work again:

diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php
index ea2f0dd7575..4e2a559ce8a 100644
--- a/lib/private/Federation/CloudFederationProviderManager.php
+++ b/lib/private/Federation/CloudFederationProviderManager.php
@@ -116,6 +116,7 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager
                try {
                        $ocmProvider = $this->discoveryService->discover($cloudID->getRemote());
                } catch (OCMProviderException $e) {
+                       $this->logger->debug($e->getMessage(), ['exception' => $e]);
                        return false;
                }
 
diff --git a/lib/private/OCM/OCMDiscoveryService.php b/lib/private/OCM/OCMDiscoveryService.php
index ac9bf2a3965..10d460b34da 100644
--- a/lib/private/OCM/OCMDiscoveryService.php
+++ b/lib/private/OCM/OCMDiscoveryService.php
@@ -105,6 +107,9 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
                                'exception' => $e,
                                'remote' => $remote
                        ]);
+                       if (!str_ends_with($remote, '/index.php')) {
+                               return $this->discover($remote . '/index.php', $skipCache);
+                       }
                        throw new OCMProviderException('error while requesting remote ocm provider');
                }
 

@nickvergessen
Copy link
Member

I'm not sure what exactly ErrorDocument 404 /index.php/error/404 does, but yeah with that line in .htaccess the request seems to work.

@nickvergessen
Copy link
Member

Simply always requesting index.php also works (tested with our instance and locally), so I sent that as a patch in #41234

@kesselb
Copy link
Contributor

kesselb commented Nov 2, 2023

I'm not sure what exactly ErrorDocument 404 /index.php/error/404 does, but yeah with that line in .htaccess the request seems to work.

It tells apache2 to forward a 404 error to our index.php to handle it.
Our implementation then maps the request to the actual ocm-controller.

I haven't heard back from the customer, but I assume that they have AllowOverride None and therefore the ErrorDocument in .htaccess has no effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews 4. to release Ready to be released and/or waiting for tests to finish backport-request enhancement pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: accessing OCM federated shares does not seem to be compliant to OCM specs