rclone-webui-react icon indicating copy to clipboard operation
rclone-webui-react copied to clipboard

Getting a 500 error when trying to create a Google Drive config from the GUI running in a Docker container and it doesn’t open auth window

Open imthenachoman opened this issue 2 years ago • 12 comments

What is the problem you are having with rclone?

I am running rclone gui from a Docker container. I can browse configs fine. I am trying to add one for Google Drive and I am getting a 500 error. It creates the config but never finishes the creation process. It should open a new window so I can auth the Google Drive but it never opens that window.

Run the command 'rclone version' and share the full output of the command.

/data # rclone version
rclone v1.58.0
- os/version: alpine 3.15.1 (64 bit)
- os/kernel: 5.10.28-Unraid (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.18
- go/linking: static
- go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

n/a - using GUI

The rclone config contents with secrets removed.

it is empty

A log from the command with the -vv flag

Error creating config. Error: Request failed with status code 500

Screenshots

Creating a new config:

image

Before clicking Next

image

Error after clicking Next

image

Console error after clicking Next

image

Config was created but never finished -- it didn't open a new window to auth:

image

imthenachoman avatar Mar 20 '22 22:03 imthenachoman

It seems like it's the last build of rclone that is buggy and I suppose even incompatible with the web gui. Try to download a previuos version. It was working fine for me.

redsector72 avatar Mar 27 '22 02:03 redsector72

@redsector72 Are you using it in a Docker container?

imthenachoman avatar Apr 02 '22 16:04 imthenachoman

@negative0 @ncw Sorry to bug but is this something you can help with?

imthenachoman avatar Apr 06 '22 02:04 imthenachoman

If I had to guess, I'd say the issue is here: https://github.com/rclone/rclone/blob/3425726c503f7822508071b113e1cc5492d538e7/lib/oauthutil/oauthutil.go#L637

From https://github.com/skratchdot/open-golang/:

Open a file, directory, or URI using the OS's default application for that object type.

This works fine when you're on the machine rclone is running on. But if you run rclone in a container then open won't do anything to the host machine.

Does this sound right?

So I guess rclone GUI has to intercept the open request and open it on the user's browser.

Looks like https://github.com/rclone/rclone-webui-react/blob/9ed0e9e05b1805caa57d636fb590cf3413b44437/src/views/RemoteManagement/NewDrive/NewDrive.js#L485 is where a new config is created. So I guess it makes a post request to the webserver url config/create (from https://github.com/rclone/rclone-webui-react/blob/9ed0e9e05b1805caa57d636fb590cf3413b44437/src/utils/API/endpoint.js#L87).

This, I assume, calls rclone's API: https://rclone.org/rc/#config-create.

Now, I assume that in the call to config/create the data object needs to include the authorization information from Google Drive. But I can't figure out where in the process that is supposed to be handled?

imthenachoman avatar Apr 06 '22 02:04 imthenachoman

Looking through https://rclone.org/commands/rclone_config_create/, I think the process would be to call config/create, which will return a question in JSON blob that then has to be answered in another call to config/create.

imthenachoman avatar Apr 06 '22 12:04 imthenachoman

@ncw Sorry to call you out but I'm hoping you can help me get some traction? I'm happy to modify the code but I need some guidance on how the GUI works.

I'd love to get the config create process working when running rclone in a Docker container.

imthenachoman avatar May 19 '22 14:05 imthenachoman

Is there anyone that can help me with this?

imthenachoman avatar Aug 09 '22 05:08 imthenachoman

I'd love to get the config create process working when running rclone in a Docker container.

I don't see how it can ever work.

You can't open a webbrowser window outside the container from within the container.

ncw avatar Aug 09 '22 10:08 ncw

I don't see how it can ever work. You can't open a webbrowser window outside the container from within the container.

There would need to be some small logic changes in the code. Right now, from what I can tell, when you config a remote the code opens a URL. There should be an option to create a remote and have it return a JSON. That JSON has the information needed to finish the configuration (like the URL of the page to open). The caller would take that JSON, do what is needed, and make a second call to rclone with return data to finish the config creation.

Then, the GUI would make the call using this new mechanism. It would take the JSON, send to the client (the browser) that would finish the auth, and then return the data back to rclone.

Does that make sense?

I'm happy to see how I can make those tweaks but I have some questions about the rclone base and GUI code that I need to chat about.

imthenachoman avatar Aug 09 '22 16:08 imthenachoman

Sorry, I misunderstood what you were trying to do

This problem has been solved in RCX by parsing the output of rclone config as rclone prints the URL that needs to be opened in the JSON response.

However that doesn't work when configuring things over the rc so won't work for the GUI.

So what needs to happen is that rclone returns the URL in the JSON response instead of logging it

2022/08/09 17:45:54 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=upS8NlYieyGev9BohN-hpQ

We got nearly all the way there with RCX in this issue: https://github.com/rclone/rclone/issues/3455

But that last little - "Open this brower window to continue" state has eluded us.

The config state machine for the oauth is here

https://github.com/rclone/rclone/blob/1ad22b8881ceaa6219f0bc1ae67507c74f49bdb2/lib/oauthutil/oauthutil.go#L440

So what I'd suggest is that GUI sets a config key, say config_no_open_browser and we check that here

https://github.com/rclone/rclone/blob/1ad22b8881ceaa6219f0bc1ae67507c74f49bdb2/lib/oauthutil/oauthutil.go#L553

That would probably mean splitting that state config state in half, and getting the first half to start the webserver and return the URL needed (and probably the URL to redirect to) and the second half to stop the webserver.

The redirect URL would need to point at the IP address of the docker container so rclone received the response. I think RCX runs their own webserver to do this. This might be a bit tricky to arrange.

So to sum that up - not easy - but it would be a worthwhile thing to do.

ncw avatar Aug 09 '22 17:08 ncw

I'd love to get the config create process working when running rclone in a Docker container.

I don't see how it can ever work.

You can't open a webbrowser window outside the container from within the container.

Overseer, running in Docker, opens a browser window to login with Plex.

dalepmay avatar Aug 16 '22 23:08 dalepmay

This problem has been solved in RCX

What is RCX?

So to sum that up - not easy - but it would be a worthwhile thing to do.

Agreed.

I am not completely following on everything you said, or what is mentioned in that other issue but my thought is the flow would be like this:

  1. issue command to create config passing initial options like remote type, name, etc...
  2. command would provide the remote URL that the user would need to go for auth-ing (like the actual Google Drive URL) and some token
  3. whatever issued the command would relay the URL back and wait for input of the auth token that the remote gives
  4. issue command providing token from #2 and auth token from #3

Does that make sense or do I have it completely wrong?

imthenachoman avatar Aug 17 '22 03:08 imthenachoman