[GH-ISSUE #3633] stcp优雅的使用方式应该是怎样的? #2897

Closed
opened 2026-05-05 13:52:18 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @zhufeng on GitHub (Sep 28, 2023).
Original GitHub issue: https://github.com/fatedier/frp/issues/3633

Bug Description

目前的环境共有1个frps,2个frpc,分别为frpc1( linux/mips, v0.45.0) 以及frpc2( win/amd64, v0.51.2)。

在frpc1中开启了stcp,配置如下:

[common]
...
user = frpc1

[web_http_stcp]
type = stcp
sk = ***
local_ip = 127.0.0.1
local_port = 8443

在frpc2中开启了visitor,配置如下:

[common]
...
#user = frpc1

[http_STCP_visitor]
type = stcp
role = visitor
server_name = frpc1.web_http_stcp
#server_name = web_http_stcp
sk = ***
bind_addr = 127.0.0.1
bind_port = 8003

最近把frps升级到了linux/amd64 v0.51.3,然后发现visitor这端无法正常访问stcp了,日志错误为:

2023/09/28 10:07:39 [W] [stcp.go:114] [dafea2a2d7683e69] [http_STCP_visitor] start new visitor connection error: visitor connection of [frpc1.web_http_stcp] user [] not allowed

最终发现原因是在frpc2的visitor的[common]里面没有写user=参数。
但是在frps升级至0.51.3版本之前,frpc2 visitor的写法,其实是上面注释掉的部分,即server_name = frpc1.web_http_stcp,也就是说新版不再支持用加user前缀这种方式来定义user了。即使是显式的在visitor里面再加上server_user = frpc1,仍然会由于没有在common里面定义user而继续报错,那么visitor的server_user的参数的意义在哪里呢?

那么就引申出了另外一个问题,stcp优雅的使用方式是怎么样的?

由于stcp visitor会解析[common]里面的user=字段当成用户,如果我需要在一个frpc上,同时访问2个不同机器的stcp,这样是否就需要开2个frpc的进程及2个单独的frpc.ini配置,分别在[common]里面定义不同stcp的user=字段?

另外就是,如果一个frpc同时需要既当成普通frpc客户端,也需要作为visitor访问stcp,那么现有的版本有没有办法只开一个frpc的进程来实现呢?(按照上面的方法测试发现是不行的,需要跑2个frpc进程,以及需要各自的frpc.ini配置)

https://github.com/fatedier/frp/issues/927#issuecomment-440503770

stcp client and visitor should be the same user.

frpc Version

0.51.2 & 0.45.0

frps Version

0.51.3

System Architecture

linux/mips, windows/amd64

Configurations

[common]
...
#user = frpc2

[http_STCP_visitor]
type = stcp
role = visitor
server_name = frpc2.web_http_stcp
#server_name = web_http_stcp
sk = ***
bind_addr = 127.0.0.1
bind_port = 8003

Logs

2023/09/28 10:07:39 [W] [stcp.go:114] [dafea2a2d7683e69] [http_STCP_visitor] start new visitor connection error: visitor connection of [frpc1.web_http_stcp] user [] not allowed

Steps to reproduce

...

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @zhufeng on GitHub (Sep 28, 2023). Original GitHub issue: https://github.com/fatedier/frp/issues/3633 ### Bug Description 目前的环境共有1个frps,2个frpc,分别为frpc1( linux/mips, v0.45.0) 以及frpc2( win/amd64, v0.51.2)。 在frpc1中开启了stcp,配置如下: ``` [common] ... user = frpc1 [web_http_stcp] type = stcp sk = *** local_ip = 127.0.0.1 local_port = 8443 ``` 在frpc2中开启了visitor,配置如下: ``` [common] ... #user = frpc1 [http_STCP_visitor] type = stcp role = visitor server_name = frpc1.web_http_stcp #server_name = web_http_stcp sk = *** bind_addr = 127.0.0.1 bind_port = 8003 ``` 最近把frps升级到了linux/amd64 v0.51.3,然后发现visitor这端无法正常访问stcp了,日志错误为: ``` 2023/09/28 10:07:39 [W] [stcp.go:114] [dafea2a2d7683e69] [http_STCP_visitor] start new visitor connection error: visitor connection of [frpc1.web_http_stcp] user [] not allowed ``` 最终发现原因是在frpc2的visitor的[common]里面没有写user=参数。 但是在frps升级至0.51.3版本之前,frpc2 visitor的写法,其实是上面注释掉的部分,即server_name = frpc1.web_http_stcp,也就是说新版不再支持用加user前缀这种方式来定义user了。即使是显式的在visitor里面再加上server_user = frpc1,仍然会由于没有在common里面定义user而继续报错,那么visitor的server_user的参数的意义在哪里呢? 那么就引申出了另外一个问题,stcp优雅的使用方式是怎么样的? 由于stcp visitor会解析[common]里面的user=字段当成用户,如果我需要在一个frpc上,同时访问2个不同机器的stcp,这样是否就需要开2个frpc的进程及2个单独的frpc.ini配置,分别在[common]里面定义不同stcp的user=字段? 另外就是,如果一个frpc同时需要既当成普通frpc客户端,也需要作为visitor访问stcp,那么现有的版本有没有办法只开一个frpc的进程来实现呢?(按照上面的方法测试发现是不行的,需要跑2个frpc进程,以及需要各自的frpc.ini配置) [https://github.com/fatedier/frp/issues/927#issuecomment-440503770](url) > stcp client and visitor should be the same user. ### frpc Version 0.51.2 & 0.45.0 ### frps Version 0.51.3 ### System Architecture linux/mips, windows/amd64 ### Configurations ``` [common] ... #user = frpc2 [http_STCP_visitor] type = stcp role = visitor server_name = frpc2.web_http_stcp #server_name = web_http_stcp sk = *** bind_addr = 127.0.0.1 bind_port = 8003 ``` ### Logs ``` 2023/09/28 10:07:39 [W] [stcp.go:114] [dafea2a2d7683e69] [http_STCP_visitor] start new visitor connection error: visitor connection of [frpc1.web_http_stcp] user [] not allowed ``` ### Steps to reproduce 1. 2. 3. ... ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
Author
Owner

@fatedier commented on GitHub (Sep 28, 2023):

先通过 allow_users 指定允许哪些其他用户访问。doc

visitor 中通过配置 server_user 指定要访问的其他用户名称。doc

<!-- gh-comment-id:1738380335 --> @fatedier commented on GitHub (Sep 28, 2023): 先通过 `allow_users` 指定允许哪些其他用户访问。[doc](https://gofrp.org/docs/reference/proxy/#stcp) visitor 中通过配置 `server_user` 指定要访问的其他用户名称。[doc](https://gofrp.org/docs/reference/visitor/#:~:text=%E8%A1%A8%E7%A4%BA%E8%AE%BF%E9%97%AE%E7%AB%AF-,server_user,-string)
Author
Owner

@superzjg commented on GitHub (Sep 28, 2023):

是的,我也发现了,不都升级只能是在全局设置user
如果都升级了,按照楼上大大的方法,可达到你的要求。

<!-- gh-comment-id:1738457089 --> @superzjg commented on GitHub (Sep 28, 2023): 是的,我也发现了,不都升级只能是在全局设置user 如果都升级了,按照楼上大大的方法,可达到你的要求。
Author
Owner

@zhufeng commented on GitHub (Sep 28, 2023):

原来这个allow_users的stcp的参数是在v0.50版本引入的,需要更新frpc bin文件。

测试了一下确实是能解决这个问题,感谢。

先通过 allow_users 指定允许哪些其他用户访问。doc

visitor 中通过配置 server_user 指定要访问的其他用户名称。doc

<!-- gh-comment-id:1738783938 --> @zhufeng commented on GitHub (Sep 28, 2023): 原来这个allow_users的stcp的参数是在v0.50版本引入的,需要更新frpc bin文件。 测试了一下确实是能解决这个问题,感谢。 > 先通过 `allow_users` 指定允许哪些其他用户访问。[doc](https://gofrp.org/docs/reference/proxy/#stcp) > > visitor 中通过配置 `server_user` 指定要访问的其他用户名称。[doc](https://gofrp.org/docs/reference/visitor/#:~:text=%E8%A1%A8%E7%A4%BA%E8%AE%BF%E9%97%AE%E7%AB%AF-,server_user,-string)
Author
Owner

@finallycc commented on GitHub (Sep 26, 2024):

版本0.60.0
各位好,我参考配置

allowUsers | []string | 允许访问的 visitor 用户列表,默认只允许同一用户下的 visitor 访问,配置为 * 则允许任何 visitor 访问。

在linux A系统使用
ssh -R :80:127.0.0.1:22 v0@192.168.1.10 -p 2200 stcp -t Pwd001 -u finallycc -n U001 --sk P001 --allow-users *
创建stcp,这个* 号不生效
ssh -R :80:127.0.0.1:22 v0@192.168.1.10 -p 2200 stcp -t Pwd001 -u finallycc -n U001 --sk P001 --allow-users finallycc
创建stcp,这个是生效的
在linux B系统使用
./frpc stcp visitor -s "192.168.1.10" -P 9000 -t Pwd001 --uc --ue -n V001 -u finallycc --server_name U001 --sk P001 --bind_addr "127.0.0.1" --bind_port 22

能否给我一个例子能正确配置--allow-users 参数?
可以访问

<!-- gh-comment-id:2376741403 --> @finallycc commented on GitHub (Sep 26, 2024): **版本0.60.0** 各位好,我参考配置 > allowUsers | []string | 允许访问的 visitor 用户列表,默认只允许同一用户下的 visitor 访问,配置为 * 则允许任何 visitor 访问。 在linux A系统使用 `ssh -R :80:127.0.0.1:22 v0@192.168.1.10 -p 2200 stcp -t Pwd001 -u finallycc -n U001 --sk P001 --allow-users *` 创建stcp,这个* 号不生效 `ssh -R :80:127.0.0.1:22 v0@192.168.1.10 -p 2200 stcp -t Pwd001 -u finallycc -n U001 --sk P001 --allow-users finallycc ` 创建stcp,这个是生效的 在linux B系统使用 `./frpc stcp visitor -s "192.168.1.10" -P 9000 -t Pwd001 --uc --ue -n V001 -u finallycc --server_name U001 --sk P001 --bind_addr "127.0.0.1" --bind_port 22` 能否给我一个例子能正确配置--allow-users 参数? 可以访问
Author
Owner

@finallycc commented on GitHub (Sep 27, 2024):

您好,我发现--server_user 这个参数在命令模式下,还未支持,如果可以希望您增加以下
**Usage:
frpc stcp visitor [flags]

Flags:
--bind-addr string bind addr
--bind-port int bind port
-h, --help help for visitor
--server-name string server name
--sk string secret key
--uc use compression
--ue use encryption
-n, --visitor-name string visitor name**

<!-- gh-comment-id:2378326977 --> @finallycc commented on GitHub (Sep 27, 2024): 您好,我发现--server_user 这个参数在命令模式下,还未支持,如果可以希望您增加以下 **Usage: frpc stcp visitor [flags] Flags: --bind-addr string bind addr --bind-port int bind port -h, --help help for visitor --server-name string server name --sk string secret key --uc use compression --ue use encryption -n, --visitor-name string visitor name**
Author
Owner

@finallycc commented on GitHub (Sep 27, 2024):

经过测试 --allow-users U002 和--allow-users "*" 是可以的
但是我如果想设置多个用户呢
我测试了如下场景,都失败了
--allow-users U001 U002
--allow-users "U001" "U002"
--allow-users '["U001","U002"]'
--allow-users [U001,U002]
--allow-users ["U001","U002"]

请问我该如何配置U001 和U002

<!-- gh-comment-id:2378382286 --> @finallycc commented on GitHub (Sep 27, 2024): 经过测试 --allow-users U002 和--allow-users "*" 是可以的 但是我如果想设置多个用户呢 我测试了如下场景,都失败了 --allow-users U001 U002 --allow-users "U001" "U002" --allow-users '["U001","U002"]' --allow-users [U001,U002] --allow-users ["U001","U002"] 请问我该如何配置U001 和U002
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2897
No description provided.