northsea4 / mdcx-docker

在Docker容器中运行 MDCX,并通过Web界面或远程桌面进行控制。Run MDCX in a Docker container, accessible and controllable via a web interface or remote desktop.
GNU General Public License v3.0
619 stars 78 forks source link

webtop-base镜像,当使用非默认的RDP_PORT时,不能通过web方式访问 #10

Closed northsea4 closed 1 year ago

northsea4 commented 1 year ago

复现

RDP_PORT=3390

页面会显示: Error Connecting to Desktop {"code":519,"message":"Aborted. See logs."}

日志

test  | [2023-03-05 21:04:45] [Connection 3]  Client connection open
test  | [2023-03-05 21:04:45] [Connection 3]  Opening guacd connection
test  | [2023-03-05 21:04:45] [Connection 3]  guacd connection open
test  | [2023-03-05 21:04:45] [Connection 3]  Selecting connection type: rdp
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 6.select,3.rdp;
test  | guacd[198]: INFO:   Creating new client for protocol "rdp"
test  | guacd[198]: INFO:   Connection ID is "$306d850b-7567-46cd-bac7-468b86c93f11"
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 4.size,4.1512,13.776?undefined,2.96;
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 5.audio,9.audio/L16;
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 5.video;
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 5.image;
test  | [2023-03-05 21:04:45] [Connection 3]  Server sent handshake: 4.args,13.VERSION_1_1_0,8.hostname,4.port,6.domain,8.username,8.password,5.width,6.height,3.dpi,15.initial-program,11.color-depth,13.disable-audio,15.enable-printing,12.printer-name,12.enable-drive,10.drive-name,10.drive-path,17.create-drive-path,7.console,13.console-audio,13.server-layout,8.security,11.ignore-cert,12.disable-auth,10.remote-app,14.remote-app-dir,15.remote-app-args,15.static-channels,11.client-name,16.enable-wallpaper,14.enable-theming,21.enable-font-smoothing,23.enable-full-window-drag,26.enable-desktop-composition,22.enable-menu-animations,22.disable-bitmap-caching,25.disable-offscreen-caching,21.disable-glyph-caching,16.preconnection-id,18.preconnection-blob,8.timezone,14.recording-path,14.recording-name,24.recording-exclude-output,23.recording-exclude-mouse,22.recording-include-keys,21.create-recording-path,13.resize-method,18.enable-audio-input,9.read-only,16.gateway-hostname,12.gateway-port,14.gateway-domain,16.gateway-username,16.gateway-password,17.load-balance-info
test  | [2023-03-05 21:04:45] [Connection 3]  Sending opCode: 7.connect,0.,9.127.0.0.1,4.3802,0.,0.,0.,4.1512,13.776?undefined,2.96,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,12.en-us-qwerty,3.any,4.true,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,14.display-update,0.,0.,0.,0.,0.,0.,0.,0.;
test  | guacd[302]: INFO:   Security mode: Negotiate (ANY)
test  | guacd[302]: INFO:   Resize method: display-update
test  | guacd[302]: INFO:   User "@b6d017dd-46c1-4781-ab04-8ef00387a047" joined connection "$306d850b-7567-46cd-bac7-468b86c93f11" (1 users now present)
test  | guacd[302]: INFO:   Loading keymap "base"
test  | guacd[302]: INFO:   Loading keymap "en-us-qwerty"
test  | guacd[302]: ERROR:  Error connecting to RDP server
test  | guacd[302]: INFO:   User "@b6d017dd-46c1-4781-ab04-8ef00387a047" disconnected (0 users remain)
test  | guacd[302]: INFO:   Last user of connection "$306d850b-7567-46cd-bac7-468b86c93f11" disconnected
test  | [2023-03-05 21:04:45] [Connection 3]  Closing connection with error:  Error: not opened
test  |     at WebSocket.send (/gclient/node_modules/ws/lib/WebSocket.js:218:38)
test  |     at ClientConnection.send (/gclient/node_modules/guacamole-lite/lib/ClientConnection.js:125:24)
test  |     at GuacdClient.sendBufferToWebSocket (/gclient/node_modules/guacamole-lite/lib/GuacdClient.js:172:35)
test  |     at GuacdClient.processReceivedData (/gclient/node_modules/guacamole-lite/lib/GuacdClient.js:163:14)
test  |     at Socket.emit (node:events:513:28)
test  |     at addChunk (node:internal/streams/readable:315:12)
test  |     at readableAddChunk (node:internal/streams/readable:289:9)
test  |     at Socket.Readable.push (node:internal/streams/readable:228:10)
test  |     at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
test  | [2023-03-05 21:04:45] [Connection 3]  Closing guacd connection
test  | [2023-03-05 21:04:45] [Connection 3]  Client connection closed
test  | guacd[198]: INFO:   Connection "$306d850b-7567-46cd-bac7-468b86c93f11" removed.

排查

提供web访问服务的是一个叫gclient的应用。 该应用的启动脚本(app.js):

// LinuxServer Guacamole Client

//// Env variables ////
var CUSTOM_PORT = process.env.CUSTOM_PORT || 3000;
var CUSTOM_USER = process.env.CUSTOM_USER || 'abc';
var PASSWORD = process.env.PASSWORD || 'abc';
var RDP_HOST = process.env.RDP_HOST || '127.0.0.1';
var RDP_PORT = process.env.RDP_PORT || '3389';

~~初步怀疑,通过docker设置的环境变量(当然包含RDP_PORT),并没有传递到gclient运行的环境中。 即process.env.RDP_PORT为空,所以gclient就取了默认的3389,导致不能通过web访问。~~

~~docker exec -it test bash进入容器,使用printenv查看环境变量,可以看到.env里的环境变量都在列表里。 但是,通过RDP连接到容器里的ubuntu,在konsole里使用printenv,却看不到.env里的环境变量。~~

northsea4 commented 1 year ago

犯了低级错误。 分析:

  1. RDP_PORT是写在.env文件里的,然后docker-compose.yml文件里使用env_file指定了.env文件,也就是这个原本只是用来作为映射宿主机端口的环境变量,同时也被映射到了容器内;
  2. gclient实际连接的是「容器环境内的RDP端口(3389)」,而不是「映射到宿主机的RDP端口」,而因为第一点,导致gclient连接到了一个错误的端口(3390)。

解决: 避免环境变量污染。 把.env文件里的RDP_PORT改名为RDP_LISTEN_PORThttps://github.com/northsea4/mdcx-docker/commit/79c880b00234c94cd4f87fe93ff2fa775ec73409