Permissions issue when syncing Nextcloud snap and Jupyter server docker via external storage

Hello everyone!

I am trying to have files synced between my Nextcloud installed via snap and a docker container with Jupyterlab and I need help because I am completely lost with how to solve .

So, the setup is quite simple: I have a server with Ubuntu and I have installed Nextcloud there via snap. I also have a Jupyterlab server running on the same machine in a docker container. Now, I want to be able to access the same files via both Nextcloud and Jupyterlab (so that I can create Python notebooks both online in Jupyter, but also to be able to easily run and work with them locally via Nextcloud sync if I want more computing power).

What I have done:

  • I have created a folder, let’s call it /home/username/notebooks
  • I have create a mount point sudo mount -o bind /home/username/notebooks/ /media/nextcloud
  • Enabled external media in snap sudo snap connect nextcloud:removable-media
  • I added a local external storage /media/nextcloud in Nextcloud.
  • I have my docker container running under username user (not from root) and mount /home/username/notebooks as a volume to the docker container.
  • I have given the most relaxed possible permissions to the notebooks

ls -l in the home directory says that the notebooks folder permissions are:
drwxrwsrwx 4 username username 4096 notebooks

So far I can successfully see files in both Nextcloud and Jupyter.

However, the problem is that whenever I create any file in Nextcloud, then they are owned by user and group root:root and have -rw-r--r-- permissions, and whenever I create any file in Jupyter, they are created with username:users and have the same -rw-r--r-- permissions. Therefore, I cannot change in Nextcloud files created by Jupyter and vice-versa.

I am completely lost in the permissions and user systems of docker and snap. How can I fix that and get both of them to collaborate with each other?

Possible solutions I can see:

  • Give up and setup a nextcloud client in the docker container with a separate user with whom I only share one folder. I would like to avoid this solution if possible, because there is no headless daemon client for Nextcloud, so I will have to improvise with nextcloudcmd and cron. Also, I think this would waste resources as I will be syncing things via internet within the same server, but I am not 100% sure about that. On the other hand, if there is no other easy solution, then I will go for this one.
  • Run docker with Jupyter as root - not sure if it is good from the security point of view, especially given that I am running Jupyter notebooks there which I want to be accessible from the outside. Also, not sure if I can have only one docker container to run from root.
  • To somehow make Nextcloud snap work (i.e., create and edit files) from username user.
  • To use some Linux magic to get all new files created in this notebooks directory to be writable for the owner group by default and add both users to both groups.

I would be very thankful if someone can at least pinpoint me in the direction of how I can solve my issue, at this point I am not even sure in what technology and direction to look for the solution.

So, after looking for solutions for a while, I discovered that external storage in Nextcloud does not work exceptionally well (for me it seems to be requiring visiting the web version and checking the external folder to get files updated, which is not very convenient), so I decided to go with the easiest path - I modified GitHub - juanitomint/nextcloud-client-docker: Docker image with the Nextcloud sync client based on Alpine Linux Dockerfile for my needs and just put both jupyter server and nextcloud client into one docker-compose (but two different containers), so now both are automatically built and running. And even if someone hacks my jupyter notebooks server, they will not know anything about my nextcloud. And since I don’t have many notebooks, syncing is rather fast.

I am leaving this in case anyone ever is having similar problems to mine.

P.S. It would be nice to have a proper Nextcloud client daemon (without GUI) instead of have to run nextcloudcmd in a loop.