Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79944

Moodle wrong permission on Nextcloud repository, only with S3?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.4
    • Repositories
    • None
    • MOODLE_401_STABLE

      Environment with:
       
      Moodle v. 4.1
      Nextcloud Enterprise v. 27.0.2.2 with S3 Primary Storage.
      This bug seems to not been able to replicate on NAS Primary Storage.
       
      First of all, in the morning when we firstly tried to upload a file to a Nextcloud S3 primary storage as a Repository of Moodle, we've got this logs in Apache:
       
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:05 +0200] "POST /ocs/v1.php/apps/files_sharing/api/v1/shares?format=xml HTTP/1.1" 200 1829 "-" "MoodleBot/4.1 (+https://fpikaskuntzagunea.test.hezkuntza.net)"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:07 +0200] "PROPFIND /remote.php/webdav HTTP/1.1" 207 6449 "" "Moodle WebDav Client"   /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:08 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29 HTTP/1.1" 201 1155 "" "Moodle WebDav Client"  
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:08 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29 HTTP/1.1" 207 1861 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:08 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29 HTTP/1.1" 201 1155 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:08 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29 HTTP/1.1" 207 1898 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:08 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29 HTTP/1.1" 201 1153 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:09 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29 HTTP/1.1" 207 1943 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:09 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29 HTTP/1.1" 201 1147 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:09 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29 HTTP/1.1" 207 1979 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:09 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29/mod_forum HTTP/1.1" 201 1151 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:09 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29/mod_forum HTTP/1.1" 207 1985 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:10 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29/mod_forum/attachment HTTP/1.1" 201 1151 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:10 +0200] "PROPFIND /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29/mod_forum/attachment HTTP/1.1" 207 2004 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:10 +0200] "MKCOL /remote.php/webdav//System%20%28moodlev4%29/Category%20Category%201%20%28id%201%29/Course%20preuba%20nextcloud%20%28id%208%29/Forum%20foro%20discusi%C3%B3n%20%28id%2020%29/mod_forum/attachment/25 HTTP/1.1" 201 1147 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:11 +0200] "COPY /remote.php/webdav/Nextcloud.png HTTP/1.1" 500 1096 "-" "Moodle WebDav Client"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:12 +0200] "GET /core/img/logo/logo-enterprise.png?v=0 HTTP/1.1" 200 20377 "http://mail.google.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246 Mozilla/5.0"
       
      /var/log/apache2/other_vhosts_access.log:alfatec.librebit.com:80 172.20.2.5 - - [26/Sep/2023:10:04:15 +0200] "GET /core/img/logo/logo-enterprise.png?v=0 HTTP/1.1" 200 20377 "http://mail.google.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246 Mozilla/5.0"
       
      Watch out this error in Apache:

      /var/log/apache2/error.log:[Tue Sep 26 10:04:11.131987 2023] [proxy_fcgi:error] [pid 1763383:tid 140471460423424] [client 172.20.2.5:41872] AH01071: Got error 'PHP message: PHP Fatal error:  Declaration of Aws\\S3
      ObjectCopier::promise() must be compatible with GuzzleHttp\\Promise
      PromisorInterface::promise(): GuzzleHttp\\Promise
      PromiseInterface in /var/www/nextcloud/3rdparty/aws/aws-sdk-php/src/S3/ObjectCopier.php on line 82'
       
      Similar error in Nextcloud:
       
      /var/log/nextcloud/nextcloud.log:{"reqId":"ZPTbroFYkHekaVF3BZ32","level":3,"time":"Sep 26 10:04:11","remoteAddr":"185.161.117.1","user":"moodle-admin","app":"PHP","method":"COPY","url":" /remote.php/webdav/Nextcloud.png","message":"Declaration of Aws\\S3
      ObjectCopier::promise() must be compatible with GuzzleHttp\\Promise
      PromisorInterface::promise(): GuzzleHttp
      Promis
      e
      PromiseInterface at /var/www/nextcloud/3rdparty/aws/aws-sdk-php/src/S3/ObjectCopier.php#82","userAgent":"Moodle WebDav Client","version":"27.0.2.2","data":{"app":"PHP"}}
       
      Also we've made some videos:
       
      --------
       
      Video: 01_moodle-nextcloud-with-s3_failed.mp4
      https://cloud.librebit.com/s/ma7YHoE2AfFfYNk
       
      The first video shows one upload of one file "aitire.png" to Nextcloud folder "xxx" of User1.
       
      Then, in Moodle, that user gets that file from Nextcloud repository and upload it to a Moodle Forum 1.
       
      At that moment with timestamp "Sep 26 14:57:41" you can see 3 messages about "Undefined array key" {creation_time, upload_time, metadata_etag}.
       
      You can see that Moodle shows fine "Your post was succesfully added" for the upload, but if we try to download that file in Moodle Forum 1, there shows the bug about wrong permissions.
       
      After that, if we go to Nextcloud "moodle-admin" account, we can see where the file had been uploaded, on folder "39" but with wrong permissions.
       
      Hours before, we did this with another file, and as you can see in folder "37", the file "Nextcloud intro.mp4" has a lot more permissions, and it worked as expected in Moodle, so it could be downloaded in the Forum 1.
       
      --------
      Video: 02_moodle-nextcloud-with-s3_good.mp4
      https://cloud.librebit.com/s/zfRFz8K5QYy4WMt
       
      This video works fine with a file called "Nextcloud intro.mp4" already created in Nextcloud from skeleton in the account creation.
       
      --------
      Video: 03_moodle-nextcloud-with-s3_failed_strange.mp4
      https://cloud.librebit.com/s/yNptzSdEFGHqyJF
       
      This video is very strange. As you can see, it fails with a QR image, but if I rename the file in Nextcloud with name "Nextcloud intro.mp4", all goes fine... but the file that we see in Moodle is the real VIDEO, not the QR image.
       
      --------
      These errors made us conclude that files uploaded to Nextcloud (with S3 as primary storage) do not work well with the connection to Moodle, while files created through the skeleton, when creating the account, work fine. Also, the strange way of working in the third video is very strange, since a file uploaded to Nextcloud and then renamed to a skeleton file name seems to work, but not with the content of the uploaded file but with what is in the skeleton.
       
      So we think there's a misfunction between Moodle webdav and Nextcloud S3 library as this error is not reproducible in Nextcloud if we use local storage in the server instead of S3 primary storage.
       
      As you may guess, this error was not caught during POC as we used local storage in that moment. It appears with S3 primary storage.
       
      Moreover, after talking with Nextcloud Enterprise Support https://support.nextcloud.com/#ticket/zoom/49787
      they sent us a little patch to hide PHP warnings when optional CacheEntry attributes are unset, but after we've patched, files already generated through skeleton now are NOT working in Moodle neither.

      Video 04 is done with Nextcloud "Birdie.png" file, and now is giving error.
      https://cloud.librebit.com/s/kHgH94LPcAmQbi9

      Video 05 is done with a new file uploaded, also get the error.
      https://cloud.librebit.com/s/8HXrezBobCYcDSm
       
      Finally I've UNPATCHED and the original error shows ONLY when Moodle gets files UPLOADED into Nextcloud S3, not with already created through skeleton.

      Video 06 shows this behaviour:

      https://cloud.librebit.com/s/YZxYfA4SkoDXQS9

      • first part, we use the "Templates credits.md" coming from skeleton AND WORKS FINE.
      • second part, we use the recently uploaded file "Captura de pantalla..." AND FAILS.

      So their patch only hides a clue that we've got to get the origin of the bug. I think.

      So my point is, why there is no info about {creation_time,upload_time,metadata_etag} for files uploaded into Nextcloud S3 ? Is this the origin of the bug?

      The sequence could be resumed as it looks like Moodle is doing this:

      1. User shares the file with Moodle Admin
      2. Moodle Admin copies the shared file to some directory
      3. User unshares the file
      4. If you want to download the file, the Moodle Admin tries to create a share on the copied file. But this fails.

      You can see in the Nextcloud UI that you do not have sharing permissions on the uploaded (copied) files.

      This happens because Moodle does not set correct permissions on the first step, if you set no "reshare" permissions the copied file will be not sharable afterwards.

      So I recommend you to report this issue to Moodle as they have to fix the initial sharing process to include the reshare permission for the share from which they copy the file.

      The different behavior of S3 and non-S3 primary storage is reported to our backend engineers, nevertheless the root issue is the missing sharing permission on the initial share.

            Unassigned Unassigned
            capri99 capri99
            Votes:
            3 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.