Skip to content

Commit ce67782

Browse files
authored
Merge pull request fatedier#2834 from fatedier/dev
bump version
2 parents 88fcc07 + 1f88a7a commit ce67782

File tree

21 files changed

+233
-33
lines changed

21 files changed

+233
-33
lines changed

Release.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
### New
2+
3+
* Added `dial_server_timeout` in frpc to specify connect timeout to frps.
4+
* Additional EndpointParams can be set for OIDC.
5+
* Added CloseProxy operation in server plugin.
6+
7+
### Improve
8+
9+
* Added some randomness in reconnect delay.
10+
111
### Fix
212

3-
* Fixed IPv6 address parse issue.
13+
* TLS server name is ignored when `tls_trusted_ca_file` isn’t set.

client/control.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ func (ctl *Control) connectServer() (conn net.Conn, err error) {
251251
}
252252
dialOptions = append(dialOptions,
253253
libdial.WithProtocol(protocol),
254+
libdial.WithTimeout(time.Duration(ctl.clientCfg.DialServerTimeout)*time.Second),
254255
libdial.WithProxy(proxyType, addr),
255256
libdial.WithProxyAuth(auth),
256257
libdial.WithTLSConfig(tlsConfig),

client/proxy/proxy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,10 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf
787787
return
788788
}
789789

790-
localConn, err := libdial.Dial(net.JoinHostPort(localInfo.LocalIP, strconv.Itoa(localInfo.LocalPort)))
790+
localConn, err := libdial.Dial(
791+
net.JoinHostPort(localInfo.LocalIP, strconv.Itoa(localInfo.LocalPort)),
792+
libdial.WithTimeout(10*time.Second),
793+
)
791794
if err != nil {
792795
workConn.Close()
793796
xl.Error("connect to local service [%s:%d] error: %v", localInfo.LocalIP, localInfo.LocalPort, err)

client/service.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package client
1717
import (
1818
"context"
1919
"crypto/tls"
20-
"errors"
2120
"fmt"
2221
"io"
2322
"net"
@@ -34,6 +33,7 @@ import (
3433
"github.com/fatedier/frp/pkg/transport"
3534
"github.com/fatedier/frp/pkg/util/log"
3635
frpNet "github.com/fatedier/frp/pkg/util/net"
36+
"github.com/fatedier/frp/pkg/util/util"
3737
"github.com/fatedier/frp/pkg/util/version"
3838
"github.com/fatedier/frp/pkg/util/xlog"
3939
libdial "github.com/fatedier/golib/net/dial"
@@ -109,7 +109,7 @@ func (svr *Service) Run() error {
109109
if svr.cfg.LoginFailExit {
110110
return err
111111
}
112-
time.Sleep(10 * time.Second)
112+
util.RandomSleep(10*time.Second, 0.9, 1.1)
113113
} else {
114114
// login success
115115
ctl := NewControl(svr.ctx, svr.runID, conn, session, svr.cfg, svr.pxyCfgs, svr.visitorCfgs, svr.serverUDPPort, svr.authSetter)
@@ -158,8 +158,11 @@ func (svr *Service) keepControllerWorking() {
158158

159159
// the first three retry with no delay
160160
if reconnectCounts > 3 {
161-
time.Sleep(reconnectDelay)
161+
util.RandomSleep(reconnectDelay, 0.9, 1.1)
162+
xl.Info("wait %v to reconnect", reconnectDelay)
162163
reconnectDelay *= 2
164+
} else {
165+
util.RandomSleep(time.Second, 0, 0.5)
163166
}
164167
reconnectCounts++
165168

@@ -175,18 +178,12 @@ func (svr *Service) keepControllerWorking() {
175178
xl.Info("try to reconnect to server...")
176179
conn, session, err := svr.login()
177180
if err != nil {
178-
xl.Warn("reconnect to server error: %v", err)
179-
time.Sleep(delayTime)
180-
181-
opErr := &net.OpError{}
182-
// quick retry for dial error
183-
if errors.As(err, &opErr) && opErr.Op == "dial" {
184-
delayTime = 2 * time.Second
185-
} else {
186-
delayTime = delayTime * 2
187-
if delayTime > maxDelayTime {
188-
delayTime = maxDelayTime
189-
}
181+
xl.Warn("reconnect to server error: %v, wait %v for another retry", err, delayTime)
182+
util.RandomSleep(delayTime, 0.9, 1.1)
183+
184+
delayTime = delayTime * 2
185+
if delayTime > maxDelayTime {
186+
delayTime = maxDelayTime
190187
}
191188
continue
192189
}
@@ -245,6 +242,7 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) {
245242
}
246243
dialOptions = append(dialOptions,
247244
libdial.WithProtocol(protocol),
245+
libdial.WithTimeout(time.Duration(svr.cfg.DialServerTimeout)*time.Second),
248246
libdial.WithProxy(proxyType, addr),
249247
libdial.WithProxyAuth(auth),
250248
libdial.WithTLSConfig(tlsConfig),

conf/frpc_full.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
server_addr = 0.0.0.0
77
server_port = 7000
88

9+
# The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
10+
# dial_server_timeout = 10
11+
912
# if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set http_proxy here or in global environment variables
1013
# it only works when protocol is tcp
1114
# http_proxy = http://user:[email protected]:8080
@@ -48,6 +51,12 @@ oidc_audience =
4851
# It will be used to get an OIDC token if AuthenticationMethod == "oidc". By default, this value is "".
4952
oidc_token_endpoint_url =
5053

54+
# oidc_additional_xxx specifies additional parameters to be sent to the OIDC Token Endpoint.
55+
# For example, if you want to specify the "audience" parameter, you can set as follow.
56+
# frp will add "audience=<value>" "var1=<value>" to the additional parameters.
57+
# oidc_additional_audience = https://dev.auth.com/api/v2/
58+
# oidc_additional_var1 = foobar
59+
5160
# set admin address for control frpc's action by http api such as reload
5261
admin_addr = 127.0.0.1
5362
admin_port = 7400

doc/server_plugin.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The response can look like any of the following:
7070

7171
### Operation
7272

73-
Currently `Login`, `NewProxy`, `Ping`, `NewWorkConn` and `NewUserConn` operations are supported.
73+
Currently `Login`, `NewProxy`, `CloseProxy`, `Ping`, `NewWorkConn` and `NewUserConn` operations are supported.
7474

7575
#### Login
7676

@@ -136,6 +136,26 @@ Create new proxy
136136
}
137137
```
138138

139+
#### CloseProxy
140+
141+
A previously created proxy is closed.
142+
143+
Please note that one request will be sent for every proxy that is closed, do **NOT** use this
144+
if you have too many proxies bound to a single client, as this may exhaust the server's resources.
145+
146+
```
147+
{
148+
"content": {
149+
"user": {
150+
"user": <string>,
151+
"metas": map<string>string
152+
"run_id": <string>
153+
},
154+
"proxy_name": <string>
155+
}
156+
}
157+
```
158+
139159
#### Ping
140160

141161
Heartbeat from frpc

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
77
github.com/coreos/go-oidc v2.2.1+incompatible
88
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
9-
github.com/fatedier/golib v0.1.1-0.20220119075718-78e5cf8c00ee
9+
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9
1010
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
1111
github.com/go-playground/validator/v10 v10.6.1
1212
github.com/google/uuid v1.2.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
8888
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
8989
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb h1:wCrNShQidLmvVWn/0PikGmpdP0vtQmnvyRg3ZBEhczw=
9090
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb/go.mod h1:wx3gB6dbIfBRcucp94PI9Bt3I0F2c/MyNEWuhzpWiwk=
91-
github.com/fatedier/golib v0.1.1-0.20220119075718-78e5cf8c00ee h1:iS0wlj2uZPxh3pciAf/HTzi88Kqu7DPh1jNKgJaFhtI=
92-
github.com/fatedier/golib v0.1.1-0.20220119075718-78e5cf8c00ee/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
91+
github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b h1:5r5/G3NFsFK+7svxvxZYA8yy8Ubs4hWIq+QYYMgEBe8=
92+
github.com/fatedier/golib v0.1.1-0.20220218073251-9509a597216b/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
93+
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9 h1:AOGf9Z1ri+3MiyGIAYXe+shEXx6/uVGJlufb6ZfnZls=
94+
github.com/fatedier/golib v0.1.1-0.20220218075713-264f72dfbfd9/go.mod h1:fLV0TLwHqrnB/L3jbNl67Gn6PCLggDGHniX1wLrA2Qo=
9395
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible h1:ssXat9YXFvigNge/IkkZvFMn8yeYKFX+uI6wn2mLJ74=
9496
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible/go.mod h1:YpCOaxj7vvMThhIQ9AfTOPW2sfztQR5WDfs7AflSy4s=
9597
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=

pkg/auth/oidc.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ type OidcClientConfig struct {
4040
// It will be used to get an OIDC token if AuthenticationMethod == "oidc".
4141
// By default, this value is "".
4242
OidcTokenEndpointURL string `ini:"oidc_token_endpoint_url" json:"oidc_token_endpoint_url"`
43+
44+
// OidcAdditionalEndpointParams specifies additional parameters to be sent
45+
// this field will be transfer to map[string][]string in OIDC token generator
46+
// The field will be set by prefix "oidc_additional_"
47+
OidcAdditionalEndpointParams map[string]string `ini:"-" json:"oidc_additional_endpoint_params"`
4348
}
4449

4550
func getDefaultOidcClientConf() OidcClientConfig {
4651
return OidcClientConfig{
47-
OidcClientID: "",
48-
OidcClientSecret: "",
49-
OidcAudience: "",
50-
OidcTokenEndpointURL: "",
52+
OidcClientID: "",
53+
OidcClientSecret: "",
54+
OidcAudience: "",
55+
OidcTokenEndpointURL: "",
56+
OidcAdditionalEndpointParams: make(map[string]string),
5157
}
5258
}
5359

@@ -88,11 +94,17 @@ type OidcAuthProvider struct {
8894
}
8995

9096
func NewOidcAuthSetter(baseCfg BaseConfig, cfg OidcClientConfig) *OidcAuthProvider {
97+
eps := make(map[string][]string)
98+
for k, v := range cfg.OidcAdditionalEndpointParams {
99+
eps[k] = []string{v}
100+
}
101+
91102
tokenGenerator := &clientcredentials.Config{
92-
ClientID: cfg.OidcClientID,
93-
ClientSecret: cfg.OidcClientSecret,
94-
Scopes: []string{cfg.OidcAudience},
95-
TokenURL: cfg.OidcTokenEndpointURL,
103+
ClientID: cfg.OidcClientID,
104+
ClientSecret: cfg.OidcClientSecret,
105+
Scopes: []string{cfg.OidcAudience},
106+
TokenURL: cfg.OidcTokenEndpointURL,
107+
EndpointParams: eps,
96108
}
97109

98110
return &OidcAuthProvider{

pkg/config/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type ClientCommonConf struct {
3838
// ServerPort specifies the port to connect to the server on. By default,
3939
// this value is 7000.
4040
ServerPort int `ini:"server_port" json:"server_port"`
41+
// The maximum amount of time a dial to server will wait for a connect to complete.
42+
DialServerTimeout int64 `ini:"dial_server_timeout" json:"dial_server_timeout"`
4143
// ConnectServerLocalIP specifies the address of the client bind when it connect to server.
4244
// By default, this value is empty.
4345
// this value only use in TCP/Websocket protocol. Not support in KCP protocol.
@@ -157,6 +159,7 @@ func GetDefaultClientConf() ClientCommonConf {
157159
ClientConfig: auth.GetDefaultClientConf(),
158160
ServerAddr: "0.0.0.0",
159161
ServerPort: 7000,
162+
DialServerTimeout: 10,
160163
HTTPProxy: os.Getenv("http_proxy"),
161164
LogFile: "console",
162165
LogWay: "console",
@@ -258,6 +261,8 @@ func UnmarshalClientConfFromIni(source interface{}) (ClientCommonConf, error) {
258261
}
259262

260263
common.Metas = GetMapWithoutPrefix(s.KeysHash(), "meta_")
264+
common.ClientConfig.OidcAdditionalEndpointParams = GetMapWithoutPrefix(s.KeysHash(), "oidc_additional_")
265+
261266
return common, nil
262267
}
263268

0 commit comments

Comments
 (0)